html, body { height: 100%; }
body { overflow: hidden; }
.shell { display: grid; grid-template-columns: 290px 1fr; height: 100dvh; }

/* ── sidebar ───────────────────────────────────────── */
.sidebar {
  display: flex; flex-direction: column; min-height: 0;
  background: var(--paper-2); border-right: 1px solid var(--border-fade);
  padding: 14px 12px 12px;
}
.side-head { display: flex; align-items: center; justify-content: space-between; padding: 4px 6px 14px; }
.brand { display: inline-flex; align-items: center; gap: 10px; text-decoration: none; font-size: 1.55rem; }
.brand-dot {
  width: 14px; height: 14px; border-radius: 50%;
  background: conic-gradient(from 0deg, var(--accent-strong), var(--accent), var(--accent-strong));
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent-strong) 20%, transparent);
  animation: spin 6s linear infinite;
}
.brand-dot.big { width: 46px; height: 46px; box-shadow: 0 0 0 8px color-mix(in srgb, var(--accent-strong) 14%, transparent), 0 0 60px color-mix(in srgb, var(--accent-strong) 40%, transparent); }
@keyframes spin { to { transform: rotate(360deg); } }

.new-btn {
  display: flex; align-items: center; gap: 8px; width: 100%;
  background: var(--paper); border: 1px solid var(--border-fade); border-radius: 10px;
  padding: 10px 12px; cursor: pointer; font-size: 0.9rem; text-align: left;
  transition: border-color 0.18s, transform 0.18s;
}
.new-btn:hover { border-color: var(--accent-strong); }
.new-btn:active { transform: scale(0.98); }
.new-btn span[aria-hidden] { font-size: 1.1rem; line-height: 1; color: var(--accent-strong); }
.side-search {
  margin: 10px 0 8px; width: 100%; padding: 8px 11px; border-radius: 9px;
  border: 1px solid transparent; background: var(--hover); color: var(--fg); font: inherit; font-size: 0.84rem;
}
.side-search:focus { outline: none; border-color: var(--border-fade); background: var(--paper); }

