:root {
  color-scheme: light;
  --bg: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f3f2ee;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #74726c;
  --line: #e1e0d9;
  --line-strong: #c3c2b7;
  --accent: #2a78d6;
  --accent-ink: #1c5cab;
  --accent-soft: #e6f0fc;
  --good: #0ca30c;
  --good-ink: #006300;
  --warn: #fab219;
  --warn-ink: #8a5a00;
  --bad: #d03b3b;
  --bad-ink: #b02a2a;
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100; --s5: #e87ba4;
  --shadow: 0 1px 2px rgba(11, 11, 11, .05), 0 0 0 1px rgba(11, 11, 11, .06);
  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0d0d0d; --surface: #1a1a19; --surface-2: #232321; --ink: #f0efec; --ink-2: #c3c2b7; --muted: #9a988f;
    --line: #2c2c2a; --line-strong: #383835; --accent: #3987e5; --accent-ink: #86b6ef; --accent-soft: #16263a;
    --good-ink: #0ca30c; --warn-ink: #fab219; --bad-ink: #e66767;
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s5: #d55181;
    --shadow: 0 0 0 1px rgba(255, 255, 255, .08);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0d0d0d; --surface: #1a1a19; --surface-2: #232321; --ink: #f0efec; --ink-2: #c3c2b7; --muted: #9a988f;
  --line: #2c2c2a; --line-strong: #383835; --accent: #3987e5; --accent-ink: #86b6ef; --accent-soft: #16263a;
  --good-ink: #0ca30c; --warn-ink: #fab219; --bad-ink: #e66767;
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s5: #d55181;
  --shadow: 0 0 0 1px rgba(255, 255, 255, .08);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.5 var(--font); }
a { color: var(--accent-ink); }
h1 { font-size: 1.6rem; line-height: 1.2; margin: 0 0 .4rem; letter-spacing: -.01em; }
h2 { font-size: 1.2rem; margin: 0 0 .5rem; }
h3, .h3 { font-size: 1rem; margin: 0 0 .4rem; }
p { margin: 0 0 .6rem; }
.wrap { max-width: 1200px; margin: 0 auto; padding: 0 16px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.row { display: flex; align-items: center; flex-wrap: wrap; }
.gap { gap: 8px; }
[hidden] { display: none !important; }

/* Topo */
.topbar { background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10; }
.topbar-inner { display: flex; align-items: center; gap: 16px; min-height: 56px; }
.brand { display: flex; align-items: center; gap: 8px; color: var(--ink); text-decoration: none; font-weight: 650; white-space: nowrap; }
.steps { display: flex; gap: 4px; margin-left: auto; overflow-x: auto; }
.step { border: 0; background: none; color: var(--ink-2); font: inherit; font-size: .9rem; padding: 6px 10px; border-radius: 8px; cursor: pointer; white-space: nowrap; }
.step b { display: inline-grid; place-items: center; width: 20px; height: 20px; border-radius: 50%; background: var(--surface-2); font-size: .75rem; margin-right: 4px; }
.step.active { color: var(--ink); background: var(--accent-soft); }
.step.active b { background: var(--accent); color: #fff; }
.step:disabled { opacity: .45; cursor: default; }
.icon-btn { border: 1px solid var(--line); background: var(--surface); color: var(--ink-2); width: 34px; height: 34px; border-radius: 8px; display: grid; place-items: center; cursor: pointer; flex: none; }

main { padding: 24px 16px 40px; }
.view-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; margin-bottom: 16px; }
.view-foot { display: flex; justify-content: space-between; gap: 8px; margin-top: 16px; flex-wrap: wrap; }

/* Botões e campos */
.btn { font: inherit; font-size: .9rem; border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink); padding: 8px 14px; border-radius: 8px; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.small { padding: 5px 10px; font-size: .82rem; }
.btn:focus-visible, .step:focus-visible, .icon-btn:focus-visible, .tabs button:focus-visible, .dropzone:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
input, select { font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line-strong); border-radius: 6px; padding: 6px 8px; }
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }

.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 16px; }

/* Etapa 1 */
.hero { max-width: 760px; margin: 8px 0 20px; }
.lead { font-size: 1.05rem; color: var(--ink-2); }
.dropzone { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; text-align: center; border: 2px dashed var(--line-strong); border-radius: 14px; padding: 36px 16px; background: var(--surface); cursor: pointer; color: var(--ink-2); transition: border-color .15s, background .15s; }
.dropzone strong { color: var(--ink); }
.dropzone:hover, .dropzone.over { border-color: var(--accent); background: var(--accent-soft); }
.status { min-height: 1.5em; margin: 10px 0; font-size: .92rem; }
.status.error { color: var(--bad-ink); }
.actions-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 4px 0 24px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.grid-3 .card { margin: 0; }
.info p { color: var(--ink-2); font-size: .9rem; margin: 0; }
.privacy { margin-top: 20px; color: var(--muted); font-size: .88rem; }
.picker .row { gap: 8px; margin-top: 8px; }
.picker input { flex: 1; min-width: 220px; }

