/* Junior Kyvos: ChatGPT-style layout, light/dark, no build step. */
:root {
  --bg: #ffffff; --sidebar: #f7f7f8; --surface: #ffffff; --text: #1f2328; --muted: #5f6672;
  --line: #e5e5ea; --hover: #ececf1; --active: #e3e3ea; --bubble: #f1f1f4;
  --accent: #5146e5; --accent-text: #ffffff; --accent-soft: #ecebfd;
  --cite-bg: #e9e8fd; --cite-text: #3b32c9; --code-bg: #0f1117; --code-head: #1b1e27; --code-text: #e6edf3;
  --ok: #1a7f37; --ok-soft: #e8f5ec; --err: #cf222e; --warn-bg: #fff6d6; --warn-text: #6b4b00;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 8px 24px rgba(0,0,0,.08);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #212121; --sidebar: #171717; --surface: #2a2a2a; --text: #ececec; --muted: #9b9ba1;
    --line: #333336; --hover: #2a2a2d; --active: #343438; --bubble: #303033;
    --accent: #8b84ff; --accent-text: #111111; --accent-soft: #2c2a4a;
    --cite-bg: #33305a; --cite-text: #c9c5ff; --code-bg: #0d0d0f; --code-head: #19191d;
    --ok: #4ac26b; --ok-soft: #1d2f22; --err: #ff7b72; --warn-bg: #3a3214; --warn-text: #f2d77a;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.35);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #212121; --sidebar: #171717; --surface: #2a2a2a; --text: #ececec; --muted: #9b9ba1;
  --line: #333336; --hover: #2a2a2d; --active: #343438; --bubble: #303033;
  --accent: #8b84ff; --accent-text: #111111; --accent-soft: #2c2a4a;
  --cite-bg: #33305a; --cite-text: #c9c5ff; --code-bg: #0d0d0f; --code-head: #19191d;
  --ok: #4ac26b; --ok-soft: #1d2f22; --err: #ff7b72; --warn-bg: #3a3214; --warn-text: #f2d77a;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.35);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.6 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased; }
button { font: inherit; color: inherit; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2;
  stroke-linecap: round; stroke-linejoin: round; flex: none; }
.muted { color: var(--muted); }
[hidden] { display: none !important; }

/* ---- shell ---------------------------------------------------------------- */
.app { display: flex; height: 100vh; height: 100dvh; overflow: hidden; }
.sidebar { width: 264px; flex: none; background: var(--sidebar); display: flex; flex-direction: column;
  padding: 10px; gap: 6px; border-right: 1px solid var(--line); transition: margin-left .2s ease; }
.app.sb-collapsed .sidebar { margin-left: -264px; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; position: relative; }
.scrim { display: none; }

.sb-head { display: flex; align-items: center; justify-content: space-between; padding: 4px 4px 6px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; }
.logo { display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), #8f5bff); color: #fff; font-weight: 700; font-size: 12px; letter-spacing: -.02em; }
.logo.big { width: 48px; height: 48px; border-radius: 14px; font-size: 19px; }
.icon-btn { display: inline-grid; place-items: center; width: 36px; height: 36px; border: 0; border-radius: 8px;
  background: transparent; cursor: pointer; color: var(--muted); }
.icon-btn:hover { background: var(--hover); color: var(--text); }
.new-chat { display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface); cursor: pointer; font-weight: 550; }
.new-chat:hover { background: var(--hover); }
.search { display: flex; align-items: center; gap: 8px; padding: 7px 10px; border-radius: 10px; color: var(--muted); }
.search:focus-within { background: var(--surface); box-shadow: inset 0 0 0 1px var(--line); }
.search input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; color: var(--text); font: inherit; }

