/* Margin — warm, papery, quiet. */
:root {
  --paper: #faf9f7;
  --surface: #ffffff;
  --ink: #1c1b1a;
  --ink-soft: #6f6a64;
  --ink-faint: #a8a29b;
  --line: #e8e4de;
  --accent: #c2410c;
  --accent-soft: #fff1e8;
  --green: #2b8a3e;
  --green-soft: #e6f4ea;
  --red: #c92a2a;
  --red-soft: #fdecec;
  --yellow-soft: #fef3c0;
  --yellow: #f5c518;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(28, 27, 26, .05), 0 4px 16px rgba(28, 27, 26, .06);
  --shadow-lg: 0 4px 12px rgba(28, 27, 26, .08), 0 16px 48px rgba(28, 27, 26, .14);
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--sans);
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; }
a { color: var(--accent); text-decoration: none; }
h1, h2, h3 { margin: 0 0 .4em; font-weight: 650; letter-spacing: -.015em; }

/* ---------- shared controls ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--surface);
  font-size: 14px; font-weight: 500; line-height: 1;
  transition: background .12s, border-color .12s, transform .06s;
}
.btn:hover { background: #f5f2ee; }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn-primary:hover { background: #000; }
.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn-block { width: 100%; justify-content: center; padding: 10px; }
.icon-btn {
  padding: 3px 6px; border-radius: 6px; color: var(--ink-faint);
  font-size: 13px; line-height: 1;
}
.icon-btn:hover { background: #f1ede8; color: var(--ink); }
.icon-danger:hover { color: var(--red); background: var(--red-soft); }
.text-input {
  width: 100%; padding: 9px 12px; font: inherit; font-size: 14px;
  border: 1px solid var(--line); border-radius: 8px; background: var(--surface);
  color: var(--ink); outline: none;
}
.text-input:focus { border-color: var(--ink-soft); box-shadow: 0 0 0 3px rgba(28,27,26,.06); }
kbd {
  font-family: var(--sans); font-size: 11px; padding: 2px 5px;
  background: var(--surface); border: 1px solid var(--line); border-bottom-width: 2px;
  border-radius: 5px; margin: 0 1px;
}

.toasts { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 100; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast {
  background: var(--ink); color: #fff; font-size: 13.5px; padding: 9px 16px;
  border-radius: 99px; box-shadow: var(--shadow-lg);
  animation: toast-in .18s ease-out;
}
.toast.out { opacity: 0; transition: opacity .3s; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }
.toast-undo {
  font: inherit; font-size: 13px; font-weight: 600; color: #fff;
  background: none; border: none; cursor: pointer;
  margin-left: 10px; padding: 0; text-decoration: underline; text-underline-offset: 2px;
}
.toast-undo:hover { opacity: .8; }
.toast-warn { background: #7c4a02; }
.toast-warn .toast-undo { color: #ffe9c7; }

.overlay {
  position: fixed; inset: 0; background: rgba(28, 27, 26, .35);
  display: flex; align-items: center; justify-content: center; z-index: 50;
  animation: fade-in .12s ease-out; backdrop-filter: blur(2px);
}
@keyframes fade-in { from { opacity: 0; } }
.modal {
  width: min(520px, calc(100vw - 32px)); max-height: 85vh; overflow: auto;
  background: var(--paper); border-radius: 14px; box-shadow: var(--shadow-lg);
  padding: 24px;
}
.modal-sm { width: min(380px, calc(100vw - 32px)); }
.modal h2 { font-size: 19px; }
.modal h3 { font-size: 14px; margin: 18px 0 4px; }
.modal-sub { color: var(--ink-soft); font-size: 13.5px; margin: 0 0 14px; }
.modal-foot { display: flex; justify-content: flex-end; margin-top: 18px; }

.spinner {
  width: 22px; height: 22px; border-radius: 50%; display: inline-block;
  border: 2.5px solid var(--line); border-top-color: var(--ink-soft);
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading { display: flex; justify-content: center; padding: 80px 0; }

.avatar {
  display: inline-flex; align-items: center; justify-content: center;
  width: 22px; height: 22px; border-radius: 50%;
  color: #fff; font-size: 10px; font-weight: 700; letter-spacing: .02em;
  flex: none;
}
.card-spacer { flex: 1; }

/* ---------- doc page layout ---------- */
.page-doc #app { display: flex; flex-direction: column; height: 100dvh; }
#topbar {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 14px; background: rgba(250, 249, 247, .92);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(8px); z-index: 10; flex: none;
}
.logo { display: flex; align-items: center; color: var(--ink); padding: 4px; border-radius: 8px; }
.logo:hover { background: #f1ede8; }
.logo-mark { display: inline-flex; align-items: center; }
.doc-title {
  font: inherit; font-size: 15px; font-weight: 600; color: var(--ink);
  border: 1px solid transparent; background: none; border-radius: 8px;
  padding: 6px 10px; width: min(34vw, 360px); outline: none;
  /* a title too long for the field ends with an ellipsis, not a hard clip */
  text-overflow: ellipsis; white-space: nowrap; overflow: hidden;
}
.doc-title:hover:not(:disabled) { border-color: var(--line); }
.doc-title:focus { border-color: var(--ink-soft); background: var(--surface); text-overflow: clip; }
.doc-title:disabled { color: var(--ink); }
.conn { font-size: 12px; color: var(--ink-faint); }
.conn-off { color: var(--accent); }
.presence { display: flex; align-items: center; margin-right: 4px; }
.avatar-presence { width: 26px; height: 26px; font-size: 11px; border: 2px solid var(--paper); margin-left: -6px; }
.presence-more { font-size: 12px; color: var(--ink-soft); margin-left: 4px; }

.mode-group {
  display: flex; background: #efebe5; border-radius: 9px; padding: 3px; gap: 2px;
}
.mode-btn {
  padding: 5px 12px; border-radius: 7px; font-size: 13px; font-weight: 500;
  color: var(--ink-soft);
}
.mode-btn:hover { color: var(--ink); }
.mode-btn.active { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(28,27,26,.12); }
body[data-mode="suggest"] .mode-btn.active { color: var(--green); }

.tool-btn {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 7px 11px; border-radius: 8px; font-size: 13.5px; font-weight: 500;
  color: var(--ink-soft);
}
.tool-btn:hover { background: #f1ede8; color: var(--ink); }
.tool-btn.active { background: #efebe5; color: var(--ink); }
.btn-share { background: var(--ink); color: #fff; }
.btn-share:hover { background: #000; color: #fff; }
.count-badge { font-size: 11px; font-weight: 700; color: var(--accent); }
.claim-chip {
  display: inline-flex; align-items: center;
  font-size: 12.5px; font-weight: 600; color: var(--accent);
  background: var(--accent-soft); border: 1px solid #f3ceb4;
  padding: 5px 11px; border-radius: 99px; white-space: nowrap;
  cursor: pointer; text-decoration: none;
}
.claim-chip:hover { background: #ffe6d4; }
.claim-chip:disabled { opacity: .6; }

#main { display: flex; flex: 1; min-height: 0; }
#editor-wrap { flex: 1; min-width: 0; overflow-y: auto; position: relative; }
#editor { max-width: 760px; margin: 0 auto; padding: 36px 48px 50vh; }

#panel {
  width: 0; flex: none; border-left: 1px solid transparent; overflow: hidden;
  display: flex; flex-direction: column;
  transition: width .18s ease;
}
body.panel-open #panel { width: 340px; border-left-color: var(--line); }
.panel-head {
  display: flex; align-items: center; gap: 8px;
  padding: 14px 16px 10px; flex: none; min-width: 300px;
}
.panel-title { font-weight: 650; font-size: 14px; }
.panel-counts { font-size: 12px; color: var(--ink-faint); flex: 1; }
.panel-body { overflow-y: auto; padding: 4px 14px 40px; flex: 1; min-width: 300px; }
.panel-empty { text-align: center; color: var(--ink-faint); font-size: 13.5px; padding: 36px 16px; }
.panel-empty-art { font-size: 30px; margin-bottom: 8px; color: var(--ink-faint); }
.kbd-hint { margin-top: 6px; }
/* the ⌘⌥M chord is meaningless without a keyboard — hide it on touch */
@media (pointer: coarse) { .kbd-hint { display: none; } }

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px; margin-bottom: 10px; box-shadow: 0 1px 2px rgba(28,27,26,.04);
  cursor: pointer; transition: border-color .12s, box-shadow .12s;
}
.card:hover { border-color: #d9d3cb; }
.card.active { border-color: var(--ink-soft); box-shadow: var(--shadow); }
.card.resolved { opacity: .7; cursor: default; }
.card-head { display: flex; align-items: center; gap: 7px; margin-bottom: 6px; }
.card-author { font-size: 13px; font-weight: 600; }
.card-time { font-size: 11.5px; color: var(--ink-faint); }
.guest-badge {
  font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em;
  padding: 1px 6px; border-radius: 99px;
  color: var(--ink-faint); border: 1px solid var(--line); background: var(--paper);
}
.card-actions { display: flex; justify-content: flex-end; gap: 6px; margin-top: 9px; }
.quote {
  font-size: 12px; color: var(--ink-soft);
  border-left: 3px solid var(--yellow); padding: 2px 8px; margin-bottom: 7px;
  background: #fdf9ec; border-radius: 0 6px 6px 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.cm-body { font-size: 13.5px; line-height: 1.5; white-space: pre-wrap; overflow-wrap: break-word; }
.reply { margin-top: 9px; padding-top: 9px; border-top: 1px solid var(--line); }
.reply-btn { font-size: 12.5px; color: var(--ink-faint); margin-top: 8px; padding: 0; }
.reply-btn:hover { color: var(--accent); }
.resolved-toggle { font-size: 12.5px; color: var(--ink-faint); margin: 8px 0; display: block; }
.resolved-toggle:hover { color: var(--ink); }
.composer-input {
  width: 100%; font: inherit; font-size: 13.5px; resize: vertical;
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px;
  outline: none; background: var(--paper); margin-top: 2px;
}
.composer-input:focus { border-color: var(--ink-soft); background: var(--surface); }
.composer { cursor: default; border-color: var(--ink-soft); box-shadow: var(--shadow); }

.sg-badge {
  font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
  padding: 2px 7px; border-radius: 99px;
}
.sg-badge-insert { background: var(--green-soft); color: var(--green); }
.sg-badge-delete { background: var(--red-soft); color: var(--red); }
.sg-text { font-family: var(--mono); font-size: 12.5px; line-height: 1.5; overflow-wrap: break-word; }
.sg-text-ins { color: var(--green); }
.sg-text-del { color: var(--red); text-decoration: line-through; }

.comment-bubble {
  position: fixed; z-index: 30;
  width: 34px; height: 34px; border-radius: 50% 50% 50% 6px;
  background: var(--ink); color: #fff; font-size: 15px;
  box-shadow: var(--shadow-lg);
  display: flex; align-items: center; justify-content: center;
  animation: toast-in .15s ease-out;
}
.comment-bubble:hover { background: #000; transform: scale(1.08); }
/* a 34px float is under the 44px touch-target minimum — enlarge on touch, and
   back it with a transparent ≥44px hit-area (::after) so the tappable target is
   a solid 48px even during the toast-in scale animation (measuring the visual
   box mid-animation read ~39×34; the hit-area doesn't animate). */
@media (pointer: coarse) {
  .comment-bubble { width: 44px; height: 44px; font-size: 19px; }
  .comment-bubble::after {
    content: ''; position: absolute; top: 50%; left: 50%;
    width: 48px; height: 48px; transform: translate(-50%, -50%);
  }
}

/* ---------- editor content ---------- */
.cm-editor { outline: none !important; }
.cm-editor .cm-scroller {
  font-family: var(--mono); font-size: 15px; line-height: 1.75;
}
.cm-editor .cm-content { caret-color: var(--ink); }
.cm-editor .cm-line { padding: 0; }
.cm-editor .cm-activeLine { background: rgba(28,27,26,.025); border-radius: 4px; }
/* Selection must survive block-band backgrounds: the drawSelection layer paints
   BEHIND the content, so any opaque .cm-line background hides it — block bands
   below are translucent on purpose, and the selection color is strong. */
.cm-editor .cm-selectionBackground { background: #b9d2f3 !important; }
.cm-editor.cm-focused .cm-selectionBackground { background: #a5c6f0 !important; }
.cm-editor .cm-cursor { border-left-width: 2px; }
.cm-editor .cm-placeholder { color: var(--ink-faint); font-style: italic; }
.cm-editor .md-codeblock { background: rgba(126, 109, 79, .09); font-size: 13.5px; }
.cm-editor .md-blockquote { border-left: 3px solid #ddd6cc; background: rgba(232, 228, 222, .25); }
.cm-editor .md-codeblock.cm-activeLine, .cm-editor .md-blockquote.cm-activeLine { background: rgba(126, 109, 79, .14); }

/* doc ⋯ menu */
.doc-menu {
  position: fixed; z-index: 300; min-width: 200px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
  box-shadow: var(--shadow); padding: 5px; display: flex; flex-direction: column;
}
.doc-menu-item {
  appearance: none; background: none; border: none; cursor: pointer; text-align: left;
  font: inherit; font-size: 13.5px; color: var(--ink); padding: 8px 10px; border-radius: 7px;
}
.doc-menu-item:hover { background: rgba(28,27,26,.05); }

/* Inline components in edit mode: the rendered component sits in the editor
   flow; its markdown chip appears on hover (always for touch via media query) */
.cmp-edit-wrap { position: relative; margin: 6px 0; }
/* Widgets live inside CodeMirror's content, which sets pre-wrap + mono for
   markdown source — reset to document defaults or the component templates'
   literal newlines render as giant blank gaps (Matt's screenshot). */
.cm-editor .cmp-edit-wrap {
  white-space: normal;
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.55;
  overflow-x: auto; /* wide component scrolls inside the (width-capped) wrap, not the editor */
}
/* If a component fence fails to render (e.g. a malformed widget body falls
   through to a <pre><code> block), wrap it instead of clipping off the right
   edge — an unreadable single clipped line was the symptom. */
.cm-editor .cmp-edit-wrap pre,
.cm-editor .cmp-edit-wrap code { white-space: pre-wrap; overflow-wrap: anywhere; }
/* the rendered component fills the capped wrap so its own overflow-x handles
   width — the board's .cmp-board-cols / a wide sheet scroll internally */
.cm-editor .cmp-edit-wrap > div, .cm-editor .cmp-edit-wrap .cmp { max-width: 100%; }
/* The ‹/› source chip normally lives in the component's shared .cmp-toolbar
   (next to ⛶), styled by that toolbar. Only a media line with no .cmp-live
   (class cmp-edit-nobar) keeps it pinned on the wrap. */
.cmp-edit-wrap.cmp-edit-nobar > .cmp-edit-src {
  position: absolute; top: 6px; right: 6px; z-index: 6;
  font: 600 10.5px/1 var(--mono); color: var(--ink-faint);
  background: var(--surface); border: 1px solid var(--line); border-radius: 6px;
  padding: 4px 7px; cursor: pointer; opacity: 0; transition: opacity .12s;
}
.cmp-edit-wrap.cmp-edit-nobar:hover > .cmp-edit-src { opacity: 1; }
/* In the toolbar the chip matches the ⛶ button size/shape (~26px). */
.cmp-toolbar > .cmp-edit-src {
  width: 26px; height: 26px; display: grid; place-items: center;
  font: 600 11px/1 var(--mono); color: var(--ink-soft, #666);
  background: var(--surface, #fff); border: 1px solid var(--line, #e5e5e5);
  border-radius: 7px; cursor: pointer; opacity: .45; transition: opacity .12s;
}
.cmp-live:hover .cmp-toolbar > .cmp-edit-src, .cmp-toolbar > .cmp-edit-src:hover { opacity: 1; }
.cmp-edit-src:hover { color: var(--ink); border-color: var(--ink-faint); }
/* A sheet has its OWN top-right controls (add/del column, z:7). Shift the
   shared toolbar left of that column so the toolbar buttons AND the sheet
   controls are both clickable (positioning only — doesn't fight the z-order). */
.cmp-sheet > .cmp-toolbar { right: 52px; }
.cmp-edit-render {
  font: 600 10.5px/1 var(--mono); color: var(--ink-soft);
  background: var(--surface); border: 1px solid var(--line); border-radius: 6px;
  padding: 2px 7px; margin-left: 10px; cursor: pointer; vertical-align: middle;
}
.cmp-edit-render:hover { color: var(--ink); border-color: var(--ink-faint); }

/* Find results need to read at a glance: amber for every match, hot orange for
   the current one, soft amber for select-a-word twins (highlightSelectionMatches). */
.cm-editor .cm-searchMatch { background: #ffdf82; outline: 1px solid rgba(178, 134, 14, .5); border-radius: 2px; }
.cm-editor .cm-searchMatch.cm-searchMatch-selected { background: #ffAB4d; outline-color: #d97706; }
.cm-editor .cm-selectionMatch { background: rgba(255, 223, 130, .45); border-radius: 2px; }

.md-h1 { font-size: 1.7em; font-weight: 750; line-height: 1.3; }
.md-h2 { font-size: 1.4em; font-weight: 700; line-height: 1.35; }
.md-h3 { font-size: 1.2em; font-weight: 650; }
.md-h4 { font-size: 1.05em; font-weight: 650; }
.md-strong { font-weight: 700; }
.md-em { font-style: italic; }
.md-strike { text-decoration: line-through; color: var(--ink-soft); }
.md-link { color: var(--accent); }
.md-url { color: var(--ink-faint); }
.md-code { background: #f1ede8; border-radius: 4px; padding: 1px 0; }
.md-quote { color: var(--ink-soft); font-style: italic; }
.md-meta, .md-comment { color: var(--ink-faint); }
.md-list { color: var(--accent); }
.tok-keyword { color: #7c3aed; }
.tok-string { color: var(--green); }
.tok-number { color: #b45309; }
.tok-type { color: #0b7285; }
.tok-fn { color: #1971c2; }

.sg-ins { background: var(--green-soft); text-decoration: underline; text-decoration-color: var(--green); text-underline-offset: 3px; }
.sg-del { background: var(--red-soft); text-decoration: line-through; text-decoration-color: var(--red); }
.cm-hl { background: var(--yellow-soft); border-bottom: 2px solid var(--yellow); cursor: pointer; }
.mark-active.cm-hl { background: #fce588; }
.mark-active.sg-ins { background: #c9ecd2; }
.mark-active.sg-del { background: #fbd3d3; }
.flash-hl { border-radius: 2px; animation: flash-fade 1.1s ease-out; }
@keyframes flash-fade { from { background: var(--yellow); } to { background: transparent; } }
.card-shake { animation: card-shake .35s ease-in-out; }
@keyframes card-shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

/* y-codemirror remote cursors */
.cm-ySelectionInfo { font-family: var(--sans) !important; font-size: 10.5px !important; padding: 2px 5px !important; border-radius: 4px !important; opacity: 1 !important; }

/* ---------- preview ---------- */
#preview { display: none; }
body.preview-on #editor { display: none; }
body.preview-on #preview { display: block; }
.prose { max-width: 720px; margin: 0 auto; padding: 40px 48px 30vh; font-size: 16.5px; line-height: 1.75; overflow-wrap: anywhere; }
.prose h1 { font-size: 2em; margin: 1em 0 .4em; }
.prose h2 { font-size: 1.5em; margin: 1.4em 0 .4em; }
.prose h3 { font-size: 1.2em; margin: 1.2em 0 .3em; }
.prose p { margin: .65em 0; }
.prose pre { background: #f4f1ec; border: 1px solid var(--line); border-radius: 8px; padding: 14px; overflow-x: auto; font-size: 13.5px; line-height: 1.6; }
.prose code { font-family: var(--mono); font-size: .88em; background: #f1ede8; padding: 2px 5px; border-radius: 4px; }
.prose pre code { background: none; padding: 0; }
.prose blockquote { border-left: 3px solid var(--line); margin: 1em 0; padding: 2px 18px; color: var(--ink-soft); }
.prose img { max-width: 100%; border-radius: 8px; }
.prose table { border-collapse: collapse; width: 100%; }
.prose th, .prose td { border: 1px solid var(--line); padding: 7px 11px; text-align: left; }
.prose th { background: #f4f1ec; }
.prose hr { border: none; border-top: 1px solid var(--line); margin: 2em 0; }
.prose li.task-list-item { list-style: none; margin-left: -1.4em; }
.prose li.task-list-item .task-checkbox { margin: 0 .5em 0 0; vertical-align: middle; }

/* ---------- history drawer ---------- */
.drawer {
  width: min(980px, calc(100vw - 32px)); height: min(640px, calc(100dvh - 64px));
  background: var(--paper); border-radius: 14px; box-shadow: var(--shadow-lg);
  display: flex; flex-direction: column; overflow: hidden;
}
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px 10px; }
.drawer-cols { display: flex; flex: 1; min-height: 0; border-top: 1px solid var(--line); }
.drawer-list { width: 240px; flex: none; overflow-y: auto; border-right: 1px solid var(--line); padding: 8px; }
.drawer-detail { flex: 1; overflow-y: auto; padding: 14px 20px; }
.drawer-hint { color: var(--ink-faint); font-size: 13.5px; }
.rev-day {
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em;
  color: var(--ink-faint); padding: 12px 11px 4px;
}
.rev-item {
  display: block; width: 100%; text-align: left; padding: 9px 11px;
  border-radius: 8px; margin-bottom: 2px;
}
.rev-item:hover { background: #f1ede8; }
.rev-item.active { background: var(--surface); box-shadow: var(--shadow); }
.rev-time { font-size: 13.5px; font-weight: 600; }
.rev-meta { font-size: 12px; color: var(--ink-faint); margin-top: 1px; }
.rev-actions { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.diff { font-family: var(--mono); font-size: 13px; line-height: 1.6; white-space: pre-wrap; overflow-wrap: break-word; }
.diff > div { padding: 2px 10px; border-radius: 4px; }
.diff-del { background: var(--red-soft); color: #8c1f1f; }
.diff-ins { background: var(--green-soft); color: #1e5e2e; }
.diff-ctx { color: var(--ink-faint); }
.diff mark.dw-del { background: #f6b3b3; color: inherit; border-radius: 3px; text-decoration: line-through; }
.diff mark.dw-ins { background: #a9dfb6; color: inherit; border-radius: 3px; }

/* ---------- share dialog ---------- */
.share-row { display: flex; align-items: center; gap: 10px; padding: 11px 0; border-bottom: 1px solid var(--line); }
.share-row:last-of-type { border-bottom: none; }
.share-info { display: flex; flex-direction: column; gap: 1px; font-size: 14px; }
.share-desc { font-size: 12px; color: var(--ink-faint); }
.share-actions { display: flex; gap: 6px; }
.token-row { display: flex; align-items: center; gap: 8px; }
.token-field {
  font-family: var(--mono); font-size: 12px; background: var(--surface);
  border: 1px solid var(--line); border-radius: 7px; padding: 7px 10px;
  overflow-x: auto; white-space: nowrap; flex: 1;
}
.agent-name-input {
  font: inherit; font-size: 14px; background: var(--surface); color: var(--ink);
  border: 1px solid var(--line); border-radius: 7px; padding: 8px 10px; flex: 1;
}
.agent-name-input:focus { outline: none; border-color: var(--ink-soft); }
.cli-block {
  font-family: var(--mono); font-size: 12px; background: #211f1d; color: #e8e4de;
  border-radius: 8px; padding: 12px 14px; overflow-x: auto; margin: 6px 0 10px;
}
/* the "needs you" inbox strip */
.needs-you { border: 1px solid color-mix(in srgb, #e8590c 35%, transparent); background: color-mix(in srgb, #e8590c 5%, transparent); border-radius: 12px; padding: 14px 16px; margin-bottom: 22px; }
.needs-you-head { display: flex; align-items: center; gap: 9px; margin-bottom: 8px; }
.needs-you-head h2 { margin: 0; font-size: 15px; }
.needs-you-badge { background: #d9480f; color: #fff; font-size: 12px; font-weight: 700; min-width: 20px; height: 20px; border-radius: 999px; display: inline-flex; align-items: center; justify-content: center; padding: 0 6px; }
.needs-row { display: flex; align-items: baseline; gap: 9px; padding: 7px 8px; border-radius: 8px; text-decoration: none; color: inherit; font-size: 13.5px; }
.needs-row:hover { background: color-mix(in srgb, #e8590c 9%, transparent); }
.needs-dot { flex: none; }
.needs-title { font-weight: 600; white-space: nowrap; }
.needs-msg { color: var(--ink-soft, #777); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* onboarding activation modal */
.onboard-modal { max-width: 560px; position: relative; }
.onboard-close { position: absolute; top: 12px; right: 12px; }
.onboard-step { margin: 14px 0; }
.onboard-step-label { font-size: 12px; font-weight: 600; color: var(--ink-3, #999); margin-bottom: 4px; letter-spacing: .02em; }
.onboard-prompt { white-space: pre-wrap; word-break: break-word; max-height: 40vh; }

/* ---------- gates ---------- */
.gate { display: flex; align-items: center; justify-content: center; min-height: 100dvh; padding: 20px; }
.gate-card {
  text-align: center; background: var(--surface); border: 1px solid var(--line);
  border-radius: 16px; padding: 44px 40px; max-width: 420px; box-shadow: var(--shadow);
}
.gate-card h1 { font-size: 22px; margin: 14px 0 6px; }
.gate-card p { color: var(--ink-soft); font-size: 14.5px; margin: 0 0 18px; }

/* ---------- dashboard ---------- */
.bar { display: flex; align-items: center; gap: 10px; padding: 14px 28px; }
.wordmark { font-weight: 750; font-size: 17px; letter-spacing: -.02em; }
.wordmark-xl { font-size: 26px; }
.logo-lg { display: inline-flex; }
.dash { max-width: 1060px; margin: 0 auto; padding: 18px 28px 80px; }
.dash-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 22px; }
.dash-head h1 { font-size: 26px; }
/* "+ New document" split button: main = blank, caret = start from a template */
.newdoc-wrap { position: relative; display: inline-flex; align-self: center; }
.newdoc-main { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.newdoc-caret { border-top-left-radius: 0; border-bottom-left-radius: 0; border-left: 1px solid rgba(255,255,255,.25); padding: 0 9px; font-size: 11px; }
.newdoc-menu {
  position: absolute; top: calc(100% + 6px); right: 0; z-index: 40; min-width: 240px; max-width: 320px;
  max-height: 60vh; overflow-y: auto; padding: 6px;
  background: var(--surface, #fff); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow-lg);
}
.newdoc-item {
  display: flex; align-items: center; gap: 9px; width: 100%; box-sizing: border-box;
  padding: 9px 10px; border: 0; border-radius: 8px; background: none; cursor: pointer;
  font: inherit; font-size: 14px; color: var(--ink); text-align: left; text-decoration: none;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.newdoc-item:hover { background: var(--wash, #f4f4f2); }
.newdoc-tpl-icon { color: var(--accent, #c2410c); flex: none; }
.newdoc-muted { color: var(--ink-soft, #666); }
.newdoc-label { padding: 8px 10px 4px; font-size: 11px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--ink-3, #999); }
.newdoc-sep { height: 1px; margin: 6px 4px; background: var(--line); }
.doc-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }
.doc-card {
  display: flex; flex-direction: column; gap: 8px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  padding: 18px; color: var(--ink); min-height: 130px;
  transition: border-color .12s, box-shadow .12s, transform .1s;
}
.doc-card:hover { border-color: #d9d3cb; box-shadow: var(--shadow); transform: translateY(-1px); }
.doc-card-title { font-weight: 650; font-size: 15.5px; }
.doc-card-excerpt { font-size: 13px; color: var(--ink-soft); line-height: 1.5; flex: 1;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.doc-card-foot { display: flex; align-items: center; justify-content: space-between; font-size: 12px; color: var(--ink-faint); }
/* Dashboard tabs: My docs / Shared with me / Opened. Hidden entirely when
   only "My docs" has anything in it. */
.dash-tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 20px; }
.dash-tab {
  appearance: none; background: none; border: none; cursor: pointer;
  font: inherit; font-size: 14px; font-weight: 600; color: var(--ink-soft);
  padding: 8px 12px 10px; border-bottom: 2px solid transparent; margin-bottom: -1px;
  display: inline-flex; align-items: center; gap: 6px;
}
.dash-tab:hover { color: var(--ink); }
.dash-tab.active { color: var(--ink); border-bottom-color: var(--ink); }
.dash-tab-count {
  font-size: 11px; font-weight: 650; color: var(--ink-soft);
  background: #f1ede8; border-radius: 999px; padding: 1px 7px;
}
.role-tag {
  font-size: 11px; font-weight: 600; color: var(--ink-soft);
  background: #f1ede8; border-radius: 999px; padding: 2px 8px; margin-right: 4px;
}
.dash-empty { text-align: center; padding: 90px 0; color: var(--ink-soft); }
.dash-empty p { margin: 0 0 16px; }

/* ---------- landing ---------- */
.landing {
  min-height: 100dvh; display: flex; align-items: center; justify-content: center;
  gap: 70px; padding: 40px; flex-wrap: wrap;
}
.landing-hero { max-width: 520px; }
.wordmark-row { display: flex; align-items: center; gap: 10px; margin-bottom: 34px; }
.landing h1 { font-size: 46px; line-height: 1.08; letter-spacing: -.03em; margin-bottom: 16px; }
.landing-sub { font-size: 16.5px; line-height: 1.65; color: var(--ink-soft); margin: 0 0 24px; }
.landing-cta-row { display: flex; align-items: center; gap: 14px; margin: 0 0 26px; flex-wrap: wrap; }
.btn-lg { padding: 12px 22px; font-size: 15.5px; border-radius: 10px; }
.landing-cta-note { font-size: 13px; color: var(--ink-faint); max-width: 220px; line-height: 1.4; }
.landing-points { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 12px; }
.landing-points li { font-size: 14.5px; line-height: 1.55; color: var(--ink-soft); padding-left: 22px; position: relative; }
.landing-points li::before { content: '❧'; position: absolute; left: 0; color: var(--accent); }
.landing-points strong { color: var(--ink); }
.landing-points code { font-family: var(--mono); font-size: .9em; background: #f1ede8; padding: 2px 5px; border-radius: 4px; }
.auth-card {
  width: 360px; background: var(--surface); border: 1px solid var(--line);
  border-radius: 16px; padding: 26px; box-shadow: var(--shadow);
}
.auth-tabs { display: flex; background: #efebe5; border-radius: 9px; padding: 3px; gap: 2px; margin-bottom: 18px; }
.auth-tab { flex: 1; padding: 7px; border-radius: 7px; font-size: 13.5px; font-weight: 550; color: var(--ink-soft); }
.auth-tab.active { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(28,27,26,.12); }
.auth-card label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 12px; }
.auth-card .text-input { margin-top: 5px; }
.auth-err { color: var(--red); font-size: 13px; min-height: 18px; margin-bottom: 8px; }
.auth-divider {
  display: flex; align-items: center; gap: 10px; margin: 14px 0;
  color: var(--ink-faint); font-size: 12.5px;
}
.auth-divider::before, .auth-divider::after { content: ''; flex: 1; height: 1px; background: var(--line); }
.btn-google { gap: 9px; background: #fff; }
.btn-google:hover { background: #f8f7f5; }

/* ---------- landing: scroll sections ---------- */
.page-landing .landing { min-height: 92dvh; }
.ld-section { max-width: 1060px; margin: 0 auto; padding: 76px 32px; border-top: 1px solid var(--line); }
.ld-kicker { font-size: 12.5px; font-weight: 650; letter-spacing: .09em; text-transform: uppercase; color: var(--accent); margin-bottom: 10px; }
.ld-section h2 { font-size: 30px; letter-spacing: -.025em; text-wrap: balance; }
.ld-sub { font-size: 15.5px; line-height: 1.65; color: var(--ink-soft); max-width: 64ch; margin: 0 0 36px; }
.ld-sub strong { color: var(--ink); }

/* demo doc */
.ld-demo { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); overflow: hidden; }
.ld-demo-top { display: flex; align-items: center; gap: 10px; padding: 11px 16px; border-bottom: 1px solid var(--line); font-size: 13px; color: var(--ink-soft); }
.ld-doc-name { font-weight: 650; color: var(--ink); }
.ld-presence { display: flex; margin-left: auto; }
.ld-avatar { width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; font-size: 10.5px; font-weight: 700; color: #fff; border: 2px solid var(--surface); margin-left: -6px; }
.ld-presence-label { font-size: 12px; color: var(--ink-faint); margin-left: 10px; }
.ld-demo-body { display: grid; grid-template-columns: 1.15fr .85fr; }
.ld-demo-main { padding: 20px 22px; border-right: 1px solid var(--line); }
.ld-demo-side { padding: 20px 22px; background: var(--paper); }
.ld-demo-h { font-size: 12px; font-weight: 700; letter-spacing: .07em; text-transform: uppercase; color: var(--ink-faint); margin-bottom: 12px; }
.ld-board { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.ld-col-title { font-size: 11.5px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--ink-faint); margin-bottom: 8px; }
.ld-card { background: var(--surface); border: 1px solid var(--line); border-radius: 9px; padding: 9px 11px; font-size: 13px; line-height: 1.45; margin-bottom: 8px; box-shadow: 0 1px 2px rgba(28,27,26,.04); }
.ld-card.ld-doing { border-left: 3px solid var(--accent); }
.ld-meta { display: flex; gap: 6px; margin-top: 6px; flex-wrap: wrap; align-items: center; }
.ld-chip { font-size: 10.5px; font-weight: 600; padding: 2px 7px; border-radius: 20px; background: #f1ede8; color: var(--ink-soft); }
.ld-chip.ld-assignee { background: var(--accent-soft); color: var(--accent); }
.ld-chip.ld-done { background: var(--green-soft); color: var(--green); }
.ld-byline { font-size: 10.5px; color: var(--ink-faint); }
.ld-caret { display: inline-block; width: 2px; height: 1em; background: var(--accent); vertical-align: text-bottom; margin-left: 1px; animation: ld-blink 1s steps(1) infinite; }
@keyframes ld-blink { 50% { opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .ld-caret { animation: none; } }
.ld-chat-line { display: flex; gap: 9px; margin-bottom: 12px; font-size: 13px; line-height: 1.5; }
.ld-chat-line .ld-avatar { width: 22px; height: 22px; margin: 1px 0 0; border: none; flex: none; }
.ld-chat-who { font-weight: 650; font-size: 12.5px; }
.ld-tag { font-size: 9.5px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; background: var(--accent-soft); color: var(--accent); padding: 1px 5px; border-radius: 4px; margin-left: 5px; vertical-align: 1px; }
.ld-chat-msg { color: var(--ink-soft); }
.ld-caption { text-align: center; font-size: 13.5px; color: var(--ink-faint); margin-top: 18px; line-height: 1.6; }
.ld-caption strong { color: var(--ink-soft); font-weight: 600; }

/* use cases */
.ld-use-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; }
.ld-use-card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 24px; transition: box-shadow .12s, transform .1s; }
.ld-use-card:hover { box-shadow: var(--shadow); transform: translateY(-1px); }
.ld-use-icon { width: 38px; height: 38px; border-radius: 10px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; margin-bottom: 14px; }
.ld-use-card h3 { font-size: 17px; margin-bottom: 6px; }
.ld-use-card p { margin: 0; font-size: 14px; line-height: 1.6; color: var(--ink-soft); }

/* why it works + editor features */
.ld-why-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 8px 44px; }
.ld-why-item { padding: 14px 0 14px 24px; position: relative; font-size: 14.5px; line-height: 1.6; color: var(--ink-soft); }
.ld-why-item::before { content: '❧'; position: absolute; left: 0; top: 14px; color: var(--accent); }
.ld-why-item strong { color: var(--ink); }
.ld-human-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 4px 40px; margin: 0; padding: 0; }
.ld-human-grid li { list-style: none; font-size: 14.5px; line-height: 1.55; color: var(--ink-soft); padding: 10px 0 10px 22px; position: relative; }
.ld-human-grid li::before { content: '❧'; position: absolute; left: 0; color: var(--accent); }
.ld-human-grid strong { color: var(--ink); }

/* footer cta */
.ld-foot { text-align: center; padding: 88px 32px 100px; border-top: 1px solid var(--line); }
.ld-foot h2 { font-size: 34px; letter-spacing: -.03em; }
.ld-foot h2 em { font-style: normal; color: var(--accent); }
.ld-foot p { color: var(--ink-soft); font-size: 15.5px; margin: 0 0 28px; }
.ld-fine { display: block; margin-top: 30px; font-size: 13px; color: var(--ink-faint); }
.ld-fine code { font-family: var(--mono); font-size: .95em; background: #f1ede8; padding: 2px 5px; border-radius: 4px; }

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  #editor { padding: 24px 20px 40vh; }
  .doc-title { width: 30vw; }
  body.panel-open #panel {
    position: fixed; right: 0; top: 49px; bottom: 0; width: min(340px, 88vw);
    background: var(--paper); box-shadow: var(--shadow-lg); z-index: 20;
  }
  .tool-btn { padding: 7px 8px; }
}
@media (max-width: 700px) {
  /* Two tidy rows, never three: row 1 = logo + title + preview + ⋯ (essentials
     pinned right), row 2 = the tool cluster. The spacer forces exactly one break. */
  #topbar { flex-wrap: wrap; row-gap: 6px; column-gap: 6px; padding: 8px 10px; }
  .doc-title { width: auto; flex: 1; min-width: 80px; order: 1; }
  .logo { order: 0; }
  /* Insert + History fold into the ⋯ menu on phones; the rest fits one row. */
  #insert-btn, #history-btn, .conn { display: none; }
  #preview-btn, #panel-btn, #doc-menu-btn { order: 2; }
  #topbar .card-spacer { flex-basis: 100%; height: 0; order: 3; margin: 0; }
  .presence, .mode-group, .claim-chip { order: 4; }
  .tool-btn { font-size: 12.5px; padding: 6px 9px; min-height: 34px; }
  .mode-btn { padding: 5px 11px; font-size: 12.5px; }
  .claim-chip { font-size: 12px; padding: 5px 9px; }
  body.panel-open #panel {
    left: 0; right: 0; width: 100vw; top: auto; height: 72dvh;
    border-radius: 14px 14px 0 0; border-top: 1px solid var(--line);
  }
  .landing { gap: 30px; padding: 28px 20px; }
  .landing h1 { font-size: 34px; }
  .auth-card { width: 100%; max-width: 380px; }
  .ld-section { padding: 56px 20px; }
  .ld-demo-body { grid-template-columns: 1fr; }
  .ld-demo-main { border-right: none; border-bottom: 1px solid var(--line); }
  .ld-foot { padding: 64px 20px 76px; }
}

/* first-visit intro */
.intro-modal { width: min(480px, calc(100vw - 32px)); }
.intro-row { display: flex; gap: 14px; padding: 12px 0; border-top: 1px solid var(--line); align-items: flex-start; }
.intro-row:first-of-type { border-top: 0; }
.intro-icon { flex: none; width: 34px; height: 34px; border-radius: 9px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; }
.intro-icon svg { width: 18px; height: 18px; }
.intro-row-title { font-weight: 600; font-size: 14px; }
.intro-row-body { color: var(--ink-soft); font-size: 13px; line-height: 1.5; margin-top: 2px; }
.intro-foot { justify-content: space-between; align-items: center; }
.intro-link { color: var(--ink-soft); font-size: 13px; text-decoration: none; }
.intro-link:hover { color: var(--ink); }
.intro-fine { color: var(--ink-faint); font-size: 12px; margin: 12px 0 0; text-align: center; }

/* publish row in the share dialog */
.share-publish {
  display: flex; align-items: center; gap: 12px;
  background: var(--accent-soft); border: 1px solid #f3d9c6;
  border-radius: var(--radius); padding: 12px 14px; margin: 4px 0 14px;
}
.publish-icon {
  flex: none; width: 34px; height: 34px; border-radius: 9px;
  background: var(--accent); color: #fff; display: grid; place-items: center;
}
.publish-icon svg { width: 19px; height: 19px; }

/* an API/agent editor present in the doc — pulsing ring so live edits by
   agents are noticed while they happen, not discovered afterwards */
.avatar-agent { position: relative; }
.avatar-agent::after {
  content: ''; position: absolute; inset: -3px; border-radius: 50%;
  border: 2px solid var(--accent); animation: agent-pulse 1.6s ease-out infinite;
}
@keyframes agent-pulse {
  0% { opacity: 0.9; transform: scale(0.85); }
  100% { opacity: 0; transform: scale(1.35); }
}
@media (prefers-reduced-motion: reduce) { .avatar-agent::after { animation: none; opacity: 0.7; } }

/* insert-component menu */
.insert-menu { position: fixed; z-index: 60; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow-lg); padding: 6px; width: 280px; display: flex; flex-direction: column; gap: 2px; }
.slash-menu { max-height: 320px; overflow-y: auto; }
.slash-menu .insert-item.sel { background: var(--hover, rgba(127,127,127,.12)); }
.insert-item { display: flex; align-items: center; gap: 11px; width: 100%; padding: 8px 10px; border: 0; background: none; border-radius: 8px; cursor: pointer; text-align: left; font: inherit; }
.insert-item:hover { background: var(--paper); }
.insert-ico { flex: none; width: 30px; height: 30px; border-radius: 8px; background: var(--accent-soft); display: grid; place-items: center; font-size: 15px; }
.insert-label { font-size: 13.5px; font-weight: 600; color: var(--ink); }
.insert-desc { font-size: 12px; color: var(--ink-soft); margin-top: 1px; }

/* slash /link doc picker */
.doc-pick-list { display: flex; flex-direction: column; gap: 2px; margin-top: 12px; max-height: 300px; overflow-y: auto; }
.doc-pick-item { display: flex; align-items: center; gap: 8px; text-align: left; border: 0; background: none; padding: 9px 10px; border-radius: 8px; cursor: pointer; font: inherit; color: inherit; }
.doc-pick-item:hover { background: var(--hover, rgba(127,127,127,.1)); }
.doc-pick-title { flex: 1; font-size: 14.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.auth-forgot { background: none; border: 0; color: var(--ink-soft, #777); font: inherit; font-size: 13px; text-decoration: underline; cursor: pointer; margin-top: 10px; padding: 0; }
.verified-tag { color: #2b8a3e; font-weight: 600; font-size: 12px; }
.notify-toggle { display: flex; align-items: center; gap: 8px; font-size: 14px; }

/* onboarding v2 */
.onboard-live { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--ink-soft, #777); margin: 10px 0; }
.onboard-live-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ink-faint, #bbb); animation: onboard-pulse 1.4s infinite; }
.onboard-live.arrived { color: #2b8a3e; font-weight: 600; }
.onboard-live.arrived .onboard-live-dot { background: #2b8a3e; animation: none; }
@keyframes onboard-pulse { 0%,100% { opacity: .3 } 50% { opacity: 1 } }
.onboard-fallback { margin: 6px 0; font-size: 13px; }
.onboard-fallback summary { cursor: pointer; color: var(--ink-soft, #777); }
