/* SIIE · Painel Executivo — UniCarioca
   Tokens por papel; modo escuro selecionado (passos próprios), não invertido. */
:root {
  color-scheme: light;
  --page: #f4f3f0;
  --surface: #fcfcfb;
  --surface-2: #f4f3f0;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #6f6d68;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, .10);
  --shadow: 0 1px 2px rgba(11, 11, 11, .04), 0 4px 16px rgba(11, 11, 11, .04);
  --brand: #a31d24;
  --brand-strong: #821519;
  --brand-ink: #ffffff;
  --brand-soft: #f8e9ea;
  --link: #a31d24;
  --s1: #2a78d6;
  --s2: #eb6834;
  --s3: #1baf7a;
  --seq-0: #f0efec;
  --seq-1: #cde2fb;
  --seq-2: #9ec5f4;
  --seq-3: #5598e7;
  --seq-4: #2a78d6;
  --seq-5: #1c5cab;
  --seq-6: #0d366b;
  --good: #0ca30c;
  --good-ink: #006300;
  --warning: #fab219;
  --critical: #d03b3b;
  --critical-ink: #b42727;
  --focus: #2a78d6;
  --radius: 14px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", 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: #9a988f;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, .10);
    --shadow: none;
    --brand: #7d1519;
    --brand-strong: #e0565c;
    --brand-ink: #ffffff;
    --brand-soft: #3a1416;
  --link: #f08a8f;
    --link: #f08a8f;
    --s1: #3987e5;
    --s2: #d95926;
    --s3: #199e70;
    --seq-0: #232321;
    --seq-1: #104281;
    --seq-2: #184f95;
    --seq-3: #256abf;
    --seq-4: #3987e5;
    --seq-5: #6da7ec;
    --seq-6: #b7d3f6;
    --good-ink: #0ca30c;
    --critical-ink: #e66767;
    --focus: #6da7ec;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #232321;
  --ink: #f0efec;
  --ink-2: #c3c2b7;
  --muted: #9a988f;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, .10);
  --shadow: none;
  --brand: #7d1519;
  --brand-strong: #e0565c;
  --brand-ink: #ffffff;
  --brand-soft: #3a1416;
  --link: #f08a8f;
  --s1: #3987e5;
  --s2: #d95926;
  --s3: #199e70;
  --seq-0: #232321;
  --seq-1: #104281;
  --seq-2: #184f95;
  --seq-3: #256abf;
  --seq-4: #3987e5;
  --seq-5: #6da7ec;
  --seq-6: #b7d3f6;
  --good-ink: #0ca30c;
  --critical-ink: #e66767;
  --focus: #6da7ec;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: var(--font);
  background: var(--page);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  padding-bottom: env(safe-area-inset-bottom);
}
a { color: inherit; }
button, select, input { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 6px; }
.muted { color: var(--muted); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- topo ---------- */
.topbar {
  background: var(--brand);
  color: var(--brand-ink);
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  display: flex; align-items: center; gap: 12px;
  position: sticky; top: 0; z-index: 30;
}
.brand-mark {
  width: 36px; height: 36px; border-radius: 10px; flex: none;
  background: #ffffff; color: #a31d24; display: grid; place-items: center;
  font-weight: 800; font-size: 19px; letter-spacing: -.5px;
}
.topbar .titulo { display: flex; flex-direction: column; min-width: 0; }
.topbar .titulo strong { font-size: 16px; font-weight: 650; white-space: nowrap; }
.topbar .titulo span { font-size: 12px; opacity: .85; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .acoes { margin-left: auto; display: flex; align-items: center; gap: 6px; }
.icon-btn {
  width: 38px; height: 38px; border-radius: 10px; border: 0; cursor: pointer;
  background: rgba(255, 255, 255, .12); color: inherit; display: grid; place-items: center;
}
.icon-btn[hidden] { display: none; }
.icon-btn:hover { background: rgba(255, 255, 255, .22); }
.icon-btn svg { width: 20px; height: 20px; }
.user-chip { font-size: 13px; opacity: .9; margin-right: 4px; }


/* ---------- filtros ---------- */
.filtros {
  position: sticky; top: calc(58px + env(safe-area-inset-top)); z-index: 20;
  background: var(--page);
  border-bottom: 1px solid var(--border);
  padding: 10px 16px;
  display: flex; gap: 10px; align-items: end; overflow-x: auto;
  scrollbar-width: thin;
}
.filtro { display: flex; flex-direction: column; gap: 3px; flex: none; }
.filtro > span { font-size: 11px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.filtro select {
  height: 36px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface);
  padding: 0 30px 0 10px; min-width: 120px; max-width: 240px; appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 15px) 15px, calc(100% - 10px) 15px; background-size: 5px 5px; background-repeat: no-repeat;
}
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); padding: 2px; height: 36px; }
.seg button { border: 0; background: transparent; padding: 0 12px; border-radius: 8px; cursor: pointer; color: var(--ink-2); font-size: 14px; }
.seg button[aria-pressed="true"] { background: var(--brand); color: var(--brand-ink); }
.btn-limpar { height: 36px; border: 0; background: transparent; color: var(--link); cursor: pointer; padding: 0 6px; font-weight: 600; flex: none; }

