:root {
  --bg: #0b0f14;
  --panel: #141b23;
  --panel-2: #1b232d;
  --text: #e6edf3;
  --muted: #8d99a8;
  --border: #233041;
  --accent: #4c9aff;
  --accent-strong: #2b7cff;
  --ok: #3fb950;
  --warn: #d29922;
  --err: #f85149;
  --critical: #f85149;
  --major: #d29922;
  --minor: #e3b341;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

header {
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
}
header h1 { margin: 0; font-size: 18px; font-weight: 600; }
header .status-bar { display: flex; gap: 20px; font-size: 13px; color: var(--muted); flex-wrap: wrap; }
header .status-bar strong { color: var(--text); }
header nav a, header nav form { display: inline-block; margin-left: 10px; }
header .logout { background: transparent; border: 1px solid var(--border); color: var(--muted); padding: 8px 14px; border-radius: 6px; cursor: pointer; min-height: 44px; }

main { max-width: 1200px; margin: 0 auto; padding: 20px; }

.card { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 20px; margin-bottom: 20px; }
.card h2 { margin: 0 0 15px; font-size: 16px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }

.status-pill { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.status-not_started { background: #2d3748; color: var(--muted); }
.status-draft_pending { background: #2d4a63; color: #a8d4ff; }
.status-needs_review { background: #3d2d14; color: #f8c56e; }
.status-approved { background: #14361c; color: #7fe09d; }
.status-needs_rerun { background: #3d1a1a; color: #fcae9e; }

.spend-bar { background: #0b1118; border: 1px solid var(--border); border-radius: 999px; height: 10px; margin-top: 6px; overflow: hidden; }
.spend-bar > div { background: linear-gradient(90deg, var(--accent) 0%, var(--accent-strong) 100%); height: 100%; }
.spend-bar.warn > div { background: var(--warn); }
.spend-bar.err > div { background: var(--err); }

.pill-toggle { display: inline-flex; align-items: center; gap: 8px; }
.pill-toggle button { background: var(--panel-2); color: var(--text); border: 1px solid var(--border); border-radius: 6px; padding: 6px 12px; cursor: pointer; min-height: 44px; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); font-size: 14px; }
th { font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); font-weight: 600; }
tr:hover td { background: rgba(76, 154, 255, 0.04); }

.issue-cell { font-variant-numeric: tabular-nums; font-size: 13px; color: var(--muted); }
.issue-cell .c { color: var(--critical); font-weight: 600; }
.issue-cell .m { color: var(--major); font-weight: 600; }
.issue-cell .l { color: var(--minor); }

.btn { background: var(--accent); color: #fff; border: 0; border-radius: 6px; padding: 10px 16px; font: inherit; font-weight: 600; cursor: pointer; min-height: 44px; }
.btn:hover { background: var(--accent-strong); }
.btn.secondary { background: var(--panel-2); color: var(--text); border: 1px solid var(--border); }
.btn.danger { background: var(--err); color: #fff; }
.btn.small { padding: 6px 10px; font-size: 13px; min-height: 36px; }
form.inline { display: inline-block; margin: 0; }

input[type=text], input[type=password], textarea {
  width: 100%;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 12px;
  font: inherit;
  min-height: 44px;
}
textarea { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 13px; min-height: 100px; resize: vertical; }

.login-wrap { min-height: 60vh; display: flex; align-items: center; justify-content: center; }
.login-card { max-width: 360px; width: 100%; }
.login-card h1 { font-size: 20px; margin: 0 0 20px; }
.login-card .btn { width: 100%; margin-top: 12px; }

.flash { padding: 12px 16px; border-radius: 8px; margin-bottom: 15px; font-size: 14px; }
.flash.error { background: rgba(248, 81, 73, 0.15); border: 1px solid var(--err); color: #fdada7; }
.flash.ok { background: rgba(63, 185, 80, 0.15); border: 1px solid var(--ok); color: #a7f0b5; }

.review-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.review-grid > div { min-width: 0; }
@media (max-width: 900px) { .review-grid { grid-template-columns: 1fr; } }

.field { background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; padding: 14px; margin-bottom: 12px; }
.field h3 { margin: 0 0 8px; font-size: 13px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
.field .actions { margin-top: 10px; display: flex; gap: 8px; flex-wrap: wrap; }

.issue { padding: 12px 14px; border-radius: 8px; margin-bottom: 10px; border-left: 4px solid var(--border); background: var(--panel-2); font-size: 13px; }
.issue.CRITICAL { border-left-color: var(--critical); }
.issue.MAJOR { border-left-color: var(--major); }
.issue.MINOR { border-left-color: var(--minor); }
.issue .sev { display: inline-block; padding: 2px 8px; border-radius: 4px; font-size: 11px; font-weight: 700; margin-right: 8px; }
.issue.CRITICAL .sev { background: var(--critical); color: #fff; }
.issue.MAJOR .sev { background: var(--major); color: #000; }
.issue.MINOR .sev { background: var(--minor); color: #000; }
.issue code { background: rgba(0,0,0,0.3); padding: 1px 5px; border-radius: 3px; font-size: 12px; }
.issue .detail, .issue .fix { margin-top: 6px; color: var(--muted); font-size: 12px; }
.issue .fix { color: #a7f0b5; }

.toolbar { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 20px; }

@media (max-width: 768px) {
  header { flex-direction: column; align-items: flex-start; }
  main { padding: 12px; }
  table { font-size: 13px; }
  th, td { padding: 8px 6px; }
  .btn.small { padding: 8px 10px; }
}

/* ============ Review view v2 ============ */

.pmid-chip {
  display: inline-block;
  padding: 2px 8px;
  background: #1e3a5f;
  color: #a8d4ff;
  border-radius: 999px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 12px;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
  vertical-align: baseline;
  margin: 0 1px;
}
.pmid-chip:hover { background: #2b4f7c; text-decoration: none; color: #d4e8ff; }

.evidence-tier-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}
.evidence-tier-Human-RCT { background: #14361c; color: #7fe09d; }
.evidence-tier-Human-observational { background: #142a3d; color: #a8d4ff; }
.evidence-tier-Animal-studies-only { background: #3d2d14; color: #f8c56e; }
.evidence-tier-In-vitro-only { background: #2d3748; color: var(--muted); }
.evidence-tier-Mixed { background: #2d1a3d; color: #d4a8ff; }

.population-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  text-transform: lowercase;
}
.population-human { background: #14361c; color: #7fe09d; }
.population-animal { background: #3d2d14; color: #f8c56e; }
.population-in_vitro { background: #2d3748; color: var(--muted); }

.issue-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  border: 0;
  font-family: inherit;
  margin-left: 8px;
  min-height: 24px;
}
.issue-badge.CRITICAL { background: var(--critical); color: #fff; }
.issue-badge.MAJOR { background: var(--major); color: #000; }
.issue-badge.MINOR { background: var(--minor); color: #000; }
.issue-badge:hover { filter: brightness(1.1); }

.field-wrap {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-left-width: 4px;
  border-left-color: var(--border);
  border-radius: 8px;
  padding: 14px;
  margin-bottom: 14px;
}
.field-wrap.has-CRITICAL { border-left-color: var(--critical); }
.field-wrap.has-MAJOR { border-left-color: var(--major); }
.field-wrap.has-MINOR { border-left-color: var(--minor); }
.field-wrap.field-approved { border-left-color: var(--ok); background: rgba(63, 185, 80, 0.04); }

.field-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}
.field-head h3 {
  margin: 0;
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.field-head .ctrls { display: flex; gap: 6px; flex-wrap: wrap; }
.field-head .ctrls button {
  background: var(--panel);
  color: var(--muted);
  border: 1px solid var(--border);
  padding: 5px 10px;
  font-size: 12px;
  border-radius: 5px;
  cursor: pointer;
  min-height: 32px;
  font-family: inherit;
}
.field-head .ctrls button:hover { color: var(--text); border-color: var(--accent); }
.field-head .ctrls button.active { background: var(--accent); color: #fff; border-color: var(--accent); }

.field-approved-badge {
  display: inline-block;
  padding: 2px 8px;
  background: var(--ok);
  color: #000;
  font-size: 11px;
  font-weight: 700;
  border-radius: 4px;
  margin-left: 6px;
}

.issue-panel {
  background: #0e1620;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 12px;
  margin: 8px 0;
  font-size: 13px;
}
.issue-panel.CRITICAL { border-left: 3px solid var(--critical); }
.issue-panel.MAJOR { border-left: 3px solid var(--major); }
.issue-panel.MINOR { border-left: 3px solid var(--minor); }
.issue-panel .detail { color: var(--muted); margin-top: 6px; font-size: 12px; }
.issue-panel .fix { color: #a7f0b5; margin-top: 6px; font-size: 12px; }
.issue-panel .issue-ctrls { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }

.field-view, .field-edit-pretty, .field-edit-raw { }
.field-edit-pretty, .field-edit-raw { display: none; }
.field-wrap[data-mode="edit-pretty"] .field-view { display: none; }
.field-wrap[data-mode="edit-pretty"] .field-edit-pretty { display: block; }
.field-wrap[data-mode="edit-raw"] .field-view { display: none; }
.field-wrap[data-mode="edit-raw"] .field-edit-raw { display: block; }

.name-pretty { font-size: 24px; font-weight: 700; }
.class-pretty { display: inline-block; padding: 8px 14px; background: var(--panel); border-radius: 6px; }

.alias-pill, .no-data-pill {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid var(--border);
  font-size: 13px;
  margin: 2px 2px;
}
.no-data-pill { color: var(--muted); font-style: italic; }

.reg-row {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}
.reg-row:last-child { border-bottom: 0; }
.reg-row .label { font-weight: 600; color: var(--muted); font-size: 13px; }
@media (max-width: 600px) { .reg-row { grid-template-columns: 1fr; gap: 2px; } }

details.use-card, details.qa-card, details.refusal-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  margin-bottom: 8px;
  padding: 0;
}
details.use-card > summary, details.qa-card > summary, details.refusal-card > summary {
  padding: 10px 14px;
  cursor: pointer;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  list-style: none;
  min-height: 44px;
}
details.use-card > summary::marker,
details.qa-card > summary::marker,
details.refusal-card > summary::marker { content: ''; }
details.use-card > summary::before,
details.qa-card > summary::before,
details.refusal-card > summary::before { content: '▸'; color: var(--muted); margin-right: 6px; }
details[open].use-card > summary::before,
details[open].qa-card > summary::before,
details[open].refusal-card > summary::before { content: '▾'; }
details .inner { padding: 0 14px 14px; }

.study-card {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px;
  margin-top: 8px;
  font-size: 13px;
}
.study-card .cite { color: var(--muted); font-size: 12px; margin-bottom: 4px; }

.quoted-response {
  border-left: 3px solid var(--accent);
  padding: 8px 12px;
  margin: 8px 0 0;
  background: rgba(76, 154, 255, 0.06);
  border-radius: 0 6px 6px 0;
  font-size: 14px;
  white-space: pre-wrap;
}

.refusal-trigger {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  font-weight: 700;
}

.dosage-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.dosage-table th, .dosage-table td { padding: 8px; text-align: left; border-bottom: 1px solid var(--border); }
.dosage-table th { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; }
@media (max-width: 768px) {
  .dosage-table thead { display: none; }
  .dosage-table tr { display: block; background: var(--panel); border-radius: 6px; padding: 10px; margin-bottom: 8px; border: 1px solid var(--border); }
  .dosage-table td { display: block; border: 0; padding: 3px 0; }
  .dosage-table td::before { content: attr(data-label) ": "; color: var(--muted); font-size: 11px; text-transform: uppercase; font-weight: 600; }
}

.list-signal { padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.list-signal:last-child { border-bottom: 0; }

.empty-note { color: var(--muted); font-style: italic; padding: 10px 0; }

.pretty-list-editor .row {
  display: flex;
  gap: 6px;
  align-items: center;
  margin-bottom: 6px;
}
.pretty-list-editor .row input, .pretty-list-editor .row textarea { flex: 1; }
.pretty-list-editor .row .remove {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--err);
  width: 36px;
  height: 36px;
  min-height: 36px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 16px;
}
.pretty-list-editor .row .remove:hover { background: var(--err); color: #fff; }
.pretty-list-editor .add {
  background: var(--panel);
  border: 1px dashed var(--border);
  color: var(--accent);
  padding: 8px 12px;
  border-radius: 6px;
  cursor: pointer;
  font: inherit;
  font-size: 13px;
  margin-top: 4px;
}

.obj-editor .obj-row {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px;
  margin-bottom: 8px;
  display: grid;
  gap: 8px;
}
.obj-editor .obj-row label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
.obj-editor .obj-row .remove-row {
  justify-self: end;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--err);
  padding: 4px 10px;
  border-radius: 5px;
  cursor: pointer;
  font-size: 12px;
}

.field-save-row { display: flex; gap: 8px; margin-top: 10px; justify-content: flex-end; flex-wrap: wrap; }

.btn[disabled] { opacity: 0.5; cursor: not-allowed; }

.hint { font-size: 12px; color: var(--muted); margin-top: 4px; }
