/* ═══════════════════════════════════════════════════════ *
 * Universal wiki framework styles                          *
 * — Ported from NTU_FR_Wiki. All theme tokens overridable  *
 *   via CSS vars injected from meta.json (accent,          *
 *   accentSoft, accentDark, …)                             *
 * ═══════════════════════════════════════════════════════ */

:root {
  --bg:          #fafaf7;
  --text:        #1a1a1a;
  --muted:       #666;
  --accent:      #a63d00;
  --accent-soft: #f4e9df;
  --accent-dark: #7a2b00;
  --border:      #e0ddd5;
  --code-bg:     #f3efea;
  --sidebar-bg:  #f5f2ec;
  --green:       #2d6a4f;
  --red:         #9d2c2c;
  --blue:        #1e4a7a;
  --purple:      #6c5ce7;
  --electric:    #0984e3;
}

* { box-sizing: border-box; }
html, body { max-width: 100%; }
body { overflow-x: clip; }
@supports not (overflow-x: clip) { body { overflow-x: hidden; } }
body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  margin: 0;
  line-height: 1.75;
  font-size: 16px;
}

.wiki-loading, .wiki-error {
  padding: 80px 20px;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
}
.wiki-error { color: var(--red); }

/* ── Layout ─────────────────────────────────────────────── */
.container {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  min-height: 100vh;
  transition: grid-template-columns .22s ease;
}
aside {
  background: var(--sidebar-bg);
  padding: 16px 20px 32px;
  border-right: 1px solid var(--border);
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  overflow-x: hidden;
}
main {
  padding: 48px 64px;
  max-width: 960px;
  margin: 0 auto;
  width: 100%;
}

/* ── Collapsed sidebar (desktop horizontal hide) ────────── */
body.sb-collapsed .container { grid-template-columns: 48px minmax(0, 1fr); }
body.sb-collapsed aside { padding: 10px 6px; }
body.sb-collapsed .sb-header {
  position: static;
  margin: 0 0 10px;
  padding: 0;
  background: transparent;
  border: none;
  justify-content: center;
}
body.sb-collapsed .sb-logo,
body.sb-collapsed .sb-title,
body.sb-collapsed .sb-back,
body.sb-collapsed .sb-glossary,
body.sb-collapsed .nav-tree {
  display: none;
}
body.sb-collapsed .sb-tool {
  width: 36px; height: 36px;
  padding: 0;
  border-radius: 8px;
  font-size: 15px; font-weight: 700;
  color: var(--accent);
  border-color: var(--border);
}
body.sb-collapsed .sb-tool:hover { background: var(--accent-soft); }
body.sb-collapsed aside::after {
  content: "目  录";
  display: block;
  margin: 18px auto 0;
  font-size: 10.5px; color: var(--muted);
  letter-spacing: 4px; font-weight: 600;
  writing-mode: vertical-rl;
  text-align: center; opacity: .65;
  cursor: pointer;
}

/* ── Content typography ─────────────────────────────────── */
h1 {
  font-size: 36px;
  margin: 0 0 8px;
  color: var(--text);
  border-bottom: 3px solid var(--accent);
  padding-bottom: 16px;
}
.subtitle {
  color: var(--muted);
  font-size: 16px;
  margin-bottom: 32px;
}
h2 {
  font-size: 26px;
  margin-top: 48px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
  color: var(--accent);
}
h3 {
  font-size: 20px;
  margin-top: 32px;
  color: var(--text);
}
h4 {
  font-size: 16px;
  color: var(--blue);
  margin-top: 20px;
}
p { margin: 12px 0; }
main a { color: var(--accent); text-decoration: none; border-bottom: 1px dotted var(--accent); }
main a:hover { background: var(--accent-soft); }
code {
  background: var(--code-bg);
  padding: 2px 6px;
  border-radius: 3px;
  font-size: 14px;
  font-family: "SF Mono", Menlo, monospace;
}
pre {
  background: var(--code-bg);
  padding: 16px;
  border-radius: 6px;
  overflow-x: auto;
  font-size: 13px;
  line-height: 1.5;
  border-left: 3px solid var(--accent);
}
pre code { background: transparent; padding: 0; font-size: inherit; }
blockquote {
  border-left: 4px solid var(--accent);
  background: var(--accent-soft);
  padding: 12px 20px;
  margin: 20px 0;
  font-style: italic;
  color: #555;
}
table {
  width: 100%;
  border-collapse: collapse;
  margin: 20px 0;
  font-size: 14px;
}
th, td {
  border: 1px solid var(--border);
  padding: 10px 14px;
  text-align: left;
  vertical-align: top;
}
th {
  background: var(--sidebar-bg);
  font-weight: 600;
}
tr:nth-child(even) td { background: rgba(0,0,0,0.015); }

img {
  max-width: 100%;
  height: auto;
}

