:root {
  --bg: #f4f4f2; --surface: #fcfcfb; --surface-2: #f0efec; --line: #e2e1dc; --ink: #0b0b0b; --ink-2: #52514e; --ink-3: #75746f;
  --accent: #0f766e; --accent-ink: #ffffff; --series-1: #0f766e;
  --good: #0a7d0a; --good-bg: #e6f4e6; --warn: #8a5a00; --warn-bg: #fdf2dc; --bad: #b42a2a; --bad-bg: #fbe7e7;
  --info-bg: #e6f4f1; --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.05);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121211; --surface: #1a1a19; --surface-2: #232321; --line: #33332f; --ink: #f0efec; --ink-2: #c3c2b7; --ink-3: #9a998f;
    --accent: #34bfae; --accent-ink: #042f2e; --series-1: #34bfae;
    --good: #5fd35f; --good-bg: #16301a; --warn: #f2c25a; --warn-bg: #352a12; --bad: #f08a8a; --bad-bg: #3a1a1a;
    --info-bg: #10282a; --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #121211; --surface: #1a1a19; --surface-2: #232321; --line: #33332f; --ink: #f0efec; --ink-2: #c3c2b7; --ink-3: #9a998f;
  --accent: #34bfae; --accent-ink: #042f2e; --series-1: #34bfae;
  --good: #5fd35f; --good-bg: #16301a; --warn: #f2c25a; --warn-bg: #352a12; --bad: #f08a8a; --bad-bg: #3a1a1a;
  --info-bg: #10282a; --shadow: none; color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif; }
a { color: var(--accent); text-decoration: none; } a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0 0 4px; letter-spacing: -.01em; } h2 { font-size: 16px; margin: 0 0 10px; } h3 { font-size: 14px; margin: 0 0 8px; }
p { margin: 0 0 10px; }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; }
.boot { padding: 40px; color: var(--ink-3); }
.muted { color: var(--ink-2); } .small { font-size: 12.5px; } .faint { color: var(--ink-3); }
.grow { flex: 1; min-width: 0; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.stack > * + * { margin-top: 16px; }

/* shell */
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.side { background: var(--surface); border-right: 1px solid var(--line); padding: 18px 12px; display: flex; flex-direction: column; gap: 2px; position: sticky; top: 0; height: 100vh; }
.brand { font-weight: 700; font-size: 15px; padding: 4px 10px 16px; display: flex; gap: 8px; align-items: center; }
.brand .mark { width: 22px; height: 22px; flex: none; }   /* the Tapscribe logo */
.nav { display: block; padding: 8px 10px; border-radius: 8px; color: var(--ink-2); font-weight: 500; }
.nav:hover { background: var(--surface-2); text-decoration: none; color: var(--ink); }
.nav.on { background: var(--info-bg); color: var(--ink); }
.side .who { margin-top: auto; padding: 10px; border-top: 1px solid var(--line); font-size: 12.5px; }
.main { padding: 24px 28px 60px; max-width: 1180px; width: 100%; }
.pagehead { display: flex; gap: 12px; align-items: flex-end; margin-bottom: 18px; flex-wrap: wrap; }
.topbar { display: none; }

/* cards, tables */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); }
.pad { padding: 16px 18px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; }
.tile { padding: 14px 16px; }
a.tile { color: inherit; display: block; } a.tile:hover { text-decoration: none; border-color: var(--accent); }
.tile .k { color: var(--ink-2); font-size: 12.5px; } .tile .v { font-size: 26px; font-weight: 650; letter-spacing: -.02em; margin-top: 2px; }
.tile .s { color: var(--ink-3); font-size: 12px; }
.tablewrap { overflow-x: auto; }
table.list { width: 100%; border-collapse: collapse; }
table.list th { text-align: left; font-size: 12px; font-weight: 600; color: var(--ink-2); padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.list td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.list tr:last-child td { border-bottom: 0; }
table.list tr.click { cursor: pointer; } table.list tr.click:hover td { background: var(--surface-2); }
.num { text-align: right; white-space: nowrap; }
.empty { padding: 28px; text-align: center; color: var(--ink-3); }

/* badges & alerts: status always with a word, never colour alone */
.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--surface-2); color: var(--ink-2); white-space: nowrap; }
.badge.good { background: var(--good-bg); color: var(--good); } .badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.bad { background: var(--bad-bg); color: var(--bad); } .badge.info { background: var(--info-bg); color: var(--ink); }
.alert { padding: 10px 14px; border-radius: 10px; margin-bottom: 12px; background: var(--info-bg); }
.alert.warn { background: var(--warn-bg); } .alert.bad { background: var(--bad-bg); color: var(--bad); }

