/* Genie dashboard (formerly Buddy) — one accent color, grey everywhere else; status colors only for status.
   Mobile-first in practice: the owner reads it on a phone. Below 700px: tables become cards, the screens move to a
   bottom tab bar (+ "more" sheet), every control is at least 44px and every input 16px (no iOS zoom). RTL via logical
   properties only. Heebo when installed or vendored at /static/fonts/heebo.woff2 (strict CSP: no font CDNs). */
@font-face {
  font-family: "Heebo";
  src: local("Heebo"), local("Heebo Regular"), url("/static/fonts/heebo.woff2") format("woff2");
  font-weight: 100 900;
  font-display: swap;
}
: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;
  --tap: 44px;
  --topbar-h: 61px;
  --bottom-nav-h: 0px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --font: "Heebo", 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; }
[hidden] { display: none !important; }                  /* .icon-btn and the banner set display; hidden must still win */
html, body { margin: 0; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body { background: var(--bg); color: var(--text); font: 15px/1.5 var(--font); -webkit-tap-highlight-color: transparent; }
a { color: var(--accent); }
button, select, input, textarea { font: inherit; color: inherit; }
input, select, textarea { font-size: 16px; }            /* below 16px iOS zooms the page on focus */
: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; }
.inline { display: flex; flex-wrap: wrap; gap: 6px 8px; align-items: center; }
.stack { display: grid; gap: 12px; }

/* ---- shell ---------------------------------------------------------------- */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 12px;
  padding: calc(8px + var(--safe-top)) 16px 8px; background: var(--surface); border-block-end: 1px solid var(--border);
  padding-inline: max(16px, env(safe-area-inset-left, 0px)) max(16px, env(safe-area-inset-right, 0px));
}
.topbar h1 { font-size: 17px; margin: 0; font-weight: 650; }
.topbar .brand { display: inline-flex; align-items: center; gap: 8px; }
.topbar .brand img { border-radius: 7px; flex: none; }
.topbar .spacer { flex: 1; }
.topbar .updated { color: var(--text-2); font-size: 13px; }
.topbar select { min-height: var(--tap); padding: 4px 8px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); min-width: 0; }
.topbar .btn { min-height: var(--tap); }
.icon-btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-width: var(--tap); }
.icon-btn svg { flex: none; }
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; min-height: var(--tap); padding: 10px 12px; cursor: pointer; white-space: nowrap;
  color: var(--text-2); border-block-end: 2px solid transparent; transition: color .15s, border-color .15s;
}
nav.tabs button[aria-current="page"] { color: var(--text); border-block-end-color: var(--accent); font-weight: 600; }
.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; line-height: 20px; text-align: center;
  font-variant-numeric: tabular-nums;
}
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; }

/* bottom tab bar + "more" sheet: phone only */
.bottom-nav { display: none; }
.sheet-list { list-style: none; margin: 0; padding: 4px 0; }
.sheet-list button {
  display: flex; align-items: center; gap: 12px; width: 100%; min-height: 52px; padding: 0 20px; border: 0; background: none;
  text-align: start; cursor: pointer; transition: background-color .15s;
}
.sheet-list button:active, .sheet-list button:hover { background: var(--surface-2); }
.sheet-list button[aria-current="page"] { color: var(--accent); font-weight: 600; }
.sheet-list .label { flex: 1; }
.sheet-list svg { color: var(--text-2); flex: none; }
.sheet-list button[aria-current="page"] svg { color: var(--accent); }
.sheet-head { display: flex; align-items: center; gap: 8px; padding-block: 8px; padding-inline: 20px 12px; border-block-end: 1px solid var(--border); }
.sheet-head h3 { margin: 0; flex: 1; font-size: 17px; }
.sheet-foot { display: flex; align-items: center; gap: 12px; padding: 12px 20px calc(12px + var(--safe-bottom)); border-block-start: 1px solid var(--border); }
.sheet-foot .updated { flex: 1; color: var(--text-2); font-size: 13px; }

