/* ---------- Tokens ---------- */
:root {
  --sans: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, 'Cascadia Mono', Consolas, monospace;

  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #f8f9fc;
  --surface-3: #eef1f7;
  --border: #e3e7ef;
  --border-strong: #cfd6e3;
  --text: #0f172a;
  --text-2: #334155;
  --muted: #64748b;

  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-text: #4f46e5;
  --primary-soft: #eef0ff;
  --on-primary: #ffffff;
  --ring: rgba(79, 70, 229, 0.28);

  --success: #059669;
  --success-soft: #e8f8f1;
  --warning: #b45309;
  --warning-soft: #fff6e6;
  --danger: #e11d48;
  --danger-soft: #fff0f3;
  --info: #0369a1;
  --info-soft: #ebf6fd;

  --blob-a: rgba(99, 102, 241, 0.20);
  --blob-b: rgba(20, 184, 166, 0.16);

  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 4px 16px -6px rgba(15, 23, 42, 0.12), 0 1px 3px rgba(15, 23, 42, 0.06);
  --shadow-lg: 0 18px 48px -18px rgba(15, 23, 42, 0.25);

  --radius: 16px;
  --radius-md: 12px;
  --radius-sm: 8px;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  color-scheme: light;
}

[data-theme="dark"] {
  --bg: #0a0f1c;
  --surface: #111827;
  --surface-2: #0e1523;
  --surface-3: #1a2336;
  --border: #212c42;
  --border-strong: #2d3a55;
  --text: #e7ebf3;
  --text-2: #c3cad8;
  --muted: #8b97ad;

  --primary: #6366f1;
  --primary-hover: #7c7ff5;
  --primary-text: #a5b4fc;
  --primary-soft: rgba(99, 102, 241, 0.14);
  --on-primary: #ffffff;
  --ring: rgba(129, 140, 248, 0.35);

  --success: #34d399;
  --success-soft: rgba(52, 211, 153, 0.12);
  --warning: #fbbf24;
  --warning-soft: rgba(251, 191, 36, 0.12);
  --danger: #fb7185;
  --danger-soft: rgba(251, 113, 133, 0.12);
  --info: #38bdf8;
  --info-soft: rgba(56, 189, 248, 0.12);

  --blob-a: rgba(99, 102, 241, 0.22);
  --blob-b: rgba(20, 184, 166, 0.12);

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 6px 20px -8px rgba(0, 0, 0, 0.6);
  --shadow-lg: 0 24px 60px -20px rgba(0, 0, 0, 0.7);
  color-scheme: dark;
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  font: 15px/1.55 var(--sans);
  color: var(--text);
  background: var(--bg);
  transition: background-color 0.3s ease, color 0.3s ease;
}
h1, h2, h3 { margin: 0; line-height: 1.2; letter-spacing: -0.02em; }
p { margin: 0; }
a { color: var(--primary-text); }
code { font-family: var(--mono); font-size: 0.88em; padding: 0.1em 0.35em; border-radius: 5px; background: var(--surface-3); }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.js .nojs-only, .no-js .js-only { display: none !important; }

