/* ============================================
   GTI IoT - Layout Base
   Cores Empresariais + Design Moderno
============================================ */

:root {
    /* Cores Primárias */
    --gti-primary: #475569;        /* Cinza slate */
    --gti-primary-dark: #334155;
    --gti-primary-light: #64748b;
    
    /* Cores Secundárias */
    --gti-secondary: #64748b;      /* Cinza moderno */
    --gti-blue: #0369a1;           /* Azul GTI institucional */
    --gti-blue-dark: #075985;
    --gti-success: #10b981;
    --gti-warning: #f59e0b;
    --gti-danger: #ef4444;
    --gti-info: #06b6d4;
    
    /* Cores de Fundo */
    --gti-bg-body: #f1f5f9;
    --gti-bg-sidebar: #0e3753;     /* Azul escuro personalizado */
    --gti-bg-sidebar-hover: #125c87;
    --gti-bg-header: #ffffff;
    --gti-bg-card: #ffffff;
    
    /* Texto */
    --gti-text-primary: #1e293b;
    --gti-text-secondary: #64748b;
    --gti-text-light: #94a3b8;
    --gti-text-sidebar: #cbd5e1;
    
    /* Bordas */
    --gti-border-color: #e2e8f0;
    
    /* Sidebar */
    --sidebar-width: 260px;
    --sidebar-collapsed-width: 70px;
    
    /* Header */
    --header-height: 64px;
    
    /* Sombras */
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
}

/* ============================================
   Reset e Base
============================================ */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    height: 100%;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    font-size: 0.9375rem;
    line-height: 1.6;
    color: var(--gti-text-primary);
    background-color: var(--gti-bg-body);
    overflow-x: hidden;
    min-height: 100%;
}

/* ============================================
   Layout Principal
============================================ */

.wrapper {
    display: flex;
    min-height: 100vh;
    width: 100%;
    position: relative;
}

.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    margin-left: var(--sidebar-width);
    min-width: 0; /* Previne overflow */
    width: calc(100% - var(--sidebar-width));
    transition: margin-left 0.3s ease, width 0.3s ease;
}

.sidebar.collapsed ~ .main-content {
    margin-left: var(--sidebar-collapsed-width);
    width: calc(100% - var(--sidebar-collapsed-width));
}

.page-content {
    flex: 1;
    padding: 2rem 1.5rem;
    margin-top: var(--header-height);
    width: 100%;
}

/* ============================================
   Sidebar
============================================ */

.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--sidebar-width);
    height: 100vh;
    background-color: var(--gti-bg-sidebar);
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-lg);
    z-index: 1000;
    transition: width 0.3s ease;
}

.sidebar.collapsed {
    width: var(--sidebar-collapsed-width);
}

.sidebar.collapsed .sidebar-title,
.sidebar.collapsed .nav-section-title,
.sidebar.collapsed span {
    display: none;
}

.sidebar.collapsed .sidebar-footer {
    display: none;
}

.sidebar.collapsed .sidebar-header {
    justify-content: center;
}

.sidebar.collapsed .nav-item {
    justify-content: center;
    padding-left: 0;
    padding-right: 0;
}

.sidebar-header {
    padding: 1.25rem 1.5rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    transition: background-color 0.2s ease;
}

.sidebar-header:hover {
    background-color: rgba(255, 255, 255, 0.05);
}

.sidebar-logo {
    width: 54px;
    height: 44px;
}

.sidebar-title {
    font-size: 1.25rem;
    font-weight: 600;
    color: white;
    margin: 0;
}

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 1rem 0;
}

/* Scrollbar customizada */
.sidebar-nav::-webkit-scrollbar {
    width: 6px;
}

.sidebar-nav::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05);
}

.sidebar-nav::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 3px;
}

.nav-section {
    margin-bottom: 1.5rem;
}

.nav-section-title {
    padding: 0.5rem 1.5rem;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #ffffff;
    margin-top: 0.5rem;
    opacity: 0.7;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1.5rem;
    color: var(--gti-text-sidebar);
    text-decoration: none;
    transition: all 0.2s ease;
    position: relative;
}

.nav-item i {
    font-size: 1.125rem;
    width: 20px;
    text-align: center;
}

