:root {
    --sidebar-width: 260px;
    --sidebar-collapsed-width: 80px;
    --header-height: 70px;
    --primary-color: #3b82f6; /* Azul Vibrante Moderno */
    --accent-color: #60a5fa;
    --bg-dark: #050505;
    --sidebar-bg: #0a0a0a;
    --sidebar-border: rgba(255, 255, 255, 0.06);
    --nav-hover-bg: rgba(255, 255, 255, 0.03);
    --nav-active-bg: rgba(59, 130, 246, 0.1);
    --text-muted: #94a3b8;
    --text-light: #f8fafc;
    --bg-light: #f1f5f9;
}

* {
    box-sizing: border-box;
}

body,
html {
    margin: 0;
    padding: 0;
    height: 100%;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background-color: var(--bg-light);
    color: #1e293b;
}

/* Layout Principal */
.app-container {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* ================== PREMIUM SIDEBAR ================== */
.sidebar {
    width: var(--sidebar-width);
    background-color: var(--sidebar-bg);
    color: var(--text-light);
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
    min-width: 0;
    z-index: 1000;
    border-right: 1px solid var(--sidebar-border);
    position: relative;
}

.sidebar.collapsed {
    width: var(--sidebar-collapsed-width);
}

.sidebar-header {
    height: var(--header-height);
    display: flex;
    align-items: center;
    justify-content: center; /* Centraliza o conteúdo horizontalmente */
    padding: 0 15px;
    margin-bottom: 10px;
    position: relative; /* Necessário para o posicionamento absoluto do botão */
}

.sidebar-header h3 {
    margin: 0;
    font-size: 0.85rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.15em;
    color: var(--primary-color);
    white-space: nowrap;
    overflow: hidden;
    transition: opacity 0.3s;
    text-align: center; /* Garante a centralização do texto */
    flex: 1; /* Ocupa o espaço disponível */
}

.sidebar.collapsed .sidebar-header h3 {
    opacity: 0;
}

.toggle-btn {
    background: var(--nav-hover-bg);
    border: 1px solid var(--sidebar-border);
    color: var(--text-muted);
    width: 28px;
    height: 28px;
    border-radius: 8px;
    font-size: 0.8rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    position: absolute; /* Remove o botão do fluxo normal de flexbox */
    right: 15px; /* Fixa ele no canto direito */
}

.toggle-btn:hover {
    color: var(--text-light);
    background: var(--sidebar-border);
}

.nav-links {
    list-style: none;
    padding: 0 12px;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    padding-bottom: 16px;
}

.nav-links li {
    position: relative;
    min-width: 0;
}

.nav-links li a {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    color: var(--text-muted);
    text-decoration: none;
    border-radius: 12px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    font-size: 0.9rem;
    font-weight: 500;
    position: relative;
    overflow: hidden;
    min-width: 0;
    line-height: 1.35;
}

/* Glassmorphism Hover */
.nav-links li a:hover {
    color: var(--text-light);
    background-color: var(--nav-hover-bg);
    transform: translateX(4px);
}

/* Active State Design */
.nav-links li a.active {
    color: var(--primary-color);
    background-color: var(--nav-active-bg);
}

.nav-links li a.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 20%;
    height: 60%;
    width: 3px;
    background: var(--primary-color);
    border-radius: 0 4px 4px 0;
    box-shadow: 4px 0 15px var(--primary-color);
}

.nav-links li a i {
    min-width: 24px;
    font-size: 1.1rem;
    margin-right: 12px;
    transition: all 0.3s;
    flex-shrink: 0;
}

.nav-links li a.active i {
    transform: scale(1.1);
    color: var(--primary-color);
}

/* ================== DROPDOWN SYSTEM ================== */
.nav-item-dropdown {
    display: flex;
    flex-direction: column;
}

.dropdown-trigger {
    width: 100%;
    display: flex;
    align-items: center;
    padding: 12px 16px;
    color: var(--text-muted);
    text-decoration: none;
    border-radius: 12px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    font-size: 0.9rem;
    font-weight: 500;
    background: transparent;
    border: none;
    cursor: pointer;
    outline: none;
    min-width: 0;
    text-align: left;
    line-height: 1.35;
}

.dropdown-trigger:hover {
    color: var(--text-light);
    background-color: var(--nav-hover-bg);
}

.dropdown-trigger i:first-child {
    min-width: 24px;
    font-size: 1.1rem;
    margin-right: 12px;
    flex-shrink: 0;
}