.icon { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

/* Slow drifting colour behind everything */
.backdrop { position: fixed; inset: 0; z-index: -1; overflow: hidden; pointer-events: none; }
.blob { position: absolute; width: 46vmax; height: 46vmax; border-radius: 50%; filter: blur(80px); }
.blob-a { background: var(--blob-a); top: -18vmax; left: -10vmax; animation: drift-a 26s ease-in-out infinite alternate; }
.blob-b { background: var(--blob-b); bottom: -22vmax; right: -12vmax; animation: drift-b 32s ease-in-out infinite alternate; }
@keyframes drift-a { to { transform: translate(14vmax, 10vmax) scale(1.1); } }
@keyframes drift-b { to { transform: translate(-12vmax, -8vmax) scale(1.15); } }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--surface) 78%, transparent);
  backdrop-filter: saturate(160%) blur(14px);
  -webkit-backdrop-filter: saturate(160%) blur(14px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner { max-width: 1120px; margin: 0 auto; padding: 12px 24px; display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.brand { display: flex; align-items: center; gap: 12px; color: inherit; text-decoration: none; }
.brand-mark {
  width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center;
  background: linear-gradient(135deg, #6366f1, #14b8a6); color: #fff;
  box-shadow: 0 6px 16px -6px rgba(99, 102, 241, 0.7);
}
.brand-mark svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-name { font-weight: 700; letter-spacing: -0.01em; }
.brand-sub { font-size: 12px; color: var(--muted); }
.topbar-actions { display: flex; align-items: center; gap: 8px; }

/* ---------- Buttons ---------- */
.btn {
  --h: 40px;
  position: relative; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: var(--h); padding: 0 16px; border-radius: 10px; border: 1px solid transparent;
  font: 600 14px/1 var(--sans); cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: transform 0.15s var(--ease), box-shadow 0.2s ease, background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease, opacity 0.2s ease;
}
.btn:active:not(:disabled) { transform: translateY(1px) scale(0.99); }
.btn:disabled { cursor: not-allowed; opacity: 0.55; }
.btn-sm { --h: 32px; padding: 0 12px; font-size: 13px; border-radius: 8px; }
.btn-lg { --h: 48px; padding: 0 22px; font-size: 15px; border-radius: 12px; }
.btn-primary { background: var(--primary); color: var(--on-primary); box-shadow: 0 8px 20px -10px var(--primary); }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); transform: translateY(-1px); box-shadow: 0 12px 26px -12px var(--primary); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); box-shadow: var(--shadow-sm); }
.btn-secondary:hover:not(:disabled) { border-color: var(--primary); color: var(--primary-text); transform: translateY(-1px); }
.btn-ghost { background: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-3); color: var(--text); }
.btn-icon { width: var(--h); padding: 0; background: transparent; color: var(--text-2); border-color: var(--border); }
.btn-icon:hover { background: var(--surface-3); color: var(--text); }
.btn-icon.btn-sm { width: 32px; }

#theme-toggle .icon-moon, [data-theme="dark"] #theme-toggle .icon-sun { display: none; }
[data-theme="dark"] #theme-toggle .icon-moon { display: block; }
#theme-toggle .icon { transition: transform 0.5s var(--ease); }
#theme-toggle:hover .icon { transform: rotate(25deg); }

.spinner {
  display: none; width: 18px; height: 18px; border-radius: 50%;
  border: 2px solid currentColor; border-right-color: transparent;
  animation: spin 0.7s linear infinite;
}
.btn.is-loading { pointer-events: none; }
.btn.is-loading .spinner { display: inline-block; }
.btn.is-loading .icon { display: none; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Layout ---------- */
.shell { width: 100%; max-width: 1120px; margin: 0 auto; padding: 40px 24px 56px; display: flex; flex-direction: column; gap: 24px; flex: 1; }
.hero h1 { font-size: clamp(28px, 4vw, 38px); font-weight: 700; }
.hero .lead { margin-top: 10px; max-width: 720px; color: var(--text-2); font-size: 16px; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-md); padding: 28px;
  transition: background-color 0.3s ease, border-color 0.3s ease;
}
.card-flush { padding: 0; overflow: hidden; }

/* Entrance animation */
.reveal { animation: rise 0.7s var(--ease) both; }
.reveal:nth-child(2) { animation-delay: 0.06s; }
.reveal:nth-child(3) { animation-delay: 0.12s; }
.reveal:nth-child(5) { animation-delay: 0.18s; }
@keyframes rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }

/* ---------- Stepper ---------- */
.stepper { list-style: none; margin: 0; padding: 0; display: flex; align-items: center; gap: 12px; }
.step { display: flex; align-items: center; gap: 10px; color: var(--muted); font-weight: 600; font-size: 14px; }
.step-dot {
  width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; font-size: 13px;
  border: 1.5px solid var(--border-strong); background: var(--surface); color: var(--muted);
  transition: all 0.4s var(--ease);
}
.step.is-active { color: var(--text); }
.step.is-active .step-dot { border-color: var(--primary); color: var(--primary-text); box-shadow: 0 0 0 5px var(--ring); }
.step.is-done .step-dot { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.step.is-done { color: var(--text-2); }
.step-bar { flex: 1; height: 2px; border-radius: 2px; background: var(--border); overflow: hidden; min-width: 24px; }
.step-bar span { display: block; height: 100%; width: 0; background: var(--primary); transition: width 0.6s var(--ease); }
.step-bar.is-done span { width: 100%; }

/* ---------- Alerts ---------- */
.alert { display: flex; align-items: flex-start; gap: 10px; padding: 12px 14px; border-radius: var(--radius-md); font-weight: 500; margin-bottom: 20px; animation: pop 0.35s var(--ease); }
.alert .icon { margin-top: 2px; }
.alert-danger { background: var(--danger-soft); color: var(--danger); border: 1px solid color-mix(in srgb, var(--danger) 30%, transparent); }
@keyframes pop { from { opacity: 0; transform: scale(0.98); } to { opacity: 1; transform: none; } }

/* ---------- Drop zone ---------- */
.dropzone {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  padding: 40px 20px; text-align: center; cursor: pointer;
  border: 1.5px dashed var(--border-strong); border-radius: var(--radius);
  background:
    radial-gradient(circle at 50% 0%, var(--primary-soft), transparent 70%),
    var(--surface-2);
  transition: border-color 0.25s ease, background-color 0.25s ease, transform 0.25s var(--ease);
}
.dropzone input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.dropzone:hover, .dropzone:focus-within { border-color: var(--primary); }
.dropzone.is-dragging { border-color: var(--primary); border-style: solid; background-color: var(--primary-soft); transform: scale(1.01); }
.dropzone.is-dragging .dropzone-icon { animation: bob 0.9s ease-in-out infinite; }
.dropzone-icon {
  width: 56px; height: 56px; border-radius: 16px; display: grid; place-items: center; margin-bottom: 6px;
  color: var(--primary-text); background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-md);
}
.dropzone-icon svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.dropzone-title { font-weight: 600; font-size: 16px; }
.dropzone-hint { font-size: 13px; color: var(--muted); }
.link { color: var(--primary-text); text-decoration: underline; text-underline-offset: 3px; }
@keyframes bob { 50% { transform: translateY(-5px); } }

.file-chip {
  display: flex; align-items: center; gap: 12px; padding: 12px 12px 12px 14px;
  border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface-2);
  animation: slide-in 0.45s var(--ease);
}
.file-chip-icon { width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center; background: var(--success-soft); color: var(--success); }
.file-chip-icon svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.file-chip-text { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.file-chip-text strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-chip-text span { font-size: 13px; color: var(--muted); }
@keyframes slide-in { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }

/* ---------- Options ---------- */
.options { display: grid; grid-template-columns: 1fr 1.3fr; gap: 20px; margin-top: 24px; }
.field { display: flex; flex-direction: column; gap: 8px; min-width: 0; border: 0; margin: 0; padding: 0; }
.field > label, .field > legend { font-weight: 600; font-size: 14px; padding: 0; }
.field-hint { font-size: 13px; color: var(--muted); min-height: 1.4em; }
.select-wrap { position: relative; }
.select-wrap::after {
  content: ''; position: absolute; right: 14px; top: 50%; width: 8px; height: 8px; margin-top: -6px; pointer-events: none;
  border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); transform: rotate(45deg);
}
select, input[type="search"] {
  width: 100%; height: 42px; padding: 0 14px; border-radius: 10px;
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  font: 500 14px var(--sans); transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
select { appearance: none; padding-right: 36px; cursor: pointer; }
select:focus, input[type="search"]:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 4px var(--ring); }

.segmented { display: grid; grid-template-columns: repeat(4, 1fr); padding: 4px; gap: 4px; border-radius: 12px; background: var(--surface-3); border: 1px solid var(--border); }
.segment { position: relative; cursor: pointer; }
.segment input { position: absolute; opacity: 0; inset: 0; cursor: pointer; }
.segment span {
  display: grid; place-items: center; height: 34px; border-radius: 9px; font-weight: 600; font-size: 13px; color: var(--muted);
  transition: background-color 0.25s ease, color 0.25s ease, box-shadow 0.25s ease;
}
.segment:hover span { color: var(--text); }
.segment input:checked + span { background: var(--surface); color: var(--primary-text); box-shadow: var(--shadow-md); }
.segment input:focus-visible + span { outline: 2px solid var(--primary); outline-offset: 1px; }

