/* styles.css - every visual decision lives here. JS emits class names only. */

:root {
  --bg: #fafaf7;
  --surface: #ffffff;
  --surface-sunken: #f7f5ef;
  --border: #e6e4dc;
  --border-strong: #d4d2c8;
  --text: #1f1f1d;
  --text-muted: #6b6a63;
  --text-faint: #9a988f;

  --user-accent: #185fa5;
  --user-bg: #e6f1fb;
  --assistant-accent: #0f6e56;
  --assistant-bg: #e1f5ee;
  --tool-accent: #854f0b;
  --tool-bg: #faeeda;
  --neutral-accent: #6b6a63;

  --json-key: #534ab7;
  --json-string: #185fa5;
  --json-number: #993c1d;
  --json-bool: #0f6e56;
  --json-null: #6b6a63;

  --rail-json: #d6d1f2;
  --rail-xml: #cfe4d9;
  --rail-embed: #f1d9b8;

  --code-bg: #f3f1ea;
  --embed-tint: #fdf8ef;
  --mark: #f6e3a1;
  --mark-current: #f2c14e;
  --mark-xlink: #dbe9d9;
  --diff-add-bg: #e3f4e6;
  --diff-add-text: #1d6b34;
  --diff-del-bg: #fbe7e4;
  --diff-del-text: #a03024;
  --diff-chg-bg: #fdf3dc;
  --radius: 10px;
  --radius-sm: 6px;
  --mono: ui-monospace, "SF Mono", Menlo, Monaco, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
}

/* dark mode (roadmap item 9): same variables, night values */
body.dark {
  --bg: #16171a;
  --surface: #1e2024;
  --surface-sunken: #26282d;
  --border: #34363c;
  --border-strong: #45484f;
  --text: #e8e6df;
  --text-muted: #a2a09a;
  --text-faint: #75736d;

  --user-accent: #6cabe8;
  --user-bg: #1c2c3d;
  --assistant-accent: #55c2a2;
  --assistant-bg: #17332b;
  --tool-accent: #d9a35c;
  --tool-bg: #35281a;
  --neutral-accent: #a2a09a;

  --json-key: #a89ef2;
  --json-string: #7db4e8;
  --json-number: #e08a63;
  --json-bool: #55c2a2;
  --json-null: #a2a09a;

  --rail-json: #45406e;
  --rail-xml: #37524a;
  --rail-embed: #5c4a2c;

  --code-bg: #26282d;
  --embed-tint: #2c2617;
  --mark: #6b5a1e;
  --mark-current: #99801f;
  --mark-xlink: #33473a;
  --diff-add-bg: #1c3524;
  --diff-add-text: #7fd497;
  --diff-del-bg: #402320;
  --diff-del-text: #ef9a8d;
  --diff-chg-bg: #3b331f;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--sans);
  background: var(--bg);
  color: var(--text);
  font-size: 14.5px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

.app {
  display: grid;
  grid-template-columns: minmax(340px, 1fr) minmax(420px, 1.5fr);
  gap: 14px;
  padding: 14px;
  height: 100vh;
}
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; height: auto; }
  .panel { min-height: 40vh; }
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}

.panel-header {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.panel-title {
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-right: auto;
}

button {
  font: inherit;
  font-size: 12px;
  padding: 4px 10px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--text);
}
button:hover { background: var(--surface-sunken); }
button:active { background: var(--code-bg); }
button:focus-visible, input:focus-visible, textarea:focus-visible, summary:focus-visible {
  outline: 2px solid var(--user-accent);
  outline-offset: 1px;
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
}
.toggle input { accent-color: var(--user-accent); }

/* ---------- input side ---------- */

#input {
  flex: 1;
  border: 0;
  resize: none;
  padding: 12px 14px;
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--text);
  background: var(--surface);
  min-height: 0;
}
#input:focus { outline: none; }

