/* boobook app: one stylesheet for desk (PC browser) and phone (mobile web app). */

:root {
  --bg: #f7f5f2;
  --surface: #ffffff;
  --surface-2: #f0ece6;
  --text: #1f1b16;
  --text-2: #5a5148;
  --border: #d9d2c8;
  --accent: #6b4a2b;
  --accent-text: #ffffff;
  --accent-soft: #efe4d8;
  --focus: #1a5fb4;
  --ok: #1e6b34;
  --warning: #8a4b00;
  --failing: #a3161c;
  --nodata: #5f5f5f;
  --silenced: #6d6d6d;
  --live: #1f5f8b;
  --ok-bg: #e3f2e7;
  --warning-bg: #fbecd9;
  --failing-bg: #fbe1e2;
  --nodata-bg: #ececec;
  --silenced-bg: #f1f1f1;
  --live-bg: #e1edf6;
  --chart-line: #1f5f8b;
  --chart-grid: #e2ddd5;
  --radius: 8px;
  --sidebar-w: 220px;
  --topbar-h: 52px;
  --tabbar-h: 60px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15120f;
    --surface: #1f1b17;
    --surface-2: #2a251f;
    --text: #f1ece6;
    --text-2: #bdb3a7;
    --border: #3d362e;
    --accent: #d9b48a;
    --accent-text: #1a1410;
    --accent-soft: #3a2e22;
    --focus: #8ab4f8;
    --ok: #7fd18f;
    --warning: #f2b45c;
    --failing: #ff8a8a;
    --nodata: #b5b5b5;
    --silenced: #a8a8a8;
    --live: #8cc4ec;
    --ok-bg: #1d3323;
    --warning-bg: #3a2a12;
    --failing-bg: #3d1a1b;
    --nodata-bg: #2b2b2b;
    --silenced-bg: #262626;
    --live-bg: #182c3b;
    --chart-line: #8cc4ec;
    --chart-grid: #3a342c;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #15120f;
  --surface: #1f1b17;
  --surface-2: #2a251f;
  --text: #f1ece6;
  --text-2: #bdb3a7;
  --border: #3d362e;
  --accent: #d9b48a;
  --accent-text: #1a1410;
  --accent-soft: #3a2e22;
  --focus: #8ab4f8;
  --ok: #7fd18f;
  --warning: #f2b45c;
  --failing: #ff8a8a;
  --nodata: #b5b5b5;
  --silenced: #a8a8a8;
  --live: #8cc4ec;
  --ok-bg: #1d3323;
  --warning-bg: #3a2a12;
  --failing-bg: #3d1a1b;
  --nodata-bg: #2b2b2b;
  --silenced-bg: #262626;
  --live-bg: #182c3b;
  --chart-line: #8cc4ec;
  --chart-grid: #3a342c;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  -webkit-text-size-adjust: 100%;
}
a { color: var(--accent); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
h1 { font-size: 1.4rem; margin: 0 0 12px; }
h2 { font-size: 1.1rem; margin: 20px 0 8px; }
p { margin: 0 0 10px; }
code, .mono { font-family: ui-monospace, "SF Mono", Consolas, "DejaVu Sans Mono", monospace; font-size: 0.92em; }
.muted { color: var(--text-2); }
.loading { color: var(--text-2); padding: 24px 0; }
.hidden { display: none !important; }

.skip {
  position: absolute; left: 8px; top: -60px; z-index: 100;
  background: var(--accent); color: var(--accent-text); padding: 8px 12px; border-radius: var(--radius);
}
.skip:focus { top: 8px; }

/* ── layout ───────────────────────────────────────────────────────── */
.app { min-height: 100vh; }
.topbar {
  position: sticky; top: 0; z-index: 20;
  height: var(--topbar-h);
  display: flex; align-items: center; gap: 12px;
  padding: 0 16px; padding-top: env(safe-area-inset-top);
  background: var(--accent); color: var(--accent-text);
}
.topbar .brand { font-weight: 700; font-size: 1.05rem; white-space: nowrap; }
.topbar .spacer { flex: 1; }
.topbar .who { font-size: 0.85rem; opacity: 0.9; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar select, .topbar button {
  background: transparent; color: var(--accent-text); border: 1px solid currentColor;
  border-radius: 6px; padding: 4px 8px; font: inherit; font-size: 0.85rem; cursor: pointer;
}
.topbar select option { color: #1f1b16; }

.sidebar {
  position: fixed; top: var(--topbar-h); bottom: 0; left: 0; width: var(--sidebar-w);
  background: var(--surface); border-right: 1px solid var(--border); overflow-y: auto; padding: 8px 0;
}
.sidebar a {
  display: block; padding: 9px 18px; color: var(--text); text-decoration: none;
  border-left: 4px solid transparent;
}
.sidebar a:hover { background: var(--surface-2); }
.sidebar a[aria-current="page"] { background: var(--accent-soft); border-left-color: var(--accent); font-weight: 600; }

.main { margin-left: var(--sidebar-w); padding: 20px 28px 40px; max-width: 1200px; outline: none; }

.tabbar { display: none; }

@media (max-width: 760px) {
  .sidebar { display: none; }
  .main { margin-left: 0; padding: 14px 14px calc(var(--tabbar-h) + 24px + env(safe-area-inset-bottom)); }
  .topbar .who, .topbar .wide-only { display: none; }
  .tabbar {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
    height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    background: var(--surface); border-top: 1px solid var(--border);
  }
  .tabbar a {
    flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
    color: var(--text-2); text-decoration: none; font-size: 0.78rem; gap: 2px; position: relative;
  }
  .tabbar a .ico { font-size: 1.2rem; line-height: 1; }
  .tabbar a[aria-current="page"] { color: var(--accent); font-weight: 600; }
  .tabbar .badge-count {
    position: absolute; top: 6px; right: calc(50% - 22px);
    background: var(--failing); color: #fff; border-radius: 9px; font-size: 0.7rem; padding: 0 5px; min-width: 18px; text-align: center;
  }
}

/* signed-out: no navigation */
.app.signed-out .sidebar, .app.signed-out .tabbar { display: none; }
.app.signed-out .main { margin-left: 0; max-width: 460px; margin-right: auto; margin-left: auto; }

/* ── pieces ───────────────────────────────────────────────────────── */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; }
.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.grow { flex: 1; }
.crumbs { font-size: 0.85rem; color: var(--text-2); margin-bottom: 6px; }
.crumbs a { color: var(--text-2); }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; margin-bottom: 16px; }
.tile { border-radius: var(--radius); padding: 12px 14px; border: 1px solid var(--border); background: var(--surface); }
.tile .n { font-size: 1.8rem; font-weight: 700; line-height: 1.1; }
.tile.ok { background: var(--ok-bg); } .tile.warning { background: var(--warning-bg); }
.tile.failing { background: var(--failing-bg); } .tile.nodata { background: var(--nodata-bg); }

.status {
  display: inline-flex; align-items: center; gap: 5px; white-space: nowrap;
  font-size: 0.85rem; font-weight: 600; padding: 1px 8px; border-radius: 999px;
}
.status .sym { font-size: 0.9em; }
.status.ok { color: var(--ok); background: var(--ok-bg); }
.status.warning { color: var(--warning); background: var(--warning-bg); }
.status.failing { color: var(--failing); background: var(--failing-bg); }
.status.nodata { color: var(--nodata); background: var(--nodata-bg); }
.status.silenced { color: var(--silenced); background: var(--silenced-bg); }
.status.live { color: var(--live); background: var(--live-bg); }

.level {
  display: inline-block; font-size: 0.78rem; font-weight: 600; padding: 1px 8px; border-radius: 4px;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
}
.level.regulated { border-color: var(--live); color: var(--live); }
.level.standard { border-color: var(--warning); color: var(--warning); }

table.list { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
table.list th, table.list td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
table.list th { font-size: 0.82rem; color: var(--text-2); font-weight: 600; background: var(--surface-2); }
table.list tr:last-child td { border-bottom: 0; }
table.list tr.clickable { cursor: pointer; }
table.list tr.clickable:hover td { background: var(--surface-2); }

@media (max-width: 760px) {
  table.list.stack, table.list.stack tbody, table.list.stack tr, table.list.stack td { display: block; width: 100%; }
  table.list.stack thead { display: none; }
  table.list.stack tr { border-bottom: 1px solid var(--border); padding: 8px 4px; }
  table.list.stack tr:last-child { border-bottom: 0; }
  table.list.stack td { border: 0; padding: 3px 8px; }
  table.list.stack td[data-label]::before { content: attr(data-label) ": "; color: var(--text-2); font-size: 0.82rem; }
  table.list.stack td.primary::before { content: none; }
  table.list.stack td.primary { font-weight: 600; }
}

button, .btn {
  font: inherit; cursor: pointer; border-radius: 6px; padding: 8px 14px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  min-height: 40px;
}
.btn { display: inline-flex; align-items: center; text-decoration: none; }
button.primary, .btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }
button.danger { color: var(--failing); border-color: var(--failing); }
button:disabled { opacity: 0.55; cursor: not-allowed; }
button.big { width: 100%; padding: 12px; font-size: 1.02rem; }
.segmented { display: inline-flex; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.segmented button { border: 0; border-radius: 0; min-height: 34px; padding: 4px 12px; }
.segmented button[aria-pressed="true"] { background: var(--accent); color: var(--accent-text); }

label { display: block; font-weight: 600; margin: 10px 0 4px; }
input, select, textarea {
  font: inherit; width: 100%; padding: 8px 10px; border-radius: 6px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
}
.help { font-size: 0.85rem; color: var(--text-2); margin-top: 4px; }
.error-text { color: var(--failing); font-weight: 600; }
.notice { padding: 10px 12px; border-radius: var(--radius); background: var(--warning-bg); color: var(--text); margin-bottom: 12px; }
.notice.info { background: var(--live-bg); }
.notice.ok { background: var(--ok-bg); }

.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; }
.kv dt { color: var(--text-2); }
.kv dd { margin: 0; font-weight: 600; }

.words { font-size: 1.4rem; font-weight: 700; letter-spacing: 0.02em; padding: 12px; text-align: center; background: var(--accent-soft); border-radius: var(--radius); }
.codebox { font-family: ui-monospace, Consolas, monospace; word-break: break-all; background: var(--surface-2); padding: 8px 10px; border-radius: 6px; }

.suggest { border-left: 4px solid var(--ok); padding: 8px 12px; margin: 8px 0; background: var(--surface-2); border-radius: 0 6px 6px 0; }
.suggest .call { font-family: ui-monospace, Consolas, monospace; font-weight: 700; }
ul.check { padding-left: 20px; margin: 4px 0; }

.chart { width: 100%; height: auto; display: block; }
.chart text { fill: var(--text-2); font-size: 13px; font-family: system-ui, sans-serif; }
.chart .grid { stroke: var(--chart-grid); stroke-width: 1; }
.chart .line { fill: none; stroke: var(--chart-line); stroke-width: 2; }
.chart .area { fill: var(--chart-line); opacity: 0.12; }
.charts { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); gap: 12px; }
.charts figure.card { margin: 0; }