.actions { display: flex; align-items: center; gap: 16px; margin-top: 28px; flex-wrap: wrap; }
.actions-hint { color: var(--muted); font-size: 14px; }

/* ---------- Results ---------- */
.results { display: flex; flex-direction: column; gap: 20px; animation: rise 0.6s var(--ease); }
.results-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; }
.results-head h2 { font-size: 22px; }
.results-head p { margin-top: 4px; font-size: 14px; }
.results.is-refreshing .stats, .results.is-refreshing .card { opacity: 0.55; transition: opacity 0.2s ease; }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.stat {
  position: relative; overflow: hidden; padding: 18px 20px; border-radius: var(--radius-md);
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-sm);
  animation: rise 0.6s var(--ease) both;
}
.stat:nth-child(2) { animation-delay: 0.05s; }
.stat:nth-child(3) { animation-delay: 0.1s; }
.stat:nth-child(4) { animation-delay: 0.15s; }
.stat::before { content: ''; position: absolute; inset: 0 auto 0 0; width: 3px; background: linear-gradient(#6366f1, #14b8a6); }
.stat-label { display: block; font-size: 13px; color: var(--muted); font-weight: 500; }
.stat-value { display: block; margin-top: 4px; font-size: 28px; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }

.tabs { position: relative; display: flex; gap: 4px; padding: 0 12px; border-bottom: 1px solid var(--border); background: var(--surface-2); overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  display: inline-flex; align-items: center; gap: 8px; height: 50px; padding: 0 14px; border: 0; background: none; cursor: pointer;
  font: 600 14px var(--sans); color: var(--muted); transition: color 0.2s ease;
}
.tab:hover, .tab.is-active { color: var(--text); }
.count {
  min-width: 22px; height: 22px; padding: 0 7px; border-radius: 11px; display: inline-grid; place-items: center;
  font-size: 12px; background: var(--surface-3); color: var(--text-2); font-variant-numeric: tabular-nums;
}
.tab.has-warnings .count { background: var(--warning-soft); color: var(--warning); }
.tab.has-differences .count { background: var(--info-soft); color: var(--info); }
.tab-indicator { position: absolute; bottom: -1px; left: 0; height: 2px; width: 0; border-radius: 2px; background: var(--primary); transition: transform 0.35s var(--ease), width 0.35s var(--ease); }

.panel { display: none; padding: 20px; }
.panel.is-active { display: block; animation: fade 0.35s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.panel-tools { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.search { position: relative; flex: 1; max-width: 380px; }
.search .icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.search input { padding-left: 38px; }
.panel-foot { display: flex; justify-content: center; margin-top: 14px; }
.panel-foot:empty { display: none; }

.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius-md); }
table.records { width: 100%; border-collapse: collapse; font-size: 14px; }
.records th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); font-weight: 600; padding: 10px 14px; background: var(--surface-2); border-bottom: 1px solid var(--border); white-space: nowrap; }
.records td { padding: 12px 14px; border-bottom: 1px solid var(--border); vertical-align: top; }
.records .num { text-align: right; font-variant-numeric: tabular-nums; }
.records tr.record-row { cursor: pointer; transition: background-color 0.15s ease; animation: fade 0.35s ease both; }
.records tr.record-row:hover, .records tr.record-row.is-open { background: var(--surface-2); }
.records tbody tr:last-child td { border-bottom: 0; }
.record-title { font-weight: 600; }
.record-title .badge { margin-left: 6px; }
.record-sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.mono { font-family: var(--mono); font-size: 13px; }
.records td.mono { white-space: nowrap; }
.records td.idx { color: var(--muted); font-variant-numeric: tabular-nums; width: 48px; }
.records tr.detail-row td { padding: 0; background: var(--surface-2); }

.badge { display: inline-flex; align-items: center; gap: 4px; height: 20px; padding: 0 8px; border-radius: 10px; font-size: 11.5px; font-weight: 600; vertical-align: 2px; }
.badge-info { background: var(--info-soft); color: var(--info); }
.badge-success { background: var(--success-soft); color: var(--success); }
.badge-muted { background: var(--surface-3); color: var(--text-2); }