.stats-bar {
  border-top: 1px solid var(--border);
  padding: 6px 14px;
  font-size: 11.5px;
  color: var(--text-faint);
  font-family: var(--mono);
  min-height: 28px;
}

/* ---------- output side ---------- */

#output {
  flex: 1;
  overflow: auto;
  padding: 14px;
  min-height: 0;
}

.empty-state { color: var(--text-faint); font-size: 13px; padding: 24px 8px; }

/* block sections */
.block {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 14px;
  overflow: hidden;
  background: var(--surface);
}
.block-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-sunken);
}
.flex-spacer { flex: 1; }
.block-index { font-family: var(--mono); font-size: 11px; color: var(--text-faint); }
.block-body { padding: 12px; }

.role-user .block-head { background: var(--user-bg); }
.role-user .role-chip { background: var(--user-accent); }
.role-assistant .block-head { background: var(--assistant-bg); }
.role-assistant .role-chip { background: var(--assistant-accent); }
.role-tool .block-head, .role-function .block-head { background: var(--tool-bg); }
.role-tool .role-chip, .role-function .role-chip { background: var(--tool-accent); }
.role-block .role-chip, .role-system .role-chip, .role-developer .role-chip { background: var(--neutral-accent); }

.chip {
  display: inline-block;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.04em;
  padding: 1px 8px;
  border-radius: 999px;
  color: #fff;
  text-transform: uppercase;
}
.kind-chip { background: transparent; color: var(--text-muted); border: 1px solid var(--border-strong); text-transform: none; font-family: var(--mono); font-weight: 500; }
.type-chip { background: transparent; color: var(--text-faint); border: 1px solid var(--border); text-transform: none; font-weight: 500; margin-left: 8px; }

.mini-btn { font-size: 11px; padding: 2px 8px; }

/* nesting rails - depth is visible structure, colored by content kind */
.rail { border-left: 2px solid var(--border); padding-left: 12px; margin: 4px 0 4px 4px; }
.rail-json { border-left-color: var(--rail-json); }
.rail-xml { border-left-color: var(--rail-xml); }
.rail-embed { border-left-color: var(--rail-embed); background: linear-gradient(90deg, var(--embed-tint), transparent 60%); border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }

/* collapsibles */
details { margin: 2px 0; }
summary {
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: baseline;
  gap: 6px;
  padding: 2px 4px;
  border-radius: var(--radius-sm);
  flex-wrap: wrap;
}
summary::-webkit-details-marker { display: none; }
summary::before {
  content: "▸";
  color: var(--text-faint);
  font-size: 10px;
  transition: transform 0.12s;
}
details[open] > summary::before { transform: rotate(90deg); }
summary:hover { background: var(--surface-sunken); }
.sum-label { font-size: 11.5px; color: var(--text-muted); font-style: italic; }
.count-note { font-size: 11px; color: var(--text-faint); }

/* JSON */
.json-key { font-family: var(--mono); font-size: 12.5px; color: var(--json-key); font-weight: 600; }
.json-string { font-family: var(--mono); font-size: 12.5px; color: var(--json-string); white-space: pre-wrap; word-break: break-word; }
.json-number { font-family: var(--mono); font-size: 12.5px; color: var(--json-number); }
.json-bool { font-family: var(--mono); font-size: 12.5px; color: var(--json-bool); font-weight: 600; }
.json-null { font-family: var(--mono); font-size: 12.5px; color: var(--json-null); font-style: italic; }
.embedded-src { color: var(--text-faint); }

.kv-row { padding: 2px 4px; display: block; }
.kv-row > .json-key::after { content: ": "; color: var(--text-faint); font-weight: 400; }

/* XML */
.xml-tag { font-family: var(--mono); font-size: 12.5px; color: var(--assistant-accent); font-weight: 600; }
.xml-comment { font-family: var(--mono); font-size: 12px; color: var(--text-faint); font-style: italic; padding: 2px 4px; }
.attr-grid {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 2px 12px;
  padding: 4px 2px 6px;
}
.attr-name { font-family: var(--mono); font-size: 12px; color: var(--tool-accent); }
.attr-value { font-family: var(--mono); font-size: 12px; color: var(--text); white-space: pre-wrap; word-break: break-word; }
.xml-text { padding: 2px 0; }

