:root {
  --bg: #f3f5f8; --panel: #ffffff; --ink: #1b2430; --muted: #5f6b7a; --faint: #8a95a3; --line: #dfe4ea;
  --accent: #1f5fa8; --accent-soft: #e8f0fa; --brand: #102a43;
  --met: #1d7a46; --met-soft: #e4f4ea; --notmet: #b42318; --notmet-soft: #fdecea;
  --unk: #8a5a00; --unk-soft: #fdf3dc; --sel: #fff5c2; --cited: #ffe98a;
  --radius: 8px; --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --topbar: 48px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
       color: var(--ink); background: var(--bg); -webkit-font-smoothing: antialiased; }
button { font: inherit; cursor: pointer; color: inherit; }
button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible, .row:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px; }
h1, h2, h3 { margin: 0; }

/* ---- top bar ---- */
.topbar { height: var(--topbar); display: flex; align-items: center; gap: 14px; padding: 0 16px;
          background: var(--brand); color: #fff; position: sticky; top: 0; z-index: 10; }
.brand { font-weight: 650; white-space: nowrap; }
#crumbs { flex: 1; min-width: 0; display: flex; gap: 6px; overflow: hidden; white-space: nowrap; }
#crumbs a { color: #c9dcf2; text-decoration: none; overflow: hidden; text-overflow: ellipsis; }
#crumbs a + a::before { content: "›"; margin-right: 6px; color: #7f9bbb; }
#crumbs a:hover { color: #fff; }
#who { font-size: 13px; color: #c9dcf2; display: flex; align-items: center; gap: 10px; white-space: nowrap; }
#who button { background: transparent; border: 1px solid #5d7e9f; color: #fff; border-radius: 6px; padding: 3px 10px; }
main { padding: 14px; }

/* ---- shared ---- */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.primary { background: var(--accent); color: #fff; border: 0; border-radius: 6px; padding: 8px 16px; font-weight: 600; }
.primary:hover { background: #184f8d; }
.ghost { background: #fff; border: 1px solid var(--line); border-radius: 6px; padding: 3px 10px; font-size: 12.5px; }
.ghost:hover { border-color: var(--accent); color: var(--accent); }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px; border-radius: 999px; font-size: 12px;
        background: #eef1f5; color: var(--muted); white-space: nowrap; }
.chip.met, .chip.include, .chip.likely_eligible { background: var(--met-soft); color: var(--met); }
.chip.not_met, .chip.exclude, .chip.excluded, .chip.not_eligible { background: var(--notmet-soft); color: var(--notmet); }
.chip.unknown, .chip.unsure, .chip.needs_data { background: var(--unk-soft); color: var(--unk); }
.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.bar { height: 6px; background: #e7ebf0; border-radius: 999px; overflow: hidden; min-width: 80px; }
.bar > span { display: block; height: 100%; background: var(--met); }

/* ---- sign in ---- */
.login { max-width: 420px; margin: 12vh auto; }
.login h2 { margin-bottom: 6px; }
.login input { width: 100%; padding: 9px 10px; border: 1px solid var(--line); border-radius: 6px; margin: 12px 0;
               font-family: var(--mono); }

/* ---- worklist ---- */
.worklist { max-width: 1100px; margin: 0 auto; }
.worklist h2 { margin-bottom: 4px; }
.worklist .group-title { margin: 18px 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
table.list { width: 100%; border-collapse: collapse; background: var(--panel); }
table.list th, table.list td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.list th { font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; background: #f8fafc; }
table.list tr.click:hover { background: var(--accent-soft); cursor: pointer; }
table.list td.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.tid { font-family: var(--mono); font-size: 12.5px; white-space: nowrap; }

/* ---- task workspace: patients | chart | checklist ---- */
.workspace { display: grid; gap: 12px; height: calc(100vh - var(--topbar) - 28px);
             grid-template-columns: 240px minmax(0, 1fr) minmax(340px, 400px); }
.pane { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: auto; min-height: 0; min-width: 0; }

.plist .head { padding: 10px 12px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: #fff; z-index: 1; }
.plist .head input { width: 100%; margin-top: 8px; padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; }
.plist .p { padding: 8px 12px; border-bottom: 1px solid var(--line); cursor: pointer; border-left: 3px solid transparent; }
.plist .p:hover { background: #f6f9fd; }
.plist .p.active { background: var(--accent-soft); border-left-color: var(--accent); }
.plist .name { font-weight: 600; }
.plist .sub { font-size: 12px; color: var(--muted); margin: 1px 0 3px; }

/* switcher shown instead of the patient list on narrower screens */
.pbar { display: none; align-items: center; gap: 8px; padding: 8px 12px; border-bottom: 1px solid var(--line); background: #fff; }
.pbar select { flex: 1; min-width: 0; padding: 5px 6px; border: 1px solid var(--line); border-radius: 6px; background: #fff; }

.banner { padding: 12px 14px 10px; border-bottom: 1px solid var(--line); background: #f8fafc; }
.banner .pname { font-size: 17px; font-weight: 650; }
.banner .facts { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 14px; margin-top: 3px; color: var(--muted); font-size: 13px; }
.banner .facts b { color: var(--ink); font-weight: 600; }
.tabs { display: flex; gap: 2px; padding: 0 8px; border-bottom: 1px solid var(--line); background: #fff;
        position: sticky; top: 0; z-index: 2; overflow-x: auto; scrollbar-width: none; }
.tabs button { border: 0; background: none; padding: 10px 12px; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs button:hover { color: var(--ink); }
.tabs button.on { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.tabs .count { font-size: 11px; background: #eef1f5; border-radius: 999px; padding: 0 6px; margin-left: 4px; color: var(--muted); }
.tabbody { padding: 10px 14px 18px; }

.section + .section { margin-top: 14px; }
.section h3 { font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 6px 0 4px; font-weight: 650; }
.row { display: grid; grid-template-columns: 86px minmax(0, 1fr) auto; gap: 2px 10px; align-items: baseline;
       padding: 5px 8px; border-radius: 6px; }
.row .date { font-family: var(--mono); font-size: 12px; color: var(--faint); }
.row .what { min-width: 0; overflow-wrap: anywhere; }
.row .meta { font-size: 12px; color: var(--muted); text-align: right; white-space: nowrap; }
.row .meta.active { color: var(--met); }
.row.citable { cursor: copy; }
.row.citable:hover { background: var(--sel); }
.row.cited { box-shadow: inset 3px 0 0 #e0b400; background: #fffbe6; }
.empty { color: var(--faint); padding: 4px 8px; font-size: 13px; }

table.results td { font-size: 13px; }
table.results td.val { font-variant-numeric: tabular-nums; white-space: nowrap; }
.flag-H, .flag-L { color: var(--notmet); font-weight: 650; }
.filter { width: 100%; padding: 7px 9px; border: 1px solid var(--line); border-radius: 6px; margin-bottom: 8px; }

.docs { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 12px; align-items: start; }
.doclist { position: sticky; top: 46px; max-height: calc(100vh - 220px); overflow: auto; }
.doclist .d { padding: 6px 8px; border-radius: 6px; cursor: pointer; border-left: 3px solid transparent; }
.doclist .d:hover { background: #f6f9fd; }
.doclist .d.on { background: var(--accent-soft); border-left-color: var(--accent); }
.doclist .d .t { font-weight: 600; font-size: 13px; }
.docselect { display: none; width: 100%; padding: 6px; border: 1px solid var(--line); border-radius: 6px; margin-bottom: 8px; }
.doc { font-family: var(--mono); font-size: 12.5px; line-height: 1.5; border: 1px solid var(--line); border-radius: 6px; padding: 8px 4px; background: #fcfdfe; }
.doc .ln { padding: 0 8px; border-radius: 3px; min-height: 1.5em; white-space: pre-wrap; overflow-wrap: anywhere; }
.doc .ln.citable { cursor: copy; }
.doc .ln.citable:hover { background: var(--sel); }
.doc .ln.cited { background: var(--cited); }
pre.protocol { white-space: pre-wrap; font-size: 13px; font-family: inherit; margin: 0; }

/* ---- checklist ---- */
.checklist { display: flex; flex-direction: column; }
.checklist .head { padding: 12px 14px; border-bottom: 1px solid var(--line); background: #fff; position: sticky; top: 0; z-index: 2; }
.checklist .q { font-weight: 650; }
.progress { display: flex; align-items: center; gap: 8px; margin-top: 6px; font-size: 12px; color: var(--muted); }
.progress .bar { flex: 1; }
.hint { font-size: 12px; color: var(--muted); margin-top: 6px; }
.hint .act { color: var(--accent); font-weight: 600; }
.crit { padding: 9px 14px; border-bottom: 1px solid var(--line); scroll-margin-top: 120px; }
.crit.active { background: #f4f8fe; box-shadow: inset 3px 0 0 var(--accent); }
.crit .top { display: grid; grid-template-columns: 34px minmax(0, 1fr) auto; gap: 6px; align-items: baseline; cursor: pointer; }
.crit .cid { font-weight: 700; font-variant-numeric: tabular-nums; }
.crit .sum { min-width: 0; }
.kind { font-size: 10.5px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; padding: 1px 6px; border-radius: 4px; }
.kind.inclusion { color: #1f5fa8; background: #e8f0fa; }
.kind.exclusion { color: #7a3fa0; background: #f3eafa; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; margin-top: 7px; background: #fff; }
.seg button { border: 0; background: #fff; padding: 4px 10px; font-size: 12.5px; border-right: 1px solid var(--line); }
.seg button:last-child { border-right: 0; }
.seg button:hover { background: #f3f6f9; }
.seg button.on.met, .seg button.on.include { background: var(--met); color: #fff; }
.seg button.on.not_met, .seg button.on.exclude { background: var(--notmet); color: #fff; }
.seg button.on.unknown, .seg button.on.unsure { background: var(--unk); color: #fff; }
.ev { margin-top: 6px; display: flex; flex-direction: column; gap: 3px; }
.ev .e { display: flex; align-items: baseline; gap: 6px; font-size: 12px; background: #fffbe6; border: 1px solid #f0dd8a;
         border-radius: 5px; padding: 2px 6px; }
.ev .e span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ev .e button { border: 0; background: none; padding: 0 2px; color: var(--muted); line-height: 1; }
.ev .e button:hover { color: var(--notmet); }
.crit textarea, .foot textarea { width: 100%; margin-top: 7px; border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px;
                                 font: inherit; font-size: 13px; resize: vertical; }
.foot { padding: 12px 14px; border-top: 1px solid var(--line); background: #f8fafc; position: sticky; bottom: 0; z-index: 2; }
.foot .derived { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; font-size: 13px; }
.foot .actions { display: flex; align-items: center; gap: 12px; margin-top: 8px; }
.compare { margin: 10px 14px 0; padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius); background: #fbfcfe; font-size: 13px; }
.compare .line { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.compare .line + .line { margin-top: 6px; }
.compare .dis { color: var(--notmet); }

#toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: var(--brand); color: #fff;
         padding: 8px 14px; border-radius: 6px; opacity: 0; transition: opacity .2s; pointer-events: none; z-index: 20; max-width: 90vw; }
#toast.show { opacity: 1; }
#toast.err { background: var(--notmet); }

/* ---- narrower screens ---- */
@media (max-width: 1280px) {
  .workspace { grid-template-columns: minmax(0, 1fr) minmax(320px, 380px); }
  .plist { display: none; }
  .pbar { display: flex; }
}
@media (max-width: 980px) {
  .docs { grid-template-columns: minmax(0, 1fr); }
  .doclist { display: none; }
  .docselect { display: block; }
}
@media (max-width: 820px) {
  main { padding: 8px; }
  .workspace { grid-template-columns: minmax(0, 1fr); height: auto; }
  .pane.chart { max-height: 62vh; }
  .pane.checklist { overflow: visible; }
  .brand { display: none; }
  .row { grid-template-columns: 78px minmax(0, 1fr); }
  .row .meta { grid-column: 2; text-align: left; }
}
table.list tr.cited td { background: #fffbe6; }
table.list tr.cited td:first-child { box-shadow: inset 3px 0 0 #e0b400; }

/* protocol tab */
.protocol { font-size: 13.5px; line-height: 1.55; max-width: 760px; }
.protocol p.md { margin: 0 0 8px; }
.protocol ul.md { margin: 0 0 8px; padding-left: 18px; }
.protocol ul.md li { margin: 0 0 6px; }
.protocol strong { font-weight: 650; }
.protocol .proto-h { font-size: 13px; margin: 14px 0 6px; color: var(--ink); }
.protocol .proto-item { display: grid; grid-template-columns: 28px minmax(0, 1fr); gap: 4px; margin: 0 0 7px; }
.protocol .proto-item .n { color: var(--muted); font-variant-numeric: tabular-nums; }
.protocol .proto-or { font-weight: 700; color: var(--accent); margin: 2px 0 7px 28px; }
.protocol p.md.proto-alt { margin-left: 32px; }
a.button { display: inline-block; text-align: center; text-decoration: none; margin-bottom: 10px; }
.login p.err { color: var(--notmet); }

/* ---- one-trial home page ---- */
.worklist.home .card, .worklist .card.protocol { margin-bottom: 14px; }
.card.trial h1 { font-size: 30px; margin: 2px 0 4px; }
.card.trial .eyebrow { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.card.trial .full { font-weight: 600; margin: 0 0 6px; }
.card.trial .facts { display: flex; flex-wrap: wrap; gap: 6px 22px; margin: 12px 0 16px; color: var(--muted); }
.card.trial .facts b { color: inherit; color: #1b2330; }
.card .actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
a.button.ghost { border: 1px solid var(--line); border-radius: 6px; padding: 8px 16px; color: inherit; margin-bottom: 0; }
.card.how ol { margin: 6px 0 0 18px; padding: 0; line-height: 1.55; }
.card.how li { margin-bottom: 4px; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 8px; }
.progress.wide .bar { width: 160px; }
.workspace.single { grid-template-columns: minmax(0, 1fr) minmax(340px, 420px); }
@media (max-width: 820px) { .workspace.single { grid-template-columns: minmax(0, 1fr); } }
.login input { margin: 6px 0; }
.login .primary { width: 100%; margin-top: 8px; }
.login .or { text-align: center; color: var(--muted); margin: 12px 0 8px; font-size: 13px; }
.login a.button.ghost { display: block; }
.login select { width: 100%; padding: 9px 10px; border: 1px solid var(--line); border-radius: 6px; margin: 6px 0; background: #fff; }
