:root {
  --bg: #ffffff;
  --fg: #1e1e24;
  --muted: #6b7280;
  --border: #e5e7eb;
  --bubble-user: #dbeafe;
  --bubble-user-fg: #0f172a;
  --bubble-assistant: #f3f4f6;
  --bubble-assistant-fg: #0f172a;
  --accent: #2563eb;
  --code-bg: #f6f8fa;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14151a;
    --fg: #e5e7eb;
    --muted: #9199a8;
    --border: #2b2d36;
    --bubble-user: #1d3a5f;
    --bubble-user-fg: #e8f0fe;
    --bubble-assistant: #23242b;
    --bubble-assistant-fg: #e5e7eb;
    --accent: #7ab0ff;
    --code-bg: #1c1e26;
  }
}

* { box-sizing: border-box; }

/* Browsers don't reliably default <button>/<select> to a pointer cursor the
   way <a href> does -- rather than remembering to add cursor:pointer to
   every new button/select rule one at a time (already missed once), cover
   the element types globally and let :disabled opt back out. */
button, select, summary { cursor: pointer; }
button:disabled, select:disabled { cursor: default; }

/* The `hidden` attribute's default UA-stylesheet rule (display:none) has the
   same specificity as any of our own class selectors -- so a class like
   .regex-progress-wrap that sets display:flex silently wins and the element
   stays visible despite `hidden`, since author styles load after UA styles.
   Confirmed live: the regex-search progress bar showed on a fresh, never-
   searched page load. One !important rule closes this off for every
   hidden-toggled element site-wide, not just the one that got caught. */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

a { color: var(--accent); }

.muted { color: var(--muted); font-weight: normal; }

/* ---------- list page ---------- */

.page-list {
  max-width: 900px;
  margin: 0 auto;
  padding: 24px 16px 60px;
}

.list-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.list-header-actions { display: flex; gap: 8px; }

/* Shared, lighter-weight cross-page nav (index/search/regex-search/longest/
   timeline/settings) -- these are all ways to browse the same archive, so
   they read better as one quiet nav strip than as 6 competing pill buttons
   each shouting for attention. */
.site-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  margin-bottom: 14px;
  font-size: 13px;
}
.site-nav a {
  padding: 5px 10px;
  border-radius: 6px;
  text-decoration: none;
  color: var(--muted);
}
.site-nav a:hover { background: rgba(127,127,127,0.1); color: var(--fg); }
.site-nav a.active { color: var(--fg); font-weight: 600; background: rgba(37,99,235,0.1); }

.filters {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.filters input[type=text] {
  flex: 1;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--fg);
}

.filters select, .filters button {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--fg);
}

.conv-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.conv-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 8px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.conv-title {
  font-weight: 600;
  text-decoration: none;
  flex: 1;
  min-width: 200px;
}

