/* ============================================================
   Genver Docs — design system
   ============================================================ */

:root {
  /* Surfaces */
  --bg-app: #fbfbfc;
  --bg-panel: #ffffff;
  --bg-sidebar: #f8f8fa;
  --bg-subtle: #f3f3f6;
  --bg-hover: #eeeef2;
  --bg-active: #e7e7ed;
  --bg-sunken: #eaeaec;

  /* Text */
  --text-1: #18181b;
  --text-2: #5b5b66;
  --text-3: #8a8a95;
  --text-inv: #ffffff;

  /* Borders */
  --border-1: #ededf1;
  --border-2: #e0e0e6;
  --border-3: #c9c9d2;

  /* Accent */
  --accent: #5b5bd6;
  --accent-hover: #4e4ec4;
  --accent-press: #4444b0;
  --accent-subtle: #f1f1fe;
  --accent-border: #d7d7f8;
  --accent-text: #4a4ab5;

  /* Semantic */
  --success: #167c3c;
  --success-subtle: #e9f6ed;
  --warning: #9a5700;
  --warning-subtle: #fdf2e4;
  --danger: #c22b2b;
  --danger-subtle: #fdecec;
  --danger-border: #f5c9c9;

  /* Type scale */
  --fs-11: 11px;
  --fs-12: 12px;
  --fs-13: 13px;
  --fs-14: 14px;
  --fs-15: 15px;
  --fs-17: 17px;

  /* Radius */
  --r-4: 4px;
  --r-6: 6px;
  --r-8: 8px;
  --r-10: 10px;
  --r-14: 14px;

  /* Elevation */
  --sh-1: 0 1px 2px rgba(20, 20, 35, 0.05);
  --sh-2: 0 4px 12px rgba(20, 20, 35, 0.07), 0 0 0 1px rgba(20, 20, 35, 0.04);
  --sh-3: 0 16px 48px rgba(20, 20, 35, 0.16), 0 0 0 1px rgba(20, 20, 35, 0.06);
  --sh-paper: 0 1px 2px rgba(20, 20, 35, 0.06), 0 10px 30px rgba(20, 20, 35, 0.07);

  --ring: 0 0 0 3px rgba(91, 91, 214, 0.16);

  /* Layout */
  --menu-w: 216px;
  --toc-w: 264px;
  --chat-w: 440px;
  --split-w: 1px;
  --hit: 9px; /* splitter hit area padding */
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body { height: 100%; overflow: hidden; }

body {
  font-family: "Pretendard Variable", Pretendard, "IBM Plex Sans KR", -apple-system,
    BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: var(--fs-13);
  line-height: 1.5;
  color: var(--text-1);
  background: var(--bg-app);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: "tnum" 0;
}

::selection { background: rgba(91, 91, 214, 0.18); }

/* Scrollbars — thin and quiet */
* { scrollbar-width: thin; scrollbar-color: var(--border-3) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb {
  background: transparent;
  border: 3px solid transparent;
  border-radius: 8px;
  background-clip: padding-box;
}
*:hover::-webkit-scrollbar-thumb { background: var(--border-3); background-clip: padding-box; }
*::-webkit-scrollbar-thumb:hover { background: #adadb8; background-clip: padding-box; }

/* ============================================================
   Shell
   ============================================================ */

.app {
  display: grid;
  grid-template-columns:
    var(--menu-w) var(--split-w)
    var(--toc-w) var(--split-w)
    var(--chat-w) var(--split-w)
    minmax(320px, 1fr);
  height: 100dvh;
  max-height: 100dvh;
  min-height: 0;
  overflow: hidden;
}

.app.resizing { cursor: col-resize; user-select: none; }
.app.resizing .preview-stage { pointer-events: none; }

.splitter {
  position: relative;
  z-index: 20;
  width: var(--split-w);
  background: var(--border-1);
  cursor: col-resize;
  touch-action: none;
}
.splitter::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: calc(var(--hit) * -1);
  right: calc(var(--hit) * -1);
}
.splitter::before {
  content: "";
  position: absolute;
  inset: 0;
  background: transparent;
  transition: background 0.12s ease;
}
.splitter:hover::before,
.splitter:focus-visible::before,
.app.resizing .splitter.active::before {
  background: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}
.splitter:focus-visible { outline: none; }

/* ============================================================
   Buttons
   ============================================================ */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 28px;
  padding: 0 10px;
  border: 1px solid var(--border-2);
  border-radius: var(--r-6);
  background: var(--bg-panel);
  color: var(--text-1);
  font: inherit;
  font-size: var(--fs-12);
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease;
}
.btn:hover { background: var(--bg-subtle); border-color: var(--border-3); color: var(--text-1); }
.btn:active { background: var(--bg-active); }
.btn:focus-visible { outline: none; box-shadow: var(--ring); }
.btn:disabled { opacity: 1; cursor: not-allowed; color: var(--text-3); }
.btn:disabled:hover { background: var(--bg-panel); border-color: var(--border-2); color: var(--text-3); }

.btn.primary {
  background: var(--accent);
  border-color: transparent;
  color: var(--text-inv);
  box-shadow: var(--sh-1);
}
.btn.primary:hover { background: var(--accent-hover); border-color: transparent; color: var(--text-inv); }
.btn.primary:active { background: var(--accent-press); }
.btn.primary:disabled,
.btn.primary:disabled:hover {
  background: var(--bg-subtle);
  border-color: var(--border-2);
  color: var(--text-3);
  box-shadow: none;
}

.btn.ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn.ghost:hover { background: var(--bg-hover); color: var(--text-1); }

.btn.stop {
  background: var(--bg-panel);
  border-color: var(--danger-border);
  color: var(--danger);
}
.btn.stop:hover { background: var(--danger-subtle); border-color: var(--danger); color: var(--danger); }
.btn .stop-icon {
  width: 8px;
  height: 8px;
  background: currentColor;
  border-radius: 2px;
}

.btn.icon { width: 28px; padding: 0; }
.btn svg { width: 14px; height: 14px; flex-shrink: 0; }

.btn.sm { height: 24px; padding: 0 8px; font-size: var(--fs-11); }

/* ============================================================
   Menu (left rail)
   ============================================================ */

.menu {
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 12px 10px;
  background: var(--bg-sidebar);
  overflow: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 4px 6px 14px;
}
.brand .logo {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  flex-shrink: 0;
  border-radius: 7px;
  background: linear-gradient(150deg, var(--accent), #7b6cf0);
  color: #fff;
  font-size: var(--fs-13);
  font-weight: 700;
  letter-spacing: -0.02em;
  box-shadow: var(--sh-1);
}
.brand .txt { min-width: 0; display: flex; flex-direction: column; }
.brand .mark {
  font-size: var(--fs-13);
  font-weight: 650;
  letter-spacing: -0.01em;
  color: var(--text-1);
  line-height: 1.25;
}
.brand .sub {
  font-size: var(--fs-11);
  color: var(--text-3);
  line-height: 1.3;
}

.nav-label {
  padding: 12px 8px 4px;
  font-size: var(--fs-11);
  font-weight: 600;
  letter-spacing: 0.03em;
  color: var(--text-3);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  height: 30px;
  padding: 0 8px;
  border: 0;
  border-radius: var(--r-6);
  background: transparent;
  color: var(--text-2);
  font: inherit;
  font-size: var(--fs-13);
  font-weight: 500;
  text-align: left;
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease;
}
.nav-item:hover { background: var(--bg-hover); color: var(--text-1); }
.nav-item.active { background: var(--accent-subtle); color: var(--accent-text); font-weight: 600; }
.nav-item:focus-visible { outline: none; box-shadow: var(--ring); }
.nav-item .ico {
  display: grid;
  place-items: center;
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  color: currentColor;
  opacity: 0.85;
}
.nav-item .ico svg { width: 16px; height: 16px; }

.menu-foot {
  margin-top: auto;
  padding: 10px 8px 2px;
  border-top: 1px solid var(--border-1);
}
.model-chip {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 7px 8px;
  border-radius: var(--r-6);
  background: var(--bg-panel);
  border: 1px solid var(--border-1);
}
.model-chip .dot {
  width: 6px;
  height: 6px;
  flex-shrink: 0;
  border-radius: 50%;
  background: var(--text-3);
  box-shadow: 0 0 0 3px var(--bg-subtle);
}
.model-chip strong {
  min-width: 0;
  font-size: var(--fs-11);
  font-weight: 600;
  color: var(--text-2);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.model-chip[data-state="on"] .dot {
  background: var(--success);
  box-shadow: 0 0 0 3px var(--success-subtle);
}
.model-chip[data-state="on"] strong { color: var(--text-1); }
.model-chip[data-state="off"] .dot {
  background: var(--danger);
  box-shadow: 0 0 0 3px var(--danger-subtle);
}

/* ============================================================
   Panel primitives
   ============================================================ */

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-shrink: 0;
  height: 44px;
  padding: 0 12px 0 14px;
  border-bottom: 1px solid var(--border-1);
}
.panel-head h2 {
  font-size: var(--fs-12);
  font-weight: 600;
  color: var(--text-2);
  letter-spacing: 0.01em;
}

.badge {
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--bg-subtle);
  color: var(--text-2);
  font-size: var(--fs-11);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.badge.done { background: var(--success-subtle); color: var(--success); }

/* ============================================================
   TOC
   ============================================================ */

.toc {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: var(--bg-panel);
}

.toc-progress {
  flex-shrink: 0;
  height: 2px;
  background: var(--border-1);
}
.toc-progress .bar {
  height: 100%;
  width: 0;
  background: var(--accent);
  transition: width 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

.toc-list {
  flex: 1;
  min-height: 0;
  list-style: none;
  padding: 8px 8px 20px;
  overflow-x: hidden;
  overflow-y: auto;
}

.toc-item { border-radius: var(--r-6); }
.toc-item + .toc-item { margin-top: 1px; }

.toc-section-btn {
  display: grid;
  grid-template-columns: 16px 1fr auto;
  align-items: start;
  gap: 8px;
  width: 100%;
  padding: 7px 8px;
  border: 0;
  border-radius: var(--r-6);
  background: transparent;
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: background 0.12s ease;
}
.toc-section-btn:hover { background: var(--bg-hover); }
.toc-item.active > .toc-section-btn { background: var(--accent-subtle); }
.toc-section-btn:focus-visible { outline: none; box-shadow: var(--ring); }

.toc-section-btn .num {
  font-size: var(--fs-11);
  font-weight: 600;
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
  line-height: 1.5;
  padding-top: 1px;
}
.toc-item.active .num { color: var(--accent-text); }

.toc-section-btn .title {
  font-size: var(--fs-13);
  font-weight: 500;
  color: var(--text-1);
  line-height: 1.45;
  word-break: keep-all;
}
.toc-item.active .title { color: var(--accent-text); font-weight: 600; }

/* status as a dot, not repeated text */
.toc-section-btn .status {
  display: grid;
  place-items: center;
  width: 14px;
  height: 20px;
  flex-shrink: 0;
}
.toc-section-btn .status::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--border-3);
}
.toc-item.done .status::before { background: var(--success); }
.toc-item.writing .status::before {
  background: var(--warning);
  animation: pulse 1.4s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.35; transform: scale(0.8); }
}