.bar { height: 8px; background: var(--surface-2); border-radius: 4px; overflow: hidden; min-width: 80px; }
.bar > span { display: block; height: 100%; background: var(--ok); }
.bar.warning > span { background: var(--warning); }
.bar.failing > span { background: var(--failing); }

.morelist a { display: flex; justify-content: space-between; padding: 14px 4px; border-bottom: 1px solid var(--border); color: var(--text); text-decoration: none; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: 24px; z-index: 50;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: var(--radius);
  max-width: 90vw; opacity: 0; pointer-events: none; transition: opacity 0.2s;
}
.toast.show { opacity: 1; }
@media (max-width: 760px) { .toast { bottom: calc(var(--tabbar-h) + 16px + env(safe-area-inset-bottom)); } }

.install-hint { display: flex; gap: 10px; align-items: center; background: var(--live-bg); padding: 10px 12px; border-radius: var(--radius); margin-bottom: 12px; }
.install-hint p { margin: 0; flex: 1; }

.offline-banner { background: var(--warning-bg); padding: 8px 12px; border-radius: var(--radius); margin-bottom: 12px; }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* ── v2 screens ───────────────────────────────────────────────────── */
:root { --tier0: #1e6b34; --tier1: #2e7d32; --tier2: #9a5800; --tier3: #a3161c; --tier4: #111111; --term-fg: #e5e5e5; --term-bg: #111111; }
:root[data-theme="dark"] { --tier0: #7fd18f; --tier1: #8fdc9a; --tier2: #f2b45c; --tier3: #ff8a8a; --tier4: #f1ece6; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --tier0: #7fd18f; --tier1: #8fdc9a; --tier2: #f2b45c; --tier3: #ff8a8a; --tier4: #f1ece6; } }
:root[data-contrast="high"] { --text-2: var(--text); --border: var(--text); }
:root[data-contrast="high"] .status, :root[data-contrast="high"] .level { outline: 1px solid currentColor; }

.skeleton { padding: 8px 0; }
.sk-line { height: 14px; border-radius: 4px; background: var(--surface-2); margin: 10px 0; }
.sk-line.w1 { width: 70%; } .sk-line.w2 { width: 90%; } .sk-line.w3 { width: 50%; }
.empty { padding: 8px 0; }
details > summary { cursor: pointer; color: var(--text-2); }
.center { text-align: center; }
label.inline { display: inline; font-weight: 400; margin: 0; }
input[type="checkbox"] { width: auto; min-width: 22px; min-height: 22px; }
fieldset { border: 1px solid var(--border); border-radius: 6px; margin: 12px 0; padding: 8px 12px; }
legend { font-weight: 600; padding: 0 4px; }
.ok-text { color: var(--ok); font-weight: 600; }
.greyed { opacity: 0.6; }
.notice.unreachable { background: var(--nodata-bg); }
.notice.sealed { background: var(--surface-2); border: 1px dashed var(--border); }
ul.plain { list-style: none; padding: 0; margin: 4px 0; }
ul.plain li { padding: 4px 0; }
.section { margin-bottom: 8px; }
.me { font-weight: 700; text-decoration: underline; }
a.btn.big, .btn.big { width: 100%; justify-content: center; padding: 12px; margin: 6px 0; }

/* tiers: green for observe and routine, orange for change, red for emergency, black for agreed */
.tier { display: inline-block; font-size: 0.78rem; font-weight: 700; padding: 1px 8px; border-radius: 4px; border: 1px solid currentColor; white-space: nowrap; }
.tier.t0 { color: var(--tier0); } .tier.t1 { color: var(--tier1); } .tier.t2 { color: var(--tier2); }
.tier.t3 { color: var(--tier3); } .tier.t4 { color: var(--bg); background: var(--tier4); border-color: var(--tier4); }
.tiergroup { border-left: 4px solid var(--border); padding-left: 12px; margin: 14px 0; }
.tiergroup.t0 { border-color: var(--tier0); } .tiergroup.t1 { border-color: var(--tier1); } .tiergroup.t2 { border-color: var(--tier2); }
.tiergroup.t3 { border-color: var(--tier3); } .tiergroup.t4 { border-color: var(--tier4); }
ul.calls { list-style: none; padding: 0; margin: 0; }
ul.calls li { padding: 8px 0; border-bottom: 1px solid var(--border); }
ul.calls li a { font-weight: 600; }
ul.calls li.disabled a { color: var(--text-2); }
code.big { font-size: 1.15rem; font-weight: 700; }

/* tabs within a screen */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin: 4px 0 14px; overflow-x: auto; }
.tabs a { padding: 8px 14px; text-decoration: none; color: var(--text-2); border-bottom: 3px solid transparent; white-space: nowrap; min-height: 44px; display: inline-flex; align-items: center; }
.tabs a[aria-current="page"] { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }

/* home */
.tile.approval { background: var(--live-bg); text-decoration: none; color: var(--text); }
.needs h2 { margin-top: 0; }
ul.needlist { list-style: none; padding: 0; margin: 0 0 12px; }
ul.needlist li { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: space-between; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); margin-bottom: 8px; }
ul.needlist li.failing { border-left: 4px solid var(--failing); }
.shift { color: var(--text-2); }