/* text + clipping */
.text-pre {
  font-family: var(--mono);
  font-size: 12.5px;
  white-space: pre-wrap;
  word-break: break-word;
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  margin: 4px 0;
}
.inline-text { background: transparent; border: 0; padding: 2px 4px; margin: 0; }
.clip-toggle {
  border: 0;
  background: transparent;
  color: var(--user-accent);
  font-size: 11px;
  padding: 0 4px;
  cursor: pointer;
  font-family: var(--mono);
}
.clip-toggle:hover { text-decoration: underline; background: transparent; }

/* explicit emptiness */
.empty-marker {
  display: inline-block;
  font-size: 11px;
  font-family: var(--mono);
  color: var(--text-muted);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 0 6px;
  background: var(--surface-sunken);
}
.absence-card {
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  color: var(--text-muted);
  font-size: 12.5px;
  background: var(--surface-sunken);
}

/* parser-derived annotations */
.parser-note {
  font-size: 11px;
  color: var(--tool-accent);
  font-style: italic;
  padding: 2px 0 4px;
}

/* pipe tables */
.pipe-table-wrap { margin: 4px 0; overflow-x: auto; }
.pipe-table { border-collapse: collapse; font-family: var(--mono); font-size: 12px; }
.pipe-table td {
  border: 1px solid var(--border);
  padding: 3px 8px;
  white-space: nowrap;
}
.pipe-table tr:nth-child(odd) td { background: var(--surface-sunken); }
.pipe-table .cell-missing { background: repeating-linear-gradient(45deg, transparent, transparent 4px, var(--border) 4px, var(--border) 5px); }

/* ---------- compact mode ---------- */

.cblock {
  border-left: 3px solid var(--border-strong);
  margin: 0 0 10px;
  padding: 2px 0 2px 10px;
}
.cblock.role-user { border-left-color: var(--user-accent); }
.cblock.role-assistant { border-left-color: var(--assistant-accent); }
.cblock.role-tool, .cblock.role-function { border-left-color: var(--tool-accent); }

.cline {
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}
.chead { margin-bottom: 2px; }
.crole { font-weight: 700; font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); }
.ckey { color: var(--json-key); font-weight: 600; margin-right: 6px; }
.cattr { color: var(--tool-accent); margin-left: 8px; }
.cattrval { color: var(--text); }
.cmuted { color: var(--text-faint); font-style: italic; }
.crow { color: var(--text); }
.ctext { color: var(--text); }

.compact-mode #output { padding: 12px 16px; }

@media (prefers-reduced-motion: reduce) {
  summary::before { transition: none; }
}

/* inline JSON (small flat containers on one line) */
.json-inline { font-family: var(--mono); font-size: 12.5px; }
.json-brace { color: var(--text-faint); font-family: var(--mono); font-size: 12.5px; }

/* array-of-similar-objects table */
.json-array-table { margin: 2px 0 4px; }
.json-table { border-collapse: collapse; font-size: 12px; margin: 4px 0 2px; max-width: 100%; }
.json-table th {
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 600;
  color: var(--json-key);
  text-align: left;
  border: 1px solid var(--border);
  padding: 3px 8px;
  background: var(--surface-sunken);
}
.json-table td {
  border: 1px solid var(--border);
  padding: 3px 8px;
  font-family: var(--mono);
  font-size: 12px;
  vertical-align: top;
  word-break: break-word;
}
.json-table .row-idx { color: var(--text-faint); font-size: 10.5px; text-align: right; }
.json-array-table { overflow-x: auto; }

/* mixed nodes */
.mixed-node > .text-pre { margin: 4px 0; }

/* ==================== Phase 1 additions ==================== */