.history { flex: 1; overflow-y: auto; min-height: 0; margin: 0 -4px; padding: 0 4px; }
.group-label { font-family: var(--font-mono); text-transform: uppercase; letter-spacing: 0.1em; font-size: 0.62rem; color: var(--muted); padding: 14px 8px 6px; }
.chat-item { border-radius: 9px; margin-bottom: 1px; }
.chat-row {
  display: flex; align-items: center; gap: 4px; padding: 7px 6px 7px 8px; border-radius: 9px; cursor: pointer;
  font-size: 0.87rem; color: var(--text-2); transition: background 0.15s;
}
.chat-row:hover { background: var(--hover); }
.chat-item.active > .chat-row { background: color-mix(in srgb, var(--fg) 9%, transparent); color: var(--fg); }
.chat-row .t { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-row .count { font-family: var(--font-mono); font-size: 0.62rem; color: var(--muted); }
.caret {
  width: 20px; height: 20px; flex: 0 0 20px; display: grid; place-items: center; border: 0; background: none; cursor: pointer;
  color: var(--muted); border-radius: 5px; transition: transform 0.2s;
}
.caret:hover { background: var(--hover); }
.chat-item.open .caret { transform: rotate(90deg); }
.caret.ghost { visibility: hidden; }
.pages { display: none; padding: 2px 0 6px 18px; }
.chat-item.open .pages { display: block; animation: drop 0.22s ease both; }
@keyframes drop { from { opacity: 0; transform: translateY(-4px); } }
.page-link {
  display: flex; gap: 6px; align-items: baseline; width: 100%; text-align: left; border: 0; background: none; cursor: pointer;
  padding: 5px 8px; border-left: 1px solid var(--border-fade); font-size: 0.8rem; color: var(--muted);
  border-radius: 0 7px 7px 0;
}
.page-link:hover { color: var(--fg); background: var(--hover); }
.page-link .n { font-family: var(--font-mono); font-size: 0.64rem; flex: 0 0 auto; }
.page-link .pt { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.page-link.depth-1 { margin-left: 14px; }
.page-link.depth-2 { margin-left: 28px; }
.page-link.depth-3 { margin-left: 42px; }
.page-link .dot { width: 6px; height: 6px; border-radius: 50%; flex: 0 0 6px; align-self: center; background: var(--border-fade); }
.page-link .dot.running { background: var(--accent-strong); animation: pulse 1s infinite; }
.page-link .dot.error { background: var(--bad); }
.page-link .dot.good { background: var(--good); } .page-link .dot.bad { background: var(--bad); }
.page-link .dot.warn { background: var(--warn); } .page-link .dot.info { background: var(--info); }
@keyframes pulse { 50% { opacity: 0.3; } }
.history-empty { padding: 20px 10px; font-size: 0.82rem; color: var(--muted); line-height: 1.5; }

.side-foot { display: flex; align-items: center; justify-content: space-between; padding: 12px 4px 0; border-top: 1px solid var(--border-fade); margin-top: 8px; }
.foot-link { font-size: 0.62rem; color: var(--muted); text-decoration: none; }
.foot-link:hover { color: var(--accent-strong); }

.icon-btn {
  display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 9px;
  border: 0; background: transparent; cursor: pointer; color: var(--muted); font-size: 1.3rem; line-height: 1;
  transition: background 0.15s, color 0.15s;
}
.icon-btn:hover { background: var(--hover); color: var(--fg); }
.icon-btn.small { width: 24px; height: 24px; font-size: 1rem; }
.only-mobile { display: none; }
.scrim { display: none; }

/* ── main ──────────────────────────────────────────── */
.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; position: relative; }
.topbar { display: flex; align-items: center; gap: 10px; padding: 10px 18px; min-height: 54px; border-bottom: 1px solid var(--border-fade); }
.chat-title { flex: 1; min-width: 0; margin: 0; font-family: var(--font-display); font-weight: 400; font-size: 1.3rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-actions { display: flex; gap: 2px; }

.scroller { flex: 1; overflow-y: auto; min-height: 0; scroll-behavior: smooth; padding: 0 20px; }

.empty { max-width: 640px; margin: 0 auto; padding: 12vh 0 40px; text-align: center; animation: rise 0.7s cubic-bezier(.2,.7,.2,1) both; }
.empty-mark { display: grid; place-items: center; margin-bottom: 26px; }
.empty h2 { font-size: clamp(2.2rem, 5vw, 3rem); margin: 0 0 12px; }
.empty p { color: var(--text-2); line-height: 1.6; margin: 0 auto 26px; max-width: 34em; }
.examples { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; text-align: left; }
.example {
  border: 1px solid var(--border-fade); background: var(--paper); border-radius: 12px; padding: 12px 14px; cursor: pointer;
  font-size: 0.86rem; line-height: 1.4; color: var(--text-2); text-align: left; transition: border-color 0.18s, transform 0.18s;
}
.example:hover { border-color: var(--accent-strong); transform: translateY(-2px); }
.example b { display: block; font-family: var(--font-mono); font-weight: 400; text-transform: uppercase; letter-spacing: 0.1em; font-size: 0.6rem; color: var(--accent-strong); margin-bottom: 4px; }
@keyframes rise { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }

.shared-banner { max-width: 820px; margin: 18px auto 0; display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 12px 16px; border: 1px dashed var(--accent-strong); border-radius: 12px; font-size: 0.9rem; }

.thread { max-width: 820px; margin: 0 auto; padding: 22px 0 40px; }

.entry { margin-bottom: 34px; animation: rise 0.5s cubic-bezier(.2,.7,.2,1) both; scroll-margin-top: 16px; }
.entry.nested { margin-left: 34px; position: relative; }
.entry.nested::before { content: ""; position: absolute; left: -20px; top: -26px; bottom: 30px; border-left: 1px dashed var(--border-fade); }
.entry.nested.depth-2 { margin-left: 68px; }
.entry.nested.depth-3 { margin-left: 96px; }

.ask { display: flex; justify-content: flex-end; margin-bottom: 14px; }
.ask-bubble {
  max-width: 80%; background: color-mix(in srgb, var(--fg) 7%, var(--bg)); border-radius: 16px 16px 4px 16px;
  padding: 10px 14px; font-size: 0.93rem; line-height: 1.5; white-space: pre-wrap; overflow-wrap: anywhere;
}
.ask-bubble a { color: var(--info); }
.ask-parent { font-family: var(--font-mono); font-size: 0.62rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin-bottom: 6px; white-space: normal; }
.ask-files { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.ask-files span { font-size: 0.74rem; border: 1px solid var(--border-fade); border-radius: 6px; padding: 2px 8px; background: var(--paper); }

/* the report page — reads like a printed document */
.page {
  position: relative; background: var(--paper); border-radius: 4px; box-shadow: var(--shadow);
  padding: 42px 52px 30px; border: 1px solid var(--border-fade);
}
.page::after { /* folded-corner feel */
  content: ""; position: absolute; top: 0; right: 0; width: 26px; height: 26px;
  background: linear-gradient(225deg, var(--bg) 50%, color-mix(in srgb, var(--fg) 10%, var(--paper)) 50%);
  border-bottom-left-radius: 4px;
}
.page-meta { display: flex; justify-content: space-between; gap: 10px; font-size: 0.62rem; color: var(--muted); margin-bottom: 18px; flex-wrap: wrap; padding-right: 20px; }
.page-title { font-family: var(--font-display); font-weight: 400; font-size: clamp(1.8rem, 3.6vw, 2.5rem); line-height: 1.05; margin: 12px 0 18px; }

.sources { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; margin: 0 0 24px; }
.src {
  display: flex; gap: 10px; align-items: stretch; border: 1px solid var(--border-fade); border-radius: 10px; padding: 8px;
  text-decoration: none; background: color-mix(in srgb, var(--bg) 40%, var(--paper)); min-width: 0; transition: border-color 0.18s;
}
a.src:hover { border-color: var(--accent-strong); }
.src img { width: 64px; height: 64px; object-fit: cover; border-radius: 6px; flex: 0 0 64px; background: var(--hover); }
.src .ph { width: 64px; height: 64px; border-radius: 6px; flex: 0 0 64px; display: grid; place-items: center; background: var(--hover); font-family: var(--font-mono); font-size: 0.6rem; color: var(--muted); }
.src-body { min-width: 0; display: flex; flex-direction: column; gap: 2px; font-size: 0.78rem; }
.src-plat { font-family: var(--font-mono); text-transform: uppercase; letter-spacing: 0.08em; font-size: 0.6rem; color: var(--accent-strong); }
.src-who { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.src-sub { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.src-open { margin-top: auto; color: var(--info); font-size: 0.72rem; }
.src.failed .src-plat { color: var(--bad); }

.md { font-size: 0.98rem; line-height: 1.66; color: var(--text-2); }
.md h2 {
  font-family: var(--font-mono); font-weight: 700; text-transform: uppercase; letter-spacing: 0.12em; font-size: 0.72rem;
  color: var(--fg); margin: 26px 0 10px; padding-top: 14px; border-top: 1px solid var(--border-fade);
}
.md h2:first-child { border-top: 0; padding-top: 0; margin-top: 0; }
.md h2.oneline + p { font-family: var(--font-display); font-size: 1.45rem; line-height: 1.25; color: var(--fg); }
.md h2.oneline + p strong { font-weight: 400; }
.md strong { color: var(--fg); font-weight: 600; }
.md p { margin: 0 0 10px; }
.md ul, .md ol { margin: 0 0 10px; padding-left: 20px; }
.md li { margin-bottom: 6px; }
.md ul.checks { list-style: none; padding-left: 0; }
.md ul.checks li { padding: 8px 12px; border-radius: 8px; background: color-mix(in srgb, var(--bg) 45%, var(--paper)); border-left: 3px solid var(--border-fade); }
.md ul.checks li.ok { border-left-color: var(--good); }
.md ul.checks li.no { border-left-color: var(--bad); }
.md ul.checks li.warn { border-left-color: var(--warn); }
.md ul.checks li.ctx { border-left-color: var(--info); }
.md a { color: var(--info); text-decoration-thickness: 1px; text-underline-offset: 2px; overflow-wrap: anywhere; }
.md blockquote { margin: 0 0 10px; padding: 4px 14px; border-left: 2px solid var(--accent-strong); font-style: italic; }
.md code { font-family: var(--font-mono); font-size: 0.86em; }

.page-foot { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 26px; padding-top: 14px; border-top: 1px solid var(--border-fade); }
.page-foot .meta { font-size: 0.6rem; color: var(--muted); }
.actions { display: flex; gap: 6px; flex-wrap: wrap; }
.actions .btn { padding: 6px 12px; font-size: 0.8rem; }
.verified-by { font-size: 0.76rem; color: var(--muted); margin-top: 12px; line-height: 1.6; }
.verified-by a { color: var(--muted); }

/* pending page */
.page.pending { min-height: 260px; }
.stages { list-style: none; padding: 0; margin: 20px 0 0; display: grid; gap: 12px; }
.stages li { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 0.92rem; transition: color 0.3s; }
.stages li .bullet { width: 18px; height: 18px; border-radius: 50%; border: 1.5px solid var(--border-fade); flex: 0 0 18px; display: grid; place-items: center; font-size: 0.7rem; }
.stages li.now { color: var(--fg); }
.stages li.now .bullet { border-color: var(--accent-strong); border-top-color: transparent; animation: spin 0.8s linear infinite; }
.stages li.did { color: var(--text-2); }
.stages li.did .bullet { background: var(--good); border-color: var(--good); color: var(--paper); }
.skel { height: 10px; border-radius: 5px; margin-top: 14px; background: linear-gradient(90deg, var(--hover), color-mix(in srgb, var(--fg) 14%, transparent), var(--hover)); background-size: 200% 100%; animation: shimmer 1.4s linear infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }
.page.error .err { color: var(--bad); margin: 8px 0 16px; line-height: 1.5; }

/* ── composer ──────────────────────────────────────── */
.composer { padding: 8px 20px 12px; position: relative; }
.composer > * { max-width: 820px; margin-left: auto; margin-right: auto; }
.composer-box {
  display: flex; align-items: flex-end; gap: 6px; background: var(--paper); border: 1px solid var(--border-fade);
  border-radius: 18px; padding: 8px; box-shadow: var(--shadow); transition: border-color 0.18s;
}
.composer-box:focus-within { border-color: color-mix(in srgb, var(--accent-strong) 60%, transparent); }
.composer textarea {
  flex: 1; border: 0; background: transparent; resize: none; color: var(--fg); font: inherit; font-size: 0.97rem;
  line-height: 1.45; padding: 7px 4px; max-height: 220px; min-height: 34px;
}
.composer textarea:focus { outline: none; }
.send {
  width: 36px; height: 36px; border-radius: 11px; border: 0; cursor: pointer; display: grid; place-items: center;
  background: var(--fg); color: var(--bg); transition: opacity 0.18s, transform 0.18s;
}
.send:disabled { opacity: 0.3; cursor: default; }
.send:not(:disabled):active { transform: scale(0.92); }
.composer-note { font-size: 0.58rem; color: var(--muted); text-align: center; margin-top: 8px; margin-bottom: 0; }
.reply-bar {
  display: flex; align-items: center; gap: 8px; font-size: 0.84rem; padding: 6px 8px 6px 14px; margin-bottom: 6px;
  border-radius: 10px; background: color-mix(in srgb, var(--accent-strong) 12%, transparent);
}
.reply-bar .mono { font-size: 0.6rem; color: var(--accent-strong); }
.reply-bar b { flex: 1; min-width: 0; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.file-chips:not(:empty) { margin-bottom: 6px; }
.chip { display: inline-flex; align-items: center; gap: 6px; background: var(--paper); border: 1px solid var(--border-fade); border-radius: 8px; padding: 4px 4px 4px 4px; font-size: 0.78rem; animation: rise 0.25s both; }
.chip img, .chip .ph { width: 30px; height: 30px; border-radius: 5px; object-fit: cover; background: var(--hover); display: grid; place-items: center; font-size: 0.55rem; font-family: var(--font-mono); color: var(--muted); }
.chip .nm { max-width: 160px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chip { position: relative; overflow: hidden; }
.chip-bar { position: absolute; left: 0; bottom: 0; height: 3px; width: 100%; transform-origin: left; transform: scaleX(var(--p, 0)); background: var(--accent-strong); opacity: 0; transition: transform 0.2s linear, opacity 0.2s; }
.chip.uploading .chip-bar { opacity: 1; }
.chip.uploading:not(.done) img, .chip.uploading:not(.done) .ph { animation: pulse 1s ease-in-out infinite alternate; }
.chip.done { border-color: color-mix(in srgb, var(--good) 55%, transparent); }
.chip.done .chip-bar { background: var(--good); }
@keyframes pulse { to { opacity: 0.45; } }
.upload-status {
  position: relative; overflow: hidden; display: flex; align-items: center; gap: 10px; font-size: 0.66rem; color: var(--text-2);
  padding: 7px 12px; margin-bottom: 6px; border-radius: 10px; background: var(--hover);
}
.upload-status::before { content: ""; width: 12px; height: 12px; flex: 0 0 12px; border-radius: 50%; border: 1.5px solid var(--accent-strong); border-top-color: transparent; animation: spin 0.8s linear infinite; }
.upload-status::after { content: ""; position: absolute; left: 0; bottom: 0; height: 2px; width: 100%; transform-origin: left; transform: scaleX(var(--p, 0)); background: var(--accent-strong); transition: transform 0.2s linear; }
.upload-status.processing::after { transform: none; background: linear-gradient(90deg, transparent, var(--accent-strong), transparent); background-size: 50% 100%; background-repeat: no-repeat; animation: sweep 1.1s linear infinite; }
@keyframes sweep { from { background-position: -50% 0; } to { background-position: 150% 0; } }
.composer.sending .send { position: relative; color: transparent; opacity: 1; }
.composer.sending .send::after { content: ""; position: absolute; width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--bg); border-top-color: transparent; animation: spin 0.8s linear infinite; }
.composer.sending textarea { opacity: 0.6; }
.drop-hint {
  position: absolute; inset: -60vh 0 0 0; max-width: none; z-index: 5; display: grid; place-items: center;
  background: color-mix(in srgb, var(--bg) 80%, transparent); border: 2px dashed var(--accent-strong); border-radius: 16px;
  font-family: var(--font-display); font-size: 1.8rem; pointer-events: none;
}

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translate(-50%, 30px); opacity: 0; pointer-events: none;
  background: var(--fg); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: 0.88rem;
  transition: opacity 0.2s, transform 0.2s; z-index: 50; max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ── mobile ────────────────────────────────────────── */
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .only-mobile { display: inline-grid; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; width: min(86vw, 320px); z-index: 30;
    transform: translateX(-102%); transition: transform 0.25s cubic-bezier(.2,.7,.2,1);
  }
  .sidebar.open { transform: none; box-shadow: var(--shadow); }
  .scrim { display: block; position: fixed; inset: 0; z-index: 20; background: rgb(0 0 0 / 35%); }
  .topbar { padding: 8px 10px; }
  .scroller { padding: 0 12px; }
  .composer { padding: 6px 12px 10px; }
  .page { padding: 26px 18px 20px; }
  .entry.nested, .entry.nested.depth-2, .entry.nested.depth-3 { margin-left: 14px; }
  .entry.nested::before { left: -9px; }
  .examples { grid-template-columns: 1fr; }
  .ask-bubble { max-width: 92%; }
  .empty { padding-top: 6vh; }
  .composer-note { display: none; }
}

/* ── print: only the chosen page ───────────────────── */
@media print {
  @page { size: A4; margin: 16mm; }
  body { overflow: visible; background: #fff; }
  :root { --paper: #fff; --bg: #fff; --fg: #111; --text-2: #222; --muted: #666; --border-fade: #ddd; --info: #1a4a9a; }
  .shell { display: block; height: auto; }
  .sidebar, .topbar, .composer, .empty, .toast, .shared-banner, .ask, .actions, .scrim { display: none !important; }
  .scroller { overflow: visible; padding: 0; }
  .thread { padding: 0; max-width: none; }
  body.printing-one .entry:not(.print-target) { display: none; }
  .entry { margin: 0 0 0 0 !important; animation: none; break-after: page; }
  .entry::before { display: none; }
  .page { box-shadow: none; border: 0; padding: 0; }
  .page::after { display: none; }
  .md a::after { content: ""; }
}

/* ── login ─────────────────────────────────────────── */
.login {
  position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; padding: 16px;
  background:
    radial-gradient(circle at 80% 0%, color-mix(in srgb, var(--accent-strong) 18%, transparent), transparent 50%),
    var(--bg);
}
.login-card {
  width: min(400px, 100%); background: var(--paper); border: 1px solid var(--border-fade); border-radius: 18px;
  box-shadow: var(--shadow); padding: 30px 28px 26px; display: flex; flex-direction: column; gap: 14px;
  animation: rise 0.6s cubic-bezier(.2,.7,.2,1) both;
}
.login-card h2 { font-size: 2rem; margin: 8px 0 0; line-height: 1.05; }
.login-sub { margin: 0 0 4px; color: var(--text-2); font-size: 0.9rem; line-height: 1.5; }
.login-card label { display: flex; flex-direction: column; gap: 6px; }
.login-card label .mono { font-size: 0.62rem; color: var(--muted); }
.login-card input {
  font: inherit; font-size: 1rem; color: var(--fg); background: var(--bg); border: 1px solid var(--border-fade);
  border-radius: 10px; padding: 11px 12px;
}
.login-card input:focus { outline: none; border-color: var(--accent-strong); }
.login-err { color: var(--bad); font-size: 0.86rem; margin: 0; min-height: 1.2em; }
.login-btn { justify-content: center; padding: 12px; font-size: 0.98rem; }
.login-btn:disabled { opacity: 0.6; }
.login.shake .login-card { animation: shake 0.4s; }
@keyframes shake { 20%, 60% { transform: translateX(-8px); } 40%, 80% { transform: translateX(8px); } }
.logout { border: 0; background: none; cursor: pointer; padding: 0; max-width: 60%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.src-wrap { margin: 0 0 24px; }
.src-wrap .sources { margin-bottom: 10px; }
.src-hint { margin: 0; font-size: 0.82rem; line-height: 1.5; color: var(--warn); background: color-mix(in srgb, var(--warn) 10%, transparent); border-radius: 8px; padding: 8px 12px; }