.chat-list { flex: 1; overflow-y: auto; margin: 4px -4px 0; padding: 0 4px; }
.group-label { font-size: 12px; font-weight: 600; color: var(--muted); padding: 14px 10px 6px; }
.chat-item { position: relative; display: flex; align-items: center; border-radius: 8px; }
.chat-item a { flex: 1; min-width: 0; padding: 8px 10px; border-radius: 8px; color: var(--text); text-decoration: none;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 14px; }
.chat-item:hover, .chat-item.current { background: var(--hover); }
.chat-item.current { background: var(--active); }
.chat-item .del { position: absolute; right: 4px; width: 28px; height: 28px; opacity: 0; }
.chat-item:hover .del, .chat-item .del:focus-visible { opacity: 1; }
.chat-item:hover a { padding-right: 34px; }
.list-empty { padding: 14px 10px; color: var(--muted); font-size: 14px; }

.sb-foot { border-top: 1px solid var(--line); padding-top: 6px; display: flex; flex-direction: column; gap: 2px; }
.sb-link { display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 10px; border: 0; border-radius: 8px;
  background: transparent; cursor: pointer; text-align: left; font-size: 14px; }
.sb-link:hover, .sb-link.current { background: var(--hover); }
.count { margin-left: auto; font-size: 12px; color: var(--muted); }

.topbar { display: flex; align-items: center; gap: 6px; padding: 8px 12px; min-height: 52px; }
.app:not(.sb-collapsed) #sb-open { display: none; }
.version { display: flex; align-items: center; gap: 6px; padding: 6px 10px; border-radius: 10px; font-weight: 600; font-size: 15px; }
.version select { font: inherit; font-weight: 600; border: 0; background: transparent; color: var(--text); cursor: pointer; }
.version:hover { background: var(--hover); }
.spacer { flex: 1; }
.banner { margin: 0 auto 8px; max-width: 768px; width: calc(100% - 32px); background: var(--warn-bg); color: var(--warn-text);
  border-radius: 10px; padding: 8px 12px; font-size: 14px; }
.link { border: 0; background: none; color: inherit; text-decoration: underline; cursor: pointer; padding: 0; font-weight: 600; }

/* ---- chat ----------------------------------------------------------------- */
.view { display: none; flex: 1; min-height: 0; }
.view.active { display: flex; flex-direction: column; }
.thread { flex: 1; overflow-y: auto; overflow-x: hidden; }
.msgs { max-width: 768px; margin: 0 auto; padding: 8px 20px 24px; display: flex; flex-direction: column; gap: 28px; }

.empty { max-width: 720px; margin: 0 auto; padding: 12vh 20px 24px; text-align: center; }
.empty h1 { font-size: 28px; margin: 16px 0 6px; letter-spacing: -.01em; }
.empty p { margin: 0 0 28px; }
.suggestions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; text-align: left; }
.suggestion { display: flex; flex-direction: column; gap: 2px; padding: 12px 14px; border: 1px solid var(--line);
  border-radius: 14px; background: var(--surface); cursor: pointer; }
.suggestion:hover { background: var(--hover); }
.suggestion strong { font-weight: 600; font-size: 14px; }
.suggestion span { color: var(--muted); font-size: 13px; }

.row.user { display: flex; flex-direction: column; align-items: flex-end; }
.meta { margin-top: 4px; padding-right: 8px; font-size: 11.5px; color: var(--muted); }
.row.day { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 12px; }
.row.day::before, .row.day::after { content: ""; flex: 1; border-top: 1px solid var(--line); }
.act-time { align-self: center; margin-left: 6px; font-size: 12px; color: var(--muted); }
.bubble { max-width: min(85%, 640px); background: var(--bubble); padding: 10px 16px; border-radius: 20px;
  white-space: pre-wrap; overflow-wrap: anywhere; }
.row.bot { display: grid; grid-template-columns: 30px minmax(0, 1fr); gap: 14px; }
.row.bot .logo { width: 30px; height: 30px; font-size: 11.5px; margin-top: 2px; }
.content { min-width: 0; }
.steps { display: flex; flex-direction: column; gap: 4px; margin-bottom: 6px; }
.step { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13.5px; }
.step.err { color: var(--err); }
.spinner { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--line); border-top-color: var(--accent);
  animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.typing { display: inline-flex; gap: 4px; padding: 8px 0; }
.typing span { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite ease-in-out; }
.typing span:nth-child(2) { animation-delay: .15s; } .typing span:nth-child(3) { animation-delay: .3s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-2px); } }

