:root {
  --bg: #f6f3ee;
  --bg-2: #efeae1;
  --panel: #ffffff;
  --panel-2: #fbf9f5;
  --panel-3: #f2ede4;
  --line: #e4ddd0;
  --line-soft: #ede7dc;
  --ink: #211a12;
  --ink-2: #574d3f;
  --muted: #94897a;
  --accent: #ee5a0e;
  --accent-2: #c2490a;
  --accent-glow: rgba(238, 90, 14, 0.22);
  --ok: #1a9d6a;
  --contradict: #d62839;
  --superseded: #7c47cf;
  --context: #2f6fe0;
  --derived: #0d9488;
  --unresolved: #bf7d0c;
  --mark: #ffe08a;
  --shadow: 0 8px 26px rgba(60, 45, 20, 0.08);
  --radius: 14px;
  color-scheme: light;
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  color: var(--ink);
  font-size: 14px;
  line-height: 1.5;
  background:
    radial-gradient(1100px 520px at 82% -10%, rgba(238, 90, 14, 0.10), transparent 60%),
    radial-gradient(900px 480px at 0% 0%, rgba(238, 90, 14, 0.045), transparent 55%),
    var(--bg);
  -webkit-font-smoothing: antialiased;
}
::selection { background: var(--accent-glow); }
h2 { font-size: 19px; margin: 0 0 4px; letter-spacing: -0.01em; }
h3 { font-size: 14px; margin: 0; }
p { margin: 0 0 8px; }
a { color: var(--accent-2); }
.muted { color: var(--muted); }
.mono { font-family: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace; font-variant-numeric: tabular-nums; }
.hidden { display: none !important; }
.label { font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); font-weight: 600; }

button {
  font: inherit; font-weight: 500; cursor: pointer; border-radius: 9px;
  border: 1px solid transparent;
  background: linear-gradient(180deg, var(--accent-2), var(--accent));
  color: #fff; padding: 8px 14px; transition: transform .12s, box-shadow .15s, background .15s;
  box-shadow: 0 4px 14px var(--accent-glow);
}
button:hover { transform: translateY(-1px); box-shadow: 0 6px 20px var(--accent-glow); }
button:active { transform: translateY(0); }
button.secondary { background: var(--panel-2); color: var(--ink-2); border-color: var(--line); box-shadow: none; }
button.secondary:hover { background: var(--panel-3); color: var(--ink); border-color: var(--accent); }
button.icon { background: transparent; border: none; color: var(--muted); font-size: 20px; padding: 0 6px; box-shadow: none; }
button.icon:hover { color: var(--ink); transform: none; }
button:disabled { opacity: .45; cursor: default; box-shadow: none; transform: none; }
input, select {
  font: inherit; padding: 8px 10px; border: 1px solid var(--line); border-radius: 9px;
  background: var(--bg-2); color: var(--ink);
}
input::placeholder { color: var(--muted); }
input:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; gap: 22px; padding: 14px 26px;
  background: rgba(255, 255, 255, 0.82); backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line-soft); position: sticky; top: 0; z-index: 20; flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  display: grid; place-items: center; width: 34px; height: 34px; border-radius: 10px; font-weight: 800; font-size: 13px;
  background: linear-gradient(145deg, var(--accent-2), var(--accent)); color: #fff;
  box-shadow: 0 4px 16px var(--accent-glow), inset 0 1px 0 rgba(255,255,255,.35);
}
.brand-name { font-weight: 700; font-size: 16px; letter-spacing: -0.01em; }
.tabs { display: flex; gap: 4px; background: var(--bg-2); padding: 4px; border-radius: 11px; border: 1px solid var(--line-soft); }
.tabs button {
  background: transparent; color: var(--muted); border: none; padding: 7px 13px; border-radius: 8px;
  font-weight: 600; box-shadow: none;
}
.tabs button:hover { color: var(--ink-2); transform: none; }
.tabs button.active { background: var(--panel); color: var(--accent); box-shadow: 0 1px 3px rgba(60, 45, 20, 0.14); }
.health {
  margin-left: auto; font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 8px;
  background: var(--bg-2); border: 1px solid var(--line-soft); padding: 6px 12px; border-radius: 20px;
}
.health::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 10px var(--ok); }

