:root {
  --paper: #f2f1f8; --card: #ffffff; --wash: #f7f6fc; --ink: #17183a; --muted: #65678a; --line: #dad9ea;
  --brand: #3a3db8; --brand-ink: #ffffff;
  --gold: #e3a21a; --gold-soft: #fff1cc; --gold-ink: #6b4a00;
  --ok: #178a5f; --ok-soft: #ddf3ea;
  --bad: #c2394a; --bad-soft: #fbe3e6;
  --side: #17183a; --side-ink: #c9caec;
  --display: "Bricolage Grotesque", "Segoe UI", system-ui, sans-serif;
  --body: "Figtree", "Segoe UI", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, Consolas, monospace;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #0f1020; --card: #181a33; --wash: #1d1f3c; --ink: #ececfa; --muted: #9a9cc0; --line: #2b2d52;
    --brand: #9094ff; --brand-ink: #0f1020;
    --gold: #f0b43a; --gold-soft: #3a2e10; --gold-ink: #f6d58a;
    --ok: #4cc38f; --ok-soft: #12332a;
    --bad: #ff7a8a; --bad-soft: #3d1820;
    --side: #0a0b18; --side-ink: #a9abd6;
  }
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--paper); color: var(--ink); font: 15px/1.5 var(--body); }
h1, h2, h3 { font-family: var(--display); margin: 0; letter-spacing: -0.01em; }
button, input { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.mono, .num { font-family: var(--mono); font-size: 0.92em; }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.muted, .hint, small { color: var(--muted); }
.hint { font-size: 13px; margin: 10px 0 0; }

/* shell */
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.side { background: var(--side); color: var(--side-ink); padding: 22px 14px; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 4px; }
.side a { color: inherit; text-decoration: none; padding: 9px 12px; border-radius: 8px; font-weight: 500; }
.side a:hover { background: rgba(255, 255, 255, 0.07); }
.side a[aria-current="page"] { background: rgba(255, 255, 255, 0.13); color: #fff; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 12px 20px; color: #fff; font-family: var(--display); font-weight: 700; font-size: 17px; line-height: 1.15; }
.brand small { display: block; font: 500 12px var(--body); color: var(--side-ink); letter-spacing: 0.04em; text-transform: uppercase; }
.star { width: 20px; height: 20px; background: var(--gold); flex: none; clip-path: polygon(50% 0, 62% 38%, 100% 50%, 62% 62%, 50% 100%, 38% 62%, 0 50%, 38% 38%); }
main { min-width: 0; }
.page { padding: 26px 32px 60px; max-width: 1100px; }

/* environment strip: always visible so nobody mistakes live data for a sandbox */
.env { padding: 9px 32px; font-size: 13px; border-bottom: 1px solid var(--line); }
.env.production { background: var(--gold-soft); color: var(--gold-ink); border-left: 4px solid var(--gold); }
.env.emulator { background: var(--ok-soft); color: var(--ok); border-left: 4px solid var(--ok); }

.head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.head h1 { font-size: 30px; }
.sub { margin: 4px 0 0; color: var(--muted); }
.loading { color: var(--muted); }

/* cards, figures, tables */
.card, .sec { background: var(--card); border: 1px solid var(--line); border-radius: 12px; }
.sec { padding: 18px; margin-top: 16px; }
.sec h3 { font-size: 15px; margin-bottom: 12px; }
.figures { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); background: var(--card); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.fig { padding: 16px 18px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); margin: 0 -1px -1px 0; }
.fig span, .mini span { display: block; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
.fig b, .mini b { font: 700 28px var(--display); }
.mini { display: flex; gap: 32px; margin-bottom: 12px; }
.mini b { font-size: 22px; }
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.cols .sec { margin-top: 16px; }

.tools { display: flex; gap: 16px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.tblwrap { overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; }
.tbl th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); font-weight: 500; padding: 10px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl td { padding: 12px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl tbody tr[data-act]:hover { background: var(--wash); cursor: pointer; }
.tbl td small { display: block; }
.tbl.small td, .tbl.small th { padding: 9px 10px; font-size: 14px; }
.sec .tblwrap { margin: 0 -18px -18px; }

/* controls */
.btn { background: var(--brand); color: var(--brand-ink); border: 1px solid var(--brand); border-radius: 8px; padding: 8px 16px; font-weight: 600; cursor: pointer; }
.btn:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.btn.ghost:hover { background: var(--wash); filter: none; }
.btn.danger { background: transparent; color: var(--bad); border-color: var(--bad); }
.btn.danger:hover { background: var(--bad-soft); filter: none; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.link { background: none; border: 0; padding: 0; font-weight: 600; color: var(--ink); cursor: pointer; text-align: left; }
.link:hover { color: var(--brand); text-decoration: underline; }
.x { position: absolute; top: 14px; right: 14px; width: 34px; height: 34px; border-radius: 8px; border: 1px solid var(--line); background: var(--card); font-size: 20px; line-height: 1; cursor: pointer; }
.x:hover { background: var(--wash); }

label { display: block; font-size: 13px; font-weight: 500; color: var(--muted); }
label input:not([type="checkbox"]) { display: block; width: 100%; margin-top: 4px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--card); color: var(--ink); font-size: 15px; }
input[type="search"] { width: min(360px, 100%); padding: 9px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--card); }
label.check { display: flex; align-items: center; gap: 8px; color: var(--ink); font-size: 14px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.full { grid-column: 1 / -1; }
.row { display: flex; gap: 10px; margin-top: 14px; flex-wrap: wrap; }
.inline { display: flex; gap: 10px; align-items: flex-end; margin-top: 12px; }
.inline label { flex: 1; }
.pw { display: flex; gap: 8px; align-items: flex-end; }
.pw input { margin-top: 4px; }
.mt { margin-top: 18px; margin-bottom: 10px; font-size: 15px; }

/* chips and presence */
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px; border-radius: 99px; font-size: 12px; font-weight: 600; background: var(--wash); color: var(--muted); border: 1px solid var(--line); white-space: nowrap; }
.chip.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.chip.bad { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
.chip.gold { background: var(--gold-soft); color: var(--gold-ink); border-color: transparent; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); display: inline-block; }
.dot.on { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-soft); }
.plain { list-style: none; margin: 0; padding: 0; }
.plain li { display: flex; align-items: center; gap: 10px; padding: 7px 0; }
.log li { justify-content: space-between; align-items: baseline; gap: 16px; border-bottom: 1px solid var(--line); }
.log li:last-child { border-bottom: 0; }
.log time { color: var(--muted); font-size: 12px; white-space: nowrap; }
.kv { display: grid; grid-template-columns: 110px 1fr; gap: 6px 12px; margin: 0; }
.kv dt { color: var(--muted); font-size: 13px; }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.cr { color: var(--ok); } .dr { color: var(--bad); }
.empty { padding: 40px 20px; text-align: center; color: var(--muted); }
.empty strong { color: var(--ink); }

/* side sheet and modal */
dialog { color: var(--ink); background: var(--paper); }
dialog::backdrop { background: rgba(23, 24, 58, 0.5); }
.sheet { position: fixed; inset: 0 0 0 auto; margin: 0; width: min(580px, 100%); max-width: 100%; height: 100%; max-height: 100%; border: 0; border-left: 1px solid var(--line); padding: 0; }
.sheet-in { position: relative; padding: 24px; height: 100%; overflow-y: auto; }
.sh-head h2 { font-size: 26px; padding-right: 44px; }
.sh-head p { margin: 2px 0 0; }
.modal { width: min(560px, calc(100% - 24px)); max-height: calc(100% - 24px); border: 1px solid var(--line); border-radius: 14px; padding: 0; }
.modal-in { position: relative; padding: 22px; }
.modal-in h2 { font-size: 22px; margin-bottom: 16px; padding-right: 44px; }

/* a manual popover lives in the top layer, so it shows above the open side sheet too */
.toast { position: fixed; inset: auto auto 24px 50%; transform: translateX(-50%); margin: 0; border: 0; background: var(--ink); color: var(--paper); padding: 10px 18px; border-radius: 10px; max-width: calc(100% - 32px); }
.toast.err { background: var(--bad); color: #fff; }

@media (max-width: 820px) {
  .shell { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .side { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 10px 12px; }
  .brand { padding: 0 12px 0 4px; }
  .brand small { display: none; }
  .page { padding: 20px 16px 48px; }
  .env { padding: 9px 16px; }
  .cols, .grid2 { grid-template-columns: 1fr; }
  .inline { flex-direction: column; align-items: stretch; }
}

/* sign-in gate and signed-in user */
[hidden] { display: none !important; }
.gate { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.gate-card { width: min(380px, 100%); background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 28px; display: flex; flex-direction: column; gap: 14px; }
.gate-card .brand { padding: 0; color: var(--ink); }
.gate-card .brand small { color: var(--muted); }
.gate-card h1 { font-size: 26px; }
.gate-card p { margin: 0; }
.gate-card .row { margin-top: 0; }
.err { min-height: 1.4em; color: var(--bad); font-size: 14px; }
.err.ok { color: var(--ok); }
.who { margin-top: auto; padding: 12px; font-size: 13px; display: flex; flex-direction: column; gap: 6px; overflow-wrap: anywhere; }
.who .link { color: var(--side-ink); }
.who .link:hover { color: #fff; }
@media (max-width: 820px) { .who { margin: 0 0 0 auto; flex-direction: row; align-items: center; gap: 12px; white-space: nowrap; } #who { display: none; } }

/* blog editor */
label textarea, label select { display: block; width: 100%; margin-top: 4px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--card); color: var(--ink); font: inherit; font-size: 15px; resize: vertical; }
label textarea.article { min-height: 320px; line-height: 1.6; }
.sec .hint, label .hint { display: block; }
.cover-prev { min-height: 64px; display: grid; place-items: center; padding: 8px; border: 1px dashed var(--line); border-radius: 10px; background: var(--wash); }
.cover-prev img { display: block; max-width: 100%; max-height: 220px; border-radius: 8px; }
.filebtn { position: relative; display: inline-block; cursor: pointer; color: var(--ink); }
.filebtn:focus-within { outline: 2px solid var(--brand); outline-offset: 2px; }
label input.sr { position: absolute; left: 0; top: 0; width: 1px; height: 1px; margin: 0; padding: 0; border: 0; opacity: 0; overflow: hidden; }
.faq { display: grid; gap: 8px; padding: 12px; margin-bottom: 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--wash); }
.faq .btn { justify-self: start; }
.postbar { position: sticky; bottom: 0; margin: 14px -18px -18px; padding: 14px 18px; background: var(--card); border-top: 1px solid var(--line); }
a.chip { text-decoration: none; color: var(--ink); }
a.chip:hover { background: var(--wash); }

/* applications */
.tab { border: 1px solid var(--line); background: var(--card); color: var(--ink); border-radius: 99px; padding: 6px 14px; font-weight: 500; cursor: pointer; }
.tab:hover { background: var(--wash); }
.tab[aria-pressed="true"] { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.prewrap { white-space: pre-wrap; overflow-wrap: anywhere; margin: 0; }
.files li { display: grid; grid-template-columns: 1fr auto; gap: 8px 12px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); }
.files li:last-child { border-bottom: 0; }
.files small { display: block; color: var(--muted); }
.files b { overflow-wrap: anywhere; }
.files .prev { grid-column: 1 / -1; }
.files .prev img { display: block; max-width: 100%; max-height: 420px; border-radius: 8px; border: 1px solid var(--line); }
