/* ניהולפון — the design system.
   One type scale, one spacing scale, one neutral ramp, one accent. Built for
   a wide screen first, because that is where the work happens, and folded
   down to a phone rather than the other way round. No build step and no
   framework: on a service facing the internet, every dependency is a supply
   chain somebody has to keep watching. */

:root {
  /* neutrals: one ramp, used for every surface, line and text */
  --n-0:  #ffffff;
  --n-25: #fbfcfd;
  --n-50: #f5f7f9;
  --n-100:#eceff3;
  --n-200:#dfe4ea;
  --n-300:#c6ced8;
  --n-500:#6b7787;
  --n-600:#4d5866;
  --n-800:#232c38;
  --n-900:#141b24;

  --bg: var(--n-50);
  --surface: var(--n-0);
  --surface-2: var(--n-50);
  --surface-3: var(--n-100);
  --line: var(--n-200);
  --line-strong: var(--n-300);
  --ink: var(--n-900);
  --ink-2: var(--n-600);
  --ink-3: var(--n-500);

  --brand: #0e7c74;
  --brand-hover: #0a6660;
  --brand-ink: #ffffff;
  --brand-soft: #e3f3f1;
  --brand-line: #a9dbd5;

  --ok: #0a7c48;
  --ok-soft: #e6f6ee;
  --warn: #9a6400;
  --warn-soft: #fdf3e2;
  --danger: #b3251c;
  --danger-soft: #fdeceb;

  /* type scale */
  --t-xs: .72rem;
  --t-sm: .81rem;
  --t-md: .89rem;
  --t-base: 1rem;
  --t-lg: 1.15rem;
  --t-xl: 1.45rem;
  --t-2xl: 2rem;

  --s1: 4px;  --s2: 8px;  --s3: 12px; --s4: 16px;
  --s5: 24px; --s6: 32px; --s7: 48px; --s8: 64px;

  --r-sm: 6px;
  --r: 10px;
  --r-lg: 16px;
  --r-full: 999px;

  --shadow-sm: 0 1px 2px rgba(20, 27, 36, .05);
  --shadow: 0 1px 3px rgba(20, 27, 36, .07), 0 8px 24px -8px rgba(20, 27, 36, .12);
  --shadow-lg: 0 24px 64px -16px rgba(20, 27, 36, .28);

  --rail: 232px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans Hebrew",
          "Arial Hebrew", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --n-0:  #121820;
    --n-25: #161d26;
    --n-50: #0d1219;
    --n-100:#1c242e;
    --n-200:#2a3440;
    --n-300:#3a4653;
    --n-500:#8593a3;
    --n-600:#a7b4c2;
    --n-800:#dde4ec;
    --n-900:#eef2f6;

    --bg: #0d1219;
    --surface: #121820;
    --surface-2: #161d26;
    --surface-3: #1c242e;
    --line: #232d38;
    --line-strong: #323d4a;

    --brand: #2fb6a8;
    --brand-hover: #43c6b8;
    --brand-ink: #062522;
    --brand-soft: #10302d;
    --brand-line: #1d4a45;

    --ok: #56cc8f;
    --ok-soft: #10281d;
    --warn: #e0ab55;
    --warn-soft: #2a2114;
    --danger: #f3928a;
    --danger-soft: #2c1917;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3);
    --shadow: 0 1px 3px rgba(0, 0, 0, .4), 0 8px 24px -8px rgba(0, 0, 0, .5);
    --shadow-lg: 0 24px 64px -16px rgba(0, 0, 0, .7);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: var(--t-base);
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
}
bdi { unicode-bidi: isolate; }
h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -.012em; }
::selection { background: var(--brand-soft); color: var(--ink); }

/* ── boot ──────────────────────────────────────────────────────────────── */
.boot { display: grid; place-items: center; min-height: 100dvh; }
.spinner {
  width: 26px; height: 26px; border-radius: 50%;
  border: 2.5px solid var(--line); border-top-color: var(--brand);
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ── the gate ──────────────────────────────────────────────────────────── */
.gate { min-height: 100dvh; display: grid; place-items: center; padding: var(--s5) var(--s4); }
.gate > div { width: 100%; max-width: 400px; animation: rise .35s ease both; }
.card-gate {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow);
  padding: var(--s6) var(--s5) var(--s5);
}
.brand { display: flex; align-items: center; gap: var(--s3); margin-bottom: var(--s5); }
.brand svg { width: 40px; height: 40px; border-radius: 11px; flex: none; }
.brand b { font-size: var(--t-lg); }
.brand span { display: block; font-size: var(--t-sm); color: var(--ink-3); font-weight: 400; }

