:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f3f2ef;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --ring: rgba(11, 11, 11, 0.10);
  --accent: #2a78d6;
  --accent-wash: rgba(42, 120, 214, 0.10);
  --good: #006300;
  --good-mark: #0ca30c;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100; --s5: #e87ba4; --s6: #008300; --s7: #6250d6; --s8: #e34948;
  --seq-1: #cde2fb; --seq-4: #3987e5; --seq-7: #0d366b;
  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page: #0d0d0d; --surface: #1a1a19; --surface-2: #232321;
    --ink: #f0efec; --ink-2: #c3c2b7; --muted: #898781; --grid: #2c2c2a; --axis: #383835;
    --ring: rgba(255, 255, 255, 0.10); --accent: #3987e5; --accent-wash: rgba(57, 135, 229, 0.16);
    --good: #0ca30c;
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
    --seq-1: #184f95; --seq-4: #3987e5; --seq-7: #cde2fb;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d; --surface: #1a1a19; --surface-2: #232321;
  --ink: #f0efec; --ink-2: #c3c2b7; --muted: #898781; --grid: #2c2c2a; --axis: #383835;
  --ring: rgba(255, 255, 255, 0.10); --accent: #3987e5; --accent-wash: rgba(57, 135, 229, 0.16);
  --good: #0ca30c;
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
  --seq-1: #184f95; --seq-4: #3987e5; --seq-7: #cde2fb;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--page); color: var(--ink); font: 14px/1.45 var(--font); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0 0 4px; font-weight: 650; letter-spacing: -0.01em; }
h2 { font-size: 15px; margin: 0 0 12px; font-weight: 600; }
h3 { font-size: 13px; margin: 0 0 8px; font-weight: 600; color: var(--ink-2); }
.sub { color: var(--ink-2); margin: 0 0 20px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.neg { color: var(--critical); }
.pos { color: var(--good); }

/* layout */
.app { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.side { background: var(--surface); border-right: 1px solid var(--grid); padding: 20px 12px; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 2px; }
.brand { font-weight: 700; font-size: 16px; padding: 0 10px 16px; display: flex; align-items: center; gap: 8px; }
.brand svg { width: 22px; height: 22px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; color: var(--ink-2); font-weight: 500; }
.nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav a.on { background: var(--accent-wash); color: var(--accent); }
.side .foot { margin-top: auto; padding: 10px; font-size: 12px; color: var(--muted); display: flex; flex-direction: column; gap: 6px; }
.main { padding: 28px 32px 60px; max-width: 1280px; min-width: 0; }
.head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; margin-bottom: 8px; }

.grid { display: grid; gap: 16px; align-items: start; }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g21 { grid-template-columns: 2fr 1fr; }
.card { background: var(--surface); border: 1px solid var(--ring); border-radius: var(--radius); padding: 18px; min-width: 0; }
.card + .card, .grid + .card, .card + .grid, .grid + .grid { margin-top: 16px; }
.grid > .card { margin-top: 0; }
.card .card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 12px; }
.card .card-head h2 { margin: 0; }

/* stat tiles */
.stat .label { color: var(--ink-2); font-size: 13px; }
.stat .value { font-size: 26px; font-weight: 650; margin: 4px 0 2px; letter-spacing: -0.02em; }
.stat .delta { font-size: 12px; color: var(--ink-2); }
.delta .up-bad, .delta .down-bad { color: var(--critical); }
.delta .up-good, .delta .down-good { color: var(--good); }