/* MARC view: expands smoothly */
.marc-wrap { display: grid; grid-template-rows: 0fr; transition: grid-template-rows 0.35s var(--ease); }
.marc-wrap.is-open { grid-template-rows: 1fr; }
.marc-wrap > div { overflow: hidden; }
.marc { margin: 0; padding: 16px 20px; font: 13px/1.7 var(--mono); color: var(--text-2); white-space: pre-wrap; word-break: break-word; border-top: 1px dashed var(--border); }
.marc .m-tag { color: var(--primary-text); font-weight: 600; }
.marc .m-ind { color: var(--muted); }
.marc .m-code { color: var(--success); font-weight: 600; }

/* Differences and warnings */
.stack { display: flex; flex-direction: column; gap: 12px; }
.diff-card, .issue-group { border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface); animation: fade 0.35s ease both; }
.diff-card { padding: 16px 18px; }
.diff-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.diff-head strong { font-size: 15px; }
.diff-field { margin-top: 12px; display: grid; grid-template-columns: 170px 1fr; gap: 12px; }
.diff-field-name .mono { color: var(--primary-text); font-weight: 600; }
.diff-field-name .muted { display: block; font-size: 12.5px; }
.diff-values { display: flex; flex-direction: column; gap: 6px; }
.diff-value { display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: 8px; background: var(--surface-2); font-size: 14px; }
.diff-value.is-kept { background: var(--success-soft); }
.diff-row { color: var(--muted); font-size: 12.5px; white-space: nowrap; font-variant-numeric: tabular-nums; }

.issue-group > summary { list-style: none; display: flex; align-items: center; gap: 12px; padding: 14px 16px; cursor: pointer; }
.issue-group > summary::-webkit-details-marker { display: none; }
.issue-group[open] > summary { border-bottom: 1px solid var(--border); }
.issue-icon { width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center; flex: none; }
.issue-icon svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.level-warning .issue-icon { background: var(--warning-soft); color: var(--warning); }
.level-info .issue-icon { background: var(--info-soft); color: var(--info); }
.issue-title { flex: 1; font-weight: 600; }
.issue-title .muted { display: block; font-weight: 400; font-size: 13px; }
.chevron { transition: transform 0.3s var(--ease); color: var(--muted); }
details[open] > summary .chevron { transform: rotate(180deg); }
.issue-list { list-style: none; margin: 0; padding: 6px 16px 12px; max-height: 320px; overflow: auto; }
.issue-list li { display: flex; gap: 12px; padding: 7px 0; border-bottom: 1px dashed var(--border); font-size: 14px; }
.issue-list li:last-child { border-bottom: 0; }

.empty { display: flex; flex-direction: column; align-items: center; gap: 10px; text-align: center; padding: 36px 16px; color: var(--muted); }
.empty-icon { width: 52px; height: 52px; border-radius: 50%; display: grid; place-items: center; background: var(--success-soft); color: var(--success); animation: pop 0.5s var(--ease); }
.empty-icon svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.empty strong { color: var(--text); }

/* Download bar */
.download-bar {
  position: sticky; bottom: 16px; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  padding: 16px 18px 16px 22px; border-radius: var(--radius);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--border); box-shadow: var(--shadow-lg);
}
.download-text { display: flex; flex-direction: column; }
.download-text .muted { font-size: 13px; }
.download-actions { display: flex; gap: 10px; flex-wrap: wrap; }

/* Loading skeleton while the preview is prepared */
.skeleton { position: relative; overflow: hidden; background: var(--surface-3); border-radius: 8px; color: transparent !important; }
.skeleton::after {
  content: ''; position: absolute; inset: 0; transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, color-mix(in srgb, var(--surface) 70%, transparent), transparent);
  animation: shimmer 1.2s infinite;
}
@keyframes shimmer { to { transform: translateX(100%); } }

