/* AiBtl clinical platform — follows docs/aibtl-design-rules.md.
   Deviation for the investor demo: status uses green/amber/red tones (rules §4 reserve these). */

:root {
  --mist: #F4F7FA;
  --white: #FFFFFF;
  --hairline: #DDE3E9;
  --ink: #2B2B2B;
  --text-2: #535353;
  --muted: #6B7280;
  --blue: #0077BB;
  --blue-pressed: #005F96;
  --blue-tint: #E6F2FA;
  --blue-tint-text: #0A4F7D;
  --blue-outline: #B9D8EE;
  --ok: #1E6B2E; --ok-tint: #E7F4EA; --ok-solid: #2E7D32;
  --warn: #6B4A00; --warn-tint: #FFF6DC; --warn-solid: #F2A900;
  --bad: #8E1B1B; --bad-tint: #FDECEC; --bad-solid: #C62828;
  --sim: #5B3E96; --sim-tint: #F1ECFA;
  --radius: 8px;
  --font-head: "Montserrat", system-ui, sans-serif;
  --font-body: "Roboto", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--mist);
  color: var(--ink);
  font: 400 15px/1.5 var(--font-body);
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { font-family: var(--font-head); font-weight: 600; margin: 0; color: var(--ink); }
h1 { font-size: 26px; line-height: 1.25; }
h2 { font-size: 19px; }
h3 { font-size: 16px; font-weight: 500; }
p { margin: 0 0 8px; }
:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }
[x-cloak] { display: none !important; }

/* ---------- shell ---------- */
.demo-banner {
  background: var(--sim-tint); color: var(--sim); font-size: 13px; text-align: center;
  padding: 6px 16px; border-bottom: 1px solid #DCD0F2;
}
.topbar {
  background: var(--white); border-bottom: 1px solid var(--hairline);
  display: flex; align-items: center; gap: 24px; padding: 0 24px; height: 60px;
  position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none !important; }
