:root { color-scheme: light; }
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

.viz-root {
  color-scheme: light;
  --brand:          #1F5C3B;
  --brand-dark:     #143e28;
  --surface-1:      #fcfcfb;
  --page:           #f2f3f0;
  --text-primary:   #0b0b0b;
  --text-secondary: #52514e;
  --muted:          #898781;
  --gridline:       #e1e0d9;
  --baseline:       #c3c2b7;
  --border:         rgba(11,11,11,0.10);
  --series-1:       #2a78d6;
  --series-2:       #eb6834;
  --status-good:    #0ca30c;
  --status-warning: #fab219;
  --status-serious: #ec835a;
  --status-critical:#d03b3b;
  --success-text:   #006300;
  --card-shadow: 0 1px 2px rgba(11,11,11,0.06), 0 1px 1px rgba(11,11,11,0.04);
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) .viz-root {
    color-scheme: dark;
    --surface-1: #1a1a19; --page: #0d0d0d; --text-primary: #ffffff; --text-secondary: #c3c2b7;
    --muted: #898781; --gridline: #2c2c2a; --baseline: #383835; --border: rgba(255,255,255,0.10);
    --series-1: #3987e5; --series-2: #d95926; --success-text: #0ca30c;
    --card-shadow: 0 1px 2px rgba(0,0,0,0.4), 0 1px 1px rgba(0,0,0,0.3);
  }
}
:root[data-theme="dark"] .viz-root {
  color-scheme: dark;
  --surface-1: #1a1a19; --page: #0d0d0d; --text-primary: #ffffff; --text-secondary: #c3c2b7;
  --muted: #898781; --gridline: #2c2c2a; --baseline: #383835; --border: rgba(255,255,255,0.10);
  --series-1: #3987e5; --series-2: #d95926; --success-text: #0ca30c;
  --card-shadow: 0 1px 2px rgba(0,0,0,0.4), 0 1px 1px rgba(0,0,0,0.3);
}

body { font-family: system-ui, -apple-system, "Segoe UI", sans-serif; background: var(--page); color: var(--text-primary); }
.viz-root { min-height: 100vh; padding-bottom: 30px; }
a { color: var(--series-1); }

/* ---------- header / nav ---------- */
header.top {
  background: linear-gradient(120deg, var(--brand), var(--brand-dark));
  color: #fff; padding: 14px 28px; display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: 12px; row-gap: 10px;
}
header.top h1 { font-size: 18px; margin: 0 0 2px 0; font-weight: 700; }
header.top p { margin: 0; font-size: 12px; opacity: 0.88; }
.top-nav { display: flex; gap: 4px; flex-wrap: wrap; }
.top-nav a {
  color: #fff; text-decoration: none; font-size: 13px; padding: 7px 12px; border-radius: 7px;
  background: rgba(255,255,255,0.08); border: 1px solid transparent;
}
.top-nav a:hover { background: rgba(255,255,255,0.18); }
.top-nav a.active { background: rgba(255,255,255,0.22); border-color: rgba(255,255,255,0.35); font-weight: 600; }
.top-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.user-chip { font-size: 12px; background: rgba(255,255,255,0.14); padding: 6px 10px; border-radius: 999px; }
.user-chip small { opacity: 0.8; }
.theme-toggle {
  background: rgba(255,255,255,0.14); border: 1px solid rgba(255,255,255,0.3); color: #fff;
  border-radius: 999px; padding: 6px 12px; font-size: 12px; cursor: pointer; font-family: inherit; text-decoration: none;
}
.theme-toggle:hover { background: rgba(255,255,255,0.24); }

main { max-width: 1440px; margin: 0 auto; padding: 20px 24px 0 24px; }

.section-title {
  font-size: 12.5px; font-weight: 700; color: var(--text-secondary); text-transform: uppercase;
  letter-spacing: 0.04em; margin: 26px 0 10px 2px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
}
.section-title .hint { font-weight: 400; text-transform: none; letter-spacing: normal; font-size: 11.5px; color: var(--muted); }

/* ---------- flash messages ---------- */
.flash { padding: 10px 16px; border-radius: 8px; font-size: 13px; margin: 14px 0; border: 1px solid var(--border); }
.flash-sucesso { background: color-mix(in srgb, var(--status-good) 14%, transparent); color: var(--success-text); }
.flash-erro { background: color-mix(in srgb, var(--status-critical) 12%, transparent); color: var(--status-critical); }
.flash-info { background: color-mix(in srgb, var(--series-1) 12%, transparent); color: var(--series-1); }

/* ---------- cards / panels ---------- */
.panel {
  background: var(--surface-1); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: var(--card-shadow); padding: 16px;
}

