/* ---------------------------------------------------------------------------
   Design tokens. Light is the default; dark follows the OS unless the user
   picked a theme (data-theme on <html>, remembered in localStorage).
   --------------------------------------------------------------------------- */
:root {
  --bg: #f3f4f7;
  --surface: #ffffff;
  --surface-2: #f7f8fa;
  --surface-3: #eef0f4;
  --border: #e3e5ea;
  --border-strong: #cdd1d9;
  --text: #16181d;
  --text-2: #565c6b;
  --text-3: #8b909e;
  --accent: #2f6fed;
  --accent-hover: #2560d6;
  --accent-soft: #e9f0ff;
  --accent-text: #1d4fc4;
  --success: #1a7f45; --success-soft: #e6f6ec;
  --warn: #a35f00;    --warn-soft: #fff3df;
  --danger: #c93b2a;  --danger-soft: #fdeceb;
  --info: #4b3fa3;    --info-soft: #efedfb;
  --mark: #fff0a3;
  --code-bg: #1d1f2b; --code-text: #e8eaf2;
  --shadow-sm: 0 1px 2px rgba(20, 24, 40, .06);
  --shadow-md: 0 6px 24px rgba(20, 24, 40, .10);
  --radius: 12px; --radius-sm: 8px; --radius-xs: 6px;
  --font: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", system-ui, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --topbar-h: 56px;
  --bar-h: 62px;          /* the conversation's title bar */
  --panel-w: 360px;       /* the details panel */
  color-scheme: light;
}
:root[data-theme="dark"] { color-scheme: dark; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { color-scheme: dark; } }

:root[data-theme="dark"],
:root:not([data-theme="light"]).dark-auto {
  --bg: #0f1117;
  --surface: #171a22;
  --surface-2: #1d2029;
  --surface-3: #262a35;
  --border: #272b36;
  --border-strong: #363b48;
  --text: #e9ebf1;
  --text-2: #a4a9b8;
  --text-3: #6f7587;
  --accent: #5b8cff;
  --accent-hover: #6f9bff;
  --accent-soft: #1b2540;
  --accent-text: #8fb0ff;
  --success: #4cc27a; --success-soft: #14301f;
  --warn: #e0a24a;    --warn-soft: #34281a;
  --danger: #ff7b6b;  --danger-soft: #3a1e1c;
  --info: #a99cf5;    --info-soft: #262246;
  --mark: #5a4b12;
  --code-bg: #0c0e14; --code-text: #dfe2ec;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow-md: 0 8px 28px rgba(0, 0, 0, .5);
}

/* ---------------------------------------------------------------------------
   Base
   --------------------------------------------------------------------------- */
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; font: 14px/1.5 var(--font); color: var(--text); background: var(--bg);
  display: flex; flex-direction: column; -webkit-font-smoothing: antialiased;
}
a { color: var(--accent-text); }
button { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: var(--radius-xs); }
kbd {
  font: 11px var(--mono); color: var(--text-3); border: 1px solid var(--border-strong);
  border-bottom-width: 2px; border-radius: 5px; padding: 0 5px; background: var(--surface-2);
}
.hint { color: var(--text-3); font-size: 12.5px; }
.icon { width: 16px; height: 16px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px; font-size: 13px; font-weight: 500;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--surface);
  cursor: pointer; transition: background .12s, border-color .12s, color .12s; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); border-color: var(--text-3); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--text-2); }