.nav-item:hover {
    background-color: var(--gti-bg-sidebar-hover);
    color: #ffffff;
    transform: translateX(2px);
}

.nav-item.active {
    background-color: #0a2436;
    color: #ffffff;
    border-left: 4px solid #38bdf8;
    font-weight: 500;
}

.nav-item.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    background-color: #38bdf8;
}

/* Submenu */
.submenu {
    background-color: rgba(0, 0, 0, 0.2);
}

.submenu-item {
    padding-left: 3.5rem !important;
    font-size: 0.875rem;
}

.submenu-arrow {
    font-size: 0.75rem;
    transition: transform 0.2s ease;
}

.nav-item[aria-expanded="true"] .submenu-arrow {
    transform: rotate(180deg);
}

/* Badge */
.nav-item .badge {
    margin-left: auto;
    font-size: 0.625rem;
    padding: 0.25rem 0.5rem;
}

.sidebar-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    transition: opacity 0.3s ease;
    color: #ffffff;
}

.version-text {
    color: #ffffff;
    font-size: 0.75rem;
}

.sidebar-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    color: #ffffff;
}

.sidebar-footer-content {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

/* ============================================
   Header
============================================ */

.header {
    position: fixed;
    top: 0;
    left: var(--sidebar-width);
    right: 0;
    height: var(--header-height);
    background: linear-gradient(to bottom, #f0f9ff 0%, #ffffff 100%);
    border-bottom: 1px solid #e0f2fe;
    box-shadow: 0 4px 12px rgba(3, 105, 161, 0.08), 0 2px 4px rgba(0, 0, 0, 0.06);
    z-index: 999;
    transition: left 0.3s ease;
}

.sidebar.collapsed ~ .main-content .header {
    left: var(--sidebar-collapsed-width);
}

.header-container {
    height: 100%;
    display: flex;
    align-items: center;
    padding: 0 1.5rem;
    gap: 1rem;
}

.sidebar-toggle {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--gti-text-primary);
    cursor: pointer;
    padding: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    border-radius: 0.375rem;
}

.sidebar-toggle:hover {
    background-color: var(--gti-bg-body);
    color: var(--gti-primary);
}

.header-brand {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-left: 1rem;
}

.header-logo {
    font-size: 1.5rem;
    color: var(--gti-primary);
}

.header-title {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--gti-text-primary);
}

/* Tenant Info */
.tenant-info {
    display: flex;
    align-items: center;
}

.tenant-badge {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background-color: transparent;
    border: 1px solid var(--gti-border-color);
    border-radius: 0.5rem;
    font-size: 0.875rem;
    transition: all 0.2s ease;
    height: 42px;
    min-height: 42px;
}

.tenant-badge:hover {
    background-color: var(--gti-bg-body);
    border-color: var(--gti-primary-light);
}

.system-name {
    font-weight: 600;
    color: var(--gti-text-primary);
}

.separator {
    color: var(--gti-border-color);
    margin: 0 0.25rem;
}

.tenant-name {
    font-weight: 500;
    color: var(--gti-text-primary);
    line-height: 1.5;
}

.tenant-subdomain {
    font-size: 0.75rem;
}

/* User Menu */
.user-menu-toggle {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background-color: transparent;
    border: 1px solid var(--gti-border-color);
    border-radius: 0.5rem;
    color: var(--gti-text-primary);
    cursor: pointer;
    transition: all 0.2s ease;
    min-width: 200px;
    height: 42px;
    min-height: 42px;
}

.user-menu-toggle:hover {
    background-color: var(--gti-bg-body);
    border-color: var(--gti-primary-light);
}

.user-menu-toggle i {
    font-size: 1.5rem;
    flex-shrink: 0;
}

.user-name {
    font-weight: 500;
    font-size: 0.875rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Dropdown do user menu com mesma largura do botão */
.user-menu {
    position: relative;
}

.user-menu-toggle + .dropdown-menu {
    min-width: 100%;
    width: max-content;
    max-width: 350px;
}

.dropdown-header .user-info-detail {
    padding: 0.25rem 0;
}

/* ============================================
   Overlay para Mobile
============================================ */

.overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 999;
    display: none;
    transition: opacity 0.3s ease;
}

