/* ============================================================================
   Evidence Atlas — design system
   Aesthetic: field-atlas / archival cartography. Ink-navy ground, brass
   wayfinding accent, four distinct relation hues encode graph semantics.
   ========================================================================== */

@media (prefers-reduced-motion: no-preference) {
  :root { --motion-ok: 1; }
}

:root {
  color-scheme: dark;

  /* ---- surfaces ---- */
  --bg: #0e1016;
  --bg-soft: #12141c;
  --panel: #181b26;
  --panel-raised: #1f2330;
  --card: #1b1e2a;
  --card-hover: #232738;
  --border: #2b2f40;
  --border-soft: #22263352;
  --scrim: rgba(8, 9, 13, 0.72);

  /* ---- ink ---- */
  --ink: #ece8dc;
  --ink-dim: #a8adc2;
  --ink-muted: #9195ab;
  --ink-faint: #666a80;

  /* ---- wayfinding accent (chrome only, never data-encoding) ---- */
  --brass: #c9a55c;
  --brass-soft: #c9a55c26;
  --brass-ink: #14120a;

  /* ---- relation / semantic colors ---- */
  --rel-supports: #52b78a;
  --rel-supports-soft: #52b78a22;
  --rel-contradicts: #e2707a;
  --rel-contradicts-soft: #e2707a22;
  --rel-depends: #8b93e0;
  --rel-depends-soft: #8b93e022;
  --rel-context: #dba24e;
  --rel-context-soft: #dba24e22;

  /* ---- node kinds ---- */
  --node-source: #7fb3c9;
  --node-claim: #e0c26a;

  --radius-sm: 5px;
  --radius-md: 9px;
  --radius-lg: 14px;
  --shadow-panel: 0 12px 40px -12px rgba(0,0,0,0.55);
  --shadow-card: 0 1px 0 rgba(255,255,255,0.03) inset, 0 6px 18px -10px rgba(0,0,0,0.5);

  --font-display: "Fraunces", "Iowan Old Style", Georgia, serif;
  --font-body: "Public Sans", -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: "IBM Plex Mono", "SFMono-Regular", Menlo, monospace;
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    color-scheme: light;
    --bg: #e8e4d9;
    --bg-soft: #eeeadf;
    --panel: #f3f0e6;
    --panel-raised: #faf8f1;
    --card: #f7f4ea;
    --border: #d6d0bd;
    --border-soft: #d6d0bd66;
    --scrim: rgba(30, 27, 18, 0.35);

    --ink: #211f18;
    --ink-dim: #4b4736;
    --ink-muted: #6b674f;
    --ink-faint: #8b876d;

    --brass: #92662c;
    --brass-soft: #92662c1c;
    --brass-ink: #fbf6ea;

    --rel-supports: #227a56;
    --rel-supports-soft: #227a561a;
    --rel-contradicts: #b23a44;
    --rel-contradicts-soft: #b23a441a;
    --rel-depends: #4652b0;
    --rel-depends-soft: #4652b01a;
    --rel-context: #97671c;
    --rel-context-soft: #97671c1a;

    --node-source: #2c7690;
    --node-claim: #97671c;

    --shadow-panel: 0 12px 30px -14px rgba(40, 32, 10, 0.35);
    --shadow-card: 0 1px 0 rgba(255,255,255,0.6) inset, 0 4px 14px -8px rgba(60, 50, 20, 0.25);
  }
}
[data-theme="light"] {
  color-scheme: light;
  --bg: #e8e4d9;
  --bg-soft: #ece7da;
  --panel: #f3f0e6;
  --panel-raised: #faf8f1;
  --card: #f7f4ea;
  --border: #d6d0bd;
  --border-soft: #d6d0bd66;
  --scrim: rgba(30, 27, 18, 0.35);

  --ink: #211f18;
  --ink-dim: #4b4736;
  --ink-muted: #6b674f;
  --ink-faint: #8b876d;

  --brass: #92662c;
  --brass-soft: #92662c1c;
  --brass-ink: #fbf6ea;

  --rel-supports: #227a56;
  --rel-supports-soft: #227a561a;
  --rel-contradicts: #b23a44;
  --rel-contradicts-soft: #b23a441a;
  --rel-depends: #4652b0;
  --rel-depends-soft: #4652b01a;
  --rel-context: #97671c;
  --rel-context-soft: #97671c1a;

  --node-source: #2c7690;
  --node-claim: #97671c;

  --shadow-panel: 0 12px 30px -14px rgba(40, 32, 10, 0.35);
  --shadow-card: 0 1px 0 rgba(255,255,255,0.6) inset, 0 4px 14px -8px rgba(60, 50, 20, 0.25);
}
[data-theme="dark"] { color-scheme: dark; }

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background:
    radial-gradient(1200px 700px at 12% -10%, var(--bg-soft), transparent 60%),
    var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

::selection { background: var(--brass-soft); color: var(--ink); }

a { color: inherit; }

button, input, select { font-family: inherit; color: inherit; }
button { cursor: pointer; }

:focus-visible {
  outline: 2px solid var(--brass);
  outline-offset: 2px;
  border-radius: 3px;
}

.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* =============================== HEADER =============================== */

.hdr {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 14px 22px;
  border-bottom: 1px solid var(--border-soft);
  position: sticky;
  top: 0;
  z-index: 40;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
}

