/* Quest Note — Notion-style workspace (QN.6). Design tokens first; everything else uses them. */
:root {
  --paper: #ffffff; --side: #f7f6f3; --ink: #2f2e2b; --ink-2: #6f6e69; --ink-3: #a19f99;
  --rule: #ebeae6; --rule-2: #dcdbd6; --hover: rgba(47, 46, 43, .055); --active: rgba(47, 46, 43, .09);
  --accent: #2b63c6; --accent-soft: rgba(43, 99, 198, .12); --mark: rgba(255, 212, 0, .38);
  --ok: #2f8a5b; --warn: #b7791f; --bad: #c9372c; --bad-soft: rgba(201, 55, 44, .1);
  --code-bg: #f6f5f2; --code-ink: #c0392b; --chip: #efeeea; --th: #f7f6f3; --menu: #ffffff;
  --shadow: 0 0 0 1px rgba(15, 15, 15, .05), 0 3px 6px rgba(15, 15, 15, .08), 0 9px 24px rgba(15, 15, 15, .12);
  --sans: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI Variable Text", "Segoe UI", Helvetica, Arial, sans-serif;
  --serif: "Iowan Old Style", Charter, "Bitstream Charter", ui-serif, Georgia, Cambria, "Times New Roman", serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
  --side-w: 248px; --page-w: 708px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #191919; --side: #202020; --ink: #e6e5e2; --ink-2: #a3a29e; --ink-3: #6d6c68;
    --rule: #2c2c2b; --rule-2: #3a3a38; --hover: rgba(255, 255, 255, .055); --active: rgba(255, 255, 255, .09);
    --accent: #6b9cf0; --accent-soft: rgba(107, 156, 240, .16); --mark: rgba(255, 212, 0, .28);
    --ok: #4fb383; --warn: #d9a441; --bad: #ef6b5e; --bad-soft: rgba(239, 107, 94, .14);
    --code-bg: #242423; --code-ink: #ff8c7f; --chip: #2c2c2b; --th: #222221; --menu: #252525;
    --shadow: 0 0 0 1px rgba(255, 255, 255, .06), 0 3px 6px rgba(0, 0, 0, .35), 0 9px 24px rgba(0, 0, 0, .45);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #191919; --side: #202020; --ink: #e6e5e2; --ink-2: #a3a29e; --ink-3: #6d6c68;
  --rule: #2c2c2b; --rule-2: #3a3a38; --hover: rgba(255, 255, 255, .055); --active: rgba(255, 255, 255, .09);
  --accent: #6b9cf0; --accent-soft: rgba(107, 156, 240, .16); --mark: rgba(255, 212, 0, .28);
  --ok: #4fb383; --warn: #d9a441; --bad: #ef6b5e; --bad-soft: rgba(239, 107, 94, .14);
  --code-bg: #242423; --code-ink: #ff8c7f; --chip: #2c2c2b; --th: #222221; --menu: #252525;
  --shadow: 0 0 0 1px rgba(255, 255, 255, .06), 0 3px 6px rgba(0, 0, 0, .35), 0 9px 24px rgba(0, 0, 0, .45);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--paper); color: var(--ink); font: 14px/1.5 var(--sans); -webkit-font-smoothing: antialiased; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
