/* ============================================================
   Diffbench — Terminal direction
   Monospace-forward, dense, information-first, developer-native.
   All colors come from the token tables below (exact values).
   ============================================================ */

/* ---------- Tokens: light (default) ---------- */
:root {
  --bg: #FFFFFF;
  --surface: #F6F8FA;
  --surface2: #F6F8FA;
  --text: #1F2328;
  --dim: #57606A;
  --faint: #7E8892;
  --rule: #D8DEE4;
  --rule-strong: #AFB8C2;
  --accent: #1A7F37;
  --on-accent: #FFFFFF;
  --added-bg: #E6FFEC;
  --added-text: #116329;
  --added-word: #ABEDBC;
  --removed-bg: #FFEBE9;
  --removed-text: #A40E26;
  --removed-word: #F2B8B5;
  --changed-bg: #FFF1C9;
  --changed-text: #6E4A00;
  --kw: #CF222E;
  --str: #0A3069;
  --com: #59636E;
  --num: #0550AE;
  --fn: #8250DF;
  --gap-bg: #E9EDF1;
  --hatch: repeating-linear-gradient(135deg, #E9EDF1 0 4px, transparent 4px 8px);
  --cvd-added-bg: #DBEEFF;
  --cvd-added-text: #09477E;
  --cvd-added-word: #B4DDFA;
  --cvd-removed-bg: #FEEBD3;
  --cvd-removed-text: #8A4B0B;
  --cvd-removed-word: #F4D6A4;

  --mono: "JetBrains Mono", "SF Mono", "Cascadia Mono", Menlo, Consolas, "DejaVu Sans Mono", monospace;
  --sans: "Avenir Next", Avenir, "Segoe UI", "Noto Sans", system-ui, sans-serif;
  --ui: 12px;
  --radius: 3px;
  --panel-radius: 4px;
}

/* Dark tokens, applied either by explicit toggle or by OS preference. */
html[data-theme="dark"] {
  --bg: #0D1117;
  --surface: #161B22;
  --surface2: #10151B;
  --text: #E6EDF3;
  --dim: #9198A1;
  --faint: #6E7681;
  --rule: #21262D;
  --rule-strong: #30363D;
  --accent: #3FB950;
  --on-accent: #041508;
  --added-bg: #122B1E;
  --added-text: #56D364;
  --added-word: #1E4E2B;
  --removed-bg: #3A161C;
  --removed-text: #FF8D86;
  --removed-word: #612D2C;
  --changed-bg: #3D2E12;
  --changed-text: #E3B341;
  --kw: #FF7B72;
  --str: #A5D6FF;
  --com: #7D8590;
  --num: #79C0FF;
  --fn: #D2A8FF;
  --gap-bg: #0A0E12;
  --hatch: repeating-linear-gradient(135deg, #0A0E12 0 4px, transparent 4px 8px);
  --cvd-added-bg: #102438;
  --cvd-added-text: #79C0FF;
  --cvd-added-word: #204A6E;
  --cvd-removed-bg: #3A2712;
  --cvd-removed-text: #E3B341;
  --cvd-removed-word: #52401F;
}
@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]) {
    --bg: #0D1117;
    --surface: #161B22;
    --surface2: #10151B;
    --text: #E6EDF3;
    --dim: #9198A1;
    --faint: #6E7681;
    --rule: #21262D;
    --rule-strong: #30363D;
    --accent: #3FB950;
    --on-accent: #041508;
    --added-bg: #122B1E;
    --added-text: #56D364;
    --added-word: #1E4E2B;
    --removed-bg: #3A161C;
    --removed-text: #FF8D86;
    --removed-word: #612D2C;
    --changed-bg: #3D2E12;
    --changed-text: #E3B341;
    --kw: #FF7B72;
    --str: #A5D6FF;
    --com: #7D8590;
    --num: #79C0FF;
    --fn: #D2A8FF;
    --gap-bg: #0A0E12;
    --hatch: repeating-linear-gradient(135deg, #0A0E12 0 4px, transparent 4px 8px);
    --cvd-added-bg: #102438;
    --cvd-added-text: #79C0FF;
    --cvd-added-word: #204A6E;
    --cvd-removed-bg: #3A2712;
    --cvd-removed-text: #E3B341;
    --cvd-removed-word: #52401F;
  }
}

