:root {
    --bg: #f5f6f8;
    --surface: #ffffff;
    --surface-alt: #f0f1f5;
    --surface-alt-2: #f7f8fa;
    --border: #e6e8ee;
    --border-soft: #eef0f3;
    --input-border: #d5d8de;
    --text: #1c1f26;
    --text-heading-muted: #444;
    --text-label: #555;
    --text-muted: #666;
    --text-muted-2: #777;
    --text-faint: #999;
    --accent: #2c3550;
    --accent-hover: #1c2338;
    --shadow-sm: rgba(0,0,0,0.06);
    --shadow-md: rgba(0,0,0,0.08);
    --overlay-bg: rgba(255,255,255,0.7);
    --pill-bg: #eef0f5;
    --flash-ok-bg: #e3f6e8;
    --flash-ok-text: #146c2e;
    --flash-erro-bg: #fde8e8;
    --flash-erro-text: #9b1c1c;
    --kpi-up: #146c2e;
    --kpi-down: #b31c1c;
}

html[data-theme="dark"] {
    --bg: #11121a;
    --surface: #1a1c27;
    --surface-alt: #20222f;
    --surface-alt-2: #1d1f2b;
    --border: #2a2d3c;
    --border-soft: #262838;
    --input-border: #363a4d;
    --text: #e8e9ee;
    --text-heading-muted: #c3c6d4;
    --text-label: #a7abbd;
    --text-muted: #9aa0b4;
    --text-muted-2: #8b91a6;
    --text-faint: #767c92;
    --accent: #4a5580;
    --accent-hover: #5c6996;
    --shadow-sm: rgba(0,0,0,0.35);
    --shadow-md: rgba(0,0,0,0.45);
    --overlay-bg: rgba(10,11,18,0.75);
    --pill-bg: #262a3a;
    --flash-ok-bg: rgba(47,191,107,0.15);
    --flash-ok-text: #6fdb9c;
    --flash-erro-bg: rgba(255,107,107,0.15);
    --flash-erro-text: #ff9c9c;
    --kpi-up: #4ad080;
    --kpi-down: #ff6b6b;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
}

/* --- foco de inputs/selects/botoes (substitui o azul padrao do navegador) --- */

input:focus, select:focus, textarea:focus, button:focus,
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 1px var(--accent);
}

/* --- drawer (menu lateral) — sempre escuro, independe do tema da página --- */

.drawer-toggle-input { display: none; }

.drawer-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(10, 11, 18, 0.45);
    z-index: 40;
}

.drawer {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 240px;
    background: #14161f;
    color: #fff;
    display: flex;
    flex-direction: column;
    z-index: 50;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
}

.drawer-brand {
    padding: 18px 20px;
    border-bottom: 1px solid #262939;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
}

.drawer-brand .logo-mark { height: 30px; width: auto; }

.drawer-brand .brand-tagline {
    margin-left: 80px;
    color: #fff;
}

.drawer-brand-mini {
    display: none;
    height: 26px;
    width: auto;
}

.drawer-nav {
    flex: 1;
    overflow-y: auto;
    padding: 10px 0;
    display: flex;
    flex-direction: column;
}

.drawer-nav a {
    color: #b8bccb;
    text-decoration: none;
    padding: 10px 20px;
    font-size: 0.92rem;
    display: flex;
    align-items: center;
    gap: 12px;
}

.drawer-nav a:hover, .drawer-nav a.active {
    color: #fff;
    background: #1c2030;
    font-weight: 600;
}

.nav-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

.nav-icon svg { width: 18px; height: 18px; }

.drawer-section-title {
    color: #676c82;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding: 16px 20px 6px;
}

.drawer-footer {
    padding: 14px 20px;
    border-top: 1px solid #262939;
}

.drawer-user {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
    font-size: 0.85rem;
}

.drawer-user .pill {
    background: #262939;
    color: #b8bccb;
}

#drawer-toggle:checked ~ .drawer { transform: translateX(0); }
#drawer-toggle:checked ~ .drawer-backdrop { display: block; }

/* --- menu completo / só ícones (desktop, via hamburguer do topbar) ----- */

body.sidebar-collapsed .nav-label,
body.sidebar-collapsed .drawer-section-title,
body.sidebar-collapsed .drawer-brand .logo-mark,
body.sidebar-collapsed .drawer-brand .brand-tagline,
body.sidebar-collapsed .drawer-user strong,
body.sidebar-collapsed .drawer-user .pill {
    display: none;
}

body.sidebar-collapsed .drawer-brand-mini {
    display: block;
}