/* install banner (app.js renderInstall): phone only; the top bar's install button covers wide screens */
.install-banner { display: none; }
@media (max-width: 700px) {
  .install-banner {
    position: fixed; z-index: 7; inset-inline: 12px; inset-block-end: calc(var(--bottom-nav-h) + var(--safe-bottom) + 12px);
    display: flex; align-items: center; gap: 12px; padding: 12px; padding-inline-end: 8px;
    background: var(--surface); border: 1px solid var(--border); border-radius: 16px; box-shadow: 0 8px 24px rgba(0, 0, 0, .14);
  }
  .install-banner img { border-radius: 10px; flex: none; }
  .install-banner .text { flex: 1; min-width: 0; display: grid; gap: 2px; font-size: 14px; line-height: 1.35; }
  .install-banner .text .muted { font-size: 13px; }
  .install-banner .btn { flex: none; }
}
@media (max-width: 700px) and (prefers-reduced-motion: no-preference) {
  .install-banner { animation: install-in .35s ease-out; }
  @keyframes install-in { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
}

.banner { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; padding: 10px 14px; border-radius: var(--radius); margin-block-end: 14px; border: 1px solid var(--border); background: var(--surface); }
.banner.error { border-color: var(--critical); }
.banner .grow { flex: 1 1 200px; }

/* first paint: a skeleton instead of a blank screen */
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .45; } }
.boot { display: grid; gap: 12px; }
.boot .bar { display: block; height: 12px; border-radius: 6px; background: var(--surface-2); animation: pulse 1.4s ease-in-out infinite; }
.boot > .bar:first-child { height: 20px; }
.boot .w40 { width: 40%; } .boot .w50 { width: 50%; } .boot .w60 { width: 60%; } .boot .w70 { width: 70%; }
.boot-card { display: grid; gap: 10px; padding: 16px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
@media (prefers-reduced-motion: reduce) { .boot .bar { animation: none; } }

/* ---- 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)); }
.card .grid.tiles { margin-block-start: 12px; }
.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 minmax(0, 1fr) auto; gap: 4px 12px; align-items: start; }
.queue .title { font-weight: 600; overflow-wrap: anywhere; }
.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); }
.queue .body bdi.mono { white-space: normal; overflow-wrap: anywhere; }
.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); max-width: 100%; }
.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-block-end: 10px; }
.filters input, .filters select { min-height: var(--tap); padding: 6px 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); min-width: 160px; }

/* ---- launches: the owner reads these tables with the first column (API cost) on the left -------- */
@media (min-width: 701px) {
  .ltr-cols table { direction: ltr; }
  .ltr-cols th, .ltr-cols td { direction: rtl; }
  [dir="ltr"] .ltr-cols th, [dir="ltr"] .ltr-cols td { direction: ltr; }
}
.ltr-cols td .btn, .empty-state .btn { min-height: var(--tap); min-width: var(--tap); }
.ltr-cols td .chip { margin-block-start: 4px; }
.empty-state { display: grid; justify-items: center; gap: 8px; padding: 24px 16px; }
.empty-state .icon { font-size: 28px; line-height: 1; color: var(--text-3); }
.empty-state h4 { margin: 0; font-size: 16px; color: var(--text); }
.empty-state p { margin: 0; max-width: 40ch; }

/* ---- controls ---------------------------------------------------------------------- */
.btn { border: 1px solid var(--border); background: var(--surface); padding: 5px 12px; border-radius: 8px; cursor: pointer; white-space: nowrap;
  transition: background-color .15s, opacity .15s, transform .1s; }
.btn:hover { background: var(--surface-2); }
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn:disabled { opacity: .55; cursor: default; transform: none; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg label { display: inline-flex; align-items: center; justify-content: center; min-height: 36px; padding: 5px 12px; cursor: pointer;
  border-inline-start: 1px solid var(--border); transition: background-color .15s, color .15s; }
.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; min-height: var(--tap); min-width: var(--tap); }
.toggle input { width: 22px; height: 22px; margin: 0; accent-color: var(--accent); }
details > summary { cursor: pointer; }

.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; }

/* ---- dialog ------------------------------------------------------------------------- */
dialog { border: 1px solid var(--border); border-radius: 12px; padding: 0; background: var(--surface); color: var(--text);
  width: min(560px, calc(100vw - 32px)); max-height: calc(100dvh - 32px); overflow: auto; }
dialog::backdrop { background: rgba(0, 0, 0, .35); }
dialog form { padding: 18px; display: grid; gap: 12px; }
dialog h3 { margin: 0; overflow-wrap: anywhere; }
dialog .row { display: grid; gap: 4px; }
dialog input, dialog select, dialog textarea { min-height: var(--tap); padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); width: 100%; }
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 .buttons .btn { min-height: var(--tap); min-width: 88px; }
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-card { margin-block-start: var(--gap); }
.findings { margin: 12px 0 0; padding-inline-start: 18px; display: grid; gap: 6px; overflow-wrap: anywhere; }
.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 { color: var(--text-2); }

/* ---- login ------------------------------------------------------------------------------ */
body.login { display: grid; place-items: center; min-height: 100vh; min-height: 100dvh; padding: 16px; }
.login-card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 28px 24px; width: min(380px, 100%); display: grid; gap: 14px; }
.login-card h1 { margin: 0; font-size: 24px; }
.login-logo { border-radius: 14px; }
.login-card p { margin: 0; }
.login-card label { display: grid; gap: 6px; color: var(--text-2); font-size: 14px; }
.login-card input { min-height: 48px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text); font-size: 16px; }
.login-card button { min-height: 48px; padding: 8px; border: 0; border-radius: 8px; background: var(--accent); color: var(--accent-ink); font-weight: 600; cursor: pointer;
  transition: opacity .15s, transform .1s; }