/* CVD-safe mode swaps ONLY the diff tints; accent is untouched. */
html.cvd {
  --added-bg: var(--cvd-added-bg);
  --added-text: var(--cvd-added-text);
  --added-word: var(--cvd-added-word);
  --removed-bg: var(--cvd-removed-bg);
  --removed-text: var(--cvd-removed-text);
  --removed-word: var(--cvd-removed-word);
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }

/* component classes set display:flex etc., which would beat the UA's
   [hidden] rule — hide wins, always */
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--mono);
  font-size: var(--ui);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow: hidden; /* prevent page scroll; inner panels scroll */
}

button, input, select, textarea {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
}
textarea { resize: none; }
h1, h2, h3, h4, p { margin: 0; }

.mono { font-family: var(--mono); }
.sans { font-family: var(--sans); }
.dim { color: var(--dim); }
.faint { color: var(--faint); }
.spring { flex: 1 1 auto; min-width: 0; }

.noscript {
  padding: 16px;
  font-family: var(--mono);
  border-bottom: 1px solid var(--rule);
}

/* Only opacity/transform transition, and never longer than 120 ms. */
.tscale, .divhandle, .fade-cv {
  transition: transform 100ms ease, opacity 100ms ease;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition: none !important;
    animation: none !important;
    scroll-behavior: auto !important;
  }
}

/* ---------- Focus rings ---------- */
:is(button, input, select, textarea, a, [tabindex]):focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.seg-item:focus-visible,
.padbtn:focus-visible { outline-offset: -2px; }
.dropzone:focus-visible { outline-offset: 4px; }

/* ---------- App frame: full viewport, no side borders ---------- */
.app {
  width: 100%;
  height: 100vh; /* fallback for older engines */
  height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  overflow: hidden;
  /* no max-width, margin, or border-inline: the shell fills the viewport */
}
.body {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: stretch;
  overflow: hidden;
}

/* ---------- Top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--rule);
  flex: none;
  flex-wrap: wrap;
}

#queueBtn { display: none; }
@media (max-width: 1023.98px) {
  #queueBtn { display: inline-flex; }
}
.brand {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text);
  text-decoration: none;
  white-space: nowrap;
}
.filepair {
  margin-inline: auto;
  font-size: calc(var(--ui) - 1.5px);
  color: var(--dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 40%;
}
.filepair .fp-a, .filepair .fp-b { overflow: hidden; text-overflow: ellipsis; }
.theme-btn { margin-left: auto; }
/* light theme shows the plain sun, dark theme the sun-with-rays */
.ic-sunrays { display: none; }
html[data-theme="dark"] .ic-sun { display: none; }
html[data-theme="dark"] .ic-sunrays { display: block; }
@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]) .ic-sun { display: none; }
  html:not([data-theme="light"]) .ic-sunrays { display: block; }
}

/* ---------- Rails ---------- */
.rail {
  background: var(--surface);
  display: flex;
  flex-direction: column;
  flex: none;
  min-height: 0;
}
.rail-batch {
  width: 224px;
  border-right: 1px solid var(--rule);
  z-index: 10;
}
.rail-side {
  width: 262px;
  border-left: 1px solid var(--rule);
  overflow-y: auto;
  scrollbar-width: thin;
  z-index: 10;
}
.rail-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--rule);
  flex: none;
}
.rail-title {
  font-size: 12px;
  font-weight: 600;
  font-family: var(--mono);
}
.pill {
  margin-left: auto;
  font-size: 11px;
  font-weight: 400;
  padding: 0 7px;
  border: 1px solid var(--rule);
  border-radius: 999px;
  color: var(--dim);
}