/* ---------- filter row ---------- */
.filter-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; background: var(--surface-1); border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px; box-shadow: var(--card-shadow); }
.filter-field { display: flex; flex-direction: column; gap: 4px; min-width: 150px; }
.filter-field label { font-size: 11px; font-weight: 600; color: var(--text-secondary); }
.filter-scope-note { font-size: 11px; color: var(--muted); margin-left: auto; align-self: center; max-width: 320px; text-align: right; }

/* ---------- forms ---------- */
input, select, textarea, button {
  font-family: inherit; font-size: 13px; color: var(--text-primary); background: var(--surface-1);
}
input[type=text], input[type=email], input[type=password], input[type=date], input[type=number], select, textarea {
  padding: 8px 10px; border-radius: 6px; border: 1px solid var(--baseline); width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--series-1); outline-offset: 1px; }
label { font-size: 11.5px; font-weight: 600; color: var(--text-secondary); display: block; margin-bottom: 4px; }
.form-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
@media (max-width: 800px) { .form-grid { grid-template-columns: 1fr 1fr; } }
@media (max-width: 520px) { .form-grid { grid-template-columns: 1fr; } }
.form-field { display: flex; flex-direction: column; gap: 4px; }
.form-field.span-2 { grid-column: span 2; }
.form-field.span-3 { grid-column: 1 / -1; }
.form-actions { display: flex; gap: 10px; margin-top: 16px; align-items: center; }
.help-text { font-size: 11px; color: var(--muted); margin-top: 2px; }

button, .btn {
  cursor: pointer; border-radius: 7px; padding: 9px 16px; font-size: 13px; font-weight: 600;
  border: 1px solid var(--baseline); background: var(--surface-1); color: var(--text-primary); text-decoration: none; display: inline-block;
}
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); }
.btn-danger { background: transparent; border-color: var(--status-critical); color: var(--status-critical); }
.btn-danger:hover { background: color-mix(in srgb, var(--status-critical) 12%, transparent); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
button:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---------- tables ---------- */
.table-card { background: var(--surface-1); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--card-shadow); padding: 14px 16px; overflow-x: auto; }
table.data-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
table.data-table th { text-align: left; font-weight: 700; color: var(--text-secondary); font-size: 11px; text-transform: uppercase; letter-spacing: 0.02em; padding: 8px 10px; border-bottom: 2px solid var(--baseline); white-space: nowrap; }
table.data-table th.sortable { cursor: pointer; user-select: none; }
table.data-table th.sortable:hover { color: var(--text-primary); }
table.data-table td { padding: 8px 10px; border-bottom: 1px solid var(--gridline); white-space: nowrap; font-variant-numeric: tabular-nums; }
table.data-table td.num { text-align: right; }
table.data-table tbody tr:hover { background: var(--page); }
.row-actions { display: flex; gap: 6px; }
.empty-state { text-align: center; padding: 30px; color: var(--muted); font-size: 13px; }
.pagination { display: flex; gap: 6px; justify-content: center; margin-top: 14px; flex-wrap: wrap; }
.pagination a, .pagination span { padding: 6px 11px; border-radius: 6px; border: 1px solid var(--baseline); font-size: 12.5px; text-decoration: none; color: var(--text-primary); }
.pagination a:hover { background: var(--page); }
.pagination .current { background: var(--brand); border-color: var(--brand); color: #fff; }

.status-pill { display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; font-weight: 600; padding: 4px 10px; border-radius: 999px; }
.status-good { background: color-mix(in srgb, var(--status-good) 16%, transparent); color: var(--status-good); }
.status-warning { background: color-mix(in srgb, var(--status-warning) 55%, transparent); color: #7a4f00; }
.status-critical { background: color-mix(in srgb, var(--status-critical) 16%, transparent); color: var(--status-critical); }
.status-neutral { background: color-mix(in srgb, var(--series-1) 16%, transparent); color: var(--series-1); }
.pct-cell { display: flex; align-items: center; gap: 6px; }
.pct-track { width: 54px; height: 7px; background: var(--gridline); border-radius: 4px; overflow: hidden; }
.pct-fill { height: 100%; background: var(--brand); }

/* ---------- KPI grid ---------- */
.kpi-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; }
@media (max-width: 1100px) { .kpi-grid { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 680px) { .kpi-grid { grid-template-columns: repeat(2, 1fr); } }
.kpi-card { background: var(--surface-1); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--card-shadow); overflow: hidden; display: flex; flex-direction: column; }
.kpi-card .kpi-label { background: var(--brand); color: #fff; font-size: 10.5px; font-weight: 700; padding: 8px 10px; text-align: center; min-height: 30px; display: flex; align-items: center; justify-content: center; line-height: 1.25; }
.kpi-card .kpi-value { font-size: 21px; font-weight: 700; color: var(--brand); text-align: center; padding: 14px 8px; }
.kpi-card.alt .kpi-value { color: var(--series-1); }
.kpi-card .kpi-note { font-size: 9.5px; color: var(--muted); text-align: center; padding: 0 8px 10px; }

/* ---------- legend / chart cards ---------- */
.legend-row { display: flex; flex-wrap: wrap; gap: 14px; margin: 12px 2px 0; }
.legend-chip { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-secondary); }
.legend-chip .swatch { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.chart-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 980px) { .chart-grid { grid-template-columns: 1fr; } }
.chart-card { background: var(--surface-1); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--card-shadow); padding: 14px 16px 10px; }
.chart-card .chart-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
.chart-card h3 { font-size: 13.5px; margin: 0; font-weight: 700; }
.chart-card .chart-sub { font-size: 11px; color: var(--muted); margin-top: 2px; }
.table-toggle { font-family: inherit; font-size: 11px; padding: 5px 9px; border-radius: 6px; cursor: pointer; border: 1px solid var(--baseline); background: transparent; color: var(--text-secondary); white-space: nowrap; }
.table-toggle:hover { background: var(--gridline); }
.chart-canvas-wrap { position: relative; height: 260px; }
.chart-canvas-wrap.tall { height: 300px; }
.chart-svg-el { width: 100%; height: 100%; }
.chart-svg-el svg { display: block; overflow: visible; }
.chart-svg-el .bar-mark { cursor: pointer; transition: opacity .1s; }
.chart-svg-el .bar-mark:hover, .chart-svg-el .bar-mark:focus { opacity: 0.82; outline: none; }
.chart-svg-el .axis-text { fill: var(--muted); font-size: 10px; font-family: inherit; }
.chart-svg-el .grid-line { stroke: var(--gridline); stroke-width: 1; }
.chart-svg-el .value-label { fill: var(--text-secondary); font-size: 9.5px; font-variant-numeric: tabular-nums; }
.chart-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.chart-table th, .chart-table td { padding: 5px 8px; border-bottom: 1px solid var(--gridline); text-align: right; }
.chart-table th:first-child, .chart-table td:first-child { text-align: left; }

