:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --panel-2: #f0f1f4;
  --side: #eceef2;
  --text: #15171b;
  --muted: #5b626d;
  --line: rgba(16, 22, 32, .11);
  --line-strong: rgba(16, 22, 32, .2);
  --accent: #5b4bf5;
  --accent-ink: #ffffff;
  --accent-soft: rgba(91, 75, 245, .1);
  --ok: #138a52;
  --warn: #a15c00;
  --danger: #c92a2a;
  --danger-soft: rgba(201, 42, 42, .09);
  --focus: var(--accent);
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 22, 32, .06), 0 4px 14px rgba(16, 22, 32, .05);
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d0f12; --panel: #15181c; --panel-2: #1b1f24; --side: #111317; --text: #e8eaee; --muted: #9aa2ad;
    --line: rgba(255, 255, 255, .08); --line-strong: rgba(255, 255, 255, .16); --accent: #8f84ff; --accent-ink: #0e0a2e;
    --accent-soft: rgba(143, 132, 255, .14); --ok: #3ccf8e; --warn: #f0b44c; --danger: #ff6b6b; --danger-soft: rgba(255, 107, 107, .1);
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 6px 18px rgba(0, 0, 0, .25); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0d0f12; --panel: #15181c; --panel-2: #1b1f24; --side: #111317; --text: #e8eaee; --muted: #9aa2ad;
  --line: rgba(255, 255, 255, .08); --line-strong: rgba(255, 255, 255, .16); --accent: #8f84ff; --accent-ink: #0e0a2e;
  --accent-soft: rgba(143, 132, 255, .14); --ok: #3ccf8e; --warn: #f0b44c; --danger: #ff6b6b; --danger-soft: rgba(255, 107, 107, .1);
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 6px 18px rgba(0, 0, 0, .25); color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
::selection { background: var(--accent-soft); color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 6px; }
a { color: var(--accent); text-underline-offset: 3px; }
h1, h2, h3 { margin: 0; letter-spacing: -.01em; text-wrap: balance; }
h1 { font-size: 20px; font-weight: 680; }
h2 { font-size: 15px; font-weight: 650; }
p { margin: 0; }
.muted { color: var(--muted); }
.num { font-variant-numeric: tabular-nums; }
.mono { font-family: var(--mono); font-size: 12.5px; }
.ic { width: 16px; height: 16px; flex: none; display: block; }
* { scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent; }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: 232px minmax(0, 1fr); min-height: 100vh; }
.side { background: var(--side); border-right: 1px solid var(--line); padding: 14px 10px; display: flex; flex-direction: column; gap: 14px; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 8px; padding: 4px 8px; font-weight: 720; letter-spacing: -.01em; }
.brand .ic { color: var(--accent); width: 18px; height: 18px; }
.sitepick { display: grid; gap: 6px; padding: 0 4px; }
.sitepick label { font-size: 11.5px; font-weight: 650; color: var(--muted); padding-left: 2px; }
.nav { display: grid; gap: 1px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: 8px; color: var(--muted); text-decoration: none; font-weight: 550; }
.nav a:hover { background: var(--panel-2); color: var(--text); }
.nav a[aria-current="page"] { background: var(--panel); color: var(--text); box-shadow: var(--shadow); }
.nav a[aria-current="page"] .ic { color: var(--accent); }
.nav-sep { height: 1px; background: var(--line); margin: 6px 8px; }
.side-foot .role { font-size: 12px; color: var(--muted); }
.nav .count { margin-left: auto; font-size: 12px; font-variant-numeric: tabular-nums; color: var(--muted); }
.side-foot { margin-top: auto; display: grid; gap: 4px; padding: 0 4px; font-size: 13px; }
.side-foot .who { color: var(--muted); padding: 0 6px; }
.main { min-width: 0; padding: 24px 28px 48px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 20px; align-content: start; max-width: 1240px; }
.pagehead { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.pagehead p { color: var(--muted); margin-top: 3px; max-width: 72ch; }

/* ---------- surfaces ---------- */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.panel > .ph { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.panel > .pb { padding: 16px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.stat { padding: 12px 16px; border-left: 1px solid var(--line); }
.stat:first-child { border-left: 0; }
.stat dt { color: var(--muted); font-size: 12.5px; }
.stat dd { margin: 2px 0 0; font-size: 20px; font-weight: 650; font-variant-numeric: tabular-nums; }
.live-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--ok); margin-right: 6px; vertical-align: 1px; }

/* ---------- tables ---------- */
.tablewrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th { text-align: left; font-weight: 600; color: var(--muted); font-size: 12.5px; padding: 9px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; background: var(--panel); }
td { padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: color-mix(in oklab, var(--panel-2) 60%, transparent); }
td.actions { text-align: right; white-space: nowrap; }
td.user { white-space: nowrap; }
td.actions .btn + .btn { margin-left: 4px; }
td.msgbody { max-width: 460px; overflow-wrap: anywhere; }
tr.deleted td.msgbody { color: var(--muted); text-decoration: line-through; }
tr.expand td { background: var(--panel-2); }
.nowrap { white-space: nowrap; }

/* ---------- controls ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 32px; padding: 0 12px;
  border-radius: 8px; border: 1px solid var(--line-strong); background: var(--panel); color: var(--text);
  font: inherit; font-weight: 600; font-size: 13px; cursor: pointer; transition: background .15s, border-color .15s, color .15s; white-space: nowrap;
}
.btn:hover:not(:disabled) { background: var(--panel-2); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.primary:hover:not(:disabled) { background: color-mix(in oklab, var(--accent) 88%, black); }
.btn.danger { color: var(--danger); }
.btn.danger:hover:not(:disabled) { background: var(--danger-soft); border-color: color-mix(in oklab, var(--danger) 45%, transparent); }
.btn.armed { background: var(--danger); color: #fff; border-color: transparent; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover:not(:disabled) { background: var(--panel-2); }
.btn.sm { height: 28px; padding: 0 9px; font-size: 12.5px; }
.btn.loading { color: transparent !important; position: relative; }
.btn.loading::after { content: ""; position: absolute; width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--muted); border-top-color: transparent; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--panel); border: 1px solid var(--line-strong); border-radius: 8px;
  padding: 0 10px; height: 34px; min-width: 0; transition: border-color .15s, box-shadow .15s;
}
textarea { height: auto; padding: 8px 10px; resize: vertical; }
input::placeholder, textarea::placeholder { color: var(--muted); opacity: 1; }
input:focus, select:focus, textarea:focus { outline: 0; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input[type="checkbox"] { height: 16px; width: 16px; accent-color: var(--accent); margin: 0; }
input[type="color"] { padding: 2px; width: 44px; }
.field { display: grid; gap: 5px; }
.field > span { font-size: 12.5px; font-weight: 600; color: var(--muted); }
.field small { color: var(--muted); font-size: 12px; }
.check { display: flex; gap: 8px; align-items: flex-start; }
.check input { margin-top: 2px; }
.check small { display: block; color: var(--muted); font-size: 12px; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.toolbar input[type="search"], .toolbar input[type="text"] { flex: 1 1 200px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px 20px; }
.form-actions { display: flex; gap: 8px; align-items: center; justify-content: flex-end; flex-wrap: wrap; }
.err { color: var(--danger); font-size: 13px; }
.segmented { display: inline-flex; background: var(--panel-2); border: 1px solid var(--line); border-radius: 9px; padding: 2px; }
.segmented button { border: 0; background: transparent; font: inherit; font-weight: 600; font-size: 12.5px; color: var(--muted); padding: 5px 10px; border-radius: 7px; cursor: pointer; }
.segmented button[aria-pressed="true"] { background: var(--panel); color: var(--text); box-shadow: var(--shadow); }

/* ---------- tags ---------- */
.tag { display: inline-flex; align-items: center; gap: 4px; padding: 1px 7px; border-radius: 999px; font-size: 11.5px; font-weight: 650; border: 1px solid var(--line-strong); color: var(--muted); white-space: nowrap; }
.tag.ok { color: var(--ok); border-color: color-mix(in oklab, var(--ok) 40%, transparent); }
.tag.bad { color: var(--danger); border-color: color-mix(in oklab, var(--danger) 40%, transparent); background: var(--danger-soft); }
.tag.mod { color: var(--accent); border-color: color-mix(in oklab, var(--accent) 45%, transparent); background: var(--accent-soft); }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; vertical-align: 0; }

