/* Site Compare — mobile-first, no build step, no framework. */

:root {
  --bg: #f4f5f8;
  --surface: #ffffff;
  --surface-2: #fafbfc;
  --text: #12151b;
  --muted: #626a78;
  --faint: #8d95a3;
  --border: #e2e5ea;
  --border-strong: #cfd4dc;

  --site-a: #2563eb;
  --site-b: #c2410c;
  --conflict: #dc2626;
  --missing: #7c3aed;
  --differs: #0e7490;
  --agree: #15803d;
  --added: #15803d;
  --removed: #b91c1c;

  --shadow: 0 1px 2px rgba(16, 20, 28, .06), 0 4px 14px rgba(16, 20, 28, .05);
  --radius: 14px;
  --radius-sm: 10px;
  --header-h: 58px;
  --tab-h: 56px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1116;
    --surface: #161a21;
    --surface-2: #1b2028;
    --text: #e7eaf0;
    --muted: #9aa3b2;
    --faint: #7b8494;
    --border: #262c36;
    --border-strong: #333b47;

    --site-a: #60a5fa;
    --site-b: #fb923c;
    --conflict: #f87171;
    --missing: #a78bfa;
    --differs: #22d3ee;
    --agree: #4ade80;
    --added: #4ade80;
    --removed: #f87171;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 6px 18px rgba(0, 0, 0, .25);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overscroll-behavior-y: contain;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  display: flex;
  flex-direction: column;
}

svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }

/* --- chrome ------------------------------------------------------------- */

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: var(--header-h);
  padding: 8px 14px;
  padding-top: max(8px, env(safe-area-inset-top));
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--border);
}

.app-header-titles { flex: 1; min-width: 0; }

