:root {
  --bg: #f3f6fa; --surface: #ffffff; --ink: #1b2836; --muted: #5a6b7e; --line: #dce3eb;
  --accent: #1e5fc2; --accent-ink: #ffffff; --accent-soft: #e7effb;
  --side: #10263f; --side-ink: #c5d3e4; --side-active: rgba(255, 255, 255, .1); --side-mark: #6cb4ff;
  --ok: #1f7a55; --warn: #9a5b06; --danger: #b42318;
  --ok-soft: #e4f4ec; --warn-soft: #fbf0dc; --danger-soft: #fce8e6;
  --term-bg: #0f1d2e; --term-ink: #bdebcb;
  --radius: 8px;
  --sans: 'IBM Plex Sans', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --mono: 'IBM Plex Mono', ui-monospace, Consolas, Menlo, monospace;
}
[data-theme='dark'] {
  --bg: #121a24; --surface: #19232f; --ink: #e2e8ef; --muted: #95a4b5; --line: #2a3746;
  --accent: #6ea6f2; --accent-ink: #0b1a2e; --accent-soft: #1e2f47;
  --side: #0c1825; --side-ink: #aebdd0;
  --ok: #5cc99b; --warn: #e3a23c; --danger: #f08a80;
  --ok-soft: #173327; --warn-soft: #3a2d14; --danger-soft: #3b1d1a;
  --term-bg: #0a131e;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 400 16px/1.6 var(--sans); color: var(--ink); background: var(--bg); }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5em; font-weight: 600; }
h1 { font-size: 1.75rem; } h2 { font-size: 1.25rem; } h3 { font-size: 1.05rem; }
a { color: var(--accent); }
p { margin: 0 0 1em; }
.muted { color: var(--muted); font-size: .9rem; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; scroll-behavior: auto !important; } }

/* layout */
.layout { display: grid; grid-template-columns: 248px 1fr; min-height: 100vh; }
.sidebar { background: var(--side); color: var(--side-ink); padding: 20px 14px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: flex; gap: 12px; align-items: center; color: #fff; text-decoration: none; font-weight: 600; line-height: 1.25; padding: 4px 8px 22px; }
.brand-mark { display: inline-grid; place-items: center; width: 38px; height: 38px; border-radius: 10px; background: var(--side-mark); color: #0b2038; font-size: 1.2rem; flex: none; }
.brand-mark.big { width: 52px; height: 52px; font-size: 1.6rem; margin-bottom: 8px; }
.sidebar nav { display: grid; gap: 2px; }
.sidebar nav a { color: var(--side-ink); text-decoration: none; padding: 10px 12px; border-radius: 6px; border-left: 3px solid transparent; }
.sidebar nav a:hover { background: var(--side-active); color: #fff; }
.sidebar nav a[aria-current='page'] { background: var(--side-active); color: #fff; border-left-color: var(--side-mark); font-weight: 500; }
.content { min-width: 0; }
.topbar { position: sticky; top: 0; z-index: 5; display: flex; gap: 10px; align-items: center; padding: 12px 28px; background: var(--bg); border-bottom: 1px solid var(--line); }
.search { flex: 1; max-width: 560px; }
.search input { width: 100%; }
.topbar .spacer { flex: 1; }
.menu-btn { display: none; }
main { padding: 28px; max-width: 1040px; margin: 0 auto; outline: none; }

/* controls */
input, select, textarea { font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 9px 12px; width: 100%; }
input[type='checkbox'] { width: auto; }
input::placeholder { color: var(--muted); }
textarea { min-height: 90px; resize: vertical; }
.btn { font: inherit; font-weight: 500; cursor: pointer; padding: 8px 14px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--surface); color: var(--ink); text-decoration: none; display: inline-flex; align-items: center; gap: 6px; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); }
.btn.ghost { background: transparent; }
.btn.small { padding: 4px 10px; font-size: .875rem; }
.btn.block { width: 100%; justify-content: center; }
.icon-btn { font: inherit; cursor: pointer; background: transparent; border: 1px solid var(--line); color: var(--ink); width: 40px; height: 40px; border-radius: var(--radius); }
.icon-btn:hover { border-color: var(--accent); }
.stack { display: grid; gap: 14px; }
.field { display: grid; gap: 5px; }
.field > span, .field > .label { font-weight: 500; font-size: .9rem; }
.check { display: flex; gap: 8px; align-items: center; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0; }
.error { color: var(--danger); min-height: 1.4em; margin: 0; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

/* page head */
.page-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: end; gap: 12px; margin-bottom: 18px; }
.page-head h1 { margin: 0; }
.lede { font-size: 1.05rem; color: var(--muted); max-width: 70ch; }
section.block { margin: 34px 0; }
section.block > h2 { margin-bottom: 12px; }

/* lists */
.list { display: grid; gap: 8px; }
.row { display: flex; justify-content: space-between; gap: 18px; align-items: start; padding: 14px 16px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); text-decoration: none; color: inherit; }
.row:hover { border-color: var(--accent); }
.row h3 { margin: 0 0 2px; color: var(--accent); display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.row p { margin: 0; color: var(--muted); font-size: .92rem; }
.row-meta { display: grid; gap: 4px; justify-items: end; flex: none; text-align: right; }
.badge { background: var(--accent-soft); color: var(--accent); border-radius: 999px; padding: 1px 10px; font-size: .8rem; font-weight: 500; white-space: nowrap; }
.pill { background: var(--ok-soft); color: var(--ok); border-radius: 999px; padding: 0 8px; font-size: .75rem; font-weight: 600; }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.cats { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; }
.cat { padding: 14px 16px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); text-decoration: none; color: inherit; border-top: 3px solid var(--accent); }
.cat:hover { border-color: var(--accent); }
.cat strong { display: block; } .cat span { color: var(--muted); font-size: .88rem; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 16px; }
.chip { padding: 5px 13px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); text-decoration: none; font-size: .92rem; cursor: pointer; font-family: inherit; }
.chip[aria-current='true'] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.empty { text-align: center; padding: 44px 16px; border: 1px dashed var(--line); border-radius: var(--radius); color: var(--muted); }
.empty h2 { color: var(--ink); }

