:root {
  color-scheme: light dark;
  --bg: #f6f5f2;
  --panel: #ffffff;
  --sunken: #efeee9;
  --line: #dddbd4;
  --text: #1d1c1a;
  --muted: #6b6963;
  --accent: #1f5fbf;
  --accent-text: #ffffff;
  --ok: #1a7f4b;
  --ok-bg: #e3f4ea;
  --warn: #8a5a00;
  --warn-bg: #fdf1d8;
  --bad: #b3261e;
  --bad-bg: #fbe5e3;
  --info: #1f5fbf;
  --info-bg: #e3ecfa;
  --radius: 8px;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151514;
    --panel: #1e1e1c;
    --sunken: #191918;
    --line: #34332f;
    --text: #ecebe7;
    --muted: #9c9991;
    --accent: #7fb0ff;
    --accent-text: #0e1320;
    --ok: #6fd3a0;
    --ok-bg: #16301f;
    --warn: #f0c060;
    --warn-bg: #352a12;
    --bad: #ff8a80;
    --bad-bg: #3a1a18;
    --info: #9cc2ff;
    --info-bg: #1a2638;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 14px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif; background: var(--bg); color: var(--text); }
a { color: var(--accent); }
h1 { font-size: 20px; margin: 0 0 4px; font-weight: 650; }
h2 { font-size: 15px; margin: 24px 0 10px; font-weight: 650; }
h3 { font-size: 13px; margin: 16px 0 8px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
p { margin: 0 0 10px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: var(--mono); font-size: 12.5px; }
.nowrap { white-space: nowrap; }
.hidden { display: none !important; }

/* ---------- layout ---------- */
.shell { display: grid; grid-template-columns: 220px minmax(0, 1fr); min-height: 100vh; }
.side { border-right: 1px solid var(--line); padding: 18px 12px; position: sticky; top: 0; height: 100vh; overflow: auto; display: flex; flex-direction: column; gap: 2px; }
.brand { font-weight: 700; font-size: 15px; padding: 0 10px 14px; display: flex; align-items: center; gap: 8px; }
.brand .dot { width: 10px; height: 10px; border-radius: 3px; background: var(--accent); }
.side a { display: flex; justify-content: space-between; align-items: center; padding: 7px 10px; border-radius: 6px; color: inherit; text-decoration: none; }
.side a:hover { background: var(--sunken); }
.side a[aria-current="page"] { background: var(--accent); color: var(--accent-text); }
.side .group { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; padding: 14px 10px 4px; }
.side .count { font-size: 11px; background: var(--warn-bg); color: var(--warn); border-radius: 10px; padding: 0 7px; }
.side .spacer { flex: 1; }
.side .me { padding: 10px; font-size: 12px; color: var(--muted); border-top: 1px solid var(--line); margin-top: 10px; }
.main { padding: 24px 32px 60px; max-width: 1200px; width: 100%; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.banner { background: var(--warn-bg); color: var(--warn); padding: 8px 14px; border-radius: var(--radius); margin-bottom: 16px; font-size: 13px; }
.menu-bar { display: none; }

@media (max-width: 860px) {
  .shell { display: block; }
  .side { position: fixed; z-index: 20; left: 0; top: 0; width: 240px; background: var(--panel); transform: translateX(-100%); transition: transform .15s; }
  .side.open { transform: none; box-shadow: 0 0 0 100vw rgba(0,0,0,.35); }
  .main { padding: 16px; }
  .menu-bar { display: block; padding: 12px 16px 0; }
}

/* ---------- panels, tiles, tables ---------- */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.panel + .panel { margin-top: 14px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.tile { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; text-decoration: none; color: inherit; display: block; }
a.tile:hover { border-color: var(--accent); }
.tile .label { font-size: 12px; color: var(--muted); }
.tile .value { font-size: 24px; font-weight: 650; font-variant-numeric: tabular-nums; margin-top: 2px; }
.tile .sub { font-size: 11px; color: var(--muted); }

.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; font-weight: 500; color: var(--muted); padding: 8px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; background: var(--sunken); }
td { padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--sunken); }
td.trunc { max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.empty { padding: 28px; text-align: center; color: var(--muted); }

.badge { display: inline-block; font-size: 11.5px; font-weight: 550; padding: 1px 8px; border-radius: 10px; background: var(--sunken); color: var(--muted); white-space: nowrap; }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.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(--info); }

/* ---------- forms ---------- */
label { display: block; font-size: 12px; color: var(--muted); margin: 12px 0 4px; }
input, textarea, select { width: 100%; font: inherit; color: inherit; background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 7px 9px; }
textarea { font-family: var(--mono); font-size: 12.5px; resize: vertical; }
input[type="checkbox"], input[type="radio"] { width: auto; }
input:focus-visible, textarea:focus-visible, select:focus-visible, button:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
@media (max-width: 700px) { .grid2 { grid-template-columns: 1fr; } }
.hint { font-size: 12px; color: var(--muted); margin-top: 4px; }
.err { color: var(--bad); font-size: 13px; min-height: 18px; margin-top: 8px; }
.choice { display: flex; gap: 6px; flex-wrap: wrap; }
.choice label { margin: 0; display: inline-flex; align-items: center; gap: 6px; padding: 6px 10px; border: 1px solid var(--line); border-radius: 6px; color: var(--text); font-size: 13px; cursor: pointer; background: var(--panel); }
.choice label:has(input:checked) { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }

.btn { display: inline-flex; align-items: center; gap: 6px; font: inherit; font-size: 13px; padding: 7px 13px; border-radius: 6px; border: 1px solid var(--line); background: var(--panel); color: var(--text); cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.danger { color: var(--bad); }
.btn.small { padding: 3px 9px; font-size: 12px; }
.btn[disabled] { opacity: .55; cursor: default; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { font: inherit; font-size: 12.5px; padding: 4px 11px; border-radius: 14px; border: 1px solid var(--line); background: var(--panel); color: var(--text); cursor: pointer; }
.chip[aria-pressed="true"] { background: var(--text); color: var(--bg); border-color: var(--text); }

/* ---------- setup checklist ---------- */
.setup { margin-bottom: 16px; border-color: var(--accent); }
.steps { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 4px; }
.steps li { display: grid; grid-template-columns: 26px minmax(0, 1fr); gap: 10px; padding: 10px; border-radius: 6px; }
.steps li.next { background: var(--info-bg); }
.steps li.done .step-title { color: var(--muted); text-decoration: line-through; }
.step-title { font-weight: 600; }
.step-icon { width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; font-size: 13px; font-weight: 700; border: 2px solid var(--line); }
.step-icon.done { background: var(--ok); border-color: var(--ok); color: var(--panel); }
.step-icon.waiting { border-color: var(--warn); color: var(--warn); }
.step-icon.todo { border-color: var(--accent); }
.howto { margin: 8px 0 4px; padding-left: 20px; display: grid; gap: 3px; }
.banner.attention { background: var(--bad-bg); color: var(--bad); }

/* ---------- auth ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.auth .panel { width: 100%; max-width: 380px; padding: 26px; }
.auth h1 { margin-bottom: 4px; }

/* ---------- misc ---------- */
.split { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; align-items: start; }
@media (max-width: 1000px) { .split { grid-template-columns: 1fr; } }
.tlist { display: grid; grid-template-columns: 200px minmax(0, 1fr); gap: 16px; align-items: start; }
@media (max-width: 900px) { .tlist { grid-template-columns: 1fr; } }
.tlist nav button { display: block; width: 100%; text-align: left; font: inherit; background: none; border: 0; color: inherit; padding: 7px 10px; border-radius: 6px; cursor: pointer; }
.tlist nav button:hover { background: var(--sunken); }
.tlist nav button[aria-current="true"] { background: var(--accent); color: var(--accent-text); }
iframe.preview { width: 100%; height: 420px; border: 1px solid var(--line); border-radius: 6px; background: #fff; }
pre.text { white-space: pre-wrap; background: var(--sunken); border: 1px solid var(--line); border-radius: 6px; padding: 10px 12px; margin: 0; font-family: var(--mono); font-size: 12.5px; max-height: 360px; overflow: auto; }
.subject-out { font-weight: 600; padding: 8px 10px; background: var(--sunken); border-radius: 6px; margin-bottom: 8px; }
.kv { display: grid; grid-template-columns: 120px minmax(0, 1fr); gap: 6px 12px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { padding: 8px 0; border-bottom: 1px solid var(--line); display: grid; grid-template-columns: 150px 110px minmax(0, 1fr); gap: 10px; font-size: 13px; }
.timeline li:last-child { border-bottom: 0; }
.keybox { font-family: var(--mono); font-size: 12.5px; background: var(--sunken); border: 1px dashed var(--accent); border-radius: 6px; padding: 10px; overflow-wrap: anywhere; }
.copyable { display: flex; gap: 6px; align-items: flex-start; }
.copyable code { flex: 1; font-family: var(--mono); font-size: 12px; overflow-wrap: anywhere; }

#toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 9px 16px; border-radius: 8px; font-size: 13px; opacity: 0; pointer-events: none; transition: opacity .15s; z-index: 50; max-width: 90vw; }
#toast.show { opacity: 1; }
#toast.bad { background: var(--bad); color: #fff; }
