
:root {
  --bg:#f4f6f9; --surface:#ffffff; --surface2:#eef2f6; --border:#d3dae3; --ink:#0f172a; --muted:#475569;
  --accent:#0f766e; --on-accent:#ffffff; --accent-soft:#e2f3f0; --accent-text:#0b5e58;
  --ok-bg:#e6f5ec; --ok:#146c3d; --bad-bg:#fcebe9; --bad:#a12a1d; --warn-bg:#fff3dc; --warn:#8a4a00;
  --info-bg:#e8eef9; --info:#1d4c9a; --code-bg:#0f172a; --code:#e2e8f0; --field:#ffffff; --field-border:#8593a3;
  --row-hover:#f6f8fb; --shadow:0 12px 40px rgba(15,23,42,.18);
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg:#0a0f15; --surface:#111922; --surface2:#17212c; --border:#263342; --ink:#e5eaf0; --muted:#a1aebc;
  --accent:#2dd4bf; --on-accent:#042b27; --accent-soft:#0d2d2a; --accent-text:#5eead4;
  --ok-bg:#0e2a1b; --ok:#6ee7a0; --bad-bg:#33161a; --bad:#ff9c91; --warn-bg:#2d2108; --warn:#f8c056;
  --info-bg:#13233d; --info:#93b8f5; --code-bg:#060a0e; --code:#d6dee8; --field:#0d141c; --field-border:#5b6b7d;
  --row-hover:#151f2a; --shadow:0 12px 40px rgba(0,0,0,.55);
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
  --bg:#0a0f15; --surface:#111922; --surface2:#17212c; --border:#263342; --ink:#e5eaf0; --muted:#a1aebc;
  --accent:#2dd4bf; --on-accent:#042b27; --accent-soft:#0d2d2a; --accent-text:#5eead4;
  --ok-bg:#0e2a1b; --ok:#6ee7a0; --bad-bg:#33161a; --bad:#ff9c91; --warn-bg:#2d2108; --warn:#f8c056;
  --info-bg:#13233d; --info:#93b8f5; --code-bg:#060a0e; --code:#d6dee8; --field:#0d141c; --field-border:#5b6b7d;
  --row-hover:#151f2a; --shadow:0 12px 40px rgba(0,0,0,.55);
  color-scheme: dark;
  }
}
* { box-sizing: border-box; }
/* Component display rules (flex/grid) would otherwise override the hidden attribute. */
[hidden] { display: none !important; }
html, body { margin:0; background:var(--bg); color:var(--ink); }
body { font-family: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif; font-size:15px; line-height:1.5; }
a { color:var(--accent-text); }
h1 { margin:0; font-size:26px; line-height:1.25; font-weight:600; }
h2 { margin:0; font-size:17px; font-weight:600; }
h3 { margin:0; font-size:15px; font-weight:600; }
p { margin:0; }
code, .mono { font-family: Consolas, "Cascadia Mono", ui-monospace, monospace; font-size:13px; }
.muted { color:var(--muted); }
.small { font-size:13px; }
.stack { display:flex; flex-direction:column; gap:16px; }
.stack-sm { display:flex; flex-direction:column; gap:8px; }
.row { display:flex; flex-wrap:wrap; gap:12px; align-items:center; }
.row-tight { display:flex; flex-wrap:wrap; gap:6px; align-items:center; }
.spread { justify-content:space-between; }
.end { justify-content:flex-end; }
.nowrap { white-space:nowrap; }
.sr-only { position:absolute; width:1px; height:1px; overflow:hidden; clip:rect(0 0 0 0); white-space:nowrap; }
svg.icon { width:18px; height:18px; flex:none; }