/* inbox lists */
ul.inbox { list-style: none; padding: 0; margin: 0; }
ul.inbox li { padding: 10px 4px; border-bottom: 1px solid var(--border); }
ul.inbox li a { text-decoration: none; color: var(--text); }
ul.inbox li.unread a strong { color: var(--accent); }

/* requests */
.fp { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 10px; margin: 10px 0; }
.fpcode { font-size: 1.3rem; font-weight: 700; letter-spacing: 0.06em; text-align: center; padding: 12px; background: var(--surface-2); border-radius: var(--radius); }
.words.inline { display: inline-block; font-size: 1rem; padding: 2px 8px; }
pre.output { background: var(--term-bg); color: var(--term-fg); padding: 10px; border-radius: 6px; overflow: auto; max-height: 50vh; white-space: pre-wrap; font: 0.85rem/1.35 ui-monospace, Consolas, "DejaVu Sans Mono", monospace; }
.stop { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.stop input { max-width: 320px; }
ul.changes li { padding: 4px 0; }
ul.changes li.owneronly { font-weight: 600; }
.consent { border-left: 4px solid var(--live); }

/* shell */
.shellbar { position: sticky; top: var(--topbar-h); z-index: 10; display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: center; padding: 8px 12px; background: var(--live-bg); color: var(--text); border-radius: var(--radius) var(--radius) 0 0; font-size: 0.88rem; }
.shellbar .rec { color: var(--failing); font-weight: 700; }
.shellbar .left { margin-left: auto; font-weight: 600; }
.termbox { position: relative; margin-bottom: 12px; }
.term { background: var(--term-bg); color: var(--term-fg); font: 14px/1.25 ui-monospace, "SF Mono", Consolas, "DejaVu Sans Mono", monospace; padding: 6px; overflow: auto; max-height: 70vh; outline: none; white-space: pre; }
.term:focus-within, .term:focus { box-shadow: 0 0 0 3px var(--focus); }
.term-row { min-height: 1.25em; }
.term-cursor { background: var(--term-fg); color: var(--term-bg); }
.term-b { font-weight: 700; } .term-dim { opacity: 0.6; } .term-u { text-decoration: underline; }
.term-phone { font-size: 12px; overflow-x: auto; }
.term-phone .term-rows { width: 80ch; }
.term-input { position: absolute; left: 0; top: 0; width: 1px; height: 1px; opacity: 0; border: 0; padding: 0; resize: none; }
.phonekeys { display: flex; gap: 4px; padding: 6px 0; position: sticky; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); background: var(--bg); }
.phonekeys button { flex: 1; min-height: 44px; padding: 4px; font-family: ui-monospace, monospace; }
.phonekeys button[aria-pressed="true"] { background: var(--accent); color: var(--accent-text); }
.player { margin-top: 8px; }
.player progress { flex: 1; min-width: 120px; }
.player select { width: auto; }