/* ── the shell ─────────────────────────────────────────────────────────── */
.shell { display: grid; grid-template-columns: var(--rail) 1fr; min-height: 100dvh; }
.rail {
  background: var(--surface);
  border-inline-start: 1px solid var(--line);
  padding: var(--s4);
  display: flex; flex-direction: column; gap: var(--s5);
  position: sticky; top: 0; height: 100dvh;
}
.rail .brand { margin: var(--s2) var(--s2) 0; }
.rail nav { display: flex; flex-direction: column; gap: 2px; }
.rail nav button {
  display: flex; align-items: center; gap: var(--s3);
  width: 100%; text-align: start;
  padding: 9px var(--s3);
  border: 0; background: none; border-radius: var(--r-sm);
  color: var(--ink-2); font: inherit; font-size: var(--t-md); font-weight: 550;
  cursor: pointer;
}
.rail nav button:hover { background: var(--surface-3); color: var(--ink); }
.rail nav button.on { background: var(--brand-soft); color: var(--brand); }
.rail nav .ico { width: 18px; text-align: center; font-size: 1rem; opacity: .9; }
.rail .foot { margin-top: auto; border-top: 1px solid var(--line); padding-top: var(--s3); }
.rail .foot b { display: block; font-size: var(--t-md); }
.rail .foot span { display: block; font-size: var(--t-xs); color: var(--ink-3); margin-bottom: var(--s2); }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: baseline; gap: var(--s3);
  padding: var(--s5) var(--s6) var(--s4);
}
.topbar h1 { font-size: var(--t-xl); }
.topbar p { margin: 0; color: var(--ink-3); font-size: var(--t-md); }
.content { padding: 0 var(--s6) var(--s7); flex: 1; animation: rise .25s ease both; }

/* ── controls ──────────────────────────────────────────────────────────── */
button, .as-button {
  font: inherit; font-weight: 600; font-size: var(--t-md);
  border-radius: var(--r-sm); border: 1px solid transparent;
  padding: 8px var(--s4); cursor: pointer;
  transition: background .12s, border-color .12s, opacity .12s;
}
button:disabled { opacity: .5; cursor: default; }
.primary { background: var(--brand); color: var(--brand-ink); }
.primary:not(:disabled):hover { background: var(--brand-hover); }
.ghost { background: var(--surface); color: var(--ink-2); border-color: var(--line); }
.ghost:hover { background: var(--surface-3); color: var(--ink); }
.wide { width: 100%; }
a.as-button { display: inline-block; text-align: center; text-decoration: none; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

.field { margin-bottom: var(--s4); }
.field label { display: block; font-size: var(--t-sm); font-weight: 600; margin-bottom: 6px; }
input[type="text"], input[type="email"], input[type="password"], input[type="search"], select {
  width: 100%; padding: 9px var(--s3);
  font: inherit; font-size: 16px;            /* 16px: iOS zooms anything smaller */
  color: var(--ink); background: var(--surface-2);
  border: 1px solid var(--line); border-radius: var(--r-sm);
  transition: border-color .12s, box-shadow .12s;
}
input:focus-visible, select:focus-visible {
  outline: none; border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-soft);
}

.msg { border-radius: var(--r-sm); padding: 10px var(--s3); font-size: var(--t-md); margin-bottom: var(--s4); }
.msg.error { background: var(--danger-soft); color: var(--danger); }
.msg.info { background: var(--brand-soft); color: var(--brand); }
.foot-note { text-align: center; color: var(--ink-3); font-size: var(--t-xs); margin-top: var(--s5); }

/* ── metric cards ──────────────────────────────────────────────────────── */
.metrics { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--s3); margin-bottom: var(--s5); }
.metric {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r); padding: var(--s4); min-width: 0;
}
.metric .k { font-size: var(--t-sm); color: var(--ink-3); display: block; margin-bottom: 2px; }
.metric .v {
  font-size: var(--t-2xl); font-weight: 680; letter-spacing: -.03em;
  font-variant-numeric: tabular-nums; line-height: 1.1;
}
.metric .d { font-size: var(--t-xs); color: var(--ink-3); }
.metric .d.up { color: var(--ok); }
.metric .d.down { color: var(--danger); }
.metric.alert .v { color: var(--danger); }