::selection { background: var(--accent-soft); }
kbd { font: 500 11px var(--sans); color: var(--ink-3); border: 1px solid var(--rule-2); border-radius: 4px; padding: 0 4px; }
svg.i { width: 16px; height: 16px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
[hidden] { display: none !important; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* ---------- shared controls ---------- */
.mark { width: 24px; height: 24px; border-radius: 6px; background: var(--ink); color: var(--paper); display: grid; place-items: center;
  font: 700 14px/1 var(--serif); flex: none; }
.mark.big { width: 44px; height: 44px; border-radius: 11px; font-size: 26px; }
.btn-solid { display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 14px; border-radius: 6px;
  background: var(--ink); color: var(--paper); font-weight: 500; }
.btn-solid:hover { opacity: .88; }
.btn-solid.wide { width: 100%; justify-content: center; height: 38px; }
.btn-quiet { height: 28px; padding: 0 10px; border-radius: 6px; color: var(--ink-2); font-weight: 500; }
.btn-quiet:hover { background: var(--hover); color: var(--ink); }
.icon-btn { width: 28px; height: 28px; display: inline-grid; place-items: center; border-radius: 6px; color: var(--ink-2); }
.icon-btn:hover { background: var(--hover); color: var(--ink); }
.link-btn { color: var(--ink-2); font-weight: 500; text-decoration: underline; text-underline-offset: 3px; text-decoration-color: var(--rule-2); }
.link-btn:hover { color: var(--ink); }
.danger { color: var(--bad) !important; }
[data-tip] { position: relative; }
[data-tip]:hover::after { content: attr(data-tip); position: absolute; top: calc(100% + 6px); right: 0; white-space: nowrap; z-index: 50;
  background: var(--ink); color: var(--paper); font-size: 12px; padding: 3px 8px; border-radius: 5px; pointer-events: none; }

/* ---------- layout ---------- */
.app { display: grid; grid-template-columns: var(--side-w) 1fr; height: 100vh; }
.sidebar { background: var(--side); display: flex; flex-direction: column; min-height: 0; border-right: 1px solid var(--rule); }
main { overflow-y: auto; min-width: 0; position: relative; }
.scrim { display: none; }

.ws { display: flex; align-items: center; gap: 10px; padding: 14px 14px 10px; }
.ws-name { font-weight: 600; }
.ws-user { font-size: 12px; color: var(--ink-2); min-height: 16px; }
.search { display: flex; align-items: center; gap: 8px; margin: 2px 8px 2px; padding: 0 8px; height: 30px; border-radius: 6px;
  color: var(--ink-3); background: var(--hover); }
.search:focus-within { background: var(--paper); box-shadow: 0 0 0 1px var(--rule-2); }
.search input { flex: 1; min-width: 0; border: 0; background: none; outline: none; color: var(--ink); }
.search input::-webkit-search-cancel-button { display: none; }
.side-row { display: flex; align-items: center; gap: 8px; width: 100%; height: 30px; padding: 0 10px; border-radius: 6px; color: var(--ink-2);
  text-decoration: none; text-align: left; }
.side-row:hover { background: var(--hover); color: var(--ink); }
#newBtn { margin: 4px 8px 0; width: auto; }
.side-row.strong { color: var(--ink); font-weight: 500; }
.side-head { display: flex; align-items: center; gap: 8px; padding: 14px 18px 4px; font-size: 12px; font-weight: 600; color: var(--ink-3); }
.side-head select { margin-left: auto; border: 0; background: none; color: var(--ink-2); font-size: 12px; max-width: 130px; cursor: pointer; }
.list { flex: 1; overflow-y: auto; padding: 0 8px 12px; }
.group { font-size: 12px; font-weight: 600; color: var(--ink-3); margin: 14px 10px 4px; }
.item { display: block; width: 100%; text-align: left; padding: 5px 10px; border-radius: 6px; color: var(--ink-2); }
.item:hover { background: var(--hover); color: var(--ink); }
.item.active { background: var(--active); color: var(--ink); }
.item .t { display: block; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .m { display: flex; gap: 6px; margin-top: 1px; font-size: 12px; color: var(--ink-3); white-space: nowrap; overflow: hidden; }
.item .snip { display: block; margin-top: 2px; font-size: 12px; line-height: 1.45; color: var(--ink-2);
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.item mark { background: var(--mark); color: inherit; border-radius: 2px; padding: 0 1px; }
.empty { color: var(--ink-3); padding: 14px 10px; font-size: 13px; }

.side-foot { padding: 8px; border-top: 1px solid var(--rule); display: grid; gap: 2px; }
.backup { display: flex; align-items: center; flex-wrap: wrap; gap: 4px 8px; padding: 6px 10px 8px; font-size: 12.5px; color: var(--ink-2); }
.backup-text { flex: 1; min-width: 0; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ink-3); flex: none; }
.dot.ok { background: var(--ok); } .dot.due { background: var(--warn); } .dot.bad { background: var(--bad); }
.foot-row { display: flex; align-items: center; gap: 2px; }

/* ---------- top bar & banners ---------- */
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 4px; height: 44px; padding: 0 12px 0 16px;
  background: color-mix(in srgb, var(--paper) 90%, transparent); backdrop-filter: blur(8px); }
.crumbs { display: flex; align-items: center; gap: 6px; min-width: 0; color: var(--ink-2); }
.crumbs span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.crumbs .cur { color: var(--ink); }
.crumbs .sl { color: var(--ink-3); }
.spacer { flex: 1; }
.save-state { font-size: 12.5px; color: var(--ink-3); margin-right: 6px; white-space: nowrap; }
.save-state.bad { color: var(--bad); }
.actions { display: flex; gap: 2px; }
.only-narrow { display: none; }
.conflict { position: sticky; top: 44px; z-index: 19; display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  margin: 0 auto; max-width: calc(var(--page-w) + 96px); padding: 10px 14px; border-radius: 8px;
  background: var(--bad-soft); color: var(--ink); font-size: 13.5px; }

/* ---------- welcome ---------- */
.welcome { max-width: 520px; margin: 18vh auto 0; padding: 0 24px; }
.welcome h1 { font: 700 30px/1.2 var(--sans); letter-spacing: -.02em; margin: 18px 0 8px; }
.welcome p { color: var(--ink-2); font-size: 15px; margin: 0 0 22px; }

/* ---------- the page ---------- */
.doc { max-width: calc(var(--page-w) + 96px); margin: 0 auto; padding: 56px 48px 30vh; }
.doc.font-sans { --page-font: var(--sans); }
.doc.font-serif { --page-font: var(--serif); }
.doc.font-mono { --page-font: var(--mono); }
.title { width: 100%; border: 0; outline: none; background: none; padding: 0; margin: 0 0 14px;
  font: 700 40px/1.15 var(--page-font); letter-spacing: -.022em; color: var(--ink); }
.font-serif .title { font-weight: 600; letter-spacing: -.012em; font-size: 42px; }
.font-mono .title { font-size: 34px; letter-spacing: -.01em; }
.title::placeholder { color: var(--ink-3); opacity: .55; }

.props { display: grid; gap: 1px; padding-bottom: 14px; margin-bottom: 18px; border-bottom: 1px solid var(--rule); }
.prop { display: grid; grid-template-columns: 140px 1fr; align-items: center; min-height: 34px; }
.prop-label { display: flex; align-items: center; gap: 8px; color: var(--ink-2); }
.prop input { width: 100%; height: 30px; padding: 0 8px; border: 0; border-radius: 5px; background: none; outline: none; }
.prop input:hover, .chips:hover { background: var(--hover); }
.prop input:focus { background: var(--paper); box-shadow: 0 0 0 1px var(--rule-2); }
.prop input::placeholder { color: var(--ink-3); }
.chips { display: flex; flex-wrap: wrap; gap: 4px; min-height: 30px; align-items: center; padding: 0 8px; border-radius: 5px; cursor: text; }
.chip { background: var(--chip); border-radius: 4px; padding: 1px 7px; font-size: 13px; }
.chips .ph { color: var(--ink-3); }

/* the font picker is the one bold element: each choice is shown in its own face */
.fonts { display: flex; gap: 6px; padding: 4px 0; }
.fonts button { display: flex; flex-direction: column; align-items: center; gap: 2px; width: 74px; padding: 6px 0 5px; border-radius: 8px;
  color: var(--ink-2); font-size: 11.5px; box-shadow: inset 0 0 0 1px var(--rule); }
.fonts button:hover { color: var(--ink); background: var(--hover); }
.fonts button[aria-checked="true"] { color: var(--ink); box-shadow: inset 0 0 0 1.5px var(--ink); }
.fonts .ag { font-size: 22px; line-height: 1.1; color: var(--ink); }
.fonts [data-font="sans"] .ag { font-family: var(--sans); font-weight: 600; }
.fonts [data-font="serif"] .ag { font-family: var(--serif); }
.fonts [data-font="mono"] .ag { font-family: var(--mono); font-size: 19px; }

.page { min-height: 40vh; outline: none; font: 16px/1.7 var(--page-font); overflow-wrap: anywhere; caret-color: var(--ink); }
.font-serif .page { font-size: 17.5px; line-height: 1.75; }
.font-mono .page { font-size: 14.5px; line-height: 1.7; }
.page:empty::before { content: attr(data-placeholder); color: var(--ink-3); pointer-events: none; }
.page > :first-child { margin-top: 0; }
.page h1 { font-size: 1.875em; font-weight: 700; line-height: 1.25; letter-spacing: -.015em; margin: 1.4em 0 .2em; }
.page h2 { font-size: 1.5em; font-weight: 650; line-height: 1.3; letter-spacing: -.01em; margin: 1.3em 0 .2em; }
.page h3 { font-size: 1.25em; font-weight: 600; line-height: 1.35; margin: 1.1em 0 .15em; }
.font-serif .page h1, .font-serif .page h2, .font-serif .page h3 { font-weight: 600; letter-spacing: 0; }
.page h4, .page h5, .page h6 { font-size: 1.05em; font-weight: 600; margin: 1em 0 .2em; }
.page p { margin: .25em 0; }
.page ul, .page ol { padding-left: 1.6em; margin: .25em 0; }
.page li { margin: .1em 0; padding-left: .15em; }
.page li::marker { color: var(--ink-2); }
.page blockquote { border-left: 3px solid var(--ink); margin: .5em 0; padding: 0 0 0 14px; }
.page hr { border: 0; border-top: 1px solid var(--rule-2); margin: 1.4em 0; }
.page a { color: inherit; text-decoration: underline; text-decoration-color: var(--ink-3); text-underline-offset: 3px; }
.page a:hover { color: var(--accent); text-decoration-color: var(--accent); }
.page code { font: .86em var(--mono); }
.page :not(pre) > code { background: var(--code-bg); color: var(--code-ink); padding: .15em .35em; border-radius: 4px; }
.page pre { background: var(--code-bg); border-radius: 6px; padding: 16px 18px; margin: .6em 0; overflow-x: auto; white-space: pre; line-height: 1.55; }
.page pre code { font-size: 13.5px; }
.page img { max-width: 100%; height: auto; border-radius: 4px; cursor: pointer; }
.page img.selected { outline: 2px solid var(--accent); outline-offset: 2px; }
.page table { border-collapse: collapse; margin: .8em 0; font-size: .93em; display: block; overflow-x: auto; max-width: 100%; }
.page th, .page td { border: 1px solid var(--rule-2); padding: 6px 10px; min-width: 72px; vertical-align: top; text-align: left; }
.page th { background: var(--th); font-weight: 600; }
.page .missing-img { background: var(--bad-soft); color: var(--bad); font-size: 13px; padding: 2px 8px; border-radius: 4px; }

/* ---------- floating menus ---------- */
.menu { position: fixed; z-index: 60; display: none; background: var(--menu); border-radius: 8px; box-shadow: var(--shadow); padding: 4px; }
.bubble, .imgbar, .tablebar { gap: 1px; align-items: center; }
.bubble button, .imgbar button, .tablebar button { height: 28px; min-width: 28px; padding: 0 8px; border-radius: 5px; color: var(--ink-2);
  font-size: 13px; font-weight: 500; display: inline-grid; place-items: center; }
.bubble button:hover, .imgbar button:hover, .tablebar button:hover { background: var(--hover); color: var(--ink); }
.bubble .serif-i { font-family: var(--serif); font-size: 15px; }
.bubble .sep { width: 1px; height: 18px; background: var(--rule-2); margin: 0 3px; }
.slash { width: 300px; max-height: 340px; overflow-y: auto; padding: 6px; }
.slash .sh { font-size: 12px; font-weight: 600; color: var(--ink-3); padding: 6px 8px 4px; }
.slash .opt { display: flex; align-items: center; gap: 10px; padding: 5px 8px; border-radius: 6px; cursor: pointer; }
.slash .opt.on { background: var(--hover); }
.slash .ic { width: 38px; height: 38px; border-radius: 6px; display: grid; place-items: center; flex: none;
  box-shadow: inset 0 0 0 1px var(--rule-2); background: var(--paper); color: var(--ink-2); font-weight: 600; }
.slash .nm { font-weight: 500; }
.slash .ds { font-size: 12px; color: var(--ink-3); }
.more { width: 250px; padding: 6px; }
.more button, .menu-check { display: flex; align-items: center; gap: 10px; width: 100%; padding: 7px 8px; border-radius: 6px; color: var(--ink); }
.more button:hover, .menu-check:hover { background: var(--hover); }
.menu-check { cursor: pointer; font-size: 14px; }
.menu-check input { accent-color: var(--ink); margin: 0 2px; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 8px); z-index: 80; max-width: min(480px, 90vw);
  padding: 9px 16px; border-radius: 8px; background: var(--ink); color: var(--paper); font-weight: 500; opacity: 0;
  transition: opacity .16s, transform .16s; pointer-events: none; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { background: var(--bad); color: #fff; }

/* ---------- sign-in ---------- */
.login-body { display: grid; place-items: center; min-height: 100vh; background: var(--side); padding: 16px; }
.login { width: min(360px, 100%); background: var(--paper); border-radius: 12px; box-shadow: var(--shadow); padding: 32px 28px; display: grid; gap: 14px; }
.login h1 { margin: 6px 0 0; font: 700 22px/1.2 var(--sans); letter-spacing: -.015em; }
.login-sub { margin: -8px 0 4px; color: var(--ink-2); }
.login label { display: grid; gap: 6px; font-weight: 500; font-size: 13px; color: var(--ink-2); }
.login input { height: 38px; padding: 0 11px; border: 1px solid var(--rule-2); border-radius: 7px; background: var(--paper); color: var(--ink); outline: none; }
.login input:focus { border-color: var(--ink); }
.login-error { margin: 0; min-height: 1.2em; color: var(--bad); font-size: 13px; }

/* ---------- narrow screens: sidebar becomes a drawer (R15) ---------- */
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: min(300px, 86vw); z-index: 70; transform: translateX(-102%); transition: transform .18s; }
  body.drawer-open .sidebar { transform: none; box-shadow: var(--shadow); }
  body.drawer-open .scrim { display: block; position: fixed; inset: 0; z-index: 65; background: rgba(15, 15, 15, .35); }
  .only-narrow { display: inline-grid; }
  .doc { padding: 28px 18px 30vh; }
  .title { font-size: 32px; }
  .prop { grid-template-columns: 96px 1fr; }
  .search kbd { display: none; }
}
@media print {
  .sidebar, .topbar, .menu, .toast, .conflict { display: none !important; }
  .app { display: block; height: auto; } main { overflow: visible; }
}