/* ---------- layout ---------- */
.layout { display: grid; grid-template-columns: minmax(0, 1fr) 0; gap: 18px; padding: 22px 26px 60px; transition: grid-template-columns .25s ease; }
.layout.with-evidence { grid-template-columns: minmax(0, 1fr) minmax(380px, 40%); }
.panel { background: linear-gradient(180deg, var(--panel), var(--bg-2)); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px 22px; min-width: 0; box-shadow: var(--shadow); }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 14px; flex-wrap: wrap; margin-bottom: 16px; }
.filters, .actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- overview ---------- */
.hero { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.hero h1 { font-size: 26px; margin: 4px 0 6px; letter-spacing: -0.02em; }
.hero .flow { color: var(--muted); font-size: 13px; }
.hero .flow b { color: var(--accent-2); font-weight: 600; }
.tiles { display: grid; grid-template-columns: repeat(5, 1fr); gap: 14px; margin-bottom: 22px; }
.tile {
  background: linear-gradient(180deg, var(--panel-2), var(--bg-2)); border: 1px solid var(--line);
  border-radius: 13px; padding: 16px 18px; position: relative; overflow: hidden;
}
.tile::after { content: ""; position: absolute; inset: 0; background: radial-gradient(120px 60px at 100% 0, var(--accent-glow), transparent 70%); opacity: .5; pointer-events: none; }
.tile .num { font-size: 30px; font-weight: 700; letter-spacing: -0.02em; }
.tile .cap { color: var(--muted); font-size: 12px; margin-top: 2px; }
.tile.g-ok .num { color: var(--ok); } .tile.g-bad .num { color: var(--contradict); } .tile.g-accent .num { color: var(--accent-2); }

.verdict-bar { display: flex; height: 16px; border-radius: 10px; overflow: hidden; border: 1px solid var(--line); }
.verdict-bar > span { display: block; height: 100%; transition: width .5s ease; }
.legend { display: flex; flex-wrap: wrap; gap: 8px 18px; margin-top: 12px; }
.legend .item { display: flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--ink-2); }
.legend .dot { width: 10px; height: 10px; border-radius: 3px; }
.legend .n { color: var(--muted); }

.cards { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; margin-top: 6px; }
.case-card {
  border: 1px solid var(--line); border-left-width: 4px; border-radius: 12px; padding: 15px 17px; cursor: pointer;
  background: var(--panel-2); transition: transform .12s, border-color .15s, background .15s;
}
.case-card:hover { transform: translateY(-2px); background: var(--panel-3); }
.case-card .k { font-size: 11px; letter-spacing: .06em; text-transform: uppercase; font-weight: 700; }
.case-card .t { font-weight: 600; margin: 6px 0 3px; }
.case-card .d { color: var(--muted); font-size: 12.5px; }
.case-card .go { color: var(--accent-2); font-size: 12px; margin-top: 8px; font-weight: 600; }

/* verdict color hooks */
.v-corroborates { --v: var(--ok); }
.v-contradicts { --v: var(--contradict); }
.v-superseded { --v: var(--superseded); }
.v-context_explained { --v: var(--context); }
.v-derived { --v: var(--derived); }
.v-unresolved { --v: var(--unresolved); }
.tint { color: var(--v); }

/* ---------- tables ---------- */
.wrap { overflow-x: auto; border-radius: 12px; border: 1px solid var(--line-soft); }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line-soft); vertical-align: top; }
th { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); background: var(--bg-2); position: sticky; top: 0; }
tbody tr { transition: background .1s; }
tbody tr:hover { background: rgba(238, 90, 14, 0.06); }
tr.clickable { cursor: pointer; }
td strong { color: var(--ink); }
.num { font-family: "JetBrains Mono", ui-monospace, monospace; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---------- badges ---------- */
.badge { display: inline-flex; align-items: center; gap: 5px; font-size: 11px; padding: 2px 8px; border-radius: 20px; border: 1px solid var(--line); color: var(--muted); margin: 0 4px 3px 0; white-space: nowrap; background: var(--bg-2); }
.badge.ok { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 45%, transparent); }
.badge.warn { color: var(--unresolved); border-color: color-mix(in srgb, var(--unresolved) 45%, transparent); }
.badge.bad { color: var(--contradict); border-color: color-mix(in srgb, var(--contradict) 45%, transparent); }
.badge.info { color: var(--accent-2); border-color: color-mix(in srgb, var(--accent) 45%, transparent); }
.badge.solid { background: color-mix(in srgb, var(--v) 18%, var(--bg-2)); color: var(--v); border-color: color-mix(in srgb, var(--v) 45%, transparent); text-transform: capitalize; font-weight: 600; }