/* ---------- navegação de seções ---------- */
.secoes { display: flex; gap: 8px; padding: 12px 16px 0; overflow-x: auto; scrollbar-width: none; }
.secoes a {
  flex: none; text-decoration: none; font-size: 14px; padding: 7px 14px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface); color: var(--ink-2);
}
.secoes a.ativo { border-color: var(--link); color: var(--link); font-weight: 600; background: var(--brand-soft); }

/* ---------- conteúdo ---------- */
main.conteudo { max-width: 1440px; margin: 0 auto; padding: 8px 16px 48px; transition: opacity .2s; }
main.conteudo.carregando { opacity: .45; pointer-events: none; }
.secao { scroll-margin-top: 140px; padding-top: 18px; }
.secao > header { display: flex; align-items: baseline; gap: 12px; margin: 0 2px 12px; flex-wrap: wrap; }
.secao > header h2 { font-size: 20px; margin: 0; font-weight: 700; letter-spacing: -.01em; }
.secao > header p { margin: 0; color: var(--muted); font-size: 14px; }
.grid { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 14px; }
.c-12 { grid-column: span 12; } .c-8 { grid-column: span 8; } .c-6 { grid-column: span 6; } .c-4 { grid-column: span 4; } .c-3 { grid-column: span 3; }
@media (max-width: 1100px) { .c-8, .c-4 { grid-column: span 12; } .c-3 { grid-column: span 6; } }
@media (max-width: 760px) { .c-6, .c-3 { grid-column: span 12; } .kpis .c-3 { grid-column: span 6; } }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px; min-width: 0;
}
.card > .card-head { display: flex; align-items: flex-start; gap: 10px; margin-bottom: 10px; }
.card-head h3 { margin: 0; font-size: 15px; font-weight: 650; }
.card-head p { margin: 2px 0 0; font-size: 13px; color: var(--muted); }
.card-head .tbl-toggle {
  margin-left: auto; flex: none; border: 1px solid var(--border); background: transparent; border-radius: 8px;
  font-size: 12px; padding: 4px 8px; cursor: pointer; color: var(--ink-2);
}
.card-head .tbl-toggle[aria-pressed="true"] { background: var(--surface-2); }
.chart { position: relative; width: 100%; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart text { font-family: var(--font); pointer-events: none; }
.legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 13px; color: var(--ink-2); margin: 2px 0 8px; }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.legend i.line { height: 3px; border-radius: 2px; vertical-align: 3px; width: 16px; }
.nota { font-size: 12px; color: var(--muted); margin: 10px 0 0; }

/* KPIs */
.kpi { display: flex; flex-direction: column; gap: 4px; min-height: 118px; }
.kpi .rotulo { font-size: 13px; color: var(--ink-2); font-weight: 600; }
.kpi .valor { font-size: 30px; font-weight: 700; letter-spacing: -.02em; line-height: 1.1; }
.kpi .sub { font-size: 12px; color: var(--muted); }
.delta { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; font-weight: 600; }
.delta svg { width: 14px; height: 14px; }
.delta.bom { color: var(--good-ink); }
.delta.ruim { color: var(--critical-ink); }
.delta.neutro { color: var(--muted); }
@media (max-width: 760px) { .kpi .valor { font-size: 24px; } .kpi { min-height: 104px; } }