/* ---------- search bars (item 2) ---------- */

.search-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-sunken);
  flex: 0 0 auto;
}
.search-bar input[type="search"] {
  flex: 1 1 auto;
  min-width: 0;
  font: inherit;
  font-size: 12px;
  padding: 4px 8px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
}
.search-count {
  font-size: 11px;
  font-family: var(--mono);
  color: var(--text-muted);
  min-width: 34px;
  text-align: right;
  white-space: nowrap;
}
.search-bar button { padding: 3px 8px; }
#btn-link-panels[aria-pressed="true"] {
  background: var(--user-bg);
  border-color: var(--user-accent);
  color: var(--user-accent);
}

/* ---------- source overlay: textarea with a highlight backdrop ---------- */

.source-wrap {
  position: relative;
  flex: 1;
  display: flex;
  min-height: 0;
  background: var(--surface);
}
.source-wrap #input {
  position: relative;
  z-index: 1;
  width: 100%;
  background: transparent;
}
.source-backdrop {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 0;
}
#source-hl {
  /* metrics must mirror #input exactly so marks align with the text */
  padding: 12px 14px;
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  word-break: normal;
  color: transparent;
  min-height: 100%;
}
#source-hl mark {
  color: transparent;
  border-radius: 2px;
  background: transparent;
}
#source-hl .src-mark { background: var(--mark); }
#source-hl .src-mark.current { background: var(--mark-current); outline: 1px solid var(--tool-accent); }
#source-hl .src-xlink { background: var(--user-bg); outline: 1px dashed var(--user-accent); }
#source-hl .src-xlink.approx { outline-style: dotted; }
#source-hl .src-mark.src-xlink { background: var(--mark-xlink); }

/* ---------- rendered-side hit highlighting ---------- */

#output .search-hit-current {
  outline: 2px solid var(--tool-accent);
  outline-offset: 1px;
  background: var(--tool-bg);
  border-radius: var(--radius-sm);
}
#output details.search-hit-current { outline-offset: -1px; }
#output .search-xlink {
  outline: 2px dashed var(--user-accent);
  outline-offset: 1px;
  border-radius: var(--radius-sm);
}

/* highlight-all: every hit visible at once, dimmer than the current one */
#output .search-hit-all {
  outline: 1px solid var(--tool-accent);
  outline-offset: 1px;
  border-radius: var(--radius-sm);
}
#output mark.ren-word.hl-all { background: var(--mark); }
#source-hl .src-xlink.xall { outline-style: dotted; background: var(--mark-xlink); }

/* ---------- hide-source toggle (item 3) ---------- */

#btn-show-source { display: none; }
body.source-hidden .panel-source { display: none; }
body.source-hidden .app { grid-template-columns: 1fr; }
body.source-hidden #btn-show-source { display: inline-block; }

/* ---------- lazy rendering + chunking (item 5) ---------- */

.lazy-note {
  font-size: 11px;
  color: var(--text-faint);
  font-style: italic;
  padding: 2px 8px 4px;
}
.chunk-more-wrap { padding: 4px 0; }
button.chunk-more {
  font-size: 11.5px;
  color: var(--text-muted);
  border-style: dashed;
}
button.chunk-more:hover { color: var(--text); }
.json-table td .chunk-more { margin: 2px 0; }

/* ---------- file drag-and-drop (item 5) ---------- */

.panel-source.drag-over {
  outline: 2px dashed var(--user-accent);
  outline-offset: -6px;
}
.panel-source.drag-over #input { opacity: 0.55; }

/* ==================== Phase 1 polish (user feedback round) ==================== */

/* mixed segments: prose stands alone between islands, never reads as a
 * caption of the previous card */
.mixed-node > .seg { margin: 12px 0; }
.mixed-node > .seg:first-child { margin-top: 0; }
.mixed-node > .seg:last-child { margin-bottom: 0; }
.seg-text .text-pre {
  border-left: 3px solid var(--border-strong);
  padding-left: 10px;
  margin: 0;
}