.btn.ghost:hover { background: var(--surface-3); color: var(--text); }
.btn.danger { color: var(--danger); }
.btn.danger:hover { background: var(--danger-soft); border-color: var(--danger); }
.btn.icon-only { padding: 7px; }
.btn .spin { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------------------------------------------------------------------
   Top bar
   --------------------------------------------------------------------------- */
.topbar {
  height: var(--topbar-h); flex: none; display: flex; align-items: center; gap: 16px; padding: 0 20px;
  background: var(--surface); border-bottom: 1px solid var(--border); position: relative; z-index: 5;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; font-size: 15px; color: var(--text); text-decoration: none; letter-spacing: -.01em; }
.brand .logo { width: 28px; height: 28px; border-radius: 8px; background: linear-gradient(135deg, var(--accent), #7c5cff); display: grid; place-items: center; color: #fff; }
.brand .logo .icon { width: 15px; height: 15px; stroke-width: 2.2; }
nav.tabs { display: flex; gap: 2px; background: var(--surface-3); padding: 3px; border-radius: 9px; margin-left: 4px; }
nav.tabs a { color: var(--text-2); text-decoration: none; font-size: 13px; font-weight: 550; padding: 5px 14px; border-radius: 7px; transition: color .12s, background .12s; }
nav.tabs a:hover { color: var(--text); }
nav.tabs a.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }
.topbar .spacer { flex: 1; }
.topbar .search-box { flex: 1 1 360px; max-width: 640px; min-width: 0; height: 38px; }
.topbar .search-box input { font-size: 14px; }
.topbar #refresh .label { display: none; }
.topbar .status { font-size: 12.5px; color: var(--text-3); }

/* ---------------------------------------------------------------------------
   Search page: search box (in the top bar) and the filters panel
   --------------------------------------------------------------------------- */
.search-box {
  flex: 1; min-width: 260px; display: flex; align-items: center; gap: 8px; padding: 0 10px 0 12px; height: 40px;
  border: 1px solid var(--border-strong); border-radius: 10px; background: var(--surface);
  transition: border-color .12s, box-shadow .12s;
}
.search-box:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.search-box .icon { color: var(--text-3); }
.search-box input {
  flex: 1; border: 0; outline: 0; background: transparent; font: inherit; font-size: 15px; color: var(--text); min-width: 0;
}
.search-box input::placeholder { color: var(--text-3); }
.search-box input::-webkit-search-cancel-button { display: none; }
.search-box .clear { display: none; border: 0; background: transparent; color: var(--text-3); cursor: pointer; padding: 4px; border-radius: 6px; line-height: 0; }
.search-box .clear:hover { color: var(--text); background: var(--surface-3); }
.search-box.has-value .clear { display: inline-flex; }
.search-box.has-value kbd { display: none; }

.segmented { display: inline-flex; background: var(--surface-3); padding: 3px; border-radius: 10px; height: 40px; }
.segmented button {
  border: 0; background: transparent; padding: 0 14px; border-radius: 8px; font-size: 13px; font-weight: 550; color: var(--text-2); cursor: pointer;
  transition: background .12s, color .12s;
}
.segmented button:hover:not(:disabled) { color: var(--text); }
.segmented button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }
.segmented button:disabled { opacity: .45; cursor: not-allowed; }

.filters-panel { display: grid; gap: 12px; padding: 12px 14px; margin: 0 0 10px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.filters-panel[hidden] { display: none; }
.filters { display: flex; align-items: center; gap: 10px 18px; flex-wrap: wrap; }
#filters-toggle { margin-left: auto; padding: 5px 10px; }
#filters-toggle.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-text); }
.filter-count:not(:empty) { min-width: 18px; padding: 0 5px; border-radius: 999px; background: var(--accent); color: #fff; font-size: 11px; font-weight: 650; text-align: center; line-height: 18px; }
.active-filters { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 10px; }
.active-filters:empty { display: none; }
.active-chip {
  display: inline-flex; align-items: center; gap: 4px; max-width: 100%; padding: 3px 6px 3px 10px; border: 0; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent-text); font-size: 12.5px; cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.active-chip:hover { background: color-mix(in srgb, var(--accent-soft) 70%, var(--accent)); }
.active-chip .icon { width: 13px; height: 13px; }
.chip-group { display: inline-flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.chip-group-label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--text-3); margin-right: 2px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 11px; border-radius: 999px; font-size: 12.5px; font-weight: 500;
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text-2); cursor: pointer; user-select: none;
  transition: background .12s, border-color .12s, color .12s;
}
.chip:hover { border-color: var(--text-3); color: var(--text); }
.chip input { position: absolute; opacity: 0; pointer-events: none; width: 0; height: 0; }
.chip.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-text); }
.filters .clear-filters { display: none; margin-left: auto; }
.filters.active .clear-filters { display: inline-flex; }

/* ---------------------------------------------------------------------------
   Two-pane layout
   --------------------------------------------------------------------------- */
.layout { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(340px, 440px) 1fr; }
#list-pane { overflow-y: auto; padding: 14px 16px 24px; border-right: 1px solid var(--border); background: var(--bg); }
#detail-pane { position: relative; overflow-y: auto; background: var(--surface); }

.results-head { display: flex; align-items: center; gap: 10px; padding: 2px 4px 10px; font-size: 12.5px; color: var(--text-3); }
.results-head .count b { color: var(--text-2); font-weight: 600; }
#results { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: minmax(0, 1fr); gap: 6px; }