/* ---------- upload ---------- */
.dropzone {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  border: 1.5px dashed var(--line); border-radius: 14px; padding: 44px; color: var(--muted); cursor: pointer;
  margin: 14px 0; background: var(--bg-2); transition: border-color .15s, background .15s, color .15s;
}
.dropzone:hover { border-color: var(--accent); color: var(--ink-2); }
.dropzone.drag { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, var(--bg-2)); color: var(--accent-2); }
.dropzone .big { font-size: 16px; font-weight: 600; color: var(--ink-2); }
.jobs { display: flex; flex-direction: column; gap: 12px; }
.job { border: 1px solid var(--line); border-radius: 11px; padding: 12px 14px; background: var(--panel-2); }
.job-title { display: flex; justify-content: space-between; font-weight: 600; }
.job-pct { font-family: "JetBrains Mono", monospace; color: var(--accent-2); }
.job-status { color: var(--muted); font-size: 12px; margin-top: 3px; }
.bar { height: 7px; background: var(--bg); border-radius: 4px; margin-top: 9px; overflow: hidden; }
.bar > span { display: block; height: 100%; width: 0; border-radius: 4px; background: linear-gradient(90deg, var(--accent), var(--derived)); transition: width .35s; box-shadow: 0 0 12px var(--accent-glow); }
.job.error .bar > span { background: var(--contradict); box-shadow: none; }

/* ---------- relations ---------- */
.verdict-group { margin-bottom: 22px; }
.verdict-group h3 { font-size: 14px; margin-bottom: 10px; display: flex; align-items: center; gap: 9px; text-transform: capitalize; }
.verdict-group h3 .spine { width: 10px; height: 10px; border-radius: 3px; background: var(--v); box-shadow: 0 0 10px var(--v); }
.verdict-group h3 .count { color: var(--muted); font-family: "JetBrains Mono", monospace; font-size: 12px; }
.relation { border: 1px solid var(--line); border-radius: 12px; padding: 0; margin-bottom: 11px; overflow: hidden; background: var(--panel-2); border-left: 4px solid var(--v); }
.relation-facts { display: grid; grid-template-columns: 1fr auto 1fr; gap: 0; align-items: stretch; }
.relation-fact { padding: 13px 15px; cursor: pointer; transition: background .12s; min-width: 0; }
.relation-fact:hover { background: rgba(238, 90, 14, 0.06); }
.relation-fact .val { font-size: 18px; font-weight: 700; font-family: "JetBrains Mono", monospace; }
.relation-fact .who { font-size: 13px; margin-top: 2px; }
.relation-fact .src { color: var(--muted); font-size: 11.5px; margin-top: 4px; }
.relation-fact .quote { font-size: 12px; color: var(--ink-2); font-style: italic; margin-top: 6px; opacity: .85; }
.rel-mid { display: grid; place-items: center; padding: 0 12px; border-left: 1px solid var(--line-soft); border-right: 1px solid var(--line-soft); background: var(--bg-2); }
.rel-mid .op { font-size: 20px; color: var(--v); font-weight: 700; }
.relation-meta { padding: 11px 15px; border-top: 1px solid var(--line-soft); font-size: 13px; background: var(--bg-2); }
.relation-meta .explanation { margin-top: 6px; color: var(--ink-2); }