/* markdown */
.md { overflow-wrap: anywhere; }
.md > :first-child { margin-top: 0; } .md > :last-child { margin-bottom: 0; }
.md p { margin: 0 0 12px; }
.md h1, .md h2, .md h3, .md h4 { margin: 20px 0 8px; line-height: 1.3; }
.md h1 { font-size: 20px; } .md h2 { font-size: 18px; } .md h3 { font-size: 16px; } .md h4 { font-size: 15px; }
.md ul, .md ol { margin: 0 0 12px; padding-left: 24px; }
.md li { margin: 4px 0; }
.md a { color: var(--accent); }
.md code { font: 13px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; background: var(--bubble);
  padding: 1px 5px; border-radius: 5px; }
.md blockquote { margin: 0 0 12px; padding: 2px 14px; border-left: 3px solid var(--line); color: var(--muted); }
.md table { border-collapse: collapse; margin: 0 0 14px; display: block; overflow-x: auto; max-width: 100%; font-size: 14px; }
.md th, .md td { border: 1px solid var(--line); padding: 7px 10px; text-align: left; vertical-align: top; }
.md th { background: var(--bubble); font-weight: 600; }
.md .diagram { margin: 0 0 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface);
  overflow: hidden; }
.md .diagram-view { padding: 12px; overflow-x: auto; }
.md .diagram-view svg { display: block; width: 100%; max-width: 100%; height: auto; margin: 0 auto; fill: initial;
  stroke: initial; stroke-width: initial; stroke-linecap: initial; stroke-linejoin: initial; }