/* word-level rendered hits */
#output mark.ren-word {
  background: var(--mark);
  border-radius: 2px;
  padding: 0 1px;
}
#output mark.ren-word.current {
  background: var(--mark-current);
  outline: 1px solid var(--tool-accent);
}

/* rendered match-mode selector */
#rendered-match {
  font: inherit;
  font-size: 11.5px;
  padding: 3px 6px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
}

/* pressed states for the new toggles */
#btn-link-follow[aria-pressed="true"],
#btn-src-search[aria-pressed="true"],
#btn-ren-search[aria-pressed="true"] {
  background: var(--user-bg);
  border-color: var(--user-accent);
  color: var(--user-accent);
}

/* ==================== UX round 2 ==================== */

/* The hidden attribute must always win. Class rules like
 * .search-bar { display: flex } otherwise override the user-agent
 * [hidden] style and the element never actually disappears. */
[hidden] { display: none !important; }

/* markup declarations (<?xml?>, <!DOCTYPE>) */
.xml-decl {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 2px 0;
}
.xml-decl .decl-badge {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0 5px;
  flex: 0 0 auto;
}
.xml-decl .decl-text {
  font-family: var(--mono, ui-monospace, monospace);
  font-size: 12px;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
}

/* ==================== Phase 2 ==================== */

/* ---------- carousel view (item 6) ---------- */

.carousel { padding: 12px 14px; }
.carousel-nav {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
  position: sticky;
  top: 0;
  background: var(--surface);
  padding: 6px 0;
  z-index: 2;
  border-bottom: 1px solid var(--border);
}
.car-pos { font-size: 12px; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.carousel-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 10px;
  align-items: start;
}
.tile {
  background: var(--surface-sunken);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  min-width: 0;
  overflow-wrap: anywhere;
}
.tile-wide { grid-column: 1 / -1; }
.tile-muted { opacity: 0.85; }
.tile-path {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 4px;
  border-bottom: 1px dashed var(--border);
  padding-bottom: 3px;
  word-break: break-all;
}
.tile-value { font-family: var(--mono); font-size: 12.5px; white-space: pre-wrap; }
.tile-table-wrap { overflow-x: auto; }
.tile-table { font-size: 12px; }
.car-note { padding: 10px 2px 2px; }
body.carousel-mode #btn-expand, body.carousel-mode #btn-collapse { display: none; }

/* ---------- node actions (item 7) ---------- */

.node-actions {
  position: absolute;
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 3px 6px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.12);
  z-index: 30;
  font-size: 11px;
}
.node-actions-path {
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--text-muted);
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.node-action-btn { font-size: 10.5px; padding: 2px 6px; }

/* ---------- trace diff (item 8) ---------- */

#btn-diff[aria-pressed="true"] { background: var(--user-bg); border-color: var(--user-accent); }
.source-b { display: flex; flex-direction: column; border-top: 2px solid var(--border-strong); min-height: 30%; }
.source-b-head {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  padding: 6px 14px;
  border-bottom: 1px solid var(--border);
}
#input-b {
  flex: 1;
  border: 0;
  resize: none;
  padding: 10px 14px;
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 20px;
  background: var(--surface);
  color: var(--text);
  outline: none;
  min-height: 120px;
}
body.diff-mode #btn-ren-search, body.diff-mode #view-mode,
body.diff-mode #btn-expand, body.diff-mode #btn-collapse { display: none; }

