:root {
  color-scheme: light;
  --bg: #f6f6f4;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --line: #e4e3df;
  --grid: #ecebe7;
  --text: #0b0b0b;
  --text-2: #52514e;
  --text-3: #7a7974;
  --accent: #2a78d6;
  --accent-ink: #1c5cab;
  --accent-soft: #e6f0fc;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --good: #0ca30c;
  --warning: #fab219;
  --critical: #d03b3b;
  --serious: #ec835a;
  --up: #0a7d0a;
  --down: #c03030;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 1px 1px rgba(0,0,0,.03);
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #121211;
    --surface: #1a1a19;
    --surface-2: #232321;
    --line: #2e2e2b;
    --grid: #2a2a27;
    --text: #f0efec;
    --text-2: #c3c2b7;
    --text-3: #93928a;
    --accent: #3987e5;
    --accent-ink: #86b6ef;
    --accent-soft: #17283d;
    --series-1: #3987e5;
    --series-2: #d95926;
    --up: #3fbf3f;
    --down: #e66767;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  font-variant-numeric: tabular-nums;
}
button, input, select { font: inherit; color: inherit; }
a { color: var(--accent-ink); }
.hidden { display: none !important; }
.muted { color: var(--text-2); }
.small { font-size: 13px; }

/* ---------- Estrutura ---------- */
.app { display: grid; grid-template-columns: 232px 1fr; min-height: 100dvh; }
.side {
  position: sticky; top: 0; height: 100dvh; padding: 20px 14px;
  border-right: 1px solid var(--line); background: var(--surface);
  display: flex; flex-direction: column; gap: 4px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 18px; font-weight: 700; font-size: 17px; }
.brand-mark {
  width: 30px; height: 30px; border-radius: 9px; background: var(--text); color: var(--surface);
  display: grid; place-items: center; font-size: 15px; font-weight: 800; letter-spacing: -.5px;
}
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 10px;
  color: var(--text-2); text-decoration: none; font-weight: 500;
}
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a.active { background: var(--accent-soft); color: var(--accent-ink); }
.nav svg { width: 19px; height: 19px; flex: none; }
.side-foot { margin-top: auto; padding: 10px 12px; font-size: 12px; color: var(--text-3); }

main { min-width: 0; padding: 22px 28px 60px; max-width: 1280px; width: 100%; }
.topbar { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-bottom: 18px; }
.topbar h1 { font-size: 22px; margin: 0; letter-spacing: -.3px; }
.topbar .sub { color: var(--text-2); font-size: 13px; }
.topbar .grow { flex: 1; }

.bottomnav { display: none; }

/* ---------- Controles ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 40px; padding: 0 16px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface); cursor: pointer; font-weight: 600; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--text); color: var(--surface); border-color: var(--text); }
.btn.primary:hover { opacity: .9; }
.btn:disabled { opacity: .55; cursor: default; }
.btn svg { width: 17px; height: 17px; }
.btn.sm { height: 32px; padding: 0 12px; font-size: 13px; }
.btn.ghost { border-color: transparent; background: transparent; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 13px; font-weight: 600; color: var(--text-2); }
.input, select.input {
  height: 42px; padding: 0 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface); outline: none; width: 100%;
}
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.hint { font-size: 12.5px; color: var(--text-3); }

.filters { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 18px; }
.seg { display: inline-flex; background: var(--surface-2); border-radius: 10px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.seg button {
  border: 0; background: transparent; padding: 6px 11px; border-radius: 8px; cursor: pointer;
  font-size: 13px; font-weight: 600; color: var(--text-2);
}
.seg button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.chip {
  display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 10px 0 12px;
  border-radius: 999px; border: 1px solid var(--line); background: var(--surface); font-size: 13px; cursor: pointer;
}
.chip.on { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-ink); font-weight: 600; }
.chip .x { font-size: 15px; line-height: 1; opacity: .7; }
.dates { display: inline-flex; gap: 6px; align-items: center; }
.dates .input { height: 34px; width: 150px; font-size: 13px; }

/* ---------- Cartões ---------- */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow); min-width: 0;
}
.card h2 { font-size: 15px; margin: 0 0 2px; }
.card .desc { color: var(--text-2); font-size: 13px; margin: 0 0 14px; }
.grid { display: grid; gap: 14px; }
.kpis { grid-template-columns: repeat(6, minmax(0, 1fr)); margin-bottom: 14px; }
.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.section { margin-bottom: 14px; }

