:root {
  --navy: #0a2342;
  --navy-2: #1a3a5c;
  --amber-bg: #fef3c7;
  --amber-bd: #f59e0b;
  --green-bg: #f0fdf4;
  --green-bd: #16a34a;
  --slate: #64748b;
  --line: #cbd5e1;
  --ink: #1e293b;
  --bg: #f1f5f9;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
}
a { color: var(--navy-2); }

/* ── Header ─────────────────────────────────────────────────────────────── */
header.app {
  background: linear-gradient(120deg, var(--navy), var(--navy-2));
  color: #fff;
  padding: 14px 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
}
header.app h1 { font-family: Georgia, serif; font-size: 1.15rem; margin: 0; font-weight: 600; }
header.app .who { font-size: 0.9rem; opacity: 0.92; }
header.app .who button {
  margin-left: 8px; background: rgba(255,255,255,0.15); color: #fff;
  border: 1px solid rgba(255,255,255,0.35); border-radius: 5px; padding: 3px 9px;
  font-size: 0.78rem; cursor: pointer;
}
.progress { font-size: 0.85rem; opacity: 0.95; }
.progress .bar { display:inline-block; width: 140px; height: 8px; background: rgba(255,255,255,0.25);
  border-radius: 5px; overflow: hidden; vertical-align: middle; margin-left: 8px; }