.dropdown-trigger .chevron {
    margin-left: auto;
    font-size: 0.75rem;
    transition: transform 0.3s ease;
    opacity: 0.5;
    flex-shrink: 0;
    padding-left: 10px;
}

.nav-item-dropdown.open .dropdown-trigger {
    color: var(--text-light);
}

.nav-item-dropdown.open .dropdown-trigger .chevron {
    transform: rotate(180deg);
    opacity: 1;
    color: var(--primary-color);
}

.sub-menu {
    list-style: none;
    padding: 0;
    margin: 4px 0 8px 24px;
    display: none;
    flex-direction: column;
    gap: 2px;
    border-left: 1px solid var(--sidebar-border);
    overflow: hidden;
    min-width: 0;
}

.nav-item-dropdown.open .sub-menu {
    display: flex;
}

.sub-menu li a {
    padding: 10px 16px !important;
    font-size: 0.85rem !important;
    border-radius: 0 10px 10px 0 !important;
    margin-left: -1px; /* Alinha com a borda esquerda */
    min-width: 0;
}

.sub-menu li a:hover {
    transform: translateX(2px) !important;
}

/* Quando o pai está "ativo" (um filho está selecionado) */
.nav-item-dropdown.active-parent .dropdown-trigger {
    color: var(--primary-color);
}

.nav-item-dropdown.active-parent .dropdown-trigger i:first-child {
    color: var(--primary-color);
}

/* Ajustes para Sidebar Colapsado */
.sidebar.collapsed .dropdown-trigger .link-name,
.sidebar.collapsed .dropdown-trigger .chevron {
    display: none;
}

.sidebar.collapsed .sub-menu {
    display: none !important;
}

.link-name {
    display: block;
    flex: 1;
    min-width: 0;
    white-space: normal;
    overflow: hidden;
    text-overflow: ellipsis;
    overflow-wrap: anywhere;
    word-break: break-word;
    line-height: 1.35;
    opacity: 1;
    transition: opacity 0.3s, transform 0.3s;
}

.sidebar.collapsed .link-name {
    opacity: 0;
    pointer-events: none;
    width: 0;
    margin: 0;
}

.sidebar.collapsed .nav-links {
    padding: 0 10px;
}

.sidebar.collapsed .nav-links li a {
    justify-content: center;
    padding: 14px 0;
    margin-bottom: 4px;
}

.sidebar.collapsed .nav-links li a i {
    margin-right: 0;
    font-size: 1.25rem; /* Ícones levemente maiores quando minimizado */
    min-width: unset;
}

.sidebar.collapsed .dropdown-trigger {
    justify-content: center;
    padding: 14px 0;
}

.sidebar.collapsed .dropdown-trigger i:first-child {
    margin-right: 0;
}

.sidebar.collapsed .sidebar-header {
    padding: 0;
    justify-content: center;
}

/* Ajuste específico para o botão Mudar Unidade minimizado */
.sidebar.collapsed .nav-links li:first-child a {
    border-radius: 12px;
    background: var(--nav-active-bg);
}

/* Remover o deslocamento lateral no hover quando colapsado */
.sidebar.collapsed .nav-links li a:hover {
    transform: none;
}

/* Tooltip nativo (opcional, mas ajuda UX) */
.sidebar.collapsed .nav-links li a::after {
    display: none;
}

/* ================== MAIN CONTENT & HEADER ================== */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.topbar {
    height: var(--header-height);
    background-color: #fff;
    border-bottom: 1px solid #e2e8f0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 32px;
    z-index: 10;
}

.topbar-left h2 {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 700;
    color: #0f172a;
}

.mobile-toggle-btn {
    display: none;
    background: transparent;
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
    color: var(--text-dark);
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 500;
}

.content-wrapper {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
}

/* ================== MAPA NA HOME ================== */
.dashboard-grid {
    display: flex;
    flex-direction: column;
    gap: 20px;
    height: 100%;
    /* Toma a altura do wrapper inteiro */
}

.map-container {
    flex: 2;
    /* Mapa ocupa 2/3 da altura */
    min-height: 400px;
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
    overflow: hidden;
    position: relative;
    border: 1px solid #e0e0e0;
}

#map {
    width: 100%;
    height: 100%;
    z-index: 1;
}

/* Widgets e Gráficos abaixo do mapa */
.widgets-container {
    flex: 1;
    /* Widgets ocupam 1/3 da altura */
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
    min-height: 150px;
}

