/* 记忆中枢 — "studio archive": paper, ink, a seal-red accent. No external fonts. */

:root {
  --font-sans: system-ui, -apple-system, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei UI", "Microsoft YaHei", "Noto Sans CJK SC", "Source Han Sans SC", "WenQuanYi Micro Hei", sans-serif;
  --font-serif: "Songti SC", "STSong", "Noto Serif CJK SC", "Source Han Serif SC", "SimSun", Georgia, serif;
  --font-mono: ui-monospace, "Cascadia Mono", "SF Mono", Consolas, "Liberation Mono", Menlo, monospace;

  --bg: #f4f0e7;
  --surface: #fffdf8;
  --surface-2: #ece6d9;
  --surface-3: #e3dccc;
  --line: #d9cfbd;
  --line-soft: #e8e1d3;
  --text: #24211c;
  --muted: #6e665a;
  --accent: #a23b2a;          /* seal red */
  --accent-hover: #8a3022;
  --accent-ink: #fff8ee;
  --accent-soft: #f3dfd7;
  --link: #2c5f63;            /* archive teal */
  --focus: #2c7a80;
  --mark: #f6e3a1;
  --ok: #3f7a4a;  --ok-soft: #e1eedf;
  --warn: #9a6512; --warn-soft: #f6e9cf;
  --err: #a8322a; --err-soft: #f6dcd7;
  --shadow: 0 1px 2px rgba(60, 45, 20, .06), 0 4px 16px rgba(60, 45, 20, .06);
  --shadow-lg: 0 10px 40px rgba(40, 30, 10, .22);
  --radius: 8px;
  --radius-sm: 5px;

  /* type badges */
  --t-decision: #2c5f63; --t-rule: #a23b2a; --t-progress: #36598f; --t-problem: #9a6512; --t-fix: #3f7a4a;
  --t-change: #6d4f8f; --t-discovery: #2f6d8a; --t-kb: #5d6b3a; --t-digest: #6e665a; --t-asset: #8a5a2b; --t-obs: #4a5560;

  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141619; --surface: #1c1f23; --surface-2: #24282d; --surface-3: #2c3137; --line: #363c43; --line-soft: #2b3036;
    --text: #e8e3d8; --muted: #a39b8d; --accent: #d0644d; --accent-hover: #e07a63; --accent-ink: #1a0f0b; --accent-soft: #3a2420;
    --link: #82bdb8; --focus: #6cc3bd; --mark: #5c4a17;
    --ok: #7fbf87; --ok-soft: #1f3324; --warn: #e0b061; --warn-soft: #3a2f1a; --err: #ef8a7d; --err-soft: #3d2220;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25); --shadow-lg: 0 10px 40px rgba(0, 0, 0, .55);
    --t-decision: #6fb4b0; --t-rule: #e07a63; --t-progress: #86a8e0; --t-problem: #e0b061; --t-fix: #7fbf87;
    --t-change: #b79ae0; --t-discovery: #78b9d6; --t-kb: #b2c27d; --t-digest: #a39b8d; --t-asset: #d4a06a; --t-obs: #a5b1bd;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #141619; --surface: #1c1f23; --surface-2: #24282d; --surface-3: #2c3137; --line: #363c43; --line-soft: #2b3036;
  --text: #e8e3d8; --muted: #a39b8d; --accent: #d0644d; --accent-hover: #e07a63; --accent-ink: #1a0f0b; --accent-soft: #3a2420;
  --link: #82bdb8; --focus: #6cc3bd; --mark: #5c4a17;
  --ok: #7fbf87; --ok-soft: #1f3324; --warn: #e0b061; --warn-soft: #3a2f1a; --err: #ef8a7d; --err-soft: #3d2220;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25); --shadow-lg: 0 10px 40px rgba(0, 0, 0, .55);
  --t-decision: #6fb4b0; --t-rule: #e07a63; --t-progress: #86a8e0; --t-problem: #e0b061; --t-fix: #7fbf87;
  --t-change: #b79ae0; --t-discovery: #78b9d6; --t-kb: #b2c27d; --t-digest: #a39b8d; --t-asset: #d4a06a; --t-obs: #a5b1bd;
  color-scheme: dark;
}