/* Batch queue rows */
.queue-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  scrollbar-width: thin;
}
.queue-row {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  text-align: left;
  padding: 6px 10px;
  border-bottom: 1px solid var(--rule);
  cursor: pointer;
}
.queue-row:hover { background: var(--surface2); }
.queue-row.is-active {
  background: var(--surface2);
  box-shadow: inset 0 0 0 2px var(--accent);
}
.qrow-icon {
  flex: none;
  width: 20px;
  height: 20px;
  border-radius: var(--panel-radius);
  background: var(--surface2);
  border: 1px solid var(--rule);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 9px;
  font-weight: 700;
  color: var(--dim);
  text-transform: uppercase;
  overflow: hidden;
}
/* Hidden in the full three-column layout; shown when the rail collapses. */
.queue-row .qrow-icon { display: none; }
.qrow-names {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  line-height: 1.35;
}
.qrow-name {
  font-size: calc(var(--ui) - 2px);
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.qrow-sub {
  font-size: calc(var(--ui) - 2px);
  color: var(--dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.qrow-sub .faint { color: var(--faint); }
.qrow-chips {
  flex: none;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
}
.qrow-remove {
  flex: none;
  align-self: flex-start;
  opacity: 0;
}
.queue-row:hover .qrow-remove,
.queue-row.is-active .qrow-remove,
.queue-row:focus-within .qrow-remove { opacity: 1; }

.rail-foot {
  position: relative;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  border-top: 1px solid var(--rule);
  flex: none;
}
.add-pair .sans { font-family: var(--sans); }
.folder-chooser {
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: calc(100% + 6px);
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 8px;
  background: var(--surface);
  border: 1px solid var(--rule-strong);
  border-radius: var(--panel-radius);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
  z-index: 5;
}

/* Collapsed settings rail (desktop) */
.rail.side-collapsed { width: 44px; }
.rail.side-collapsed .rail-head,
.rail.side-collapsed .settings-view,
.rail.side-collapsed .details-view { display: none; }
#railCollapsed { padding: 8px 0; flex-direction: column; align-items: center; }

/* Tablet + mobile: both rails become slide-over drawers */
@media (max-width: 1023.98px) {
  .rail-batch {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(300px, 86vw);
    max-height: 100dvh;
    border-right: 1px solid var(--rule-strong);
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.28);
    transform: translateX(-100%);
    transition: transform 200ms ease;
    z-index: 100;
  }
  .rail-batch.is-open {
    transform: translateX(0);
  }
  .rail-side {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: min(300px, 86vw);
    max-height: 100dvh;
    border-left: 1px solid var(--rule-strong);
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.28);
    transform: translateX(100%);
    transition: transform 200ms ease;
    z-index: 100;
  }
  .rail-side.is-open {
    transform: translateX(0);
  }
  /* A desktop-collapsed rail must still open at full drawer width. */
  .rail-side.side-collapsed { width: min(300px, 86vw); }
  .rail-side.side-collapsed .rail-head,
  .rail-side.side-collapsed .settings-view,
  .rail-side.side-collapsed .details-view { display: flex; }
  .rail-side.side-collapsed .settings-view,
  .rail-side.side-collapsed .details-view { display: block; }
  #railCollapsed { display: none !important; }
  .app .body { position: relative; }
  .rail-head {
    position: sticky;
    top: 0;
    z-index: 1;
    background: var(--surface);
  }
}

/* Touch targets: keep every interactive control at least 40 px tall on
   coarse pointers and small screens. */
@media (max-width: 1023.98px), (pointer: coarse) {
  .iconbtn { width: 40px; height: 40px; }
  .iconbtn.tiny { width: 40px; height: 40px; }
  .seg-item { min-height: 40px; padding: 8px 12px; }
  .btn { min-height: 40px; padding: 8px 12px; }
  .btn.tiny { min-height: 40px; }
  .padbtn { width: 40px; height: 40px; }
  .pad { grid-template-columns: 40px 40px 40px; grid-auto-rows: 40px; }
  .switch { width: 40px; height: 22px; }
  .switch::after { width: 14px; height: 14px; }
  .switch[aria-checked="true"]::after { transform: translateX(18px); }
  .cbx { width: 20px; height: 20px; }
  .queue-row { min-height: 44px; }
  .divhandle { width: 44px; height: 44px; margin-left: -22px !important; margin-top: -22px !important; }
}

/* ---------- Stage ---------- */
.stage {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  overflow: hidden;
}
.toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  padding: 6px 10px;
  background: var(--surface);
  border-bottom: 1px solid var(--rule);
  flex: none;
}
.tb-actions { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }

/* ---------- Segmented control ---------- */
.seg {
  display: inline-flex;
  border: 1px solid var(--rule-strong);
  border-radius: var(--radius);
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
}
.seg::-webkit-scrollbar { display: none; }
.seg-item {
  padding: 4px 10px;
  background: transparent;
  color: var(--dim);
  cursor: pointer;
  border-right: 1px solid var(--rule-strong);
  white-space: nowrap;
}
.seg-item:last-child { border-right: 0; }
.seg-item:hover { background: var(--surface2); color: var(--text); }
.seg-item.is-active {
  background: var(--accent);
  color: var(--on-accent);
  font-weight: 600;
}
.seg-item:disabled {
  color: var(--faint);
  background: transparent;
  cursor: not-allowed;
}

/* ---------- Switch (30×16) ---------- */
.switch-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.switch-row.inline { padding: 0 4px; }
.switch-label { color: var(--dim); }
.switch {
  position: relative;
  width: 30px;
  height: 16px;
  flex: none;
  background: var(--surface2);
  border: 1px solid var(--rule-strong);
  border-radius: 2px; /* deliberately squared, not a pill */
  cursor: pointer;
}
.switch::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 10px;
  height: 10px;
  border-radius: 1px;
  background: var(--dim);
}
.switch:hover { border-color: var(--dim); }
.switch[aria-checked="true"] { background: var(--added-bg); border-color: var(--accent); }
.switch[aria-checked="true"]::after { background: var(--accent); transform: translateX(14px); }
.switch:disabled { opacity: 0.45; cursor: not-allowed; }
.switch:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Checkbox (14×14) ---------- */
.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}
.checkbox-row .cb-label { color: var(--dim); cursor: pointer; }
.cbx {
  position: relative;
  width: 14px;
  height: 14px;
  flex: none;
  background: var(--surface2);
  border: 1px solid var(--rule-strong);
  border-radius: 2px;
  cursor: pointer;
}
.cbx:hover { border-color: var(--dim); }
.cbx[aria-checked="true"] { background: var(--accent); border-color: var(--accent); }
.cbx[aria-checked="true"]::after {
  content: "";
  position: absolute;
  left: 3px;
  top: 4px;
  width: 6px;
  height: 3px;
  border-left: 1.6px solid var(--on-accent);
  border-bottom: 1.6px solid var(--on-accent);
  transform: rotate(-45deg);
}
.cbx:disabled { opacity: 0.45; cursor: not-allowed; }
.cbx:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--surface2);
  border: 1px solid var(--rule-strong);
  border-radius: var(--radius);
  padding: 4px 10px;
  font-family: var(--mono);
  font-size: calc(var(--ui) - 0.5px);
  color: var(--text);
  cursor: pointer;
  position: relative;
}
.btn:hover { background: var(--rule); border-color: var(--dim); }
.btn.is-active {
  background: var(--accent);
  color: var(--on-accent);
  border-color: var(--accent);
}
.btn:disabled {
  color: var(--faint);
  background: transparent;
  border-color: var(--rule);
  cursor: not-allowed;
}
.btn.tiny { padding: 2px 8px; font-size: calc(var(--ui) - 1px); }
/* primary actions keep a 44 px touch target via an invisible extension */
.compare-btn::after {
  content: "";
  position: absolute;
  inset: -7px;
}