.toc-children {
  list-style: none;
  margin: 1px 0 4px 15px;
  padding-left: 9px;
  border-left: 1px solid var(--border-1);
}
.toc-child-btn {
  display: block;
  width: 100%;
  padding: 5px 8px;
  border: 0;
  border-radius: var(--r-4);
  background: transparent;
  color: var(--text-2);
  font: inherit;
  font-size: var(--fs-12);
  line-height: 1.4;
  text-align: left;
  cursor: pointer;
  word-break: keep-all;
  transition: background 0.12s ease, color 0.12s ease;
}
.toc-child-btn:hover { background: var(--bg-hover); color: var(--text-1); }
.toc-child-btn.active { background: var(--accent-subtle); color: var(--accent-text); font-weight: 600; }
.toc-child-btn:focus-visible { outline: none; box-shadow: var(--ring); }

.toc-foot {
  flex-shrink: 0;
  display: flex;
  gap: 6px;
  padding: 10px 12px;
  border-top: 1px solid var(--border-1);
  background: var(--bg-panel);
}
.toc-foot .btn { flex: 1; height: 30px; }

/* Empty state (shared) */
.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 40px 20px;
  text-align: center;
}
.empty .icon {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  margin-bottom: 2px;
  border-radius: var(--r-8);
  background: var(--bg-subtle);
  color: var(--text-3);
}
.empty strong { font-size: var(--fs-13); font-weight: 600; color: var(--text-2); }
.empty span { font-size: var(--fs-12); color: var(--text-3); line-height: 1.5; }

