* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 14px/1.45 var(--sans);
  -webkit-font-smoothing: antialiased;
}

button, select, input { font: inherit; color: inherit; }
a { color: var(--red); text-decoration: none; }
a:hover { text-decoration: underline; }
[hidden] { display: none !important; }
h1, h2 { margin: 0; letter-spacing: -0.02em; }
.label { font-size: 12px; font-weight: 500; color: var(--muted); }
.spacer { flex: 1; }

button {
  cursor: pointer;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  border-radius: 10px;
  padding: 8px 14px;
  line-height: 1.1;
  font-weight: 500;
}
button:hover { border-color: var(--rose); background: var(--surface-2); }
button:disabled { opacity: 0.45; cursor: not-allowed; }
button.ghost { background: transparent; }
button.primary { background: var(--red); border-color: var(--red); color: #fff; font-weight: 600; }
button.primary:hover { background: var(--coral); border-color: var(--coral); }
button.big { width: 100%; padding: 15px 18px; font-size: 16px; border-radius: 12px; }
button.danger { color: var(--alarm); }
:focus-visible { outline: 2px solid var(--red); outline-offset: 2px; }
:focus:not(:focus-visible) { outline: none; }

select {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  padding: 8px 10px;
}

.segmented { display: flex; padding: 3px; gap: 3px; background: var(--surface-2); border-radius: 12px; }
.segmented button { flex: 1; border: 0; background: transparent; color: var(--muted); padding: 8px 10px; border-radius: 9px; }
.segmented button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: 0 1px 0 var(--line-strong), 0 0 0 1px var(--line); }

/* Shell: sidebar and views */
.shell { display: grid; grid-template-columns: 272px minmax(0, 1fr); height: 100vh; min-height: 720px; }
.sidebar {
  display: flex; flex-direction: column; gap: 22px;
  padding: 24px 20px;
  background: var(--surface);
  border-right: 1px solid var(--line);
  overflow: auto;
}
.brand { display: flex; align-items: center; gap: 12px; color: var(--text); text-decoration: none !important; }
.brand .word { display: flex; flex-direction: column; gap: 4px; }
.brand b { font: 650 25px/0.95 var(--sans); letter-spacing: -0.045em; }
.brand em { font-style: normal; color: var(--red); }
.brand small { font-size: 12px; color: var(--muted); }

.person { display: flex; flex-direction: column; align-items: flex-start; gap: 3px; text-align: left; padding: 10px 14px; background: var(--bg); }
.person #person-name { font-size: 15px; font-weight: 600; }

.nav { display: flex; flex-direction: column; gap: 4px; }
.nav button {
  display: flex; align-items: flex-start; gap: 12px; text-align: left;
  border: 0; background: transparent; padding: 11px 12px; border-radius: 12px; font-size: 15px; font-weight: 600;
}
.nav button small { display: block; font-size: 12px; font-weight: 400; color: var(--muted); margin-top: 2px; }
.nav button .n {
  flex: 0 0 24px; height: 24px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  font: 600 12px/1 var(--sans); color: var(--red); background: var(--surface-2); margin-top: 1px;
}
.nav button:hover { background: var(--bg); }
.nav button[aria-current="page"] { background: var(--surface-2); }
.nav button[aria-current="page"] .n { background: var(--red); color: #fff; }

.source { display: flex; flex-direction: column; gap: 10px; margin-top: auto; padding-top: 18px; border-top: 1px solid var(--line); }
.controls { display: flex; flex-direction: column; gap: 10px; }
.field { display: flex; flex-direction: column; gap: 5px; font-size: 12px; font-weight: 500; color: var(--muted); }
.truth { margin: 0; font: 400 12px/1.4 var(--mono); color: var(--muted); }
.status { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.status .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--faint); flex: none; }
.status[data-state="live"] .dot { background: var(--red); box-shadow: 0 0 0 3px rgb(245 49 74 / 0.18); animation: beat 1s ease-in-out infinite; }
.status[data-state="error"] .dot { background: var(--alarm); }
.status[data-state="error"] { color: var(--text); }
@keyframes beat { 0%, 100% { transform: scale(1); } 15% { transform: scale(1.35); } 30% { transform: scale(1); } }
@media (prefers-reduced-motion: reduce) { .status .dot { animation: none !important; } }
.side-foot { margin: 0; font-size: 12px; color: var(--faint); }

.views { min-width: 0; overflow: auto; }
.view { display: flex; flex-direction: column; gap: 18px; padding: 28px 32px 32px; min-height: 100%; }
.view-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; }
.view-head h1 { font: 650 30px/1.1 var(--sans); }
.view-head p { margin: 6px 0 0; color: var(--muted); font-size: 14px; }
.view-head .actions { display: flex; gap: 8px; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: 18px; }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; padding: 18px 20px 0; }
.card-head h2 { font: 600 16px/1.2 var(--sans); }
.legend { margin: 0; display: flex; align-items: center; flex-wrap: wrap; gap: 6px 14px; font-size: 12.5px; color: var(--muted); }
.legend .k { display: inline-block; width: 14px; height: 3px; border-radius: 2px; margin-right: -8px; vertical-align: middle; }
.k.ecg { background: var(--ecg); } .k.scg { background: var(--scg); } .k.ppg { background: var(--ppg); }
.k.sbp { background: var(--sbp); } .k.dbp { background: var(--dbp); }
.k.ptt { background: none; border-top: 2px solid var(--ptt); height: 6px; border-left: 2px solid var(--ptt); border-right: 2px solid var(--ptt); border-radius: 0; }
.canvas-box { position: relative; flex: 1; min-height: 0; }
.canvas-box canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