.progress .bar > span { display:block; height: 100%; background: #7dd3fc; width: 0%; transition: width .25s; }

/* ── Layout ─────────────────────────────────────────────────────────────── */
.wrap { max-width: 1080px; margin: 0 auto; padding: 18px; display: grid;
  grid-template-columns: 190px 1fr; gap: 18px; align-items: start; }
@media (max-width: 760px) { .wrap { grid-template-columns: 1fr; } }

/* ── Case navigator ─────────────────────────────────────────────────────── */
nav.cases {
  background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 10px;
  position: sticky; top: 14px; max-height: calc(100vh - 30px); overflow: auto;
}
nav.cases h2 { font-size: 0.8rem; text-transform: uppercase; letter-spacing: .04em;
  color: var(--slate); margin: 4px 6px 10px; }
.case-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.case-chip {
  border: 1px solid var(--line); border-radius: 6px; background: #fff; color: var(--ink);
  font-size: 0.82rem; padding: 7px 0; cursor: pointer; text-align: center; position: relative;
}
.case-chip:hover { border-color: var(--navy-2); }
.case-chip.active { background: var(--navy); color: #fff; border-color: var(--navy); }
.case-chip.done::after { content: "✓"; position: absolute; top: -5px; right: -4px;
  background: var(--green-bd); color: #fff; border-radius: 50%; width: 15px; height: 15px;
  font-size: 0.62rem; line-height: 15px; }

/* ── Main panel ─────────────────────────────────────────────────────────── */
main.panel { background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 22px; }
.casehead { display:flex; align-items:baseline; justify-content:space-between; flex-wrap:wrap; gap:8px;
  border-bottom: 1px solid var(--line); padding-bottom: 12px; margin-bottom: 16px; }
.casehead .num { font-family: Georgia, serif; color: var(--navy); font-size: 1.2rem; font-weight: 600; }
.casehead .cat { font-size: 0.75rem; color: var(--slate); text-transform: uppercase; letter-spacing:.04em; }

.section-label { font-size: 0.72rem; text-transform: uppercase; letter-spacing: .05em;
  color: var(--slate); font-weight: 700; margin: 18px 0 8px; }

.case-text { background: #f8fafc; border: 1px solid var(--line); border-radius: 8px;
  padding: 14px 16px; white-space: pre-wrap; font-size: 0.95rem; line-height: 1.5; }

/* AI output */
.protochip { display:inline-block; background: #e0e7ff; color: #3730a3; border-radius: 6px;
  padding: 3px 10px; margin: 0 6px 6px 0; font-size: 0.85rem; font-weight: 600; }
ol.questions { margin: 6px 0 0; padding-left: 22px; }
ol.questions li { background: var(--amber-bg); border-left: 3px solid var(--amber-bd);
  margin: 6px 0; padding: 8px 10px; border-radius: 4px; font-size: 0.95rem; line-height: 1.4; }
ol.questions li .tier { font-size: 0.68rem; color: var(--slate); text-transform: uppercase;
  margin-left: 6px; letter-spacing: .03em; }
details.extracted { margin-top: 10px; }
details.extracted summary { cursor: pointer; color: var(--navy-2); font-size: 0.88rem; }
table.qa { width: 100%; border-collapse: collapse; margin-top: 8px; font-size: 0.88rem; }
table.qa td { border: 1px solid var(--line); padding: 6px 8px; vertical-align: top; }
table.qa td.q { width: 48%; color: #334155; }

/* ── Rating form ────────────────────────────────────────────────────────── */
.q-block { margin: 14px 0; padding: 12px 14px; border: 1px solid var(--line); border-radius: 8px; }
.q-block.invalid { border-color: var(--amber-bd); background: #fffbeb; }
.q-block .label { font-weight: 600; font-size: 0.95rem; margin-bottom: 8px; display:block; }
.q-block .hint { font-weight: 400; color: var(--slate); font-size: 0.82rem; }
.opts { display: flex; flex-wrap: wrap; gap: 8px; }
.opts label {
  border: 1px solid var(--line); border-radius: 7px; padding: 7px 12px; cursor: pointer;
  font-size: 0.9rem; background: #fff; user-select: none;
}
.opts label:hover { border-color: var(--navy-2); }
.opts input { display: none; }
.opts input:checked + span { font-weight: 700; }
.opts label:has(input:checked) { background: var(--navy); color: #fff; border-color: var(--navy); }
textarea { width: 100%; border: 1px solid var(--line); border-radius: 7px; padding: 8px 10px;
  font: inherit; font-size: 0.9rem; resize: vertical; min-height: 52px; }

.actions { margin-top: 20px; display:flex; gap: 10px; align-items:center; flex-wrap: wrap; }
button.primary { background: var(--navy); color: #fff; border: none; border-radius: 8px;
  padding: 11px 20px; font-size: 0.95rem; font-weight: 600; cursor: pointer; }
button.primary:hover { background: var(--navy-2); }
button.ghost { background: #fff; color: var(--navy); border: 1px solid var(--line);
  border-radius: 8px; padding: 11px 16px; font-size: 0.92rem; cursor: pointer; }
button:disabled { opacity: 0.5; cursor: not-allowed; }
.savemsg { font-size: 0.85rem; }
.savemsg.ok { color: var(--green-bd); }
.savemsg.err { color: #b91c1c; }

/* ── Reviewer gate / banners ────────────────────────────────────────────── */
.gate { max-width: 460px; margin: 60px auto; background: #fff; border: 1px solid var(--line);
  border-radius: 12px; padding: 30px; text-align: center; }
.gate h2 { font-family: Georgia, serif; color: var(--navy); margin-top: 0; }
.gate select, .gate input { width: 100%; padding: 10px; font-size: 1rem; border: 1px solid var(--line);
  border-radius: 8px; margin: 14px 0; }
.banner { padding: 10px 14px; border-radius: 8px; font-size: 0.9rem; margin-bottom: 14px; }
.banner.warn { background: #fef3c7; border: 1px solid var(--amber-bd); color: #92400e; }
.banner.err { background: #fee2e2; border: 1px solid #ef4444; color: #991b1b; }
.stageA-locked { opacity: 0.6; pointer-events: none; }
.tag-locked { font-size:0.7rem; background:#e2e8f0; color:#475569; border-radius:5px; padding:2px 7px; margin-left:8px; }
.banner.ok-banner { background: var(--green-bg); border: 1px solid var(--green-bd); color: #166534; }

/* ── Results dashboard ──────────────────────────────────────────────────── */
.results-wrap { max-width: 980px; margin: 0 auto; padding: 22px 18px; }
header.app .who a { margin-right: 12px; text-decoration: none; }
header.app .who #refreshBtn {
  background: rgba(255,255,255,0.15); color: #fff; border: 1px solid rgba(255,255,255,0.35);
  border-radius: 5px; padding: 3px 11px; font-size: 0.8rem; cursor: pointer;
}

.cards { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin: 4px 0 22px; }
@media (max-width: 640px) { .cards { grid-template-columns: repeat(2, 1fr); } }
.card { background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 16px;
  text-align: center; }
.card-val { font-family: Georgia, serif; font-size: 1.9rem; color: var(--navy); font-weight: 700; }
.card-label { font-size: 0.78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--slate);
  margin-top: 4px; }
.card-sub { font-size: 0.72rem; color: var(--slate); }

.matrix-wrap { overflow-x: auto; }
table.matrix { border-collapse: collapse; width: 100%; background: #fff; font-size: 0.88rem;
  border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
table.matrix th, table.matrix td { border: 1px solid var(--line); padding: 7px 10px; text-align: center; }
table.matrix th { background: var(--navy); color: #fff; font-weight: 600; font-size: 0.8rem; }
table.matrix td.rvname { text-align: left; font-weight: 600; color: var(--navy); white-space: nowrap; }
table.matrix td.rvmean { font-weight: 700; background: #f8fafc; }
table.matrix td.score { font-weight: 700; color: #fff; }
table.matrix td.score.empty { color: var(--line); background: #fff; font-weight: 400; }
td.score.s1 { background: #dc2626; } td.score.s2 { background: #f97316; }
td.score.s3 { background: #eab308; } td.score.s4 { background: #65a30d; }
td.score.s5 { background: #16a34a; }

.case-result { background: #fff; border: 1px solid var(--line); border-radius: 10px;
  padding: 14px 16px; margin-bottom: 12px; }
.case-result-head { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.case-result-head .crnum { font-family: Georgia, serif; color: var(--navy); font-weight: 700; font-size: 1.05rem; }
.case-result-head .crcc { color: var(--ink); font-size: 0.92rem; flex: 1; }
.case-result-head .crmean { font-size: 0.85rem; color: var(--slate); font-weight: 600; }
.dist { display: flex; gap: 14px; align-items: flex-end; margin: 14px 0 4px; height: 90px; }
.distcol { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; flex: 1;
  max-width: 56px; height: 100%; }
.distbar-wrap { width: 100%; height: 60px; display: flex; align-items: flex-end; }
.distbar { width: 100%; border-radius: 4px 4px 0 0; min-height: 2px; }
.distbar.s1 { background: #dc2626; } .distbar.s2 { background: #f97316; }
.distbar.s3 { background: #eab308; } .distbar.s4 { background: #65a30d; }
.distbar.s5 { background: #16a34a; }
.distn { font-size: 0.78rem; font-weight: 700; color: var(--ink); margin-top: 3px; }
.distlabel { font-size: 0.72rem; color: var(--slate); }
ul.notes { margin: 8px 0 0; padding-left: 18px; font-size: 0.9rem; line-height: 1.5; }
ul.notes li { margin: 4px 0; }