.overlay.active {
    display: block;
}

/* ============================================
   Messages/Alerts
============================================ */

.messages-container {
    margin-bottom: 1.5rem;
}

.alert {
    border-radius: 0.5rem;
    border-left: 4px solid;
}

.alert-success {
    border-left-color: var(--gti-success);
}

.alert-warning {
    border-left-color: var(--gti-warning);
}

.alert-danger {
    border-left-color: var(--gti-danger);
}

.alert-info {
    border-left-color: var(--gti-info);
}

/* ============================================
   Responsividade
============================================ */

/* Tablets */
@media (max-width: 991px) {
    .sidebar {
        transform: translateX(-100%);
    }
    
    .sidebar.active {
        transform: translateX(0);
    }
    
    .main-content {
        margin-left: 0;
    }
    
    .header {
        left: 0;
    }
    
    .sidebar-toggle {
        display: block;
    }
    
    .tenant-name,
    .user-name {
        display: none;
    }
}

/* Mobile */
@media (max-width: 575px) {
    .page-content {
        padding: 1rem;
    }
    
    .header-container {
        padding: 0 1rem;
    }
    
    .tenant-badge {
        padding: 0.5rem;
    }
    
    .tenant-subdomain {
        display: none;
    }
    
    .user-menu-toggle {
        padding: 0.5rem;
        border: none;
    }
}

/* ============================================
   Utilitários
============================================ */

.card {
    background-color: var(--gti-bg-card);
    border-radius: 0.75rem;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--gti-border-color);
}

.btn-primary {
    background-color: var(--gti-primary);
    border-color: var(--gti-primary);
}

.btn-primary:hover {
    background-color: var(--gti-primary-dark);
    border-color: var(--gti-primary-dark);
}

/* Botão azul institucional GTI - máxima especificidade */
button[data-bs-toggle="modal"][data-bs-target="#importModal"],
button[data-bs-toggle="modal"].btn-gti-blue,
#import-btn.btn.btn-gti-blue,
.btn.btn-gti-blue,
button.btn-gti-blue,
button[data-bs-target="#importModal"] {
    background-color: #0369a1 !important;
    border-color: #0369a1 !important;
    color: #ffffff !important;
}

button[data-bs-toggle="modal"][data-bs-target="#importModal"]:hover,
button[data-bs-toggle="modal"][data-bs-target="#importModal"]:focus,
button[data-bs-toggle="modal"][data-bs-target="#importModal"]:active,
button[data-bs-toggle="modal"].btn-gti-blue:hover,
button[data-bs-toggle="modal"].btn-gti-blue:focus,
button[data-bs-toggle="modal"].btn-gti-blue:active,
#import-btn.btn.btn-gti-blue:hover,
#import-btn.btn.btn-gti-blue:focus,
#import-btn.btn.btn-gti-blue:active,
.btn.btn-gti-blue:hover,
.btn.btn-gti-blue:focus,
.btn.btn-gti-blue:active,
button.btn-gti-blue:hover,
button.btn-gti-blue:focus, 
button.btn-gti-blue:active {
    background-color: #075985 !important;
    border-color: #075985 !important;
    color: #ffffff !important;
}

.btn-info {
    background-color: var(--gti-blue) !important;
    border-color: var(--gti-blue) !important;
    color: #ffffff !important;
}

.btn-info:hover {
    background-color: var(--gti-blue-dark) !important;
    border-color: var(--gti-blue-dark) !important;
    color: #ffffff !important;
}

/* Checkboxes customizados com azul GTI */
.form-check-input {
    width: 1.125rem;
    height: 1.125rem;
    border: 2px solid #cbd5e1;
    border-radius: 0.25rem;
    cursor: pointer;
}

.form-check-input:hover {
    border-color: var(--gti-blue);
}

.form-check-input:checked {
    background-color: var(--gti-blue) !important;
    border-color: var(--gti-blue) !important;
}

.form-check-input:focus {
    border-color: var(--gti-blue);
    box-shadow: 0 0 0 0.2rem rgba(3, 105, 161, 0.25);
}

.text-primary {
    color: var(--gti-primary) !important;
}

.bg-primary {
    background-color: var(--gti-primary) !important;
}
