/* BD Intelligence Engine — admin UI.
   No framework, no build step: the server has ~600 MB of headroom shared with
   other production services, so the UI costs one static file mount. */

:root {
  color-scheme: dark;

  --bg: #07111f;
  --bg-raised: #0d1929;
  --bg-sunken: #07101c;
  --line: #213149;
  --line-soft: #18273b;
  --text: #f2f6fb;
  --text-dim: #9aaac0;
  --text-faint: #66778e;
  --accent: #2f7dff;
  --accent-soft: rgba(47, 125, 255, 0.14);
  --cyan: #4bd6c8;

  --a-plus: #10b981;
  --a: #22c55e;
  --b: #f59e0b;
  --c: #f97316;
  --d: #64748b;

  --ok: #22c55e;
  --warn: #f59e0b;
  --bad: #ef4444;

  --radius: 14px;
  --radius-sm: 8px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  background-image:
    radial-gradient(circle at 15% -10%, rgba(47, 125, 255, 0.20), transparent 34rem),
    radial-gradient(circle at 95% 10%, rgba(75, 214, 200, 0.08), transparent 28rem);
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.muted { color: var(--text-dim); }
.small { font-size: 13px; }
.mono { font-family: var(--mono); font-size: 12.5px; }

/* --- gate ---------------------------------------------------------------- */

.gate {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: clamp(28px, 5vw, 72px);
}

.gate-shell {
  width: min(1180px, 100%);
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(340px, 0.65fr);
  gap: clamp(36px, 7vw, 96px);
  align-items: center;
}
.gate-story { min-width: 0; }

.gate-story h1 {
  margin: 22px 0;
  max-width: 760px;
  font-size: clamp(44px, 6.2vw, 82px);
  line-height: 0.98;
  letter-spacing: -0.055em;
  font-weight: 680;
}
.gate-story h1 span { color: var(--cyan); }
.gate-lead { max-width: 720px; margin: 0; color: var(--text-dim); font-size: clamp(16px, 1.8vw, 20px); line-height: 1.6; }

.eyebrow { color: var(--cyan); font: 700 11px/1.2 var(--mono); letter-spacing: 0.14em; }
.signal-dot { display: inline-block; width: 7px; height: 7px; margin-right: 8px; border-radius: 50%; background: var(--warn); box-shadow: 0 0 14px currentColor; }
.signal-dot.ok { background: var(--ok); }
.signal-dot.bad { background: var(--bad); }

.process-rail { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); align-items: start; gap: 20px; margin-top: 46px; max-width: 760px; }
.process-rail div { min-width: 0; border-top: 1px solid var(--line); padding-top: 13px; }
.process-rail b { display: block; margin-bottom: 8px; color: var(--accent); font: 700 11px var(--mono); }
.process-rail span { display: block; font-weight: 650; }
.process-rail small { display: block; margin-top: 2px; color: var(--text-faint); }
.process-rail i { display: none; }
.principles { display: flex; flex-wrap: wrap; gap: 18px; margin-top: 42px; color: var(--text-faint); font: 600 11px var(--mono); text-transform: uppercase; letter-spacing: 0.07em; }
.principles span::before { content: "/"; margin-right: 7px; color: var(--accent); }

.gate-card {
  width: 100%;
  background: rgba(13, 25, 41, 0.86);
  backdrop-filter: blur(18px);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: clamp(26px, 3.5vw, 40px);
  box-shadow: 0 30px 80px rgba(0,0,0,0.30);
}
.gate-card-head { display: flex; align-items: center; gap: 13px; margin-bottom: 32px; }
.gate-card-head strong, .gate-card-head small { display: block; }
.gate-card-head strong { font-size: 15px; }
.gate-card-head small { color: var(--text-faint); margin-top: 2px; }
.service-state { display: flex; align-items: center; padding: 11px 12px; margin-bottom: 28px; border: 1px solid var(--line-soft); border-radius: var(--radius-sm); background: var(--bg-sunken); color: var(--text-dim); font-size: 12px; }
.service-state code { margin-left: auto; color: var(--text-faint); font-size: 11px; }
.gate-card label { display: block; font-size: 13px; color: var(--text-dim); margin-bottom: 6px; }
.gate-card input { padding: 13px 14px; }

input, select {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg-sunken);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--text);
  font: inherit;
  font-size: 14px;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

button {
  padding: 10px 16px;
  background: var(--accent);
  color: #fff;
  border: 0;
  border-radius: var(--radius-sm);
  font: inherit;
  font-weight: 500;
  font-size: 14px;
  cursor: pointer;
}
button:hover { filter: brightness(1.1); }
button:disabled { opacity: 0.5; cursor: default; }
.gate-card button { display: flex; justify-content: space-between; width: 100%; margin-top: 14px; padding: 13px 15px; }
.gate-hint { margin: 18px 0 0; color: var(--text-faint); font-size: 11.5px; line-height: 1.55; }

