/* ---------- tokens (dataviz reference palette; dark mode is its own selected set) ---------- */
:root {
  color-scheme: light;
  --page: #f9f9f7; --surface: #fcfcfb; --surface-2: #f3f2ee;
  --ink: #0b0b0b; --ink-2: #52514e; --muted: #898781;
  --grid: #e1e0d9; --axis: #c3c2b7; --border: rgba(11,11,11,0.10);
  --accent: #2a78d6; --accent-soft: #cde2fb;
  --good: #006300; --bad: #d03b3b; --warn: #b36b00; --critical: #d03b3b;
  --nav-w: 220px; --radius: 12px; --shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 16px rgba(0,0,0,.04);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d; --surface: #1a1a19; --surface-2: #232322;
    --ink: #f0efec; --ink-2: #c3c2b7; --muted: #898781;
    --grid: #2c2c2a; --axis: #383835; --border: rgba(255,255,255,0.10);
    --accent: #3987e5; --accent-soft: #184f95;
    --good: #0ca30c; --bad: #e66767; --warn: #fab219; --critical: #e66767;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d; --surface: #1a1a19; --surface-2: #232322;
  --ink: #f0efec; --ink-2: #c3c2b7; --muted: #898781;
  --grid: #2c2c2a; --axis: #383835; --border: rgba(255,255,255,0.10);
  --accent: #3987e5; --accent-soft: #184f95;
  --good: #0ca30c; --bad: #e66767; --warn: #fab219; --critical: #e66767;
  --shadow: none;
}

/* ---------- base ---------- */
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--page); color: var(--ink); font-size: 15px; line-height: 1.5; direction: rtl;
}
a { color: var(--accent); text-decoration: none; }
button, input, select { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -0.01em; }
h1 { font-size: 24px; } h2 { font-size: 17px; } h3 { font-size: 14px; color: var(--ink-2); font-weight: 600; }
.muted { color: var(--muted); } .small { font-size: 13px; }
.num { font-variant-numeric: tabular-nums; }