.iconbtn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  color: var(--dim);
  cursor: pointer;
  position: relative;
  flex: none;
}
.iconbtn::after {
  content: "";
  position: absolute;
  inset: -2px; /* extends the 26 px visual to a ≥28 px hit target */
}
.iconbtn:hover {
  background: var(--surface2);
  border-color: var(--rule-strong);
  color: var(--text);
}
.iconbtn.is-active {
  background: var(--accent);
  color: var(--on-accent);
  border-color: var(--accent);
}
.iconbtn:disabled { color: var(--faint); cursor: not-allowed; }
.iconbtn.tiny { width: 20px; height: 20px; }

/* ---------- Chips ---------- */
.chip {
  display: inline-flex;
  align-items: center;
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 600;
  border-radius: var(--radius);
  padding: 3px 7px;
  white-space: nowrap;
  line-height: 1.2;
}
.chip.add { background: var(--added-bg); color: var(--added-text); }
.chip.rem { background: var(--removed-bg); color: var(--removed-text); }
.chip.same {
  background: transparent;
  color: var(--faint);
  border: 1px solid var(--rule);
  font-weight: 400;
}
.chip.chg { background: var(--changed-bg); color: var(--changed-text); }

/* ---------- Align bar ---------- */
.alignbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--rule);
  flex: none;
  flex-wrap: wrap;
}
.microlabel {
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--faint);
  white-space: nowrap;
}
.pad {
  display: grid;
  grid-template-columns: 24px 24px 24px;
  grid-auto-rows: 24px;
  gap: 2px;
}
.padbtn {
  width: 24px;
  height: 24px;
  border: 1px solid var(--rule-strong);
  border-radius: var(--radius);
  color: var(--dim);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  background: transparent;
}
.padbtn:hover { background: var(--surface2); color: var(--text); }
.offset-readout { min-width: 150px; text-align: left; }
.align-hint { white-space: nowrap; }

/* ---------- Empty state ---------- */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  flex: 1 1 auto;
  min-height: 180px;
  padding: 18px;
}
.empty-state[hidden] { display: none; }
.dropzone {
  border: 1.5px dashed var(--rule-strong);
  border-radius: var(--panel-radius);
  background: var(--surface);
  padding: 34px 30px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  text-align: center;
  cursor: pointer;
  max-width: 520px;
  width: 100%;
}
.dropzone:hover, .dropzone.is-drag { border-color: var(--accent); }
.drop-ic { color: var(--faint); }
.drop-title { font-size: 12px; font-weight: 650; }
.drop-prose { font-size: 13.5px; line-height: 22px; color: var(--dim); }
.recent-hint { font-size: 11.5px; }