/* Public site */
.site-header { background:var(--surface); border-bottom:1px solid var(--border); }
.site-header .inner, .site-footer .inner { max-width:1120px; margin:0 auto; padding:16px 24px; display:flex; align-items:center; gap:12px; flex-wrap:wrap; }
.brand { display:flex; align-items:center; gap:10px; min-width:0; }
.brand-logo { display:block; object-fit:contain; flex:none; }
/* The wordmark's grey lettering needs a light ground, so it sits on a white plate in both themes. */
.wordmark-plate { background:#ffffff; border-radius:10px; padding:14px 18px; display:flex; justify-content:center; }
.wordmark { display:block; width:100%; max-width:320px; height:auto; }
.brand-name { font-weight:600; }
.brand-sub { font-size:13px; color:var(--muted); }
.site-main { min-height:calc(100vh - 140px); padding:56px 16px 48px; }
.site-footer { border-top:1px solid var(--border); font-size:13px; color:var(--muted); }
.card { width:100%; max-width:460px; margin:0 auto; background:var(--surface); border:1px solid var(--border); border-radius:12px; padding:32px; display:flex; flex-direction:column; gap:20px; }
.wide { max-width:880px; margin:0 auto; display:flex; flex-direction:column; gap:20px; }
.panel { background:var(--surface); border:1px solid var(--border); border-radius:12px; padding:22px; display:flex; flex-direction:column; gap:14px; }
label { font-size:14px; font-weight:500; }
input[type=text], input[type=email], input[type=search], input[type=number], input[type=file], select, textarea {
  font:inherit; color:var(--ink); background:var(--field); border:1px solid var(--field-border); border-radius:8px; padding:9px 12px; min-height:42px; width:100%;
}
textarea { min-height:140px; font-family: Consolas, ui-monospace, monospace; font-size:13px; }
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible, a:focus-visible, summary:focus-visible { outline:2px solid var(--accent); outline-offset:2px; }
.code-input { font-family: Consolas, ui-monospace, monospace; font-size:28px; letter-spacing:12px; text-align:center; }
.btn { font:inherit; font-weight:600; border-radius:8px; min-height:44px; padding:0 18px; cursor:pointer; border:1px solid transparent; display:inline-flex; align-items:center; justify-content:center; gap:8px; text-decoration:none; white-space:nowrap; }
.btn:disabled { opacity:.55; cursor:default; }
.btn-primary { background:var(--accent); color:var(--on-accent); }
.btn-secondary { background:var(--surface); color:var(--ink); border-color:var(--field-border); }
.btn-danger { background:transparent; color:var(--bad); border-color:var(--bad); }
.btn-danger-solid { background:var(--bad); color:var(--surface); border-color:var(--bad); }
.btn-sm { min-height:34px; padding:0 12px; font-size:13px; font-weight:500; }
.btn-icon { min-height:34px; width:34px; padding:0; }
.btn-link { background:none; border:none; padding:0; color:var(--accent-text); font:inherit; cursor:pointer; text-decoration:underline; }
.btn-full { width:100%; }
.notice { padding:12px 14px; border-radius:8px; font-size:14px; }
.notice-ok { background:var(--ok-bg); color:var(--ok); }
.notice-bad { background:var(--bad-bg); color:var(--bad); }
.notice-warn { background:var(--warn-bg); color:var(--warn); }
.notice-info { background:var(--surface2); color:var(--ink); }
.pill { display:inline-flex; align-items:center; gap:6px; padding:3px 10px; border-radius:999px; font-size:12px; font-weight:600; white-space:nowrap; }
.tag { display:inline-block; padding:2px 8px; border-radius:6px; font-size:12px; font-weight:600; white-space:nowrap; }
.t-ok { background:var(--ok-bg); color:var(--ok); }
.t-bad { background:var(--bad-bg); color:var(--bad); }
.t-warn { background:var(--warn-bg); color:var(--warn); }
.t-info { background:var(--info-bg); color:var(--info); }
.t-off { background:var(--surface2); color:var(--muted); }
.tabs { display:inline-flex; flex-wrap:wrap; gap:6px; padding:4px; border-radius:10px; background:var(--surface2); border:1px solid var(--border); }
.tab { font:inherit; font-weight:600; min-height:44px; padding:0 20px; border-radius:8px; border:1px solid transparent; background:transparent; color:var(--muted); cursor:pointer; display:inline-flex; align-items:center; gap:8px; }
.tab[aria-selected=true] { background:var(--surface); color:var(--ink); border-color:var(--field-border); }
.meta { display:grid; grid-template-columns:minmax(0, 3fr) minmax(0, 1fr) minmax(0, 2fr); gap:12px; padding:14px; border-radius:8px; background:var(--surface2); margin:0; }
.meta dt { font-size:12px; color:var(--muted); }
.meta dd { margin:0; font-size:14px; overflow-wrap:break-word; }
ol.steps { margin:0; padding-left:20px; display:flex; flex-direction:column; gap:6px; }
ol.steps ul { margin:6px 0 0; padding-left:20px; display:flex; flex-direction:column; gap:2px; }
.turnstile-box { min-height:65px; }

/* Admin shell */
.admin { display:flex; min-height:100vh; }
.sidebar { flex:0 0 248px; width:248px; background:var(--surface); border-right:1px solid var(--border); padding:16px 12px; display:flex; flex-direction:column; gap:18px; position:sticky; top:0; height:100vh; overflow-y:auto; transition:flex-basis .15s ease, width .15s ease; }
.sidebar-head { display:flex; align-items:center; justify-content:space-between; gap:8px; min-height:40px; }
.sidebar .brand-name { overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.nav { display:flex; flex-direction:column; gap:2px; }
.nav a, .side-btn { display:flex; align-items:center; gap:12px; min-height:40px; padding:0 12px; border-radius:8px; text-decoration:none; color:var(--ink); font:inherit; font-size:14px; background:none; border:none; cursor:pointer; width:100%; text-align:left; }
.nav a:hover, .side-btn:hover { background:var(--surface2); }
.nav a[aria-current=page] { background:var(--accent-soft); color:var(--accent-text); font-weight:600; }
.nav-label { flex:1; min-width:0; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.nav-icon { display:none; }
.side-tools { margin-top:auto; display:flex; flex-direction:column; gap:2px; border-top:1px solid var(--border); padding-top:12px; }
.who { padding:8px 12px; font-size:12px; color:var(--muted); overflow-wrap:anywhere; }
.collapse-btn svg { transition:transform .15s ease; }
html.nav-collapsed .sidebar { flex-basis:68px; width:68px; padding:16px 10px; }
html.nav-collapsed .sidebar .brand-name, html.nav-collapsed .nav-label, html.nav-collapsed .who, html.nav-collapsed .nav .tag { display:none; }
html.nav-collapsed .nav-icon { display:block; }
html.nav-collapsed .nav a, html.nav-collapsed .side-btn { justify-content:center; padding:0; }
html.nav-collapsed .sidebar-head { justify-content:center; }
html.nav-collapsed .collapse-btn svg { transform:rotate(180deg); }
.content { flex:1 1 0; min-width:0; padding:28px 32px 48px; display:flex; flex-direction:column; gap:20px; }
.page-head { display:flex; flex-wrap:wrap; gap:16px; align-items:flex-end; justify-content:space-between; }
.section { background:var(--surface); border:1px solid var(--border); border-radius:10px; padding:20px; display:flex; flex-direction:column; gap:14px; min-width:0; }
.cols { display:flex; flex-wrap:wrap; gap:20px; align-items:flex-start; }
.col-main { flex:3 1 520px; min-width:0; display:flex; flex-direction:column; gap:20px; }
.col-side { flex:2 1 340px; min-width:0; display:flex; flex-direction:column; gap:20px; }
.form-grid { display:grid; grid-template-columns:repeat(auto-fit, minmax(180px, 1fr)); gap:12px; align-items:end; }
.field { display:flex; flex-direction:column; gap:4px; min-width:0; }
.checks { display:flex; flex-wrap:wrap; gap:16px; border:none; margin:0; padding:0; }
.checks label { display:flex; align-items:center; gap:6px; font-weight:400; }
.stat-grid { display:grid; grid-template-columns:repeat(auto-fit, minmax(170px, 1fr)); gap:14px; }
.stat { background:var(--surface); border:1px solid var(--border); border-radius:10px; padding:16px; }
.stat .n { font-size:28px; font-weight:600; }
.danger-zone { background:var(--bad-bg); color:var(--bad); border-radius:10px; padding:20px; display:flex; flex-direction:column; gap:10px; }
.code-block { background:var(--code-bg); color:var(--code); border-radius:8px; padding:12px 14px; overflow-x:auto; white-space:pre; }

/* Definition list (details card) */
.facts { display:grid; grid-template-columns:repeat(auto-fit, minmax(220px, 1fr)); gap:16px 24px; margin:0; }
.facts dt { font-size:12px; font-weight:600; color:var(--muted); text-transform:uppercase; letter-spacing:.04em; }
.facts dd { margin:4px 0 0; font-size:15px; overflow-wrap:anywhere; display:flex; align-items:center; gap:6px; flex-wrap:wrap; }
.secret { font-family: Consolas, ui-monospace, monospace; font-size:14px; }

/* Installer cards */
.installer { border:1px solid var(--border); border-radius:10px; padding:18px; display:flex; flex-direction:column; gap:14px; background:var(--surface); }
.installer-head { display:flex; align-items:center; justify-content:space-between; gap:12px; flex-wrap:wrap; }
.installer-title { display:flex; align-items:center; gap:10px; font-weight:600; font-size:16px; }
.installer-facts { display:grid; grid-template-columns:minmax(0, 3fr) minmax(0, 1fr) minmax(0, 2fr); gap:12px; background:var(--surface2); padding:12px 14px; border-radius:8px; margin:0; }
.installer-facts dt { font-size:12px; color:var(--muted); }
.installer-facts dd { margin:2px 0 0; font-size:13px; overflow-wrap:anywhere; }
.upload { display:grid; grid-template-columns:minmax(0, 1fr) minmax(0, 1fr) auto; gap:12px; align-items:end; }
.dropzone { position:relative; border:1px dashed var(--field-border); border-radius:8px; min-height:42px; display:flex; align-items:center; gap:10px; padding:8px 12px; background:var(--field); color:var(--muted); font-size:14px; cursor:pointer; }
.dropzone:focus-within, .dropzone.drag { border-color:var(--accent); color:var(--ink); }
.dropzone input[type=file] { position:absolute; inset:0; opacity:0; cursor:pointer; min-height:0; }
.dropzone .file-name { overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }

/* Key/value chips (audit details) */
.kv { display:flex; flex-wrap:wrap; gap:4px 6px; }
.kv span { display:inline-flex; gap:4px; padding:1px 7px; border-radius:6px; background:var(--surface2); font-size:12px; max-width:100%; overflow-wrap:anywhere; }
.kv b { font-weight:600; color:var(--muted); }

/* Dialog */
dialog { border:1px solid var(--border); border-radius:12px; padding:0; background:var(--surface); color:var(--ink); width:min(560px, calc(100vw - 32px)); box-shadow:var(--shadow); }
dialog::backdrop { background:rgba(0,0,0,.45); }
.dialog-body { padding:22px; display:flex; flex-direction:column; gap:16px; }
.dialog-actions { display:flex; justify-content:flex-end; gap:10px; }

/* Data grid */
.grid { display:flex; flex-direction:column; gap:10px; min-width:0; }
.grid-toolbar { display:flex; flex-wrap:wrap; gap:10px; align-items:center; justify-content:space-between; }
.grid-toolbar .grid-search { flex:1 1 240px; max-width:420px; }
.grid-toolbar .grid-tools { display:flex; flex-wrap:wrap; gap:8px; align-items:center; }
.seg { display:inline-flex; border:1px solid var(--field-border); border-radius:8px; overflow:hidden; }
.seg button { font:inherit; font-size:13px; border:none; background:var(--surface); color:var(--muted); min-height:34px; padding:0 10px; cursor:pointer; }
.seg button[aria-pressed=true] { background:var(--accent-soft); color:var(--accent-text); font-weight:600; }
.table-wrap { overflow-x:auto; border:1px solid var(--border); border-radius:10px; background:var(--surface); }
table { width:100%; border-collapse:collapse; font-size:14px; }
.grid table.fixed { table-layout:fixed; min-width:100%; }
th { text-align:left; font-size:12px; font-weight:600; color:var(--muted); background:var(--surface2); padding:10px 14px; white-space:nowrap; position:relative; overflow:hidden; text-overflow:ellipsis; }
td { padding:11px 14px; border-top:1px solid var(--border); vertical-align:top; overflow-wrap:anywhere; }
tbody tr:hover { background:var(--row-hover); }
td.num, th.num { text-align:right; }
.grid.compact td { padding:5px 10px; font-size:13px; }
.grid.compact th { padding:7px 10px; }
.sort-btn { font:inherit; color:inherit; background:none; border:none; padding:0; cursor:pointer; display:inline-flex; align-items:center; gap:4px; max-width:100%; }
.sort-btn::after { content:"↕"; opacity:.35; font-size:11px; }
th[aria-sort=ascending] .sort-btn::after { content:"↑"; opacity:1; }
th[aria-sort=descending] .sort-btn::after { content:"↓"; opacity:1; }
.col-resize { position:absolute; top:0; right:0; width:8px; height:100%; cursor:col-resize; user-select:none; touch-action:none; }
.col-resize:hover, .col-resize.active { background:var(--accent); opacity:.4; }
tr.filter-row th { padding:6px 8px; background:var(--surface); }
tr.filter-row input, tr.filter-row select { min-height:32px; padding:4px 8px; font-size:13px; font-weight:400; }
.grid-footer { display:flex; flex-wrap:wrap; gap:10px; align-items:center; justify-content:space-between; font-size:13px; color:var(--muted); }
.grid-footer select { width:auto; min-height:34px; padding:4px 8px; font-size:13px; }
.grid-empty td { text-align:center; color:var(--muted); padding:24px; }
.inline-form { flex-wrap:nowrap; }
.inline-form form { flex-wrap:nowrap; }
.inline-form select { width:auto; min-height:34px; padding:4px 8px; font-size:13px; }

@media (max-width: 760px) {
  .admin { flex-direction:column; }
  .sidebar, html.nav-collapsed .sidebar { position:static; height:auto; width:100%; flex-basis:auto; border-right:none; border-bottom:1px solid var(--border); }
  .meta, .installer-facts, .upload { grid-template-columns:minmax(0, 1fr); }
  .content { padding:20px 16px 40px; }
  .card { padding:22px; }
}