.hdr-brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.hdr-mark { width: 34px; height: 34px; flex: none; }
.mark-ring { fill: none; stroke: var(--border); stroke-width: 1.4; }
.mark-hemi { fill: none; stroke: var(--brass); stroke-width: 1.6; }
.mark-line { stroke: var(--border); stroke-width: 1; }
.mark-dot { fill: var(--brass); }

.hdr-titles h1 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 21px;
  letter-spacing: 0.01em;
  margin: 0;
  line-height: 1.1;
}
.hdr-titles p {
  margin: 2px 0 0;
  font-size: 11.5px;
  color: var(--ink-faint);
  font-family: var(--font-mono);
  letter-spacing: 0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hdr-search {
  flex: 1;
  max-width: 480px;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 0 10px;
  height: 38px;
  transition: border-color .15s ease;
}
.hdr-search:focus-within { border-color: var(--brass); }
.search-icon { width: 16px; height: 16px; color: var(--ink-faint); flex: none; }
#search-input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  font-size: 14px;
  color: var(--ink);
  min-width: 0;
}
#search-input::placeholder { color: var(--ink-faint); }
.search-clear {
  background: none; border: none; color: var(--ink-faint);
  font-size: 18px; line-height: 1; padding: 2px 4px; border-radius: 4px;
}
.search-clear:hover { color: var(--ink); }

.hdr-actions { display: flex; align-items: center; gap: 10px; margin-left: auto; flex: none; }
.hdr-count { font-family: var(--font-mono); font-size: 11.5px; color: var(--ink-faint); white-space: nowrap; }

.icon-btn {
  width: 36px; height: 36px;
  display: grid; place-items: center;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--ink-dim);
  transition: color .15s ease, border-color .15s ease, background .15s ease;
}
.icon-btn:hover { color: var(--ink); border-color: var(--brass); }
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn.small { width: 28px; height: 28px; font-family: var(--font-mono); font-size: 14px; }
.icon-btn[aria-expanded="true"] { color: var(--ink); border-color: var(--brass); }

/* -------- popovers (saved views) -------- */
.popover-wrap { position: relative; }
.popover {
  position: absolute; top: calc(100% + 8px); right: 0;
  width: min(320px, calc(100vw - 32px));
  background: var(--panel-raised); border: 1px solid var(--border);
  border-radius: var(--radius-md); box-shadow: var(--shadow-panel);
  padding: 12px; z-index: 55;
}
.popover[hidden] { display: none; }
.popover-title {
  font-family: var(--font-mono); font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em;
  color: var(--ink-faint); margin-bottom: 8px;
}
.views-list { display: flex; flex-direction: column; gap: 5px; max-height: 260px; overflow-y: auto; margin-bottom: 10px; }
.views-empty { font-size: 12px; color: var(--ink-faint); padding: 6px 2px; }
.view-item {
  display: flex; align-items: center; gap: 8px;
  background: var(--panel); border: 1px solid var(--border-soft); border-radius: var(--radius-sm);
  padding: 7px 9px; cursor: pointer; font-size: 12.5px; color: var(--ink-dim); text-align: left;
}
.view-item:hover, .view-item:focus-visible { border-color: var(--brass); color: var(--ink); }
.view-item-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.view-item-preset {
  font-family: var(--font-mono); font-size: 9px; text-transform: uppercase; color: var(--brass);
  border: 1px solid var(--brass); border-radius: 8px; padding: 1px 5px; flex: none;
}
.view-item-delete {
  flex: none; background: none; border: none; color: var(--ink-faint); font-size: 15px; line-height: 1;
  padding: 2px 4px; border-radius: 4px;
}
.view-item-delete:hover, .view-item-delete:focus-visible { color: var(--rel-contradicts); }
.views-save-row { display: flex; gap: 6px; }
.views-save-row input {
  flex: 1; min-width: 0; background: var(--panel); border: 1px solid var(--border); color: var(--ink);
  border-radius: var(--radius-sm); padding: 6px 9px; font-size: 12.5px;
}
.views-save-row input:focus-visible { outline: 2px solid var(--brass); outline-offset: 1px; }

.i-moon { display: none; }
[data-theme="dark"] .i-sun { display: none; }
[data-theme="dark"] .i-moon { display: block; }
@media (prefers-color-scheme: dark) {
  .app:not([data-theme-explicit]) .i-sun { display: none; }
  .app:not([data-theme-explicit]) .i-moon { display: block; }
}

/* =============================== TABS =============================== */

.tabs {
  display: flex;
  gap: 4px;
  padding: 10px 22px 0;
  border-bottom: 1px solid var(--border-soft);
  overflow-x: auto;
}
.tab {
  display: flex; align-items: center; gap: 7px;
  background: none;
  border: none;
  padding: 9px 14px 12px;
  color: var(--ink-faint);
  font-size: 13.5px;
  font-weight: 600;
  white-space: nowrap;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color .15s ease, border-color .15s ease;
}
.tab svg { width: 15px; height: 15px; opacity: .8; }
.tab:hover { color: var(--ink); }
.tab[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--brass); }
.tab-count {
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--ink-faint);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 1px 6px;
}

/* =============================== FILTER BAR =============================== */

.filterbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 18px;
  padding: 12px 22px;
  border-bottom: 1px solid var(--border-soft);
  background: color-mix(in srgb, var(--panel) 55%, transparent);
}
.filter-group { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.filter-label {
  font-family: var(--font-mono);
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-faint);
  flex: none;
}
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--ink-muted);
  font-size: 12px;
  font-weight: 500;
  padding: 5px 10px 5px 8px;
  border-radius: 20px;
  transition: all .12s ease;
}
.chip:hover { border-color: var(--ink-faint); color: var(--ink); }
.chip[aria-pressed="false"] { opacity: .55; }
.chip[aria-pressed="true"] { color: var(--ink); border-color: var(--chip-color, var(--brass)); background: var(--chip-bg, var(--brass-soft)); opacity: 1; }
.chip-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--chip-color, var(--ink-faint)); flex: none; }

.filter-reset {
  margin-left: auto;
  background: none;
  border: none;
  color: var(--ink-faint);
  font-size: 12px;
  text-decoration: underline;
  text-underline-offset: 3px;
  white-space: nowrap;
}
.filter-reset:hover { color: var(--brass); }

.filter-group--emphasis { padding-left: 14px; border-left: 1px solid var(--border-soft); }
.filter-select {
  background: var(--panel); border: 1px solid var(--border); color: var(--ink);
  border-radius: 20px; padding: 5px 12px; font-size: 12px; font-weight: 500;
  max-width: 220px;
}
.filter-select:hover { border-color: var(--brass); }

/* =============================== MAIN / VIEW =============================== */

.view { flex: 1; min-height: 0; display: flex; position: relative; }
.panel { flex: 1; min-width: 0; display: none; flex-direction: column; }
.panel[data-active="true"] { display: flex; }

/* -------- Graph -------- */
.graph-panel { position: relative; }
.graph-wrap { position: relative; flex: 1; min-height: 0; }
.graph-svg {
  width: 100%; height: 100%; display: block;
  cursor: grab;
  background-image:
    linear-gradient(var(--border-soft) 1px, transparent 1px),
    linear-gradient(90deg, var(--border-soft) 1px, transparent 1px);
  background-size: 34px 34px;
  background-position: center;
}
.graph-svg:active { cursor: grabbing; }

.graph-hint {
  position: absolute; left: 16px; bottom: 14px;
  font-family: var(--font-mono); font-size: 10.5px; color: var(--ink-faint);
  background: color-mix(in srgb, var(--panel) 80%, transparent);
  border: 1px solid var(--border-soft);
  padding: 5px 9px; border-radius: 20px;
  pointer-events: none;
}
.graph-controls {
  position: absolute; right: 16px; bottom: 14px;
  display: flex; flex-direction: column; gap: 6px;
}
.graph-legend {
  position: absolute; top: 14px; right: 16px;
  background: color-mix(in srgb, var(--panel) 92%, transparent);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  font-size: 12px;
  min-width: 216px;
  max-width: 240px;
  box-shadow: var(--shadow-panel);
}
.legend-title {
  font-family: var(--font-mono); font-size: 10px; text-transform: uppercase;
  letter-spacing: .08em; color: var(--ink-faint); margin-bottom: 7px;
}
.legend-row { display: flex; align-items: flex-start; gap: 8px; padding: 3px 0; color: var(--ink-dim); cursor: default; }
.legend-row[data-rel] { cursor: pointer; border-radius: 4px; padding: 3px 4px; margin: 0 -4px; }
.legend-row[data-rel]:hover { background: var(--border-soft); }
.legend-row[data-rel].is-off { opacity: .4; }
.legend-node { width: 11px; height: 11px; border-radius: 50%; flex: none; border: 1.5px solid; margin-top: 2px; }
.legend-node--source { background: color-mix(in srgb, var(--node-source) 35%, transparent); border-color: var(--node-source); }
.legend-node--claim { background: color-mix(in srgb, var(--node-claim) 35%, transparent); border-color: var(--node-claim); border-radius: 3px; transform: rotate(45deg); }
.legend-edge { width: 18px; height: 2px; flex: none; margin-top: 7px; background: var(--rel-supports); }
.legend-edge[data-rel-swatch="supports"] { background: var(--rel-supports); }
.legend-edge[data-rel-swatch="contradicts"] { background: var(--rel-contradicts); }
.legend-edge[data-rel-swatch="depends_on"] { background: var(--rel-depends); }
.legend-edge[data-rel-swatch="contextualizes"] { background: var(--rel-context); }
.legend-row-text { display: flex; flex-direction: column; gap: 1px; }
.legend-row-text b { font-weight: 600; color: var(--ink); }
.legend-row-text small { font-size: 10.5px; color: var(--ink-faint); line-height: 1.35; }
.legend-divider { height: 1px; background: var(--border-soft); margin: 6px 0; }
.legend-row--size { font-size: 10.5px; color: var(--ink-faint); padding-top: 2px; line-height: 1.4; }

.graph-empty {
  position: absolute; inset: 0; display: grid; place-items: center;
  color: var(--ink-faint); font-size: 14px; pointer-events: none;
}
.graph-empty[hidden] { display: none; }

