:root {
  color-scheme: light;
  --brand: #223058;
  --brand-2: #1068A7;
  --brand-3: #4FA8DF;
  --bg: #f3f5f9;
  --surface-1: #fcfcfb;
  --surface-2: #eef1f6;
  --border: #dde2ea;
  --grid: #e6e9ef;
  --text-primary: #0f1726;
  --text-secondary: #4a5468;
  --text-muted: #6b7486;
  --series-1: #1068A7;   /* LVL / competência */
  --series-2: #eb6834;   /* T4F / caixa */
  --series-3: #1baf7a;   /* M2 / caixa + recebíveis */
  --cat-4: #eda100; --cat-5: #e87ba4; --cat-6: #008300; --cat-7: #6250d6;
  --pos: #1068A7;
  --neg: #e34948;
  --good: #0f7b3c; --good-bg: #e3f4ea;
  --warn: #8a5a00; --warn-bg: #fdf1d6;
  --bad: #b42318;  --bad-bg: #fde7e5;
  --info-bg: #e8f1fa;
  --shadow: 0 1px 2px rgba(15, 23, 38, .06), 0 2px 8px rgba(15, 23, 38, .04);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #111317; --surface-1: #1a1a19; --surface-2: #23242a; --border: #33353d; --grid: #2b2d33;
    --text-primary: #f0efec; --text-secondary: #c3c2b7; --text-muted: #9a9a92;
    --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70;
    --cat-4: #c98500; --cat-5: #d55181; --cat-6: #008300; --cat-7: #9085e9;
    --pos: #3987e5; --neg: #e66767;
    --good: #6fd39a; --good-bg: #173324; --warn: #f2c35b; --warn-bg: #3a2e12;
    --bad: #ff9b91; --bad-bg: #3d1c19; --info-bg: #1b2a3a;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111317; --surface-1: #1a1a19; --surface-2: #23242a; --border: #33353d; --grid: #2b2d33;
  --text-primary: #f0efec; --text-secondary: #c3c2b7; --text-muted: #9a9a92;
  --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70;
  --cat-4: #c98500; --cat-5: #d55181; --cat-6: #008300; --cat-7: #9085e9;
  --pos: #3987e5; --neg: #e66767;
  --good: #6fd39a; --good-bg: #173324; --warn: #f2c35b; --warn-bg: #3a2e12;
  --bad: #ff9b91; --bad-bg: #3d1c19; --info-bg: #1b2a3a;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text-primary);
  font: 14px/1.5 Inter, Ubuntu, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { font-family: Montserrat, Inter, sans-serif; margin: 0; letter-spacing: -.01em; }
h1 { font-size: 22px; } h2 { font-size: 16px; } h3 { font-size: 14px; }
a { color: var(--brand-2); }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--text-muted); }
.small { font-size: 12px; }

