:root {
  color-scheme: light;
  --brand: #0f3d3a;
  --brand-2: #155a54;
  --accent: #c8f169;
  --bg: #f3f5f4;
  --surface-1: #ffffff;
  --surface-2: #f7f8f8;
  --border: #e3e7e6;
  --grid: #eceff0;
  --text-primary: #191919;
  --text-secondary: #5f6664;
  --text-muted: #8a918f;
  --series-1: #257de0;
  --series-2: #f47230;
  --series-3: #00b894;
  --good: #0a7d1d;
  --bad: #c62f30;
  --warn-bg: #fff6df;
  --warn-text: #7a5300;
  --seq-0: #eef5fe; --seq-1: #cce3fd; --seq-2: #9dc8f7; --seq-3: #6aabf1; --seq-4: #338ced; --seq-5: #2370cd; --seq-6: #1757ac; --seq-7: #0e3d7e;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 40, 38, .06), 0 4px 16px rgba(16, 40, 38, .04);
  font-family: 'Montserrat', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --bg: #101413; --surface-1: #191919; --surface-2: #202423; --border: #2c3331; --grid: #2a2f2e;
    --text-primary: #efefef; --text-secondary: #a9b0ae; --text-muted: #7d8583;
    --series-1: #338ced; --series-2: #e76624; --series-3: #00a888;
    --good: #2cc04a; --bad: #eb6263; --warn-bg: #3a2f12; --warn-text: #f5cf73;
    --seq-0: #1d2328; --seq-1: #0e3d7e; --seq-2: #0f4a96; --seq-3: #1757ac; --seq-4: #2370cd; --seq-5: #338ced; --seq-6: #6aabf1; --seq-7: #9dc8f7;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #101413; --surface-1: #191919; --surface-2: #202423; --border: #2c3331; --grid: #2a2f2e;
  --text-primary: #efefef; --text-secondary: #a9b0ae; --text-muted: #7d8583;
  --series-1: #338ced; --series-2: #e76624; --series-3: #00a888;
  --good: #2cc04a; --bad: #eb6263; --warn-bg: #3a2f12; --warn-text: #f5cf73;
  --seq-0: #1d2328; --seq-1: #0e3d7e; --seq-2: #0f4a96; --seq-3: #1757ac; --seq-4: #2370cd; --seq-5: #338ced; --seq-6: #6aabf1; --seq-7: #9dc8f7;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text-primary); font-size: 14px; -webkit-font-smoothing: antialiased; }
button, input, select { font: inherit; color: inherit; }

/* Topo */
.topbar { background: var(--brand); color: #fff; padding: 14px 28px; display: flex; align-items: center; gap: 18px; position: sticky; top: 0; z-index: 10; }
.logo { display: flex; align-items: baseline; gap: 10px; }
.logo b { font-size: 22px; font-weight: 800; letter-spacing: -.5px; }
.logo b i { font-style: normal; color: var(--accent); }
.logo span { font-size: 12px; opacity: .75; font-weight: 500; }
.topbar .spacer { flex: 1; }
.topbar .user { font-size: 13px; opacity: .9; }
.topbar button.ghost { background: transparent; border: 1px solid rgba(255,255,255,.3); color: #fff; padding: 6px 12px; border-radius: 8px; cursor: pointer; }
.topbar button.ghost:hover { background: rgba(255,255,255,.1); }

/* Filtros */
.filters { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; padding: 16px 28px 4px; }
.seg { display: inline-flex; background: var(--surface-1); border: 1px solid var(--border); border-radius: 10px; padding: 3px; }
.seg button { border: 0; background: transparent; padding: 7px 14px; border-radius: 8px; cursor: pointer; font-weight: 600; color: var(--text-secondary); display: inline-flex; align-items: center; gap: 7px; }
.seg button[aria-pressed="true"] { background: var(--brand); color: #fff; }
.seg .dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
select, input[type=date] { background: var(--surface-1); border: 1px solid var(--border); border-radius: 10px; padding: 8px 10px; }
.filters .meta { margin-left: auto; color: var(--text-muted); font-size: 12px; display: flex; align-items: center; gap: 10px; }
.filters .meta button { background: var(--surface-1); border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px; cursor: pointer; }

.banner { margin: 10px 28px 0; padding: 10px 14px; border-radius: 10px; background: var(--warn-bg); color: var(--warn-text); font-size: 13px; }
.banner b { font-weight: 700; }

main { padding: 12px 28px 40px; display: flex; flex-direction: column; gap: 16px; }
main > * { min-width: 0; }
h2.section { font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--text-secondary); margin: 14px 0 0; font-weight: 700; }

/* KPIs */
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; }
.kpi { background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px 12px; box-shadow: var(--shadow); min-height: 112px; display: flex; flex-direction: column; }
.kpi .label { font-size: 12px; color: var(--text-secondary); font-weight: 600; display: flex; justify-content: space-between; gap: 6px; }
.kpi .label .src { font-size: 10px; color: var(--text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: .05em; }
.kpi .value { font-size: 28px; font-weight: 700; letter-spacing: -.5px; margin: 6px 0 4px; font-variant-numeric: tabular-nums; }
.kpi .value small { font-size: 14px; font-weight: 600; color: var(--text-secondary); }
.kpi .delta { font-size: 12px; color: var(--text-muted); margin-top: auto; }
.kpi .delta .up, .kpi .delta .down { font-weight: 700; }
.kpi .delta .good { color: var(--good); }
.kpi .delta .bad { color: var(--bad); }
.kpi.na .value { color: var(--text-muted); font-size: 20px; }

/* Cards */
.grid { display: grid; gap: 16px; grid-template-columns: repeat(12, 1fr); }
.card { background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); min-width: 0; }
.card h3 { margin: 0; font-size: 15px; font-weight: 700; }
.card .sub { color: var(--text-secondary); font-size: 12px; margin: 3px 0 12px; }
.span-4 { grid-column: span 4; } .span-5 { grid-column: span 5; } .span-6 { grid-column: span 6; } .span-7 { grid-column: span 7; } .span-8 { grid-column: span 8; } .span-12 { grid-column: span 12; }
@media (max-width: 1100px) { .span-4, .span-5, .span-6, .span-7, .span-8 { grid-column: span 12; } }
.chart-box { position: relative; height: 260px; }
.chart-box.tall { height: 320px; }
.legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 12px; color: var(--text-secondary); margin-bottom: 8px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 14px; height: 3px; border-radius: 2px; display: inline-block; }
.legend i.sq { width: 10px; height: 10px; border-radius: 3px; }
.empty { color: var(--text-muted); font-size: 13px; padding: 30px 0; text-align: center; }

/* Funil */
.funnel { display: grid; gap: 8px; }
.funnel .row { display: grid; grid-template-columns: 150px 1fr 120px; align-items: center; gap: 10px; }
.funnel .name { font-size: 13px; font-weight: 600; }
.funnel .name small { display: block; font-weight: 500; color: var(--text-muted); font-size: 11px; }
.funnel .bar { height: 30px; background: var(--surface-2); border-radius: 6px; overflow: hidden; }
.funnel .bar > div { height: 100%; background: var(--seq-5); border-radius: 0 4px 4px 0; min-width: 3px; }
.funnel .row:nth-child(1) .bar > div { background: var(--seq-3); }
.funnel .row:nth-child(2) .bar > div { background: var(--seq-4); }
.funnel .row:nth-child(4) .bar > div { background: var(--seq-6); }
.funnel .row:nth-child(5) .bar > div { background: var(--seq-7); }
.funnel .num { font-variant-numeric: tabular-nums; font-weight: 700; font-size: 15px; }
.funnel .num small { font-weight: 500; color: var(--text-muted); font-size: 11px; margin-left: 4px; }

/* Mapa de calor */
.heat { display: grid; grid-template-columns: 34px repeat(19, 1fr); gap: 2px; font-size: 10px; color: var(--text-muted); }
.heat .c { aspect-ratio: 1.6; border-radius: 3px; position: relative; }
.heat .c:hover { outline: 2px solid var(--text-primary); outline-offset: 0; z-index: 2; }
.heat .h { text-align: center; }
.heat .d { display: flex; align-items: center; }
.heat-scale { display: flex; align-items: center; gap: 6px; font-size: 11px; color: var(--text-muted); margin-top: 10px; }
.heat-scale i { width: 18px; height: 10px; border-radius: 2px; display: inline-block; }

/* Barras horizontais */
.hbars { display: grid; gap: 7px; }
.hbars .row { display: grid; grid-template-columns: minmax(120px, 42%) 1fr 48px; gap: 10px; align-items: center; font-size: 12.5px; }
.hbars .lbl { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--text-primary); }
.hbars .track { height: 14px; }
.hbars .track > div { height: 100%; background: var(--series-1); border-radius: 0 4px 4px 0; min-width: 2px; }
.hbars .v { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }

/* Tabela */
table { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
th, td { padding: 9px 10px; text-align: right; border-bottom: 1px solid var(--border); white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
th { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--text-secondary); font-weight: 700; }
tr.total td { font-weight: 700; background: var(--surface-2); }
.table-wrap { overflow-x: auto; }

.tooltip { position: fixed; pointer-events: none; background: #191919; color: #fff; padding: 7px 10px; border-radius: 8px; font-size: 12px; z-index: 50; display: none; box-shadow: 0 4px 14px rgba(0,0,0,.2); }
footer { padding: 0 28px 30px; color: var(--text-muted); font-size: 12px; }
footer .pill { display: inline-block; padding: 2px 8px; border-radius: 99px; background: var(--surface-1); border: 1px solid var(--border); margin-right: 6px; }

.loading { opacity: .55; transition: opacity .2s; pointer-events: none; }

/* Login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; background: var(--brand); padding: 20px; }
.login-card { background: var(--surface-1); border-radius: 18px; padding: 34px 30px; width: 100%; max-width: 380px; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.login-card .logo b { color: var(--brand); font-size: 28px; }
.login-card .logo b i { color: var(--brand-2); }
:root[data-theme="dark"] .login-card .logo b, :root[data-theme="dark"] .login-card .logo b i { color: #fff; }
.login-card p { color: var(--text-secondary); margin: 6px 0 22px; font-size: 13px; }
.login-card label { display: block; font-size: 12px; font-weight: 600; margin: 12px 0 6px; color: var(--text-secondary); }
.login-card input { width: 100%; padding: 11px 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-1); }
.login-card button { width: 100%; margin-top: 20px; padding: 12px; border: 0; border-radius: 10px; background: var(--brand); color: #fff; font-weight: 700; cursor: pointer; }
.login-card .err { color: var(--bad); font-size: 13px; margin-top: 12px; min-height: 18px; }
.login-card .foot { margin-top: 18px; font-size: 11px; color: var(--text-muted); text-align: center; }

/* Estados "aguardando conexão" */
.kpi.na.wait .value { color: var(--text-muted); font-size: 16px; font-weight: 600; }
.kpi.na.err .value { color: var(--bad); font-size: 16px; font-weight: 600; }
.chart-box.waiting canvas { opacity: .15; }
.chart-box.waiting::after, .waiting-box::after { content: 'Aguardando conexão'; position: absolute; inset: 0; display: grid; place-items: center; color: var(--text-muted); font-weight: 600; font-size: 13px; }
.waiting-box { position: relative; min-height: 120px; }
.waiting-box > * { opacity: .12; }
.banner.soft { margin: 0; background: var(--surface-1); color: var(--text-secondary); border: 1px dashed var(--border); }
.banner.soft code { font-size: 12px; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }
.platforms { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.plat { background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 16px; display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; box-shadow: var(--shadow); }
.plat .pn { font-weight: 700; font-size: 13px; }
.plat b { font-size: 18px; font-variant-numeric: tabular-nums; }
.plat small { color: var(--text-muted); font-size: 11px; margin-left: auto; }
.plat.off { background: var(--surface-2); box-shadow: none; }
.plat.off b { color: var(--text-muted); }
@media (max-width: 800px) { .platforms { grid-template-columns: 1fr; } }