.widget-card {
    background: #fff;
    border-radius: 8px;
    padding: 20px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
    border: 1px solid #e0e0e0;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.widget-card h4 {
    margin: 0 0 10px 0;
    color: #666;
    font-size: 0.9rem;
    text-transform: uppercase;
}

.widget-value {
    font-size: 2rem;
    font-weight: bold;
    color: var(--primary-color);
    margin: 0;
}

/* ================== RESPONSIVIDADE ================== */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: -var(--sidebar-width);
        height: 100%;
        max-width: min(var(--sidebar-width), calc(100vw - 20px));
    }

    .sidebar.mobile-open {
        left: 0;
    }

    .mobile-toggle-btn {
        display: block;
    }

    #toggle-sidebar {
        display: none;
    }

    .widgets-container {
        flex: none;
        /* Em mobile, widgets crescem no scroll */
    }
}

/* ================== HOME DASHBOARD ================== */

/* Container principal — permite scroll vertical */
.home-dashboard {
    display:        flex;
    flex-direction: column;
    gap:            16px;
}

/* Barra de Filtros */
.filter-bar {
    display:       flex;
    flex-wrap:     wrap;
    gap:           12px;
    align-items:   flex-end;
    background:    #fff;
    border-radius: 8px;
    padding:       14px 18px;
    box-shadow:    0 2px 8px rgba(0,0,0,0.06);
    border:        1px solid #e0e0e0;
}

.filter-group {
    display:        flex;
    flex-direction: column;
    gap:            4px;
    min-width:      160px;
    flex:           1;
}

.filter-group label {
    font-size:   0.78rem;
    font-weight: 600;
    color:       #555;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.filter-group select {
    padding:       7px 10px;
    border:        1px solid #ccc;
    border-radius: 5px;
    font-size:     0.88rem;
    background:    #fafafa;
    cursor:        pointer;
}

.filter-group select:focus {
    outline:      none;
    border-color: var(--primary-color);
    box-shadow:   0 0 0 2px rgba(0,86,179,0.15);
}

.filter-actions {
    display:    flex;
    gap:        8px;
    align-self: flex-end;
}

.btn-primary {
    padding:          8px 16px;
    background:       var(--primary-color);
    color:            #fff;
    border:           none;
    border-radius:    5px;
    font-size:        0.88rem;
    cursor:           pointer;
    display:          inline-flex;
    align-items:      center;
    gap:              6px;
    transition:       background 0.2s;
}
.btn-primary:hover   { background: #004494; }
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; }

.btn-secondary {
    padding:       8px 14px;
    background:    #f0f0f0;
    color:         #333;
    border:        1px solid #ccc;
    border-radius: 5px;
    font-size:     0.88rem;
    cursor:        pointer;
    display:       inline-flex;
    align-items:   center;
    gap:           6px;
    transition:    background 0.2s;
}
.btn-secondary:hover { background: #e0e0e0; }

.btn-sm { padding: 5px 10px; font-size: 0.82rem; }

/* Seção superior: mapa (2/3) + cards (1/3) */
.home-top-grid {
    display:               grid;
    grid-template-columns: 2fr 1fr;
    gap:                   16px;
    align-items:           start;
}

.home-map-box {
    background:    #fff;
    border-radius: 8px;
    box-shadow:    0 2px 10px rgba(0,0,0,0.06);
    border:        1px solid #e0e0e0;
    overflow:      hidden;
    height:        420px;
}

#map {
    width:  100%;
    height: 100%;
    z-index: 1;
}

/* Painel lateral com KPIs + legenda */
.home-side-panel {
    display:        flex;
    flex-direction: column;
    gap:            14px;
}

.kpi-grid {
    display:               grid;
    grid-template-columns: 1fr 1fr;
    gap:                   12px;
}

.kpi-card {
    background:    #fff;
    border-radius: 8px;
    padding:       14px;
    box-shadow:    0 2px 8px rgba(0,0,0,0.06);
    border:        1px solid #e0e0e0;
    display:       flex;
    align-items:   center;
    gap:           12px;
}

/* Quando há 3 cards, o último ocupa linha inteira */
.kpi-grid .kpi-card:last-child:nth-child(odd) {
    grid-column: 1 / -1;
}

.kpi-icon {
    width:         42px;
    height:        42px;
    border-radius: 50%;
    display:       flex;
    align-items:   center;
    justify-content: center;
    font-size:     1.1rem;
    flex-shrink:   0;
}

.kpi-label {
    margin:      0 0 2px;
    font-size:   0.75rem;
    font-weight: 600;
    color:       #666;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.kpi-value {
    margin:      0;
    font-size:   1.7rem;
    font-weight: 700;
    color:       var(--primary-color);
    line-height: 1;
}

