:root {
  --bg: #f4f2ee; --card: #fff; --ink: #1d2430; --muted: #6b7280; --line: #e4e0d8;
  --accent: #233a5e; --accent2: #3d5f94; --ok: #1f7a4d; --bad: #b42318; --warn: #a15c07;
  --radius: 10px; --font: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.5 var(--font); }
a { color: var(--accent2); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { font-family: Georgia, "Times New Roman", serif; font-weight: 600; margin: 0 0 .4em; }
h2 { font-size: 30px; } h3 { font-size: 19px; }
code, .mono { font-family: Consolas, "Cascadia Mono", monospace; font-size: 13px; }
.muted { color: var(--muted); } .small { font-size: 13px; } .nowrap { white-space: nowrap; }
.err { color: var(--bad); } .warn { color: var(--warn); } .live { color: var(--ok); }
input, textarea { font: inherit; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--ink); }
input:focus, textarea:focus { outline: 2px solid #9fb6dc; border-color: transparent; }
textarea { width: 100%; resize: vertical; }
.full { width: 100%; } .grow { flex: 1; min-width: 160px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; } .row.end { justify-content: flex-end; }
.stack { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 7px 13px; border-radius: 8px; border: 1px solid var(--line);
  background: #fff; color: var(--ink); cursor: pointer; font: inherit; font-size: 14px; white-space: nowrap; text-decoration: none !important; }
.btn:hover { border-color: #c9c3b8; background: #faf9f7; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #1a2d4a; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.sm { padding: 4px 10px; font-size: 13px; } .btn.xs { padding: 2px 7px; font-size: 12px; }
.btn.danger, .lnk.danger { color: var(--bad); }
.btn:disabled { opacity: .5; cursor: wait; }
.lnk { font-size: 13px; }
.chip { display: inline-block; padding: 3px 10px; border-radius: 99px; background: #ece8e1; font-size: 12.5px; color: #3b4250; white-space: nowrap; }
.chip.ok { background: #dcefe4; color: var(--ok); } .chip.bad { background: #f8e1de; color: var(--bad); }
.logo { display: inline-grid; place-items: center; width: 56px; height: 56px; border-radius: 14px; background: var(--accent); color: #fff; font: 600 20px Georgia, serif; }
.logo.sm { width: 30px; height: 30px; font-size: 12px; border-radius: 8px; vertical-align: middle; margin-right: 6px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; margin-bottom: 8px; }
body.center { min-height: 100vh; display: grid; place-items: center; }
.login { width: 340px; display: flex; flex-direction: column; gap: 12px; text-align: center; align-items: stretch; }
.login .logo { margin: 0 auto; } .login h1 { font-size: 20px; }
.top { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 24px; border-bottom: 1px solid var(--line); background: #fbfaf8; flex-wrap: wrap; }
.brand { font-weight: 600; } .chips { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; padding: 20px 24px 40px; max-width: 1200px; margin: 0 auto; }
.span2 { grid-column: span 2; }
@media (max-width: 820px) { .grid { grid-template-columns: 1fr; } .span2 { grid-column: auto; } }
.hero-doc { display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap;
  background: linear-gradient(135deg, #fff 0%, #eef2f8 100%); }
.eyebrow { font: 12px Consolas, monospace; color: var(--accent2); letter-spacing: .05em; }
.list { list-style: none; margin: 0; padding: 0; }
.list li { padding: 7px 0; border-bottom: 1px dashed var(--line); display: flex; flex-wrap: wrap; gap: 6px; align-items: baseline; }
.list li:last-child { border-bottom: 0; } .list .right { margin-left: auto; }
.tasks li { display: block; }
.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th { text-align: left; font-weight: 600; color: var(--muted); font-size: 12.5px; border-bottom: 1px solid var(--line); padding: 6px; }
.tbl td { border-bottom: 1px dashed var(--line); padding: 7px 6px; vertical-align: top; }
.badge { display: inline-block; font-size: 11.5px; padding: 1px 8px; border-radius: 99px; background: #ece8e1; }
.badge.done { background: #dcefe4; color: var(--ok); } .badge.failed, .badge.cancelled { background: #f8e1de; color: var(--bad); }
.badge.running { background: #e1e9f8; color: var(--accent2); } .badge.queued { background: #fdf0d5; color: var(--warn); }
.badge.k-manual, .badge.k-claude, .badge.k-restore, .badge.k-upload { background: #e1e9f8; color: var(--accent2); }
.steps li { margin-bottom: 4px; }
pre { white-space: pre-wrap; }
#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: #1d2430; color: #fff; padding: 10px 18px; border-radius: 8px; z-index: 50; box-shadow: 0 6px 24px #0003; max-width: 90vw; }

/* editor page */
body.editor-page { height: 100vh; display: flex; flex-direction: column; overflow: hidden; }
.ed-top { display: flex; align-items: center; gap: 6px; padding: 6px 10px; border-bottom: 1px solid var(--line); background: #fbfaf8; flex-wrap: wrap; }
.ed-title { font-weight: 600; margin: 0 8px; } .spacer { flex: 1; }
.ed-main { flex: 1; display: flex; min-height: 0; }
#editorWrap { flex: 1; min-width: 0; }
#drawer { width: 380px; border-left: 1px solid var(--line); background: #fff; display: flex; flex-direction: column; overflow: hidden; }
#drawer[hidden] { display: none; }
.drawer-head { display: flex; justify-content: space-between; align-items: center; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.panel { padding: 12px 14px; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; }
.panel[hidden] { display: none; }
.hist .item, .refs .item, .tasks .item { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; margin-bottom: 6px; font-size: 13.5px; }
.hist .item .acts, .refs .item .acts { margin-top: 4px; display: flex; gap: 6px; }
#banner { position: fixed; top: 54px; left: 50%; transform: translateX(-50%); background: var(--accent); color: #fff; padding: 10px 18px; border-radius: 8px; z-index: 40; }
#modal { position: fixed; inset: 0; background: #0006; display: grid; place-items: center; z-index: 45; }
#modal[hidden] { display: none; }
.modal-card { width: 440px; display: flex; flex-direction: column; gap: 12px; }

/* titles, descriptions, drag & drop */
.desc { white-space: pre-line; margin: 4px 0 8px; color: #3b4250; }
.pubs li.pub { align-items: flex-start; gap: 8px; border-radius: 6px; }
.handle { cursor: grab; color: #a9a295; user-select: none; padding: 0 2px; font-weight: 700; letter-spacing: -2px; }
li.pub.dragging { opacity: .45; background: #eef2f8; }
.drop-hl { outline: 2px dashed var(--accent2) !important; outline-offset: 2px; background: #eef3fb !important; }
#dropOverlay { position: fixed; inset: 0; z-index: 60; pointer-events: none; background: rgba(35, 58, 94, .10); border: 3px dashed var(--accent2); display: grid; place-items: end center; }
#dropOverlay[hidden] { display: none; }
#dropOverlay div { margin-bottom: 30px; background: var(--accent); color: #fff; padding: 10px 18px; border-radius: 8px; }
#dropOverlay.targeted div { display: none; }
.dropzone { border: 1px dashed var(--line); border-radius: 8px; padding: 8px 10px; margin-bottom: 8px; text-align: center; }
.modal { position: fixed; inset: 0; background: #0006; display: grid; place-items: center; z-index: 45; }
.modal[hidden] { display: none; }

/* public pages */
body.public { background: #fbfaf7; }
.pub-top { display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap; padding: 14px clamp(16px, 5vw, 56px); border-bottom: 1px solid var(--line); background: #fff; }
.pub-top nav { gap: 18px; }
.pub-top nav a:not(.btn) { color: var(--ink); }
.pub-main { max-width: 860px; margin: 0 auto; padding: 32px clamp(16px, 5vw, 40px) 60px; }
.pub-main section { margin-bottom: 52px; }
.pub-main h2 { font-size: 26px; border-bottom: 1px solid var(--line); padding-bottom: 6px; margin-bottom: 18px; }
.pub-hero h1 { font: 600 clamp(26px, 4vw, 38px)/1.2 Georgia, "Times New Roman", serif; margin: 6px 0 12px; }
.pub-hero h1 a { color: var(--ink); }
.lead { font-size: 17px; color: #3b4250; white-space: pre-line; }
.pub-class-block { margin-bottom: 28px; }
.pub-list { padding-left: 22px; } .pub-list li { margin-bottom: 16px; }
.pub-title { font: 600 18px Georgia, serif; color: var(--ink); }
.bib { padding-left: 34px; font-size: 15px; } .bib li { margin-bottom: 8px; }
.pub-foot { text-align: center; color: var(--muted); font-size: 13px; padding: 24px; border-top: 1px solid var(--line); }
body.viewer { height: 100vh; display: flex; flex-direction: column; }
.pub-top.doc { align-items: flex-end; }
.doc-title { font: 600 24px/1.25 Georgia, serif; margin: 4px 0 2px; }
.pdf-wrap { flex: 1; position: relative; min-height: 60vh; background: #e9e6e0; }
.pdf-wrap iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.pdf-loading { position: absolute; top: 40%; width: 100%; text-align: center; }
.pdf-note { text-align: center; margin: 6px; }