/* Measure */
.hero { display: grid; grid-template-columns: auto minmax(0, 1fr) 260px; gap: 32px; align-items: center; padding: 22px 26px; }
.bp { display: flex; align-items: flex-end; gap: 10px; }
.bp .num { display: flex; flex-direction: column; gap: 6px; }
.bp b { font: 650 84px/0.85 var(--sans); letter-spacing: -0.055em; font-variant-numeric: tabular-nums; }
.bp #sbp { color: var(--red); }
.bp .num span { font-size: 12.5px; font-weight: 500; color: var(--muted); }
.bp i { font: 300 64px/0.9 var(--sans); color: var(--rose); font-style: normal; align-self: flex-start; }
.bp small { font-size: 14px; font-weight: 500; color: var(--muted); margin-bottom: 26px; }
.hero-side { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.when { margin: 0; font-size: 12.5px; font-weight: 500; color: var(--muted); }
.note { margin: 0; color: var(--text-2); font-size: 14px; }
.vitals { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin-top: 4px; }
.vitals div { background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; display: flex; flex-direction: column; gap: 6px; }
.vitals span { font-size: 12px; color: var(--muted); }
.vitals b { font: 650 24px/1 var(--sans); letter-spacing: -0.03em; font-variant-numeric: tabular-nums; }
.vitals b span { color: var(--text); font-size: inherit; }
.vitals small { font-size: 12px; font-weight: 500; color: var(--muted); margin-left: 4px; }
.hero-action { display: flex; flex-direction: column; gap: 10px; }
.progress { position: relative; height: 49px; border-radius: 12px; background: var(--surface-2); overflow: hidden; }
.progress i { position: absolute; inset: 0 auto 0 0; width: 0; background: rgb(245 49 74 / 0.22); border-right: 2px solid var(--red); }
.progress span { position: relative; display: flex; height: 100%; align-items: center; justify-content: center; font-size: 13.5px; font-weight: 600; color: var(--text); }
.quality { margin: 0; font-size: 12.5px; color: var(--muted); min-height: 18px; }
.quality.warn { color: var(--warn); }
.signals { flex: 1; min-height: 360px; display: flex; flex-direction: column; }
.signals .canvas-box { margin: 10px 12px 12px; }

/* Calibrate */
.steps { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.step { background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 18px; display: flex; flex-direction: column; gap: 12px; }
.step .top { display: flex; align-items: center; gap: 10px; }
.step .num { width: 28px; height: 28px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-weight: 650; font-size: 13px; color: var(--red); background: var(--surface-2); }
.step.done .num { background: var(--red); color: #fff; }
.step .label { font-size: 16px; font-weight: 650; color: var(--text); }
.step .sub { margin: 0; color: var(--muted); font-size: 13px; min-height: 36px; }
.step .cuff { display: flex; align-items: center; gap: 8px; }
.step .cuff label { display: flex; flex-direction: column; gap: 4px; font-size: 11.5px; color: var(--muted); flex: 1; }
.step input { width: 100%; background: var(--bg); border: 1px solid var(--line-strong); border-radius: 10px; padding: 9px 10px; font-size: 16px; font-weight: 600; font-variant-numeric: tabular-nums; }
.step .over { color: var(--rose); font-size: 22px; margin-top: 14px; }
.step .result { margin: 0; font-size: 13px; color: var(--text-2); min-height: 18px; }
.step.done .result { color: var(--text); font-weight: 600; }
.fit { flex: 1; min-height: 300px; display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(260px, 1fr); }
.fit-chart { display: flex; flex-direction: column; min-height: 0; border-right: 1px solid var(--line); }
.fit-chart .canvas-box { margin: 8px 12px 12px; }
.fit-side { display: flex; flex-direction: column; gap: 12px; padding: 20px; }
.fit-side h2 { font: 600 16px/1.2 var(--sans); }
.model { margin: 0; font: 500 14px/1.6 var(--mono); color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.model small { display: block; font: 400 12px/1.4 var(--sans); color: var(--muted); margin-top: 4px; }
.fit-text { margin: 0; font: 400 13px/1.6 var(--mono); color: var(--text-2); white-space: pre-line; flex: 1; }

/* History */
.trend { height: 300px; display: flex; flex-direction: column; }
.trend .canvas-box { margin: 8px 12px 12px; }
.table { overflow: auto; }
.table table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.table th { text-align: left; font-size: 12px; font-weight: 500; color: var(--muted); padding: 14px 18px 10px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--surface); }
.table td { padding: 11px 18px; border-bottom: 1px solid var(--line); }
.table tr:last-child td { border-bottom: 0; }
.table td.s { color: var(--red); font-weight: 650; }
.table td.d { color: var(--coral); font-weight: 650; }
.table td.notes { color: var(--muted); font-size: 12.5px; }
.empty { color: var(--faint); font-size: 13px; padding: 16px 18px; margin: 0; }

/* People dialog */
dialog { border: 1px solid var(--line-strong); border-radius: 18px; background: var(--surface); color: var(--text); padding: 0; width: min(680px, calc(100vw - 32px)); box-shadow: 0 24px 60px rgb(43 11 18 / 0.18); }
dialog::backdrop { background: rgb(43 11 18 / 0.35); }
.dialog > header { padding: 22px 24px 0; }
.dialog h2 { margin: 0 0 6px; font: 650 20px/1.2 var(--sans); }
.dialog p { margin: 0; color: var(--muted); }
.dialog-body { display: grid; grid-template-columns: 200px 1fr; gap: 20px; padding: 18px 24px; }
.person-list ul { list-style: none; margin: 10px 0; padding: 0; display: flex; flex-direction: column; gap: 4px; max-height: 280px; overflow: auto; }
.person-list li button { width: 100%; text-align: left; background: transparent; border-color: transparent; padding: 9px 10px; }
.person-list li button[aria-pressed="true"] { background: var(--surface-2); border-color: var(--line); }
.person-list li small { display: block; color: var(--muted); font-size: 11.5px; font-weight: 400; margin-top: 3px; }
.person-fields { display: flex; flex-direction: column; gap: 12px; }
.person-fields label { display: flex; flex-direction: column; gap: 6px; color: var(--muted); font-size: 12px; font-weight: 500; }
.person-fields input { background: var(--bg); border: 1px solid var(--line-strong); border-radius: 10px; padding: 9px 10px; }
.dialog > footer { display: flex; align-items: center; gap: 8px; padding: 14px 24px 20px; border-top: 1px solid var(--line); }

/* Printable report */
.report { display: none; }
@media print {
  @page { margin: 16mm; }
  html, body { background: #fff; color: #111; }
  body > :not(.report) { display: none !important; }
  .report { display: block; font: 400 11pt/1.45 var(--sans); }
  .report h1 { font: 650 20pt/1.1 var(--sans); letter-spacing: -0.02em; margin: 0 0 4pt; color: var(--red); }
  .report h2 { font: 600 12pt/1.2 var(--sans); margin: 16pt 0 6pt; }
  .report p { margin: 0 0 6pt; color: #444; }
  .report table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
  .report th, .report td { text-align: left; padding: 4pt 6pt; border-bottom: 0.5pt solid #e6c4c4; }
  .report th { font-size: 8.5pt; color: #8f5d65; font-weight: 500; }
  .report .disclaimer { margin-top: 18pt; font-size: 9pt; color: #666; }
}

@media (max-width: 1180px) {
  .hero { grid-template-columns: auto minmax(0, 1fr); }
  .hero-action { grid-column: 1 / -1; }
}
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; height: auto; }
  .sidebar {
    display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 12px;
    padding: 14px 16px; border-right: 0; border-bottom: 1px solid var(--line); overflow: visible;
  }
  .brand img { width: 32px; height: 32px; }
  .brand b { font-size: 21px; }
  .brand small { display: none; }
  .person { padding: 6px 12px; }
  .nav { grid-column: 1 / -1; flex-direction: row; gap: 4px; }
  .nav button { flex: 1; justify-content: center; padding: 9px 6px; font-size: 14px; }
  .nav button .n, .nav button small { display: none; }
  .source { grid-column: 1 / -1; margin-top: 0; padding-top: 12px; display: grid; grid-template-columns: 1fr 1fr; gap: 8px 10px; }
  .source > .label { display: none; }
  .source .segmented, .source .status, .source #device-controls { grid-column: 1 / -1; }
  #demo-controls { grid-column: 1 / -1; display: grid; grid-template-columns: 1fr 1fr; gap: 8px 10px; }
  #demo-controls .truth { grid-column: 1 / -1; }
  .side-foot { grid-column: 1 / -1; }
  .card-head { flex-wrap: wrap; }
  .view { padding: 20px 16px; }
  .view-head { flex-direction: column; align-items: flex-start; }
  .hero { grid-template-columns: 1fr; gap: 18px; }
  .bp b { font-size: 64px; }
  .steps { grid-template-columns: 1fr; }
  .fit { grid-template-columns: 1fr; }
  .fit-chart { border-right: 0; border-bottom: 1px solid var(--line); min-height: 260px; }
  .signals { min-height: 420px; }
  .trend { height: 240px; }
  .table td, .table th { padding-left: 10px; padding-right: 10px; }
  .dialog-body { grid-template-columns: 1fr; }
}