/* ============================================================
   Chat
   ============================================================ */

.chat {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: var(--bg-panel);
  border-left: 1px solid var(--border-1);
  border-right: 1px solid var(--border-1);
}

.chat-head {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  height: 44px;
  padding: 0 14px;
  border-bottom: 1px solid var(--border-1);
}
.chat-head .title-wrap { min-width: 0; }
.chat-head h1 {
  font-size: var(--fs-13);
  font-weight: 650;
  letter-spacing: -0.01em;
  color: var(--text-1);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chat-head .meta {
  font-size: var(--fs-11);
  color: var(--text-3);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  flex-shrink: 0;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--bg-subtle);
  color: var(--text-2);
  font-size: var(--fs-11);
  font-weight: 600;
}
.status-pill::before {
  content: "";
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--text-3);
}
.status-pill[data-status="toc_ready"] { background: var(--accent-subtle); color: var(--accent-text); }
.status-pill[data-status="toc_ready"]::before { background: var(--accent); }
.status-pill[data-status="writing"] { background: var(--warning-subtle); color: var(--warning); }
.status-pill[data-status="writing"]::before { background: var(--warning); animation: pulse 1.4s ease-in-out infinite; }
.status-pill[data-status="complete"] { background: var(--success-subtle); color: var(--success); }
.status-pill[data-status="complete"]::before { background: var(--success); }

