/* ==========================================================================
   BI BALANÇAS - MONITORING SP (DER-SP)
   Design System Global & Folha de Estilo Responsiva
   ========================================================================== */

/* 1. VARIÁVEIS DE DESIGN & TOKENS */
:root {
    /* Cores Institucionais DER-SP */
    --primary: #09090b;
    --primary-dark: #09090b;       /* Sidebar e Navbar background */
    --primary-surface: #18181b;    /* Superfícies de suporte escuras */
    --accent-yellow: #FFCC00;      /* Amarelo Institucional DER */
    --accent-yellow-hover: #e6b800;
    --accent-yellow-subtle: rgba(255, 204, 0, 0.12);

    /* Palette de Indicadores (KPIs) */
    --accent-blue: #2563eb;
    --accent-blue-subtle: #dbeafe;
    --accent-orange: #f59e0b;
    --accent-orange-subtle: #fef3c7;
    --accent-red: #ef4444;
    --accent-red-subtle: #fee2e2;
    --accent-green: #10b981;
    --accent-green-subtle: #d1fae5;

    /* Superfícies e Textos (Light Mode por Padrão) */
    --bg-body: #f4f4f5;
    --bg-card: #ffffff;
    --bg-card-hover: #fafafa;
    --text-main: #18181b;
    --text-muted: #71717a;
    --text-subtle: #a1a1aa;
    --border-color: #e4e4e7;
    --border-subtle: #f4f4f5;

    /* Sombras e Elevação */
    --shadow-xs: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-sm: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px -1px rgba(0, 0, 0, 0.1);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1);

    /* Dimensões */
    --navbar-height: 60px;
    --sidebar-width: 260px;
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-full: 9999px;
    --transition-fast: 0.15s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-normal: 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

/* 2. RESET & BASE */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-body);
    color: var(--text-main);
    line-height: 1.5;
    overflow-x: hidden;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Scrollbar Personalizada */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}
::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.05);
}
::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.2);
    border-radius: var(--radius-full);
}
::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.35);
}

/* 3. LAYOUT GLOBAL */
/* Navbar Governamental */
.gov-navbar {
    background-color: var(--primary-dark);
    color: #ffffff;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 1.5rem;
    height: var(--navbar-height);
    width: 100%;
    position: fixed;
    top: 0;
    left: 0;
    z-index: 1000;
    box-shadow: var(--shadow-md);
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.nav-brand {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.brand-title {
    margin: 0;
    font-size: 1.15rem;
    font-weight: 800;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: #ffffff;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.brand-badge {
    background: var(--accent-yellow);
    color: var(--primary-dark);
    font-size: 0.65rem;
    font-weight: 800;
    padding: 2px 6px;
    border-radius: var(--radius-sm);
    letter-spacing: 0.05em;
}

.gov-navbar-right {
    display: flex;
    align-items: center;
    gap: 1.25rem;
}

.der-logo {
    height: 38px;
    width: auto;
    object-fit: contain;
    transition: transform var(--transition-fast);
}

.sp-logo {
    height: 42px;
    width: auto;
    object-fit: contain;
}

.gov-navbar-text {
    text-align: right;
    line-height: 1.15;
}

.title-sec {
    font-size: 0.75rem;
    color: rgba(255, 255, 255, 0.7);
}

.subtitle-sec {
    font-size: 0.875rem;
    font-weight: 700;
    color: #ffffff;
}

/* Hamburger & Botões Touch */
.hamburger-btn {
    background: transparent;
    border: none;
    color: #ffffff;
    cursor: pointer;
    width: 42px;
    height: 42px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color var(--transition-fast);
    outline: none;
    -webkit-tap-highlight-color: transparent;
}

.hamburger-btn:hover, .hamburger-btn:focus-visible {
    background: rgba(255, 255, 255, 0.12);
}

/* Sidebar Lateral */
.sidebar {
    width: var(--sidebar-width);
    background: var(--primary-dark);
    color: #ffffff;
    height: calc(100vh - var(--navbar-height));
    position: fixed;
    top: var(--navbar-height);
    left: 0;
    display: flex;
    flex-direction: column;
    z-index: 990;
    transition: transform var(--transition-normal);
    overflow-y: auto;
    border-right: 1px solid rgba(255, 255, 255, 0.08);
}

.nav-links {
    list-style: none;
    padding: 1rem 0;
    margin: 0;
    flex-grow: 1;
}

.sidebar-section-title {
    padding: 1rem 1.5rem 0.35rem 1.5rem;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: rgba(255, 255, 255, 0.4);
}

.nav-item {
    padding: 0.75rem 1.5rem;
    min-height: 44px;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    color: rgba(255, 255, 255, 0.65);
    text-decoration: none;
    font-size: 0.875rem;
    font-weight: 500;
    border-left: 4px solid transparent;
    transition: all var(--transition-fast);
    -webkit-tap-highlight-color: transparent;
}

.nav-item:hover, .nav-item:focus-visible {
    color: #ffffff;
    background: rgba(255, 255, 255, 0.06);
}

.nav-item.active {
    background: var(--accent-yellow-subtle);
    color: var(--accent-yellow);
    border-left-color: var(--accent-yellow);
    font-weight: 700;
}

.nav-item i {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

/* Sidebar Backdrop (Mobile Overlay) */
.sidebar-backdrop {
    display: none;
    position: fixed;
    top: var(--navbar-height);
    left: 0;
    width: 100vw;
    height: calc(100vh - var(--navbar-height));
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 980;
    opacity: 0;
    transition: opacity var(--transition-normal);
    pointer-events: none;
}

body.mobile-sidebar-open .sidebar-backdrop {
    display: block;
    opacity: 1;
    pointer-events: auto;
}

/* Desktop Sidebar Collapse */
body.sidebar-collapsed .sidebar {
    transform: translateX(-100%);
}
body.sidebar-collapsed .main-content {
    margin-left: 0;
    width: 100%;
}

/* Conteúdo Principal */
.main-content {
    margin-left: var(--sidebar-width);
    margin-top: var(--navbar-height);
    padding: clamp(1.25rem, 2.5vw, 2.25rem);
    width: calc(100% - var(--sidebar-width));
    min-height: calc(100vh - var(--navbar-height));
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    transition: margin-left var(--transition-normal), width var(--transition-normal);
}

.content-wrapper {
    flex: 1;
}

/* Rodapé */
.footer {
    margin-top: 2.5rem;
    padding-top: 1.25rem;
    border-top: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.75rem;
}

.footer-text {
    font-size: 0.8125rem;
    color: var(--text-muted);
    font-weight: 500;
}

/* 4. COMPONENTES UI REUTILIZÁVEIS */
/* Cabeçalho da Página */
.page-header {
    margin-bottom: 1.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.page-header-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 1rem;
}

.page-title {
    font-size: clamp(1.35rem, 2.5vw, 1.85rem);
    font-weight: 800;
    color: var(--text-main);
    letter-spacing: -0.02em;
    line-height: 1.2;
}

.update-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--text-muted);
    background: var(--bg-card);
    padding: 0.4rem 0.85rem;
    border-radius: var(--radius-full);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-xs);
}