/* Legenda do mapa */
.map-legend {
    background:    #fff;
    border-radius: 8px;
    padding:       14px 16px;
    box-shadow:    0 2px 8px rgba(0,0,0,0.06);
    border:        1px solid #e0e0e0;
}

.legend-title {
    margin:      0 0 10px;
    font-size:   0.82rem;
    font-weight: 600;
    color:       #555;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.legend-item {
    display:     flex;
    align-items: center;
    gap:         8px;
    font-size:   0.85rem;
    color:       #444;
    margin-bottom: 5px;
}

.legend-dot {
    display:       inline-block;
    width:         14px;
    height:        14px;
    border-radius: 50%;
    flex-shrink:   0;
}

/* Seção de gráficos */
.charts-section {
    display:        flex;
    flex-direction: column;
    gap:            16px;
}

.charts-row-2 {
    display:               grid;
    grid-template-columns: 1fr 1fr;
    gap:                   16px;
}

.chart-card {
    background:    #fff;
    border-radius: 8px;
    padding:       18px 20px;
    box-shadow:    0 2px 8px rgba(0,0,0,0.06);
    border:        1px solid #e0e0e0;
}

.chart-full {
    grid-column: 1 / -1;
}

.chart-title {
    margin:      0 0 14px;
    font-size:   0.9rem;
    font-weight: 600;
    color:       #444;
    display:     flex;
    align-items: center;
    gap:         7px;
}

.chart-wrapper {
    position: relative;
}

/* ================== CONFIG PAGE ================== */

.config-page {
    display:        flex;
    flex-direction: column;
    gap:            20px;
}

.config-card {
    background:    #fff;
    border-radius: 8px;
    padding:       22px 24px;
    box-shadow:    0 2px 8px rgba(0,0,0,0.06);
    border:        1px solid #e0e0e0;
}

.config-card h3 {
    margin:      0 0 6px;
    font-size:   1.05rem;
    display:     flex;
    align-items: center;
    gap:         8px;
    color:       var(--text-dark);
}

.config-card p {
    margin:    0 0 16px;
    color:     #666;
    font-size: 0.9rem;
}

.config-card-header {
    display:         flex;
    justify-content: space-between;
    align-items:     flex-start;
    margin-bottom:   4px;
}

.config-list {
    list-style: none;
    padding:    0;
    margin:     0;
}

.config-list li {
    padding:         12px 14px;
    border:          1px solid #eee;
    border-radius:   5px;
    margin-bottom:   8px;
    display:         flex;
    justify-content: space-between;
    align-items:     center;
    font-size:       0.9rem;
}

.status-ok {
    color:       #28a745;
    font-weight: 500;
    font-size:   0.88rem;
}

/* Tabela de metas */
.meta-table {
    width:           100%;
    border-collapse: collapse;
    font-size:       0.9rem;
    margin-top:      16px;
}

.meta-table th {
    text-align:     left;
    padding:        9px 12px;
    background:     #f5f7fa;
    border-bottom:  2px solid #e0e0e0;
    font-size:      0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color:          #555;
}

.meta-table td {
    padding:       9px 12px;
    border-bottom: 1px solid #f0f0f0;
    vertical-align: middle;
}

.meta-table tr:last-child td {
    border-bottom: none;
}

.meta-input {
    width:         100px;
    padding:       6px 8px;
    border:        1px solid #ccc;
    border-radius: 4px;
    font-size:     0.9rem;
    text-align:    right;
}

.meta-input:focus {
    outline:      none;
    border-color: var(--primary-color);
    box-shadow:   0 0 0 2px rgba(0,86,179,0.15);
}

.loading-msg {
    color:     #888;
    font-size: 0.9rem;
    padding:   12px 0;
}

.save-status {
    padding:       5px 12px;
    border-radius: 5px;
    font-size:     0.85rem;
    font-weight:   500;
}

.save-status--success {
    background: #e6f9ec;
    color:      #1a7a36;
    border:     1px solid #b3e8c3;
}

.save-status--error {
    background: #fde8e8;
    color:      #b91c1c;
    border:     1px solid #f9b3b3;
}

/* ================== RESPONSIVIDADE DASHBOARD ================== */
@media (max-width: 900px) {
    .home-top-grid    { grid-template-columns: 1fr; }
    .home-map-box     { height: 300px; }
    .charts-row-2     { grid-template-columns: 1fr; }
    .filter-group     { min-width: 140px; }
}