.conv-meta {
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.badge {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: white;
}
.badge-claude { background: #d97757; }
.badge-deepseek { background: #4d6bfe; }
.badge-grok { background: #000000; }
.badge-chatgpt { background: #10a37f; }

/* ---------- search results page (the /search results list -- distinct from
   .search-result, which is the in-conversation web-search-tool-result block) ---------- */

.search-hit-group {
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  border: none;
  border-bottom: 1px solid var(--border);
  padding: 16px 8px;
}
.search-result-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.search-result-head .conv-title { font-size: 16px; flex: 1; min-width: 200px; }

.search-snippet-link { display: block; text-decoration: none; }
.search-snippet {
  font-size: 14px;
  color: var(--fg);
  white-space: pre-wrap;
  line-height: 1.55;
  padding: 4px 0 4px 14px;
  border-left: 3px solid var(--border);
}
.search-snippet-link:hover .search-snippet { border-left-color: var(--accent); background: rgba(127, 127, 127, 0.06); }

.search-more { font-size: 13px; margin-top: 2px; }
.search-more summary {
  cursor: pointer;
  color: var(--accent);
  list-style: none;
  padding: 2px 0;
}
.search-more summary::-webkit-details-marker { display: none; }
.search-more summary::before { content: "▸ "; }
.search-more[open] summary::before { content: "▾ "; }
.search-more .search-snippet { margin-top: 4px; }

/* Shared "highlighter" look for matched text -- both the search-results
   snippets and the in-conversation jump-to-message highlight (render.js)
   use real <mark> elements, so one rule covers both. Bright/opaque on
   purpose: a subtle tint didn't read as a highlight at a glance. */
mark {
  background: #fde047;
  color: #1a1a1a;
  border-radius: 2px;
  padding: 0 1px;
}

.search-context-banner {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-size: 13px;
  color: var(--muted);
  background: rgba(253, 224, 71, 0.12);
  border: 1px solid rgba(253, 224, 71, 0.35);
  border-radius: 8px;
  padding: 8px 12px;
  margin: 10px 0;
  min-width: 0; /* required for the ellipsis truncation below to actually kick in inside a flex row */
}
/* A regex pattern is one long unbroken "word" with no natural wrap points --
   left unconstrained it stretched the banner (and the whole header) wide
   and ugly. Same treatment for a long word-search query. Full text is still
   available on hover via the title attribute. */
.banner-pattern {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}
/* The banner's own "why am I here" text and the condensed single-row header
   don't mix -- its Back-to-results/Random actions already live in .conv-sub
   as proper icon buttons (which do fit the condensed row), so once
   condensed just drop the descriptive banner rather than squeezing a third
   competing flex item into that one row. */
.conv-header.condensed .search-context-banner { display: none; }

/* ---------- regex search page ---------- */

.regex-note { font-size: 13px; margin: 8px 0 16px; line-height: 1.5; }
.regex-note code, .common-popover code { font-size: 12px; }

.common-popover {
  position: relative;
  margin: -8px 0 16px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  box-shadow: 0 4px 16px rgba(0,0,0,0.12);
  max-width: 640px;
}
.common-popover-title { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.common-popover-list { list-style: none; margin: 0; padding: 0; max-height: 280px; overflow-y: auto; }
.common-pattern-btn {
  display: block;
  width: 100%;
  text-align: left;
  padding: 6px 8px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--fg);
  font-size: 13px;
}
.common-pattern-btn:hover { background: rgba(127,127,127,0.1); }
.common-pattern-btn code {
  display: block;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}

.regex-progress-wrap {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 10px 0 16px;
}
.regex-progress-bar {
  flex: 1;
  height: 8px;
  border-radius: 999px;
  background: rgba(127,127,127,0.2);
  overflow: hidden;
}
.regex-progress-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  transition: width 0.15s ease;
}
.regex-progress-label { font-size: 12.5px; color: var(--muted); white-space: nowrap; }

.pager {
  margin-top: 20px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}
.pager-num, .pager-arrow {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 30px;
  height: 30px;
  padding: 0 6px;
  border-radius: 6px;
  text-decoration: none;
  color: var(--fg);
  font-size: 13px;
  border: 1px solid transparent;
}
.pager-num:hover, .pager-arrow:hover { border-color: var(--border); background: rgba(127,127,127,0.1); }
.pager-current {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 30px;
  height: 30px;
  padding: 0 6px;
  border-radius: 6px;
  background: var(--accent);
  color: white;
  font-size: 13px;
  font-weight: 600;
}
.pager-ellipsis { color: var(--muted); padding: 0 2px; }
.pager-arrow.disabled { color: var(--muted); opacity: 0.4; pointer-events: none; }
.pager-goto {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: 10px;
  padding-left: 10px;
  border-left: 1px solid var(--border);
  font-size: 13px;
  color: var(--muted);
}
.pager-goto input[type=number] {
  width: 56px;
  padding: 5px 6px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--fg);
  font-size: 13px;
}
.pager-goto button {
  padding: 5px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--fg);
  cursor: pointer;
  font-size: 13px;
}
.pager-goto button:hover { border-color: var(--accent); }

/* ---------- conversation page ---------- */

.page-conv {
  max-width: 1180px;
  margin: 0 auto;
  padding: 20px 16px 100px;
}

.conv-header {
  position: sticky;
  top: 0;
  z-index: 30;
  margin: 0 -16px 20px;
  padding: 20px 16px 14px;
  background: var(--bg);
  border-bottom: 1px solid transparent;
  transition: padding 0.18s ease, border-color 0.18s ease;
}
.conv-header-top { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; transition: gap 0.18s ease; }
.back-link { font-size: 13px; text-decoration: none; flex-shrink: 0; }
.conv-header h1 {
  font-size: 20px;
  margin: 6px 0;
  transition: font-size 0.18s ease, margin 0.18s ease;
  min-width: 0;
}
.conv-sub { display: flex; gap: 10px; align-items: center; font-size: 13px; flex-wrap: wrap; transition: margin-top 0.18s ease; margin-top: 8px; }

/* ---------- condensed (sticky-scrolled) header ---------- */

.conv-header.condensed {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 16px;
  border-bottom-color: var(--border);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.06);
}
.conv-header.condensed .conv-header-top {
  flex: 1;
  min-width: 0;
  flex-wrap: nowrap;
  gap: 8px;
}
.conv-header.condensed h1 {
  font-size: 13px;
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  min-width: 0;
}
.conv-header.condensed .conv-sub {
  flex-shrink: 0;
  margin-top: 0;
  gap: 6px;
  flex-wrap: nowrap;
}
.conv-header.condensed .btn-label,
.conv-header.condensed .header-date {
  display: none;
}
.conv-header.condensed .orig-link {
  padding: 3px 7px;
}
.conv-header.condensed .translate-all-btn input {
  width: 22px;
}
.header-badge { flex-shrink: 0; }

.chat {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.msg-row {
  display: flex;
  flex-direction: column;
  scroll-margin-top: 56px; /* keep TOC jump-targets clear of the sticky header */
}

.msg-row.user { align-items: flex-end; }
.msg-row.assistant { align-items: flex-start; }

.msg-label {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 4px;
  padding: 0 4px;
}

.bubble {
  max-width: 100%;
  border-radius: 14px;
  padding: 12px 16px;
}

.msg-row.user .bubble {
  background: var(--bubble-user);
  color: var(--bubble-user-fg);
  border-top-right-radius: 4px;
}

.msg-row.assistant .bubble {
  background: var(--bubble-assistant);
  color: var(--bubble-assistant-fg);
  border-top-left-radius: 4px;
  width: 100%;
}

.block { margin-bottom: 8px; }
.block:last-child { margin-bottom: 0; }

.block-text :first-child { margin-top: 0; }
.block-text :last-child { margin-bottom: 0; }
.block-text pre {
  background: var(--code-bg);
  padding: 10px 12px;
  border-radius: 8px;
  overflow-x: auto;
}
.block-text code { font-size: 13px; }
.block-text p code, .block-text li code {
  background: var(--code-bg);
  padding: 1px 5px;
  border-radius: 4px;
}
.block-text table { border-collapse: collapse; max-width: 100%; }
.block-text th, .block-text td { border: 1px solid var(--border); padding: 4px 8px; }
.block-text img { max-width: 100%; border-radius: 8px; }

.block-thinking {
  border-left: 3px solid var(--muted);
  padding-left: 10px;
  color: var(--muted);
  font-size: 13px;
}
.block-thinking summary { cursor: pointer; font-weight: 600; user-select: none; }
.block-thinking .think-body { margin-top: 6px; white-space: pre-wrap; }

.block-tool, .block-search, .block-action, .block-file, .block-xpost {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 13px;
  background: rgba(127,127,127,0.06);
}

.tool-head { display: flex; align-items: center; gap: 6px; font-weight: 600; }
.tool-icon { font-size: 14px; }
.tool-body { margin-top: 6px; color: var(--muted); white-space: pre-wrap; word-break: break-word; }

.search-queries { font-weight: 600; margin-bottom: 4px; }
.search-result { margin: 6px 0; }
.search-result a { font-weight: 600; text-decoration: none; }
.search-result .snippet { color: var(--muted); font-size: 12.5px; }
.search-result .site { color: var(--muted); font-size: 11px; }

.sources-block { font-size: 12px; }
.sources-block ol { margin: 4px 0 0 18px; padding: 0; }

.notice {
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 13px;
}
.notice-warning { background: #fef3c7; color: #78350f; }
.notice-info { background: rgba(127,127,127,0.12); color: var(--muted); }

.file-chip { display: flex; align-items: center; gap: 8px; }
.file-chip .fname { font-weight: 600; }
.file-chip.unavailable { opacity: 0.6; }

.xpost { border-left: 3px solid #1da1f2; }
.xpost-head { font-weight: 600; }
.xpost-meta { color: var(--muted); font-size: 11px; margin-top: 4px; }

.block-image img { max-width: 100%; border-radius: 10px; display: block; }

/* ---------- header action buttons (conversation page) ---------- */

.orig-link {
  font-size: 12px;
  text-decoration: none;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px 10px;
  color: var(--fg);
  background: transparent;
  cursor: pointer;
  white-space: nowrap;
}
.orig-link:hover { border-color: var(--accent); }

.star-btn.favorited { color: #d97706; border-color: #d97706; }

.translate-all-btn input {
  width: 32px;
  border: none;
  border-bottom: 1px solid var(--border);
  background: transparent;
  color: var(--fg);
  font-size: 12px;
  text-align: center;
}

.fav-filter {
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
}

/* ---------- translate controls (in-message) ---------- */

.translatable { position: relative; }
.translate-controls {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 2px;
}
.translate-btn {
  font-size: 11px;
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  padding: 1px 4px;
  border-radius: 4px;
  opacity: 0.55;
}
.translate-btn:hover { opacity: 1; background: rgba(127,127,127,0.12); }

/* ---------- star toggle (list page) ---------- */

.star-toggle {
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 18px;
  color: var(--muted);
  line-height: 1;
  padding: 0 2px;
}
.star-toggle.favorited { color: #d97706; }

/* ---------- table-of-contents sidebar (conversation page) ---------- */

.toc {
  position: fixed;
  top: 24px;
  right: 24px;
  width: 230px;
  max-height: calc(100vh - 48px);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  font-size: 12px;
}

.toc-item {
  display: block;
  flex-shrink: 0;
  padding: 5px 8px;
  border-radius: 6px;
  text-decoration: none;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  border-left: 2px solid transparent;
}
.toc-item:hover { background: rgba(127,127,127,0.12); color: var(--fg); }
.toc-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 14px;
  height: 14px;
  margin-right: 5px;
  border-radius: 4px;
  vertical-align: -2px;
  color: white;
}
.toc-chip svg { width: 9px; height: 9px; }
/* Deliberately not var(--accent) -- that's the TOC's own active-item color,
   so a chip using it would blend in instead of standing out. */
.toc-chip-file { background: #d97706; }
.toc-chip-link { background: #7c3aed; }
.toc-item.active {
  color: var(--fg);
  border-left-color: var(--accent);
  background: rgba(37,99,235,0.08);
  font-weight: 600;
}
/* A message that matched the search you arrived from -- same highlighter
   hue as the <mark> highlight itself, so "this TOC entry" and "this is why"
   read as the same visual language. */
.toc-search-hit {
  background: rgba(253, 224, 71, 0.18);
  border-left-color: #eab308;
  color: var(--fg);
}
.toc-search-hit:hover { background: rgba(253, 224, 71, 0.32); }
.toc-search-hit.active {
  background: rgba(253, 224, 71, 0.4);
  border-left-color: #eab308;
}

/* ---------- split-screen file preview panel ---------- */

.file-preview {
  position: fixed;
  top: 0;
  right: 0;
  width: 45vw;
  min-width: 320px;
  max-width: 700px;
  height: 100vh;
  background: var(--bg);
  border-left: 1px solid var(--border);
  box-shadow: -8px 0 24px rgba(0,0,0,0.15);
  transform: translateX(100%);
  transition: transform 0.22s ease;
  z-index: 50;
  display: flex;
  flex-direction: column;
}
.file-preview.open { transform: translateX(0); }

.file-preview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: 13px;
}
.file-preview-header span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-preview-header button {
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 16px;
  padding: 2px 6px;
  border-radius: 6px;
  flex-shrink: 0;
}
.file-preview-header button:hover { background: rgba(127,127,127,0.12); color: var(--fg); }

.file-preview-body {
  flex: 1;
  overflow: auto;
  padding: 16px;
}
.file-preview-body img { max-width: 100%; display: block; margin: 0 auto; }
.file-preview-body iframe { width: 100%; height: 100%; border: none; }
.file-preview-body pre {
  background: var(--code-bg);
  padding: 12px;
  border-radius: 8px;
  overflow-x: auto;
  font-size: 13px;
  white-space: pre-wrap;
  word-break: break-word;
}
.file-preview-unsupported { color: var(--muted); font-size: 14px; }

@media (max-width: 900px) {
  .file-preview { width: 100vw; max-width: none; }
}

/* When the preview panel is open, get the TOC out of the way so they don't overlap. */
.toc.hidden-for-preview { display: none !important; }

/* ---------- settings page ---------- */

.settings-form {
  max-width: 640px;
  margin-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.settings-fieldset {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
}
.settings-fieldset legend {
  padding: 0 6px;
  font-weight: 600;
}

.settings-option {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 8px 4px;
  cursor: pointer;
}
.settings-option input { margin-top: 4px; }
.settings-option p { margin: 4px 0 0; font-size: 13px; }

.settings-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 14px;
  max-width: 200px;
}
.settings-field input {
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--fg);
}

.settings-form button {
  align-self: flex-start;
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--accent);
  color: white;
  cursor: pointer;
}

/* .page-conv stays centered (see base rule above) at all widths. The TOC is
   position:fixed and floats independently in the side gutter -- only show it
   once that gutter (viewport width minus the centered 820px content column)
   is wide enough that it can't overlap the content. */
@media (max-width: 1350px) {
  .toc { display: none !important; }
}