/* destaques */
.insights { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.insights li { display: flex; gap: 10px; align-items: flex-start; font-size: 14px; padding: 10px 12px; border-radius: 10px; background: var(--surface-2); }
.insights li svg { width: 18px; height: 18px; flex: none; margin-top: 1px; }
.insights li.alerta svg { color: var(--critical); }
.insights li.oportunidade svg { color: var(--good); }
.insights li.info svg { color: var(--s1); }
.insights li .tag { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); display: block; }

/* tabelas */
.tabela-wrap { overflow-x: auto; max-height: 460px; overflow-y: auto; border-radius: 8px; }
table.dados { width: 100%; border-collapse: collapse; font-size: 13px; }
table.dados th, table.dados td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--grid); white-space: nowrap; }
table.dados th { position: sticky; top: 0; background: var(--surface); font-size: 12px; color: var(--muted); font-weight: 600; cursor: pointer; user-select: none; }
table.dados th[aria-sort="ascending"]::after { content: " ▲"; font-size: 9px; }
table.dados th[aria-sort="descending"]::after { content: " ▼"; font-size: 9px; }
table.dados td.num, table.dados th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.dados td.txt { white-space: normal; min-width: 180px; }
table.dados tr:hover td { background: var(--surface-2); }
.barra-cel { display: inline-block; height: 8px; border-radius: 4px; background: var(--s1); vertical-align: middle; margin-left: 8px; opacity: .85; }
.selo { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); }
.selo.alerta { color: var(--critical-ink); }
.selo.ok { color: var(--good-ink); }

/* tiles pequenos */
.mini-tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
.mini { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; }
.mini b { display: block; font-size: 22px; font-weight: 700; }
.mini span { font-size: 12px; color: var(--muted); }

/* tooltip */
.tooltip {
  position: fixed; z-index: 100; pointer-events: none; min-width: 120px; max-width: 280px;
  background: var(--surface); color: var(--ink); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .14); padding: 8px 10px; font-size: 13px; opacity: 0; transition: opacity .08s;
}
.tooltip.on { opacity: 1; }
.tooltip .tt-t { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.tooltip .tt-r { display: flex; align-items: center; gap: 8px; }
.tooltip .tt-r i { width: 12px; height: 3px; border-radius: 2px; flex: none; }
.tooltip .tt-r b { font-variant-numeric: tabular-nums; }
.tooltip .tt-r span { color: var(--ink-2); }

.vazio { padding: 28px; text-align: center; color: var(--muted); }
.aviso-dados { font-size: 13px; color: var(--ink-2); background: var(--surface-2); border-radius: 10px; padding: 10px 12px; margin-top: 10px; }
.rodape { text-align: center; font-size: 12px; color: var(--muted); padding: 24px 16px 40px; }

/* login */
.login-body { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: var(--page); }
.login-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border); border-radius: 18px; padding: 28px; box-shadow: var(--shadow); }
.login-card .brand-mark { background: var(--brand); color: #fff; width: 48px; height: 48px; font-size: 24px; margin-bottom: 12px; }
.login-card h1 { margin: 0; font-size: 24px; }
.login-card form { display: grid; gap: 12px; margin-top: 18px; }
.login-card label { display: grid; gap: 4px; font-size: 13px; font-weight: 600; color: var(--ink-2); }
.login-card input { height: 42px; border-radius: 10px; border: 1px solid var(--border); background: var(--page); padding: 0 12px; }
.btn-primary { height: 44px; border: 0; border-radius: 10px; background: var(--brand); color: var(--brand-ink); font-weight: 650; cursor: pointer; }
.login-erro { color: var(--critical-ink); font-size: 14px; margin: 12px 0 0; }

@media (forced-colors: active) { .card { border: 1px solid CanvasText; } }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; scroll-behavior: auto !important; } }
@media print { .topbar, .filtros, .secoes, .tbl-toggle { display: none !important; } .card { break-inside: avoid; box-shadow: none; } }

/* celular: filtros em grade, sem rolagem lateral */
@media (max-width: 760px) {
  .user-chip { display: none; }
  .filtros { position: static; display: grid; grid-template-columns: 1fr 1fr; overflow: visible; }
  .filtro select { max-width: none; width: 100%; min-width: 0; }
  .filtro:has(.seg) { grid-column: span 2; }
  .seg { width: 100%; } .seg button { flex: 1; }
  .btn-limpar { grid-column: span 2; justify-self: start; }
  .secao { scroll-margin-top: 70px; }
}