/* Popups Leaflet personalizados */
.custom-popup .leaflet-popup-content-wrapper {
    border-radius: 8px;
}

.custom-popup strong {
    color: var(--primary-color);
}

.custom-popup strong {
    color: #0056b3;
}

/* ================== CONSULTA CRUD (Dark Premium) ================== */
.crud-page { display: flex; flex-direction: column; gap: 16px; }

.crud-filter-bar { background: #141414; border: 1px solid rgba(255,255,255,0.08); border-radius: 12px; padding: 18px 22px; display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; }
.crud-filter-bar .filter-title { width: 100%; display: flex; align-items: center; gap: 8px; font-size: 0.8rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; color: #94a3b8; margin-bottom: 2px; }
.crud-filter-bar .filter-title i { font-size: 0.85rem; opacity: 0.7; }
.crud-filter-group { display: flex; flex-direction: column; gap: 5px; min-width: 90px; flex: 1; }
.crud-filter-group label { font-size: 0.72rem; font-weight: 600; color: #64748b; text-transform: uppercase; letter-spacing: 0.04em; }
.crud-filter-group input, .crud-filter-group select { padding: 9px 12px; background: #1e1e1e; border: 1px solid rgba(255,255,255,0.1); border-radius: 8px; color: #e2e8f0; font-size: 0.88rem; font-family: inherit; transition: border-color 0.2s, box-shadow 0.2s; }
.crud-filter-group input::placeholder { color: #4a5568; }
.crud-filter-group input:focus, .crud-filter-group select:focus { outline: none; border-color: var(--primary-color); box-shadow: 0 0 0 3px rgba(59,130,246,0.15); }
.crud-filter-group select option { background: #1e1e1e; color: #e2e8f0; }
.crud-filter-actions { display: flex; gap: 8px; align-self: flex-end; }

.crud-btn-buscar { padding: 9px 20px; background: var(--primary-color); color: #fff; border: none; border-radius: 8px; font-size: 0.88rem; font-weight: 600; cursor: pointer; display: inline-flex; align-items: center; gap: 7px; transition: background 0.2s, transform 0.1s; }
.crud-btn-buscar:hover { background: #2563eb; transform: translateY(-1px); }
.crud-btn-buscar:active { transform: translateY(0); }

.crud-btn-limpar { padding: 9px 14px; background: rgba(255,255,255,0.05); color: #94a3b8; border: 1px solid rgba(255,255,255,0.1); border-radius: 8px; font-size: 0.88rem; cursor: pointer; transition: all 0.2s; }
.crud-btn-limpar:hover { background: rgba(255,255,255,0.1); color: #e2e8f0; }

.crud-table-card { background: #141414; border: 1px solid rgba(255,255,255,0.08); border-radius: 12px; overflow: hidden; }
.crud-table-header { display: flex; justify-content: space-between; align-items: center; padding: 16px 22px; border-bottom: 1px solid rgba(255,255,255,0.06); }
.crud-table-header-left { display: flex; align-items: center; gap: 12px; }
.crud-table-header-left h3 { margin: 0; font-size: 1rem; font-weight: 700; color: #f1f5f9; }
.crud-table-header-left .badge-count { background: rgba(255,255,255,0.06); color: #64748b; padding: 3px 10px; border-radius: 20px; font-size: 0.78rem; font-weight: 500; }
.crud-table-header-right { display: flex; gap: 10px; }

.crud-btn-exportar { padding: 8px 16px; background: rgba(255,255,255,0.05); color: #94a3b8; border: 1px solid rgba(255,255,255,0.1); border-radius: 8px; font-size: 0.84rem; font-weight: 500; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; transition: all 0.2s; }
.crud-btn-exportar:hover { background: rgba(255,255,255,0.1); color: #e2e8f0; }

.crud-table-wrapper { overflow-x: auto; max-height: calc(100vh - 360px); overflow-y: auto; }
.crud-table-wrapper::-webkit-scrollbar { width: 6px; height: 6px; }
.crud-table-wrapper::-webkit-scrollbar-track { background: #111; }
.crud-table-wrapper::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.12); border-radius: 4px; }
.crud-table-wrapper::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.22); }
.crud-table-wrapper::-webkit-scrollbar-corner { background: #111; }
.crud-table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
.crud-table thead th { position: sticky; top: 0; background: #111; color: #64748b; font-size: 0.72rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; padding: 12px 16px; text-align: left; white-space: nowrap; border-bottom: 1px solid rgba(255,255,255,0.08); z-index: 2; }
.crud-table tbody tr { border-bottom: 1px solid rgba(255,255,255,0.04); transition: background 0.15s; }
.crud-table tbody tr:hover { background: rgba(255,255,255,0.03); }
.crud-table tbody td { padding: 13px 16px; color: #cbd5e1; white-space: nowrap; }
.td-endereco { max-width: 220px; overflow: hidden; text-overflow: ellipsis; color: #f1f5f9 !important; font-weight: 500; }
.td-selo { font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace; font-size: 0.84rem; color: #94a3b8 !important; }

.status-badge { display: inline-block; padding: 4px 12px; border-radius: 20px; font-size: 0.76rem; font-weight: 600; text-align: center; white-space: nowrap; }
.badge-realizado { background: rgba(34,197,94,0.15); color: #4ade80; }
.badge-pendente { background: rgba(234,179,8,0.15); color: #facc15; }
.badge-cancelado { background: rgba(239,68,68,0.15); color: #f87171; }
.badge-vistoria { background: rgba(59,130,246,0.15); color: #60a5fa; }

.td-acoes { display: flex; gap: 6px; }
.btn-acao { width: 34px; height: 34px; border-radius: 8px; border: 1px solid rgba(255,255,255,0.08); background: rgba(255,255,255,0.04); color: #64748b; cursor: pointer; display: flex; align-items: center; justify-content: center; font-size: 0.82rem; transition: all 0.2s; }
.btn-acao:hover { color: #e2e8f0; background: rgba(255,255,255,0.1); transform: translateY(-1px); }
.btn-editar:hover { border-color: rgba(59,130,246,0.4); color: #60a5fa; box-shadow: 0 0 8px rgba(59,130,246,0.15); }
.btn-excluir:hover { border-color: rgba(239,68,68,0.4); color: #f87171; box-shadow: 0 0 8px rgba(239,68,68,0.15); }

.crud-empty-state { text-align: center; padding: 50px 20px !important; color: #475569 !important; font-size: 0.92rem; }
.crud-empty-state i { display: block; font-size: 2.2rem; margin-bottom: 12px; opacity: 0.5; }

.skeleton-row td { padding: 15px 16px !important; }
.skeleton-bar { height: 14px; background: linear-gradient(90deg, rgba(255,255,255,0.04) 25%, rgba(255,255,255,0.08) 50%, rgba(255,255,255,0.04) 75%); background-size: 200% 100%; animation: shimmer 1.5s infinite; border-radius: 6px; }
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

.crud-paginacao { display: flex; justify-content: center; align-items: center; gap: 4px; padding: 14px 22px; border-top: 1px solid rgba(255,255,255,0.06); }
.pag-btn { width: 36px; height: 36px; border-radius: 8px; border: 1px solid rgba(255,255,255,0.08); background: transparent; color: #64748b; cursor: pointer; font-size: 0.84rem; font-weight: 500; display: flex; align-items: center; justify-content: center; transition: all 0.2s; }
.pag-btn:hover:not(:disabled) { background: rgba(255,255,255,0.06); color: #e2e8f0; }
.pag-btn:disabled { opacity: 0.3; cursor: not-allowed; }
.pag-active { background: var(--primary-color) !important; color: #fff !important; border-color: var(--primary-color) !important; }

@media (max-width: 900px) { .crud-filter-bar { padding: 14px 16px; } .crud-filter-group { min-width: 120px; } .crud-table-header { flex-direction: column; gap: 10px; align-items: flex-start; } .crud-table-wrapper { max-height: calc(100vh - 420px); } }
@media (max-width: 600px) { .crud-filter-group { min-width: 100%; } }

/* ================== MODAIS (Edição / Foto) ================== */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(4px);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 20px;
}
.modal-container {
    background: #161b22;
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 16px;
    width: 100%;
    max-width: 720px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 24px 80px rgba(0,0,0,0.6);
    animation: modalIn 0.2s ease;
}
@keyframes modalIn {
    from { opacity: 0; transform: scale(0.96) translateY(8px); }
    to   { opacity: 1; transform: scale(1) translateY(0); }
}
.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
}
.modal-header h3 {
    margin: 0;
    font-size: 1rem;
    font-weight: 700;
    color: #f1f5f9;
    display: flex;
    align-items: center;
    gap: 8px;
}
.modal-header h3 i { color: var(--primary-color); }
.modal-close {
    background: transparent;
    border: none;
    color: #64748b;
    font-size: 1.4rem;
    cursor: pointer;
    line-height: 1;
    padding: 4px 8px;
    border-radius: 6px;
    transition: color 0.2s, background 0.2s;
}
.modal-close:hover { color: #f1f5f9; background: rgba(255,255,255,0.06); }

.modal-tabs {
    display: flex;
    gap: 4px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    padding-bottom: 0;
}
.tab-btn {
    padding: 10px 20px;
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    color: #64748b;
    font-size: 0.88rem;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 7px;
    transition: color 0.2s, border-color 0.2s;
    border-radius: 8px 8px 0 0;
    margin-bottom: -1px;
}
.tab-btn:hover { color: #cbd5e1; background: rgba(255,255,255,0.03); }
.tab-btn.active { color: var(--primary-color); border-bottom-color: var(--primary-color); }

.modal-body {
    overflow-y: auto;
    padding: 20px 24px;
    flex: 1;
}
.modal-form {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}
.modal-form > div { display: flex; flex-direction: column; gap: 6px; }
.modal-form label { font-size: 0.72rem; font-weight: 600; color: #64748b; text-transform: uppercase; letter-spacing: 0.04em; }
.modal-form input, .modal-form select {
    padding: 9px 12px;
    background: #1e1e1e;
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 8px;
    color: #e2e8f0;
    font-size: 0.88rem;
    font-family: inherit;
    transition: border-color 0.2s, box-shadow 0.2s;
}
.modal-form input:focus, .modal-form select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(59,130,246,0.15);
}
.modal-form input::placeholder { color: #4a5568; }
.modal-form select option { background: #1e1e1e; color: #e2e8f0; }
.form-group-full { grid-column: 1 / -1; }

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 16px 24px;
    border-top: 1px solid rgba(255,255,255,0.08);
}
.btn-cancelar {
    padding: 10px 20px;
    background: rgba(255,255,255,0.05);
    color: #94a3b8;
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 8px;
    font-size: 0.88rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}
.btn-cancelar:hover { background: rgba(255,255,255,0.1); color: #e2e8f0; }
.btn-salvar {
    padding: 10px 24px;
    background: var(--primary-color);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 0.88rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
}
.btn-salvar:hover { background: #2563eb; transform: translateY(-1px); }
.btn-salvar:disabled { opacity: 0.6; cursor: not-allowed; transform: none; }

/* Modal de confirmação de exclusão */
.modal-confirm-body { padding: 20px 24px; }
.modal-confirm-body p { margin: 0 0 14px; color: #cbd5e1; font-size: 0.92rem; line-height: 1.5; }
.modal-confirm-body p strong { color: #f1f5f9; }
.modal-confirm-alert {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 12px 14px;
    background: rgba(239,68,68,0.08);
    border: 1px solid rgba(239,68,68,0.25);
    border-radius: 8px;
    color: #fca5a5;
    font-size: 0.84rem;
    line-height: 1.45;
}
.modal-confirm-alert i { margin-top: 2px; color: #f87171; }
.btn-confirmar-exclusao {
    padding: 10px 24px;
    background: #dc2626;
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 0.88rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
}
.btn-confirmar-exclusao:hover { background: #b91c1c; transform: translateY(-1px); }
.btn-confirmar-exclusao:disabled { opacity: 0.6; cursor: not-allowed; transform: none; }

/* Botão de foto na tabela */
.btn-foto:hover { border-color: rgba(168,85,247,0.4); color: #c084fc; box-shadow: 0 0 8px rgba(168,85,247,0.15); }

/* Tab content (dentro do modal) */
.tab-content { width: 100%; }

/* Scrollbar do modal */
.modal-body::-webkit-scrollbar { width: 6px; }
.modal-body::-webkit-scrollbar-track { background: transparent; }
.modal-body::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 4px; }
.modal-body::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.2); }

/* ================== FAMÍLIAS — LINHAS EXPANSÍVEIS ================== */
.btn-expand {
    width: 30px; height: 30px;
    border-radius: 8px;
    border: 1px solid rgba(255,255,255,0.1);
    background: rgba(255,255,255,0.04);
    color: #64748b;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    font-size: 0.78rem;
    transition: all 0.2s;
    flex-shrink: 0;
}
.btn-expand:hover {
    border-color: rgba(99,102,241,0.5);
    color: #818cf8;
    background: rgba(99,102,241,0.1);
    transform: none;
}
.btn-expand.is-expanded {
    border-color: rgba(99,102,241,0.5);
    color: #818cf8;
    background: rgba(99,102,241,0.15);
}
.btn-expand .exp-chevron {
    transition: transform 0.25s ease;
    display: inline-block;
}
.btn-expand.is-expanded .exp-chevron {
    transform: rotate(90deg);
}

/* Linha expansível (hidden by default) */
.familia-expand-row {
    display: none;
}
.familia-expand-row.visible {
    display: table-row;
    animation: expand-in 0.18s ease;
}
@keyframes expand-in {
    from { opacity: 0; }
    to   { opacity: 1; }
}

/* Célula wrapper da expansão */
.familia-expand-row > td {
    padding: 0 !important;
    border-bottom: 2px solid rgba(99,102,241,0.25) !important;
}
.familia-expand-content {
    padding: 12px 20px 16px 52px;
    background: rgba(99,102,241,0.04);
    border-left: 3px solid rgba(99,102,241,0.35);
}
.familia-expand-content-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: #818cf8;
}
.familia-expand-content-header i { font-size: 0.8rem; opacity: 0.8; }

/* Mini-tabela de pessoas */
.familia-pessoas-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.84rem;
}
.familia-pessoas-table th {
    color: #475569;
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.7rem;
    letter-spacing: 0.05em;
    padding: 5px 12px 8px;
    border-bottom: 1px solid rgba(255,255,255,0.06);
    text-align: left;
    white-space: nowrap;
}
.familia-pessoas-table td {
    padding: 9px 12px;
    border-bottom: 1px solid rgba(255,255,255,0.04);
    color: #cbd5e1;
    white-space: nowrap;
}
.familia-pessoas-table tr:last-child td { border-bottom: none; }
.familia-pessoas-table tbody tr:hover td { background: rgba(255,255,255,0.025); }
.familia-pessoa-nome { color: #e2e8f0 !important; font-weight: 500; }
.familia-badge-titular {
    display: inline-block; padding: 2px 9px; border-radius: 12px; font-size: 0.7rem; font-weight: 600;
    background: rgba(99,102,241,0.15); color: #818cf8;
}
.familia-badge-conjuge {
    display: inline-block; padding: 2px 9px; border-radius: 12px; font-size: 0.7rem; font-weight: 600;
    background: rgba(236,72,153,0.12); color: #f472b6;
}
.familia-badge-dependente {
    display: inline-block; padding: 2px 9px; border-radius: 12px; font-size: 0.7rem; font-weight: 600;
    background: rgba(251,191,36,0.1); color: #fbbf24;
}
.familia-badge-outro {
    display: inline-block; padding: 2px 9px; border-radius: 12px; font-size: 0.7rem; font-weight: 600;
    background: rgba(255,255,255,0.07); color: #94a3b8;
}

.familia-loading-row {
    padding: 14px 16px;
    color: #64748b;
    font-size: 0.85rem;
    display: flex; align-items: center; gap: 8px;
}
.familia-empty-row {
    padding: 14px 16px;
    color: #475569;
    font-style: italic;
    font-size: 0.85rem;
    display: flex; align-items: center; gap: 8px;
}

/* Coluna de expand — tamanho fixo */
.td-expand { width: 46px; padding: 13px 8px 13px 16px !important; }

/* ================== MODAL DE DOCUMENTOS ================== */
.btn-documentos:hover { border-color: rgba(99,102,241,0.4); color: #818cf8; box-shadow: 0 0 8px rgba(99,102,241,0.15); }

.doc-item {
    background: rgba(255,255,255,0.03);
    border: 1px solid rgba(255,255,255,0.07);
    border-radius: 10px;
    padding: 14px 16px;
    margin-bottom: 12px;
}
.doc-item:last-child { margin-bottom: 0; }
.doc-item-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
}
.doc-tipo-badge {
    background: rgba(99,102,241,0.15);
    color: #818cf8;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    padding: 3px 10px;
    border-radius: 20px;
    white-space: nowrap;
}
.doc-numero { color: #e2e8f0; font-weight: 500; font-size: 0.9rem; }
.doc-fotos { display: flex; gap: 10px; flex-wrap: wrap; }
.doc-foto-thumb {
    width: 130px;
    height: 88px;
    object-fit: cover;
    border-radius: 7px;
    border: 1px solid rgba(255,255,255,0.1);
    cursor: zoom-in;
    transition: transform 0.18s, border-color 0.18s;
}
.doc-foto-thumb:hover { transform: scale(1.04); border-color: rgba(99,102,241,0.5); }
.doc-sem-foto { color: #475569; font-size: 0.82rem; font-style: italic; display: flex; align-items: center; gap: 6px; }