/* forms */
button, .btn { font: inherit; font-weight: 550; padding: 7px 14px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); cursor: pointer; display: inline-block; }
button:hover, .btn:hover { background: var(--surface-2); text-decoration: none; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); } button.primary:hover { filter: brightness(1.08); }
button.danger { color: var(--bad); } button.ghost { border-color: transparent; background: transparent; }
button:disabled { opacity: .55; cursor: default; }
label.field { display: block; margin-bottom: 12px; } label.field > span { display: block; font-weight: 600; font-size: 13px; margin-bottom: 4px; }
label.field small { display: block; color: var(--ink-3); margin-top: 3px; }
input, select, textarea { font: inherit; width: 100%; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); }
input:focus, select:focus, textarea:focus, button:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
textarea { min-height: 90px; resize: vertical; }
label.check { display: flex; gap: 8px; align-items: flex-start; margin: 6px 0; font-weight: 400; } label.check input { width: auto; margin-top: 3px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.search { max-width: 300px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; border-radius: 0; border-right: 1px solid var(--line); padding: 6px 12px; }
.seg button:last-child { border-right: 0; } .seg button.on { background: var(--info-bg); }

/* sign-in */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.auth .card { width: 100%; max-width: 400px; padding: 26px; }
.qr { background: #fff; padding: 8px; border-radius: 8px; display: inline-block; margin: 6px 0 10px; }
.qr svg { display: block; width: 220px; height: 220px; }   /* the SVG has a viewBox (no fixed size): the whole code scales to fit */
.secret { font-family: ui-monospace, Menlo, monospace; background: var(--surface-2); padding: 10px 12px; border-radius: 8px; word-break: break-all; user-select: all; }

/* modal, toast, tooltip */
.backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.35); display: grid; place-items: center; padding: 16px; z-index: 20; }
.modal { width: 100%; max-width: 480px; max-height: calc(100vh - 32px); overflow: auto; padding: 22px; }
.modal .actions, .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; flex-wrap: wrap; }
#toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 9px 16px; border-radius: 10px; opacity: 0; transition: opacity .2s; pointer-events: none; z-index: 30; }
#toast.on { opacity: 1; }
#tip { position: fixed; pointer-events: none; background: var(--surface); color: var(--ink); border: 1px solid var(--line); box-shadow: 0 4px 16px rgba(0,0,0,.15); border-radius: 8px; padding: 6px 10px; font-size: 12.5px; display: none; z-index: 40; white-space: nowrap; }

/* charts */
.chart svg { display: block; width: 100%; height: 150px; overflow: visible; }
.chart .bar { fill: var(--series-1); } .chart .bar.dim { opacity: .35; }
.chart .hit { fill: transparent; cursor: default; }
.chart .axis { stroke: var(--line); stroke-width: 1; } .chart .grid { stroke: var(--line); stroke-width: 1; stroke-dasharray: 2 4; }
.chart text { fill: var(--ink-3); font-size: 11px; }
.chart details { margin-top: 8px; font-size: 12.5px; } .chart details summary { cursor: pointer; color: var(--ink-2); }
.charts { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
dl.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; } dl.kv dt { color: var(--ink-2); } dl.kv dd { margin: 0; }

@media (max-width: 820px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 30% 0 0; z-index: 25; height: 100vh; transform: translateX(-102%); transition: transform .2s; }
  .side.open { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.3); }
  .main { padding: 14px 16px 60px; }
  .topbar { display: block; padding: 12px 16px 0; }
  .grid2, .charts { grid-template-columns: 1fr; }
  .search { max-width: none; }
}
table.list select { width: auto; min-width: 120px; }
pre.script { font-family: ui-monospace, Menlo, monospace; font-size: 12px; background: var(--surface-2); padding: 10px 12px; border-radius: 8px; overflow: auto; max-height: 50vh; white-space: pre; margin: 8px 0 0; }
.err { color: var(--bad); }