/* Etapa 2 */
.notice { border-radius: 8px; padding: 10px 12px; margin-bottom: 12px; font-size: .9rem; border: 1px solid; }
.notice.warn { background: color-mix(in srgb, var(--warn) 12%, var(--surface)); border-color: color-mix(in srgb, var(--warn) 45%, transparent); }
.notice.info { background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 35%, transparent); }
.notice ul { margin: 4px 0 0; padding-left: 18px; }
.period-list { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0 12px; }
.period-chip { display: flex; align-items: center; gap: 6px; border: 1px solid var(--line-strong); border-radius: 8px; padding: 4px 6px 4px 8px; background: var(--surface-2); }
.period-chip input[type=text] { width: 110px; padding: 3px 6px; }
.period-chip button { border: 0; background: none; color: var(--muted); cursor: pointer; font-size: 1rem; }
.params { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.params label { display: flex; flex-direction: column; gap: 4px; font-size: .88rem; color: var(--ink-2); }
.req-dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--accent); vertical-align: middle; }

/* Tabelas */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.grid { border-collapse: collapse; width: 100%; font-size: .88rem; }
.grid th, .grid td { padding: 6px 8px; border-bottom: 1px solid var(--line); text-align: right; vertical-align: middle; }
.grid th { font-weight: 600; color: var(--ink-2); background: var(--surface); position: sticky; top: 0; white-space: nowrap; }
.grid th:first-child, .grid td:first-child, #reviewTable th:nth-child(2) { text-align: left; }
.grid td.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.grid tr.group-row td { background: var(--surface-2); font-weight: 650; color: var(--ink); text-align: left; padding-top: 10px; }
.grid tr.strong td { font-weight: 650; }
.grid tr.heading td { font-weight: 650; color: var(--ink-2); }
.grid td.src { color: var(--muted); font-size: .8rem; text-align: left; max-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.grid td.field { min-width: 220px; }
.grid td.field .req-dot { margin-right: 6px; }
.grid input.cell { width: 120px; text-align: right; padding: 4px 6px; font-variant-numeric: tabular-nums; }
.grid tr.missing td.field { color: var(--bad-ink); }
.grid tr.missing input.cell { border-color: color-mix(in srgb, var(--bad) 55%, transparent); }
.grid .pct { color: var(--muted); font-size: .82rem; }
.neg { color: var(--bad-ink); }
.pos { color: var(--good-ink); }

/* Abas */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 16px; overflow-x: auto; }
.tabs button { font: inherit; font-size: .92rem; border: 0; background: none; color: var(--ink-2); padding: 10px 14px; border-bottom: 2px solid transparent; cursor: pointer; white-space: nowrap; }
.tabs button[aria-selected=true] { color: var(--ink); border-bottom-color: var(--accent); font-weight: 600; }
.tab-panel[hidden] { display: none; }

/* Resumo */
.kpis { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; }
.kpi .k-label { font-size: .82rem; color: var(--ink-2); }
.kpi .k-value { font-size: 1.7rem; font-weight: 650; line-height: 1.2; margin: 2px 0; }
.kpi .k-foot { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: .8rem; color: var(--muted); }
.objective { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.diag-group { margin-bottom: 14px; }
.diag-group h3 { margin-bottom: 6px; }
.diag-list { list-style: none; padding: 0; margin: 0; }
.diag-list li { display: grid; grid-template-columns: auto 1fr; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: .9rem; }
.diag-list li:last-child { border-bottom: 0; }
.diag-list .d-title { font-weight: 600; }
.diag-list .d-text { color: var(--ink-2); }
.two-col { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); gap: 16px; }
.dim { opacity: .55; }