.md details { margin: 0 0 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
.md summary { display: flex; align-items: center; gap: 8px; padding: 10px 14px; cursor: pointer; font-weight: 600;
  list-style: none; }
.md summary::-webkit-details-marker { display: none; }
.md summary::before { content: "›"; color: var(--muted); transition: transform .15s; }
.md details[open] > summary::before { transform: rotate(90deg); }
.md details > :not(summary) { margin-left: 14px; margin-right: 14px; }
.md details > :last-child:not(summary) { margin-bottom: 12px; }
.md hr { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }
.codeblock { margin: 0 0 14px; border-radius: 10px; overflow: hidden; background: var(--code-bg); }
.codeblock .code-head { display: flex; align-items: center; justify-content: space-between; padding: 6px 12px;
  background: var(--code-head); color: #a7adba; font-size: 12px; }
.codeblock .code-head button { display: flex; align-items: center; gap: 6px; border: 0; background: none; color: inherit; cursor: pointer; font-size: 12px; }
.codeblock .code-head svg { width: 14px; height: 14px; }
.codeblock pre { margin: 0; padding: 12px 14px; overflow: auto; max-height: 420px; }
.codeblock pre code { background: none; padding: 0; color: var(--code-text); font-size: 13px; }
.cite { display: inline-grid; place-items: center; min-width: 18px; height: 18px; padding: 0 5px; margin: 0 1px;
  border-radius: 9px; background: var(--cite-bg); color: var(--cite-text); font-size: 11px; font-weight: 650;
  vertical-align: 2px; cursor: pointer; line-height: 1; }
.cite:hover { filter: brightness(.95); }
.note-marker { color: var(--muted); font-size: 13px; font-style: italic; }

.sources { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.chip { display: inline-flex; align-items: center; gap: 6px; max-width: 280px; padding: 4px 10px 4px 6px;
  border: 1px solid var(--line); border-radius: 999px; color: var(--text); text-decoration: none; font-size: 12.5px; background: var(--surface); }
.chip:hover { background: var(--hover); }
.chip .n { color: var(--cite-text); background: var(--cite-bg); border-radius: 999px; padding: 0 6px; font-weight: 650; font-size: 11px; }
.chip .k { color: var(--muted); }
.chip .t { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chip svg { width: 13px; height: 13px; color: var(--muted); }

.actions { display: flex; gap: 2px; margin-top: 8px; opacity: 0; transition: opacity .15s; }
.row.bot:hover .actions, .row.bot.last .actions, .actions:focus-within { opacity: 1; }
.act { display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 8px; border: 0; border-radius: 8px;
  background: transparent; color: var(--muted); cursor: pointer; font-size: 12.5px; }
.act:hover:not(:disabled) { background: var(--hover); color: var(--text); }
.act:disabled { opacity: .55; cursor: default; }
.act.done { color: var(--ok); opacity: 1; }
.act .spinner, .btn .spinner { width: 13px; height: 13px; }
.row.bot:not(.last) [data-act="save"] { display: none; }
.cite:focus-visible, .act:focus-visible, .chip:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.memory-pill.undone { background: var(--bubble); color: var(--muted); text-decoration: line-through; }
.loading { display: flex; align-items: center; justify-content: center; gap: 10px; color: var(--muted); padding: 28px 0; font-size: 14px; }
.waiting { display: flex; align-items: center; gap: 10px; }
.err-text { color: var(--err); }
.note-status { font-size: 13px; color: var(--muted); align-self: center; }
.note-status.ok { color: var(--ok); } .note-status.err { color: var(--err); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.callback { text-align: center; padding-top: 14vh; }
@media (hover: none) { .chat-item .del, .actions { opacity: 1; } .chat-item a { padding-right: 34px; } }
.act svg { width: 15px; height: 15px; }
.memory-row { display: flex; justify-content: center; }
.memory-pill { display: inline-flex; align-items: center; gap: 8px; padding: 6px 12px; border-radius: 999px;
  background: var(--ok-soft); color: var(--ok); font-size: 13px; }
.memory-pill a { color: inherit; font-weight: 600; }
.memory-pill svg { width: 15px; height: 15px; }

.to-bottom { position: absolute; left: 50%; bottom: 128px; transform: translateX(-50%); width: 34px; height: 34px;
  border-radius: 50%; border: 1px solid var(--line); background: var(--surface); box-shadow: var(--shadow);
  display: grid; place-items: center; cursor: pointer; z-index: 2; }

.composer-wrap { padding: 0 20px 14px; }
.composer { max-width: 768px; margin: 0 auto; display: flex; align-items: flex-end; gap: 8px; padding: 10px 10px 10px 18px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 26px; box-shadow: var(--shadow); }
.composer:focus-within { border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); }
.composer textarea { flex: 1; resize: none; border: 0; outline: 0; background: transparent; color: var(--text);
  font: inherit; line-height: 1.5; max-height: 220px; padding: 6px 0; }
.send { width: 36px; height: 36px; border-radius: 50%; border: 0; display: grid; place-items: center; cursor: pointer;
  background: var(--text); color: var(--bg); flex: none; }
.send:disabled { opacity: .3; cursor: default; }
.send .i-stop { display: none; fill: currentColor; stroke: none; }
.composer.streaming .send .i-send { display: none; }
.composer.streaming .send .i-stop { display: block; }
.hint { max-width: 768px; margin: 8px auto 0; text-align: center; color: var(--muted); font-size: 12px; }

/* agent timeline */
.timeline { margin: 0 0 10px; padding-left: 12px; border-left: 2px solid var(--line); }
.tl-toggle { display: inline-flex; align-items: center; gap: 6px; border: 0; background: none; color: var(--muted);
  cursor: pointer; font-size: 13.5px; padding: 2px 0; }
.tl-toggle:hover { color: var(--text); }
.tl-body { display: grid; grid-template-rows: 1fr; transition: grid-template-rows .3s ease, opacity .25s ease, visibility 0s; }
.tl-inner { min-height: 0; overflow: hidden; }
.timeline.collapsed .tl-body { grid-template-rows: 0fr; opacity: 0; visibility: hidden;
  transition: grid-template-rows .3s ease, opacity .2s ease, visibility 0s linear .3s; }
.row.enter, .tl-step.enter { animation: rise .25s ease-out both; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }
.tl-toggle svg { width: 14px; height: 14px; }
.tl-steps { list-style: none; margin: 4px 0 0; padding: 0; display: flex; flex-direction: column; gap: 5px; }
.tl-step { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13.5px; min-width: 0; }
.tl-step svg { width: 14px; height: 14px; }
.tl-step .lbl { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.tl-step .sum { flex: none; opacity: .8; }
.tl-step.narration { font-style: italic; color: var(--text); opacity: .75; }
.tl-step.err { color: var(--err); }
.thinking { margin: 2px 0 6px; }
.thinking summary { cursor: pointer; color: var(--muted); font-size: 13.5px; }
.thinking-text { white-space: pre-wrap; color: var(--muted); font-size: 13px; max-height: 220px; overflow: auto;
  margin-top: 6px; padding: 8px 10px; border-radius: 8px; background: var(--bubble); }
.more-src { border: 1px dashed var(--line); background: none; color: var(--muted); border-radius: 999px;
  padding: 4px 10px; font-size: 12.5px; cursor: pointer; }
.more-src:hover { color: var(--text); }

/* ---- pages ---------------------------------------------------------------- */
.mem-h { font-size: 16px; margin: 22px 0 6px; }
.facts { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.fact { display: flex; align-items: center; gap: 12px; background: var(--surface); border: 1px solid var(--line);
  border-radius: 12px; padding: 10px 12px; }
.fact .fact-text { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.fact .muted { font-size: 12.5px; flex: none; }
.fact-input { flex: 1; min-width: 0; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--bg); color: var(--text); font: inherit; }
.page { overflow-y: auto; }
.page-inner { max-width: 768px; width: 100%; margin: 0 auto; padding: 8px 20px 40px; }
.page h1 { font-size: 24px; margin: 8px 0 4px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 16px 18px; margin: 16px 0; }
.card h2 { font-size: 16px; margin: 0 0 8px; }
.card ol { margin: 8px 0; padding-left: 22px; } .card li { margin: 4px 0; }
.card code { background: var(--bubble); padding: 1px 5px; border-radius: 5px; font-size: 13px; }
.note { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; margin: 12px 0; }
.note .note-head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.badge { font-size: 11.5px; font-weight: 650; padding: 2px 8px; border-radius: 999px; background: var(--accent-soft); color: var(--cite-text); }
.badge.fact { background: var(--ok-soft); color: var(--ok); }
.note label { display: block; font-size: 12px; color: var(--muted); margin-top: 8px; }
.note input, .note textarea { width: 100%; padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--bg); color: var(--text); font: inherit; font-size: 14px; }
.note textarea { resize: vertical; }
.row-btns { display: flex; gap: 8px; margin-top: 12px; }
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 7px 14px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface); cursor: pointer; font-size: 14px; font-weight: 550; }
.btn:hover { background: var(--hover); }
.btn.primary { background: var(--text); color: var(--bg); border-color: var(--text); }
.btn.danger { color: var(--err); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
dl { display: grid; grid-template-columns: max-content 1fr; gap: 8px 20px; margin: 0; font-size: 14px; }
dt { color: var(--muted); }
dd { margin: 0; }
.code-box { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 12px 14px; border-radius: 10px; background: var(--bubble); margin: 10px 0; }
.code-box .code { font: 600 22px/1 ui-monospace, Menlo, monospace; letter-spacing: .08em; }

/* ---- toasts --------------------------------------------------------------- */
.toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 30; max-width: calc(100vw - 32px); }
.toast { display: flex; align-items: center; gap: 10px; background: var(--surface); border: 1px solid var(--line);
  border-left: 3px solid var(--ok); border-radius: 12px; padding: 10px 12px; box-shadow: var(--shadow); font-size: 14px; }
.toast button { border: 0; background: none; color: var(--accent); cursor: pointer; font-weight: 600; padding: 0 2px; }
.toast .x { color: var(--muted); }
.toast.err { border-left-color: var(--err); }
.toast .t-text { flex: 1; }

/* ---- mobile --------------------------------------------------------------- */
@media (max-width: 860px) {
  .sidebar { position: fixed; inset: 0 auto 0 0; z-index: 20; margin-left: -280px; width: 280px; box-shadow: var(--shadow); }
  .app.sb-open .sidebar { margin-left: 0; }
  .app.sb-open .scrim { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 15; }
  .app #sb-open, .app:not(.sb-collapsed) #sb-open { display: inline-grid; }
  .suggestions { grid-template-columns: 1fr; }
  .empty { padding-top: 6vh; }
  .empty h1 { font-size: 23px; }
  .msgs { padding: 8px 16px 24px; }
  .composer-wrap { padding: 0 12px 10px; }
  .row.bot { grid-template-columns: minmax(0, 1fr); }
  .row.bot > .logo { display: none; }
  .hint { display: none; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; scroll-behavior: auto !important; } }
.choices { display: flex; flex-direction: column; gap: 14px; margin: 4px 0; padding: 14px 16px; border: 1px solid var(--line);
  border-radius: 14px; background: var(--surface); }
.choices fieldset { margin: 0; padding: 0; border: 0; min-width: 0; }
.choices legend { padding: 0; margin-bottom: 8px; font-weight: 600; }
.choices .opts { display: flex; flex-wrap: wrap; gap: 8px; }
.choice { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border: 1px solid var(--line);
  border-radius: 999px; cursor: pointer; font-size: 14px; }
.choice:has(input:checked) { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, transparent); }
.choice input { margin: 0; accent-color: var(--accent); }
.other-text { min-width: 180px; padding: 4px 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg);
  color: var(--text); font: inherit; }
.other-text:disabled { display: none; }
.choices > .btn { align-self: flex-start; }
.choices.locked { opacity: .7; }
.choices.locked .choice { cursor: default; }
.codeblock .code-actions { display: flex; gap: 10px; }
.codeblock.pending { border: 1px solid var(--line); background: var(--surface); }
.codeblock.pending > :not(.diagram-pending), .codeblock:not(.pending) .diagram-pending { display: none; }
.diagram-pending { padding: 28px; text-align: center; color: var(--muted); font-size: 13px; }
.diagram-bar { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 8px;
  border-bottom: 1px solid var(--line); }
.diagram-bar button { height: 28px; padding: 0 10px; border: 0; border-radius: 7px; background: none; color: var(--muted);
  cursor: pointer; font: inherit; font-size: 12.5px; }
.diagram-bar button:hover, .diagram-bar button[aria-pressed="true"] { background: var(--hover); color: var(--text); }
.diagram-bar .seg { display: flex; gap: 2px; }
.diagram[data-show="diagram"] > .codeblock, .diagram[data-show="code"] > .diagram-view { display: none; }
.diagram > .codeblock { margin: 0; border-radius: 0; }
body.viewer-open { overflow: hidden; }
.viewer { position: fixed; inset: 0; z-index: 100; display: flex; flex-direction: column; background: var(--bg); }
.viewer[hidden] { display: none; }
.viewer-bar { display: flex; align-items: center; gap: 12px; padding: 10px 16px; border-bottom: 1px solid var(--line); }
.viewer-title { flex: 1; color: var(--muted); font-size: 13px; font-weight: 600; }
.viewer-zoom { display: none; gap: 4px; }
.viewer.zoomable .viewer-zoom { display: flex; }
.viewer-bar button { min-width: 34px; height: 32px; padding: 0 10px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--surface); color: var(--text); cursor: pointer; font: inherit; }
.viewer-stage { flex: 1; min-height: 0; overflow: auto; padding: 24px; }
.viewer.zoomable .viewer-stage { overflow: hidden; cursor: grab; touch-action: none; }
.viewer.zoomable .viewer-stage:active { cursor: grabbing; }
.viewer.zoomable .viewer-content { width: 100%; height: 100%; transform-origin: center; }
.viewer-content > svg { display: block; width: 100%; height: 100%; fill: initial; stroke: initial; stroke-width: initial;
  stroke-linecap: initial; stroke-linejoin: initial; }