/* ---------- Editors strip ---------- */
.editors {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 12px;
  padding: 12px;
  border-bottom: 1px solid var(--rule);
  flex: none;
}
.editors[hidden] { display: none; }
.epane {
  border: 1px solid var(--rule);
  border-radius: var(--panel-radius);
  background: var(--surface);
  padding: 10px;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  cursor: text;
  flex: 1;
  min-height: 0;
}
.ehead {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.ename {
  font-size: calc(var(--ui) - 2px);
  color: var(--dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ehead-spring { flex: 1; }

.etext {
  width: 100%;
  flex: 1 1 auto;
  min-height: 128px;
  height: clamp(140px, 24vh, 360px);
  height: clamp(140px, 24dvh, 360px);
  font-family: var(--mono);
  font-size: calc(var(--ui) - 0.5px);
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 6px 8px;
  white-space: pre;
  overflow: auto;
  scrollbar-width: thin;
}
.epane.is-wrap .etext { white-space: pre-wrap; overflow-wrap: anywhere; }
.etext::placeholder { color: var(--faint); }
.emid {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 0 2px;
}
.emid-spring { flex: 1; }

/* Mobile: stack editors vertically */
@media (max-width: 767.98px) {
  .editors {
    grid-template-columns: 1fr;
    gap: 12px;
  }
  .emid {
    flex-direction: row;
    justify-content: flex-end;
  }
  .emid-spring { display: none; }
  .filepair { display: none !important; }
  .offset-readout { min-width: 0; }
  .align-hint { display: none; }
}

/* ---------- Stats bar ---------- */
.statsbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 12px;
  border-top: 1px solid var(--rule);
  background: var(--surface);
  font-size: 10px;
  color: var(--dim);
  flex: none;
  min-height: 28px;
}
.stats-l, .stats-r {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  min-width: 0;
}
.stats-l { flex: 1; }
.stats-r { margin-left: auto; justify-content: flex-end; }
.stats-sep { color: var(--faint); }

/* ============================================================
   Diff rendering
   ============================================================ */
.diffarea {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.diffarea[hidden] { display: none; }
.diffwrap {
  flex: 1;
  min-height: 0;
  overflow: auto;
  background: var(--bg);
  scrollbar-width: thin;
}
.vlist {
  position: relative;
  overflow: hidden;
  font-size: 12px;
  line-height: 18px;
}
.vrow { position: absolute; left: 0; width: 100%; }

/* Hunk header */
.vrow-hunk {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--dim);
  background: var(--surface2);
  border-top: 1px solid var(--rule);
  border-bottom: 1px solid var(--rule);
  padding: 3px 16px;
  white-space: pre;
  overflow: hidden;
  text-overflow: ellipsis;
}
.vrow-hunk .h-sign { color: var(--faint); }

/* Fold bar */
.vrow-fold {
  display: block;
  width: 100%;
  text-align: left;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--faint);
  background: transparent;
  border-top: 1px solid var(--rule);
  border-bottom: 1px solid var(--rule);
  padding: 4px 16px;
  cursor: pointer;
  white-space: pre;
  overflow: hidden;
  text-overflow: ellipsis;
}
.vrow-fold:hover { color: var(--dim); background: var(--surface2); }

/* Split layout */
.drow {
  display: grid;
  grid-template-columns: 1fr 1fr;
  height: 100%;
}
.dcell {
  display: flex;
  min-width: 0;
  overflow: hidden;
  min-height: 0;
}
.dcell + .dcell { border-left: 1px solid var(--rule); }
.dcell.add { background: var(--added-bg); }
.dcell.del { background: var(--removed-bg); }
.dcell.gap {
  background-image: var(--hatch);
  background-color: var(--gap-bg);
}
.gut {
  flex: 0 0 58px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  padding-right: 6px;
  background: var(--surface2);
  border-right: 1px solid var(--rule);
  color: var(--faint);
  font-size: 11px;
  flex-shrink: 0;
}
.dcell.gap .gut { background: transparent; border-right-color: transparent; }
.mk { width: 1ch; text-align: center; flex: none; }
.dcell.del .mk { color: var(--removed-text); }
.dcell.add .mk { color: var(--added-text); }
.code {
  flex: 1;
  min-width: 0;
  padding: 0 14px;
  white-space: pre;
  overflow: hidden;
  text-overflow: clip;
}

/* Unified layout */
.urow {
  display: flex;
  height: 100%;
  min-width: 100%;
  width: max-content;
  min-height: 0;
}
.urow .gut { flex: 0 0 88px; }
.urow .no-old, .urow .no-new {
  width: 3ch;
  text-align: right;
  flex: none;
}
.urow .no-new { margin-right: 4px; }
.urow.ctx { background: transparent; }
.urow.add { background: var(--added-bg); }
.urow.del { background: var(--removed-bg); }
.urow.del .mk { color: var(--removed-text); }
.urow.add .mk { color: var(--added-text); }
.urow .code { flex: 1; }

/* Word marks */
mark.wadd, mark.wdel {
  border-radius: 1px;
  padding: 0;
  background: transparent;
  color: inherit;
}
.dcell.add mark.wadd, .urow.add mark.wadd { background: var(--added-word); color: var(--added-text); }
.dcell.del mark.wdel, .urow.del mark.wdel { background: var(--removed-word); color: var(--removed-text); }

/* Line-wrap mode: rows become content-height, virtualization is off */
.vlist.wrap { width: 100% !important; }
.vlist.wrap .vrow { position: static; height: auto !important; }
.vlist.wrap .code { white-space: pre-wrap; overflow-wrap: anywhere; }

/* Syntax tokens */
.tk-kw { color: var(--kw); }
.tk-str { color: var(--str); }
.tk-com { color: var(--com); font-style: italic; }
.tk-num { color: var(--num); }
.tk-fn { color: var(--fn); }
.tk-ty { color: var(--fn); }

/* ============================================================
   Image mode
   ============================================================ */
.imgarea {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: auto;
}
.imgarea[hidden] { display: none; }
.imgempty {
  flex: 1;
  min-height: 260px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.imgstage-ph {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: min(60%, 420px);
}
.skel-bar {
  display: block;
  height: 10px;
  border-radius: var(--panel-radius);
  background: var(--rule);
}
.skel-bar-1 { width: 72%; }
.skel-bar-2 { width: 48%; }
.skel-bar-3 { width: 60%; }
.imgstage {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 18px;
  gap: 12px;
}
.imgbox {
  flex: 1;
  min-height: 260px;
  max-width: none; /* fill available width */
  width: 100%;
  margin: 0;
  position: relative;
  overflow: hidden;
  border: 1px solid var(--rule);
  border-radius: var(--panel-radius);
  background:
    repeating-conic-gradient(var(--surface) 0% 25%, var(--bg) 0% 50%) 0 0 / 16px 16px;
}
.imgbox.is-pan { cursor: grab; }
.imgbox.is-panning { cursor: grabbing; }
.zoompan {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: 0 0;
}
.cvstack { position: relative; width: 100%; height: 100%; }
.cvstack canvas { display: block; width: 100%; height: 100%; }
.cvstack .fade-cv { position: absolute; inset: 0; width: 100%; height: 100%; }
.divhandle {
  position: absolute;
  top: 0;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--on-accent);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: ew-resize;
  box-shadow: 0 1px 6px rgba(0, 0, 0, 0.35);
  z-index: 3;
  touch-action: none;
}
.divhandle:hover { transform: scale(1.10); }
.divhandle.is-drag { transform: scale(0.94); }
.divhandle:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.div-line {
  position: absolute;
  background: var(--accent);
  opacity: 0.85;
  z-index: 2;
  pointer-events: none;
}
.boxes { position: absolute; inset: 0; pointer-events: none; }
.diff-box {
  position: absolute;
  border: 1px solid var(--changed-text);
  background: color-mix(in srgb, var(--changed-bg) 55%, transparent);
}
.diff-box .db-tag {
  position: absolute;
  top: -1px;
  left: -1px;
  transform: translateY(-100%);
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 600;
  padding: 1px 5px;
  border-radius: var(--radius);
  background: var(--changed-bg);
  color: var(--changed-text);
  white-space: nowrap;
}
.imgcontrols {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  justify-content: center;
  max-width: none;
  width: 100%;
  margin: 0 auto;
  flex: none;
}
.imgctl {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  color: var(--dim);
}
.imgctl .ctl-val { min-width: 44px; color: var(--faint); }
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 140px;
  height: 16px;
  background: transparent;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 2px;
  background: var(--rule-strong);
  border-radius: 1px;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 12px;
  height: 12px;
  margin-top: -5px;
  border-radius: 50%;
  background: var(--accent);
  border: 1px solid var(--accent);
}
input[type="range"]::-moz-range-track {
  height: 2px;
  background: var(--rule-strong);
  border-radius: 1px;
}
input[type="range"]::-moz-range-thumb {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--accent);
  border: 1px solid var(--accent);
}
input[type="range"]:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Details cards (Details compare mode, centre stage) */
.details-cards {
  max-width: none;
  width: 100%;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  flex: none;
}
/* Metadata comparison summary spans the full width above the per-file cards */
.exif-diff-card { grid-column: 1 / -1; }
.exif-compare { display: flex; flex-direction: column; }
.exif-diff { display: grid; grid-template-columns: minmax(80px, 1fr) 2fr 2fr; align-items: baseline; gap: 10px; }
.exif-diff .mk-key { color: var(--dim); }
.exif-diff .old-val { color: var(--faint); text-align: right; overflow-wrap: anywhere; }
.exif-diff .new-val { text-align: right; overflow-wrap: anywhere; }
.dcard {
  border: 1px solid var(--rule);
  border-radius: var(--panel-radius);
  background: var(--surface);
  padding: 10px;
  min-width: 0;
}
.dcard-head {
  font-size: 12px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--rule);
  margin-bottom: 4px;
}
.meta-row {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 5px 10px;
  font-size: calc(var(--ui) - 0.5px);
}
.meta-row .mk-key { color: var(--dim); flex: none; }
.meta-row .mk-val {
  margin-left: auto;
  font-family: var(--mono);
  text-align: right;
  overflow-wrap: anywhere;
  min-width: 0;
}
.meta-row .mk-val.faint { color: var(--faint); }
.chg {
  background: var(--changed-bg);
  color: var(--changed-text);
  border-radius: 1px;
  padding: 0 2px;
}

