:root {
  --bg: #fefefe; --fg: #1e1e1e; --muted: #858585; --line: #e5e5e5; --line-strong: #1e1e1e;
  --soft: #f5f5f4; --accent: #e551ba; --accent-fg: #fefefe; --ok: #03aa5c; --bad: #d4383a; --warn: #c98a00;
  --mono: 'Fragment Mono', 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  --sans: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141414; --fg: #ececec; --muted: #8a8a8a; --line: #2a2a2a; --line-strong: #ececec;
    --soft: #1c1c1c; --accent: #f07bcf; --accent-fg: #141414; --ok: #2fc47a; --bad: #ff6b6b; --warn: #e3b341;
  }
}
:root[data-theme="dark"] {
  --bg: #141414; --fg: #ececec; --muted: #8a8a8a; --line: #2a2a2a; --line-strong: #ececec;
  --soft: #1c1c1c; --accent: #f07bcf; --accent-fg: #141414; --ok: #2fc47a; --bad: #ff6b6b; --warn: #e3b341;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--fg); }
body { font: 14px/1.55 var(--sans); -webkit-font-smoothing: antialiased; }
a { color: inherit; text-underline-offset: 3px; }
code, pre, .mono, input, select, button, textarea, table { font-family: var(--mono); }
code { font-size: 12.5px; background: var(--soft); padding: 1px 5px; }
pre { background: var(--soft); border: 1px solid var(--line); padding: 14px 16px; overflow-x: auto; font-size: 12.5px; line-height: 1.6; margin: 12px 0 20px; }
pre code { background: none; padding: 0; }
h1 { font: 500 22px/1.3 var(--sans); letter-spacing: -0.01em; margin: 0 0 6px; }
h2 { font: 500 16px/1.4 var(--sans); margin: 36px 0 10px; }
h3 { font: 500 14px/1.4 var(--mono); margin: 24px 0 8px; }
p { margin: 8px 0; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

/* layout */
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.side { border-right: 1px solid var(--line); padding: 22px 16px; display: flex; flex-direction: column; gap: 2px; position: sticky; top: 0; height: 100vh; }
.brand { font: 500 14px var(--mono); padding: 0 10px 22px; display: flex; align-items: center; gap: 8px; text-decoration: none; }
.brand i { width: 10px; height: 10px; background: var(--accent); display: inline-block; }
.nav a { display: block; padding: 7px 10px; text-decoration: none; font: 13px var(--mono); color: var(--muted); }
.nav a:hover { color: var(--fg); }
.nav a.on { color: var(--fg); background: var(--soft); }
.side .foot { margin-top: auto; padding: 0 10px; font: 12px var(--mono); color: var(--muted); word-break: break-all; }
.side .foot button { margin-top: 8px; }
.main { padding: 36px 48px 80px; max-width: 1360px; width: 100%; margin: 0 auto; min-width: 0; }
.head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 26px; }

/* controls */
button, .btn { font-size: 12.5px; background: var(--bg); color: var(--fg); border: 1px solid var(--line-strong); padding: 7px 14px; cursor: pointer; border-radius: 0; text-decoration: none; display: inline-block; }
button:hover { background: var(--soft); }
button.primary { background: var(--fg); color: var(--bg); }
button.primary:hover { opacity: .88; }
button.ghost { border-color: var(--line); color: var(--muted); }
button.ghost:hover { color: var(--fg); border-color: var(--line-strong); }
button.danger { color: var(--bad); border-color: var(--line); }
button.danger:hover { border-color: var(--bad); }
button:disabled { opacity: .5; cursor: default; }
td button { padding: 4px 10px; font-size: 11.5px; }
input, select, textarea { font-size: 13px; color: var(--fg); background: var(--bg); border: 1px solid var(--line); padding: 8px 10px; border-radius: 0; outline: none; width: 100%; }
input:focus, select:focus, textarea:focus { border-color: var(--line-strong); }
select { width: auto; }
label { display: block; font: 12px var(--mono); color: var(--muted); margin: 14px 0 6px; }
.seg { display: inline-flex; border: 1px solid var(--line); }
.seg button { border: 0; border-right: 1px solid var(--line); color: var(--muted); padding: 6px 12px; }
.seg button:last-child { border-right: 0; }
.seg button.on { color: var(--fg); background: var(--soft); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

/* tiles */
.tiles { display: grid; grid-template-columns: repeat(5, 1fr); border: 1px solid var(--line); margin-bottom: 20px; }
.tile { padding: 16px 18px; border-right: 1px solid var(--line); }
.tile:last-child { border-right: 0; }
.tile .k { font: 11px var(--mono); color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.tile .v { font: 500 22px var(--mono); margin-top: 6px; font-variant-numeric: tabular-nums; }

/* chart */
.card { border: 1px solid var(--line); padding: 18px; margin-bottom: 20px; }
.chart { height: 180px; display: flex; align-items: flex-end; gap: 1px; margin-top: 14px; position: relative; }
.chart .b { flex: 1; background: var(--fg); opacity: .85; min-height: 1px; position: relative; }
.chart .b.zero { opacity: .12; }
.chart .b:hover { background: var(--accent); opacity: 1; }
.axis { display: flex; justify-content: space-between; font: 11px var(--mono); color: var(--muted); margin-top: 6px; }
.tip { position: fixed; pointer-events: none; background: var(--fg); color: var(--bg); font: 11.5px/1.5 var(--mono); padding: 6px 9px; z-index: 9; white-space: pre; display: none; }

/* tables */
.tbl-wrap { overflow-x: auto; border: 1px solid var(--line); }
table { border-collapse: collapse; width: 100%; font-size: 12.5px; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 9px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { font-weight: 400; color: var(--muted); font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; user-select: none; }
th.sort { cursor: pointer; }
th.sort:hover { color: var(--fg); }
th .arr { color: var(--accent); }
td.r, th.r { text-align: right; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--soft); }
.tag { font-size: 11px; padding: 1px 7px; border: 1px solid var(--line); }
.tag.ok { color: var(--ok); border-color: currentColor; }
.tag.bad { color: var(--bad); border-color: currentColor; }
.tag.warn { color: var(--warn); border-color: currentColor; }
.empty { padding: 36px; text-align: center; color: var(--muted); font: 12.5px var(--mono); }

/* auth */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.auth form { width: 100%; max-width: 360px; }
.auth .brand { padding: 0 0 28px; font-size: 15px; }
.auth button.primary { width: 100%; margin-top: 22px; padding: 10px; }
.auth .alt { margin-top: 18px; font: 12px var(--mono); color: var(--muted); text-align: center; }
.err { color: var(--bad); font: 12px var(--mono); margin-top: 12px; min-height: 18px; }

/* key reveal / dialog */
.reveal { border: 1px solid var(--accent); padding: 16px; margin-bottom: 20px; }
.reveal .mono { word-break: break-all; font-size: 13px; margin: 8px 0 12px; }
.dialog-bg { position: fixed; inset: 0; background: rgba(0,0,0,.35); display: grid; place-items: center; z-index: 10; padding: 16px; }
.dialog { background: var(--bg); border: 1px solid var(--line-strong); padding: 22px; width: 100%; max-width: 440px; }
.dialog .row { justify-content: flex-end; margin-top: 18px; }

/* docs */
.docs { display: grid; grid-template-columns: minmax(0, 1fr) 200px; gap: 56px; max-width: 1100px; margin: 0 auto; }
.docs .toc { position: sticky; top: 36px; align-self: start; font: 12px var(--mono); }
.docs .toc a { display: block; padding: 3px 0; color: var(--muted); text-decoration: none; }
.docs .toc a:hover { color: var(--fg); }
.docs article { min-width: 0; }
.docs article section { scroll-margin-top: 24px; }
.ep { font: 13px var(--mono); border: 1px solid var(--line); padding: 10px 14px; margin: 10px 0; display: flex; gap: 12px; }
.ep b { color: var(--accent); font-weight: 500; }
.field { border-top: 1px solid var(--line); padding: 10px 0; }
.field .n { font: 13px var(--mono); }
.field .t { font: 12px var(--mono); color: var(--muted); margin-left: 8px; }
.field .req { font: 11px var(--mono); color: var(--accent); margin-left: 8px; }
.note { border-left: 2px solid var(--accent); padding: 4px 14px; margin: 14px 0; color: var(--fg); }

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; border-right: 0; border-bottom: 1px solid var(--line); padding: 12px 16px; }
  .brand { padding: 0 10px 0 0; }
  .nav { display: flex; flex-wrap: wrap; }
  .side .foot { margin: 0 0 0 auto; padding: 0; }
  .side .foot span { display: none; }
  .main { padding: 24px 16px 60px; }
  .tiles { grid-template-columns: repeat(2, 1fr); }
  .tile { border-bottom: 1px solid var(--line); }
  .docs { grid-template-columns: 1fr; }
  .docs .toc { display: none; }
}

/* skeletons */
.sk { background: linear-gradient(90deg, var(--soft) 0%, var(--line) 50%, var(--soft) 100%); background-size: 200% 100%; animation: sk 1.1s ease-in-out infinite; }
@keyframes sk { 0% { background-position: 100% 0; } 100% { background-position: -100% 0; } }
@media (prefers-reduced-motion: reduce) { .sk { animation: none; } }