.viewer-content > pre { margin: 0; color: var(--text); font: 14px/1.6 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.viewer-content > pre code { padding: 0; background: none; font: inherit; }

/* ---- pages ---- */
#view-pages.active { flex-direction: row; }
.pages { display: flex; flex: 1; min-height: 0; width: 100%; }
.pages-list { width: 280px; flex: none; display: flex; flex-direction: column; gap: 8px; padding: 12px 10px;
  border-right: 1px solid var(--line); overflow-y: auto; }
.pages-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.pages-none { padding: 8px 10px; font-size: 13px; }
.page-row { display: block; width: 100%; text-align: left; border: 0; background: none; color: inherit; font: inherit;
  padding: 8px 10px; border-radius: 10px; cursor: pointer; }
.page-row:hover { background: var(--hover); }
.page-row.current { background: var(--accent-soft); }
.page-row b { display: block; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.page-row span { color: var(--muted); font-size: 12px; }
.pages-page { flex: 1; min-width: 0; overflow-y: auto; }
.pages-empty, .tidy, .page-doc { max-width: 820px; margin: 0 auto; padding: 16px 24px 40px; }
.tidy textarea { width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface);
  color: var(--text); font: 13.5px/1.55 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; resize: vertical; }
.page-head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; min-height: 36px; }
#page-back { display: none; }
.page-title { width: 100%; border: 0; outline: 0; background: none; color: var(--text); font: inherit; font-size: 24px; font-weight: 700; padding: 4px 0; }
.page-tags { width: 100%; border: 0; outline: 0; background: none; color: var(--muted); font: inherit; font-size: 13px; padding: 2px 0 12px; }
.pe-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding-bottom: 8px; margin-bottom: 12px; border-bottom: 1px solid var(--line); }
.pe-bar .seg { display: flex; gap: 2px; }
.pe-bar button { height: 28px; padding: 0 10px; border: 1px solid transparent; border-radius: 7px; background: none; color: var(--muted);
  cursor: pointer; font: inherit; font-size: 12.5px; }