/* ------------------------------------------------------------ base */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.65 var(--font-sans); letter-spacing: .01em;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 3px; }
h1, h2, h3 { line-height: 1.3; margin: 0; }
h1 { font-family: var(--font-serif); font-weight: 700; font-size: 1.6rem; letter-spacing: .04em; }
p { margin: .4em 0; }
code, .mono { font-family: var(--font-mono); font-size: .88em; }
code { background: var(--surface-2); padding: .05em .35em; border-radius: 3px; }
mark { background: var(--mark); color: inherit; padding: 0 .1em; border-radius: 2px; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 3px; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; }
.pre-wrap { white-space: pre-wrap; word-break: break-word; }
.warn-text { color: var(--warn); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: -999px; top: 8px; background: var(--surface); padding: 6px 12px; z-index: 100; border-radius: var(--radius-sm); }
.skip:focus { left: 8px; }

/* ------------------------------------------------------------ controls */
input, select, textarea, button { font: inherit; color: inherit; }
input:not([type=checkbox]):not([type=radio]), select, textarea {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: .45rem .65rem; min-height: 2.25rem; width: 100%; transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--focus); box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 22%, transparent); }
textarea { resize: vertical; line-height: 1.5; }
.mono-in { font-family: var(--font-mono); font-size: .9em; }
input[type=checkbox] { accent-color: var(--accent); width: 1rem; height: 1rem; }
input.num { max-width: 7.5rem; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .35rem;
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  border-radius: var(--radius-sm); padding: .42rem .95rem; min-height: 2.25rem; cursor: pointer;
  font-weight: 500; white-space: nowrap; transition: background .15s, border-color .15s;
}
.btn:hover:not(:disabled) { background: var(--surface-2); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.danger { background: var(--err); border-color: var(--err); color: #fff; }
:root[data-theme="dark"] .btn.danger { color: #1a0f0b; }
.btn.danger-ghost { color: var(--err); border-color: color-mix(in srgb, var(--err) 40%, var(--line)); }
.btn.danger-ghost:hover:not(:disabled) { background: var(--err-soft); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--link); }
.btn.sm { padding: .2rem .6rem; min-height: 1.9rem; font-size: .86rem; }
.btn.block { width: 100%; min-height: 2.6rem; }
.btn-row { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.icon-btn {
  border: 1px solid transparent; background: transparent; border-radius: var(--radius-sm); cursor: pointer;
  width: 2.25rem; height: 2.25rem; display: inline-grid; place-items: center; font-size: 1.05rem; color: var(--muted);
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.linkish { background: none; border: 0; padding: 0; color: var(--link); cursor: pointer; text-align: left; }
.linkish:hover { text-decoration: underline; }

/* ------------------------------------------------------------ badges / pills / chips */
.badge {
  --c: var(--t-obs);
  display: inline-block; flex: none; font-size: .74rem; font-weight: 600; letter-spacing: .06em;
  padding: .08rem .45rem; border-radius: 3px; color: var(--c);
  border: 1px solid color-mix(in srgb, var(--c) 45%, transparent);
  background: color-mix(in srgb, var(--c) 10%, transparent);
}
.badge[data-t=decision] { --c: var(--t-decision); } .badge[data-t=rule] { --c: var(--t-rule); }
.badge[data-t=progress] { --c: var(--t-progress); } .badge[data-t=problem] { --c: var(--t-problem); }
.badge[data-t=fix], .badge[data-t=bugfix] { --c: var(--t-fix); } .badge[data-t=change], .badge[data-t=refactor], .badge[data-t=feature] { --c: var(--t-change); }
.badge[data-t=discovery] { --c: var(--t-discovery); } .badge[data-t=kb] { --c: var(--t-kb); }
.badge[data-t=digest] { --c: var(--t-digest); } .badge[data-t=asset] { --c: var(--t-asset); }

.pill {
  display: inline-block; font-size: .76rem; padding: .05rem .5rem; border-radius: 999px; white-space: nowrap;
  background: var(--surface-2); color: var(--muted); border: 1px solid var(--line-soft);
}
.pill.st-active { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.pill.st-verified { background: color-mix(in srgb, var(--link) 14%, transparent); color: var(--link); border-color: transparent; }
.pill.st-superseded { background: var(--surface-3); color: var(--muted); text-decoration: line-through; border-color: transparent; }
.pill.st-rejected { background: var(--err-soft); color: var(--err); border-color: transparent; }
.pill.st-stale { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.pill.role-admin { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.pill.role-editor { background: color-mix(in srgb, var(--link) 14%, transparent); color: var(--link); border-color: transparent; }

.chips { display: inline-flex; flex-wrap: wrap; gap: .3rem; }
.chip {
  font-family: var(--font-mono); font-size: .76rem; padding: .02rem .45rem; border-radius: 3px;
  background: var(--surface-2); color: var(--text); border: 1px solid var(--line-soft);
}
a.chip:hover { border-color: var(--link); text-decoration: none; color: var(--link); }
.chip.more { color: var(--muted); }

/* ------------------------------------------------------------ states / toasts */
.state { padding: 2rem 1rem; text-align: center; color: var(--muted); }
.state.error { color: var(--err); background: var(--err-soft); border-radius: var(--radius); padding: 1rem; display: flex; gap: .6rem; justify-content: center; align-items: center; flex-wrap: wrap; }
.state.loading { display: flex; gap: .6rem; justify-content: center; align-items: center; }
.spinner { width: 1rem; height: 1rem; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.boot { min-height: 100vh; display: grid; place-items: center; }

#toasts { position: fixed; bottom: 1rem; left: 50%; transform: translateX(-50%); z-index: 300; display: flex; flex-direction: column; gap: .5rem; align-items: center; pointer-events: none; }
.toast { background: var(--text); color: var(--bg); padding: .55rem 1rem; border-radius: var(--radius); box-shadow: var(--shadow-lg); max-width: min(90vw, 520px); transition: opacity .3s, transform .3s; pointer-events: auto; }
.toast.err { background: var(--err); color: #fff; }
.toast.out { opacity: 0; transform: translateY(8px); }

.note { padding: .65rem .85rem; border-radius: var(--radius-sm); margin: .6rem 0; border-left: 3px solid var(--line); background: var(--surface-2); }
.note.warn { border-left-color: var(--warn); background: var(--warn-soft); }
.note.ok { border-left-color: var(--ok); background: var(--ok-soft); }

/* ------------------------------------------------------------ shell */
.topbar {
  position: sticky; top: 0; z-index: 40; display: flex; align-items: center; gap: .9rem;
  height: 3.5rem; padding: 0 1rem; background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(8px); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: .55rem; color: var(--text); flex: none; }
.brand:hover { text-decoration: none; }
.brand-name { font-family: var(--font-serif); font-weight: 700; font-size: 1.15rem; letter-spacing: .12em; }
.seal {
  display: inline-grid; place-items: center; width: 1.9rem; height: 1.9rem; border-radius: 4px;
  background: var(--accent); color: var(--accent-ink); font-family: var(--font-serif); font-weight: 700; font-size: 1.05rem;
  box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--accent-ink) 30%, transparent);
  transform: rotate(-3deg);
}
.seal.lg { width: 3.2rem; height: 3.2rem; font-size: 1.8rem; border-radius: 6px; }
.spacer { flex: 1; }
.proj { display: inline-flex; background: var(--surface-2); border-radius: 6px; padding: 3px; gap: 2px; border: 1px solid var(--line-soft); }
.proj-btn { border: 0; background: transparent; padding: .2rem .65rem; border-radius: 4px; cursor: pointer; font-size: .86rem; color: var(--muted); font-weight: 500; }
.proj-btn:hover { color: var(--text); }
.proj-btn[aria-checked=true] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.user { position: relative; }
.user-btn { display: flex; align-items: center; gap: .45rem; background: none; border: 1px solid transparent; padding: .2rem .45rem; border-radius: 999px; cursor: pointer; }
.user-btn:hover { background: var(--surface-2); }
.avatar { width: 1.8rem; height: 1.8rem; border-radius: 50%; display: grid; place-items: center; background: var(--surface-3); font-weight: 700; font-size: .85rem; }
.menu {
  position: absolute; right: 0; top: calc(100% + 6px); min-width: 200px; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-lg); padding: .35rem; z-index: 60;
}
.menu-who { display: flex; flex-direction: column; padding: .45rem .6rem .55rem; border-bottom: 1px solid var(--line-soft); margin-bottom: .3rem; }
.menu [role=menuitem] { display: block; width: 100%; text-align: left; background: none; border: 0; padding: .45rem .6rem; border-radius: 4px; cursor: pointer; color: var(--text); }
.menu [role=menuitem]:hover, .menu [role=menuitem]:focus-visible { background: var(--surface-2); text-decoration: none; }

.layout { display: grid; grid-template-columns: 208px minmax(0, 1fr); min-height: calc(100vh - 3.5rem); }
.side { border-right: 1px solid var(--line); padding: 1rem .6rem; position: sticky; top: 3.5rem; height: calc(100vh - 3.5rem); overflow-y: auto; }
.nav-group + .nav-group { margin-top: 1.2rem; padding-top: 1rem; border-top: 1px dashed var(--line); }
.nav-title { font-size: .74rem; color: var(--muted); letter-spacing: .2em; padding: 0 .6rem .35rem; }
.side a { display: flex; align-items: center; gap: .55rem; padding: .42rem .6rem; border-radius: 5px; color: var(--text); }
.side a:hover { background: var(--surface-2); text-decoration: none; }
.side a[aria-current=page] { background: var(--surface); box-shadow: var(--shadow); color: var(--accent); font-weight: 600; position: relative; }
.side a[aria-current=page]::before { content: ""; position: absolute; left: -.6rem; top: .35rem; bottom: .35rem; width: 3px; border-radius: 0 2px 2px 0; background: var(--accent); }
.nav-ic { width: 1.1rem; text-align: center; color: var(--muted); }
.side a[aria-current=page] .nav-ic { color: var(--accent); }
.content { padding: 1.6rem clamp(1rem, 3vw, 2.5rem) 4rem; max-width: 1180px; width: 100%; outline: none; }

/* ------------------------------------------------------------ page heads / toolbars */
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.1rem; padding-bottom: .9rem; border-bottom: 1px solid var(--line); }
.page-head p { margin: .3rem 0 0; }
.head-actions { display: flex; gap: .5rem; }
.toolbar { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; margin-bottom: 1rem; }
.toolbar > input { flex: 1 1 220px; max-width: 360px; }
.f-group { display: inline-flex; align-items: center; gap: .4rem; white-space: nowrap; }
.f-group select, .f-group input { width: auto; }
.sec-title { font-family: var(--font-serif); font-size: 1.08rem; letter-spacing: .05em; }
.back { display: inline-block; margin-bottom: .6rem; font-size: .9rem; }

/* ------------------------------------------------------------ search */
.search-hero { padding: 1.4rem 0 1rem; }
.hero-label { display: block; font-family: var(--font-serif); font-size: 1.5rem; font-weight: 700; letter-spacing: .08em; margin-bottom: .7rem; }
.q-wrap { position: relative; }
.q-icon { position: absolute; left: 1rem; top: 50%; transform: translateY(-50%); font-size: 1.4rem; color: var(--muted); pointer-events: none; }
input:not([type]).q-input, input[type=search].q-input {
  font-size: 1.15rem; min-height: 3.4rem; padding: .7rem 1rem .7rem 2.9rem; border-radius: 10px;
  border: 1.5px solid var(--line); box-shadow: var(--shadow); background: var(--surface);
}
input[type=search].q-input:focus { border-color: var(--accent); box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 16%, transparent), var(--shadow); }
.filters { display: flex; flex-wrap: wrap; gap: .6rem 1rem; align-items: center; margin-top: .8rem; }
.seg { display: inline-flex; flex-wrap: wrap; gap: .3rem; border: 0; padding: 0; margin: 0; }
.seg-item { position: relative; cursor: pointer; }
.seg-item input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.seg-item span { display: inline-block; padding: .2rem .7rem; border-radius: 999px; border: 1px solid var(--line); font-size: .86rem; color: var(--muted); background: var(--surface); user-select: none; }
.seg-item input:checked + span { background: var(--text); color: var(--bg); border-color: var(--text); }
.seg-item input:focus-visible + span { outline: 2px solid var(--focus); outline-offset: 2px; }
.switch { display: inline-flex; align-items: center; gap: .35rem; font-size: .88rem; cursor: pointer; user-select: none; }
.results-status { min-height: 1.4rem; margin: .3rem 0; }

.hit-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .55rem; }
.hit {
  display: block; width: 100%; text-align: left; background: var(--surface); border: 1px solid var(--line-soft);
  border-radius: var(--radius); padding: .8rem 1rem; cursor: pointer; color: var(--text); transition: border-color .15s, box-shadow .15s, transform .15s;
}
.hit:hover { border-color: var(--line); box-shadow: var(--shadow); }
.hit:active { transform: translateY(1px); }
.hit-top { display: flex; align-items: center; gap: .55rem; flex-wrap: wrap; }
.hit-title { font-weight: 600; font-size: 1.02rem; flex: 1 1 auto; min-width: 0; overflow-wrap: anywhere; }
.snippet { color: var(--muted); margin: .35rem 0 .25rem; font-size: .92rem; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.hit-meta { display: flex; flex-wrap: wrap; gap: .4rem .8rem; align-items: center; font-size: .8rem; color: var(--muted); margin-top: .3rem; }
.hit-list.compact .hit { padding: .55rem .75rem; }
.why { display: inline-flex; gap: .4rem; font-size: .76rem; color: var(--muted); }
.why span { padding: 0 .35rem; border-radius: 3px; background: var(--surface-2); }
.why-1 { color: var(--t-discovery); } .why-2 { color: var(--t-asset); }
.more { text-align: center; margin: 1rem 0; }

.welcome { margin-top: 1rem; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .7rem; margin: .8rem 0; }
.tile { background: var(--surface); border: 1px solid var(--line-soft); border-radius: var(--radius); padding: .8rem 1rem; }
.tile-v { font-family: var(--font-serif); font-size: 1.6rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.tile-l { color: var(--muted); font-size: .85rem; }
.tips { margin-top: 1.4rem; padding: 1rem 1.2rem; border: 1px dashed var(--line); border-radius: var(--radius); }
.tips h3 { font-size: .95rem; margin-bottom: .3rem; }
.tips ul { margin: 0; padding-left: 1.2rem; color: var(--muted); }

.pager { display: flex; justify-content: center; align-items: center; gap: 1rem; margin: 1.2rem 0; }

/* ------------------------------------------------------------ cards / panels */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: .8rem; }
.card {
  display: flex; flex-direction: column; gap: .4rem; background: var(--surface); border: 1px solid var(--line-soft);
  border-radius: var(--radius); padding: .9rem 1rem; color: var(--text); transition: box-shadow .15s, border-color .15s;
  border-top: 3px solid var(--t-asset);
}
.card:hover { text-decoration: none; box-shadow: var(--shadow); border-color: var(--line); border-top-color: var(--accent); }
.card-top { display: flex; justify-content: space-between; gap: .5rem; align-items: center; }
.card .code { font-weight: 700; font-size: .95rem; }
.card-text { color: var(--muted); font-size: .9rem; margin: 0; flex: 1; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }
.panel { background: var(--surface); border: 1px solid var(--line-soft); border-radius: var(--radius); padding: 1rem 1.15rem; margin-bottom: 1rem; }
.panel > .sec-title { margin-bottom: .6rem; }
.detail-grid { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: 1rem; align-items: start; }
details summary { cursor: pointer; color: var(--link); margin: .4rem 0; }
.files { list-style: none; padding: 0; margin: .3rem 0; display: flex; flex-direction: column; gap: .2rem; font-size: .85rem; overflow-wrap: anywhere; }

.rules { display: flex; flex-direction: column; gap: .7rem; }
.rule { background: var(--surface); border: 1px solid var(--line-soft); border-left: 3px solid var(--t-rule); border-radius: var(--radius); padding: .8rem 1rem; }
.rule.inactive { opacity: .65; border-left-color: var(--line); }
.panel .rule { border-color: var(--line-soft); margin-bottom: .6rem; }
.rule-top { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; }
.rule-top .linkish { font-weight: 700; }
.quote {
  margin: .55rem 0; padding: .45rem .9rem; border-left: 2px solid var(--accent); background: var(--accent-soft);
  font-family: var(--font-serif); font-size: 1rem; border-radius: 0 var(--radius-sm) var(--radius-sm) 0; overflow-wrap: anywhere;
}
.quote::before { content: "“"; color: var(--accent); font-weight: 700; margin-right: .1em; }
.quote::after { content: "”"; color: var(--accent); font-weight: 700; margin-left: .1em; }
.rule-text { margin: .3rem 0 .45rem; overflow-wrap: anywhere; }

.md h3, .md h4, .md h5 { font-family: var(--font-serif); margin: 1rem 0 .35rem; }
.md ul { padding-left: 1.3rem; margin: .3rem 0; }
.md li.task { list-style: none; margin-left: -1.2rem; }
.md .tick { display: inline-block; width: 1.2rem; color: var(--muted); }
.md li.done { color: var(--muted); }
.md li.done .tick { color: var(--ok); }

/* ------------------------------------------------------------ drawer */
.scrim { position: fixed; inset: 0; background: rgba(20, 15, 8, .32); opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 80; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(640px, 92vw); background: var(--surface);
  border-left: 1px solid var(--line); box-shadow: var(--shadow-lg); z-index: 90; display: flex; flex-direction: column;
  transform: translateX(105%); transition: transform .24s cubic-bezier(.2, .8, .2, 1); visibility: hidden; outline: none;
}
body.drawer-open .drawer { transform: none; visibility: visible; }
body.drawer-open .scrim { opacity: 1; pointer-events: auto; }
.drawer-head { display: flex; align-items: center; gap: .6rem; padding: .8rem 1rem .8rem 1.25rem; border-bottom: 1px solid var(--line); }
.drawer-head h2 { flex: 1; font-size: 1rem; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.drawer-body { overflow-y: auto; padding: 1rem 1.25rem 2rem; flex: 1; overscroll-behavior: contain; }
.d-head { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.d-title { font-family: var(--font-serif); font-size: 1.2rem; font-weight: 700; margin: .6rem 0 .4rem; overflow-wrap: anywhere; }
.d-sec { margin-top: 1.1rem; }
.d-sec h3 { font-size: .8rem; letter-spacing: .18em; color: var(--muted); font-weight: 600; margin-bottom: .45rem; padding-bottom: .25rem; border-bottom: 1px dashed var(--line); }
.facts { margin: 0; padding-left: 1.3rem; display: flex; flex-direction: column; gap: .3rem; overflow-wrap: anywhere; }
.meta { display: grid; grid-template-columns: auto 1fr; gap: .25rem 1rem; margin: 0; font-size: .88rem; }
.meta dt { color: var(--muted); }
.meta dd { margin: 0; overflow-wrap: anywhere; }
.link-list { display: flex; flex-direction: column; gap: .25rem; }
.link-row {
  display: flex; align-items: center; gap: .5rem; width: 100%; text-align: left; background: none; border: 1px solid transparent;
  border-radius: 5px; padding: .35rem .5rem; cursor: pointer; color: var(--text); font-size: .9rem;
}
.link-row:hover { background: var(--surface-2); }
.link-row.current { background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 30%, transparent); }
.lr-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.link-row time { font-size: .78rem; flex: none; }
.rel { font-size: .78rem; color: var(--link); flex: none; }
.chain .link-row { position: relative; padding-left: 1.3rem; }
.chain .link-row::before { content: ""; position: absolute; left: .5rem; top: 50%; width: 6px; height: 6px; border-radius: 50%; background: var(--line); transform: translateY(-50%); }
.chain .link-row:last-child::before { background: var(--ok); }
.d-actions { position: sticky; bottom: -2rem; margin: 1.4rem -1.25rem -2rem; padding: .8rem 1.25rem; background: var(--surface); border-top: 1px solid var(--line); display: flex; gap: .5rem; flex-wrap: wrap; }
.body-text { white-space: pre-wrap; word-break: break-word; font: .9rem/1.65 var(--font-sans); background: var(--surface-2); padding: .9rem 1rem; border-radius: var(--radius-sm); max-height: none; }

/* ------------------------------------------------------------ modal / forms */
dialog.modal {
  border: 1px solid var(--line); border-radius: 10px; padding: 0; background: var(--surface); color: var(--text);
  width: min(460px, calc(100vw - 2rem)); box-shadow: var(--shadow-lg); max-height: calc(100vh - 2rem);
}
dialog.modal.wide { width: min(820px, calc(100vw - 2rem)); }
dialog.modal::backdrop { background: rgba(20, 15, 8, .4); }
dialog.modal > header { display: flex; align-items: center; padding: .8rem 1rem .8rem 1.25rem; border-bottom: 1px solid var(--line); }
dialog.modal > header h2 { flex: 1; font-size: 1.05rem; font-family: var(--font-serif); }
.modal-body { padding: 1rem 1.25rem; overflow-y: auto; }
dialog.modal > footer { display: flex; justify-content: flex-end; gap: .5rem; padding: .8rem 1.25rem; border-top: 1px solid var(--line); }
.form { display: flex; flex-direction: column; gap: .8rem; }
.field { display: flex; flex-direction: column; gap: .3rem; min-width: 0; }
.field > label { font-size: .88rem; font-weight: 500; }
.hint { color: var(--muted); font-size: .8rem; }
.check { display: inline-flex; align-items: center; gap: .45rem; cursor: pointer; }
.form-err { color: var(--err); font-size: .9rem; min-height: 1.2em; }
.form-err:empty { min-height: 0; }
.form-actions { display: flex; justify-content: flex-end; gap: .5rem; margin-top: .3rem; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .8rem; }
.form-grid .span2 { grid-column: span 2; }
.sub { font-size: .95rem; margin-top: .4rem; }
.copy-row { display: flex; gap: .5rem; }
.token-field { font-size: .95rem !important; background: var(--surface-2) !important; }
details textarea { margin: .4rem 0; font-size: .82rem; }

/* ------------------------------------------------------------ tables */
.table-wrap { overflow-x: auto; border: 1px solid var(--line-soft); border-radius: var(--radius); background: var(--surface); }
.tbl { width: 100%; border-collapse: collapse; font-size: .9rem; }
.tbl th { text-align: left; font-weight: 600; font-size: .8rem; color: var(--muted); letter-spacing: .06em; background: var(--surface-2); padding: .55rem .8rem; white-space: nowrap; }
.tbl td { padding: .55rem .8rem; border-top: 1px solid var(--line-soft); vertical-align: middle; font-variant-numeric: tabular-nums; }
.tbl tbody tr:hover td { background: color-mix(in srgb, var(--surface-2) 45%, transparent); }
.tbl td.actions { text-align: right; white-space: nowrap; }
.tbl td.detail { max-width: 340px; }
.tbl.mini { font-size: .84rem; }
.tbl.mini th, .tbl.mini td { padding: .35rem .6rem; }
.tbl.edit td { padding: .3rem .35rem; }
.tbl.edit input, .tbl.edit select { min-height: 2rem; padding: .25rem .45rem; }
.tbl.edit input[name=model] { min-width: 12rem; }

/* ------------------------------------------------------------ console specifics */
.channel-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(380px, 1fr)); gap: 1rem; }
.panel.channel { display: flex; flex-direction: column; gap: .7rem; margin: 0; }
.panel.channel.inactive { opacity: .7; }
.test-result:empty { display: none; }
.slot-grid { display: grid; grid-template-columns: 180px 1fr 1fr; gap: .8rem 1rem; align-items: end; margin-bottom: 1rem; }
.slot-l { padding-bottom: .5rem; }
.big-num { font-family: var(--font-serif); font-size: 1.6rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.meter { height: .6rem; background: var(--surface-2); border-radius: 999px; overflow: hidden; margin: .6rem 0 .3rem; }
.meter > span { display: block; height: 100%; background: var(--ok); border-radius: inherit; transition: width .4s; min-width: 2px; }
.meter.high > span { background: var(--warn); }
.meter.over > span { background: var(--err); }
.cov-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: .8rem; margin-bottom: 1rem; }
.cov-list .panel { margin: 0; }
.cov .rule-top .btn { margin-left: auto; }

/* ------------------------------------------------------------ login */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 1rem; position: relative;
  background:
    repeating-linear-gradient(0deg, transparent 0 31px, color-mix(in srgb, var(--line) 35%, transparent) 31px 32px),
    var(--bg); }
.login-theme { position: absolute; top: .8rem; right: .8rem; }
.login-card { width: min(380px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow-lg); padding: 1.8rem 1.6rem 1.4rem; display: flex; flex-direction: column; gap: .9rem; }
.login-brand { display: flex; align-items: center; gap: .9rem; margin-bottom: .4rem; }
.login-brand h1 { font-size: 1.5rem; letter-spacing: .14em; }
.login-brand p { margin: 0; }

/* ------------------------------------------------------------ responsive */
@media (max-width: 960px) {
  .detail-grid { grid-template-columns: minmax(0, 1fr); }
  .channel-list { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 760px) {
  body { font-size: 14.5px; }
  .topbar { gap: .5rem; padding: 0 .6rem; height: 3.2rem; }
  .brand-name, .user-name { display: none; }
  .proj-btn { padding: .2rem .45rem; font-size: .8rem; }
  .layout { display: block; }
  .side {
    position: sticky; top: 3.2rem; z-index: 30; height: auto; display: flex; gap: .2rem; overflow-x: auto; padding: .4rem .5rem;
    border-right: 0; border-bottom: 1px solid var(--line); background: var(--bg); scrollbar-width: none;
  }
  .side::-webkit-scrollbar { display: none; }
  .nav-group { display: contents; }
  .nav-group + .nav-group { margin: 0; padding: 0; border: 0; }
  .nav-title { display: none; }
  .side a { flex: none; padding: .3rem .65rem; font-size: .88rem; white-space: nowrap; }
  .side a[aria-current=page]::before { display: none; }
  .nav-ic { display: none; }
  .content { padding: 1rem .9rem 3rem; }
  h1 { font-size: 1.35rem; }
  .hero-label { font-size: 1.25rem; }
  .toolbar > input { max-width: none; }
  .drawer { width: 100vw; border-left: 0; }
  .form-grid { grid-template-columns: minmax(0, 1fr); }
  .form-grid .span2 { grid-column: auto; }
  .slot-grid { grid-template-columns: minmax(0, 1fr); gap: .4rem; }
  .slot-l { padding: .6rem 0 0; border-top: 1px dashed var(--line); }
  .copy-row { flex-direction: column; }
  /* stacked tables */
  .table-wrap:not(:has(.tbl.edit)):not(:has(.tbl.mini)) { border: 0; background: none; }
  .tbl:not(.edit):not(.mini) thead { display: none; }
  .tbl:not(.edit):not(.mini), .tbl:not(.edit):not(.mini) tbody, .tbl:not(.edit):not(.mini) tr, .tbl:not(.edit):not(.mini) td { display: block; width: 100%; }
  .tbl:not(.edit):not(.mini) tr { background: var(--surface); border: 1px solid var(--line-soft); border-radius: var(--radius); margin-bottom: .6rem; padding: .4rem 0; }
  .tbl:not(.edit):not(.mini) td { border: 0; padding: .25rem .8rem; display: flex; gap: .8rem; justify-content: space-between; text-align: right; }
  .tbl:not(.edit):not(.mini) td::before { content: attr(data-label); color: var(--muted); font-size: .8rem; text-align: left; flex: none; }
  .tbl:not(.edit):not(.mini) td.detail { max-width: none; }
  .tbl:not(.edit):not(.mini) td.actions { justify-content: flex-end; }
  .tbl:not(.edit):not(.mini) td.actions::before { display: none; }
}
@media (max-width: 440px) {
  .proj { padding: 2px; }
  .proj-btn { padding: .15rem .35rem; }
  .filters { gap: .5rem .7rem; }
  dialog.modal, dialog.modal.wide { width: 100vw; max-width: 100vw; height: 100dvh; max-height: 100dvh; border-radius: 0; margin: 0; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation-duration: .01ms !important; }
}
.form > .btn { align-self: flex-start; }