/* ---------- empty / loading ---------- */
.empty { padding: 32px 20px; text-align: center; color: var(--muted); }
.empty strong { display: block; color: var(--text); font-weight: 600; margin-bottom: 4px; }
.skel { display: block; height: 12px; border-radius: 6px; background: var(--panel-2); margin: 10px 0; animation: pulse 1.1s ease-in-out infinite alternate; }
@keyframes pulse { from { opacity: .5; } to { opacity: 1; } }

/* ---------- code / embed ---------- */
pre.code { margin: 0; background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; overflow-x: auto; font-family: var(--mono); font-size: 12.5px; line-height: 1.6; white-space: pre; }
.embed-grid { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 20px; align-items: start; }
.preview { height: 520px; }

/* ---------- sign in ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login form { width: min(380px, 100%); display: grid; gap: 14px; padding: 28px; }
.login .brand { padding: 0; font-size: 16px; }

/* ---------- toast ---------- */
#toast { position: fixed; left: 50%; bottom: 20px; transform: translate(-50%, 12px); opacity: 0; pointer-events: none; z-index: 50;
  background: var(--text); color: var(--bg); padding: 9px 14px; border-radius: 9px; font-weight: 550; font-size: 13.5px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .25); transition: opacity .18s, transform .2s cubic-bezier(.2, .8, .2, 1); max-width: calc(100vw - 32px); }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.bad { background: var(--danger); color: #fff; }

/* ---------- responsive ---------- */
@media (max-width: 860px) {
  .shell { grid-template-columns: minmax(0, 1fr); align-content: start; }
  .side { min-width: 0; position: sticky; top: 0; height: auto; z-index: 10; flex-direction: column; gap: 8px; padding: 10px 12px 0; border-right: 0; border-bottom: 1px solid var(--line); }
  .side-top { display: flex; align-items: center; gap: 10px; }
  .side-top .sitepick { flex: 1; padding: 0; }
  .sitepick label { display: none; }
  .nav { display: flex; overflow-x: auto; gap: 2px; margin: 0 -12px; padding: 0 12px 8px; scrollbar-width: none; }
  .nav a { white-space: nowrap; padding: 6px 10px; }
  .nav-sep { height: 1px; background: var(--line); margin: 6px 8px; }
.side-foot .role { font-size: 12px; color: var(--muted); }
.nav .count { display: none; }
  .side-foot { display: none; }
  .main { padding: 16px 14px 40px; }
  .embed-grid { grid-template-columns: 1fr; }
  .stat:nth-child(odd) { border-left: 0; }
  .stats { grid-template-columns: 1fr 1fr; }
  .stat:nth-child(n+3) { border-top: 1px solid var(--line); }
  /* Tables turn into stacked cards on phones. */
  table.stack thead { display: none; }
  table.stack, table.stack tbody, table.stack tr, table.stack td { display: block; width: 100%; }
  table.stack tr { border-bottom: 1px solid var(--line); padding: 8px 4px; }
  table.stack tr[hidden] { display: none; }
  table.stack td { border: 0; padding: 3px 12px; }
  table.stack td[data-label]::before { content: attr(data-label); color: var(--muted); font-size: 12px; font-weight: 600; display: inline-block; min-width: 92px; }
  table.stack td.actions { text-align: left; padding-top: 8px; white-space: normal; }
  table.stack td.actions .btn { margin: 0 4px 4px 0; }
  td.msgbody { max-width: none; }
}
@media (min-width: 861px) { .side-top { display: contents; } .side-top .menu-foot { display: none; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