.messages {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 20px 16px 8px;
  overflow-x: hidden;
  overflow-y: auto;
  scroll-behavior: smooth;
}

/* --- conversation --- */
.msg { animation: rise 0.24s ease; }
@keyframes rise {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}

.msg.user {
  align-self: flex-end;
  max-width: 86%;
}
.msg.user .bubble {
  padding: 9px 12px;
  border-radius: var(--r-14);
  border-bottom-right-radius: var(--r-4);
  background: var(--accent);
  color: var(--text-inv);
  font-size: var(--fs-13);
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}
.msg.user .role { display: none; }

.msg.assistant { max-width: 100%; }
.msg.assistant .role {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 5px;
  font-size: var(--fs-11);
  font-weight: 600;
  color: var(--text-3);
}
.msg.assistant .role::before {
  content: "";
  width: 15px;
  height: 15px;
  border-radius: 5px;
  background: linear-gradient(150deg, var(--accent), #7b6cf0);
}
.msg.assistant .bubble {
  font-size: var(--fs-13);
  line-height: 1.65;
  color: var(--text-1);
  word-break: break-word;
}
.msg.assistant .bubble code {
  padding: 1px 5px;
  border-radius: var(--r-4);
  background: var(--bg-subtle);
  border: 1px solid var(--border-1);
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
  font-size: 0.88em;
  color: var(--text-1);
}
.msg.assistant .bubble ul { margin: 6px 0 0 18px; }
.msg.assistant .bubble li { margin: 2px 0; }

.msg .actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

/* --- system log group (file-level progress) --- */
.log-group {
  border: 1px solid var(--border-1);
  border-radius: var(--r-8);
  background: var(--bg-sidebar);
  overflow: hidden;
}
.log-row {
  display: grid;
  grid-template-columns: 16px 1fr auto;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 7px 10px;
  border: 0;
  background: transparent;
  font: inherit;
  font-size: var(--fs-12);
  color: var(--text-2);
  text-align: left;
  transition: background 0.12s ease;
}
button.log-row { cursor: pointer; }
button.log-row:hover { background: var(--bg-hover); }
button.log-row:focus-visible { outline: none; box-shadow: inset var(--ring); }
.log-row + .log-row { border-top: 1px solid var(--border-1); }
.log-row .log-icon {
  display: grid;
  place-items: center;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  font-size: 10px;
  font-weight: 700;
}
.log-row[data-state="done"] .log-icon { background: var(--success-subtle); color: var(--success); }
.log-row[data-state="running"] .log-icon { background: var(--warning-subtle); color: var(--warning); }
.log-row[data-state="cancelled"] .log-icon { background: var(--bg-active); color: var(--text-3); }
.log-row .log-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
  font-size: var(--fs-11);
  color: var(--text-1);
}
.log-row[data-state="cancelled"] .log-name { color: var(--text-3); font-family: inherit; font-size: var(--fs-12); }
.log-row .log-meta {
  flex-shrink: 0;
  font-size: var(--fs-11);
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
}