/* ---------- layout ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10; background: var(--brand); color: #fff;
  display: flex; align-items: center; gap: 16px; padding: 10px 20px;
}
.topbar img { height: 26px; }
.topbar .title { font-family: Montserrat, sans-serif; font-weight: 700; font-size: 15px; opacity: .95; }
.topbar .spacer { flex: 1; }
.topbar .who { font-size: 12px; opacity: .85; }
.topbar button { background: rgba(255,255,255,.12); color: #fff; border: 0; }
.shell { display: grid; grid-template-columns: 210px minmax(0, 1fr); min-height: calc(100vh - 46px); }
nav.side { background: var(--surface-1); border-right: 1px solid var(--border); padding: 14px 10px; }
nav.side a {
  display: block; padding: 8px 12px; border-radius: 8px; color: var(--text-secondary);
  text-decoration: none; font-weight: 500; margin-bottom: 2px;
}
nav.side a:hover { background: var(--surface-2); color: var(--text-primary); }
nav.side a.active { background: var(--info-bg); color: var(--brand-2); font-weight: 600; }
nav.side .group { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-muted); margin: 14px 12px 6px; }
main { padding: 22px 26px 60px; max-width: 1400px; width: 100%; min-width: 0; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head p { margin: 4px 0 0; color: var(--text-secondary); max-width: 760px; }

.grid { display: grid; gap: 14px; }
.kpis { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); margin-bottom: 14px; }
.two { grid-template-columns: repeat(auto-fit, minmax(min(420px, 100%), 1fr)); }
.card { min-width: 0; }
.card {
  background: var(--surface-1); border: 1px solid var(--border); border-radius: 12px;
  padding: 16px 18px; box-shadow: var(--shadow); min-width: 0;
}
.card h2 { margin-bottom: 4px; }
.card .sub { color: var(--text-muted); font-size: 12px; margin-bottom: 12px; }
.kpi .label { font-size: 12px; color: var(--text-secondary); font-weight: 500; }
.kpi .value { font-family: Montserrat, sans-serif; font-size: 24px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi .note { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.kpi.hero { background: var(--brand); color: #fff; border-color: var(--brand); }
.kpi.hero .label, .kpi.hero .note { color: rgba(255,255,255,.78); }

.chart-box { position: relative; height: 320px; }
.chart-box.tall { height: 380px; }
.chart-box.short { height: 240px; }
.legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 12px; color: var(--text-secondary); margin: 2px 0 10px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 14px; height: 4px; border-radius: 2px; display: inline-block; }
.legend i.dash { background: repeating-linear-gradient(90deg, currentColor 0 4px, transparent 4px 7px) !important; height: 2px; }

.callout { border-radius: 10px; padding: 12px 14px; background: var(--info-bg); color: var(--text-primary); font-size: 13px; margin-bottom: 14px; }
.callout.warn { background: var(--warn-bg); }
.callout b { font-weight: 600; }
.callout ul { margin: 6px 0 0 18px; padding: 0; }

/* ---------- tabelas ---------- */
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { padding: 7px 10px; border-bottom: 1px solid var(--grid); text-align: right; white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
th { font-weight: 600; color: var(--text-secondary); font-size: 12px; background: var(--surface-1); position: sticky; top: 0; }
tr.total td { font-weight: 700; border-top: 2px solid var(--border); }
tr.future td { color: var(--text-secondary); font-style: italic; }
tr.current td { background: var(--info-bg); }
td.neg { color: var(--bad); }

.badge { display: inline-block; font-size: 11px; font-weight: 600; padding: 1px 7px; border-radius: 999px; }
.badge.good { background: var(--good-bg); color: var(--good); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.bad { background: var(--bad-bg); color: var(--bad); }
.badge.info { background: var(--info-bg); color: var(--brand-2); }

/* ---------- controles ---------- */
button, .btn {
  font: inherit; font-weight: 600; border-radius: 8px; padding: 8px 14px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface-1); color: var(--text-primary);
}
button.primary { background: var(--brand-2); color: #fff; border-color: var(--brand-2); }
button:disabled { opacity: .55; cursor: default; }
input, select {
  font: inherit; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface-1); color: var(--text-primary); min-width: 0;
}
label { font-size: 12px; font-weight: 600; color: var(--text-secondary); display: block; margin-bottom: 4px; }
.row { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.field { display: flex; flex-direction: column; }
.copy { font-family: ui-monospace, Consolas, monospace; font-size: 12px; word-break: break-all; background: var(--surface-2); padding: 8px; border-radius: 6px; }

/* ---------- login ---------- */
.auth-page { min-height: 100vh; display: grid; place-items: center; background: var(--brand); padding: 16px; }
.auth-card { width: 100%; max-width: 380px; background: var(--surface-1); border-radius: 14px; padding: 28px; box-shadow: 0 10px 40px rgba(0,0,0,.25); }
.auth-card .logo { background: var(--brand); border-radius: 10px; padding: 14px; text-align: center; margin-bottom: 18px; }
.auth-card .logo img { height: 30px; }
.auth-card .field { margin-bottom: 12px; }
.auth-card input { width: 100%; }
.auth-card button { width: 100%; margin-top: 6px; }
.error { color: var(--bad); font-size: 13px; min-height: 18px; margin-top: 8px; }

/* ---------- celular ---------- */
@media (max-width: 860px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  nav.side { display: flex; overflow-x: auto; gap: 4px; padding: 8px 12px; border-right: 0; border-bottom: 1px solid var(--border); }
  nav.side a { white-space: nowrap; margin: 0; }
  nav.side .group { display: none; }
  main { padding: 16px; }
  .two { grid-template-columns: 1fr; }
  .topbar .who { display: none; }
}

/* ---------- impressão (relatório) ---------- */
@media print {
  .topbar, nav.side, .no-print { display: none !important; }
  .shell { display: block; }
  main { padding: 0; max-width: none; }
  body { background: #fff; }
  .card { box-shadow: none; break-inside: avoid; }
}