/* ---------- layout ---------- */
.layout { display: grid; grid-template-columns: var(--nav-w) 1fr; min-height: 100vh; }
nav.side { background: var(--surface); border-left: 1px solid var(--border); padding: 20px 14px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
nav .brand { font-weight: 700; font-size: 18px; padding: 4px 10px 18px; display: flex; align-items: center; gap: 10px; }
nav .brand .logo { width: 28px; height: 28px; border-radius: 8px; background: var(--accent); display: inline-block; }
nav a.item { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px; color: var(--ink-2); font-weight: 500; }
nav a.item:hover { background: var(--surface-2); }
nav a.item.active { background: var(--accent-soft); color: var(--ink); }
nav .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); flex: none; }
nav .group { margin-top: 14px; padding: 0 10px 6px; font-size: 12px; color: var(--muted); text-transform: none; letter-spacing: .02em; }
nav .status-pill { margin-right: auto; width: 8px; height: 8px; border-radius: 50%; background: var(--axis); }
nav .status-pill.ok { background: var(--good); } nav .status-pill.err { background: var(--critical); } nav .status-pill.manual { background: var(--warn); }
main { padding: 24px 28px 60px; min-width: 0; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.topbar .sub { color: var(--muted); font-size: 13px; margin-top: 2px; }

/* filter row: one row, above everything it scopes */
.filters { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.seg { display: inline-flex; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 3px; }
.seg button { border: 0; background: transparent; padding: 6px 12px; border-radius: 7px; cursor: pointer; color: var(--ink-2); font-weight: 500; }
.seg button.active { background: var(--accent-soft); color: var(--ink); }
.filters input[type=date] { border: 1px solid var(--border); background: var(--surface); border-radius: 8px; padding: 6px 8px; }
.btn { border: 1px solid var(--border); background: var(--surface); border-radius: 8px; padding: 7px 14px; cursor: pointer; font-weight: 500; }
.btn:hover { background: var(--surface-2); } .btn.primary { background: var(--accent); color: #fff; border-color: transparent; }
.btn:disabled { opacity: .5; cursor: default; }

/* ---------- cards & grids ---------- */
.grid { display: grid; gap: 16px; }
.grid.kpis { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); }
.grid.three { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); min-width: 0; }
.card header { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.card header .tools { display: flex; gap: 6px; }
.card header .tools button { border: 0; background: transparent; color: var(--muted); cursor: pointer; font-size: 12px; padding: 2px 6px; border-radius: 6px; }
.card header .tools button:hover, .card header .tools button.active { background: var(--surface-2); color: var(--ink); }
.section { margin: 26px 0 12px; display: flex; align-items: baseline; gap: 12px; }
.section h2 { font-size: 18px; }
.loading main > * { opacity: .55; transition: opacity .2s; }

/* stat tile */
.tile .label { font-size: 13px; color: var(--ink-2); display: flex; align-items: center; gap: 8px; }
.tile .swatch { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.tile .value { font-size: 28px; font-weight: 600; margin-top: 4px; line-height: 1.15; }
.tile .delta { font-size: 13px; margin-top: 4px; display: flex; gap: 6px; align-items: center; }
.tile .delta.up { color: var(--good); } .tile .delta.down { color: var(--bad); } .tile .delta.flat { color: var(--muted); }
.tile .spark { position: relative; height: 36px; margin-top: 10px; }
.tile .spark canvas { display: block; width: 100% !important; height: 36px !important; }
.tile .delta { flex-wrap: wrap; }
.tile .asof { font-size: 11px; color: var(--muted); margin-top: 6px; }
.hero { display: flex; align-items: flex-end; gap: 24px; flex-wrap: wrap; }
.hero .big { font-size: 48px; font-weight: 650; line-height: 1; }
.hero .cap { color: var(--ink-2); font-size: 14px; }

/* charts */
.chart-box { position: relative; height: 280px; }
.chart-box.tall { height: 340px; } .chart-box.short { height: 220px; }
.chart-box canvas { width: 100% !important; height: 100% !important; }
.chart-table { display: none; max-height: 320px; overflow: auto; }
.card.table-mode .chart-box { display: none; } .card.table-mode .chart-table { display: block; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 13px; color: var(--ink-2); margin: 0 0 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.rect { height: 10px; width: 10px; border-radius: 3px; }

/* ranked bars (html) */
.ranked { display: grid; gap: 8px; }
.ranked .row { display: grid; grid-template-columns: minmax(80px, 150px) 1fr 96px; align-items: center; gap: 10px; font-size: 13px; }
.ranked .row .name { color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ranked .row .bar { height: 10px; background: var(--surface-2); border-radius: 5px; overflow: hidden; display: flex; justify-content: flex-start; }
.ranked .row .bar i { display: block; height: 100%; border-radius: 5px 0 0 5px; margin-right: auto; background: var(--accent); }
.ranked .row .val { text-align: left; color: var(--ink); font-variant-numeric: tabular-nums; white-space: nowrap; direction: ltr; }

/* tables */
table.data { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.data th, table.data td { padding: 9px 10px; text-align: right; border-bottom: 1px solid var(--grid); white-space: nowrap; }
table.data th { color: var(--muted); font-weight: 500; font-size: 12px; position: sticky; top: 0; background: var(--surface); cursor: pointer; }
table.data th.sorted { color: var(--ink); }
table.data td.n { font-variant-numeric: tabular-nums; text-align: left; direction: ltr; }
table.data td.title { max-width: 360px; overflow: hidden; text-overflow: ellipsis; }
table.data tr:hover td { background: var(--surface-2); }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 2px 8px; border-radius: 999px; font-size: 12px; background: var(--surface-2); color: var(--ink-2); }
.pill i { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.thumb { width: 44px; height: 28px; object-fit: cover; border-radius: 4px; background: var(--surface-2); vertical-align: middle; margin-left: 8px; }
.segbar { display: flex; height: 8px; border-radius: 4px; overflow: hidden; gap: 2px; background: transparent; min-width: 120px; }
.segbar i { display: block; height: 100%; }

/* status */
.status-card .row { display: flex; justify-content: space-between; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--grid); font-size: 13px; }
.status-card .row:last-child { border: 0; }
.badge { padding: 2px 8px; border-radius: 6px; font-size: 12px; font-weight: 600; }
.badge.ok { background: color-mix(in srgb, var(--good) 15%, transparent); color: var(--good); }
.badge.err { background: color-mix(in srgb, var(--critical) 15%, transparent); color: var(--critical); }
.badge.off { background: var(--surface-2); color: var(--muted); }
.badge.warn { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }
.empty { padding: 40px; text-align: center; color: var(--muted); }
.notice { background: color-mix(in srgb, var(--warn) 12%, transparent); border: 1px solid color-mix(in srgb, var(--warn) 40%, transparent); border-radius: 10px; padding: 12px 16px; margin-bottom: 16px; font-size: 14px; }
.steps { padding-right: 20px; } .steps li { margin: 6px 0; }
code { background: var(--surface-2); padding: 1px 6px; border-radius: 4px; font-size: 13px; direction: ltr; unicode-bidi: embed; }

/* red alert bar (manual imports not updated today) */
#alerts { position: sticky; top: 0; z-index: 20; display: grid; gap: 6px; margin: -24px -28px 20px; }
#alerts:empty { display: none; }
.alert-bar { background: var(--critical); color: #fff; padding: 10px 28px; font-weight: 600; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.alert-bar a { color: #fff; text-decoration: underline; font-weight: 500; margin-right: auto; }
@media (max-width: 860px) { #alerts { margin: -16px -16px 16px; } .alert-bar { padding: 10px 16px; } }

/* responsive */
@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  nav.side { position: static; height: auto; display: flex; flex-wrap: wrap; gap: 4px; padding: 10px; }
  nav .brand { width: 100%; padding-bottom: 8px; } nav .group { display: none; }
  nav a.item { padding: 6px 10px; font-size: 13px; }
  main { padding: 16px; }
  .grid.two, .grid.three { grid-template-columns: 1fr; }
}
