:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #fafbfc;
  --border: #e3e6ea;
  --text: #1b2733;
  --muted: #6b7885;
  --primary: #1f6feb;
  --primary-ink: #ffffff;
  --accent: #0b8a5a;
  --warn: #b7791f;
  --danger: #c0392b;
  --highlight: #fff8d6;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(16, 24, 40, .06), 0 1px 2px rgba(16, 24, 40, .04);
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f141a; --surface: #161c24; --surface-2: #1b222c; --border: #2a333f;
    --text: #e6edf3; --muted: #92a0b0; --primary: #4d9bff; --highlight: #3a3620;
  }
}
* { box-sizing: border-box; }
body { margin: 0; font-family: var(--sans); background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.5; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- topbar ---------- */
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20; }
.topbar-inner { max-width: none; margin: 0 auto; display: flex; align-items: center; gap: 20px; padding: 12px 14px; }
.brand { font-weight: 700; font-size: 17px; letter-spacing: -.2px; display: flex; align-items: center; gap: 9px; color: var(--text); }
.brand .logo { width: 26px; height: 26px; border-radius: 7px; background: linear-gradient(135deg, var(--primary), var(--accent)); display: grid; place-items: center; color: #fff; font-size: 15px; }
.nav { display: flex; gap: 4px; margin-left: 8px; }
.nav a { padding: 7px 13px; border-radius: 8px; color: var(--muted); font-weight: 500; }
.nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav a.active { background: var(--primary); color: var(--primary-ink); }
.spacer { flex: 1; }
.tbright { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* ---------- layout ---------- */
.wrap { max-width: none; margin: 0 auto; padding: 18px 14px; }
.grid-2 { display: grid; grid-template-columns: 380px 1fr; gap: 22px; align-items: start; }
@media (max-width: 900px) { .grid-2 { grid-template-columns: 1fr; } }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-h { padding: 14px 18px; border-bottom: 1px solid var(--border); font-weight: 650; display: flex; align-items: center; gap: 10px; }
.card-b { padding: 18px; }
.card-b.tight { padding: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* ---------- forms ---------- */
label { display: block; font-size: 13px; font-weight: 600; margin: 0 0 5px; color: var(--text); }
.hint { font-weight: 400; color: var(--muted); font-size: 12px; }
input, select, textarea { width: 100%; padding: 9px 11px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2); color: var(--text); font-size: 14px; font-family: inherit; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; border-color: var(--primary); }
.field { margin-bottom: 14px; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }

.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg button { border: none; background: var(--surface-2); color: var(--muted); padding: 9px 14px; font-size: 13px; font-weight: 600; cursor: pointer; }
.seg button.on { background: var(--primary); color: #fff; }
.seg.max button.on { background: var(--primary); }
.seg.min button.on { background: var(--warn); }

.btn { display: inline-flex; align-items: center; gap: 7px; border: 1px solid var(--border); background: var(--surface); color: var(--text); padding: 9px 15px; border-radius: 8px; font-weight: 600; font-size: 14px; cursor: pointer; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { filter: brightness(1.06); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.danger { color: var(--danger); }
.btn.sm { padding: 5px 10px; font-size: 13px; }

/* ---------- KPIs ---------- */
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
@media (max-width: 900px) { .kpis { grid-template-columns: repeat(2, 1fr); } }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 15px 16px; box-shadow: var(--shadow); }
.kpi .k-label { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .3px; }
.kpi .k-value { font-size: 22px; font-weight: 700; margin-top: 5px; font-variant-numeric: tabular-nums; }
.kpi .k-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
/* resumo (KPIs) colapsavel — liberta espaco vertical para a analise */
.kpi-toggle { display: inline-flex; align-items: center; gap: 6px; background: none; border: none; color: var(--muted); font: inherit; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .3px; cursor: pointer; padding: 3px 6px; margin-bottom: 10px; border-radius: 6px; }
.kpi-toggle:hover { color: var(--text); background: var(--surface-2); }
.kpi-toggle .tri { font-size: 10px; display: inline-block; }
.kpis-off .kpis { display: none; }
.kpis-off .table-scroll { max-height: calc(100vh - 130px); }
/* ecra inteiro (botao ⛶ / tecla F): margem lateral ZERO — cada pixel para a analise */
.fs-on .wrap { padding-left: 0; padding-right: 0; }
.fs-on .topbar-inner { padding-left: 10px; padding-right: 10px; }
.fs-on .card { border-radius: 0; border-left: 0; border-right: 0; }
.fs-on .table-scroll { max-height: calc(100vh - 150px); }
.fs-on .kpis-off .table-scroll { max-height: calc(100vh - 80px); }

/* ---------- tables ---------- */
/* scroll interno (horizontal + vertical) para o header ficar sticky no topo da tabela */
.table-scroll { overflow: auto; max-height: calc(100vh - 200px); }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { padding: 9px 11px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { background: var(--surface-2); font-size: 12px; text-transform: uppercase; letter-spacing: .3px; color: var(--muted); font-weight: 700; position: sticky; top: 0; z-index: 5; box-shadow: inset 0 -1px 0 var(--border); }
tbody tr:hover { background: var(--surface-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; font-family: var(--mono); }
tr.total td { font-weight: 700; background: var(--surface-2); border-top: 2px solid var(--border); position: sticky; bottom: 0; z-index: 4; }
td.hl { background: var(--highlight); }
.pill { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 700; }
.pill.max { background: rgba(31,111,235,.12); color: var(--primary); }
.pill.min { background: rgba(183,121,31,.15); color: var(--warn); }
.pill.done { background: rgba(11,138,90,.14); color: var(--accent); }
.badge { font-size: 11px; color: var(--muted); font-family: var(--mono); }

/* ---------- landing ---------- */
.hero { text-align: center; padding: 40px 20px 10px; }
.hero h1 { font-size: 30px; letter-spacing: -.5px; margin: 0 0 8px; }
.hero p { color: var(--muted); max-width: 640px; margin: 0 auto; }
.cards2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; max-width: 860px; margin: 30px auto; }
@media (max-width: 760px) { .cards2 { grid-template-columns: 1fr; } }
.pick { display: block; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 26px; box-shadow: var(--shadow); transition: transform .08s, border-color .12s; }
.pick:hover { transform: translateY(-2px); border-color: var(--primary); text-decoration: none; }
.pick .ico { font-size: 30px; }
.pick h3 { margin: 12px 0 6px; color: var(--text); }
.pick p { color: var(--muted); margin: 0; font-size: 14px; }

/* ---------- misc ---------- */
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }
.toolbar .spacer { flex: 1; }
dialog { border: 1px solid var(--border); border-radius: 14px; padding: 0; background: var(--surface); color: var(--text); box-shadow: 0 20px 50px rgba(0,0,0,.25); max-width: 640px; width: 92vw; }
dialog::backdrop { background: rgba(0,0,0,.4); }
.dlg-h { padding: 16px 20px; border-bottom: 1px solid var(--border); font-weight: 700; display: flex; align-items: center; }
.dlg-b { padding: 20px; max-height: 70vh; overflow: auto; }
.dlg-f { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; gap: 10px; justify-content: flex-end; }
.empty { text-align: center; padding: 44px; color: var(--muted); }
.note { background: var(--surface-2); border: 1px solid var(--border); border-left: 3px solid var(--primary); border-radius: 8px; padding: 11px 14px; font-size: 13px; color: var(--muted); }
.autocomplete { position: relative; }
.ac-list { position: absolute; z-index: 30; left: 0; right: 0; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; margin-top: 3px; max-height: 240px; overflow: auto; box-shadow: var(--shadow); }
.ac-item { padding: 8px 11px; cursor: pointer; font-size: 13px; display: flex; justify-content: space-between; gap: 10px; }
.ac-item:hover, .ac-item.sel { background: var(--surface-2); }
.ac-item .code { font-family: var(--mono); color: var(--primary); font-weight: 700; }