/* --- chat empty state --- */
.chat-empty {
  margin: auto 0;
  padding: 8px 4px 24px;
  text-align: left;
}
.chat-empty h2 {
  font-size: var(--fs-17);
  font-weight: 650;
  letter-spacing: -0.02em;
  color: var(--text-1);
  margin-bottom: 6px;
}
.chat-empty p {
  font-size: var(--fs-13);
  color: var(--text-2);
  line-height: 1.6;
  margin-bottom: 16px;
}
.suggestions { display: flex; flex-direction: column; gap: 6px; }
.suggestion {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--border-1);
  border-radius: var(--r-8);
  background: var(--bg-panel);
  color: var(--text-1);
  font: inherit;
  font-size: var(--fs-12);
  line-height: 1.45;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.12s ease, background 0.12s ease;
}
.suggestion:hover { border-color: var(--accent-border); background: var(--accent-subtle); }
.suggestion:focus-visible { outline: none; box-shadow: var(--ring); }
.suggestion .arrow { margin-left: auto; color: var(--text-3); flex-shrink: 0; }

/* ============================================================
   Composer
   ============================================================ */

.composer {
  flex-shrink: 0;
  padding: 10px 14px 12px;
  border-top: 1px solid var(--border-1);
  background: var(--bg-panel);
}