/* Chips de status (cor + ícone + texto) */
.chip { display: inline-flex; align-items: center; gap: 4px; font-size: .75rem; font-weight: 600; padding: 1px 8px; border-radius: 999px; white-space: nowrap; border: 1px solid; }
.chip::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.chip.bom { color: var(--good-ink); border-color: color-mix(in srgb, var(--good) 40%, transparent); background: color-mix(in srgb, var(--good) 9%, var(--surface)); }
.chip.atencao { color: var(--warn-ink); border-color: color-mix(in srgb, var(--warn) 55%, transparent); background: color-mix(in srgb, var(--warn) 12%, var(--surface)); }
.chip.ruim { color: var(--bad-ink); border-color: color-mix(in srgb, var(--bad) 40%, transparent); background: color-mix(in srgb, var(--bad) 9%, var(--surface)); }
.trend { font-size: .78rem; white-space: nowrap; }
.trend.melhora { color: var(--good-ink); }
.trend.piora { color: var(--bad-ink); }
.trend.estavel, .trend.subiu, .trend.caiu { color: var(--muted); }

/* Indicadores */
.ind-table td.name { min-width: 230px; }
.ind-table td.name .sigla { font-weight: 700; margin-right: 6px; }
.ind-table td.name .better { display: block; font-size: .75rem; color: var(--muted); }
.ind-table tr.ind-row { cursor: pointer; }
.ind-table tr.ind-row:hover td { background: var(--surface-2); }
.ind-table tr.ind-row td:first-child::before { content: "▸"; color: var(--muted); margin-right: 6px; display: inline-block; transition: transform .15s; }
.ind-table tr.ind-row.open td:first-child::before { transform: rotate(90deg); }
.ind-table td.warnmark { color: var(--warn-ink); cursor: help; }
.ind-detail td { background: var(--surface-2); text-align: left !important; }
.ind-detail .det { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; padding: 6px 4px; font-size: .88rem; }
.ind-detail .formula { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: .84rem; background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; display: inline-block; }
.ind-detail ul { margin: 4px 0 0; padding-left: 18px; color: var(--ink-2); }
.ind-detail label { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 8px; }
.ind-detail input { width: 110px; }
.group-intro { color: var(--ink-2); font-size: .9rem; }
.spark { display: block; overflow: visible; }
.spark path { fill: none; stroke: var(--s1); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.spark circle.pt { fill: var(--s1); stroke: var(--surface); stroke-width: 2; }
.spark circle.hit { fill: transparent; cursor: default; }

/* Estrutura patrimonial (barras empilhadas) */
.legend { display: flex; flex-wrap: wrap; gap: 12px; font-size: .8rem; color: var(--ink-2); margin-bottom: 10px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.struct { display: grid; grid-template-columns: 70px 1fr; gap: 6px 10px; align-items: center; font-size: .8rem; }
.struct .per { grid-column: 1 / -1; font-weight: 600; color: var(--ink); margin-top: 6px; }
.struct .lab { color: var(--muted); }
.bar { display: flex; gap: 2px; height: 24px; }
.bar .seg { height: 100%; display: flex; align-items: center; justify-content: center; color: #fff; font-size: .72rem; font-weight: 600; overflow: hidden; white-space: nowrap; min-width: 2px; }
.bar .seg:first-child { border-radius: 4px 0 0 4px; }
.bar .seg:last-child { border-radius: 0 4px 4px 0; }
.bar .seg:only-child { border-radius: 4px; }

/* DuPont */
.dupont-eq { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 8px 0 16px; }
.dupont-eq .box { background: var(--surface-2); border-radius: 8px; padding: 8px 12px; text-align: center; min-width: 110px; }
.dupont-eq .box b { display: block; font-size: 1.2rem; }
.dupont-eq .box span { font-size: .76rem; color: var(--ink-2); }
.dupont-eq .op { font-size: 1.2rem; color: var(--muted); }
.dupont-eq .box.result { background: var(--accent-soft); }

.tooltip { position: fixed; z-index: 50; background: var(--ink); color: var(--bg); font-size: .78rem; padding: 4px 8px; border-radius: 6px; pointer-events: none; max-width: 280px; }

.foot { color: var(--muted); font-size: .8rem; padding-bottom: 32px; }

@media (max-width: 860px) {
  .grid-3, .kpis, .two-col, .params { grid-template-columns: 1fr; }
  .ind-detail .det { grid-template-columns: 1fr; }
  .brand span { display: none; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 340px) {
  .kpis { grid-template-columns: 1fr; }
  h1 { font-size: 1.35rem; }
}

@media print {
  .topbar, .no-print, .foot, .view-foot { display: none !important; }
  body { background: #fff; font-size: 11px; }
  main { padding: 0; }
  .tab-panel { display: block !important; break-inside: auto; }
  .tab-panel + .tab-panel { break-before: page; }
  .card, .kpi { box-shadow: none; border: 1px solid #ddd; }
  .ind-detail { display: table-row !important; }
  input { border: 0; }
}