/* ---------- facts (quote-first cards) ---------- */
.fact-group { margin-bottom: 24px; }
.fact-group > h3 {
  display: flex; align-items: center; gap: 9px; font-size: 13px; margin: 0 0 11px;
  color: var(--ink-2); position: sticky; top: 64px; z-index: 1;
  padding: 7px 0; background: linear-gradient(180deg, var(--panel) 70%, transparent);
}
.fact-group > h3 .doc-dot { width: 8px; height: 8px; border-radius: 2px; background: var(--accent); box-shadow: 0 0 8px var(--accent-glow); flex: none; }
.fact-group > h3 .count { color: var(--muted); font-family: "JetBrains Mono", monospace; font-size: 12px; }
.fact-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 11px; }
.fact-card {
  border: 1px solid var(--line); border-left: 3px solid var(--line); border-radius: 11px;
  padding: 12px 14px; background: var(--panel-2); cursor: pointer;
  transition: background .12s, border-color .12s, transform .12s;
}
.fact-card:hover { background: rgba(238, 90, 14, 0.06); transform: translateY(-1px); }
.fact-card.ev-ok { border-left-color: var(--ok); }
.fact-card.ev-visual { border-left-color: var(--unresolved); }
.fact-card.ev-bad { border-left-color: var(--contradict); }
.fact-card.is-dup { opacity: .6; }
.fact-card .val { font-size: 19px; font-weight: 700; font-family: "JetBrains Mono", monospace; color: var(--ink); line-height: 1.15; }
.fact-card .who { font-size: 13px; margin-top: 3px; color: var(--ink-2); }
.fact-card .who b { color: var(--ink); font-weight: 600; }
.fact-card .quote { font-size: 12.5px; color: var(--ink-2); font-style: italic; margin-top: 9px; line-height: 1.5; border-left: 2px solid var(--line-soft); padding-left: 9px; }
.fact-card .quote mark { background: var(--mark); color: #10151f; padding: 0 3px; border-radius: 3px; font-weight: 600; font-style: normal; }
.fact-card .visual { font-size: 12px; color: var(--unresolved); margin-top: 9px; font-style: italic; }
.fact-card .fact-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; margin-top: 10px; font-size: 11.5px; color: var(--muted); }
.fact-card .fact-meta .sep { color: var(--line); }
.fact-card .fact-meta .badge { margin: 0; }

/* ---------- evidence panel ---------- */
.evidence { background: linear-gradient(180deg, var(--panel), var(--bg-2)); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; position: sticky; top: 82px; max-height: calc(100vh - 104px); overflow: auto; box-shadow: var(--shadow); }
.evidence-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 10px; }
.evidence-head strong { font-size: 14px; }
.evidence img { width: 100%; border: 1px solid var(--line); border-radius: 9px; }
.evidence pre { white-space: pre-wrap; font-size: 12px; background: var(--bg); border: 1px solid var(--line-soft); color: var(--ink-2); padding: 10px; border-radius: 9px; max-height: 320px; overflow: auto; }
.evidence mark { background: var(--mark); color: #10151f; padding: 0 3px; border-radius: 3px; font-weight: 600; }
.evidence h3 { margin: 14px 0 7px; color: var(--muted); font-size: 11px; letter-spacing: .06em; text-transform: uppercase; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 5px 12px; font-size: 13px; margin: 8px 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-word; }
.kv dd .num { color: var(--accent-2); }
.timeline { margin-top: 8px; }
.timeline-entry { display: grid; grid-template-columns: 96px 1fr; gap: 8px; padding: 6px 0; border-bottom: 1px dashed var(--line-soft); font-size: 12.5px; }
.timeline-entry.current { font-weight: 600; }
.timeline-entry .num { color: var(--muted); }

.empty { color: var(--muted); padding: 32px; text-align: center; }

@media (max-width: 1000px) {
  .layout, .layout.with-evidence { grid-template-columns: 1fr; }
  .evidence { position: static; max-height: none; }
  .tiles { grid-template-columns: repeat(2, 1fr); }
  .cards { grid-template-columns: 1fr; }
  .relation-facts { grid-template-columns: 1fr; }
  .rel-mid { border: none; border-top: 1px solid var(--line-soft); border-bottom: 1px solid var(--line-soft); padding: 6px; }
  .rel-mid .op { transform: rotate(90deg); }
}
@media (max-width: 560px) { .tiles { grid-template-columns: 1fr; } .topbar { gap: 12px; } .fact-cards { grid-template-columns: 1fr; } }