/* ── Reusable components (inline HTML in markdown) ──────── */
.tldr {
  background: linear-gradient(135deg, #fff7e6 0%, #fdf4dd 100%);
  border: 1px solid #e6c878;
  border-radius: 8px;
  padding: 20px 24px;
  margin: 24px 0;
}
.tldr h3, .tldr h4 { margin-top: 0; color: #8a6200; }
.card {
  background: white;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 20px 24px;
  margin: 16px 0;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}
.card h4 { margin-top: 0; }
.flag-red {
  background: #fdf0f0;
  border-left: 4px solid var(--red);
  padding: 12px 16px;
  margin: 12px 0;
  border-radius: 4px;
}
.flag-green {
  background: #eef7f0;
  border-left: 4px solid var(--green);
  padding: 12px 16px;
  margin: 12px 0;
  border-radius: 4px;
}
.flag-blue {
  background: #eaf1f9;
  border-left: 4px solid var(--blue);
  padding: 12px 16px;
  margin: 12px 0;
  border-radius: 4px;
}
.flag-yellow {
  background: #fff8e1;
  border-left: 4px solid #c99a00;
  padding: 12px 16px;
  margin: 12px 0;
  border-radius: 4px;
}
.img-wrap {
  margin: 24px 0;
  text-align: center;
}
.img-wrap img {
  max-width: 100%;
  border-radius: 6px;
  border: 1px solid var(--border);
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}
.img-caption {
  font-size: 13px;
  color: var(--muted);
  margin-top: 8px;
  font-style: italic;
}
.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin: 20px 0;
}
.tag {
  display: inline-block;
  background: var(--accent-soft);
  color: var(--accent);
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 12px;
  margin-right: 6px;
  font-weight: 500;
}
.tag-blue { background: #e3edf7; color: var(--blue); }
.tag-green { background: #e3f1e9; color: var(--green); }
.tag-purple { background: #eef0ff; color: var(--purple); }
.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin: 24px 0;
}
.stat {
  background: white;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  text-align: center;
}
.stat-value {
  font-size: 24px;
  font-weight: 700;
  color: var(--accent);
}
.stat-label {
  font-size: 12px;
  color: var(--muted);
  margin-top: 4px;
}
.diagram {
  background: white;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 24px;
  margin: 20px 0;
  font-family: "SF Mono", Menlo, monospace;
  font-size: 13px;
  line-height: 1.6;
  white-space: pre;
  overflow-x: auto;
}
.checklist {
  background: var(--code-bg);
  padding: 20px 24px;
  border-radius: 8px;
  margin: 20px 0;
  font-family: "SF Mono", Menlo, monospace;
  font-size: 13px;
  line-height: 1.8;
}
.project-banner {
  border-radius: 10px; padding: 28px 32px; margin: 48px 0 24px; color: #fff;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-dark) 100%);
}
.project-banner h2 { color: #fff !important; border-bottom: none !important; margin-top: 0 !important; padding-bottom: 0; font-size: 28px; }
.project-banner p { opacity: .9; margin: 4px 0 0; }
.process-flow {
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
  background: white; border: 1px solid var(--border); border-radius: 8px;
  padding: 20px; margin: 20px 0;
}
.process-step {
  background: linear-gradient(135deg, var(--electric), var(--purple));
  color: #fff; padding: 10px 16px; border-radius: 8px;
  font-size: 13px; font-weight: 600; text-align: center; min-width: 90px;
}
.process-arrow { font-size: 18px; color: var(--purple); }

footer.wiki-footer {
  margin-top: 80px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
  font-size: 13px;
  color: var(--muted);
}
footer.wiki-footer .disc {
  margin-top: 8px;
  font-size: 12.5px;
  color: var(--muted);
  line-height: 1.6;
}

/* ── Sticky sidebar header ──────────────────────────────── */
.sb-header {
  position: sticky; top: -16px;
  margin: -16px -20px 14px;
  padding: 14px 16px 12px;
  background: var(--sidebar-bg);
  border-bottom: 1px solid var(--border);
  z-index: 2;
  display: flex; align-items: center; gap: 10px;
}
.sb-back {
  display: flex; align-items: center; justify-content: center;
  width: 26px; height: 26px;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  text-decoration: none;
  font-size: 16px;
  border: 1px solid var(--border);
  flex-shrink: 0;
}
.sb-back:hover { background: #fff; color: var(--accent); border-color: var(--accent); }
.sb-logo {
  width: 34px; height: 34px; border-radius: 8px;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-dark) 100%);
  color: #fff; font-weight: 800; font-size: 13px; letter-spacing: .5px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 2px 6px rgba(0,0,0,.18);
}
.sb-title { flex: 1; min-width: 0; }
.sb-title .name {
  font-size: 13px; font-weight: 700; color: var(--text);
  line-height: 1.25; letter-spacing: .2px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.sb-title .sub { font-size: 10.5px; color: var(--muted); margin-top: 1px; letter-spacing: .2px; }
.sb-tool {
  background: transparent; border: 1px solid var(--border);
  color: var(--muted); font-size: 10.5px; font-weight: 600;
  padding: 4px 8px; border-radius: 5px;
  cursor: pointer; letter-spacing: .3px;
  transition: background .12s, color .12s, border-color .12s;
  flex-shrink: 0;
  white-space: nowrap;
}
.sb-tool:hover { background: #fff; color: var(--accent); border-color: var(--accent); }

.sb-glossary {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px; margin: 6px 4px 10px;
  border: 1px dashed var(--border); border-radius: 6px;
  font-size: 12.5px; color: var(--muted);
  text-decoration: none;
  background: rgba(255,255,255,0.4);
  cursor: pointer;
}
.sb-glossary:hover { border-color: var(--accent); color: var(--accent); background: #fff; }

/* ── Sidebar export widget ───────────────────────────────── */
.sb-export {
  position: relative;
  margin: 0 4px 10px;
}
.sb-export-btn {
  display: flex; align-items: center; gap: 8px; width: 100%;
  padding: 8px 10px;
  border: 1px dashed var(--border); border-radius: 6px;
  background: rgba(255,255,255,.4);
  color: var(--muted);
  font-size: 12.5px; font-family: inherit;
  cursor: pointer;
  transition: border-color .12s, color .12s, background .12s;
}
.sb-export-btn:hover,
.sb-export-btn[aria-expanded="true"] {
  border-color: var(--accent); color: var(--accent); background: #fff;
}
.sb-export-btn svg {
  width: 14px; height: 14px; flex-shrink: 0;
  stroke: currentColor; fill: none;
  stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round;
}
.sb-export-btn .label   { flex: 1; text-align: left; }
.sb-export-btn .chev    { font-size: 10px; opacity: .6; transition: transform .2s; }
.sb-export-btn[aria-expanded="true"] .chev { transform: rotate(180deg); }
.sb-export-menu {
  display: none;
  margin-top: 6px;
  border: 1px solid var(--border); border-radius: 6px;
  background: #fff;
  overflow: hidden;
  box-shadow: 0 4px 14px rgba(0,0,0,.06);
}
.sb-export.open .sb-export-menu { display: block; }
.sb-export-menu button {
  display: block; width: 100%;
  padding: 9px 12px;
  border: 0; background: transparent;
  text-align: left; cursor: pointer;
  font: inherit; color: var(--text);
  font-size: 12.5px;
  border-bottom: 1px solid var(--border);
}
.sb-export-menu button:last-child { border-bottom: 0; }
.sb-export-menu button:hover {
  background: color-mix(in srgb, var(--accent) 6%, transparent);
  color: var(--accent);
}
.sb-export-menu .ex-hint {
  display: block;
  font-size: 10.5px; color: var(--muted);
  margin-top: 2px; font-weight: 400;
  letter-spacing: .2px;
}
.sb-export-toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: #1b1b1b; color: #fff;
  padding: 10px 16px; border-radius: 8px;
  font-size: 13px; z-index: 300;
  opacity: 0; pointer-events: none;
  transition: opacity .2s;
}
.sb-export-toast.show { opacity: .92; }
body.sb-collapsed .sb-export { display: none; }

/* ── Print: clean page for "Save as PDF" ─────────────────── */
@media print {
  body { background: #fff !important; }
  aside, .mobile-topbar, .drawer-backdrop,
  .search-wrap, .sb-export-toast, .gloss-overlay, .ai-assistant { display: none !important; }
  .container { display: block !important; }
  main { padding: 0 !important; max-width: none !important; }
  a { color: inherit; text-decoration: none; }
  .nav-tree, .sb-header, .sb-glossary, .sb-export { display: none !important; }
}

/* ── Nav tree ───────────────────────────────────────────── */
.nav-tree { margin: 0; padding: 0 4px 8px; }
.nav-tree details { margin: 0; }
.nav-tree summary::-webkit-details-marker,
.nav-tree summary::marker { display: none; content: ''; }

.nav-part {
  margin: 0 -4px 4px;
  border-radius: 8px;
  transition: background .15s;
}
.nav-part[open] { background: rgba(255,255,255,.55); }
.nav-part > summary {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px;
  font-size: 13px; font-weight: 700;
  color: var(--text); letter-spacing: .2px;
  cursor: pointer; list-style: none;
  border-radius: 8px;
  user-select: none; -webkit-user-select: none;
}
.nav-part > summary:hover { background: color-mix(in srgb, var(--accent) 6%, transparent); }
.nav-part .chip {
  flex-shrink: 0;
  width: 22px; height: 22px; border-radius: 5px;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 800;
  background: var(--accent-soft); color: var(--accent);
  font-variant-numeric: tabular-nums;
}
.nav-part.part-green  .chip { background: #e4f1ec; color: var(--green); }
.nav-part.part-blue   .chip { background: #e3ecf5; color: var(--blue); }
.nav-part.part-gray   .chip { background: #e6e4df; color: var(--muted); }
.nav-part.part-purple .chip { background: #eef0ff; color: var(--purple); }
.nav-part > summary .chev {
  margin-left: auto; flex-shrink: 0;
  width: 18px; height: 18px;
  display: flex; align-items: center; justify-content: center;
  color: var(--muted);
  transition: transform .2s ease;
}
.nav-part > summary .chev svg { width: 10px; height: 10px; }
.nav-part[open] > summary .chev { transform: rotate(90deg); }
.nav-part > .nav-children {
  padding: 4px 6px 8px 10px;
  display: flex; flex-direction: column; gap: 1px;
}

.nav-sub { margin: 2px 0; border-radius: 6px; }
.nav-sub > summary {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 10px;
  font-size: 12.5px; font-weight: 600;
  color: var(--text);
  cursor: pointer; list-style: none;
  border-radius: 6px;
  user-select: none; -webkit-user-select: none;
}
.nav-sub > summary:hover { background: color-mix(in srgb, var(--accent) 5%, transparent); }
.nav-sub > summary::before {
  content: '';
  width: 0; height: 0;
  border-left: 5px solid currentColor;
  border-top: 3.5px solid transparent;
  border-bottom: 3.5px solid transparent;
  opacity: .55;
  transition: transform .2s ease;
  flex-shrink: 0;
}
.nav-sub[open] > summary::before { transform: rotate(90deg); }
.nav-sub > summary .nav-badge {
  font-size: 9.5px; font-weight: 800; padding: 2px 6px;
  border-radius: 4px; margin-left: auto; flex-shrink: 0;
  letter-spacing: .5px;
}
.nav-badge.p1 { background: #fde6d6; color: var(--accent); }
.nav-badge.p2 { background: #e5e8ff; color: var(--purple); }
.nav-badge.p3 { background: #d9f0e6; color: #0b6e4f; }
.nav-badge.p4 { background: #f0e4d0; color: #6b4a25; }
.nav-badge.p5 { background: #cfeeea; color: #0f766e; }
.nav-badge.p6 { background: #e0e7ff; color: #4338ca; }
.nav-sub > .nav-children {
  padding: 2px 0 4px 10px;
  margin-left: 8px;
  border-left: 1.5px solid rgba(0,0,0,.06);
}

.nav-tree .nav-children a {
  display: flex; align-items: center; gap: 6px;
  padding: 5px 10px;
  font-size: 12.5px; color: var(--text);
  text-decoration: none; border-bottom: none;
  border-radius: 5px;
  border-left: 2px solid transparent;
  transition: background .12s, color .12s, border-color .12s;
  line-height: 1.4;
}
.nav-tree .nav-children a:hover { background: color-mix(in srgb, var(--accent) 5%, transparent); color: var(--accent); }
.nav-tree .nav-children a .meta {
  margin-left: auto; flex-shrink: 0;
  font-size: 10.5px; color: var(--muted); font-weight: 400;
}
.nav-tree .nav-children a.active {
  background: var(--accent-soft); color: var(--accent);
  font-weight: 600; border-left-color: var(--accent);
}

.nav-person {
  display: flex !important;
  flex-direction: column !important;
  align-items: flex-start !important;
  gap: 1px !important;
  padding: 6px 10px !important;
}
.nav-person .name { font-size: 12.5px; font-weight: 600; color: var(--text); line-height: 1.3; }
.nav-person .role { font-size: 10.5px; color: var(--muted); line-height: 1.3; }
.nav-person.active { background: var(--accent-soft); border-left-color: var(--accent); }
.nav-person.active .name { color: var(--accent); }

/* Solo part (h2 without h3 children) — looks like nav-part summary but is a leaf link */
.nav-part-solo {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px; margin: 0 -4px 4px;
  font-size: 13px; font-weight: 700;
  color: var(--text); letter-spacing: .2px;
  text-decoration: none;
  border-radius: 8px;
  border-left: 2px solid transparent;
  transition: background .12s, color .12s, border-color .12s;
}
.nav-part-solo:hover {
  background: color-mix(in srgb, var(--accent) 6%, transparent);
  color: var(--accent);
}
.nav-part-solo.active {
  background: var(--accent-soft); color: var(--accent);
  border-left-color: var(--accent);
}
.nav-part-solo.active .chip { background: var(--accent); color: #fff; }

/* Active nav-part (whole chapter is currently in view) */
.nav-part.active > summary {
  background: color-mix(in srgb, var(--accent) 8%, transparent);
  color: var(--accent);
}
.nav-part.active > summary .chip { background: var(--accent); color: #fff; }

/* ── Mobile drawer ──────────────────────────────────────── */
.mobile-topbar {
  display: none;
  position: sticky; top: 0; z-index: 40;
  background: var(--sidebar-bg);
  border-bottom: 1px solid var(--border);
  padding: 10px 14px;
  align-items: center; gap: 10px;
  box-shadow: 0 2px 8px rgba(0,0,0,.04);
}
.mobile-topbar .title {
  font-size: 14px; font-weight: 700; color: var(--accent);
  flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.hamburger {
  width: 38px; height: 38px;
  border: 1px solid var(--border); border-radius: 6px;
  background: #fff; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}
.hamburger span {
  display: block; width: 18px; height: 2px; background: var(--text);
  border-radius: 1px;
}
.drawer-backdrop {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 45;
  opacity: 0; transition: opacity .25s;
  -webkit-tap-highlight-color: transparent;
}
body.drawer-open .drawer-backdrop { display: block; opacity: 1; }
body.drawer-open { overflow: hidden; }
.drawer-close { display: none; }

@media (max-width: 900px) {
  .container { grid-template-columns: minmax(0, 1fr); }
  main { padding: 20px 18px 40px; max-width: 100%; min-width: 0; overflow-x: visible; }
  table { display: block; overflow-x: auto; max-width: 100%; -webkit-overflow-scrolling: touch; }
  pre { max-width: 100%; overflow-x: auto; }
  h1 { font-size: 26px; padding-bottom: 12px; }
  h2 { font-size: 21px; margin-top: 32px; }
  h3 { font-size: 17px; margin-top: 22px; }
  body { font-size: 15px; line-height: 1.7; }
  .subtitle { font-size: 14px; margin-bottom: 20px; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .two-col { grid-template-columns: 1fr; }
  .process-flow { justify-content: center; padding: 14px; }
  .process-step { font-size: 12px; padding: 8px 12px; min-width: 72px; }
  .project-banner { padding: 20px 20px; margin: 32px 0 20px; border-radius: 8px; }
  .project-banner h2 { font-size: 22px; }
  .card { padding: 16px 18px; }
  .tldr { padding: 16px 18px; }
  .img-wrap { margin: 18px 0; }
  blockquote { padding: 10px 16px; margin: 16px 0; }
  table { font-size: 13px; }
  th, td { padding: 7px 9px; }
  pre { padding: 12px; font-size: 12px; }

  .mobile-topbar { display: flex; }

  aside {
    position: fixed;
    top: 0; left: 0;
    width: 300px; max-width: 85vw;
    height: 100vh;
    transform: translateX(-100%);
    transition: transform .28s ease;
    z-index: 50;
    padding: 16px 20px 40px;
    box-shadow: 4px 0 24px rgba(0,0,0,.18);
    border-right: 1px solid var(--border);
  }
  .sb-tool { display: none; }
  body.drawer-open aside { transform: translateX(0); }
  aside .drawer-close {
    display: block;
    position: absolute; top: 10px; right: 12px;
    width: 34px; height: 34px; border-radius: 6px;
    border: 1px solid var(--border); background: #fff;
    font-size: 18px; line-height: 1; cursor: pointer;
    color: var(--muted);
  }
}
@media (max-width: 480px) {
  main { padding: 16px 14px 32px; }
  h1 { font-size: 22px; }
  h2 { font-size: 19px; }
  .project-banner { padding: 18px 16px; }
  .project-banner h2 { font-size: 19px; }
  table { font-size: 12px; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .process-flow { flex-direction: column; align-items: stretch; }
  .process-arrow { transform: rotate(90deg); align-self: center; }
}

/* ── Glossary auto-link ─────────────────────────────────── */
a.kw-link {
  color: inherit;
  text-decoration: none;
  border-bottom: 1px dashed var(--accent);
  cursor: help;
}
a.kw-link:hover { color: var(--accent); border-bottom-style: solid; }

/* ── Search widget ──────────────────────────────────────── */
.search-wrap {
  position: fixed;
  top: 14px;
  right: 20px;
  z-index: 200;
  width: 300px;
  font-family: inherit;
}
.search-input {
  width: 100%;
  box-sizing: border-box;
  padding: 8px 38px 8px 34px;
  border: 1px solid #e3dfd6;
  border-radius: 8px;
  background: #fff url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="%23666" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><circle cx="11" cy="11" r="7"/><line x1="21" y1="21" x2="16.65" y2="16.65"/></svg>') no-repeat 10px center;
  font-size: 13px;
  color: #3a3a3a;
  box-shadow: 0 1px 3px rgba(0,0,0,.04);
  transition: box-shadow .15s, border-color .15s;
  font-family: inherit;
}
.search-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 2px 10px rgba(0,0,0,.1);
}
.search-kbd {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 11px;
  color: #888;
  background: #f1ede4;
  border: 1px solid #e3dfd6;
  border-radius: 4px;
  padding: 1px 6px;
  pointer-events: none;
  letter-spacing: .5px;
}
.search-wrap.focused .search-kbd { display: none; }
.search-results {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  background: #fff;
  border: 1px solid #e3dfd6;
  border-radius: 8px;
  box-shadow: 0 8px 28px rgba(0,0,0,.14);
  max-height: 70vh;
  overflow-y: auto;
  display: none;
}
.search-results.open { display: block; }
.search-result {
  display: block;
  padding: 10px 14px;
  border-bottom: 1px solid #f4f0e7;
  text-decoration: none;
  color: inherit;
  cursor: pointer;
}
.search-result:last-child { border-bottom: none; }
.search-result:hover,
.search-result.active { background: #faf6ef; }
.search-result .sr-title {
  font-weight: 600;
  color: var(--accent);
  font-size: 13.5px;
  line-height: 1.3;
}
.search-result .sr-part {
  font-size: 11px;
  color: #999;
  font-weight: 500;
  margin-right: 6px;
}
.search-result .sr-snippet {
  font-size: 12px;
  color: #666;
  margin-top: 3px;
  line-height: 1.45;
}
.search-result mark {
  background: #fff4d6;
  color: inherit;
  padding: 0 1px;
  border-radius: 2px;
}
.search-hint, .search-empty {
  padding: 12px 14px;
  color: #888;
  font-size: 12.5px;
}
.search-empty { text-align: center; }
@keyframes sr-flash {
  0%   { background: #fff4d6; }
  100% { background: transparent; }
}
.search-flash { animation: sr-flash 1.8s ease-out; }
@media (max-width: 900px) {
  .search-wrap { top: 9px; right: 10px; width: 170px; }
  .search-input { font-size: 12.5px; padding: 6px 10px 6px 30px; }
  .search-kbd { display: none; }
  .search-results { max-height: 60vh; }
  .mobile-topbar { padding-right: 190px; }
}

/* ── Glossary overlay ───────────────────────────────────── */
.gloss-overlay {
  position: fixed; inset: 0;
  background: rgba(20,17,14,.55);
  z-index: 300;
  display: none;
  padding: 4vh 20px;
  overflow-y: auto;
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
}
.gloss-overlay.open { display: block; }
.gloss-panel {
  max-width: 860px;
  margin: 0 auto;
  background: #fff;
  border-radius: 12px;
  padding: 28px 32px 40px;
  box-shadow: 0 20px 60px rgba(0,0,0,.35);
}
.gloss-panel h1 {
  border-bottom: 3px solid var(--accent);
  padding-bottom: 12px;
  margin: 0 0 8px;
  font-size: 28px;
}
.gloss-panel .lead {
  color: var(--muted); font-size: 13.5px; margin-bottom: 18px;
}
.gloss-close {
  float: right;
  background: transparent; border: 1px solid var(--border);
  width: 30px; height: 30px; border-radius: 6px;
  cursor: pointer; font-size: 16px; color: var(--muted);
}
.gloss-close:hover { color: var(--accent); border-color: var(--accent); }
.gloss-cat-nav { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0 20px; }
.gloss-cat-btn {
  border: 1px solid var(--border); background: #fff;
  padding: 4px 12px; border-radius: 16px;
  font-size: 12.5px; color: var(--muted); cursor: pointer;
  text-decoration: none;
}
.gloss-cat-btn:hover, .gloss-cat-btn.active {
  background: var(--accent-soft); color: var(--accent); border-color: var(--accent);
}
.gloss-entry {
  border: 1px solid var(--border); background: #fff;
  border-radius: 8px; padding: 14px 18px; margin: 10px 0;
}
.gloss-entry h3 { margin: 0 0 4px; color: var(--accent); font-size: 17px; }
.gloss-entry .aliases { color: var(--muted); font-size: 12.5px; margin-bottom: 6px; }
.gloss-entry .short { font-weight: 500; margin: 4px 0 6px; font-size: 14px; }
.gloss-entry .definition { color: #333; font-size: 13.5px; line-height: 1.65; }
.gloss-entry .ext { margin-top: 6px; font-size: 12.5px; }
.gloss-entry .ext a { color: var(--accent); }
@media (max-width: 600px) {
  .gloss-overlay { padding: 0; }
  .gloss-panel { border-radius: 0; padding: 20px 16px 40px; min-height: 100vh; }
}


/* ═══════════════════════════════════════════════════════ *
 * SiliWiki shelf + V1 additions over NTU wiki framework   *
 * ═══════════════════════════════════════════════════════ */
body.shelf-view {
  background: #f6f2ec;
  color: #1f1d1a;
}
body.shelf-view main.shelf-page {
  max-width: 1080px;
  padding: 56px 24px 72px;
}
.shelf-hero {
  padding: 34px 0 28px;
  border-bottom: 1px solid #e4ddd2;
}
.shelf-hero .eyebrow {
  font-size: .76rem;
  letter-spacing: 3px;
  text-transform: uppercase;
  color: #7a726a;
  font-weight: 700;
  margin: 0 0 .75rem;
}
.shelf-hero h1 {
  border: 0;
  padding: 0;
  margin: 0 0 .8rem;
  font-size: clamp(2.4rem, 6vw, 4.8rem);
  line-height: .98;
  letter-spacing: -2.5px;
}
.shelf-hero h1 em {
  color: var(--accent);
  font-style: normal;
}
.shelf-hero .lede {
  color: #7a726a;
  max-width: 680px;
  font-size: 1.05rem;
}
.shelf-actions { display: flex; gap: .75rem; flex-wrap: wrap; margin-top: 1.2rem; }
.shelf-btn {
  display: inline-flex; align-items: center; gap: .4rem;
  border: 1px solid #e4ddd2;
  border-radius: 999px;
  padding: .72rem 1rem;
  background: #fff;
  font-weight: 700;
  color: #1f1d1a;
}
.shelf-btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.quick-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1rem; margin: 28px 0; }
.quick-card {
  background: #fff;
  border: 1px solid #e4ddd2;
  border-radius: 14px;
  padding: 1rem;
  display: grid;
  gap: .45rem;
  box-shadow: 0 10px 24px rgba(31,29,26,.06);
}
.quick-card strong { color: var(--accent); }
.quick-card code { display: block; overflow-x: auto; white-space: nowrap; }
.library-head { display: flex; justify-content: space-between; align-items: baseline; border-top: 1px solid #e4ddd2; padding-top: 22px; margin-top: 18px; color: #7a726a; }
.library-head h2 { margin: 0; border: 0; padding: 0; color: #1f1d1a; font-size: 1rem; letter-spacing: 1px; text-transform: uppercase; }
.library { display: grid; grid-template-columns: repeat(auto-fill, minmax(285px, 1fr)); gap: 1.1rem; margin-top: 1rem; }
.wiki-card {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: #fff;
  border: 1px solid #e4ddd2;
  border-radius: 14px;
  color: inherit;
  text-decoration: none;
  box-shadow: 0 10px 24px rgba(31,29,26,.05);
  transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease;
}
.wiki-card:hover { transform: translateY(-3px); box-shadow: 0 16px 34px rgba(31,29,26,.1); border-color: #d4c9b8; }
.wiki-card .cover {
  height: 150px;
  background: radial-gradient(circle at 20% 20%, rgba(255,255,255,.22), transparent 46%), linear-gradient(135deg, var(--card-accent, var(--accent)), #2b1dc9 70%, #c85a2a 140%);
  display: flex; align-items: end; justify-content: end;
  padding: 1rem;
}
.wiki-card .cover span { color: rgba(255,255,255,.42); font: 800 2.3rem "SF Mono", Menlo, monospace; letter-spacing: -1px; }
.wiki-card .meta { padding: 1rem 1.1rem 1.1rem; }
.wiki-card .meta .tag { margin-bottom: .55rem; }
.wiki-card .meta h3 { margin: 0 0 .35rem; font-size: 1.12rem; line-height: 1.3; color: #1f1d1a; }
.wiki-card .meta p { margin: 0 0 .8rem; min-height: 3em; color: #7a726a; font-size: .9rem; }
.wiki-card .kv { border-top: 1px dashed #e4ddd2; padding-top: .65rem; display: flex; flex-wrap: wrap; gap: .45rem .85rem; color: #7a726a; font-size: .78rem; }
.empty, .error { padding: 1.2rem; border-radius: 12px; background: #fff; border: 1px solid #e4ddd2; color: #7a726a; }
.error { color: var(--red); }
.local-notice {
  background: var(--accent-soft);
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  margin: 0 0 22px;
  font-size: 13px;
}

/* SiliWiki V1 guide diagrams */
.diagram {
  border: 1px solid var(--border);
  background: linear-gradient(135deg, #fffaf2 0%, #f7efe4 100%);
  border-radius: 12px;
  padding: 1rem;
  margin: 1.2rem 0;
  overflow-x: auto;
}
.flow-diagram { display: grid; gap: .9rem; }
.flow-row { display: grid; grid-template-columns: 1fr auto 1fr auto 1fr; gap: .65rem; align-items: center; min-width: 720px; }
.flow-node, .arch-box, .sequence-diagram > div {
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 10px;
  padding: .85rem;
  box-shadow: 0 2px 8px rgba(0,0,0,.04);
}
.flow-node strong, .arch-box strong, .sequence-diagram strong { display: block; color: var(--accent-dark); margin-bottom: .25rem; }
.flow-node span, .arch-box span, .sequence-diagram span { display: block; color: var(--muted); font-size: .86rem; line-height: 1.45; }
.flow-arrow, .arch-arrow { color: var(--accent); font-weight: 900; text-align: center; }
.diagram-title {
  font-family: inherit;
  white-space: normal;
  color: var(--accent-dark);
  font-weight: 800;
  letter-spacing: .2px;
  margin: 0 0 .9rem;
  font-size: 1rem;
}
.architecture-diagram {
  display: grid;
  gap: .9rem;
  min-width: 680px;
  white-space: normal;
  font-family: inherit;
}
.v1-architecture {
  border: 1px solid color-mix(in srgb, var(--accent) 24%, var(--border));
  background:
    radial-gradient(circle at 8% 6%, rgba(166,61,0,.12), transparent 30%),
    radial-gradient(circle at 92% 12%, rgba(30,74,122,.10), transparent 26%),
    linear-gradient(135deg, #fffaf2 0%, #f6ecdf 100%);
  box-shadow: 0 18px 48px rgba(31,29,26,.10);
}
.hero-architecture {
  padding: 1.35rem;
  margin: 1.4rem 0 1.6rem;
  border-radius: 18px;
}
.hero-architecture .diagram-title,
.system-map .diagram-title {
  display: flex;
  align-items: center;
  gap: .55rem;
  font-size: clamp(1.05rem, 2.2vw, 1.35rem);
}
.hero-architecture .diagram-title::before,
.system-map .diagram-title::before {
  content: '◎';
  display: inline-grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 16px;
  box-shadow: 0 8px 18px rgba(166,61,0,.22);
}
.arch-layer {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: .85rem;
}
.arch-layer:first-child,
.arch-layer.single { grid-template-columns: 1fr; }
.arch-box {
  position: relative;
  overflow: hidden;
  min-height: 104px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  font-family: inherit;
  white-space: normal;
}
.arch-box::after {
  content: '';
  position: absolute;
  inset: auto -18px -24px auto;
  width: 74px;
  height: 74px;
  border-radius: 50%;
  background: color-mix(in srgb, var(--box-color, var(--accent)) 13%, transparent);
}
.arch-box strong { font-size: 1.02rem; }
.arch-box span { max-width: 92%; }
.arch-box.user { --box-color: #a63d00; border-left: 6px solid #a63d00; background: linear-gradient(135deg, #fff, #fff7ed); }
.arch-box.ai { --box-color: #2563eb; border-left: 6px solid #2563eb; background: linear-gradient(135deg, #fff, #eff6ff); }
.arch-box.frontend { --box-color: #0891b2; border-left: 6px solid #0891b2; background: linear-gradient(135deg, #fff, #ecfeff); }
.arch-box.backend { --box-color: #059669; border-left: 6px solid #059669; background: linear-gradient(135deg, #fff, #ecfdf5); }
.arch-box.cli { --box-color: #f59e0b; border-left: 6px solid #f59e0b; background: linear-gradient(135deg, #fff, #fffbeb); }
.arch-box.data { --box-color: #7c3aed; border-left: 6px solid #7c3aed; background: linear-gradient(135deg, #fff, #f5f3ff); }
.arch-box.harness { --box-color: #e11d48; border-left: 6px solid #e11d48; background: linear-gradient(135deg, #fff, #fff1f2); }
.arch-arrow {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  border-radius: 999px;
  color: var(--accent-dark);
  background: linear-gradient(90deg, rgba(166,61,0,.10), rgba(255,255,255,.86), rgba(166,61,0,.10));
  border: 2px dashed color-mix(in srgb, var(--accent) 52%, var(--border));
  font-family: inherit;
  white-space: normal;
  font-size: .96rem;
  font-weight: 900;
  letter-spacing: .1px;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.75), 0 8px 18px rgba(166,61,0,.08);
}
.role-diagram {
  white-space: normal;
  font-family: inherit;
  background: linear-gradient(135deg, #fffaf2 0%, #f7efe4 100%);
}
.role-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: .85rem;
  min-width: 760px;
}
.role-card {
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1rem;
  background: #fff;
  box-shadow: 0 10px 26px rgba(31,29,26,.07);
  min-height: 132px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  border-top: 6px solid var(--box-color, var(--accent));
}
.role-card.owner { --box-color: #a63d00; }
.role-card.ai { --box-color: #2563eb; }
.role-card.system { --box-color: #0891b2; }
.role-card strong { color: var(--accent-dark); font-size: 1.05rem; margin-bottom: .35rem; }
.role-card span { color: var(--muted); font-size: .88rem; line-height: 1.5; }
.sequence-diagram { display: grid; grid-template-columns: repeat(6, minmax(145px, 1fr)); gap: .7rem; min-width: 900px; }
.sequence-diagram > div { position: relative; }
.sequence-diagram > div:not(:last-child)::after {
  content: '→'; position: absolute; right: -.55rem; top: 50%; transform: translate(50%, -50%); color: var(--accent); font-weight: 900;
}
.file-tree pre { background: #1f1d1a; color: #fff8ed; border-left: 4px solid var(--accent); }
pre.mermaid-lite {
  background: #f6f0e9;
  color: var(--text);
  border: 0;
  border-left: 5px solid #9b3f13;
  border-radius: 12px;
  padding: 18px 14px 16px;
  white-space: normal;
  overflow-x: hidden;
  max-width: 100%;
  box-shadow: inset 0 0 0 1px rgba(122, 68, 35, .06);
}
pre.mermaid-lite .m-figure {
  display: block;
  margin: 0;
  width: 100%;
  max-width: 100%;
  min-width: 0;
}
.m-graph {
  display: block;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  height: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Noto Sans Mono CJK SC", monospace;
}
.m-link {
  fill: none;
  stroke: #95532f;
  stroke-width: 1.15;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.m-arrow-head { fill: #95532f; }
.m-edge-label {
  fill: #7a4a31;
  font-size: 11px;
  paint-order: stroke;
  stroke: #f6f0e9;
  stroke-width: 5px;
  stroke-linejoin: round;
}
.m-node rect,
.m-node polygon {
  fill: #fffaf4;
  stroke: #9b5b36;
  stroke-width: 1.15;
  vector-effect: non-scaling-stroke;
}
.m-node.app rect,
.m-node.app polygon {
  fill: #e6eef3;
  stroke: #607f90;
}
.m-node.decision polygon {
  fill: #fbf4ec;
  stroke: #9b5b36;
}
.m-label {
  fill: #26211d;
  font-size: 12px;
  line-height: 1.25;
  dominant-baseline: middle;
}
.m-caption {
  margin: 10px 4px 0;
  color: #6f6860;
  font-style: italic;
  font-size: .86rem;
  line-height: 1.45;
  white-space: normal;
}
.m-lite.m-sequence {
  display: grid;
  gap: 10px;
  min-width: 0;
  width: 100%;
  max-width: 100%;
}
.m-sequence .m-step {
  display: grid;
  grid-template-columns: minmax(80px, 1fr) auto minmax(80px, 1fr);
  gap: 8px 12px;
  align-items: center;
  background: rgba(255, 250, 244, .78);
  border: 1px solid rgba(155, 91, 54, .28);
  border-radius: 8px;
  padding: 11px 13px;
  color: var(--text);
}
.m-sequence .m-step b {
  color: #95532f;
  font-size: 18px;
  text-align: center;
}
.m-sequence .m-step span {
  min-width: 0;
  overflow-wrap: anywhere;
}
.m-sequence .m-step em {
  grid-column: 1 / -1;
  color: var(--muted);
  font-style: normal;
  font-size: 13px;
}
/* ── AI Q&A assistant ────────────────────────────────────── */
.ai-assistant {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 380;
  font-family: inherit;
}
.ai-fab {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  padding: 9px 16px 9px 10px;
  border: 1px solid color-mix(in srgb, var(--accent) 48%, #fff);
  border-radius: 999px;
  background: linear-gradient(135deg, var(--accent), var(--accent-dark));
  color: #fff;
  box-shadow: 0 18px 38px rgba(31,29,26,.22), 0 2px 8px rgba(31,29,26,.18);
  cursor: pointer;
  font: inherit;
  font-weight: 800;
  letter-spacing: .2px;
  transition: transform .16s ease, box-shadow .16s ease, opacity .16s ease;
}
.ai-fab:hover { transform: translateY(-2px); box-shadow: 0 22px 46px rgba(31,29,26,.28), 0 2px 8px rgba(31,29,26,.18); }
.ai-fab-mark {
  display: inline-grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: rgba(255,255,255,.18);
  border: 1px solid rgba(255,255,255,.34);
  font: 900 12px/1 "SF Mono", Menlo, monospace;
}
.ai-fab-label { font-size: 13px; white-space: nowrap; }
.ai-panel {
  position: absolute;
  right: 0;
  bottom: 62px;
  width: min(348px, calc(100vw - 28px));
  height: min(440px, calc(100vh - 160px));
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  overflow: hidden;
  border: 1px solid color-mix(in srgb, var(--accent) 22%, var(--border));
  border-radius: 18px;
  background: rgba(255, 252, 247, .97);
  box-shadow: 0 26px 72px rgba(31,29,26,.24), 0 0 0 1px rgba(255,255,255,.72) inset;
  opacity: 0;
  pointer-events: none;
  transform: translateY(12px) scale(.98);
  transform-origin: bottom right;
  transition: opacity .18s ease, transform .18s ease;
  backdrop-filter: blur(14px);
}
.ai-assistant.open .ai-panel {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0) scale(1);
}
.ai-assistant.open .ai-fab { opacity: .92; }
.ai-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 14px 12px 16px;
  background: linear-gradient(135deg, var(--accent-soft), #fffaf2);
  border-bottom: 1px solid var(--border);
}
.ai-head strong {
  display: block;
  color: var(--accent-dark);
  font-size: 14px;
  line-height: 1.25;
}
.ai-head span {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 11.5px;
  line-height: 1.35;
}
.ai-close {
  width: 30px;
  height: 30px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: #fff;
  color: var(--muted);
  cursor: pointer;
  font: inherit;
  line-height: 1;
}
.ai-close:hover { color: var(--accent); border-color: var(--accent); }
.ai-messages {
  min-height: 0;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
}
.ai-msg {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  gap: 9px;
  align-items: start;
}
.ai-msg-role {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent-dark);
  font-size: 11px;
  font-weight: 900;
}
.ai-msg.user .ai-msg-role { background: #eaf1f9; color: var(--blue); }
.ai-msg-body {
  min-width: 0;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: #fff;
  color: var(--text);
  font-size: 13.5px;
  line-height: 1.65;
  overflow-wrap: anywhere;
  box-shadow: 0 4px 16px rgba(31,29,26,.05);
}
.ai-msg.user .ai-msg-body {
  background: #f6fbff;
  border-color: #d6e7f5;
}
.ai-msg.error .ai-msg-body {
  background: #fff6f6;
  border-color: #f0c5c5;
  color: var(--red);
}
.ai-msg.pending .ai-msg-body { color: var(--muted); }
.ai-msg.pending .ai-msg-body::after {
  content: '•••';
  display: inline-block;
  margin-left: 4px;
  letter-spacing: 2px;
  color: var(--accent);
  animation: ai-pulse 1.1s infinite ease-in-out;
}
.ai-msg-body p,
.ai-msg-body ul,
.ai-msg-body ol,
.ai-msg-body pre,
.ai-msg-body blockquote { margin: 0 0 9px; }
.ai-msg-body p:last-child,
.ai-msg-body ul:last-child,
.ai-msg-body ol:last-child,
.ai-msg-body pre:last-child,
.ai-msg-body blockquote:last-child { margin-bottom: 0; }
.ai-msg-body ul,
.ai-msg-body ol { padding-left: 1.2rem; }
.ai-msg-body pre {
  padding: 10px;
  border-left-width: 3px;
  border-radius: 8px;
  font-size: 12px;
}
.ai-msg-body code { font-size: 12px; }
.ai-msg-body a { color: var(--accent); border-bottom: 1px dotted var(--accent); }
.ai-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 9px;
  padding: 12px;
  border-top: 1px solid var(--border);
  background: rgba(255,255,255,.72);
}
.ai-form textarea {
  width: 100%;
  resize: none;
  min-height: 46px;
  max-height: 112px;
  padding: 10px 11px;
  border: 1px solid var(--border);
  border-radius: 12px;
  outline: none;
  font: inherit;
  font-size: 13px;
  line-height: 1.45;
  color: var(--text);
  background: #fff;
}
.ai-form textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 14%, transparent);
}
.ai-form textarea:disabled { opacity: .65; }
.ai-form button {
  align-self: end;
  min-height: 46px;
  padding: 0 14px;
  border: 0;
  border-radius: 12px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  font: inherit;
  font-size: 13px;
  font-weight: 800;
}
.ai-form button:hover { background: var(--accent-dark); }
.ai-form button:disabled { opacity: .55; cursor: progress; }
@keyframes ai-pulse {
  0%, 100% { opacity: .28; }
  50% { opacity: 1; }
}

@media (max-width: 600px) {
  .ai-assistant { right: 14px; bottom: 14px; left: 14px; display: flex; justify-content: flex-end; }
  .ai-panel {
    left: 0;
    right: 0;
    width: 100%;
    height: min(590px, calc(100vh - 96px));
    bottom: 62px;
  }
  .ai-fab-label { display: none; }
}

@media (max-width: 900px) {
  .quick-grid { grid-template-columns: 1fr; }
  body.shelf-view main.shelf-page { padding: 44px 16px 56px; }
  .flow-row, .architecture-diagram, .sequence-diagram { min-width: 680px; }
}