.viz-tooltip {
  position: fixed; z-index: 2000; pointer-events: none; background: var(--surface-1); border: 1px solid var(--border);
  border-radius: 7px; padding: 8px 11px; font-size: 12px; box-shadow: 0 4px 14px rgba(0,0,0,0.18);
  color: var(--text-primary); max-width: 240px; transform: translate(-50%, -112%);
}
.viz-tooltip .tt-title { font-size: 10.5px; color: var(--text-secondary); margin-bottom: 3px; font-weight: 600; }
.viz-tooltip .tt-row { display: flex; align-items: center; gap: 6px; }
.viz-tooltip .tt-key { display: inline-block; width: 10px; height: 3px; border-radius: 2px; flex: none; }
.viz-tooltip .tt-value { font-weight: 700; }
.viz-tooltip .tt-name { color: var(--text-secondary); font-size: 11.5px; }

/* ---------- drilldown ---------- */
.drilldown { background: var(--surface-1); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--card-shadow); padding: 16px; display: grid; grid-template-columns: 260px 1fr; gap: 20px; }
@media (max-width: 820px) { .drilldown { grid-template-columns: 1fr; } }
.dd-card { background: var(--page); border: 1px solid var(--border); border-radius: 8px; padding: 10px; text-align: center; }
.dd-card .dd-label { font-size: 9.5px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.03em; margin-bottom: 4px; }
.dd-card .dd-value { font-size: 15.5px; font-weight: 700; }
.drilldown-cards { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
@media (max-width: 620px) { .drilldown-cards { grid-template-columns: repeat(2, 1fr); } }
.dd-progress { grid-column: 1 / -1; }
.dd-progress-track { height: 10px; background: var(--gridline); border-radius: 6px; overflow: hidden; }
.dd-progress-fill { height: 100%; background: var(--brand); }
.dd-progress-label { font-size: 11px; color: var(--text-secondary); margin-top: 4px; }

footer.foot { max-width: 1440px; margin: 30px auto 0; padding: 16px 24px 30px; color: var(--muted); font-size: 11.5px; border-top: 1px solid var(--gridline); }

/* ---------- login page ---------- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--page); }
.login-box { background: var(--surface-1); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--card-shadow); padding: 32px; width: 340px; }
.login-box h1 { font-size: 16px; margin: 0 0 4px; color: var(--brand); }
.login-box p.sub { font-size: 12px; color: var(--muted); margin: 0 0 20px; }
.login-box .form-field { margin-bottom: 14px; }
.login-box button { width: 100%; margin-top: 6px; }