/* graph node/edge svg element styling is largely inline (data-driven), but shared bits: */
.gnode { cursor: pointer; transition: opacity .25s ease; }
.gnode circle, .gnode rect { transition: stroke-width .2s ease, fill .2s ease; }
.gnode:focus-visible circle, .gnode:focus-visible rect { outline: none; filter: drop-shadow(0 0 6px var(--brass)); }
.gnode-label {
  font-family: var(--font-body); font-size: 10.5px; font-weight: 600;
  fill: var(--ink-dim); pointer-events: none; paint-order: stroke;
  stroke: var(--bg); stroke-width: 3px; stroke-linejoin: round;
}
.gedge { fill: none; transition: opacity .25s ease, stroke-width .25s ease; }
.gedge-hit { fill: none; stroke: transparent; stroke-width: 14px; cursor: pointer; }
.gedge-hit:focus-visible { outline: none; stroke: var(--brass); stroke-opacity: 0.22; }

/* -------- panel toolbar / sort -------- */
.panel-toolbar {
  display: flex; justify-content: space-between; align-items: center;
  flex-wrap: wrap; gap: 10px 16px; padding: 14px 22px 0;
}
.sort-group { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--ink-faint); }
.sort-group select {
  background: var(--panel); border: 1px solid var(--border); color: var(--ink);
  border-radius: var(--radius-sm); padding: 5px 8px; font-size: 12.5px;
}
.toolbar-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.toolbar-hint { font-family: var(--font-mono); font-size: 10.5px; color: var(--ink-faint); white-space: nowrap; }
.log-count-label { font-family: var(--font-mono); font-size: 11px; color: var(--ink-faint); }

.btn-ghost {
  background: var(--panel); border: 1px solid var(--border); color: var(--ink-dim);
  border-radius: 20px; padding: 6px 13px; font-size: 12.5px; font-weight: 600;
  transition: border-color .15s ease, color .15s ease;
  white-space: nowrap;
}
.btn-ghost:hover, .btn-ghost:focus-visible { border-color: var(--brass); color: var(--ink); }
.btn-ghost:disabled { opacity: .4; cursor: default; }
.btn-ghost:disabled:hover { border-color: var(--border); color: var(--ink-dim); }
.btn-ghost.small { padding: 5px 11px; font-size: 11.5px; }
.btn-ghost--muted { background: none; border-color: transparent; color: var(--ink-faint); }
.btn-ghost--muted:hover, .btn-ghost--muted:focus-visible { color: var(--rel-contradicts); border-color: transparent; }
.btn-ghost--primary { border-color: var(--brass); color: var(--ink); background: var(--brass-soft); }

/* -------- Source cards -------- */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(298px, 1fr));
  gap: 14px;
  padding: 16px 22px 32px;
  overflow-y: auto;
}
.source-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px 16px 14px;
  display: flex; flex-direction: column; gap: 10px;
  box-shadow: var(--shadow-card);
  cursor: pointer;
  transition: border-color .15s ease, transform .15s ease;
  text-align: left;
}
.source-card:hover { border-color: var(--brass); transform: translateY(-1px); }
.source-card.is-dimmed { opacity: .32; filter: grayscale(.4); }
.source-card.is-match { border-color: var(--brass); box-shadow: 0 0 0 1px var(--brass), var(--shadow-card); }
.source-card.is-deemphasized { opacity: .55; }
.source-card.is-central-source { border-color: var(--brass); box-shadow: 0 0 0 1px var(--brass), var(--shadow-card); }

.central-flag {
  display: inline-flex; align-items: center; gap: 4px; width: fit-content;
  font-family: var(--font-mono); font-size: 10px; text-transform: uppercase; letter-spacing: .04em;
  font-weight: 700; color: var(--brass);
}
.central-flag--large {
  font-size: 11px; background: var(--brass-soft); padding: 5px 10px; border-radius: 20px;
  margin-bottom: 10px; text-transform: none; letter-spacing: 0;
}
.card-emphasis {
  font-family: var(--font-mono); font-size: 10.5px; color: var(--brass);
  border-top: 1px dashed var(--border-soft); padding-top: 7px; margin-top: -2px;
}

.card-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.type-badge {
  font-family: var(--font-mono); font-size: 10px; text-transform: uppercase; letter-spacing: .05em;
  padding: 3px 8px; border-radius: 20px; border: 1px solid var(--border);
  color: var(--node-source); background: color-mix(in srgb, var(--node-source) 12%, transparent);
  white-space: nowrap;
}
.card-year { font-family: var(--font-mono); font-size: 12px; color: var(--ink-faint); flex: none; }

.source-card h3 {
  font-family: var(--font-display); font-size: 16.5px; font-weight: 600; line-height: 1.28;
  margin: 0;
}
.card-byline { font-size: 12px; color: var(--ink-muted); }
.card-byline .venue { font-style: italic; }

.card-summary {
  font-size: 12.8px; color: var(--ink-dim); line-height: 1.5;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}

.card-meta-row {
  display: flex; gap: 10px; font-family: var(--font-mono); font-size: 10.8px; color: var(--ink-faint);
  border-top: 1px solid var(--border-soft); padding-top: 9px; flex-wrap: wrap;
}

