/* Buddy dashboard — one accent color, grey everywhere else; status colors only for status. */
:root {
  color-scheme: light;
  --bg: #f6f6f4;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --border: #e2e1dc;
  --text: #0b0b0b;
  --text-2: #52514e;
  --text-3: #6f6e69;
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --good: #0ca30c;
  --good-ink: #006300;
  --warning: #fab219;
  --warning-ink: #7a5200;
  --serious: #ec835a;
  --critical: #d03b3b;
  --critical-ink: #a32424;
  --focus: #2a78d6;
  --radius: 8px;
  --gap: 16px;
  --font: system-ui, -apple-system, "Segoe UI", "Noto Sans Hebrew", "Arial Hebrew", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121211; --surface: #1a1a19; --surface-2: #232321; --border: #33332f;
    --text: #f0efec; --text-2: #c3c2b7; --text-3: #9d9c93;
    --accent: #3987e5; --good-ink: #5fd35f; --warning-ink: #fab219; --critical-ink: #ff8a8a;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121211; --surface: #1a1a19; --surface-2: #232321; --border: #33332f;
  --text: #f0efec; --text-2: #c3c2b7; --text-3: #9d9c93;
  --accent: #3987e5; --good-ink: #5fd35f; --warning-ink: #fab219; --critical-ink: #ff8a8a;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 15px/1.5 var(--font); }
a { color: var(--accent); }
button, select, input, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.mono, code { font-family: var(--mono); font-size: 0.86em; }
bdi.mono { white-space: nowrap; }
.muted { color: var(--text-2); }
.faint { color: var(--text-3); }
.nowrap { white-space: nowrap; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---- shell ---------------------------------------------------------------- */
.topbar {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 5;
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px; background: var(--surface); border-block-end: 1px solid var(--border);
}
.topbar h1 { font-size: 17px; margin: 0; font-weight: 650; }
.topbar .spacer { flex: 1; }
.topbar .updated { color: var(--text-2); font-size: 13px; }
.topbar select { padding: 4px 8px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); }
nav.tabs {
  display: flex; gap: 2px; overflow-x: auto; padding: 0 12px;
  background: var(--surface); border-block-end: 1px solid var(--border);
  scrollbar-width: thin;
}
nav.tabs button {
  border: 0; background: none; padding: 10px 12px; cursor: pointer; white-space: nowrap;
  color: var(--text-2); border-block-end: 2px solid transparent;
}
nav.tabs button[aria-current="page"] { color: var(--text); border-block-end-color: var(--accent); font-weight: 600; }
nav.tabs .count {
  display: inline-block; min-width: 20px; padding: 0 6px; margin-inline-start: 6px;
  border-radius: 10px; background: var(--critical); color: #fff; font-size: 12px; text-align: center;
}
main { max-width: 1240px; margin: 0 auto; padding: 20px 16px 64px; }
section.screen > h2 { font-size: 20px; margin: 0 0 4px; }
section.screen > .lead { margin: 0 0 18px; color: var(--text-2); }
h3 { font-size: 15px; margin: 24px 0 8px; }

.banner { padding: 10px 14px; border-radius: var(--radius); margin-bottom: 14px; border: 1px solid var(--border); background: var(--surface); }
.banner.error { border-color: var(--critical); }

/* ---- cards & tiles ---------------------------------------------------------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.grid { display: grid; gap: var(--gap); }
.grid.tiles { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.tile .label { color: var(--text-2); font-size: 13px; }
.tile .value { font-size: 26px; font-weight: 650; font-variant-numeric: tabular-nums; margin-top: 2px; }
.tile .context { color: var(--text-2); font-size: 13px; }

/* ---- needs-you queue ----------------------------------------------------------- */
.queue { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.queue > li { display: grid; grid-template-columns: auto 1fr auto; gap: 4px 12px; align-items: start; }
.queue .title { font-weight: 600; }
.queue .meta { grid-column: 2; color: var(--text-2); font-size: 13px; }
.queue .actions { grid-row: 1 / span 2; grid-column: 3; display: flex; gap: 6px; }
.queue .actions .inline { flex-wrap: nowrap; }
.queue .body { grid-column: 2; display: grid; gap: 4px; font-size: 14px; }
.queue .reasons { margin: 0; padding-inline-start: 18px; color: var(--text); }
.critic { line-height: 1.5; }
.pre { white-space: pre-wrap; margin-top: 6px; max-width: 60ch; }
.empty { padding: 18px; text-align: center; color: var(--text-2); background: var(--surface); border: 1px dashed var(--border); border-radius: var(--radius); }

/* ---- status chips: color + icon + word, never color alone ------------------------ */
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px; border-radius: 999px; font-size: 12.5px; white-space: nowrap; border: 1px solid var(--border); background: var(--surface-2); color: var(--text); }
.chip::before { font-weight: 700; }
.chip.good { border-color: var(--good); } .chip.good::before { content: "✓"; color: var(--good-ink); }
.chip.warning { border-color: var(--warning); } .chip.warning::before { content: "!"; color: var(--warning-ink); }
.chip.critical { border-color: var(--critical); } .chip.critical::before { content: "✕"; color: var(--critical-ink); }
.chip.info::before { content: "i"; color: var(--accent); font-style: italic; }
.chip.neutral::before { content: "•"; color: var(--text-3); }
.chip.accent { border-color: var(--accent); } .chip.accent::before { content: "●"; color: var(--accent); font-size: 9px; }

/* ---- tables (cards below 700px) ------------------------------------------------- */
.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: start; padding: 8px 12px; border-block-end: 1px solid var(--border); vertical-align: top; }
th { font-size: 12.5px; font-weight: 600; color: var(--text-2); background: var(--surface-2); position: sticky; top: 0; }
tbody tr:last-child td { border-block-end: 0; }
td.num, th.num { text-align: end; font-variant-numeric: tabular-nums; }
tr.attention td:first-child { box-shadow: inset 3px 0 0 var(--critical); }
[dir="rtl"] tr.attention td:first-child { box-shadow: inset -3px 0 0 var(--critical); }
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 10px; }
.filters input, .filters select { padding: 6px 10px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); min-width: 160px; }

