:root {
  --bg: #f4f6f7;
  --panel: #ffffff;
  --ink: #17202a;
  --muted: #5f6b76;
  --line: #d9e0e5;
  --nav: #16211f;
  --nav-ink: #cfd9d6;
  --nav-active: #223632;
  --accent: #1f8a7a;
  --accent-ink: #ffffff;
  --accent-soft: #e2f3ef;
  --warn: #b7791f;
  --warn-soft: #fff5e0;
  --danger: #b3261e;
  --danger-soft: #fde9e7;
  --ok: #2e7d32;
  --ok-soft: #e6f4e8;
  --radius: 8px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body { font: 15px/1.45 var(--font); color: var(--ink); background: var(--bg); -webkit-text-size-adjust: 100%; }
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .55; }
h1, h2, h3, h4 { margin: 0 0 .5rem; line-height: 1.25; }
h1 { font-size: 1.45rem; } h2 { font-size: 1.15rem; } h3 { font-size: 1rem; } h4 { font-size: .92rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
p { margin: 0 0 .6rem; }
code, .mono { font-family: var(--mono); font-size: .88em; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.hidden { display: none !important; }
.draft-launch { margin: 12px 0; border: 1px solid var(--accent); background: linear-gradient(120deg,var(--accent-soft),var(--panel)); }
.draft-primary { font-size: 1.05rem; padding: 12px 20px; }
.draft-launch details, .advanced-book details { margin-top: 10px; }
summary { cursor: pointer; padding: 5px 0; }
.brief-grid { display: grid; grid-template-columns: 130px 1fr; gap: 6px 12px; margin-top: 8px; }
.candidate-text { width: 100%; min-height: 220px; max-height: 460px; margin: 8px 0; }
.chapter-board { margin: 12px 0; }
.chapter-board .table-wrap { max-height: 480px; overflow: auto; margin: 10px 0; }
.chapter-board th { position: sticky; top: 0; background: var(--panel); }
.chapter-board td:first-child { min-width: 180px; }
.chapter-board #quick-find { min-width: 160px; }
.nav details summary { color: var(--nav-ink); padding: 8px 10px; font-size: .9rem; }
@media(max-width:600px){ .brief-grid {grid-template-columns:1fr;} .draft-launch .row .btn { flex:1; } .draft-launch h2 {font-size:1.1rem;} }
hr { border: 0; border-top: 1px solid var(--line); margin: 1rem 0; }

/* layout */
.shell { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.nav { background: var(--nav); color: var(--nav-ink); padding: 14px 12px; display: flex; flex-direction: column; gap: 6px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.nav .brand { color: #fff; font-weight: 700; font-size: 1.02rem; padding: 6px 8px 10px; border-bottom: 1px solid #2a3a36; margin-bottom: 6px; }
.nav .brand small { display: block; color: #8fa39d; font-weight: 400; font-size: .78rem; margin-top: 2px; }
.nav .group { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: #7f948e; padding: 10px 8px 4px; }
.nav a, .nav button.navlink { display: flex; align-items: center; justify-content: space-between; gap: 8px; color: var(--nav-ink); text-decoration: none; padding: 7px 10px; border-radius: 6px; background: none; border: 0; text-align: left; width: 100%; font-size: .93rem; }
.nav a:hover, .nav button.navlink:hover { background: #1d2b28; color: #fff; }
.nav a.active, .nav button.navlink.active { background: var(--nav-active); color: #fff; }
.nav .badge { background: var(--accent); color: #fff; border-radius: 10px; padding: 0 7px; font-size: .75rem; }
.nav .book { background: #1b2724; border: 1px solid #2c3f3a; border-radius: 6px; padding: 8px 10px; margin: 4px 0 8px; }
.nav .book .title { color: #fff; font-weight: 600; font-size: .92rem; }
.nav .book select { width: 100%; margin-top: 6px; background: #0f1816; color: #fff; border: 1px solid #2c3f3a; border-radius: 4px; padding: 4px 6px; }
.nav .user { margin-top: auto; border-top: 1px solid #2a3a36; padding-top: 10px; font-size: .85rem; color: #a9b9b4; }
.nav .user strong { color: #fff; display: block; }
.main { padding: 18px 22px 40px; min-width: 0; }
.topbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.topbar .grow { flex: 1; }
.topbar input[type=search] { min-width: 220px; }
.menu-toggle { display: none; }

/* cards */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 14px; }
.card.compact { padding: 10px 12px; }
.card h2 { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.grid { display: grid; gap: 14px; }
.grid.two { grid-template-columns: 1fr 1fr; }
.grid.three { grid-template-columns: repeat(3, 1fr); }
.split { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 14px; align-items: start; }
.split .side { position: sticky; top: 12px; max-height: calc(100vh - 24px); overflow-y: auto; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack { display: flex; flex-direction: column; gap: 8px; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; }
.kpi .v { font-size: 1.5rem; font-weight: 700; }
.kpi .l { color: var(--muted); font-size: .82rem; }
.empty { color: var(--muted); padding: 18px; text-align: center; border: 1px dashed var(--line); border-radius: var(--radius); }

/* forms */
label { display: block; font-size: .85rem; color: var(--muted); margin-bottom: 3px; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=search], input[type=url], select, textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 6px; padding: 7px 9px; background: #fff;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
textarea { min-height: 90px; resize: vertical; font-family: inherit; }
textarea.body { min-height: 420px; font-family: var(--mono); font-size: .9rem; line-height: 1.5; }
.field { margin-bottom: 10px; }
.inline { display: inline-block; width: auto; }
.btn { border: 1px solid var(--line); background: #fff; border-radius: 6px; padding: 7px 12px; font-size: .9rem; white-space: nowrap; }
.btn:hover { background: #f1f4f5; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: #197061; }
.btn.danger { color: var(--danger); border-color: #e4b4b0; }
.btn.danger:hover { background: var(--danger-soft); }
.btn.sm { padding: 3px 8px; font-size: .82rem; }
.btn.link { border: 0; background: none; color: var(--accent); padding: 2px 4px; }
.btn.block { width: 100%; }

/* tags */
.tag { display: inline-block; border-radius: 4px; padding: 1px 7px; font-size: .76rem; font-weight: 600; background: #e9eef1; color: #3c4a56; white-space: nowrap; }
.tag.ok { background: var(--ok-soft); color: var(--ok); }
.tag.warn { background: var(--warn-soft); color: var(--warn); }
.tag.danger { background: var(--danger-soft); color: var(--danger); }
.tag.accent { background: var(--accent-soft); color: var(--accent); }
.tag.dim { background: #f1f3f4; color: #7a858f; }
.note { border-left: 3px solid var(--warn); background: var(--warn-soft); padding: 8px 12px; border-radius: 4px; font-size: .88rem; margin-bottom: 10px; }
.note.info { border-color: var(--accent); background: var(--accent-soft); }
.note.danger { border-color: var(--danger); background: var(--danger-soft); }

/* tables */
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; }
tr.clickable { cursor: pointer; }
tr.clickable:hover { background: #f6f9f8; }
.table-wrap { overflow-x: auto; }

/* tree */
.tree { font-size: .92rem; }
.tree .node { display: flex; align-items: center; gap: 6px; padding: 3px 6px; border-radius: 4px; }
.tree .node:hover { background: #f1f5f4; }
.tree .node.selected { background: var(--accent-soft); }
.tree .node .num { color: var(--muted); font-family: var(--mono); font-size: .8rem; min-width: 2.2em; }
.tree .node .title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tree .node.volume .title, .tree .node.part .title { font-weight: 600; }
.tree .node.volume { background: #f7f9f9; border-top: 1px solid var(--line); margin-top: 4px; }
.tree .toggle { width: 18px; height: 18px; border: 0; background: none; color: var(--muted); padding: 0; font-size: .8rem; }
.tree .children { margin-left: 16px; border-left: 1px dotted var(--line); padding-left: 4px; }
.tree .flags { display: flex; gap: 4px; }
.tree .dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }

/* lists */
.list { list-style: none; margin: 0; padding: 0; }
.list li { padding: 8px 0; border-bottom: 1px solid var(--line); }
.list li:last-child { border-bottom: 0; }
.item-title { font-weight: 600; }
.comment { border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px; margin-bottom: 8px; background: #fbfcfc; }
.comment.resolved { opacity: .7; }
.comment .quote { border-left: 3px solid var(--line); padding-left: 8px; color: var(--muted); font-style: italic; margin: 4px 0; font-size: .85rem; }
.reply { margin: 6px 0 0 14px; padding: 6px 8px; background: #fff; border: 1px solid var(--line); border-radius: 4px; font-size: .88rem; }

/* diff */
.diff { font-family: var(--mono); font-size: .82rem; white-space: pre-wrap; border: 1px solid var(--line); border-radius: 6px; max-height: 420px; overflow: auto; }
.diff .l { padding: 1px 8px; }
.diff .l.add { background: #e3f6e6; }
.diff .l.del { background: #fde7e5; text-decoration: line-through; opacity: .85; }
.diff .l.ctx { color: #4b5560; }

/* tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 12px; flex-wrap: wrap; }
.tabs button { border: 0; background: none; padding: 8px 12px; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs button.active { color: var(--ink); border-bottom-color: var(--accent); font-weight: 600; }

/* status strip */
.status-strip { display: flex; gap: 4px; flex-wrap: wrap; align-items: center; margin-bottom: 10px; }
.status-strip .step { padding: 3px 9px; border-radius: 12px; font-size: .78rem; background: #eef1f3; color: #6b7682; }
.status-strip .step.current { background: var(--accent); color: #fff; font-weight: 600; }
.status-strip .step.done { background: var(--ok-soft); color: var(--ok); }

/* toasts, modal */
.toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 1000; max-width: 360px; }
.toast { background: #1d2a28; color: #fff; padding: 10px 14px; border-radius: 6px; box-shadow: 0 6px 20px rgba(0,0,0,.2); font-size: .9rem; }
.toast.error { background: var(--danger); }
.toast.ok { background: var(--ok); }
.modal-bg { position: fixed; inset: 0; background: rgba(20,30,28,.5); display: flex; align-items: center; justify-content: center; z-index: 900; padding: 16px; }
.modal { background: #fff; border-radius: 10px; padding: 18px; width: min(720px, 100%); max-height: 90vh; overflow-y: auto; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal.wide { width: min(1100px, 100%); }

/* auth */
.auth { max-width: 460px; margin: 8vh auto; }
.auth .brand { font-size: 1.4rem; font-weight: 700; margin-bottom: 4px; }

/* unsaved */
.author-brief-panel { border-top:1px solid var(--line); margin:16px 0; padding-top:12px; }
.author-brief-panel h3 { margin:4px 0 12px; }
.author-brief-panel select { width:100%; min-width:0; text-overflow:ellipsis; }
.author-brief-text { width:100%; min-height:300px; max-height:65vh; margin:8px 0; line-height:1.55; font-family:inherit; resize:vertical; background:#fcfdfb; }
.brief-references { display:flex; flex-wrap:wrap; gap:6px; }
.brief-references .btn { white-space:normal; text-align:left; }
.brief-links { margin-top:10px; }
.dirty { color: var(--warn); font-weight: 600; font-size: .85rem; }
.saved { color: var(--ok); font-size: .85rem; }
.caps li { display: flex; gap: 8px; align-items: flex-start; }
.search-results { position: absolute; background: #fff; border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 10px 30px rgba(0,0,0,.15); width: min(640px, 92vw); max-height: 60vh; overflow-y: auto; z-index: 800; padding: 8px; }
.search-wrap { position: relative; }
.kbd { font-family: var(--mono); font-size: .75rem; border: 1px solid var(--line); border-radius: 3px; padding: 0 4px; color: var(--muted); }
.protected { background: #fff3cd; }

@media (max-width: 1100px) {
  .split { grid-template-columns: 1fr; }
  .split .side { position: static; max-height: none; }
  .grid.three { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .nav { position: fixed; left: 0; top: 0; bottom: 0; width: 82vw; max-width: 320px; transform: translateX(-100%); transition: transform .2s; z-index: 950; box-shadow: 0 0 40px rgba(0,0,0,.4); }
  .nav.open { transform: translateX(0); }
  .menu-toggle { display: inline-flex; }
  .main { padding: 12px 12px 60px; }
  .grid.two, .grid.three { grid-template-columns: 1fr; }
  textarea.body { min-height: 260px; }
  .topbar input[type=search] { min-width: 0; width: 100%; }
  table { font-size: .84rem; }
}

/* Editable narrative plan, shared by AI and human authors. */
.draft-plan-panel{margin:20px 0;padding:20px;background:#fff;border:1px solid var(--line,#d9e1e4);border-radius:12px}.draft-plan-panel h3{margin:0}.draft-plan-text{min-height:400px;width:100%;line-height:1.6;font-family:inherit;font-size:14px;resize:vertical;margin:7px 0 10px}.plan-generate{white-space:normal;text-align:left;line-height:1.5}.plan-scope{margin-top:16px}.draft-plan-panel [hidden]{display:none!important}#plan-proposal{width:100%;line-height:1.55;font-family:inherit}
