/* ============================================================================
 * LAYOUT — header, tabs, container, grids, sidebars, zonas
 * ========================================================================== */

/* ============================== HEADER ====================================== */
.app-header {
    position: sticky;
    top: 0;
    z-index: var(--z-header);
    background: rgba(255,255,255,0.85);
    backdrop-filter: saturate(180%) blur(16px);
    -webkit-backdrop-filter: saturate(180%) blur(16px);
    border-bottom: 1px solid var(--line-1);
    height: var(--header-h);
    display: flex;
    align-items: center;
}
[data-theme="dark"] .app-header {
    background: rgba(8, 19, 38, 0.85);
}

.app-header-inner {
    max-width: var(--container-max);
    width: 100%;
    margin: 0 auto;
    padding: 0 var(--sp-7);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--sp-6);
}

.brand {
    display: flex;
    align-items: center;
}

.brand-logo {
    height: 84px;
    width: auto;
    display: block;
    transition: opacity var(--t-fast);
}

/* Mostra o logo claro no tema light; esconde o dark */
.brand-logo-dark { display: none; }
.brand-logo-light { display: block; }

/* No tema dark: troca */
[data-theme="dark"] .brand-logo-light { display: none; }
[data-theme="dark"] .brand-logo-dark { display: block; }

.brand-text { display: flex; flex-direction: column; gap: 2px; }
.brand-name {
    font-family: var(--font-display);
    font-style: italic;
    font-weight: var(--fw-black);
    font-size: 17px;
    color: var(--navy-600);
    letter-spacing: -0.02em;
    line-height: 1;
}
[data-theme="dark"] .brand-name { color: white; }

.brand-name em {
    font-style: italic;
    color: var(--emerald-600);
    font-weight: var(--fw-black);
}

.brand-sub {
    font-size: 10.5px;
    font-weight: var(--fw-medium);
    color: var(--ink-3);
    text-transform: uppercase;
    letter-spacing: 0.10em;
}

.brand-version {
    font-size: 10px;
    color: var(--ink-4);
    background: var(--canvas-2);
    padding: 2px 8px;
    border-radius: var(--r-full);
    font-family: var(--font-mono);
    margin-left: 2px;
}

/* Header meta direita */
.header-meta {
    display: flex;
    align-items: center;
    gap: var(--sp-3);
}

.header-pill {
    display: inline-flex;
    align-items: center;
    gap: var(--sp-2);
    padding: 6px 12px;
    background: var(--canvas-2);
    border: 1px solid var(--line-1);
    border-radius: var(--r-full);
    font-size: 12px;
    font-weight: var(--fw-medium);
    color: var(--ink-2);
}

.header-pill svg { width: 14px; height: 14px; color: var(--ink-3); }
.header-pill strong { color: var(--ink-1); font-weight: var(--fw-semi); }

.theme-toggle {
    width: 38px;
    height: 38px;
    border-radius: var(--r-md);
    background: var(--canvas-2);
    border: 1px solid var(--line-1);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background var(--t-fast), color var(--t-fast), transform var(--t-fast);
    color: var(--ink-2);
}
.theme-toggle:hover { background: var(--canvas); color: var(--emerald-600); transform: rotate(15deg); }
.theme-toggle svg { width: 18px; height: 18px; }
.theme-toggle .sun { display: none; }
.theme-toggle .moon { display: block; }
[data-theme="dark"] .theme-toggle .sun { display: block; }
[data-theme="dark"] .theme-toggle .moon { display: none; }

/* ============================== TABS ======================================== */
.app-tabs {
    position: sticky;
    top: var(--header-h);
    z-index: var(--z-sticky);
    background: var(--surface);
    border-bottom: 1px solid var(--line-1);
    box-shadow: var(--shadow-xs);
}

.app-tabs-inner {
    max-width: var(--container-max);
    margin: 0 auto;
    padding: 0 var(--sp-7);
    display: flex;
    gap: 4px;
    overflow-x: auto;
    scrollbar-width: none;
}
.app-tabs-inner::-webkit-scrollbar { display: none; }

.tab {
    background: transparent;
    border: 0;
    cursor: pointer;
    padding: 0 var(--sp-5);
    height: var(--tabs-h);
    display: inline-flex;
    align-items: center;
    gap: var(--sp-2);
    font-size: 13.5px;
    font-weight: var(--fw-semi);
    color: var(--ink-3);
    border-bottom: 2.5px solid transparent;
    white-space: nowrap;
    transition: color var(--t-fast), border-color var(--t-fast), background var(--t-fast);
    position: relative;
}
.tab:hover { color: var(--navy-600); background: var(--canvas); }
[data-theme="dark"] .tab:hover { color: var(--emerald-400); background: var(--surface-elev); }

.tab.active {
    color: var(--navy-600);
    border-bottom-color: var(--emerald-500);
}
[data-theme="dark"] .tab.active { color: white; }

.tab svg { width: 16px; height: 16px; }