/* ---------- Settings rail ---------- */
.settings-view, .details-view { flex: 1; min-height: 0; }
.set-group {
  padding: 8px 10px;
  border-bottom: 1px solid var(--rule);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.set-group h4 {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--faint);
}
.set-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: calc(var(--ui) - 0.5px);
  color: var(--dim);
}
.set-row .row-label { flex: 1; cursor: pointer; }
.set-note {
  font-family: var(--sans);
  font-size: 11.5px;
  line-height: 18px;
  color: var(--faint);
  padding: 10px 12px;
}
.lang-select {
  border: 1px solid var(--rule-strong);
  border-radius: var(--radius);
  background: var(--surface2);
  color: var(--text);
  font-size: 11px;
  padding: 3px 6px;
  max-width: 100%;
}
.side-head .iconbtn { margin-left: auto; }

/* Details rail */
.dr-head {
  display: flex;
  align-items: center;
  padding: 8px 10px;
  border-bottom: 1px solid var(--rule);
}
.dr-head .rail-title { flex: 1; }
.dr-headline {
  font-size: 12px;
  padding: 10px 12px 0;
  overflow-wrap: anywhere;
}
.dr-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px 12px;
}
.dr-list { padding-bottom: 10px; }

/* ============================================================
   Responsive
   ============================================================ */