.diff-view { padding: 10px 14px; }
.diff-summary { font-size: 12px; color: var(--text-muted); padding: 4px 0 10px; }
.diff-block {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 12px;
  overflow: hidden;
}
.diff-block.dstatus-added { border-color: var(--diff-add-text); }
.diff-block.dstatus-removed { border-color: var(--diff-del-text); }
.diff-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-sunken);
}
.diff-idx { font-size: 12px; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.diff-counts { font-size: 11.5px; color: var(--text-faint); margin-left: auto; }
.diff-body { padding: 6px 8px; }
.dline {
  display: flex;
  gap: 10px;
  padding: 2px 6px;
  border-radius: 4px;
  font-family: var(--mono);
  font-size: 12px;
  align-items: baseline;
}
.dline + .dline { margin-top: 1px; }
.dpath { color: var(--text-muted); flex: 0 0 34%; min-width: 0; word-break: break-all; }
.dvals { flex: 1; min-width: 0; white-space: pre-wrap; word-break: break-word; }
.d-added { background: var(--diff-add-bg); }
.d-removed { background: var(--diff-del-bg); }
.d-changed { background: var(--diff-chg-bg); }
.d-new { color: var(--diff-add-text); }
.d-old { color: var(--diff-del-text); text-decoration: line-through; text-decoration-thickness: 1px; }
.d-arrow { color: var(--text-faint); margin: 0 6px; }
.d-empty { font-style: italic; opacity: 0.8; }
.d-same .dvals { color: var(--text-muted); }
.d-same-summary { font-size: 11.5px; color: var(--text-faint); cursor: pointer; padding: 2px 6px; }
.d-same-body { border-left: 2px solid var(--border); margin-left: 6px; }

/* ---------- keyboard navigation (item 9) ---------- */

.kbd-current { outline: 2px solid var(--user-accent); outline-offset: 2px; }

#btn-theme[aria-pressed="true"] { background: var(--surface-sunken); }

/* ---------- Phase 3: insights, redaction, export (items 10-12) ---------- */

#btn-insights[aria-pressed="true"] { background: var(--surface-sunken); border-color: var(--user-accent); }
#btn-redact[aria-pressed="true"] { background: var(--tool-bg); border-color: var(--tool-accent); color: var(--tool-accent); }
#export-menu {
  font: inherit;
  font-size: 12px;
  padding: 4px 6px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  border-radius: var(--radius-sm);
  color: var(--text);
}

#insights {
  border-bottom: 1px solid var(--border);
  background: var(--surface-sunken);
  padding: 10px 14px;
  max-height: 34vh;
  overflow: auto;
  font-size: 12.5px;
}
body.diff-mode #insights { display: none; } /* insights describe trace A; the diff view has its own story */

.insight-section + .insight-section { margin-top: 12px; }
.insight-title {
  font-weight: 600;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}
.insight-note { font-size: 11.5px; color: var(--text-faint); margin: 1px 0 4px; }
.insight-empty { color: var(--text-faint); font-style: italic; }

.insight-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 2px 0;
  flex-wrap: wrap;
}
.insight-token, .insight-ts {
  font-family: var(--mono);
  font-size: 11.5px;
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 1px 6px;
}
.insight-arrow { color: var(--text-faint); }
.insight-jump {
  font-size: 11.5px;
  padding: 1px 8px;
}
.insight-delta { color: var(--text-faint); font-family: var(--mono); font-size: 11px; min-width: 56px; }
.insight-size-label { min-width: 160px; color: var(--text-muted); }
.insight-bar-wrap {
  flex: 1;
  min-width: 80px;
  max-width: 280px;
  height: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  overflow: hidden;
}
.insight-bar { display: block; height: 100%; background: var(--user-accent); opacity: 0.55; }
.insight-size-num { color: var(--text-faint); font-family: var(--mono); font-size: 11px; }

/* C3: format-adapter rows. Theme variables only, so dark mode is automatic. */
.insight-adapter { flex-wrap: wrap; gap: 8px; }
.insight-adapter-badge {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 1px 6px;
}
.insight-adapter-name { font-weight: 600; }
.insight-adapter-hint { color: var(--text-muted); font-size: 12px; flex: 1; min-width: 160px; }

/* insight jump target flash */
.jump-flash { animation: jumpflash 1.5s ease-out; }
@keyframes jumpflash {
  0% { background: var(--mark-current); box-shadow: 0 0 0 3px var(--mark-current); }
  100% { background: transparent; box-shadow: 0 0 0 3px transparent; }
}