.tab-badge {
    display: inline-flex;
    align-items: center;
    background: var(--emerald-500);
    color: white;
    font-size: 9.5px;
    font-weight: var(--fw-bold);
    padding: 2px 7px;
    border-radius: var(--r-full);
    margin-left: 2px;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

/* ============================== MAIN ======================================== */
.main {
    max-width: var(--container-max);
    margin: 0 auto;
    padding: var(--sp-6) var(--sp-7) var(--sp-9);
}

.tab-pane { display: none; }
.tab-pane.active { display: block; animation: fadeIn var(--t-slow) ease-out; }

/* ============================== WORK AREA: SIDEBAR + DASHBOARD =============== */
.work {
    display: grid;
    grid-template-columns: var(--sidebar-w) 1fr;
    gap: var(--sp-6);
    align-items: start;
}
@media (max-width: 1280px) { .work { grid-template-columns: 1fr; } }

/* Sidebar de inputs */
.sidebar {
    position: sticky;
    top: calc(var(--header-h) + var(--tabs-h) + 16px);
    background: var(--surface);
    border: 1px solid var(--line-1);
    border-radius: var(--r-lg);
    box-shadow: var(--shadow-sm);
    max-height: calc(100vh - var(--header-h) - var(--tabs-h) - 32px);
    overflow-y: auto;
}

.sidebar-head {
    padding: var(--sp-4) var(--sp-5);
    background: var(--grad-navy);
    color: white;
    border-radius: var(--r-lg) var(--r-lg) 0 0;
    position: relative;
    overflow: hidden;
}
.sidebar-head::after {
    content: '';
    position: absolute;
    inset: 0;
    background: radial-gradient(circle at 90% -10%, rgba(34, 197, 94, 0.35) 0%, transparent 50%);
    pointer-events: none;
}

.sidebar-head h3 {
    color: white;
    font-style: italic;
    font-weight: var(--fw-black);
    font-size: 14px;
    letter-spacing: -0.01em;
    margin-bottom: 2px;
}
.sidebar-head p { color: rgba(255,255,255,0.75); font-size: 11px; margin: 0; }

.sidebar-body { padding: var(--sp-4); }

/* Dashboard à direita */
.dashboard {
    display: flex;
    flex-direction: column;
    gap: var(--sp-6);
    /* item de grid: sem isto o mínimo é o conteúdo, e a coluna empurra a página */
    min-width: 0;
}

/* ============================== TOOLBAR (acima da work area) ================ */
.toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--sp-4);
    margin-bottom: var(--sp-5);
    padding: var(--sp-4) var(--sp-5);
    background: var(--surface);
    border: 1px solid var(--line-1);
    border-radius: var(--r-lg);
    box-shadow: var(--shadow-xs);
    flex-wrap: wrap;
}

.toolbar-title {
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.toolbar-title h2 {
    font-style: italic;
    font-weight: var(--fw-black);
    color: var(--navy-600);
    font-size: 22px;
    letter-spacing: -0.02em;
}
[data-theme="dark"] .toolbar-title h2 { color: white; }
.toolbar-title p {
    font-size: 12px;
    color: var(--ink-3);
    max-width: 700px;
}

.toolbar-right { display: flex; gap: var(--sp-2); flex-wrap: wrap; }

/* ============================== GRIDS ====================================== */
.kpi-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: var(--sp-4);
}

.chart-grid-2 {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: var(--sp-5);
}
@media (max-width: 1024px) { .chart-grid-2 { grid-template-columns: 1fr; } }

.chart-grid-3 {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: var(--sp-4);
}
@media (max-width: 1280px) { .chart-grid-3 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 768px)  { .chart-grid-3 { grid-template-columns: 1fr; } }

/* ============================== FOOTER ===================================== */
.app-footer {
    background: var(--navy-700);
    color: rgba(255,255,255,0.75);
    padding: var(--sp-7) var(--sp-7) var(--sp-6);
    margin-top: var(--sp-10);
    border-top: 3px solid var(--emerald-500);
}
[data-theme="dark"] .app-footer { background: var(--navy-900); }

.app-footer-inner {
    max-width: var(--container-max);
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: var(--sp-6);
    flex-wrap: wrap;
}

.app-footer-brand {
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    font-size: 13px;
}
.app-footer-brand strong { color: white; font-style: italic; }

.app-footer-meta {
    font-size: 11px;
    line-height: 1.6;
    text-align: right;
    opacity: 0.65;
}

/* ============================== PRINT (apenas exporta painéis úteis) ======= */
@media print {
    .app-header, .app-tabs, .sidebar, .toolbar-right,
    .panel-actions, .app-footer { display: none !important; }
    .work { grid-template-columns: 1fr; gap: 0; }
    .main { padding: 0; max-width: 100%; }
    body { background: white; }
    .panel { page-break-inside: avoid; box-shadow: none; border: 1px solid #ccc; }
}