.job-progress {
  margin-bottom: 8px;
  border: 1px solid var(--accent-border);
  border-radius: var(--r-8);
  background: var(--accent-subtle);
  overflow: hidden;
}
.job-bar {
  height: 2px;
  background: rgba(91, 91, 214, 0.16);
  overflow: hidden;
}
.job-bar::after {
  content: "";
  display: block;
  width: 36%;
  height: 100%;
  background: var(--accent);
  animation: indeterminate 1.15s ease-in-out infinite;
}
@keyframes indeterminate {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(340%); }
}
.job-progress-main {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
}
.job-progress-text { display: flex; align-items: baseline; gap: 7px; min-width: 0; }
.job-progress-text strong {
  font-size: var(--fs-12);
  font-weight: 600;
  color: var(--accent-text);
  flex-shrink: 0;
}
.job-progress-text span {
  font-size: var(--fs-11);
  color: var(--text-2);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.job-count {
  margin-left: auto;
  flex-shrink: 0;
  font-size: var(--fs-11);
  font-weight: 600;
  color: var(--accent-text);
  font-variant-numeric: tabular-nums;
}
.job-steps {
  list-style: none;
  max-height: 92px;
  overflow: auto;
  margin: 0;
  padding: 0 10px 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.job-steps li {
  font-size: var(--fs-11);
  color: var(--text-3);
  padding-left: 12px;
  position: relative;
  line-height: 1.55;
}
.job-steps li::before {
  content: "";
  position: absolute;
  left: 2px;
  top: 7px;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--border-3);
}
.job-steps li.running { color: var(--accent-text); font-weight: 600; }
.job-steps li.running::before { background: var(--accent); }
.job-steps li.done::before { background: var(--success); }
.job-steps li.cancelled { text-decoration: line-through; }

.composer-box {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: end;
  gap: 8px;
  padding: 8px 8px 8px 12px;
  border: 1px solid var(--border-2);
  border-radius: var(--r-10);
  background: var(--bg-panel);
  box-shadow: var(--sh-1);
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}
.composer-box:focus-within {
  border-color: var(--accent-border);
  box-shadow: var(--ring);
}
.composer textarea {
  width: 100%;
  min-height: 40px;
  max-height: 168px;
  padding: 4px 0;
  border: 0;
  outline: none;
  resize: none;
  background: transparent;
  font: inherit;
  font-size: var(--fs-13);
  line-height: 1.6;
  color: var(--text-1);
}
.composer textarea::placeholder { color: var(--text-3); }

.composer .send-btn { height: 30px; padding: 0 12px; }

.composer .hint {
  margin-top: 7px;
  padding: 0 2px;
  font-size: var(--fs-11);
  line-height: 1.9;
  color: var(--text-3);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.composer .hint kbd {
  padding: 1px 5px;
  border: 1px solid var(--border-2);
  border-bottom-width: 2px;
  border-radius: var(--r-4);
  background: var(--bg-subtle);
  font-family: inherit;
  font-size: 10px;
  color: var(--text-2);
}

/* ============================================================
   Preview
   ============================================================ */

.preview {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: var(--bg-sunken);
}

.preview-toolbar {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 44px;
  padding: 7px 12px;
  border-bottom: 1px solid var(--border-2);
  background: var(--bg-panel);
  flex-wrap: wrap;
}

.seg {
  display: inline-flex;
  gap: 2px;
  padding: 2px;
  border-radius: var(--r-8);
  background: var(--bg-subtle);
}
.seg button {
  height: 26px;
  padding: 0 10px;
  border: 0;
  border-radius: var(--r-6);
  background: transparent;
  color: var(--text-2);
  font: inherit;
  font-size: var(--fs-12);
  font-weight: 500;
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease;
}
.seg button:hover { color: var(--text-1); }
.seg button.active {
  background: var(--bg-panel);
  color: var(--text-1);
  font-weight: 600;
  box-shadow: var(--sh-1);
}
.seg button:focus-visible { outline: none; box-shadow: var(--ring); }

.preview-actions { display: flex; align-items: center; gap: 6px; }

.preview-meta {
  flex-basis: 100%;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 2px;
  font-size: var(--fs-11);
  color: var(--text-3);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.preview-meta .sep { opacity: 0.5; }
.preview-meta b { font-weight: 600; color: var(--text-2); }

.preview-stage {
  flex: 1;
  min-height: 0;
  padding: 24px 24px 40px;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.preview-stage .preview-root { min-height: min-content; }
.preview-stage .page {
  max-width: 660px;
  margin: 0 auto 22px;
  padding: 46px 48px;
  min-height: auto;
  background: #fff;
  border-radius: 3px;
  box-shadow: var(--sh-paper);
}
.preview-stage .page:last-child { margin-bottom: 0; }
.preview-stage .cover-page { min-height: 540px; }

/* ============================================================
   Modal / overlays
   ============================================================ */

.modal-backdrop,
.docs-panel {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(20, 20, 35, 0.4);
  backdrop-filter: blur(2px);
}
.modal-backdrop.open,
.docs-panel.open { display: flex; animation: fade 0.14s ease; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.modal,
.docs-modal {
  display: flex;
  flex-direction: column;
  width: min(920px, 100%);
  max-height: min(90vh, 900px);
  overflow: hidden;
  border-radius: var(--r-14);
  background: var(--bg-panel);
  box-shadow: var(--sh-3);
  animation: pop 0.16s cubic-bezier(0.2, 0, 0.2, 1);
}
@keyframes pop {
  from { opacity: 0; transform: translateY(6px) scale(0.99); }
  to { opacity: 1; transform: none; }
}

.modal-head,
.docs-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-shrink: 0;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border-1);
}
.modal-head h3,
.docs-head h3 {
  font-size: var(--fs-14);
  font-weight: 650;
  letter-spacing: -0.01em;
}
.modal-head .sub {
  display: block;
  margin-top: 2px;
  font-size: var(--fs-11);
  font-weight: 400;
  color: var(--text-3);
}

.modal-body { flex: 1; min-height: 0; padding: 16px 18px 20px; overflow: auto; }

.style-tabs {
  display: inline-flex;
  gap: 2px;
  margin-bottom: 16px;
  padding: 2px;
  border-radius: var(--r-8);
  background: var(--bg-subtle);
}
.style-tabs button {
  height: 28px;
  padding: 0 12px;
  border: 0;
  border-radius: var(--r-6);
  background: transparent;
  color: var(--text-2);
  font: inherit;
  font-size: var(--fs-12);
  font-weight: 500;
  cursor: pointer;
}
.style-tabs button:hover { color: var(--text-1); }
.style-tabs button.active {
  background: var(--bg-panel);
  color: var(--text-1);
  font-weight: 600;
  box-shadow: var(--sh-1);
}

.style-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 14px;
}
.style-card {
  border: 1px solid var(--border-2);
  border-radius: var(--r-10);
  background: var(--bg-panel);
  overflow: hidden;
  cursor: pointer;
  transition: border-color 0.12s ease, box-shadow 0.12s ease, transform 0.12s ease;
}
.style-card:hover { border-color: var(--border-3); transform: translateY(-1px); box-shadow: var(--sh-2); }
.style-card.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}
.style-card .thumb {
  --c: #8b8b96;
  position: relative;
  aspect-ratio: 210 / 297;
  background: var(--c);
  border-bottom: 1px solid var(--border-1);
  overflow: hidden;
}
.style-card .thumb iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  display: block;
  /* Clicks belong to the card, not the rendered page inside. */
  pointer-events: none;
}