.card-relbadges { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 2px; }
.relbadge {
  font-size: 10.5px; font-weight: 600; padding: 2px 7px; border-radius: 20px;
  display: inline-flex; align-items: center; gap: 4px;
}
.relbadge[data-rel="supports"] { color: var(--rel-supports); background: var(--rel-supports-soft); }
.relbadge[data-rel="contradicts"] { color: var(--rel-contradicts); background: var(--rel-contradicts-soft); }
.relbadge[data-rel="depends_on"] { color: var(--rel-depends); background: var(--rel-depends-soft); }
.relbadge[data-rel="contextualizes"] { color: var(--rel-context); background: var(--rel-context-soft); }
.relbadge .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

.coi-flag {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 10.5px; font-weight: 600; color: var(--rel-context);
  background: var(--rel-context-soft); padding: 2px 8px; border-radius: 20px;
  width: fit-content;
}

/* -------- Claims list -------- */
.claim-list { padding: 16px 22px 32px; display: flex; flex-direction: column; gap: 10px; overflow-y: auto; }
.claim-row {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 15px 18px; cursor: pointer; display: flex; flex-direction: column; gap: 9px;
  transition: border-color .15s ease;
}
.claim-row:hover { border-color: var(--brass); }
.claim-row.is-dimmed { opacity: .32; }
.claim-row.is-match { border-color: var(--brass); }
.claim-row.is-central { border-color: var(--brass); box-shadow: 0 0 0 1px var(--brass), 0 6px 18px -10px rgba(0,0,0,0.5); }
.claim-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.claim-top-left { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.claim-top-right { display: flex; align-items: center; gap: 8px; }
.compare-toggle {
  font-family: var(--font-mono); font-size: 10.5px; font-weight: 600;
  border: 1px solid var(--border); background: var(--panel); color: var(--ink-faint);
  border-radius: 20px; padding: 4px 10px; white-space: nowrap;
}
.compare-toggle:hover, .compare-toggle:focus-visible { border-color: var(--brass); color: var(--ink); }
.compare-toggle[aria-pressed="true"] { border-color: var(--brass); background: var(--brass-soft); color: var(--ink); }
.claim-domain {
  font-family: var(--font-mono); font-size: 10px; text-transform: uppercase; letter-spacing: .05em;
  color: var(--node-claim);
}
.claim-id { font-family: var(--font-mono); font-size: 10.5px; color: var(--ink-faint); }
.claim-row p.statement {
  font-family: var(--font-display); font-size: 17px; line-height: 1.4; margin: 0; color: var(--ink);
}
.claim-tally { display: flex; gap: 14px; flex-wrap: wrap; }
.tally-item { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--ink-muted); }
.tally-item .dot { width: 8px; height: 8px; border-radius: 50%; }
.tally-item[data-rel="supports"] .dot { background: var(--rel-supports); }
.tally-item[data-rel="contradicts"] .dot { background: var(--rel-contradicts); }
.tally-item[data-rel="depends_on"] .dot { background: var(--rel-depends); }
.tally-item[data-rel="contextualizes"] .dot { background: var(--rel-context); }
.tally-bar { display: flex; height: 5px; border-radius: 4px; overflow: hidden; background: var(--border-soft); }
.tally-seg[data-rel="supports"] { background: var(--rel-supports); }
.tally-seg[data-rel="contradicts"] { background: var(--rel-contradicts); }
.tally-seg[data-rel="depends_on"] { background: var(--rel-depends); }
.tally-seg[data-rel="contextualizes"] { background: var(--rel-context); }

/* -------- Evidence log table -------- */
.log-wrap { padding: 16px 22px 32px; overflow: auto; flex: 1; }
.log-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.log-table thead th {
  position: sticky; top: 0; background: var(--bg-soft);
  text-align: left; font-family: var(--font-mono); font-size: 10.5px; text-transform: uppercase;
  letter-spacing: .05em; color: var(--ink-faint); padding: 9px 12px; border-bottom: 1px solid var(--border);
  cursor: pointer; white-space: nowrap; user-select: none;
}
.log-table thead th:hover { color: var(--ink); }
.log-table thead th.sorted::after { content: " ▾"; color: var(--brass); }
.log-table thead th.sorted[data-dir="asc"]::after { content: " ▴"; }
.log-table tbody tr {
  border-bottom: 1px solid var(--border-soft); cursor: pointer; transition: background .1s ease;
}
.log-table tbody tr:hover, .log-table tbody tr:focus-visible { background: var(--panel); outline: none; box-shadow: inset 2px 0 0 var(--brass); }
.log-table tbody tr.is-hidden { display: none; }
.log-table td { padding: 9px 12px; vertical-align: top; color: var(--ink-dim); }
.log-table td.excerpt-cell { max-width: 340px; color: var(--ink-muted); }
.log-table td .mono { font-family: var(--font-mono); font-size: 11.5px; color: var(--ink-faint); }
.conf-pill {
  font-size: 10.5px; font-weight: 600; padding: 2px 7px; border-radius: 20px; white-space: nowrap;
}
.conf-pill[data-level="High"] { color: var(--rel-supports); background: var(--rel-supports-soft); }
.conf-pill[data-level="Moderate"] { color: var(--rel-context); background: var(--rel-context-soft); }
.conf-pill[data-level="Low"] { color: var(--rel-contradicts); background: var(--rel-contradicts-soft); }

/* =============================== INSPECTOR =============================== */