.update-badge-date {
    color: var(--accent-blue);
    font-weight: 700;
}

/* Painel de Filtros Responsivo */
.filter-panel {
    background: var(--bg-card);
    padding: 1.15rem 1.5rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-wrap: wrap;
    gap: 1.25rem;
    align-items: flex-end;
    margin-bottom: 1.75rem;
}

.filter-item {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    flex: 1 1 200px;
    min-width: 160px;
}

.filter-item label {
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.form-select, select {
    width: 100%;
    padding: 0.6rem 0.85rem;
    min-height: 42px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background-color: var(--bg-card);
    color: var(--text-main);
    font-size: 0.875rem;
    font-weight: 600;
    outline: none;
    cursor: pointer;
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.form-select:hover, select:hover {
    border-color: #cbd5e1;
}

.form-select:focus, select:focus {
    border-color: var(--accent-blue);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

/* Cards de KPI (Grid Fluido) */
.grid-kpi {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1.25rem;
    margin-bottom: 1.75rem;
}

.kpi-card {
    background: var(--bg-card);
    padding: 1.25rem 1.5rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: 0.75rem;
    border-top: 4px solid var(--border-color);
    transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}

.kpi-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.kpi-card.blue { border-top-color: var(--accent-blue); }
.kpi-card.orange { border-top-color: var(--accent-orange); }
.kpi-card.purple { border-top-color: #8b5cf6; }
.kpi-card.red { border-top-color: var(--accent-red); }
.kpi-card.yellow { border-top-color: var(--accent-yellow); }

.kpi-title {
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.kpi-value {
    font-size: clamp(1.65rem, 3.5vw, 2.25rem);
    font-weight: 800;
    color: var(--text-main);
    line-height: 1.1;
    letter-spacing: -0.03em;
}

/* Seção Raio-X (Mini KPIs) */
.audit-section {
    background: #ffffff;
    padding: 1.25rem 1.5rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
    margin-bottom: 1.75rem;
}

.audit-header {
    margin-bottom: 1rem;
    font-size: 0.8125rem;
    font-weight: 800;
    color: var(--text-main);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-bottom: 2px solid var(--bg-body);
    padding-bottom: 0.6rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.grid-mini-kpi {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
    gap: 1rem;
}

.mini-kpi-card {
    background: var(--bg-body);
    padding: 0.85rem 1rem;
    border-radius: var(--radius-sm);
    border-left: 4px solid var(--accent-orange);
    text-align: center;
    transition: transform var(--transition-fast);
}

.mini-kpi-card:hover {
    transform: translateY(-1px);
}

.mini-title {
    font-size: 0.6875rem;
    color: var(--text-muted);
    font-weight: 700;
    display: block;
    margin-bottom: 0.25rem;
    text-transform: uppercase;
}

.mini-value {
    font-size: 1.25rem;
    color: var(--accent-orange);
    font-weight: 800;
    display: block;
    line-height: 1.1;
}

/* Gráficos Responsivos */
.charts-grid {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 1.25rem;
    margin-bottom: 1.75rem;
}

.chart-card {
    background: var(--bg-card);
    padding: 1.25rem 1.5rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-direction: column;
    margin-bottom: 1.75rem;
    height: auto;
    min-height: auto;
}

.chart-title {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text-main);
    margin-top: 0;
    margin-bottom: 1rem;
    border-bottom: 1px solid var(--border-subtle);
    padding-bottom: 0.65rem;
}

.chart-container, .chart-canvas-wrapper {
    position: relative;
    width: 100%;
    height: 320px;
    flex: 1;
}

.chart-container-sm {
    position: relative;
    width: 100%;
    height: 175px;
    flex: 1;
}

/* Flex Container para múltiplas pizzas lado a lado */
.pie-charts-wrapper {
    display: flex;
    flex-wrap: wrap;
    gap: 1.25rem;
    justify-content: center;
    align-items: stretch;
    width: 100%;
    margin-top: 0.5rem;
}

.pie-chart-box {
    flex: 1 1 240px;
    max-width: 360px;
    min-width: 220px;
    background: #fafafa;
    border: 1px solid var(--border-color);
    padding: 1rem;
    border-radius: var(--radius-sm);
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* Tabelas Responsivas */
.table-card {
    background: var(--bg-card);
    padding: 1.25rem 1.5rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
    margin-bottom: 1.75rem;
}

.table-responsive {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: var(--radius-sm);
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
    text-align: left;
    white-space: nowrap;
}

.data-table th {
    padding: 0.85rem 1rem;
    background-color: var(--bg-body);
    border-bottom: 2px solid var(--border-color);
    color: var(--text-muted);
    font-weight: 700;
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 0.04em;
}

.data-table td {
    padding: 0.85rem 1rem;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-main);
}

.data-table tbody tr:hover {
    background-color: var(--bg-card-hover);
}

.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.25rem 0.6rem;
    border-radius: var(--radius-full);
    font-size: 0.75rem;
    font-weight: 700;
}

.badge-alert {
    background: var(--accent-red-subtle);
    color: #b91c1c;
}

.badge-success {
    background: var(--accent-green-subtle);
    color: #047857;
}

/* 5. MEDIA QUERIES & RESPONSIVIDADE MOBILE */
@media (max-width: 1024px) {
    .charts-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    /* Navbar e Logos no Mobile */
    .gov-navbar {
        padding: 0 1rem;
    }
    
    .gov-navbar-text {
        display: none;
    }
    
    .sp-logo {
        height: 32px;
    }
    
    .der-logo {
        height: 28px;
    }
    
    .brand-title {
        font-size: 1rem;
    }

    /* Sidebar Mobile Drawer */
    .sidebar {
        transform: translateX(-100%);
        box-shadow: var(--shadow-lg);
        width: 280px;
    }
    
    body.mobile-sidebar-open .sidebar {
        transform: translateX(0);
    }
    
    .main-content {
        margin-left: 0 !important;
        width: 100% !important;
        padding: 1.15rem 0.85rem;
    }
    
    /* Filtros e Grids no Mobile */
    .filter-panel {
        padding: 1rem;
        gap: 0.85rem;
    }
    
    .filter-item {
        flex: 1 1 100%;
        min-width: 100%;
    }
    
    .grid-kpi {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.75rem;
    }

    .kpi-card {
        padding: 1rem;
    }

    .kpi-value {
        font-size: 1.5rem;
    }
    
    .grid-mini-kpi {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.65rem;
    }

    .mini-kpi-card {
        padding: 0.65rem;
    }
    
    .chart-card {
        padding: 0.85rem 0.65rem;
        width: 100%;
        box-sizing: border-box;
    }

    .chart-container, .chart-canvas-wrapper, .chart-box {
        width: 100% !important;
        max-width: 100% !important;
        height: 230px !important;
        max-height: 260px !important;
        box-sizing: border-box;
        margin: 0;
    }

    canvas {
        max-width: 100% !important;
    }

    .pie-chart-box {
        flex: 1 1 100%;
        max-width: 100%;
        width: 100%;
        box-sizing: border-box;
    }

    .table-card {
        padding: 0.85rem 0.65rem;
    }
}

@media (max-width: 480px) {
    /* Ajustes específicos para smartphones estreitos (< 480px) */
    .chart-container, .chart-canvas-wrapper, .chart-box {
        height: 210px !important;
        max-height: 230px !important;
        width: 100% !important;
        max-width: 100% !important;
    }

    .grid-kpi {
        grid-template-columns: 1fr;
    }

    .grid-mini-kpi {
        grid-template-columns: repeat(2, 1fr);
    }

    .page-title {
        font-size: 1.35rem;
    }

    .brand-badge {
        display: none;
    }
}