/* filepair visible only in the full three-column layout */
.filepair { display: none; }

@media (min-width: 1280px) {
  .filepair { display: block; }
  .queue-row .qrow-icon { display: flex; }
}

/* 1024–1279: filepair hidden, batch rail collapses to 46 px, settings 236 px */
@media (min-width: 1024px) and (max-width: 1279px) {
  .rail-batch { width: 46px; }
  .rail-batch .rail-title,
  .rail-batch .rail-head { display: none; }
  .queue-row {
    flex-direction: column;
    align-items: center;
    padding: 6px 4px;
    gap: 4px;
  }
  .queue-row .qrow-icon { display: flex; }
  .qrow-names { display: none; }
  .qrow-chips { align-items: center; }
  .qrow-remove { align-self: center; }
  .rail-side { width: 236px; }
  .seg-item { padding: 6px 8px; }
}

/* <768: stack the editor panes; rails are already drawers above */
@media (max-width: 767.98px) {
  .editors { grid-template-columns: 1fr; }
  .emid {
    flex-direction: row;
    justify-content: flex-end;
  }
  .emid-spring { display: none; }
  .filepair { display: none !important; }
  .offset-readout { min-width: 0; }
  .align-hint { display: none; }
  .etext { height: clamp(120px, 30dvh, 300px); }
}

/* Keep the app frame stable on tiny screens */
@media (max-width: 400px) {
  .dropzone { padding: 24px 16px; }
  .statsbar { flex-wrap: wrap; }
}

/* Mobile drawer overlay backdrop */
.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.3);
  z-index: 50;
  opacity: 0;
  visibility: hidden;
  transition: opacity 200ms ease, visibility 200ms ease;
}
.drawer-backdrop.is-open {
  opacity: 1;
  visibility: visible;
}