/* ---------- Phase 4: tail mode (item 15) ---------- */

#btn-tail[aria-pressed="true"] { background: var(--assistant-bg); border-color: var(--assistant-accent); color: var(--assistant-accent); }

/* ---------- audit Tier A additions ---------- */

/* A7: search toggles (Aa / .* / Filter) share the pressed treatment */
.search-toggle { font-size: 10.5px; padding: 3px 7px; font-family: var(--mono); }
.search-toggle[aria-pressed="true"],
#btn-ren-filter[aria-pressed="true"] {
  background: var(--user-bg);
  border-color: var(--user-accent);
  color: var(--user-accent);
}

/* A7: filter mode hides blocks with no hits; nothing is removed */
.filter-hidden { display: none !important; }

/* A4: interpretation tags on retyped YAML scalars */
.itag {
  font-size: 10px;
  font-style: italic;
  color: var(--text-muted);
  margin-left: 6px;
  white-space: nowrap;
}

/* A3: literals beyond double precision carry a visible marker */
.imprecise-mark {
  color: var(--tool-accent);
  font-weight: 700;
  margin-left: 4px;
  cursor: help;
}

/* recovered malformed JSON: a structural fidelity marker, styled from theme
 * vars so it adapts to dark mode with everything else */
.recovered-chip {
  background: transparent;
  color: var(--tool-accent);
  border: 1px solid var(--tool-accent);
  text-transform: none;
  font-family: var(--mono);
  font-weight: 600;
}
.embedded.is-recovered { border-left: 2px solid var(--tool-accent); }

/* A8: detected header rows */
.pipe-table th {
  font-weight: 600;
  background: var(--surface-sunken);
  text-align: left;
}

/* A13: action bar corner-dock toggle */
.node-actions-dock {
  font-size: 10px;
  padding: 2px 4px;
  border: none;
  background: transparent;
  opacity: 0.6;
  cursor: pointer;
}
.node-actions-dock:hover { opacity: 1; }
.node-actions-dock[aria-pressed="true"] { opacity: 1; background: var(--surface-sunken); border-radius: 3px; }

/* A9: keyboard jump targets take focus; the outline says where you landed */
#output [tabindex="-1"]:focus-visible {
  outline: 2px solid var(--user-accent);
  outline-offset: 1px;
}
.notice-jump-full { font-style: italic; }
.notice-label-ignore { font-size: 11px; }
.notice-label-accept { font-size: 11px; }
.notice-boundary { font-weight: 600; }

/* ---- item 55: parse skeleton / loading states ------------------------- */
/* While a worker parse is in flight (mobile profile: every parse), the app
   marks body.parse-pending. Existing content stays visible but dims, so a
   superseding keystroke never blanks the view; an empty output shows
   skeleton bars instead. Perceived latency is governed by this feedback,
   not by sync parse speed. */
body.parse-pending #output { opacity: 0.55; transition: opacity 0.15s ease; }
.parse-skeleton { padding: 12px; }
.parse-skeleton .sk-block {
  border: 1px solid var(--border, #d8d8d8);
  border-radius: 6px;
  padding: 10px 12px;
  margin-bottom: 10px;
}
.parse-skeleton .sk-line {
  height: 10px;
  border-radius: 4px;
  margin: 6px 0;
  background: linear-gradient(90deg, rgba(128,128,128,0.18) 25%, rgba(128,128,128,0.32) 50%, rgba(128,128,128,0.18) 75%);
  background-size: 200% 100%;
  animation: sk-shimmer 1.1s linear infinite;
}
.parse-skeleton .sk-line.sk-short { width: 40%; }
@keyframes sk-shimmer {
  from { background-position: 200% 0; }
  to { background-position: 0 0; }
}
@media (prefers-reduced-motion: reduce) {
  .parse-skeleton .sk-line { animation: none; }
}