@media (max-width: 700px) {
  table, thead, tbody, tr, td { display: block; }
  thead { display: none; }
  .table-wrap { background: none; border: 0; }
  tbody tr { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 10px; padding: 6px 0; }
  td { border: 0; padding: 4px 12px; display: grid; grid-template-columns: 9.5em 1fr; gap: 8px; }
  td::before { content: attr(data-label); color: var(--text-2); font-size: 12.5px; }
  td.secondary { display: none; }
  td.num { text-align: start; }
  .queue > li { grid-template-columns: auto 1fr; }
  .queue .actions { grid-row: auto; grid-column: 1 / -1; }
  .queue .body { grid-column: 1 / -1; }
  main { padding: 14px 12px 64px; }
  .topbar { gap: 8px; padding: 8px 12px; }
  .topbar .updated { display: none; }
  .topbar select { max-width: 40vw; }
}

/* ---- controls ---------------------------------------------------------------------- */
.btn { border: 1px solid var(--border); background: var(--surface); padding: 5px 12px; border-radius: 6px; cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn:disabled { opacity: .55; cursor: default; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.seg label { padding: 5px 12px; cursor: pointer; border-inline-start: 1px solid var(--border); }
.seg label:first-child { border-inline-start: 0; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg > .btn { border: 0; border-radius: 0; border-inline-start: 1px solid var(--border); }
.seg > .btn:first-child { border-inline-start: 0; }
.seg input:checked + span { font-weight: 650; }
.seg label:has(input:checked) { background: var(--accent); color: var(--accent-ink); }
.seg label:has(input:focus-visible) { outline: 2px solid var(--focus); outline-offset: -2px; }
.toggle { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.toggle input { width: 18px; height: 18px; accent-color: var(--accent); }

.setting { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px 20px; align-items: start; }
.setting + .setting { border-block-start: 1px solid var(--border); padding-block-start: 14px; margin-block-start: 14px; }
.setting .name { font-weight: 600; }
.setting .evidence { grid-column: 1 / -1; font-size: 13px; color: var(--text-2); background: var(--surface-2); padding: 6px 10px; border-radius: 6px; }
@media (max-width: 700px) { .setting { grid-template-columns: 1fr; } }

/* ---- dialog ------------------------------------------------------------------------- */
dialog { border: 1px solid var(--border); border-radius: 10px; padding: 0; background: var(--surface); color: var(--text); width: min(560px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(0, 0, 0, .35); }
dialog form { padding: 18px; display: grid; gap: 12px; }
dialog h3 { margin: 0; }
dialog .row { display: grid; gap: 4px; }
dialog input, dialog select, dialog textarea { padding: 7px 10px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); width: 100%; }
dialog .inline { display: flex; gap: 8px; flex-wrap: wrap; }
dialog .inline > * { flex: 1 1 120px; }
dialog .preview { background: var(--surface-2); border-radius: 6px; padding: 10px 12px; font-size: 14px; }
dialog .buttons { display: flex; gap: 8px; justify-content: flex-end; }
dialog .error { color: var(--critical-ink); margin: 0; }
dialog .error:empty { display: none; }

/* ---- chart ---------------------------------------------------------------------------- */
.chart { position: relative; width: 100%; min-height: 200px; }
.chart svg { display: block; }
.card-title { margin-top: 0; }
.chart .tooltip { position: absolute; pointer-events: none; background: var(--surface); border: 1px solid var(--border); border-radius: 6px; padding: 6px 10px; font-size: 13px; box-shadow: 0 2px 8px rgba(0,0,0,.12); white-space: nowrap; }
details.table-view { margin-top: 8px; font-size: 13px; }
details.table-view summary { cursor: pointer; color: var(--text-2); }

/* ---- login ------------------------------------------------------------------------------ */
body.login { display: grid; place-items: center; min-height: 100vh; }
.login-card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 28px; width: min(360px, calc(100vw - 32px)); display: grid; gap: 12px; }
.login-card h1 { margin: 0; font-size: 22px; }
.login-card label { display: grid; gap: 4px; }
.login-card input { padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); }
.login-card button { padding: 8px; border: 0; border-radius: 6px; background: var(--accent); color: var(--accent-ink); font-weight: 600; cursor: pointer; }
.login-card .error { color: var(--critical-ink); margin: 0; }

td select { padding: 3px 8px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); }
td .inline { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