@media (min-width: 900px) {
    body.sidebar-collapsed .drawer { width: 64px; }
    body.sidebar-collapsed .page { margin-left: 64px; }
    body.sidebar-collapsed .drawer-brand { align-items: center; padding: 18px 0; }
    body.sidebar-collapsed .drawer-nav a { justify-content: center; padding: 12px 0; }
    body.sidebar-collapsed .drawer-user { justify-content: center; margin-bottom: 8px; }
}

.page { min-height: 100vh; }

.topbar {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 0 20px;
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    gap: 14px;
    min-height: 52px;
}

.topbar-title {
    flex: 1;
    margin: 0;
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--text);
}

.hamburger {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    cursor: pointer;
    font-size: 1.25rem;
    color: var(--accent);
    flex-shrink: 0;
}

.topbar-status {
    padding: 10px 0;
    font-size: 0.82rem;
    color: var(--text-muted-2);
}

.theme-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: var(--text-muted-2);
    cursor: pointer;
    flex-shrink: 0;
}

.theme-toggle:hover { background: var(--surface-alt); color: var(--text); }

.theme-toggle svg { width: 18px; height: 18px; }

.theme-toggle .icon-moon { display: none; }

html[data-theme="dark"] .theme-toggle .icon-sun { display: none; }
html[data-theme="dark"] .theme-toggle .icon-moon { display: block; }

@media (min-width: 900px) {
    .drawer { transform: translateX(0); }
    .drawer-backdrop { display: none !important; }
    .page { margin-left: 240px; }
}

.badge {
    display: inline-block;
    margin-left: 10px;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 0.75rem;
}

.badge-warn { background: #5a4200; color: #ffd76a; }

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 24px;
}

h1 { font-size: 1.4rem; margin-bottom: 4px; }
h2 { font-size: 1.1rem; margin-top: 28px; }
.subtitle { color: var(--text-muted); margin-top: 0; margin-bottom: 20px; font-size: 0.9rem; }

.flash-list { margin-bottom: 16px; }

.flash {
    padding: 10px 14px;
    border-radius: 6px;
    margin-bottom: 8px;
    font-size: 0.9rem;
}

.flash-ok { background: var(--flash-ok-bg); color: var(--flash-ok-text); }
.flash-erro { background: var(--flash-erro-bg); color: var(--flash-erro-text); }

.card-row {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
    margin-bottom: 24px;
}

.card {
    background: var(--surface);
    border-radius: 10px;
    padding: 16px 20px;
    box-shadow: 0 1px 3px var(--shadow-md);
    min-width: 0;
}

.card-span-2 { grid-column: span 2; }

.card-row-4 { grid-template-columns: repeat(4, 1fr); }

@media (max-width: 700px) {
    .card-row { grid-template-columns: 1fr; }
    .card-span-2 { grid-column: span 1; }
}