.login-card button:active { transform: scale(.98); }
.login-card .error { color: var(--critical-ink); margin: 0; }

td select { min-height: 36px; padding: 3px 8px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); }
td .inline { gap: 6px; }

/* ---- phone ---------------------------------------------------------------------------------- */
@media (max-width: 700px) {
  :root { --bottom-nav-h: 60px; }
  .wide-only { display: none !important; }
  .btn-label { display: none; }
  .topbar { gap: 8px; padding-inline: max(12px, env(safe-area-inset-left, 0px)) max(12px, env(safe-area-inset-right, 0px)); }
  .topbar .updated { display: none; }
  .topbar select { max-width: 46vw; }
  nav.tabs { display: none; }
  main { padding: 14px 12px calc(32px + var(--bottom-nav-h) + var(--safe-bottom)); }
  section.screen > h2 { font-size: 22px; }

  .bottom-nav {
    position: fixed; inset-inline: 0; inset-block-end: 0; z-index: 6;
    display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
    padding-block-end: var(--safe-bottom); background: var(--surface); border-block-start: 1px solid var(--border);
  }
  .bottom-nav button {
    position: relative; display: grid; justify-items: center; align-content: center; gap: 2px; min-height: var(--bottom-nav-h);
    padding: 6px 2px; border: 0; background: none; color: var(--text-2); font-size: 12px; line-height: 1.2; cursor: pointer;
    transition: color .15s;
  }
  .bottom-nav button[aria-current="page"] { color: var(--accent); font-weight: 600; }
  .bottom-nav .label { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .bottom-nav .count { position: absolute; inset-block-start: 4px; inset-inline-start: calc(50% + 6px); margin: 0; }
  .bottom-nav .dot { position: absolute; inset-block-start: 8px; inset-inline-start: calc(50% + 8px); width: 8px; height: 8px; border-radius: 50%; background: var(--critical); }
  dialog.sheet {
    width: 100%; max-width: 100%; margin: auto 0 0; max-height: 85dvh; border-radius: 16px 16px 0 0; border-block-end: 0;
  }

  .btn { min-height: var(--tap); padding: 8px 14px; }
  .filters input, .filters select { width: 100%; min-width: 0; }
  td select { min-height: var(--tap); }
  .seg { display: flex; width: 100%; }
  .seg label, .seg > .btn { flex: 1 1 0; min-height: var(--tap); white-space: normal; text-align: center; line-height: 1.25; }
  details > summary { min-height: var(--tap); padding-block: 10px; }
  .chip { white-space: normal; overflow-wrap: anywhere; }
  bdi.mono { white-space: normal; overflow-wrap: anywhere; }

  .grid { gap: 12px; }
  .grid.tiles { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
  .tile .value { font-size: 24px; }

  table, thead, tbody, tr, td { display: block; }
  thead { display: none; }
  .table-wrap { background: none; border: 0; overflow: visible; }
  tbody tr { display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); margin-block-end: 10px; padding: 8px 0; }
  tbody tr.attention { border-inline-start: 3px solid var(--critical); }
  tr.attention td:first-child, [dir="rtl"] tr.attention td:first-child { box-shadow: none; }
  td { border: 0; padding: 5px 14px; display: grid; grid-template-columns: minmax(6.5em, 34%) minmax(0, 1fr); gap: 10px; align-items: baseline; overflow-wrap: anywhere; }
  td::before { content: attr(data-label); color: var(--text-2); font-size: 12.5px; }
  td.secondary { color: var(--text-2); font-size: 14px; }
  td.num { text-align: start; }
  /* launch cards: the launch's name is the card's title, the API cost right under it */
  .ltr-cols td:last-child { order: -1; display: block; padding-block: 4px 6px; border-block-end: 1px solid var(--border); margin-block-end: 4px; }
  .ltr-cols td:last-child::before { content: none; }

  .queue > li { grid-template-columns: auto minmax(0, 1fr); padding: 14px; }
  .queue .meta { grid-column: 1 / -1; order: 1; }
  .queue .body { grid-column: 1 / -1; order: 2; }
  .queue .actions { grid-row: auto; grid-column: 1 / -1; order: 3; margin-block-start: 6px; }
  .queue .actions > .btn, .queue .actions .inline, .queue .actions .inline > .btn { flex: 1 1 0; }
  .queue .actions .inline { display: flex; gap: 8px; }

  .setting { grid-template-columns: minmax(0, 1fr); }
  dialog .buttons .btn { flex: 1 1 0; }
  .chart .tooltip { white-space: normal; max-width: 180px; }
}
@media (max-width: 700px) and (prefers-reduced-motion: no-preference) {
  dialog.sheet[open] { animation: sheet-in .2s ease-out; }
  @keyframes sheet-in { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
}