/* notices */
.notice { border-left: 5px solid var(--accent); background: var(--surface); border-radius: var(--radius); padding: 12px 16px; margin-bottom: 10px; border-top: 1px solid var(--line); border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.notice.important { border-left-color: var(--warn); background: var(--warn-soft); }
.notice.urgent { border-left-color: var(--danger); background: var(--danger-soft); }
.notice h3 { margin: 0 0 4px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.notice .prose > :last-child { margin-bottom: 0; }

/* article */
.doc { max-width: 820px; }
.crumbs { font-size: .9rem; margin-bottom: 8px; color: var(--muted); }
.meta { color: var(--muted); font-size: .9rem; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.toc { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 16px; margin: 16px 0; }
.toc strong { display: block; margin-bottom: 4px; }
.toc button { display: block; background: none; border: 0; padding: 3px 0; font: inherit; color: var(--accent); cursor: pointer; text-align: left; }
.toc button.sub { padding-left: 16px; }
.prose { font-size: 1.02rem; line-height: 1.7; overflow-wrap: anywhere; }
.prose h2 { margin-top: 1.6em; padding-bottom: 6px; border-bottom: 1px solid var(--line); }
.prose h3 { margin-top: 1.3em; }
.prose img { max-width: 100%; height: auto; border-radius: 6px; border: 1px solid var(--line); cursor: zoom-in; display: block; margin: 12px 0; }
.prose blockquote { margin: 1em 0; padding: 10px 16px; background: var(--accent-soft); border-left: 4px solid var(--accent); border-radius: 0 var(--radius) var(--radius) 0; }
.prose blockquote > :last-child { margin-bottom: 0; }
.prose ul, .prose ol { padding-left: 1.5em; }
.prose code { font-family: var(--mono); font-size: .9em; background: var(--accent-soft); padding: 1px 5px; border-radius: 4px; }
.prose pre { margin: 0; font-family: var(--mono); font-size: .92rem; line-height: 1.55; background: var(--term-bg); color: var(--term-ink); padding: 14px 16px; padding-right: 76px; border-radius: var(--radius); overflow-x: auto; white-space: pre-wrap; }
.prose pre code { background: none; padding: 0; }
.codewrap { position: relative; margin: 1em 0; }
.copy-btn { position: absolute; top: 8px; right: 8px; font: inherit; font-size: .8rem; padding: 2px 10px; border-radius: 6px; border: 1px solid rgba(255, 255, 255, .25); background: rgba(255, 255, 255, .08); color: #dfe9f5; cursor: pointer; }
.copy-btn:hover { background: rgba(255, 255, 255, .18); }
.tablewrap { overflow-x: auto; margin: 1em 0; }
.prose table { border-collapse: collapse; min-width: 60%; }
.prose th, .prose td { border: 1px solid var(--line); padding: 7px 12px; text-align: left; vertical-align: top; }
.prose th { background: var(--accent-soft); }
.prose a { word-break: break-word; }

/* editor */
.editor { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); overflow: hidden; }
.toolbar { display: flex; flex-wrap: wrap; gap: 4px; padding: 6px; border-bottom: 1px solid var(--line); background: var(--bg); position: sticky; top: 0; }
.toolbar button { font: inherit; font-size: .88rem; padding: 4px 10px; border-radius: 6px; border: 1px solid transparent; background: transparent; color: var(--ink); cursor: pointer; }
.toolbar button:hover { background: var(--accent-soft); border-color: var(--line); }
.editable { min-height: 280px; padding: 14px 16px; outline: none; }
.editable:empty::before { content: attr(data-placeholder); color: var(--muted); }
.editable.prose pre { padding-right: 16px; }
.editable.drop { background: var(--accent-soft); }

/* table */
.tbl { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.tbl th, .tbl td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl th { background: var(--bg); font-size: .88rem; color: var(--muted); font-weight: 600; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl .acts { display: flex; gap: 6px; flex-wrap: wrap; }

/* faq */
details.faq { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 8px; }
details.faq summary { cursor: pointer; padding: 13px 16px; font-weight: 500; list-style: none; display: flex; justify-content: space-between; gap: 12px; }
details.faq summary::-webkit-details-marker { display: none; }
details.faq summary::after { content: '+'; color: var(--accent); font-size: 1.3rem; line-height: 1; }
details.faq[open] summary::after { content: '–'; }
details.faq[open] summary { border-bottom: 1px solid var(--line); }
details.faq .answer { padding: 12px 16px 6px; }
details.faq .answer .acts { margin-bottom: 10px; }

/* links */
.linkcard { display: block; padding: 12px 16px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); text-decoration: none; color: inherit; height: 100%; }
.linkcard:hover { border-color: var(--accent); }
.linkcard strong { color: var(--accent); display: block; }
.linkcard .host { color: var(--muted); font-size: .82rem; font-family: var(--mono); overflow-wrap: anywhere; }
.linkcard p { margin: 4px 0 0; font-size: .92rem; color: var(--muted); }
.linkgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 10px; }
.linkwrap { position: relative; }
.linkwrap .acts { display: flex; gap: 6px; margin-top: 6px; }

/* dialog */
dialog.dlg { border: 1px solid var(--line); border-radius: 12px; padding: 0; width: min(560px, calc(100vw - 24px)); background: var(--surface); color: var(--ink); box-shadow: 0 20px 60px rgba(0, 0, 0, .35); max-height: calc(100vh - 32px); overflow: auto; }
dialog.dlg.wide { width: min(820px, calc(100vw - 24px)); }
dialog.dlg::backdrop { background: rgba(8, 16, 28, .6); }
.dlg-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--surface); z-index: 2; }
.dlg-head h2 { margin: 0; }
.dlg-body { padding: 18px; }
dialog.lightbox { border: 0; padding: 0; background: transparent; max-width: 96vw; max-height: 96vh; }
dialog.lightbox::backdrop { background: rgba(0, 0, 0, .85); }
dialog.lightbox img { max-width: 94vw; max-height: 92vh; display: block; cursor: zoom-out; border-radius: 6px; }

/* toasts */
#toasts { position: fixed; bottom: 18px; right: 18px; display: grid; gap: 8px; z-index: 100; }
.toast { background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: var(--radius); box-shadow: 0 6px 24px rgba(0, 0, 0, .25); max-width: 360px; }
.toast.error { background: var(--danger); color: #fff; }

/* auth */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: linear-gradient(160deg, var(--side), #1d4170); }
.auth-card { width: min(400px, 100%); background: var(--surface); border-radius: 14px; padding: 30px; box-shadow: 0 20px 60px rgba(0, 0, 0, .35); }
.auth-card h1 { margin-bottom: 0; }

/* responsive */
@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: fixed; z-index: 20; width: 264px; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; box-shadow: 0 0 0 100vmax rgba(0, 0, 0, .5); }
  .menu-btn { display: inline-block; }
  .topbar { padding: 10px 14px; }
  main { padding: 18px 14px; }
  .row { flex-direction: column; gap: 6px; }
  .row-meta { justify-items: start; text-align: left; grid-auto-flow: column; gap: 10px; align-items: center; }
  .grid-2 { grid-template-columns: 1fr; }
  #acctBtn { max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}