/* releases */
.wave .progressbar { height: 8px; background: var(--surface-2); border-radius: 4px; overflow: hidden; margin: 8px 0; }
.wave .progressbar span { display: block; height: 100%; background: var(--ok); }
code.hash { font-size: 0.8rem; }

/* audit */
.filters { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px 12px; align-items: end; }
.filters label { margin-top: 0; }
.verified { background: var(--ok-bg); color: var(--ok); font-weight: 700; padding: 10px 12px; border-radius: var(--radius); margin-bottom: 12px; }
.verify { margin-bottom: 8px; }

/* pairing */
.qrbox { display: flex; justify-content: center; padding: 16px; background: #fff; border-radius: var(--radius); margin: 10px 0; }
.qrbox svg { max-width: 100%; height: auto; }
video.scanner { width: 100%; max-width: 360px; border-radius: var(--radius); }

/* chrome additions */
.sidebar hr { border: 0; border-top: 1px solid var(--border); margin: 8px 12px; }
.sidebar a.minor { font-size: 0.9rem; padding: 6px 18px; color: var(--text-2); }
.sidebar .badge-count { background: var(--failing); color: #fff; border-radius: 9px; font-size: 0.72rem; padding: 0 6px; margin-left: 6px; }
.live-dot { width: 10px; height: 10px; border-radius: 50%; background: rgba(255,255,255,0.35); flex: none; }
.live-dot.up { background: #7fd18f; }
.offline-banner { position: sticky; top: var(--topbar-h); z-index: 15; }
@media (max-width: 760px) {
  .shellbar { top: var(--topbar-h); font-size: 0.8rem; }
  .fp { grid-template-columns: 1fr; }
  .filters { grid-template-columns: 1fr 1fr; }
}