.inspector-backdrop {
  /* Scoped to .view (its positioned ancestor) rather than the full
     viewport, so it dims the content area without blocking the header,
     tabs, or filter bar behind it. #about-backdrop overrides back to
     fixed below, since the about panel isn't nested in .view. */
  position: absolute; inset: 0; background: var(--scrim);
  opacity: 0; pointer-events: none; transition: opacity .2s ease; z-index: 50;
}
.inspector-backdrop.is-open { opacity: 1; pointer-events: auto; }
#about-backdrop { position: fixed; }

.inspector {
  position: fixed; top: 0; right: 0; bottom: 0;
  width: min(480px, 100vw);
  background: var(--panel-raised);
  border-left: 1px solid var(--border);
  box-shadow: var(--shadow-panel);
  transform: translateX(100%);
  transition: transform .25s cubic-bezier(.2,.7,.3,1);
  z-index: 51;
  overflow-y: auto;
}
.inspector.is-open { transform: translateX(0); }

.inspector-close {
  position: sticky; top: 12px; float: right; margin: 0 14px 0 0;
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--panel); border: 1px solid var(--border); color: var(--ink-muted);
  font-size: 18px; line-height: 1; display: grid; place-items: center;
  z-index: 2;
}
.inspector-close:hover { color: var(--ink); border-color: var(--brass); }

.inspector-body { padding: 20px 26px 40px; clear: both; }

.eyebrow {
  font-family: var(--font-mono); font-size: 10.5px; text-transform: uppercase; letter-spacing: .09em;
  color: var(--ink-faint); margin: 0 0 6px;
}
.inspector-body h2 {
  font-family: var(--font-display); font-size: 22px; line-height: 1.32; font-weight: 600; margin: 0 0 12px;
}
.insp-actions { display: flex; gap: 8px; margin-bottom: 12px; }
/* Focus is moved to the panel itself on open purely so keyboard/screen-reader
   users land inside it — the visible ring belongs on the actual controls
   (close button, links) they tab to next, not the panel container. */
.inspector:focus, .compare-drawer:focus, .about:focus { outline: none; }
.about-p { font-size: 13.5px; color: var(--ink-dim); line-height: 1.6; }
.about-meta { font-family: var(--font-mono); font-size: 11px; color: var(--ink-faint); margin-top: 20px; border-top: 1px solid var(--border-soft); padding-top: 14px; }

.insp-citation {
  font-family: var(--font-mono); font-size: 12px; color: var(--ink-muted);
  background: var(--panel); border: 1px solid var(--border-soft); border-radius: var(--radius-sm);
  padding: 10px 12px; line-height: 1.6; margin-bottom: 14px;
}
.insp-citation b { color: var(--ink); }

.insp-facts { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 14px 0; }
.fact { background: var(--panel); border: 1px solid var(--border-soft); border-radius: var(--radius-sm); padding: 8px 10px; }
.fact-label { font-family: var(--font-mono); font-size: 9.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-faint); }
.fact-value { font-size: 12.5px; color: var(--ink); margin-top: 2px; }
.fact-def { font-size: 10.5px; color: var(--ink-faint); margin-top: 4px; line-height: 1.4; }
.fact.full { grid-column: 1 / -1; }
.fact.coi-warn { border-color: var(--rel-context); background: var(--rel-context-soft); }
.fact.coi-warn .fact-value { color: var(--rel-context); font-weight: 600; }

.insp-emphasis-note {
  font-family: var(--font-mono); font-size: 11px; color: var(--brass);
  background: var(--brass-soft); border-radius: var(--radius-sm);
  padding: 7px 10px; margin: 0 0 14px;
}

.insp-summary { font-size: 13.5px; color: var(--ink-dim); line-height: 1.65; margin: 16px 0; }

.insp-section-title {
  font-family: var(--font-mono); font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em;
  color: var(--ink-faint); margin: 24px 0 10px; display: flex; align-items: center; gap: 8px;
}
.insp-section-title::after { content: ""; flex: 1; height: 1px; background: var(--border-soft); }

.rel-group { margin-bottom: 16px; }
.rel-group-head { display: flex; align-items: center; gap: 8px; font-size: 12.5px; font-weight: 700; margin-bottom: 3px; text-transform: capitalize; }
.rel-group-def { font-size: 11px; color: var(--ink-faint); margin: 0 0 9px; line-height: 1.4; }
.rel-group-head .dot { width: 9px; height: 9px; border-radius: 50%; }
.rel-group[data-rel="supports"] .dot { background: var(--rel-supports); }
.rel-group[data-rel="contradicts"] .dot { background: var(--rel-contradicts); }
.rel-group[data-rel="depends_on"] .dot { background: var(--rel-depends); }
.rel-group[data-rel="contextualizes"] .dot { background: var(--rel-context); }
.rel-group[data-rel="supports"] .rel-group-head { color: var(--rel-supports); }
.rel-group[data-rel="contradicts"] .rel-group-head { color: var(--rel-contradicts); }
.rel-group[data-rel="depends_on"] .rel-group-head { color: var(--rel-depends); }
.rel-group[data-rel="contextualizes"] .rel-group-head { color: var(--rel-context); }