.card .label {
    font-size: 0.78rem;
    color: var(--text-muted-2);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.card .value {
    font-size: 1.5rem;
    font-weight: 700;
    margin-top: 4px;
}

.card .card-subtitle {
    font-size: 0.72rem;
    color: var(--text-faint);
    margin-top: 2px;
}


.filters {
    display: flex;
    gap: 12px;
    align-items: end;
    flex-wrap: wrap;
    background: var(--surface);
    padding: 14px 18px;
    border-radius: 10px;
    margin-bottom: 20px;
    box-shadow: 0 1px 3px var(--shadow-sm);
}

.filters label {
    display: flex;
    flex-direction: column;
    font-size: 0.78rem;
    color: var(--text-label);
    gap: 4px;
}

.filters input, .filters select {
    padding: 6px 8px;
    border: 1px solid var(--input-border);
    border-radius: 6px;
    font-size: 0.88rem;
    background: var(--surface);
    color: var(--text);
}

.filters button, .btn {
    background: var(--accent);
    color: #fff;
    border: none;
    padding: 8px 16px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.88rem;
    text-decoration: none;
    display: inline-block;
}

.filters button:hover, .btn:hover { background: var(--accent-hover); }

.btn-logout {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

/* --- filtros agrupados (Visão geral) ----------------------------------- */

.filters-grouped {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
}

.filters-title {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text);
}

.filter-row {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    align-items: end;
}

.filter-checkbox {
    flex-direction: row !important;
    align-items: center;
    gap: 6px !important;
    width: auto;
}

.filter-checkbox input { width: auto; }

.filters-apply { margin-left: auto; }

/* --- login (sempre no visual escuro/claro fixo, não segue o tema) ------ */

.login-body {
    margin: 0;
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #14161f;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
}

.login-box {
    background: #fff;
    padding: 32px;
    border-radius: 12px;
    width: 100%;
    max-width: 360px;
    box-shadow: 0 8px 30px rgba(0,0,0,0.3);
}

.login-brand {
    margin: 0 auto 20px auto;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
    width: fit-content;
}

.login-brand .logo-mark { height: 30px; width: auto; }

.login-brand .brand-tagline {
    margin-left: 80px;
    color: #14161f;
}

.brand-tagline {
    font-weight: 700;
    font-style: italic;
    font-size: 0.9rem;
}

.brand-dot { color: #ffa14d; }

.login-box form {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.login-box label {
    display: flex;
    flex-direction: column;
    font-size: 0.82rem;
    color: #555;
    gap: 4px;
}

.login-box input {
    padding: 8px 10px;
    border: 1px solid #d5d8de;
    border-radius: 6px;
    font-size: 0.92rem;
}

.login-box button { margin-top: 6px; }

table {
    width: 100%;
    border-collapse: collapse;
    background: var(--surface);
    border-radius: 10px;
    overflow: hidden;
    box-shadow: 0 1px 3px var(--shadow-sm);
}

th, td {
    padding: 10px 14px;
    text-align: right;
    border-bottom: 1px solid var(--border-soft);
    font-size: 0.88rem;
    white-space: nowrap;
}

th:first-child, td:first-child { text-align: left; }

.sort-link { color: inherit; text-decoration: none; }
.sort-link:hover { text-decoration: underline; }

/* --- resumo --------------------------------------------------------- */

.kpi-variacao {
    margin-top: 6px;
    font-size: 0.82rem;
    font-weight: 600;
}

.kpi-up { color: var(--kpi-up); }
.kpi-down { color: var(--kpi-down); }

.chart-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
    margin-bottom: 24px;
}

.chart-box {
    background: var(--surface);
    border-radius: 10px;
    padding: 16px 20px;
    box-shadow: 0 1px 3px var(--shadow-md);
}

.chart-title {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-heading-muted);
    margin-bottom: 10px;
}

.chart-box-full {
    margin-bottom: 16px;
}

.chart-box-full canvas, .chart-box canvas {
    height: 220px !important;
}

/* --- overlay de carregamento -------------------------------------------- */

.loading-overlay {
    position: fixed;
    inset: 0;
    background: var(--overlay-bg);
    z-index: 999;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s ease;
}

.loading-overlay.active {
    opacity: 1;
    pointer-events: all;
}

.spinner {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 4px solid var(--border-soft);
    border-top-color: var(--accent);
    animation: girar 0.7s linear infinite;
}

@keyframes girar {
    to { transform: rotate(360deg); }
}

.pizza-wrap {
    display: flex;
    align-items: center;
    gap: 20px;
}

.chart-box-pizza canvas {
    height: 150px !important;
    width: 150px !important;
    max-width: 150px;
    flex-shrink: 0;
}

.pizza-legend {
    flex: 1;
    min-width: 0;
}

.pizza-legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
    font-size: 0.82rem;
    color: var(--text-heading-muted);
}

.pizza-legend-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.pizza-legend-nome {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.pizza-legend-pct {
    color: var(--text-faint);
    flex-shrink: 0;
    font-variant-numeric: tabular-nums;
}

@media (max-width: 480px) {
    .pizza-wrap { flex-direction: column; align-items: stretch; }
}

@media (max-width: 720px) {
    .chart-grid { grid-template-columns: 1fr; }
}

th {
    background: var(--surface-alt);
    font-weight: 600;
    color: var(--text-heading-muted);
    position: sticky;
    top: 0;
}

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

tfoot td {
    font-weight: 700;
    background: var(--surface-alt-2);
}

.neg { color: var(--kpi-down); }
.pos { color: var(--kpi-up); }

.pill {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    background: var(--pill-bg);
    font-size: 0.75rem;
    color: var(--text-heading-muted);
}

.table-wrap { overflow-x: auto; }

form.inline { display: inline; }

.assoc-form {
    display: flex;
    gap: 6px;
    align-items: center;
    justify-content: flex-end;
}

.assoc-form select {
    padding: 4px 6px;
    border: 1px solid var(--input-border);
    border-radius: 5px;
    font-size: 0.82rem;
    background: var(--surface);
    color: var(--text);
}

.assoc-form button {
    padding: 4px 10px;
    font-size: 0.8rem;
}

.pagination {
    margin-top: 16px;
    display: flex;
    gap: 8px;
    align-items: center;
    font-size: 0.85rem;
}

.pagination a { color: var(--accent); text-decoration: none; }

.upload-box {
    background: var(--surface);
    padding: 20px;
    border-radius: 10px;
    box-shadow: 0 1px 3px var(--shadow-sm);
    margin-bottom: 24px;
}

.helptext { color: var(--text-muted-2); font-size: 0.85rem; margin-top: 6px; }

.empty-state {
    background: var(--surface);
    padding: 40px;
    text-align: center;
    border-radius: 10px;
    color: var(--text-muted-2);
}
