:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11,11,11,0.10);
  --wash: rgba(11,11,11,0.04);
  --series-1: #2a78d6;
  /* ordinal ramp (etapas) */
  --stage-1: #86b6ef;
  --stage-2: #2a78d6;
  --stage-3: #104281;
  /* status */
  --good: #0ca30c;
  --warning: #fab219;
  --critical: #d03b3b;
  --neutral: #c3c2b7;
  --good-text: #006300;
  --bad-text: #b02a2a;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --ink: #ffffff;
    --ink-2: #c3c2b7;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255,255,255,0.10);
    --wash: rgba(255,255,255,0.05);
    --series-1: #3987e5;
    --stage-1: #6da7ec;
    --stage-2: #3987e5;
    --stage-3: #184f95;
    --neutral: #62615c;
    --good-text: #0ca30c;
    --bad-text: #e66767;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --ink: #ffffff;
  --ink-2: #c3c2b7;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255,255,255,0.10);
  --wash: rgba(255,255,255,0.05);
  --series-1: #3987e5;
  --stage-1: #6da7ec;
  --stage-2: #3987e5;
  --stage-3: #184f95;
  --neutral: #62615c;
  --good-text: #0ca30c;
  --bad-text: #e66767;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
}
.wrap { max-width: 1240px; margin: 0 auto; padding: 24px 16px 48px; }
header.top {
  display: flex; flex-wrap: wrap; gap: 12px 24px;
  align-items: flex-end; justify-content: space-between;
  margin-bottom: 20px;
}
h1 { font-size: 22px; margin: 0 0 4px; font-weight: 650; letter-spacing: -0.01em; }
.sub { color: var(--ink-2); margin: 0; }
.controls { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
button, select, .file-btn {
  font: inherit; color: var(--ink); background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 6px 12px; cursor: pointer;
}
button:hover, .file-btn:hover, select:hover { background: var(--wash); }
.file-btn input { display: none; }
.source { color: var(--muted); font-size: 12px; }

h2 {
  font-size: 13px; font-weight: 650; text-transform: uppercase; letter-spacing: .06em;
  color: var(--ink-2); margin: 32px 0 12px;
}
.grid { display: grid; gap: 16px; }
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 16px 18px; min-width: 0;
}
.card h3 { font-size: 14px; font-weight: 600; margin: 0 0 2px; }
.card .hint { color: var(--muted); font-size: 12px; margin: 0 0 12px; }
.card-head { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px; align-items: flex-start; }
.tile .value { font-size: 34px; font-weight: 650; letter-spacing: -0.02em; margin: 6px 0 2px; }
.tile .value small { font-size: 16px; font-weight: 500; color: var(--ink-2); margin-left: 2px; }
.tile .foot { color: var(--ink-2); font-size: 12px; }
.meter { height: 6px; background: var(--grid); border-radius: 3px; margin-top: 10px; overflow: hidden; }
.meter > span { display: block; height: 100%; border-radius: 3px; background: var(--series-1); }

svg { display: block; max-width: 100%; overflow: visible; }
svg text { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
svg text.lbl { fill: var(--ink-2); font-size: 12px; }
svg text.val { fill: var(--ink); font-size: 12px; font-weight: 600; }
.gridline { stroke: var(--grid); stroke-width: 1; }
.baseline { stroke: var(--axis); stroke-width: 1; }
.hit { fill: transparent; }
.hit:hover { fill: var(--wash); }

.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin: 0 0 10px; color: var(--ink-2); font-size: 12px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; border-radius: 0; padding: 4px 10px; font-size: 12px; }
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--surface); }

.donut-wrap { display: flex; flex-wrap: wrap; gap: 16px 24px; align-items: center; }
.donut-wrap > svg { width: 180px; height: 180px; flex: 0 0 180px; }
.donut-list { list-style: none; padding: 0; margin: 0; flex: 1 1 160px; }
.donut-list li { display: flex; align-items: center; gap: 8px; padding: 5px 0; border-bottom: 1px solid var(--grid); }
.donut-list li:last-child { border-bottom: 0; }
.donut-list .n { margin-left: auto; font-weight: 600; font-variant-numeric: tabular-nums; }
.donut-list .p { color: var(--muted); width: 42px; text-align: right; font-variant-numeric: tabular-nums; }
.ico { width: 14px; height: 14px; flex: 0 0 14px; }

.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--grid); }
th { color: var(--muted); font-weight: 600; font-size: 12px; white-space: nowrap; }
td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
th.num { text-align: right; }
.pill {
  display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px;
  border: 1px solid var(--border); color: var(--ink-2); white-space: nowrap;
}
.age-hi { color: var(--bad-text); font-weight: 650; }
.empty { color: var(--muted); padding: 16px 0; text-align: center; }

#tip {
  position: fixed; pointer-events: none; z-index: 10; display: none;
  background: var(--surface); color: var(--ink); border: 1px solid var(--border);
  box-shadow: 0 4px 16px rgba(0,0,0,.12); border-radius: 8px;
  padding: 8px 10px; font-size: 12px; max-width: 260px;
}
#tip b { display: block; margin-bottom: 2px; }
#tip .row { display: flex; gap: 12px; justify-content: space-between; color: var(--ink-2); }
#tip .row span:last-child { color: var(--ink); font-weight: 600; font-variant-numeric: tabular-nums; }

/* ---------- grade de widgets ---------- */
.secao { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.w-pequeno { grid-column: span 1; }
.w-medio { grid-column: span 2; }
.w-grande { grid-column: 1 / -1; }
@media (max-width: 900px) {
  .secao { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .w-medio { grid-column: 1 / -1; }
}
@media (max-width: 560px) {
  .secao { grid-template-columns: minmax(0, 1fr); }
  .w-pequeno { grid-column: 1 / -1; }
}
a { color: var(--series-1); }
.btn-link { text-decoration: none; display: inline-block; font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 6px 12px; }
.btn-link:hover { background: var(--wash); }
.aviso {
  border: 1px solid var(--border); border-left: 3px solid var(--warning);
  background: var(--surface); border-radius: 8px; padding: 10px 12px; margin: 0 0 16px; color: var(--ink-2); font-size: 13px;
}
.aviso b { color: var(--ink); }
.vazio-dash { color: var(--muted); text-align: center; padding: 48px 16px; }

/* palavra "atraso" / "em atraso" sempre em vermelho */
.atraso { color: var(--bad-text); font-weight: 650; }
svg .atraso { fill: var(--bad-text); font-weight: 650; }

/* opções das listas suspensas sempre legíveis (no Windows o navegador desenha
   o fundo da lista em branco e o texto herdava a cor clara do tema escuro) */
select option, select optgroup { background-color: var(--surface); color: var(--ink); }
select option:disabled { color: var(--muted); }
/* status "Em atraso": texto vermelho sobre fundo claro, nos dois temas */
.atraso-status {
  background: #fde8e8; color: #b02a2a;
  padding: 1px 8px; border-radius: 999px; white-space: nowrap;
}
input[type=text].atraso-campo, input.atraso-campo, select.atraso-campo, option.atraso-campo {
  background-color: #fde8e8; color: #b02a2a; font-weight: 650;
}