/* ── panel ─────────────────────────────────────────────────────────────── */
.panel {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r); overflow: hidden; margin-bottom: var(--s5);
}
.panel > header {
  display: flex; align-items: center; gap: var(--s3);
  padding: var(--s4); border-bottom: 1px solid var(--line);
}
.panel > header h2 { font-size: var(--t-md); }
.panel > header .grow { flex: 1; }
.panel .body { padding: var(--s4); }

/* ── filters ───────────────────────────────────────────────────────────── */
.filters { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2); padding: var(--s3) var(--s4); }
.seg { display: inline-flex; background: var(--surface-3); border-radius: var(--r-sm); padding: 2px; }
.seg button {
  border: 0; background: none; padding: 5px var(--s3);
  font-size: var(--t-sm); font-weight: 600; color: var(--ink-3); border-radius: 5px;
}
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-sm); }
.filters .search { width: 190px; padding: 6px var(--s3); font-size: var(--t-md); }
.filters select { width: auto; padding: 6px var(--s3); font-size: var(--t-md); }
.filters .grow { flex: 1; }
.kbd {
  font: inherit; font-size: var(--t-xs); font-family: var(--mono);
  border: 1px solid var(--line); border-bottom-width: 2px;
  border-radius: 4px; padding: 0 5px; color: var(--ink-3);
}

/* ── the table ─────────────────────────────────────────────────────────── */
.tablewrap { overflow-x: auto; }
table.log { width: 100%; border-collapse: collapse; font-size: var(--t-md); }
table.log thead th {
  position: sticky; top: 0; z-index: 2;
  background: var(--surface-2);
  text-align: start; font-size: var(--t-xs); font-weight: 650;
  color: var(--ink-3); letter-spacing: .02em;
  padding: 9px var(--s3); border-bottom: 1px solid var(--line); white-space: nowrap;
}
table.log td { padding: 0 var(--s3); border-bottom: 1px solid var(--line); height: 46px; }
table.log tbody tr { cursor: pointer; }
table.log tbody tr:hover td { background: var(--surface-2); }
table.log tbody tr.on td { background: var(--brand-soft); }
table.log tr.daybreak td {
  height: 30px; background: var(--surface-2); color: var(--ink-3);
  font-size: var(--t-xs); font-weight: 650; cursor: default;
}
table.log tr.daybreak:hover td { background: var(--surface-2); }
.num { font-variant-numeric: tabular-nums; }
.dim { color: var(--ink-3); }
td.who b { font-weight: 600; }
td.who span { display: block; font-size: var(--t-xs); color: var(--ink-3); }

.dir { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; font-size: var(--t-sm); }
.dir i {
  width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center;
  font-style: normal; font-size: .82rem; background: var(--surface-3); color: var(--ink-2);
}
.dir.in i { background: var(--brand-soft); color: var(--brand); }
.dir.out i { background: var(--surface-3); color: var(--ink-2); }
.dir.miss i { background: var(--danger-soft); color: var(--danger); }

.pill {
  display: inline-block; padding: 2px 9px; border-radius: var(--r-full);
  font-size: var(--t-xs); font-weight: 600;
  background: var(--surface-3); color: var(--ink-2);
}
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.miss { background: var(--danger-soft); color: var(--danger); }
.pill.vm { background: var(--warn-soft); color: var(--warn); }

.tablefoot {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--s3); padding: var(--s3) var(--s4); border-top: 1px solid var(--line);
  font-size: var(--t-sm); color: var(--ink-3);
}
.empty { padding: var(--s8) var(--s5); text-align: center; color: var(--ink-3); }
.empty h2 { color: var(--ink); font-size: var(--t-lg); margin-bottom: var(--s2); }
.empty p { margin: 0 auto; max-width: 44ch; font-size: var(--t-md); }
.loading { padding: var(--s8); text-align: center; color: var(--ink-3); font-size: var(--t-md); }
.skel { height: 46px; border-bottom: 1px solid var(--line);
  background: linear-gradient(90deg, var(--surface) 0%, var(--surface-2) 50%, var(--surface) 100%);
  background-size: 200% 100%; animation: sweep 1.2s linear infinite; }
@keyframes sweep { to { background-position: -200% 0; } }