.ev-card {
  background: var(--panel); border: 1px solid var(--border-soft); border-left: 3px solid var(--border);
  border-radius: var(--radius-sm); padding: 11px 13px; margin-bottom: 8px; cursor: pointer;
  transition: border-color .12s ease;
}
.ev-card:hover, .ev-card:focus-visible { border-color: var(--brass); }
.ev-card.is-below-threshold { opacity: .5; }
.ev-card.is-below-threshold:hover, .ev-card.is-below-threshold:focus-visible { opacity: .85; }
.ev-card.is-central-evidence { box-shadow: 0 0 0 1px var(--brass); }
.rel-group[data-rel="supports"] .ev-card { border-left-color: var(--rel-supports); }
.rel-group[data-rel="contradicts"] .ev-card { border-left-color: var(--rel-contradicts); }
.rel-group[data-rel="depends_on"] .ev-card { border-left-color: var(--rel-depends); }
.rel-group[data-rel="contextualizes"] .ev-card { border-left-color: var(--rel-context); }
.ev-card-head { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; margin-bottom: 5px; flex-wrap: wrap; }
.ev-card-source { font-size: 12.5px; font-weight: 700; color: var(--ink); }
.ev-card-target { font-size: 11.5px; color: var(--ink-faint); }
.ev-excerpt { font-size: 12.8px; color: var(--ink-dim); line-height: 1.55; margin: 0 0 7px; }
.ev-why { font-size: 12px; color: var(--ink-muted); line-height: 1.5; margin: 0 0 8px; }
.ev-why b { color: var(--ink); font-weight: 600; }
.ev-prov { display: flex; flex-wrap: wrap; gap: 6px 12px; font-family: var(--font-mono); font-size: 10.5px; color: var(--ink-faint); }
.ev-prov b { color: var(--ink-muted); font-weight: 600; }
.ev-reason { font-size: 11px; color: var(--ink-faint); margin-top: 6px; font-style: italic; }
.ev-threshold-note { font-size: 10.5px; color: var(--brass); margin-top: 6px; }

.related-list { display: flex; flex-direction: column; gap: 6px; }
.related-item {
  display: flex; flex-direction: column; align-items: stretch; gap: 5px; font-size: 12.5px; color: var(--ink-dim);
  background: var(--panel); border: 1px solid var(--border-soft); border-radius: var(--radius-sm);
  padding: 8px 10px; cursor: pointer;
}
.related-item:hover, .related-item:focus-visible { border-color: var(--brass); }
.related-item-top { display: flex; align-items: center; gap: 8px; }
.related-why { font-size: 11.5px; color: var(--ink-faint); line-height: 1.45; margin: 0; }
.related-rel {
  font-family: var(--font-mono); font-size: 10px; text-transform: uppercase; padding: 1px 6px; border-radius: 10px; flex: none;
}
.related-rel[data-rel="supports"] { color: var(--rel-supports); background: var(--rel-supports-soft); }
.related-rel[data-rel="contradicts"] { color: var(--rel-contradicts); background: var(--rel-contradicts-soft); }
.related-rel[data-rel="depends_on"] { color: var(--rel-depends); background: var(--rel-depends-soft); }
.related-rel[data-rel="contextualizes"] { color: var(--rel-context); background: var(--rel-context-soft); }

.insp-type-badge {
  display: inline-flex; align-items: center; gap: 6px; font-family: var(--font-mono); font-size: 10.5px;
  text-transform: uppercase; letter-spacing: .05em; padding: 4px 10px; border-radius: 20px;
  border: 1px solid var(--node-source); color: var(--node-source); background: color-mix(in srgb, var(--node-source) 12%, transparent);
  margin-bottom: 12px;
}
.insp-type-badge.claim { border-color: var(--node-claim); color: var(--node-claim); background: color-mix(in srgb, var(--node-claim) 12%, transparent); }

/* Keep filter-bar controls (confidence emphasis, central claim, reset)
   reachable while the inspector — a fixed, full-height right-side panel —
   is open, instead of letting them wrap underneath it. Desktop only: on
   narrow viewports the inspector goes full-width and this isn't needed. */
@media (min-width: 861px) {
  body.inspector-open .filterbar,
  body.compare-open .filterbar { padding-right: 500px; }
}

/* =============================== COMPARE BAR + DRAWER =============================== */