.brand-plate {
  display: inline-flex; align-items: center; gap: 4px; padding: 3px 10px 3px 4px; border-radius: 999px;
  background: linear-gradient(90deg, #38B44C, #0077BB); color: #fff; font: 700 13px/1 var(--font-head); letter-spacing: .5px;
}
.brand-plate .ai { border: 1.5px solid #fff; border-radius: 999px; padding: 2px 6px; }
.brand-name { font: 600 15px var(--font-head); }
.brand-name small { display: block; font: 400 12px var(--font-body); color: var(--muted); }
.nav { display: flex; gap: 4px; flex: 1; }
.nav a {
  color: var(--text-2); padding: 8px 12px; border-radius: var(--radius); font-weight: 500; font-size: 14px;
}
.nav a:hover { background: var(--mist); text-decoration: none; }
.nav a.active { background: var(--blue-tint); color: var(--blue-tint-text); }
.userbox { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.userbox .who { text-align: right; line-height: 1.3; }
.userbox .who small { color: var(--muted); display: block; }
.avatar {
  width: 32px; height: 32px; border-radius: 50%; background: var(--blue-tint); color: var(--blue-tint-text);
  display: inline-flex; align-items: center; justify-content: center; font-weight: 500; font-size: 13px; flex: none;
}
.avatar.lg { width: 44px; height: 44px; font-size: 16px; }
.main { max-width: 1280px; margin: 0 auto; padding: 24px; }
.footer { max-width: 1280px; margin: 0 auto; padding: 16px 24px 40px; color: var(--muted); font-size: 12px; display: flex; gap: 16px; flex-wrap: wrap; }

/* ---------- layout helpers ---------- */
.row { display: flex; gap: 16px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.row.top { align-items: flex-start; }
.spacer { flex: 1; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.side { grid-template-columns: minmax(0, 1fr) 360px; align-items: start; }
.stack > * + * { margin-top: 16px; }
.stack-sm > * + * { margin-top: 8px; }
.mt { margin-top: 16px; } .mt-lg { margin-top: 24px; } .mb { margin-bottom: 16px; }
.muted { color: var(--muted); }
.meta { color: var(--muted); font-size: 13px; }
.small { font-size: 13px; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
@media (max-width: 960px) {
  .g2, .g3, .g4, .side { grid-template-columns: 1fr; }
  .topbar { flex-wrap: wrap; height: auto; padding: 10px 16px; gap: 10px; }
  .nav { order: 3; width: 100%; overflow-x: auto; }
  .main { padding: 16px; }
}

/* ---------- cards ---------- */
.card { background: var(--white); border: 1px solid var(--hairline); border-radius: var(--radius); }
.card-pad { padding: 16px 20px; }
.card-head { display: flex; align-items: center; gap: 12px; padding: 14px 20px; border-bottom: 1px solid var(--hairline); }
.card-head h2, .card-head h3 { flex: 1; }
.card-body { padding: 16px 20px; }
.card.spine { display: flex; overflow: hidden; }
.card.spine > .bar { width: 4px; flex: none; }
.card.spine > .content { flex: 1; min-width: 0; }
.bar.bad { background: var(--bad-solid); } .bar.warn { background: var(--warn-solid); } .bar.ok { background: var(--ok-solid); } .bar.blue { background: var(--blue); }

/* ---------- page header ---------- */
.page-head { display: flex; align-items: flex-end; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head .title { flex: 1; min-width: 260px; }
.crumbs { font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.crumbs a { color: var(--muted); }

/* Patient identification: name + participant code always together, same place on every screen. */
.patient-bar {
  background: var(--white); border: 1px solid var(--hairline); border-radius: var(--radius);
  display: flex; align-items: center; gap: 16px; padding: 14px 20px; margin-bottom: 20px; flex-wrap: wrap;
}
.patient-bar .ident { min-width: 220px; }
.patient-bar .name { font: 600 20px var(--font-head); }
.patient-bar .code { font-weight: 500; color: var(--blue-tint-text); }
.patient-bar .facts { display: flex; gap: 24px; flex-wrap: wrap; font-size: 13px; color: var(--text-2); flex: 1; }
.patient-bar .facts b { display: block; font-weight: 500; color: var(--ink); font-size: 14px; }
.tabs { display: flex; gap: 4px; margin: -8px 0 20px; border-bottom: 1px solid var(--hairline); flex-wrap: wrap; }
.tabs a { padding: 10px 14px; color: var(--text-2); font-weight: 500; font-size: 14px; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a:hover { text-decoration: none; color: var(--ink); }
.tabs a.active { color: var(--blue); border-bottom-color: var(--blue); }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 44px; padding: 0 18px;
  border-radius: var(--radius); font: 500 15px var(--font-body); cursor: pointer; border: 1px solid transparent;
  text-decoration: none !important; white-space: nowrap;
}
.btn-primary { background: var(--blue); color: #fff; }
.btn-primary:hover { background: var(--blue-pressed); }
.btn-secondary { background: transparent; border-color: var(--blue-outline); color: var(--blue-tint-text); }
.btn-secondary:hover { background: var(--blue-tint); }
.btn-danger { background: transparent; border-color: var(--bad-solid); color: var(--bad); }
.btn-text { background: none; border: none; color: var(--blue); padding: 0 6px; height: 36px; }
.btn-sm { height: 34px; padding: 0 12px; font-size: 14px; }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; }
.btn-lg { height: 48px; padding: 0 22px; font-size: 16px; }

/* ---------- chips / status ---------- */
.chip {
  display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 10px; border-radius: 999px;
  font-size: 12px; font-weight: 500; white-space: nowrap; background: var(--mist); color: var(--text-2);
}
.chip::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; opacity: .8; }
.chip.plain::before { display: none; }
.chip.ok { background: var(--ok-tint); color: var(--ok); }
.chip.warn { background: var(--warn-tint); color: var(--warn); }
.chip.bad { background: var(--bad-tint); color: var(--bad); }
.chip.info { background: var(--blue-tint); color: var(--blue-tint-text); }
.chip.sim { background: var(--sim-tint); color: var(--sim); }
.chip.sim::before { border-radius: 2px; }

.notice {
  display: flex; gap: 12px; padding: 12px 16px; border-radius: var(--radius); font-size: 14px; align-items: flex-start;
  background: var(--blue-tint); color: var(--blue-tint-text);
}
.notice .ico { flex: none; width: 20px; height: 20px; border-radius: 50%; border: 1.5px solid currentColor; display: inline-flex; align-items: center; justify-content: center; font: 700 12px var(--font-body); margin-top: 1px; }
.notice.ok { background: var(--ok-tint); color: var(--ok); }
.notice.warn { background: var(--warn-tint); color: var(--warn); }
.notice.bad { background: var(--bad-tint); color: var(--bad); }
.notice.sim { background: var(--sim-tint); color: var(--sim); }
.notice.neutral { background: var(--mist); color: var(--text-2); border: 1px solid var(--hairline); }
.notice b { font-weight: 500; }

/* ---------- clinical values (value outranks label) ---------- */
.kv { display: flex; flex-direction: column; gap: 2px; }
.kv .label { font-size: 13px; color: var(--text-2); }
.kv .value { font: 500 32px/1.1 var(--font-body); }
.kv .value.md { font-size: 24px; }
.kv .value .unit { font-size: 15px; font-weight: 400; color: var(--text-2); margin-left: 4px; }
.kv .sub { font-size: 13px; color: var(--muted); }
.delta { font-size: 13px; font-weight: 500; }
.delta.down { color: var(--ok); } .delta.up { color: var(--bad); }

/* ---------- tables ---------- */
table.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th { text-align: left; font-weight: 500; color: var(--text-2); font-size: 13px; padding: 10px 12px; border-bottom: 1px solid var(--hairline); white-space: nowrap; }
.tbl td { padding: 11px 12px; border-bottom: 1px solid var(--hairline); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: none; }
.tbl tr.clickable { cursor: pointer; }
.tbl tr.clickable:hover td { background: #F8FAFC; }
.tbl .num { text-align: right; }
.tbl-wrap { overflow-x: auto; }

/* ---------- forms ---------- */
label.lbl { display: block; font-weight: 500; font-size: 14px; margin-bottom: 6px; }
.input, select.input, textarea.input {
  width: 100%; height: 44px; padding: 0 12px; border: 1px solid #C5CED8; border-radius: var(--radius);
  font: 400 15px var(--font-body); color: var(--ink); background: #fff;
}
textarea.input { height: auto; min-height: 110px; padding: 10px 12px; line-height: 1.5; resize: vertical; }
.input:focus { outline: 2px solid var(--blue); outline-offset: 0; border-color: var(--blue); }
.field + .field { margin-top: 16px; }
.help { font-size: 13px; color: var(--muted); margin-top: 4px; }
.error { color: var(--bad); font-size: 13px; margin-top: 4px; }
.check { display: flex; gap: 10px; align-items: flex-start; font-size: 14px; cursor: pointer; }
.check input { width: 18px; height: 18px; margin-top: 2px; accent-color: var(--blue); }

/* Rating scale rows */
.item-row { display: grid; grid-template-columns: 34px minmax(0, 1fr) auto 64px; gap: 14px; align-items: center; padding: 12px 20px; border-bottom: 1px solid var(--hairline); }
.item-row:last-child { border-bottom: none; }
.item-row.missing { background: #FFFBF0; }
.item-num { width: 28px; height: 28px; border-radius: 50%; background: var(--mist); display: inline-flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 500; color: var(--text-2); }
.item-label { font-weight: 500; }
.item-label small { display: block; font-weight: 400; color: var(--muted); font-size: 12px; }
.scale { display: flex; gap: 6px; }
.scale label { position: relative; }
.scale input { position: absolute; opacity: 0; pointer-events: none; }
.scale span {
  display: inline-flex; width: 40px; height: 40px; align-items: center; justify-content: center; border-radius: var(--radius);
  border: 1px solid #C5CED8; font-weight: 500; cursor: pointer; background: #fff; user-select: none;
}
.scale input:checked + span { background: var(--blue); color: #fff; border-color: var(--blue); }
.scale input:focus-visible + span { outline: 2px solid var(--blue); outline-offset: 2px; }
.scale input:disabled + span { cursor: default; }
.scale input:disabled:not(:checked) + span { color: #B0B8C2; border-color: var(--hairline); }
.prev { font-size: 12px; color: var(--muted); text-align: right; white-space: nowrap; }
.prev b { color: var(--text-2); font-weight: 500; font-size: 14px; }
.domain-head { padding: 10px 20px; background: #F8FAFC; border-bottom: 1px solid var(--hairline); font-size: 13px; font-weight: 500; color: var(--text-2); }
@media (max-width: 720px) {
  .item-row { grid-template-columns: 28px 1fr; }
  .item-row .scale, .item-row .prev { grid-column: 2; }
  .scale span { width: 36px; height: 36px; }
}

/* Sticky score panel */
.score-panel { position: sticky; top: 76px; }
.score-big { font: 500 56px/1 var(--font-body); }
.score-big .of { font-size: 20px; color: var(--muted); font-weight: 400; }
.meter { height: 8px; background: var(--mist); border-radius: 999px; overflow: hidden; margin: 12px 0 6px; }
.meter > div { height: 100%; background: var(--blue); }

/* ---------- attention list ---------- */
.attn { display: flex; align-items: center; gap: 16px; padding: 14px 20px; border-bottom: 1px solid var(--hairline); }
.attn:last-child { border-bottom: none; }
.attn .who { flex: 1; min-width: 0; }
.attn .who b { font-weight: 500; font-size: 15px; }
.attn .who .meta { display: block; }

/* ---------- timeline ---------- */
.chart-card { padding: 14px 20px 10px; }
.chart-head { display: flex; align-items: baseline; gap: 12px; margin-bottom: 6px; flex-wrap: wrap; }
.chart-head h3 { font-size: 15px; }
.chart-head .agg { font-size: 12px; color: var(--muted); }
.chart-box { position: relative; height: 150px; }
.chart-box.tall { height: 230px; }
.legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 12px; color: var(--muted); margin-top: 6px; }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 2px; margin-right: 6px; vertical-align: -2px; }
.event { display: flex; gap: 14px; padding: 12px 20px; border-bottom: 1px solid var(--hairline); align-items: flex-start; }
.event:last-child { border-bottom: none; }
.event .when { width: 132px; flex: none; font-size: 13px; color: var(--muted); }
.event .dot { width: 10px; height: 10px; border-radius: 50%; margin-top: 6px; flex: none; }
.event .what { flex: 1; min-width: 0; }
.event .what b { font-weight: 500; }
.event .what .meta { display: block; }
.cat-clinical { background: var(--blue); }
.cat-visit { background: var(--blue-tint-text); }
.cat-wearable { background: #5AA9D6; }
.cat-quality { background: var(--warn-solid); }
.cat-participant { background: var(--bad-solid); }
.filters { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.filters .field { margin: 0; }
.chipcheck input { display: none; }
.chipcheck span { display: inline-flex; align-items: center; height: 34px; padding: 0 12px; border: 1px solid #C5CED8; border-radius: 999px; font-size: 13px; cursor: pointer; background: #fff; }
.chipcheck input:checked + span { background: var(--blue); color: #fff; border-color: var(--blue); }

/* ---------- modal ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(20, 30, 45, .45); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 16px; }
.modal { background: #fff; border-radius: var(--radius); max-width: 560px; width: 100%; border: 1px solid var(--hairline); }
.modal .card-head { border-bottom: 1px solid var(--hairline); }
.modal .actions { display: flex; gap: 12px; justify-content: flex-end; padding: 14px 20px; border-top: 1px solid var(--hairline); }
.restate { background: var(--mist); border-radius: var(--radius); padding: 12px 14px; font-size: 14px; }
.restate dt { color: var(--muted); font-size: 12px; }
.restate dd { margin: 0 0 8px; font-weight: 500; }

/* ---------- misc ---------- */
.stat-tiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
@media (max-width: 960px) { .stat-tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.stat { padding: 16px 20px; }
.stat .n { font: 500 30px/1.1 var(--font-body); }
.stat .l { font-size: 13px; color: var(--text-2); }
.stat.solid { border: 0; color: #fff; }
.stat.solid .l { color: rgba(255, 255, 255, .92); font-weight: 500; }
.stat.s-green { background: #2E7D32; }
.stat.s-blue { background: #0077BB; }
.stat.s-teal { background: #00796B; }
.stat.s-navy { background: #0A4F7D; }
.card-head .hico { flex: none; width: 30px; height: 30px; border-radius: 8px; display: inline-flex; align-items: center; justify-content: center; color: #fff; }
.card-head .hico svg { width: 17px; height: 17px; }
.dl { display: grid; grid-template-columns: 180px minmax(0, 1fr); gap: 8px 16px; font-size: 14px; margin: 0; }
.dl dt { color: var(--muted); }
.dl dd { margin: 0; word-break: break-word; }
code, .mono { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-size: 12.5px; }
pre.json { background: var(--mist); border: 1px solid var(--hairline); border-radius: var(--radius); padding: 12px; overflow: auto; font-size: 12px; margin: 0; }
.empty { padding: 28px 20px; text-align: center; color: var(--text-2); }
.pill-step { display: inline-flex; align-items: center; justify-content: center; width: 22px; height: 22px; border-radius: 50%; background: var(--blue); color: #fff; font-size: 12px; font-weight: 500; margin-right: 8px; }
.steps { display: flex; gap: 8px; flex-wrap: wrap; font-size: 13px; color: var(--text-2); }
.steps .s { display: flex; align-items: center; padding: 6px 12px 6px 6px; border-radius: 999px; background: var(--white); border: 1px solid var(--hairline); }
.steps .s.done .pill-step { background: var(--ok-solid); }
.steps .s.todo .pill-step { background: #fff; color: var(--muted); border: 1px solid #C5CED8; }
.steps .s.now { border-color: var(--blue); color: var(--ink); font-weight: 500; }
.login-wrap { min-height: 100vh; display: grid; grid-template-columns: 1fr 1fr; }
.login-art { background: var(--white); color: var(--blue); padding: 56px; display: flex; flex-direction: column; justify-content: space-between; border-right: 1px solid var(--hairline); }
.login-art h1 { color: var(--blue); font-size: 34px; max-width: 460px; }
.login-art p { color: var(--blue); max-width: 460px; font-size: 16px; }
.login-form { display: flex; align-items: center; justify-content: center; padding: 32px; background: linear-gradient(135deg, #38B44C 0%, #0077BB 70%); }
.login-form .box { width: 100%; max-width: 420px; background: var(--white); border-radius: 12px; padding: 32px; box-shadow: 0 12px 32px rgba(0, 40, 80, .18); }
@media (max-width: 860px) { .login-wrap { grid-template-columns: 1fr; } .login-art { padding: 32px; } }
.demo-users { margin-top: 24px; font-size: 13px; }
.demo-users button { display: flex; width: 100%; text-align: left; gap: 10px; align-items: center; padding: 8px 10px; border: 1px solid var(--hairline); background: #fff; border-radius: var(--radius); cursor: pointer; margin-top: 6px; font: inherit; }
.demo-users button:hover { background: var(--blue-tint); }