/* ── charts (inline SVG, no dependency) ────────────────────────────────── */
.chart { width: 100%; height: auto; display: block; overflow: visible; }
.chart .bar { fill: var(--brand); }
.chart .bar.miss { fill: var(--danger); }
.chart .axis { fill: var(--ink-3); font-size: 10px; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.heat rect { stroke: var(--surface); stroke-width: 2; rx: 3; }
.heat text { fill: var(--ink-3); font-size: 10px; }
.legend { display: flex; align-items: center; gap: var(--s2); font-size: var(--t-xs); color: var(--ink-3); }
.legend i { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }

/* ── the drawer ────────────────────────────────────────────────────────── */
.scrim { position: fixed; inset: 0; background: rgba(13, 18, 25, .45); z-index: 30; animation: fade .18s ease both; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.drawer {
  position: fixed; z-index: 31; inset-block: 0; inset-inline-start: 0;
  width: min(440px, 94vw); overflow-y: auto;
  background: var(--surface); border-inline-end: 1px solid var(--line);
  box-shadow: var(--shadow-lg);
  padding: var(--s5);
  animation: slide .22s cubic-bezier(.2, .8, .2, 1) both;
}
@keyframes slide { from { transform: translateX(-24px); opacity: .4; } to { transform: none; opacity: 1; } }
.drawer header { display: flex; align-items: flex-start; gap: var(--s3); margin-bottom: var(--s5); }
.drawer header h2 { font-size: var(--t-lg); flex: 1; }
.drawer header .sub { font-size: var(--t-sm); color: var(--ink-3); }
.pairs { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s2); margin-bottom: var(--s5); }
.pairs > div { background: var(--surface-2); border-radius: var(--r-sm); padding: var(--s2) var(--s3); }
.pairs span { display: block; font-size: var(--t-xs); color: var(--ink-3); }
.pairs b { font-size: var(--t-md); font-variant-numeric: tabular-nums; }
.drawer h3 { font-size: var(--t-sm); color: var(--ink-3); margin: var(--s5) 0 var(--s2); }
.stages { list-style: none; margin: 0; padding: 0; }
.stages li {
  position: relative; padding: 0 var(--s4) var(--s3) 0;
  border-inline-end: 2px solid var(--line); margin-inline-end: 5px;
}
.stages li::before {
  content: ""; position: absolute; inset-inline-end: -6px; top: 6px;
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--surface); border: 2px solid var(--line-strong);
}
.stages li:last-child { border-inline-end-color: transparent; }
.stages b { font-size: var(--t-md); }
.stages i { display: block; font-style: normal; font-size: var(--t-xs); color: var(--ink-3); }
.player audio { width: 100%; height: 38px; margin-top: var(--s2); }

/* ── narrow ────────────────────────────────────────────────────────────── */
@media (max-width: 1080px) {
  :root { --rail: 68px; }
  .rail .brand b, .rail .brand span, .rail nav button span.lbl, .rail .foot b, .rail .foot span { display: none; }
  .rail nav button { justify-content: center; padding: 10px 0; }
  .rail .brand { justify-content: center; }
  .topbar, .content { padding-inline: var(--s5); }
}
@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .rail {
    position: sticky; top: 0; z-index: 10; height: auto;
    flex-direction: row; align-items: center; gap: var(--s2);
    border-inline-start: 0; border-bottom: 1px solid var(--line);
    padding: var(--s2) var(--s3); padding-top: max(var(--s2), env(safe-area-inset-top));
  }
  .rail nav { flex-direction: row; flex: 1; }
  .rail .foot { margin: 0; border: 0; padding: 0; }
  .topbar { padding: var(--s4) var(--s4) var(--s3); }
  .content { padding: 0 var(--s4) var(--s7); }
  .metrics { grid-template-columns: repeat(2, 1fr); }
  .filters .search { width: 100%; }
  .pairs { grid-template-columns: 1fr; }
  /* the table folds into rows that still read as a list */
  table.log thead { display: none; }
  table.log, table.log tbody, table.log tr, table.log td { display: block; width: 100%; }
  table.log tbody tr { border-bottom: 1px solid var(--line); padding: var(--s2) 0; }
  table.log td { height: auto; border: 0; padding: 1px var(--s3); }
  table.log td.hide-sm { display: none; }
  table.log tr.daybreak td { height: auto; padding: 6px var(--s3); }
  .drawer { inset-inline: 0; inset-block: auto 0; width: auto; max-height: 88dvh;
            border-radius: var(--r-lg) var(--r-lg) 0 0; border: 0; }
}