/* bars em HTML */
.hbars { display: flex; flex-direction: column; gap: 10px; }
.hbar { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 12px; align-items: baseline; cursor: default; }
.hbar .name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hbar .track { grid-column: 1 / -1; height: 8px; border-radius: 4px; background: var(--surface-2); position: relative; }
.hbar .fill { position: absolute; inset: 0 auto 0 0; border-radius: 0 4px 4px 0; background: var(--s1); }
.hbar .budget { position: absolute; top: -3px; bottom: -3px; width: 2px; background: var(--ink-2); border-radius: 1px; }
.hbar.over .fill { background: var(--critical); }
.seg { display: flex; height: 12px; gap: 2px; border-radius: 4px; overflow: hidden; margin: 8px 0; }
.seg > span { display: block; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 12px; color: var(--ink-2); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.meter { height: 10px; border-radius: 5px; background: var(--seq-1); overflow: hidden; margin: 10px 0 6px; position: relative; }
.meter > span { position: absolute; inset: 0 auto 0 0; background: var(--accent); border-radius: 5px; }
.meter > b { position: absolute; top: -2px; bottom: -2px; width: 2px; background: var(--ink); }

.chart-box { position: relative; height: 280px; }
.chart-box.tall { height: 340px; }

/* tabelas */
.table-wrap { overflow-x: auto; margin: 0 -18px; padding: 0 18px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; font-weight: 600; color: var(--ink-2); font-size: 12px; padding: 8px 8px; border-bottom: 1px solid var(--axis); white-space: nowrap; position: sticky; top: 0; background: var(--surface); }
td { padding: 7px 8px; border-bottom: 1px solid var(--grid); vertical-align: middle; }
tr:hover td { background: var(--surface-2); }
td.desc { max-width: 280px; }
td.desc .d { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }
.heat td.cell { text-align: right; font-variant-numeric: tabular-nums; }
.tag { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 10px; background: var(--surface-2); color: var(--ink-2); white-space: nowrap; }
.tag.sev-high { background: rgba(208, 59, 59, 0.12); color: var(--critical); }
.tag.sev-medium { background: rgba(236, 131, 90, 0.16); color: #b4532b; }
:root[data-theme="dark"] .tag.sev-medium { color: var(--serious); }
@media (prefers-color-scheme: dark) { :root:where(:not([data-theme="light"])) .tag.sev-medium { color: var(--serious); } }
.tag.sev-info { background: var(--accent-wash); color: var(--accent); }

/* insights */
.insight { border-left: 3px solid var(--grid); padding: 2px 0 2px 14px; }
.insight + .insight { margin-top: 18px; }
.insight.high { border-color: var(--critical); }
.insight.medium { border-color: var(--serious); }
.insight.info { border-color: var(--accent); }
.insight .t { font-weight: 600; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.insight .d { color: var(--ink-2); margin: 4px 0 8px; }
.insight ul { margin: 0; padding: 0; list-style: none; display: grid; grid-template-columns: repeat(auto-fill, minmax(min(240px, 100%), 1fr)); gap: 4px 20px; font-size: 13px; }
.insight li { display: flex; justify-content: space-between; gap: 8px; border-bottom: 1px dashed var(--grid); padding: 3px 0; }
.insight li span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.save { color: var(--good); font-weight: 600; font-size: 13px; }
.insight.mini .t { font-size: 13px; }
.insight.mini + .insight.mini { margin-top: 12px; }
.insight.mini .d { margin: 2px 0 0; font-size: 13px; }

/* forms */
input, select, textarea, button { font: inherit; color: inherit; }
input, select, textarea { background: var(--surface); border: 1px solid var(--axis); border-radius: 7px; padding: 6px 9px; min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
select.inline { padding: 3px 4px; border-color: transparent; background: transparent; max-width: 170px; }
select.inline:hover { border-color: var(--axis); }
button, .btn { background: var(--surface); border: 1px solid var(--axis); border-radius: 7px; padding: 6px 12px; cursor: pointer; font-weight: 500; display: inline-flex; align-items: center; gap: 6px; }
button:hover, .btn:hover { background: var(--surface-2); text-decoration: none; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { filter: brightness(1.08); }
button.link { border: 0; background: none; color: var(--accent); padding: 0; }
button.danger { color: var(--critical); }
button:disabled { opacity: .55; cursor: default; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 14px; }
.filters input[type=search] { width: 220px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 10px; align-items: end; }
label.f { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--ink-2); }
.drop { border: 2px dashed var(--axis); border-radius: var(--radius); padding: 28px; text-align: center; color: var(--ink-2); }
.drop.over { border-color: var(--accent); background: var(--accent-wash); }

.toast { position: fixed; right: 20px; bottom: 20px; background: var(--ink); color: var(--page); padding: 12px 16px; border-radius: 10px; max-width: 420px; box-shadow: 0 8px 24px rgba(0,0,0,.18); display: flex; gap: 12px; align-items: center; z-index: 50; }
.toast button { background: transparent; color: var(--page); border-color: rgba(255,255,255,.35); }
:root[data-theme="dark"] .toast button { border-color: rgba(0,0,0,.35); }
dialog { border: 1px solid var(--ring); border-radius: 12px; background: var(--surface); color: var(--ink); padding: 20px; width: min(520px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(0,0,0,.35); }
.empty { text-align: center; padding: 48px 16px; color: var(--ink-2); }
.empty h2 { color: var(--ink); }
.pill-row { display: flex; gap: 4px; background: var(--surface-2); padding: 3px; border-radius: 8px; }
.pill-row button { border: 0; background: transparent; padding: 4px 10px; border-radius: 6px; }
.pill-row button.on { background: var(--surface); box-shadow: 0 0 0 1px var(--ring); }
.loading { color: var(--muted); padding: 40px; text-align: center; }

/* tooltip do chart.js externo não usado; tooltip HTML p/ barras */
.tip { position: fixed; pointer-events: none; background: var(--ink); color: var(--page); font-size: 12px; padding: 6px 9px; border-radius: 6px; z-index: 60; white-space: nowrap; }

@media (max-width: 1000px) {
  .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .g3, .g21 { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .side { position: sticky; top: 0; height: auto; flex-direction: row; padding: 8px 12px; overflow-x: auto; z-index: 10; border-right: 0; border-bottom: 1px solid var(--grid); gap: 4px; }
  .brand, .side .foot { display: none; }
  .nav { display: flex; gap: 2px; }
  .nav a { white-space: nowrap; padding: 6px 10px; }
  .nav a svg { display: none; }
  .main { padding: 18px 16px 48px; }
  .g2 { grid-template-columns: 1fr; }
  .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .card { padding: 14px; }
  .stat .value { font-size: 19px; }
  .stat .delta { font-size: 11px; }
  .table-wrap { margin: 0 -14px; padding: 0 14px; }
  .filters input[type=search] { width: 100%; }
}

/* etiquetas por pessoa (RAFAEL / LETÍCIA / CASA) */
.ptag { --pc: var(--muted); display: inline-flex; align-items: center; gap: 6px; font-size: 11px; font-weight: 700; letter-spacing: .04em;
  padding: 2px 9px 2px 7px; border-radius: 999px; white-space: nowrap; color: var(--ink);
  background: color-mix(in srgb, var(--pc) 16%, transparent); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--pc) 45%, transparent); }
.ptag i { width: 8px; height: 8px; border-radius: 50%; background: var(--pc); flex: none; }
.ptag-none { font-weight: 500; color: var(--muted); }
.ptag-sel { position: relative; display: inline-flex; cursor: pointer; }
.ptag-sel .ptag::after { content: '▾'; font-size: 9px; color: var(--muted); margin-left: 1px; }
.ptag-sel select { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; border: 0; padding: 0; }
.ptag-sel:focus-within .ptag { outline: 2px solid var(--accent); outline-offset: 1px; }