.pe-bar button:hover, .pe-bar button[aria-pressed="true"] { background: var(--hover); color: var(--text); }
.pe-marks { display: flex; flex-wrap: wrap; gap: 4px; }
.pe-marks button { border-color: var(--line); }
.pe-text { width: 100%; min-height: 50vh; padding: 12px 14px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface);
  color: var(--text); font: 13.5px/1.6 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; resize: vertical; }
.pe-editor[data-mode="read"] .pe-text, .pe-editor[data-mode="read"] .pe-marks, .pe-editor[data-mode="write"] .pe-read { display: none; }
.pe-read input[type="checkbox"] { accent-color: var(--accent); cursor: pointer; }
.md p.warning { padding: 8px 12px; border-left: 3px solid #d97706; border-radius: 6px; background: #d977061a; }
@media (max-width: 760px) {
  .pages-list { width: 100%; border-right: 0; }
  .pages-page { display: none; }
  .pages.show-page .pages-list { display: none; }
  .pages.show-page .pages-page { display: block; }
  #page-back { display: inline-grid; }
  .pages-empty, .tidy, .page-doc { padding: 10px 14px 30px; }
}
.md li:has(> input[type="checkbox"]) { list-style: none; margin-left: -18px; }
.page-draft { margin: 4px 0 14px; padding: 12px 14px; border: 1px solid var(--accent); border-radius: 12px;
  background: var(--surface); box-shadow: 0 4px 14px color-mix(in srgb, var(--accent) 12%, transparent); }
.page-draft .draft-label { font-size: 11px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--accent); margin-bottom: 6px; }
.page-draft .draft-title { font-size: 16px; font-weight: 700; }
.page-draft .draft-tags { display: flex; gap: 6px; margin: 4px 0 8px; }
.page-draft .draft-tags span { padding: 1px 8px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-size: 12px; font-weight: 600; }
.page-draft .draft-body.md { max-height: 320px; overflow-y: auto; font-size: 14px; }
.page-draft .draft-from { font-size: 12px; margin: 8px 0 0; }
.page-draft .draft-state { margin: 10px 0 0; font-weight: 600; }
.page-draft .draft-state a { color: var(--accent); }
.diff { font: 12.5px/1.55 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; border-radius: 8px; overflow: hidden; }
.diff-line { padding: 1px 10px; white-space: pre-wrap; overflow-wrap: anywhere; border-left: 3px solid transparent; }
.diff-line.add { background: #05966918; border-left-color: #059669; }
.diff-line.del { background: #e11d4814; border-left-color: #e11d48; text-decoration: line-through; color: var(--muted); }
.diff-gap { padding: 2px 10px; color: var(--muted); font-style: italic; }