.kpi { padding: 16px; display: flex; flex-direction: column; gap: 6px; }
.kpi .label { color: var(--text-2); font-size: 13px; font-weight: 500; }
.kpi .value .delta { white-space: nowrap; }
.kpi .value { font-size: 24px; font-weight: 700; letter-spacing: -.5px; line-height: 1.15; }
.kpi .foot { font-size: 12.5px; color: var(--text-3); }
.kpi.hero { background: var(--accent-soft); border-color: transparent; }
.kpi.hero .value { color: var(--accent-ink); }
.delta { font-weight: 600; }
.delta.up { color: var(--up); }
.delta.down { color: var(--down); }

/* Barras horizontais (top SubIDs etc.) */
.hbars { display: flex; flex-direction: column; gap: 10px; }
.hbar { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 10px; cursor: pointer; border-radius: 8px; padding: 2px 4px; margin: 0 -4px; }
.hbar:hover { background: var(--surface-2); }
.hbar .name { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbar .val { font-size: 13px; font-weight: 600; text-align: right; }
.hbar .track { grid-column: 1 / -1; height: 8px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.hbar .fill { height: 100%; background: var(--series-1); border-radius: 0 4px 4px 0; min-width: 2px; }
.hbar .meta { grid-column: 1 / -1; font-size: 12px; color: var(--text-3); }
.none { font-style: italic; color: var(--text-3); }

.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin-bottom: 16px; }
.stat { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; }
.stat .v { font-size: 19px; font-weight: 700; }
.stat .l { font-size: 12px; color: var(--text-2); }

.split { display: flex; height: 12px; border-radius: 6px; overflow: hidden; gap: 2px; margin: 8px 0 10px; background: var(--surface); }
.split > div { height: 100%; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 13px; }
.legend .sw { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.legend b { font-weight: 600; }

/* Gráficos SVG */
.chart { position: relative; width: 100%; }
.chart svg { display: block; width: 100%; overflow: visible; }
.chart .axis text, .chart text.axis { fill: var(--text-3); font-size: 11px; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .baseline { stroke: var(--line); stroke-width: 1; }
.tooltip {
  position: fixed; z-index: 50; pointer-events: none; background: var(--text); color: var(--surface);
  padding: 8px 10px; border-radius: 9px; font-size: 12.5px; line-height: 1.4; box-shadow: 0 6px 20px rgba(0,0,0,.18);
  max-width: 240px; opacity: 0; transition: opacity .08s;
}
.tooltip.show { opacity: 1; }
.tooltip b { font-weight: 700; }

/* Tabela */
.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); max-height: 70vh; }
table { border-collapse: collapse; width: 100%; font-size: 13.5px; }
th, td { padding: 10px 12px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
th { position: sticky; top: 0; background: var(--surface-2); font-weight: 600; color: var(--text-2); cursor: pointer; user-select: none; z-index: 1; }
th.txt, td.txt { text-align: left; }
th.sorted { color: var(--text); }
tbody tr:hover { background: var(--surface-2); }
td.pos { color: var(--up); font-weight: 600; }
td.neg { color: var(--down); font-weight: 600; }
tfoot td { font-weight: 700; background: var(--surface-2); position: sticky; bottom: 0; }
td.stick, th.stick { position: sticky; left: 0; z-index: 2; max-width: 46vw; white-space: normal; box-shadow: 1px 0 0 var(--line); }
td.stick { background: var(--surface); font-size: 13px; }
th.stick { z-index: 3; }
tfoot td.stick { background: var(--surface-2); z-index: 3; }

.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.colpicker { position: relative; }
.colpicker .menu {
  position: absolute; right: 0; top: 44px; z-index: 20; background: var(--surface); border: 1px solid var(--line);
  border-radius: 12px; padding: 8px; box-shadow: 0 10px 30px rgba(0,0,0,.12); min-width: 200px;
}
.colpicker label { display: flex; gap: 8px; align-items: center; padding: 6px 8px; border-radius: 8px; cursor: pointer; font-size: 14px; }
.colpicker label:hover { background: var(--surface-2); }

/* Sincronização */
.sync { display: inline-flex; align-items: center; gap: 10px; font-size: 13px; color: var(--text-2); }
.spin { width: 16px; height: 16px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.banner { display: flex; gap: 12px; align-items: center; padding: 12px 14px; border-radius: 12px; margin-bottom: 14px; font-size: 14px; }
.banner.info { background: var(--accent-soft); color: var(--accent-ink); }
.banner.warn { background: color-mix(in srgb, var(--warning) 18%, var(--surface)); color: var(--text); }
.banner.err { background: color-mix(in srgb, var(--critical) 14%, var(--surface)); color: var(--text); }
.banner .grow { flex: 1; }

.badge { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 999px; background: var(--surface-2); color: var(--text-2); }
.badge .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge.ok { color: var(--up); }
.badge.bad { color: var(--down); }

/* Login */
.auth { min-height: 100dvh; display: grid; place-items: center; padding: 20px; }
.auth .card { width: 100%; max-width: 380px; padding: 28px; }
.auth h1 { font-size: 22px; margin: 14px 0 4px; }
.auth p { margin: 0 0 20px; color: var(--text-2); }
.err { color: var(--down); font-size: 13.5px; min-height: 20px; margin-bottom: 8px; }
.okmsg { color: var(--up); font-size: 13.5px; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--text); color: var(--surface);
  padding: 11px 16px; border-radius: 12px; font-size: 14px; z-index: 60; box-shadow: 0 10px 30px rgba(0,0,0,.2);
}
.secret { font-family: ui-monospace, Menlo, Consolas, monospace; background: var(--surface-2); padding: 10px 12px; border-radius: 10px; font-size: 15px; user-select: all; word-break: break-all; }

.skeleton { background: linear-gradient(90deg, var(--surface-2), var(--grid), var(--surface-2)); background-size: 200% 100%; animation: sh 1.2s infinite; border-radius: 8px; }
@keyframes sh { to { background-position: -200% 0; } }

/* ---------- Responsivo ---------- */
@media (max-width: 1180px) { .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .side { display: none; }
  main { padding: 16px 14px 96px; }
  .cols-2, .cols-3 { grid-template-columns: 1fr; }
  .bottomnav {
    display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 30; background: var(--surface);
    border-top: 1px solid var(--line); padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
  }
  .bottomnav a {
    flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 0;
    color: var(--text-3); text-decoration: none; font-size: 11.5px; font-weight: 600; border-radius: 10px;
  }
  .bottomnav a.active { color: var(--accent-ink); background: var(--accent-soft); }
  .bottomnav svg { width: 22px; height: 22px; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  /* Filtros em uma linha que rola para o lado */
  .filters { flex-wrap: nowrap; overflow-x: auto; margin: 0 -14px 16px; padding: 2px 14px; scrollbar-width: none; }
  .filters::-webkit-scrollbar { display: none; }
  .filters .seg { flex-wrap: nowrap; flex: none; }
  .filters .chip, .filters .dates { flex: none; }
  .topbar .sync { width: 100%; justify-content: space-between; }
}
@media (max-width: 560px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .kpi { padding: 13px; }
  .kpi .value { font-size: 20px; }
  .topbar h1 { font-size: 19px; }
  .dates .input { width: 132px; }
}
@media (forced-colors: active) {
  .hbar .fill, .split > div { forced-color-adjust: none; }
}