/* ---------- Reference ---------- */
.reference { padding: 0; }
.reference > summary { list-style: none; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 18px 24px; cursor: pointer; }
.reference > summary::-webkit-details-marker { display: none; }
.reference[open] > summary { border-bottom: 1px solid var(--border); }
.reference-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; padding: 20px 24px 8px; }
.reference-group { padding: 14px 16px; border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface-2); }
.reference-group h3 { font-size: 14px; display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.tag { font-family: var(--mono); font-size: 12px; padding: 2px 7px; border-radius: 6px; background: var(--primary-soft); color: var(--primary-text); }
.reference-group dl { margin: 0; display: flex; flex-direction: column; gap: 4px; }
.reference-group dl div { display: grid; grid-template-columns: 58px 1fr; gap: 8px; font-size: 13px; }
.reference-group dt { font-family: var(--mono); color: var(--text-2); }
.reference-group dd { margin: 0; color: var(--muted); }
.reference-note { padding: 8px 24px 20px; }

/* ---------- Footer & toasts ---------- */
.footer { display: flex; justify-content: center; gap: 14px; padding: 20px 24px 28px; font-size: 13px; color: var(--text-2); }

.toasts { position: fixed; right: 20px; bottom: 20px; z-index: 50; display: flex; flex-direction: column; gap: 10px; max-width: min(380px, calc(100vw - 40px)); }
.toast {
  position: relative; overflow: hidden; display: flex; align-items: flex-start; gap: 10px; padding: 14px 16px;
  border-radius: var(--radius-md); background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-lg);
  animation: toast-in 0.45s var(--ease);
}
.toast.is-leaving { animation: toast-out 0.3s ease forwards; }
.toast .icon { margin-top: 1px; }
.toast-success .icon { color: var(--success); }
.toast-error .icon { color: var(--danger); }
.toast::after { content: ''; position: absolute; left: 0; bottom: 0; height: 3px; width: 100%; background: var(--primary); transform-origin: left; animation: toast-timer 4.5s linear forwards; }
@keyframes toast-in { from { opacity: 0; transform: translateY(12px) scale(0.97); } to { opacity: 1; transform: none; } }
@keyframes toast-out { to { opacity: 0; transform: translateX(24px); } }
@keyframes toast-timer { to { transform: scaleX(0); } }

/* ---------- Navigation ---------- */
.nav { display: flex; gap: 4px; margin-left: 28px; margin-right: auto; }
.nav-link {
  position: relative; display: inline-flex; align-items: center; height: 36px; padding: 0 14px; border-radius: 9px;
  font-weight: 600; font-size: 14px; color: var(--muted); text-decoration: none;
  transition: color 0.2s ease, background-color 0.2s ease;
}
.nav-link:hover { color: var(--text); background: var(--surface-3); }
.nav-link.is-active { color: var(--primary-text); background: var(--primary-soft); }

/* ---------- Text inputs ---------- */
input[type="text"] {
  width: 100%; height: 42px; padding: 0 14px; border-radius: 10px;
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  font: 500 14px var(--sans); transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
input[type="text"]:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 4px var(--ring); }
input[type="text"]::placeholder { color: var(--muted); opacity: 0.7; }
input[type="checkbox"] { accent-color: var(--primary); width: 16px; height: 16px; margin: 0; cursor: pointer; }

.alert-success { background: var(--success-soft); color: var(--success); border: 1px solid color-mix(in srgb, var(--success) 30%, transparent); margin-bottom: 0; }

/* ---------- Merge checklist ---------- */
.merge-picker { margin-top: 22px; border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface-2); }
.merge-picker > summary { list-style: none; display: flex; align-items: center; gap: 12px; padding: 14px 16px; cursor: pointer; }
.merge-picker > summary::-webkit-details-marker { display: none; }
.merge-picker[open] > summary { border-bottom: 1px solid var(--border); }
.merge-title { flex: 1; display: flex; flex-direction: column; gap: 2px; font-size: 14px; }
.merge-body { padding: 14px 16px 16px; animation: fade 0.3s ease; }
.merge-tools { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 14px; flex-wrap: wrap; }
.merge-tools .field-hint { flex: 1; min-width: 240px; }
.merge-buttons { display: flex; gap: 6px; }
.merge-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px; max-height: 360px; overflow: auto; padding-right: 4px; }
.merge-group { padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); }
.merge-tag-label { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 600; cursor: pointer; }
.merge-tag-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.merge-options { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; padding-left: 24px; }
.merge-option {
  display: inline-flex; align-items: center; gap: 5px; height: 26px; padding: 0 8px; border-radius: 7px; cursor: pointer;
  font: 600 12.5px var(--mono); color: var(--text-2); background: var(--surface-3); border: 1px solid transparent;
  transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}