/* Result card */
.card {
  min-width: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px; cursor: pointer;
  transition: border-color .12s, box-shadow .12s, transform .12s; position: relative; outline: none;
}
.card:hover { border-color: var(--border-strong); box-shadow: var(--shadow-sm); }
.card.selected { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.card:focus-visible { border-color: var(--accent); }
.card.hidden-card { opacity: .6; }
.card.hidden-card.selected, .card.hidden-card:hover { opacity: 1; }
.card-top { display: flex; align-items: baseline; gap: 10px; }
.card .title { flex: 1; min-width: 0; font-weight: 600; font-size: 14px; line-height: 1.35; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card time { flex: none; font-size: 12px; color: var(--text-3); }
.card-meta { display: flex; align-items: center; gap: 6px; flex-wrap: nowrap; margin-top: 3px; font-size: 12.5px; color: var(--text-2); }
.card-meta > * { flex: none; }
.card-meta .proj { flex: 0 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-meta .sep { color: var(--text-3); }
.card-meta .badge { margin-left: 2px; }
/* one colour per source, the same dot in the cards and the conversation header */
.src-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-3); }
.src-dot.claude_code { background: #d9772b; }
.src-dot.opencode { background: #13a07f; }
.src-dot.codex { background: #6b7080; }
.src-dot.antigravity { background: #3d6bff; }
.src-dot.pi { background: #8a63d2; }
.snippet { font-size: 13px; color: var(--text-2); margin-top: 6px; line-height: 1.45; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; }
.snippet:empty { display: none; }
.snippet mark { background: var(--mark); color: inherit; padding: 0 1px; border-radius: 2px; }

/* Skeleton loading */
.skeleton { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; display: grid; gap: 9px; }
.sk { height: 12px; border-radius: 6px; background: linear-gradient(90deg, var(--surface-3) 25%, var(--surface-2) 50%, var(--surface-3) 75%); background-size: 200% 100%; animation: shimmer 1.2s infinite; }
.sk.w60 { width: 60%; } .sk.w40 { width: 40%; } .sk.w80 { width: 80%; }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

/* Empty states */
.empty-state { text-align: center; padding: 56px 24px; color: var(--text-3); }
.empty-state .icon { width: 36px; height: 36px; margin: 0 auto 12px; stroke-width: 1.4; color: var(--text-3); }
.empty-state h4 { margin: 0 0 4px; color: var(--text-2); font-size: 15px; font-weight: 600; }
.empty-state p { margin: 0; font-size: 13px; }
.empty-state .btn { margin-top: 14px; }
#detail.empty { height: 100%; display: flex; align-items: center; justify-content: center; }
#detail.empty .empty-state kbd { margin: 0 2px; }

/* Badges */
.badge { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; font-weight: 600; padding: 1px 8px; border-radius: 999px; line-height: 1.6; white-space: nowrap; text-decoration: none; }
.badge.cat { background: var(--surface-3); color: var(--text-2); }
.badge.cat-0 { background: var(--accent-soft); color: var(--accent-text); }
.badge.cat-1 { background: var(--success-soft); color: var(--success); }
.badge.cat-2 { background: var(--warn-soft); color: var(--warn); }
.badge.cat-3 { background: var(--info-soft); color: var(--info); }
.badge.cat-4 { background: #e3f5f8; color: #0b6e7a; }
.badge.cat-5 { background: #fbe7ea; color: #a12a3a; }
:root[data-theme="dark"] .badge.cat-4, .dark-auto .badge.cat-4 { background: #12333a; color: #6fd0dd; }
:root[data-theme="dark"] .badge.cat-5, .dark-auto .badge.cat-5 { background: #3a1e25; color: #f08a9a; }
.badge.ticket { background: var(--warn-soft); color: var(--warn); font-family: var(--mono); font-weight: 500; }
a.badge.ticket:hover { text-decoration: underline; }
.badge.hidden-tag, .badge.child { background: var(--surface-3); color: var(--text-3); }
.badge.fidelity { background: var(--warn-soft); color: var(--warn); }
.badge.src { background: var(--info-soft); color: var(--info); }
.badge.src::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.src.claude_code { background: #fbeee4; color: #a34a12; }
.badge.src.opencode { background: #e4f4ef; color: #0b6e5b; }
.badge.src.codex { background: var(--surface-3); color: var(--text-2); }
.badge.src.antigravity { background: #e8efff; color: #2b4fbf; }
:root[data-theme="dark"] .badge.src.claude_code, .dark-auto .badge.src.claude_code { background: #3a2417; color: #f0a070; }
:root[data-theme="dark"] .badge.src.opencode, .dark-auto .badge.src.opencode { background: #143028; color: #6fd8b6; }
:root[data-theme="dark"] .badge.src.antigravity, .dark-auto .badge.src.antigravity { background: #1c2547; color: #92a8ff; }

/* ---------------------------------------------------------------------------
   Detail pane
   --------------------------------------------------------------------------- */
.detail-bar {
  position: sticky; top: 0; z-index: 6; display: flex; align-items: center; gap: 12px; height: var(--bar-h); padding: 0 20px;
  background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(8px); border-bottom: 1px solid var(--border);
}
.detail-head { flex: 1; min-width: 0; }
.detail-title { margin: 0; font-size: 16px; font-weight: 650; line-height: 1.3; letter-spacing: -.01em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.meta-line { display: flex; align-items: center; gap: 6px; margin-top: 2px; font-size: 12.5px; color: var(--text-2); white-space: nowrap; overflow: hidden; }
.meta-line > * { flex: none; }
.meta-line .path { flex: 0 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; font-family: var(--mono); font-size: 12px; color: var(--text-3); }
.meta-line .mi + .mi::before { content: "·"; margin-right: 6px; color: var(--text-3); font-family: var(--font); }
.meta-line .src-dot { display: inline-block; margin-right: 6px; }
.detail-bar .toolbar { display: flex; align-items: center; gap: 8px; flex: none; }
#details-toggle[aria-expanded="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-text); }
#detail-back { display: none; }
.detail-body { padding: 18px 24px 40px; max-width: 980px; }

/* The transcript, and the details panel beside it (open by default) */
.detail-grid { display: grid; grid-template-columns: minmax(0, 1fr); align-items: start; }
#detail.details-open .detail-grid { grid-template-columns: minmax(0, 1fr) var(--panel-w); }
/* a reading column: about 780px of text, centred in whatever width the pane has */
.conversation { min-width: 0; padding: 12px max(28px, calc((100% - 780px) / 2)) 0; }
.details-panel { display: none; }
#detail.details-open .details-panel {
  display: block; position: sticky; top: var(--bar-h); height: calc(100dvh - var(--topbar-h) - var(--bar-h)); overflow-y: auto;
  padding: 0 18px 24px; border-left: 1px solid var(--border); background: var(--surface-2);
}
.dsec { margin-top: 18px; font-size: 13px; color: var(--text-2); }
.dsec > div + div { margin-top: 3px; }
.dsec .path { font-family: var(--mono); font-size: 12px; color: var(--text); overflow-wrap: anywhere; }
.dsec-label { margin: 0 0 6px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--text-3); }
.details-panel .summary { margin: 0; padding: 0; border: 0; background: none; }
.details-panel .sum-row { grid-template-columns: 1fr; gap: 2px; }
.details-panel .related { margin: 0; padding: 0; border: 0; background: none; }
.details-panel .usage { margin-top: 6px; }
.tag-list { display: flex; flex-wrap: wrap; gap: 5px; }
.tag-edit { margin-top: 8px; }
.tag-edit > summary { cursor: pointer; color: var(--accent-text); font-size: 12.5px; width: max-content; }
.tag-edit[open] > summary { margin-bottom: 8px; }
.panel-head { display: none; }
.detail-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 22px; padding-top: 14px; border-top: 1px solid var(--border); }

/* Resume command */
.resume { display: flex; align-items: center; gap: 8px; }
.resume-cmd { flex: 1; font: 12px/1.5 var(--mono); background: var(--code-bg); color: var(--code-text); padding: 7px 10px; border-radius: var(--radius-sm); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.copy-btn { flex: none; }

/* Inline delete confirmation */
.confirm { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--danger); padding-left: 6px; }

/* Summary card */
.summary { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; margin-top: 18px; display: grid; gap: 8px; }
.summary.none { color: var(--text-3); font-size: 13px; }
.sum-row { display: grid; grid-template-columns: 96px 1fr; gap: 12px; font-size: 13.5px; align-items: start; }
.sum-k { color: var(--text-3); font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; padding-top: 3px; }
.sum-v { color: var(--text); overflow-wrap: anywhere; line-height: 1.5; }
.sum-pill { display: inline-block; font-size: 12px; font-weight: 600; padding: 1px 9px; border-radius: 999px; }
.rs-ok .sum-pill { background: var(--success-soft); color: var(--success); }
.rs-partial .sum-pill { background: var(--warn-soft); color: var(--warn); }
.rs-bad .sum-pill { background: var(--danger-soft); color: var(--danger); }
.cf-yes .sum-pill { background: var(--danger-soft); color: var(--danger); }
.cf-no .sum-pill { background: var(--success-soft); color: var(--success); }

/* Tag editor */
.tag-editor { display: grid; gap: 6px; }
.tag-row { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: 13px; }
.tg-name { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--text-3); min-width: 70px; }
.tag-src { color: var(--text-3); font-size: 12px; }
.tag-chip { border: 1px solid var(--border-strong); background: var(--surface); border-radius: 999px; padding: 2px 11px; font-size: 12.5px; cursor: pointer; color: var(--text-2); transition: background .12s, border-color .12s; }
.tag-chip:hover { border-color: var(--text-3); color: var(--text); }
.tag-chip.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.tag-chip.rejected { text-decoration: line-through; opacity: .6; }
.tag-chip.none { color: var(--text-3); border-style: dashed; }
.tag-chip.suggested { border-style: dashed; border-color: var(--warn); color: var(--warn); background: var(--warn-soft); }
.tag-clear { border: none; background: none; color: var(--text-3); cursor: pointer; font-size: 14px; }
.tag-clear:hover { color: var(--text); }
.tag-help { font-size: 12px; color: var(--text-3); margin-top: 4px; }

/* References */
.refs { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.ref { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; padding: 2px 9px; border-radius: 999px; background: var(--warn-soft); color: var(--warn); }
.ref a { color: inherit; text-decoration: none; }
.ref a:hover { text-decoration: underline; }
.ref-pr, .ref-issue { background: var(--accent-soft); color: var(--accent-text); }
.ref-branch { background: var(--success-soft); color: var(--success); font-family: var(--mono); }
.ref-commit, .ref-url { background: var(--surface-3); color: var(--text-2); }
.ref.unlinked { opacity: .7; text-decoration: line-through; }
.ref-toggle { border: none; background: none; color: inherit; opacity: .6; cursor: pointer; font-size: 12px; padding: 0 2px; }
.ref-toggle:hover { opacity: 1; }
.refs-more { display: inline-block; font-size: 12px; color: var(--text-3); }
.refs-more summary { cursor: pointer; }

/* Related work */
.related { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; margin-top: 14px; }
.related h3 { margin: 0 0 8px; font-size: 13px; font-weight: 650; }
.rel-group + .rel-group { margin-top: 10px; }
.rel-head { font-size: 13px; margin-bottom: 4px; }
.rel-head a { color: var(--accent-text); text-decoration: none; }
.rel-item { font-size: 13px; padding: 3px 0 3px 10px; border-left: 2px solid var(--border-strong); display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.rel-item a { color: var(--text); text-decoration: none; }
.rel-item a:hover { text-decoration: underline; }
.rel-meta { color: var(--text-3); font-size: 12px; }

/* Transcript */
.msg { display: flex; flex-direction: column; gap: 4px; padding: 9px 0; }
.msg-head { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--text-3); }
.role-tag { display: inline-flex; align-items: center; gap: 6px; font-weight: 650; color: var(--text-2); }
.role-tag::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--text-3); }
.msg.user .role-tag { color: var(--accent-text); } .msg.user .role-tag::before { background: var(--accent); }
.msg.assistant .role-tag { color: var(--success); } .msg.assistant .role-tag::before { background: var(--success); }
.msg-body { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 14px; white-space: pre-wrap; word-break: break-word; overflow-wrap: anywhere; line-height: 1.55; }
/* what the user typed: a bubble on the right; a reply: plain text on the page */
.msg.user.text:not(.harness) { align-items: flex-end; }
.msg.user.text:not(.harness) .msg-body { max-width: min(85%, 640px); background: var(--accent-soft); border-color: transparent; border-radius: 16px 16px 4px 16px; }
.msg.assistant.text:not(.step) .msg-body { background: none; border: 0; padding: 0; font-size: 14.5px; line-height: 1.6; }
.msg-body pre { background: var(--code-bg); color: var(--code-text); padding: 12px 14px; border-radius: var(--radius-sm); overflow-x: auto; white-space: pre; margin: 8px 0; font: 12.5px/1.5 var(--mono); }
.msg-body code { font: 12.5px var(--mono); background: rgba(127, 127, 160, .16); padding: 1px 5px; border-radius: 4px; }
.msg-body pre code { background: none; padding: 0; }
.msg-body .md-h { display: block; margin: 10px 0 2px; font-size: 14px; }
.msg-body .md-h:first-child { margin-top: 0; }
.msg-body .md-table { overflow-x: auto; margin: 8px 0; white-space: normal; }
.msg-body table { border-collapse: collapse; font-size: 13.5px; line-height: 1.45; }
.msg-body th, .msg-body td { border: 1px solid var(--border); padding: 5px 10px; text-align: left; vertical-align: top; }
.msg-body th { background: var(--surface-2); font-weight: 600; }
.msg-body .md-c { text-align: center; }
.msg-body .md-r { text-align: right; }
.msg-body ul, .msg-body ol { white-space: normal; margin: 6px 0; padding-left: 22px; }
.msg-body li + li { margin-top: 3px; }
.msg-body li > ul, .msg-body li > ol { margin: 3px 0; }
.msg-body .md-task { list-style: none; margin-left: -20px; }
.msg-body .md-task input { margin: 0 6px 0 0; vertical-align: -1px; }
.msg-body blockquote { margin: 8px 0; padding: 2px 12px; border-left: 3px solid var(--border); color: var(--text-2); }
.msg-body hr { border: 0; border-top: 1px solid var(--border); margin: 12px 0; }
.msg.tool_call .msg-body, .msg.tool_result .msg-body, .msg.thinking .msg-body { background: transparent; border-style: dashed; color: var(--text-2); font-size: 13px; padding: 6px 12px; }
.msg.harness .msg-body { background: transparent; border-style: dashed; border-color: var(--warn); color: var(--text-2); font-size: 13px; padding: 6px 12px; }
.msg.harness .role-tag { color: var(--warn); } .msg.harness .role-tag::before { background: var(--warn); }
.harness-kind { color: var(--warn); font-weight: 500; }
.msg-head .harness-kind { margin-left: -2px; }
details.step-text > summary { color: var(--text-2); }
details.step-text[open] > summary { display: none; }
details.step-text[open] > :not(summary) { margin-top: 0; }
body.hide-steps .msg.step:not(.harness):not(.tool_call):not(.tool_result):not(.thinking) .msg-body { background: transparent; border-style: dashed; padding: 6px 12px; }
.msg.thinking .role-tag::after, .msg.tool_call .role-tag::after, .msg.tool_result .role-tag::after { font-weight: 400; color: var(--text-3); }
.msg.thinking .role-tag::after { content: "thinking"; }
.msg.tool_call .role-tag::after { content: "tool call"; }
.msg.tool_result .role-tag::after { content: "tool result"; }
.msg details summary { cursor: pointer; color: var(--text-2); font-size: 12.5px; font-family: var(--mono); list-style: none; display: flex; gap: 6px; align-items: center; }
.msg details summary::before { content: "▸"; font-size: 10px; color: var(--text-3); transition: transform .12s; }
.msg details[open] summary::before { transform: rotate(90deg); }
.msg details summary::-webkit-details-marker { display: none; }
.msg details > :not(summary) { margin-top: 8px; }
body.hide-tools .msg:is(.tool_call, .tool_result, .thinking):not(.reveal) { display: none; }
body.hide-steps .msg.step:not(.reveal) { display: none; }
.segmented.small { height: 30px; padding: 2px; border-radius: 8px; }
.segmented.small button { padding: 0 10px; font-size: 12px; border-radius: 6px; }
.steps-toggle { display: none; }
body.hide-steps .steps-toggle {
  display: inline-flex; align-items: center; gap: 6px; margin: 4px 0; padding: 3px 10px; border: 1px dashed var(--border-strong); border-radius: 999px;
  background: none; color: var(--text-3); font: 12px var(--mono); cursor: pointer; text-align: left;
}
body.hide-steps .steps-toggle::before { content: "▸"; font-size: 10px; transition: transform .12s; }
body.hide-steps .steps-toggle[aria-expanded="true"]::before { transform: rotate(90deg); }
body.hide-steps .steps-toggle:hover { color: var(--text); }

/* Message box: one more turn of the conversation, streamed in as it runs */
/* pinned to the bottom of the pane, so it is visible that the conversation can go on */
.composer {
  position: sticky; bottom: 0; z-index: 5; margin: 12px 0 0; padding: 8px 0 16px;
  background: linear-gradient(to bottom, transparent, var(--surface) 24px);
}
.composer-box {
  border: 1px solid var(--border-strong); border-radius: 14px; background: var(--surface); box-shadow: var(--shadow-md);
  transition: border-color .12s, box-shadow .12s;
}
.composer-box:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft), var(--shadow-md); }
.composer textarea {
  display: block; width: 100%; min-height: 52px; max-height: 40vh; resize: none; padding: 12px 14px 4px;
  font: 14px/1.5 var(--font); color: var(--text); background: transparent; border: 0; outline: none;
}
.composer textarea:disabled { cursor: not-allowed; }
.composer-row { display: flex; align-items: center; gap: 8px; padding: 6px 8px 8px 10px; flex-wrap: wrap; }
.composer-row .btn[hidden] { display: none; }
.mode-pick { display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 4px 0 10px; border-radius: var(--radius-sm); background: var(--surface-3); font-size: 12.5px; color: var(--text-2); }
.mode-pick select { border: 0; background: transparent; font: 600 12.5px var(--font); color: var(--text); padding: 4px 2px; cursor: pointer; }
.mode-pick:has(select:disabled) { opacity: .6; }
.mode-pick:has(option[value="edits"]:checked) { background: var(--warn-soft); color: var(--warn); }
.tools-panel { margin: 10px 10px 0; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-2); max-height: 50vh; overflow-y: auto; }
.tools-panel[hidden] { display: none; }
.tools-head { display: grid; gap: 2px; font-size: 13px; margin-bottom: 8px; }
.tools-body { display: grid; gap: 8px; font-size: 13px; }
.tools-server { margin: 0; padding: 6px 10px 8px; border: 1px solid var(--border); border-radius: var(--radius-sm); display: flex; flex-wrap: wrap; gap: 4px 14px; }
.tools-server legend { padding: 0 4px; font-weight: 600; }
.tools-pick { display: inline-flex; align-items: center; gap: 6px; font-family: var(--mono); font-size: 12px; }
.tools-extra { display: grid; gap: 4px; font-size: 12.5px; color: var(--text-2); }
.tools-extra textarea { width: 100%; font: 12px/1.5 var(--mono); padding: 6px 8px; border: 1px solid var(--border-strong); border-radius: var(--radius-xs); background: var(--surface); color: var(--text); resize: vertical; }
.tools-actions { display: flex; align-items: center; gap: 8px; margin-top: 10px; }
#turn-tools { padding: 4px 8px; }
.turn-status { flex: 1; min-width: 0; font-size: 12.5px; color: var(--text-3); overflow-wrap: anywhere; }
.turn-status kbd { margin: 0 2px; }
.turn-status code { font: 12px var(--mono); }
.turn-status.busy { color: var(--text-2); }
.turn-status.busy::before { content: ""; display: inline-block; width: 7px; height: 7px; margin-right: 7px; border-radius: 50%; background: var(--accent); animation: pulse 1.2s ease-in-out infinite; }
.turn-status.warn { color: var(--warn); }
.turn-status.error { color: var(--danger); }
@keyframes pulse { 50% { opacity: .25; } }

/* Slash-command pill and command output */
.cmd-badge { display: inline-flex; align-items: center; gap: 6px; font: 12.5px var(--mono); background: var(--info-soft); color: var(--info); padding: 3px 10px; border-radius: 8px; }
.cmd-badge::before { content: "/"; opacity: .6; }
.cmd-rest { margin-top: 8px; }
.cmd-output { margin: 8px 0; }
.cmd-output .out-tag { display: inline-block; font: 10px var(--mono); text-transform: uppercase; letter-spacing: .05em; color: var(--code-text); background: var(--text-3); padding: 1px 7px; border-radius: 6px 6px 0 0; }
.cmd-output pre { margin: 0; border-top-left-radius: 0; }

/* Toasts */
.toasts { position: fixed; bottom: 18px; right: 18px; display: grid; gap: 8px; z-index: 50; }
.toast { display: flex; align-items: center; gap: 8px; background: var(--text); color: var(--bg); padding: 9px 14px; border-radius: var(--radius-sm); font-size: 13px; box-shadow: var(--shadow-md); animation: toast-in .18s ease-out; max-width: 380px; }
.toast.error { background: var(--danger); color: #fff; }
.toast.success { background: var(--success); color: #fff; }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } }

/* ---------------------------------------------------------------------------
   Analytics
   --------------------------------------------------------------------------- */
.analytics { flex: 1; min-height: 0; overflow-y: auto; padding: 22px 24px 56px; }
.analytics-inner { max-width: 1160px; margin: 0 auto; display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; }
.page-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.page-head h2 { margin: 0; font-size: 20px; font-weight: 650; letter-spacing: -.015em; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.kpi .k { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--text-3); }
.kpi .v { font-size: 26px; font-weight: 650; letter-spacing: -.02em; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi .s { font-size: 12.5px; color: var(--text-3); margin-top: 2px; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 16px; align-items: start; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; min-width: 0; }
.panel.wide { grid-column: 1 / -1; }
.panel h3 { margin: 0 0 12px; font-size: 14px; font-weight: 650; display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 8px; }
.panel h3 > .hint { flex: 1 1 220px; }
.panel h3 .hint { font-weight: 400; }
.bar-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(60px, 160px) 40px; align-items: center; gap: 10px; padding: 4px 0; }
.bar-label { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); text-decoration: none; }
a.bar-label { color: var(--accent-text); }
a.bar-label:hover { text-decoration: underline; }
.bar-track { background: var(--surface-3); border-radius: 5px; height: 12px; overflow: hidden; }
.bar-fill { background: var(--accent); height: 100%; border-radius: 5px; transition: width .4s ease-out; }
.bar-count { font-size: 13px; color: var(--text-2); text-align: right; font-variant-numeric: tabular-nums; }

/* Usage tabs and tables */
.tabs-row { display: flex; gap: 2px; flex-wrap: wrap; border-bottom: 1px solid var(--border); margin-bottom: 10px; }
.tabs-row button { border: 0; background: transparent; padding: 8px 12px; font-size: 13px; font-weight: 550; color: var(--text-2); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs-row button:hover { color: var(--text); }
.tabs-row button[aria-selected="true"] { color: var(--accent-text); border-bottom-color: var(--accent); }
.tab-panel { display: none; overflow-x: auto; }
.tab-panel.active { display: block; }
.usage-table { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
.usage-table th, .usage-table td { padding: 7px 8px; border-bottom: 1px solid var(--border); text-align: right; white-space: nowrap; }
.usage-table th { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--text-3); position: sticky; top: 0; background: var(--surface); }
.usage-table th:first-child, .usage-table td.lbl { text-align: left; max-width: 380px; overflow: hidden; text-overflow: ellipsis; }
.usage-table tbody tr:hover { background: var(--surface-2); }
.usage-table a { text-decoration: none; }
.usage-table a:hover { text-decoration: underline; }
.unpriced { font-size: 12.5px; color: var(--warn); background: var(--warn-soft); border-radius: var(--radius-sm); padding: 8px 12px; margin-top: 10px; }
.unpriced code { font: 12px var(--mono); }

/* ---------------------------------------------------------------------------
   Medium screens: the details panel becomes a drawer over the transcript
   --------------------------------------------------------------------------- */
/* The public playground: a read-only server, so nothing that writes or runs is offered. */
body.demo :is(#refresh, #stop-server, #handoff-toggle, .detail-actions, .tag-edit, .ref-toggle) { display: none !important; }
.demo-pill {
  flex: none; padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; text-decoration: none;
  color: var(--warn); background: var(--warn-soft); border: 1px solid color-mix(in srgb, var(--warn) 30%, transparent);
}
.demo-pill:hover { text-decoration: underline; }
@media (max-width: 640px) { .demo-pill .label { display: none; } }

@media (max-width: 1200px) {
  #detail.details-open .detail-grid { grid-template-columns: minmax(0, 1fr); }
  #detail.details-open .details-panel {
    position: fixed; top: calc(var(--topbar-h) + var(--bar-h)); right: 0; bottom: 0; z-index: 30; height: auto;
    width: min(var(--panel-w), 100vw); background: var(--surface); box-shadow: var(--shadow-md);
  }
  .panel-head { display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; z-index: 1; margin: 0 -18px; padding: 10px 10px 10px 18px; background: inherit; border-bottom: 1px solid var(--border); }
  .panel-head h2 { margin: 0; font-size: 14px; font-weight: 650; }
}

/* ---------------------------------------------------------------------------
   Phones and small tablets: the list or one conversation, full screen
   --------------------------------------------------------------------------- */
@media (max-width: 860px) {
  .topbar { flex-wrap: wrap; height: auto; padding: 8px 12px; gap: 8px 10px; }
  .topbar .status, .brand span { display: none; }
  .topbar .search-box { order: 10; flex: 1 1 100%; max-width: none; }
  .search-box kbd { display: none; }
  .layout { grid-template-columns: 1fr; }
  #list-pane { border-right: none; padding: 10px 12px calc(24px + env(safe-area-inset-bottom)); }
  #detail-pane { display: none; position: fixed; inset: 0; z-index: 20; }
  body.detail-open #detail-pane { display: block; }
  body.detail-open #list-pane { display: none; }
  #detail-back { display: inline-flex; }
  .detail-bar { padding: 0 8px 0 4px; gap: 6px; padding-top: env(safe-area-inset-top); height: calc(var(--bar-h) + env(safe-area-inset-top)); }
  .detail-title { font-size: 15px; }
  .detail-bar .toolbar .label { display: none; }
  .detail-body { padding: 14px 16px 40px; }
  .conversation { padding: 8px 14px 0; }
  .msg.user.text:not(.harness) .msg-body { max-width: 92%; }
  .composer { padding-bottom: calc(10px + env(safe-area-inset-bottom)); }
  #detail.details-open .details-panel { top: calc(var(--bar-h) + env(safe-area-inset-top)); width: 100vw; padding-bottom: calc(24px + env(safe-area-inset-bottom)); }
  .toasts { left: 12px; right: 12px; bottom: calc(12px + env(safe-area-inset-bottom)); }
  .toast { max-width: none; }
  .bar-row { grid-template-columns: minmax(0, 1fr) 80px 36px; }
  .sum-row { grid-template-columns: 1fr; gap: 2px; }
}
@media (max-width: 480px) {
  nav.tabs a { padding: 5px 10px; }
  .meta-line .path { display: none; }       /* source, messages and cost fit; the directory is in Details */
  .segmented.small button { padding: 0 8px; }
}
/* touch screens: bigger targets, and 16px inputs so iOS does not zoom in on focus */
@media (pointer: coarse) {
  .btn { min-height: 40px; }
  .btn.icon-only { min-width: 40px; justify-content: center; }
  .chip, .tag-chip, .active-chip { padding-top: 6px; padding-bottom: 6px; }
  .segmented.small { height: 36px; }
  .search-box input, .composer textarea, .mode-pick select { font-size: 16px; }
  .send-hint { display: none; }             /* no keyboard shortcut to point at */
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }

/* Over the top bar once the server has been stopped from the UI. */
.stopped-banner { flex: none; display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; padding: 10px 20px;
  background: var(--warn-soft); color: var(--warn); border-bottom: 1px solid var(--border); font-size: 13.5px; position: relative; z-index: 6; }
.stopped-banner code { font: 12.5px var(--mono); color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 3px 8px; overflow-wrap: anywhere; }
.stopped-banner .hint { color: var(--text-2); }

/* Hand off: the panel under the transcript, above the message box */
.handoff-panel { margin: 16px 0 0; padding: 12px 14px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-2); display: grid; gap: 10px; }
.handoff-panel[hidden], #handoff-preview[hidden], .handoff-confirm[hidden], #handoff-mode[hidden], .handoff-panel .btn[hidden] { display: none; }
.handoff-head { display: grid; gap: 2px; font-size: 13px; }
.handoff-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
#handoff-preview { display: grid; gap: 8px; }
.handoff-notes { font-size: 12.5px; color: var(--text-2); display: grid; gap: 4px; }
.handoff-notes p, .handoff-notes ul { margin: 0; }
.handoff-notes ul { padding-left: 18px; max-height: 160px; overflow-y: auto; }
.handoff-warn { color: var(--warn); }
#handoff-prompt { width: 100%; min-height: 220px; resize: vertical; font: 12.5px/1.5 var(--mono); color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px; box-sizing: border-box; }
.handoff-confirm { font-size: 12.5px; color: var(--warn); display: inline-flex; gap: 6px; align-items: center; }
#handoff-live:empty { display: none; }
#handoff-live { display: grid; gap: 8px; }
.handoff-done { display: flex; flex-wrap: wrap; gap: 8px; }