.style-card .meta { padding: 9px 11px 11px; }
.style-card .meta strong {
  display: block;
  font-size: var(--fs-12);
  font-weight: 600;
  color: var(--text-1);
}
.style-card .meta span {
  display: block;
  margin-top: 1px;
  font-size: var(--fs-11);
  color: var(--text-3);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  flex-shrink: 0;
  padding: 12px 18px;
  border-top: 1px solid var(--border-1);
  background: var(--bg-sidebar);
}
.modal-foot .btn { height: 30px; padding: 0 14px; }

/* Docs list */
.docs-modal { width: min(480px, 100%); }
.docs-modal ul { list-style: none; padding: 10px 12px 14px; overflow: auto; }
.docs-modal li {
  padding: 9px 11px;
  border: 1px solid var(--border-1);
  border-radius: var(--r-8);
  cursor: pointer;
  transition: border-color 0.12s ease, background 0.12s ease;
}
.docs-modal li + li { margin-top: 6px; }
.docs-modal li:hover { border-color: var(--accent-border); background: var(--accent-subtle); }
.docs-modal li strong { font-size: var(--fs-13); font-weight: 600; }
.docs-modal .dim {
  margin-top: 2px;
  font-size: var(--fs-11);
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
}

/* ============================================================
   Toast
   ============================================================ */

.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  z-index: 90;
  transform: translateX(-50%) translateY(8px);
  padding: 8px 14px;
  border-radius: var(--r-8);
  background: var(--text-1);
  color: var(--text-inv);
  font-size: var(--fs-12);
  font-weight: 500;
  box-shadow: var(--sh-3);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ============================================================
   Responsive
   ============================================================ */

@media (max-width: 1240px) {
  .app {
    grid-template-columns:
      52px var(--split-w)
      minmax(200px, var(--toc-w)) var(--split-w)
      minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr) minmax(0, 1fr);
  }
  .menu { grid-row: 1 / -1; padding: 12px 8px; }
  .splitter[data-split="menu"] { grid-row: 1 / -1; }
  .splitter[data-split="chat"] { display: none; }
  .chat { grid-column: 5; grid-row: 1; border-right: 0; }
  .preview { grid-column: 3 / -1; grid-row: 2; border-top: 1px solid var(--border-2); }
  .brand { justify-content: center; padding: 4px 0 14px; }
  .brand .txt, .nav-label, .menu-foot { display: none; }
  .nav-item { justify-content: center; padding: 0; }
  .nav-item span:not(.ico) { display: none; }
}

@media (max-width: 860px) {
  html, body { height: auto; overflow: auto; }
  .app {
    grid-template-columns: 1fr;
    grid-template-rows: none;
    height: auto;
    max-height: none;
    min-height: 100dvh;
    overflow: visible;
  }
  .splitter { display: none; }
  .menu {
    grid-row: auto;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px;
    padding: 10px 12px;
    max-height: none;
    overflow: visible;
    border-bottom: 1px solid var(--border-1);
  }
  .brand { width: 100%; justify-content: flex-start; padding: 2px 2px 8px; }
  .brand .txt { display: block; }
  .nav-item { width: auto; padding: 0 10px; justify-content: flex-start; }
  .nav-item span:not(.ico) { display: inline; }
  .toc { grid-column: auto; grid-row: auto; max-height: 320px; }
  .chat, .preview {
    grid-column: auto;
    grid-row: auto;
    height: min(72vh, 660px);
    min-height: 440px;
    border-left: 0;
    border-right: 0;
  }
  .preview-stage { padding: 16px 12px 28px; }
  .preview-stage .page { padding: 32px 24px; }
}