button.ghost {
  background: transparent;
  color: var(--text-dim);
  border: 1px solid var(--line);
}
button.ghost:hover { color: var(--text); filter: none; }

.gate-error { color: var(--bad); font-size: 13px; margin-top: 14px !important; }

/* --- shell --------------------------------------------------------------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 28px;
  padding: 0 24px;
  height: 58px;
  background: var(--bg-raised);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand { display: flex; align-items: center; gap: 11px; }
.brand strong { display: block; font-size: 14px; line-height: 1.2; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 30px; height: 30px;
  border-radius: 8px;
  background: linear-gradient(135deg, #3b82f6, #8b5cf6);
  color: #fff;
  font-weight: 700;
  font-size: 12px;
}
.brand-mark.large { width: 38px; height: 38px; border-radius: 10px; }

.nav { display: flex; gap: 4px; margin-right: auto; }
.nav a {
  padding: 7px 13px;
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  font-size: 14px;
}
.nav a:hover { background: var(--bg-sunken); color: var(--text); text-decoration: none; }
.nav a.active { background: var(--bg-sunken); color: var(--text); font-weight: 500; }

.topbar-right { display: flex; align-items: center; gap: 12px; }

main { padding: 36px 24px 60px; max-width: 1320px; margin: 0 auto; }

.footer { padding: 0 24px 32px; max-width: 1320px; margin: 0 auto; }

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

.pill {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 12px;
  background: var(--bg-sunken);
  border: 1px solid var(--line);
  color: var(--text-dim);
}
.pill.ok { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 40%, transparent); }
.pill.bad { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, transparent); }
.pill.warn { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 40%, transparent); }

.badge {
  display: inline-grid;
  place-items: center;
  min-width: 30px;
  padding: 2px 7px;
  border-radius: var(--radius-sm);
  font-weight: 700;
  font-size: 12.5px;
  color: #04140c;
}
.badge.p-A\+ { background: var(--a-plus); }
.badge.p-A  { background: var(--a); }
.badge.p-B  { background: var(--b); }
.badge.p-C  { background: var(--c); }
.badge.p-D  { background: var(--d); color: #fff; }

h2 { font-size: 17px; margin: 0 0 14px; letter-spacing: -0.01em; }
h3 { font-size: 14px; margin: 0 0 10px; color: var(--text-dim); font-weight: 600;
     text-transform: uppercase; letter-spacing: 0.04em; }

.card {
  background: rgba(13, 25, 41, 0.88);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
}

.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; margin: 0 0 28px; }
.page-head h1 { margin: 8px 0 5px; font-size: clamp(28px, 4vw, 42px); line-height: 1; letter-spacing: -0.04em; }
.page-head p { margin: 0; color: var(--text-dim); }
.button-link { display: inline-flex; gap: 28px; align-items: center; padding: 10px 14px; border: 1px solid var(--line); border-radius: var(--radius-sm); color: var(--text); white-space: nowrap; }
.button-link:hover { border-color: var(--accent); background: var(--accent-soft); text-decoration: none; }
.live-pill::before { content: ""; display: inline-block; width: 6px; height: 6px; border-radius: 50%; margin-right: 6px; background: currentColor; }

.grid { display: grid; gap: 16px; }
.grid.tiles { grid-template-columns: repeat(auto-fit, minmax(168px, 1fr)); }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }

.tile .tile-value { font-size: 27px; font-weight: 650; letter-spacing: -0.02em; }
.tile .tile-label { font-size: 13px; color: var(--text-dim); margin-top: 3px; }

.section { margin-bottom: 26px; }

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

.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; background: var(--bg-raised); font-size: 14px; }
th {
  text-align: left;
  padding: 11px 14px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
td { padding: 11px 14px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--bg-sunken); cursor: pointer; }
td.num { text-align: right; font-variant-numeric: tabular-nums; }

.filters { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.filters input, .filters select { width: auto; min-width: 170px; }

/* --- score meter --------------------------------------------------------- */

.meter { height: 6px; background: var(--bg-sunken); border-radius: 3px; overflow: hidden; }
.meter > span { display: block; height: 100%; border-radius: 3px; background: var(--accent); }

.score-head { display: flex; align-items: baseline; gap: 12px; margin-bottom: 4px; }
.score-head .n { font-size: 30px; font-weight: 650; letter-spacing: -0.02em; }

.scores-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 18px; }