.compare-bar {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%);
  display: flex; align-items: center; gap: 14px;
  background: var(--panel-raised); border: 1px solid var(--border);
  border-radius: 30px; padding: 9px 10px 9px 18px; box-shadow: var(--shadow-panel);
  z-index: 53; max-width: calc(100vw - 32px);
}
.compare-bar[hidden] { display: none; }
.compare-bar-text {
  font-size: 12.5px; color: var(--ink-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  max-width: 46vw;
}
.compare-bar-actions { display: flex; gap: 6px; flex: none; }

.compare-drawer {
  position: fixed; left: 0; right: 0; bottom: 0;
  max-height: min(78vh, 700px);
  background: var(--panel-raised);
  border-top: 1px solid var(--border);
  border-radius: 18px 18px 0 0;
  box-shadow: var(--shadow-panel);
  transform: translateY(100%);
  transition: transform .28s cubic-bezier(.2,.7,.3,1);
  z-index: 51;
  overflow-y: auto;
}
.compare-drawer.is-open { transform: translateY(0); }
.compare-drawer-handle {
  position: sticky; top: 0; display: flex; justify-content: center; padding: 10px 0 4px;
  background: var(--panel-raised);
}
.compare-drawer-handle::before { content: ""; width: 40px; height: 4px; border-radius: 4px; background: var(--border); }
.compare-drawer-close { position: sticky; top: 10px; float: right; margin: -34px 16px 0 0; }
.compare-drawer-body { padding: 4px 26px 40px; clear: both; }

.compare-empty { padding: 40px 20px; text-align: center; color: var(--ink-faint); font-size: 13px; }

.compare-head { text-align: center; margin-bottom: 18px; }
.compare-head h2 {
  font-family: var(--font-display); font-size: 20px; font-weight: 600; margin: 4px 0 0;
}

.compare-link-banner {
  display: flex; align-items: center; gap: 10px; justify-content: center; flex-wrap: wrap;
  background: var(--panel); border: 1px solid var(--border-soft); border-radius: var(--radius-md);
  padding: 10px 16px; margin: 0 0 20px; font-size: 12.5px; color: var(--ink-dim); text-align: center;
}
.compare-link-banner.no-link { color: var(--ink-faint); font-style: italic; }

.compare-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-bottom: 22px; }
.compare-col { min-width: 0; }
.compare-col-title {
  font-family: var(--font-display); font-size: 16px; font-weight: 600; line-height: 1.35; margin: 0 0 8px;
}
.compare-col-domain {
  font-family: var(--font-mono); font-size: 10px; text-transform: uppercase; letter-spacing: .05em;
  color: var(--node-claim); margin-bottom: 10px; display: block;
}
.compare-tally { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }

.compare-evlist { display: flex; flex-direction: column; gap: 5px; }
.compare-ev-row {
  display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--ink-dim);
  background: var(--panel); border: 1px solid var(--border-soft); border-left: 3px solid var(--border);
  border-radius: var(--radius-sm); padding: 6px 9px; cursor: pointer; text-align: left;
}
.compare-ev-row:hover, .compare-ev-row:focus-visible { border-color: var(--brass); }
.compare-ev-row[data-rel="supports"] { border-left-color: var(--rel-supports); }
.compare-ev-row[data-rel="contradicts"] { border-left-color: var(--rel-contradicts); }
.compare-ev-row[data-rel="depends_on"] { border-left-color: var(--rel-depends); }
.compare-ev-row[data-rel="contextualizes"] { border-left-color: var(--rel-context); }
.compare-ev-source { font-weight: 700; color: var(--ink); flex: none; }
.compare-ev-rel { flex: 1; text-transform: capitalize; }

.compare-shared-title, .compare-section-title {
  font-family: var(--font-mono); font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em;
  color: var(--ink-faint); margin: 22px 0 10px; display: flex; align-items: center; gap: 8px;
}
.compare-shared-title::after, .compare-section-title::after { content: ""; flex: 1; height: 1px; background: var(--border-soft); }
.compare-shared-empty { font-size: 12px; color: var(--ink-faint); }
.compare-shared-row {
  display: grid; grid-template-columns: minmax(0,1fr) auto auto; align-items: center; gap: 10px;
  background: var(--panel); border: 1px solid var(--border-soft); border-radius: var(--radius-sm);
  padding: 8px 12px; margin-bottom: 6px; font-size: 12.5px; cursor: pointer; text-align: left; width: 100%;
}
.compare-shared-row:hover, .compare-shared-row:focus-visible { border-color: var(--brass); }
.compare-shared-name { font-weight: 700; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* =============================== RESPONSIVE =============================== */

@media (max-width: 860px) {
  .hdr { flex-wrap: wrap; padding: 12px 14px; }
  .hdr-search { order: 3; max-width: none; width: 100%; }
  .tabs, .filterbar { padding-left: 14px; padding-right: 14px; }
  .card-grid, .claim-list, .log-wrap, .panel-toolbar { padding-left: 14px; padding-right: 14px; }
  .inspector, .compare-drawer { width: 100vw; }
  .compare-drawer { max-height: 88vh; border-radius: 14px 14px 0 0; }
  .compare-drawer-body { padding: 4px 16px 32px; }
  .graph-legend { display: none; }
  .insp-facts { grid-template-columns: 1fr; }
  .filter-group--emphasis { padding-left: 0; border-left: none; }
  .compare-grid { grid-template-columns: 1fr; gap: 24px; }
  .compare-shared-row { grid-template-columns: 1fr; gap: 4px; text-align: left; }
  /* The popover normally anchors `right:0` off its own trigger button, but
     that button isn't necessarily near the screen edge once the header
     wraps — pin it to safe viewport-relative bounds instead. JS sets
     `top` dynamically to clear the actual (variable-height) header. */
  .popover { position: fixed; left: 12px; right: 12px; width: auto; max-width: none; }
}

@media (max-width: 480px) {
  .hdr-titles p { display: none; }
  .hdr-count { display: none; }
  .hdr-actions { gap: 6px; }
  .tab { padding: 8px 10px 10px; font-size: 12.5px; }
  .tab svg { display: none; }
  .compare-bar { left: 12px; right: 12px; bottom: 14px; transform: none; max-width: none; }
  .compare-bar-text { max-width: none; white-space: normal; }
  .compare-bar { flex-wrap: wrap; justify-content: center; text-align: center; border-radius: 18px; }
  .panel-toolbar { align-items: flex-start; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition-duration: 0.001ms !important; animation-duration: 0.001ms !important; }
}
