/* 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; } }
