:root {
  color-scheme: light;
  --surface-1: #fcfcfb;
  --page: #f9f9f7;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --gridline: #e1e0d9;
  --baseline: #c3c2b7;
  --border: rgba(11, 11, 11, 0.1);
  --series-1: #2a78d6;
  --series-1-soft: #cde2fb;
  --good: #006300;
  --critical: #d03b3b;
  --warning: #fab219;
  --warning-bg: #fdf3dc;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --surface-1: #1a1a19;
    --page: #0d0d0d;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --gridline: #2c2c2a;
    --baseline: #383835;
    --border: rgba(255, 255, 255, 0.1);
    --series-1: #3987e5;
    --series-1-soft: #184f95;
    --good: #0ca30c;
    --critical: #e66767;
    --warning: #fab219;
    --warning-bg: #3a2f10;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--page);
  color: var(--text-primary);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

.wrap {
  max-width: 1180px;
  margin: 0 auto;
  padding: 24px 20px 64px;
}

.account-bar {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 16px;
  padding: 8px 0;
  margin-bottom: 8px;
  font-size: 13px;
  color: var(--text-secondary);
}

.account-bar a {
  color: var(--series-1);
  text-decoration: none;
  font-weight: 600;
}

.account-bar a:hover {
  text-decoration: underline;
}

/* Auth pages (login / denied) */
.auth-wrap {
  min-height: calc(100vh - 88px);
  display: flex;
  align-items: center;
  justify-content: center;
}

.auth-card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 40px 36px;
  max-width: 420px;
  width: 100%;
  text-align: center;
}

.auth-title {
  font-size: 24px;
  margin: 0 0 20px;
}

.auth-msg {
  color: var(--text-secondary);
  margin: 0 0 24px;
  line-height: 1.6;
}

.auth-msg.err {
  color: var(--critical);
}

header.top {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 28px;
}

header.top h1 {
  font-size: 28px;
  margin: 0 0 4px;
}

header.top p.subtitle {
  margin: 0;
  color: var(--text-secondary);
}

.sync-box {
  display: flex;
  align-items: center;
  gap: 10px;
}

.sync-box .last-sync {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text-primary);
  font-size: 15px;
  font-weight: 600;
}

.sync-box .last-sync .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--good);
  flex-shrink: 0;
}

.btn {
  font: inherit;
  font-weight: 600;
  background: var(--series-1);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 10px 16px;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
}

.btn:hover { filter: brightness(1.08); }
.btn:disabled { opacity: 0.6; cursor: default; }

.btn.secondary {
  background: transparent;
  color: var(--series-1);
  border: 1px solid var(--series-1);
}

/* KPI stat tiles */
.kpi-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 32px;
}

.kpi-tile {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px 22px;
}

.kpi-tile .label {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.kpi-tile .value {
  font-size: 40px;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.kpi-tile .delta {
  margin-top: 6px;
  font-size: 14px;
  font-weight: 600;
}

.delta.up-bad { color: var(--critical); }
.delta.down-good { color: var(--good); }
.delta.neutral { color: var(--text-muted); }

/* KPI sparklines */
.sparkline {
  margin-top: 12px;
  height: 32px;
}

.sparkline.empty {
  visibility: hidden;
}

.sparkline-svg {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.sparkline-line {
  fill: none;
  stroke: var(--text-muted);
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: 0.85;
}

.sparkline-dot {
  fill: var(--series-1);
}

/* Sections */
section.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 22px 24px;
  margin-bottom: 28px;
}

section.card h2 {
  font-size: 18px;
  margin: 0 0 4px;
}

section.card p.hint {
  margin: 0 0 16px;
  color: var(--text-secondary);
  font-size: 13px;
}

.chart-holder {
  position: relative;
  height: 320px;
}

.ranking-holder {
  height: 420px;
}

/* Shared tooltip (map + line chart) */
.chart-tooltip {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: none;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 12px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.14);
  opacity: 0;
  transform: translate(-50%, calc(-100% - 12px));
  transition: opacity 0.1s ease;
  white-space: nowrap;
  z-index: 5;
}

.chart-tooltip.visible {
  opacity: 1;
}

.chart-tooltip .tt-label {
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 2px;
}

.chart-tooltip .tt-value {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary);
}

.chart-tooltip .tt-delta {
  margin-top: 2px;
  font-size: 12px;
  font-weight: 600;
}

/* Choropleth map */
.map-holder {
  position: relative;
}

.br-map {
  width: 100%;
  height: auto;
  max-height: 560px;
  display: block;
  margin: 0 auto;
}

.br-map path {
  stroke: var(--surface-1);
  stroke-width: 1.2;
  cursor: pointer;
  transition: filter 0.12s ease, stroke-width 0.12s ease;
}

.br-map path.no-data {
  fill: var(--gridline);
}

.br-map path:hover,
.br-map path:focus {
  filter: brightness(1.12);
  stroke-width: 2;
  outline: none;
}

.map-legend {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 18px;
  font-size: 12px;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}

.map-legend-bar {
  flex: 1;
  max-width: 320px;
  height: 10px;
  border-radius: 6px;
  background: var(--gridline);
}

.map-legend-nodata {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
  color: var(--text-muted);
}

.map-legend-nodata .swatch {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  background: var(--gridline);
}

/* Table */
table.states {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

table.states th {
  text-align: left;
  font-weight: 600;
  color: var(--text-secondary);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  border-bottom: 1px solid var(--gridline);
  padding: 8px 10px;
}

table.states td {
  padding: 10px;
  border-bottom: 1px solid var(--gridline);
  font-variant-numeric: tabular-nums;
}

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

table.states td.rank {
  color: var(--text-muted);
  width: 28px;
}

table.states td.uf-name .uf-code {
  font-weight: 700;
  margin-right: 6px;
}

.badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--warning-bg);
  color: var(--warning);
  margin-left: 8px;
}

/* Fixed operational params (read-only) */
.fixed-params {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px 24px;
  margin: 0;
}

.fixed-params > div {
  border-left: 2px solid var(--gridline);
  padding-left: 12px;
}

.fixed-params dt {
  font-size: 12px;
  color: var(--text-secondary);
}

.fixed-params dd {
  margin: 2px 0 0;
  font-size: 17px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* Impact form (still used by /admin/access) */
.impact-form {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.impact-form label {
  display: block;
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.impact-form input {
  width: 100%;
  font: inherit;
  padding: 9px 10px;
  border: 1px solid var(--gridline);
  border-radius: 8px;
  background: var(--page);
  color: var(--text-primary);
}

.impact-form .actions {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.form-msg {
  font-size: 13px;
}
.form-msg.ok { color: var(--good); }
.form-msg.err { color: var(--critical); }

footer.site {
  text-align: center;
  color: var(--text-muted);
  font-size: 12px;
  margin-top: 24px;
}