.app-header h1 {
  margin: 0;
  font-size: 19px;
  font-weight: 680;
  letter-spacing: -.015em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.app-header-subtitle {
  margin: 1px 0 0;
  font-size: 12.5px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.icon-button {
  flex: none;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  margin-left: -6px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
}
.icon-button:active { background: var(--border); }

.run-button {
  flex: none;
  height: 34px;
  padding: 0 14px;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
}
.run-button:disabled { opacity: .5; cursor: default; }
.run-button.busy .run-button-label::after {
  content: "";
  display: inline-block;
  width: 9px;
  height: 9px;
  margin-left: 7px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin .7s linear infinite;
  vertical-align: -1px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.view {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 14px 14px calc(var(--tab-h) + env(safe-area-inset-bottom) + 24px);
  outline: none;
}

.tab-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  height: calc(var(--tab-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: saturate(180%) blur(14px);
  border-top: 1px solid var(--border);
}

.tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: var(--faint);
  text-decoration: none;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: .01em;
}
.tab svg { width: 21px; height: 21px; }
.tab[aria-current="page"] { color: var(--site-a); }

.banner {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 14px;
  padding-top: max(7px, env(safe-area-inset-top));
  background: #92400e;
  color: #fff;
  font-size: 12.5px;
  font-weight: 550;
}
.banner-dot { width: 7px; height: 7px; border-radius: 50%; background: #fbbf24; flex: none; }

/* --- primitives --------------------------------------------------------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 12px;
  overflow: hidden;
}

.card-pad { padding: 14px; }

.section-title {
  margin: 20px 2px 8px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--faint);
}
.section-title:first-child { margin-top: 4px; }

.headline {
  margin: 0;
  font-size: 19px;
  font-weight: 640;
  line-height: 1.32;
  letter-spacing: -.015em;
}

.meta { color: var(--muted); font-size: 12.5px; margin: 6px 0 0; }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border-top: 1px solid var(--border);
}
.stat {
  padding: 11px 8px;
  text-align: center;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  background: none;
  font: inherit;
  color: inherit;
  cursor: pointer;
  text-decoration: none;
  display: block;
}
.stat:nth-child(3n) { border-right: 0; }
.stat:nth-last-child(-n+3) { border-bottom: 0; }
.stat-value { display: block; font-size: 21px; font-weight: 680; letter-spacing: -.02em; line-height: 1.15; }
.stat-label { display: block; font-size: 11px; color: var(--muted); margin-top: 2px; }
.stat-value.zero { color: var(--faint); font-weight: 600; }

.row {
  display: flex;
  align-items: flex-start;
  gap: 11px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  color: inherit;
  text-decoration: none;
  background: none;
  border-left: 0; border-right: 0; border-top: 0;
  width: 100%;
  text-align: left;
  font: inherit;
  cursor: pointer;
}
.row:last-child { border-bottom: 0; }
.row:active { background: var(--surface-2); }
.row-body { flex: 1; min-width: 0; }
.row-title { font-weight: 600; font-size: 14.5px; line-height: 1.35; overflow-wrap: anywhere; }
.row-sub { color: var(--muted); font-size: 12.5px; margin-top: 3px; overflow-wrap: anywhere; }
.row-chevron { flex: none; color: var(--faint); align-self: center; }
.row-chevron svg { width: 18px; height: 18px; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 650;
  letter-spacing: .01em;
  white-space: nowrap;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--muted);
}
.pill.conflict { color: var(--conflict); border-color: color-mix(in srgb, var(--conflict) 35%, transparent); background: color-mix(in srgb, var(--conflict) 9%, transparent); }
.pill.missing  { color: var(--missing);  border-color: color-mix(in srgb, var(--missing) 35%, transparent);  background: color-mix(in srgb, var(--missing) 9%, transparent); }
.pill.differs  { color: var(--differs);  border-color: color-mix(in srgb, var(--differs) 35%, transparent);  background: color-mix(in srgb, var(--differs) 9%, transparent); }
.pill.agree    { color: var(--agree);    border-color: color-mix(in srgb, var(--agree) 35%, transparent);    background: color-mix(in srgb, var(--agree) 9%, transparent); }
.pill.added    { color: var(--added);    border-color: color-mix(in srgb, var(--added) 35%, transparent);    background: color-mix(in srgb, var(--added) 9%, transparent); }
.pill.removed  { color: var(--removed);  border-color: color-mix(in srgb, var(--removed) 35%, transparent);  background: color-mix(in srgb, var(--removed) 9%, transparent); }
.pill.site-a   { color: var(--site-a);   border-color: color-mix(in srgb, var(--site-a) 35%, transparent);   background: color-mix(in srgb, var(--site-a) 9%, transparent); }
.pill.site-b   { color: var(--site-b);   border-color: color-mix(in srgb, var(--site-b) 35%, transparent);   background: color-mix(in srgb, var(--site-b) 9%, transparent); }

.pill-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 7px; }

.chips {
  display: flex;
  gap: 7px;
  overflow-x: auto;
  padding: 2px 0 10px;
  scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none;
  padding: 6px 13px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  white-space: nowrap;
}
.chip[aria-pressed="true"] {
  background: var(--text);
  border-color: var(--text);
  color: var(--surface);
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 42px;
  padding: 0 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  font-size: 14.5px;
  cursor: pointer;
  text-decoration: none;
}
.button.primary { background: var(--site-a); border-color: var(--site-a); color: #fff; }
.button.danger { color: var(--conflict); border-color: color-mix(in srgb, var(--conflict) 40%, transparent); }
.button.wide { width: 100%; }
.button:disabled { opacity: .5; cursor: default; }
.button svg { width: 18px; height: 18px; }

.button-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.button-row .button { flex: 1; min-width: 120px; }

.field { margin-bottom: 12px; }
.field label { display: block; font-size: 12.5px; font-weight: 650; color: var(--muted); margin-bottom: 5px; }
.field .hint { font-size: 12px; color: var(--faint); margin-top: 5px; line-height: 1.4; }

input[type="text"], input[type="url"], input[type="time"], input[type="number"], select, textarea {
  width: 100%;
  padding: 10px 11px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 15px;
}
textarea { resize: vertical; min-height: 78px; }
input[type="text"].mono, textarea.mono { font-family: var(--mono); font-size: 13px; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--site-a) 45%, transparent); outline-offset: 1px; }

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}
.switch-row:last-child { border-bottom: 0; }
.switch-row .switch-label { font-weight: 600; font-size: 14.5px; }
.switch-row .switch-sub { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.switch input { width: 46px; height: 27px; }

.empty {
  padding: 34px 20px;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
}
.empty strong { display: block; color: var(--text); font-size: 15.5px; margin-bottom: 5px; }

.loading { padding: 40px; text-align: center; color: var(--faint); }

/* --- comparison table --------------------------------------------------- */

.compare-head {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1px;
  background: var(--border);
  border-bottom: 1px solid var(--border);
}
.compare-head div {
  background: var(--surface-2);
  padding: 8px 12px;
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
}
.compare-head .a { color: var(--site-a); }
.compare-head .b { color: var(--site-b); }

.compare-field { border-bottom: 1px solid var(--border); }
.compare-field:last-child { border-bottom: 0; }
.compare-field-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 9px 12px 3px;
}
.compare-field-name { font-size: 12px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--faint); }
.compare-values { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding: 3px 12px 11px; }
.compare-value { font-size: 14.5px; overflow-wrap: anywhere; }
.compare-value.empty-value { color: var(--faint); font-style: italic; }
.compare-field.k-conflict { background: color-mix(in srgb, var(--conflict) 6%, transparent); }
.compare-field.k-missing_a, .compare-field.k-missing_b { background: color-mix(in srgb, var(--missing) 6%, transparent); }
.compare-field.k-differs { background: color-mix(in srgb, var(--differs) 6%, transparent); }
.compare-field .history-button {
  border: 0; background: none; color: var(--site-a); font: inherit; font-size: 12px;
  font-weight: 650; cursor: pointer; padding: 0 12px 10px;
}

.timeline { padding: 0 12px 12px; }
.timeline-row {
  display: grid;
  grid-template-columns: 74px 1fr;
  gap: 10px;
  padding: 6px 0;
  border-top: 1px dashed var(--border);
  font-size: 13px;
  align-items: baseline;
}
.timeline-date { color: var(--faint); font-size: 12px; font-variant-numeric: tabular-nums; }
.timeline-state { font-weight: 600; }
.timeline-values { color: var(--muted); font-size: 12.5px; margin-top: 1px; overflow-wrap: anywhere; }

/* --- misc --------------------------------------------------------------- */

.delta { font-variant-numeric: tabular-nums; font-weight: 650; }
.delta.up { color: var(--conflict); }
.delta.down { color: var(--agree); }

.event-list .row { align-items: flex-start; }
.event-dot { width: 8px; height: 8px; border-radius: 50%; margin-top: 6px; flex: none; background: var(--faint); }
.event-dot.item_added, .event-dot.item_returned { background: var(--added); }
.event-dot.item_removed { background: var(--removed); }
.event-dot.difference_appeared, .event-dot.difference_changed { background: var(--conflict); }
.event-dot.difference_resolved { background: var(--agree); }
.event-dot.item_changed { background: var(--differs); }
.event-dot.match_added { background: var(--site-a); }
.event-dot.unit_normalised,
.event-dot.vocabulary_differs { background: var(--missing); }

.photo-strip { display: flex; gap: 8px; overflow-x: auto; padding: 12px; }
.photo-strip img { width: 96px; height: 96px; object-fit: cover; border-radius: var(--radius-sm); border: 1px solid var(--border); flex: none; }

.note { padding: 11px 14px; border-bottom: 1px solid var(--border); font-size: 14px; }
.note:last-child { border-bottom: 0; }
.note-time { color: var(--faint); font-size: 11.5px; margin-top: 4px; }

.preview-item { padding: 11px 14px; border-bottom: 1px solid var(--border); font-size: 13.5px; }
.preview-item:last-child { border-bottom: 0; }
.preview-kv { display: grid; grid-template-columns: 92px 1fr; gap: 4px 10px; margin-top: 5px; }
.preview-kv dt { color: var(--faint); font-size: 12px; }
.preview-kv dd { margin: 0; overflow-wrap: anywhere; font-size: 13px; }

.code { font-family: var(--mono); font-size: 12.5px; background: var(--surface-2); padding: 2px 5px; border-radius: 5px; border: 1px solid var(--border); overflow-wrap: anywhere; }

/* --- toast + modal ------------------------------------------------------ */

.toast-host {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(var(--tab-h) + env(safe-area-inset-bottom) + 12px);
  z-index: 60;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.toast {
  background: #1f242c;
  color: #fff;
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  font-weight: 550;
  box-shadow: 0 8px 26px rgba(0, 0, 0, .3);
  animation: toast-in .18s ease-out;
}
.toast.error { background: #991b1b; }
.toast.success { background: #14532d; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

.modal-host {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(8, 10, 14, .45);
  padding: 16px;
  padding-bottom: max(16px, env(safe-area-inset-bottom));
}
.modal {
  width: 100%;
  max-width: 460px;
  background: var(--surface);
  border-radius: 18px;
  padding: 18px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, .35);
  animation: modal-in .2s ease-out;
  max-height: 80vh;
  overflow-y: auto;
}
@keyframes modal-in { from { opacity: 0; transform: translateY(18px); } }
.modal h2 { margin: 0 0 6px; font-size: 17px; font-weight: 660; }
.modal p { margin: 0 0 14px; color: var(--muted); font-size: 14px; line-height: 1.45; }

[hidden] { display: none !important; }