/* --- disclosure: score → rule → claim → quote ---------------------------- */

details { border-top: 1px solid var(--line-soft); }
details:first-of-type { border-top: 0; }
summary {
  cursor: pointer;
  padding: 9px 0;
  display: flex;
  align-items: center;
  gap: 10px;
  list-style: none;
  font-size: 14px;
}
summary::-webkit-details-marker { display: none; }
summary::before {
  content: "▸";
  color: var(--text-faint);
  font-size: 11px;
  transition: transform 0.12s;
}
details[open] > summary::before { transform: rotate(90deg); }
summary:hover { color: var(--accent); }
summary .spacer { margin-left: auto; }

.points { font-variant-numeric: tabular-nums; font-size: 13px; color: var(--text-dim); }
.points b { color: var(--text); }

.evidence {
  margin: 4px 0 12px 22px;
  padding: 12px 14px;
  background: var(--bg-sunken);
  border-left: 2px solid var(--accent);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}
.evidence + .evidence { margin-top: 8px; }
.quote {
  font-size: 13.5px;
  line-height: 1.6;
  margin: 0 0 8px;
  padding-left: 10px;
  border-left: 2px solid var(--line);
  color: var(--text);
}
.quote.translation { color: var(--text-dim); font-size: 13px; }
.evidence-meta { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; font-size: 12px; }

.claim-row { display: flex; gap: 10px; align-items: center; padding: 7px 0 7px 22px; font-size: 13.5px; }
.claim-row .predicate { font-family: var(--mono); font-size: 12.5px; }

.status { font-size: 11.5px; padding: 1px 7px; border-radius: 4px; border: 1px solid var(--line); color: var(--text-dim); }
.status.confirmed { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 40%, transparent); }
.status.probable { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 40%, transparent); }
.status.possible, .status.requires_verification { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 40%, transparent); }
.status.contradicted { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, transparent); }

/* --- lists --------------------------------------------------------------- */

ul.clean { list-style: none; padding: 0; margin: 0; }
ul.clean li { padding: 7px 0; border-bottom: 1px solid var(--line-soft); font-size: 14px; }
ul.clean li:last-child { border-bottom: 0; }

ul.q { list-style: none; padding: 0; margin: 0; }
ul.q li { padding: 9px 0 9px 22px; position: relative; font-size: 14px; border-bottom: 1px solid var(--line-soft); }
ul.q li:last-child { border-bottom: 0; }
ul.q li::before { content: "?"; position: absolute; left: 0; color: var(--accent); font-weight: 700; }
ul.u li::before { content: "!"; color: var(--warn); }
ul.f li::before { content: "✓"; color: var(--ok); font-weight: 400; }

.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tag {
  padding: 3px 9px;
  background: var(--bg-sunken);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 12.5px;
  color: var(--text-dim);
}

.kv { display: grid; grid-template-columns: minmax(120px, auto) 1fr; gap: 8px 18px; font-size: 14px; }
.kv dt { color: var(--text-dim); }
.kv dd { margin: 0; }

.actions { display: flex; gap: 10px; flex-wrap: wrap; }

.back { display: inline-block; margin-bottom: 14px; font-size: 14px; }

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

.spinner {
  width: 15px; height: 15px;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block;
  vertical-align: -2px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.toast {
  position: fixed;
  bottom: 22px; left: 50%;
  transform: translateX(-50%);
  padding: 11px 18px;
  background: var(--bg-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-size: 14px;
  z-index: 50;
  box-shadow: 0 8px 28px rgba(0,0,0,0.32);
  max-width: min(560px, 90vw);
}
.toast.bad { border-color: var(--bad); color: var(--bad); }

.note {
  padding: 12px 14px;
  background: var(--bg-sunken);
  border-left: 2px solid var(--warn);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-size: 13.5px;
  color: var(--text-dim);
}

@media (max-width: 720px) {
  .gate { align-items: start; padding: 28px 18px; }
  .gate-shell { grid-template-columns: 1fr; gap: 38px; }
  .gate-story h1 { font-size: clamp(38px, 12vw, 50px); overflow-wrap: anywhere; }
  .gate-story .eyebrow { font-size: 9.5px; line-height: 1.5; }
  .process-rail { grid-template-columns: 1fr 1fr; gap: 22px; }
  .process-rail i { display: none; }
  .process-rail small { white-space: normal; }
  .principles { margin-top: 30px; }
  .topbar { gap: 14px; padding: 0 14px; height: auto; flex-wrap: wrap; padding-bottom: 10px; }
  .nav { order: 3; width: 100%; }
  main { padding: 18px 14px 48px; }
  .page-head { align-items: flex-start; flex-direction: column; }
}