.merge-option input { width: 13px; height: 13px; }
.merge-option:has(input:checked) { background: var(--primary-soft); color: var(--primary-text); border-color: color-mix(in srgb, var(--primary) 25%, transparent); }

/* ---------- Fields page ---------- */
.fields-layout { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); gap: 24px; align-items: start; }
.field-form, .added-fields { display: flex; flex-direction: column; gap: 20px; }
.field-form h2, .added-fields h2 { font-size: 18px; display: flex; align-items: center; gap: 10px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px 16px; }
.ind-inputs { display: flex; gap: 8px; }
.ind-inputs input { width: 56px; text-align: center; font-family: var(--mono); }
.segmented-2 { grid-template-columns: repeat(2, 1fr); }
.field-form .actions { margin-top: 4px; }
.added-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.added-item {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 16px;
  border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface-2);
  animation: rise 0.45s var(--ease) both; transition: border-color 0.2s ease, transform 0.2s var(--ease);
}
.added-item:hover { border-color: var(--border-strong); transform: translateY(-1px); }
.added-item.is-editing { border-color: var(--primary); box-shadow: 0 0 0 4px var(--ring); }
.added-main { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.added-title { display: flex; align-items: center; gap: 8px; }
.added-meta { color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }
.added-badges { display: flex; gap: 6px; flex-wrap: wrap; }
.added-actions { display: flex; gap: 6px; flex: none; }
.added-actions form { margin: 0; }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); color: var(--danger); }
.empty-icon svg path { stroke: currentColor; }

/* ---------- Sign-in ---------- */
.sign-out { margin: 0; }
input[type="password"] {
  width: 100%; height: 46px; padding: 0 14px; border-radius: 10px;
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  font: 500 15px var(--sans); transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
input[type="password"]:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 4px var(--ring); }
.auth-wrap { flex: 1; display: grid; place-items: center; padding: 24px 0; }
.auth-card { width: 100%; max-width: 420px; display: flex; flex-direction: column; gap: 16px; text-align: left; }
.auth-card h1 { font-size: 26px; }
.auth-card .alert { margin-bottom: 0; }
.auth-card .btn-lg { width: 100%; }
.auth-icon {
  width: 52px; height: 52px; border-radius: 15px; display: grid; place-items: center; color: #fff;
  background: linear-gradient(135deg, #6366f1, #14b8a6); box-shadow: 0 10px 24px -10px rgba(99, 102, 241, 0.8);
  animation: pop 0.5s var(--ease);
}
.auth-icon svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.setup-steps { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 8px; color: var(--text-2); }

/* ---------- Small screens ---------- */
@media (max-width: 900px) {
  .fields-layout { grid-template-columns: 1fr; }
}
@media (max-width: 820px) {
  .options { grid-template-columns: 1fr; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .diff-field { grid-template-columns: 1fr; gap: 6px; }
}
@media (max-width: 560px) {
  .shell { padding: 24px 16px 40px; }
  .topbar-inner { padding: 10px 16px; }
  .card { padding: 20px; }
  .hide-sm { display: none; }
  .step-label { display: none; }
  .segmented { grid-template-columns: repeat(2, 1fr); }
  .tabs { padding: 0 6px; gap: 0; }
  .tab { padding: 0 6px; gap: 5px; font-size: 13px; flex: none; }
  .count { min-width: 18px; height: 19px; padding: 0 5px; font-size: 11px; }
  .panel { padding: 16px; }
  .search { flex-basis: 100%; max-width: none; }
  .brand-text { display: none; }
  .nav { margin-left: 8px; }
  .nav-link { padding: 0 10px; }
  .form-grid { grid-template-columns: 1fr; }
  .added-item { flex-direction: column; align-items: stretch; }
  .download-bar { padding: 14px; }
  .download-actions, .download-actions .btn { flex: 1; }
}

/* ---------- Respect reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
  .blob { animation: none; }
}
