/* Read-only web view of the central monitor — mirrors qml/Theme.qml tokens. */

:root,
:root[data-theme="dark"] {
  --bgRoot: #121212;
  --bgTile: #1c1c24;
  --surface: #1e1e2a;
  --surfaceAlt: #262633;
  --field: #14141c;
  --border: #323240;
  --gridLine: #1c242c;
  --textPrimary: #e6e8ea;
  --textSecondary: #c2cad3;
  --textMuted: #9aa6b2;
  --onAccent: #000000;
  --accent: #00bcd4;
  --online: #2ecc71;
  --offline: #e74c3c;
  --ecg: #39d353;
  --spo2: #3fd2e8;
  --resp: #f5d33a;
  --nibp: #ef6a6a;
  --etco2: #c08cf0;
  --temp: #ffa64d;
  --alarmHigh: #d52b2b;
  --alarmMedium: #e8b020;
  --alarmLow: #2b8cd5;
  --font: "Inter", "Segoe UI", Roboto, "Helvetica Neue", Arial, system-ui, sans-serif;
  /* values render in the UI sans on the station too — tabular digits keep
     changing values from shifting the layout */
  --mono: "Inter", "Noto Sans", "Segoe UI", Roboto, "Helvetica Neue", Arial, system-ui, sans-serif;
  color-scheme: dark;
}

:root[data-theme="light"] {
  --bgRoot: #dde2e7;
  --bgTile: #ffffff;
  --surface: #ffffff;
  --surfaceAlt: #e6eaef;
  --field: #ffffff;
  --border: #aab4be;
  --gridLine: #b4c2d0;
  --textPrimary: #1a1f24;
  --textSecondary: #3a444e;
  --textMuted: #5f6b76;
  --onAccent: #ffffff;
  --accent: #00838f;
  --online: #2e7d32;
  --offline: #c62828;
  --ecg: #2e7d32;
  --spo2: #0097a7;
  --resp: #b58a00;
  --nibp: #d32f2f;
  --etco2: #7b3fb0;
  --temp: #e07b00;
  --alarmHigh: #c62828;
  --alarmMedium: #b58a00;
  --alarmLow: #1565c0;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-variant-numeric: tabular-nums;
  background: var(--bgRoot);
  color: var(--textPrimary);
  font-family: var(--font);
  font-size: 13px;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}
button { font-family: inherit; }
.hidden { display: none !important; }
.mono { font-family: var(--mono); }

/* ---------------------------------------------------------------- login -- */
.login {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--bgRoot);
  padding: 16px;
}
.login-card {
  width: min(380px, 100%);
  display: flex; flex-direction: column; gap: 10px;
  padding: 28px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
}
.login-logo { width: 44px; height: 44px; align-self: center; }
.login-brand { text-align: center; font-size: 28px; font-weight: 700; color: var(--spo2); }
.login-sub { text-align: center; color: var(--textMuted); margin: -6px 0 6px; }
.login-label { color: var(--textMuted); font-size: 11px; font-weight: 700; }
.login-card input {
  height: 40px; padding: 0 12px;
  font-size: 15px; font-family: var(--font);
  color: var(--textPrimary); background: var(--field);
  border: 1px solid var(--border); border-radius: 8px; outline: none;
}
.login-card input:focus { border-color: var(--accent); }
.login-error { min-height: 18px; color: var(--alarmHigh); font-weight: 600; text-align: center; }
.login-note { color: var(--textMuted); font-size: 11px; text-align: center; }
.btn {
  height: 40px; margin-top: 6px; padding: 0 16px;
  border-radius: 8px; border: 1px solid var(--accent);
  font-weight: 700; font-size: 14px; cursor: pointer;
}
.btn-fill { background: var(--accent); color: var(--onAccent); border-color: transparent; }
.btn:disabled { opacity: .6; cursor: default; }

/* ------------------------------------------------------------------ app -- */
.app {
  position: fixed; inset: 0;
  display: flex; flex-direction: column; gap: 2px;
}

.titlebar {
  flex: none;
  height: 36px;
  display: flex; align-items: center; gap: 8px;
  padding: 0 10px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.tb-logo { width: 22px; height: 22px; }
.tb-brand { color: var(--accent); font-weight: 700; font-size: 15px; }
.tb-sub { color: var(--textMuted); font-size: 12px; }
.tb-badge {
  font-size: 10px; font-weight: 700; letter-spacing: .5px;
  color: var(--accent);
  border: 1px solid color-mix(in srgb, var(--accent) 55%, transparent);
  border-radius: 4px; padding: 2px 6px;
}
.tb-spacer { flex: 1; }
.tb-link { display: flex; align-items: center; gap: 6px; color: var(--textMuted); font-size: 12px; }
.tb-link .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--textMuted); }
.tb-link.ok .dot { background: var(--online); }
.tb-link.bad .dot { background: var(--offline); }
.tb-link.bad { color: var(--offline); font-weight: 700; }
.tb-btn {
  height: 26px; min-width: 30px; padding: 0 8px;
  border-radius: 6px; border: 1px solid var(--border);
  background: var(--surfaceAlt); color: var(--textPrimary);
  font-size: 12px; font-weight: 700; cursor: pointer;
}
.tb-btn.on { border-color: var(--online); color: var(--online); }
.tb-clock { font-family: var(--mono); font-size: 14px; color: var(--textPrimary); }

/* station alarm banner */
.alarmbar {
  flex: none;
  height: 36px;
  display: flex; align-items: stretch;
  background: var(--surface);
  border: 1px solid var(--border);
}
.alarm-count {
  flex: none;
  display: flex; align-items: center;
  padding: 0 13px;
  font-weight: 700; font-size: 14px; color: white;
  background: var(--surfaceAlt);
}
.alarm-count.p3 { background: var(--alarmHigh); animation: blink-op 480ms infinite; }
.alarm-count.p2 { background: var(--alarmMedium); color: #1a1a1a; animation: blink-op 1200ms infinite; }
.alarm-count.p1 { background: var(--alarmLow); }
.alarm-count.calm { background: var(--surfaceAlt); color: var(--textPrimary); animation: none; }
.alarm-chips {
  flex: 1;
  display: flex; align-items: center; gap: 8px;
  padding: 0 10px;
  overflow-x: auto; scrollbar-width: none;
}
.alarm-chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none;
  display: flex; align-items: center; gap: 7px;
  height: 24px; padding: 0 10px;
  border-radius: 12px; border: 1px solid var(--pc);
  background: color-mix(in srgb, var(--pc) 16%, transparent);
  color: var(--textPrimary); font-weight: 700; font-size: 12.5px;
  cursor: pointer;
}
.chip.silenced { opacity: .5; }
.chip .cdot { width: 9px; height: 9px; border-radius: 50%; background: var(--pc); }
.chip.p3 .cdot { animation: blink-dot 480ms infinite; }
.chip.p2 .cdot { animation: blink-dot 1200ms infinite; }

@keyframes blink-op { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }
@keyframes blink-dot { 0%, 100% { opacity: 1; } 50% { opacity: .15; } }
@keyframes blink-banner { 0%, 100% { opacity: 1; } 50% { opacity: .25; } }

/* bed grid */
.grid {
  flex: 1; min-height: 0;
  margin: 4px;
  display: grid; gap: 4px;
}
.grid { grid-template-columns: 1fr; grid-template-rows: 1fr; }

.empty-slot {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  background: var(--bgTile); border: 1px solid var(--border); border-radius: 2px;
  color: var(--textMuted); font-weight: 700;
}
.empty-slot .glyph { font-size: 30px; color: var(--border); font-weight: 400; }
.empty-slot .sub { font-size: 11px; font-weight: 400; }

/* ----------------------------------------------------------------- tile -- */
.tile {
  position: relative;
  min-width: 0; min-height: 0;
  display: flex; flex-direction: column;
  background: var(--bgTile);
  border: 1px solid var(--border);
  overflow: hidden;
  --alarm: var(--border);
}
.tile.big { background: color-mix(in srgb, var(--accent) 14%, var(--bgTile)); }
.tile.ap3 { --alarm: var(--alarmHigh); border: 4px solid var(--alarm); }
.tile.ap2 { --alarm: var(--alarmMedium); border: 4px solid var(--alarm); }
.tile.ap1 { --alarm: var(--alarmLow); border: 3px solid var(--alarm); }
.tile.ap3:not(.silenced) { animation: tile-hi 480ms infinite; }
.tile.ap2:not(.silenced) { animation: tile-med 1200ms infinite; }
@keyframes tile-hi { 0%, 100% { border-width: 5px; } 50% { border-width: 3px; } }
@keyframes tile-med { 0%, 100% { border-width: 5px; } 50% { border-width: 3px; } }

.thead {
  flex: none;
  height: 24px;
  display: flex; align-items: center; gap: 10px;
  padding: 0 4px 0 8px;
  background: var(--surfaceAlt);
  white-space: nowrap;
}
.tile.fetal .thead { height: 30px; }
.tile.ap1 .thead { background: color-mix(in srgb, var(--alarm) 47%, var(--surfaceAlt)); }
.tile.ap2 .thead, .tile.ap3 .thead { background: color-mix(in srgb, var(--alarm) 55%, var(--surfaceAlt)); }
.tile.ap3:not(.silenced) .thead { animation: head-hi 480ms infinite; }
.tile.ap2:not(.silenced) .thead { animation: head-med 1200ms infinite; }
.tile.silenced .thead { background: color-mix(in srgb, var(--alarm) 27%, var(--surfaceAlt)); }
@keyframes head-hi {
  0%, 100% { background: color-mix(in srgb, var(--alarm) 55%, var(--surfaceAlt)); }
  50% { background: color-mix(in srgb, var(--alarm) 25%, var(--surfaceAlt)); }
}
@keyframes head-med {
  0%, 100% { background: color-mix(in srgb, var(--alarm) 55%, var(--surfaceAlt)); }
  50% { background: color-mix(in srgb, var(--alarm) 25%, var(--surfaceAlt)); }
}
.thead .cdot { flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--spo2); }
.thead .cdot.live { background: var(--online); }
.thead .cdot.connected { background: var(--alarmMedium); }
.thead .cdot.stale { background: var(--offline); }
.thead .cdot.waiting { background: var(--textMuted); }
.thead .bname { font-weight: 700; font-size: 13px; }
.thead .binfo { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; color: var(--textMuted); font-size: 11px; }
.pill {
  flex: none;
  height: 22px; padding: 0 8px;
  display: flex; align-items: center; gap: 4px;
  border-radius: 6px; border: 1px solid var(--accent);
  background: color-mix(in srgb, var(--accent) 16%, transparent); color: var(--accent);
  font-weight: 700; font-size: 11px; cursor: pointer;
}
.pill.muted { border-color: var(--border); background: transparent; color: var(--textMuted); cursor: default; }
.rec {
  flex: none;
  height: 24px; padding: 0 10px;
  display: flex; align-items: center; gap: 6px;
  border-radius: 12px; border: 1.5px solid var(--alarmHigh);
  background: color-mix(in srgb, var(--alarmHigh) 22%, transparent);
  color: var(--alarmHigh); font-weight: 700; font-size: 12px;
}
.rec .rdot { animation: blink-op 1200ms infinite; }
.phase {
  flex: none;
  height: 24px; padding: 0 9px;
  display: flex; align-items: center; gap: 5px;
  border-radius: 12px; border: 1.5px solid var(--border);
  background: color-mix(in srgb, var(--textMuted) 12%, transparent);
  font-family: var(--mono); font-size: 11px;
}
.phase.over { border-color: var(--alarmMedium); color: var(--alarmMedium); }
.phase.alarm { border-color: var(--alarmHigh); color: var(--alarmHigh); font-weight: 700;
  background: color-mix(in srgb, var(--alarmHigh) 22%, transparent); }
.phase.alarm .pglyph { animation: blink-op 1000ms infinite; }

.banner {
  flex: none;
  height: 20px; padding: 0 9px;
  display: flex; align-items: center;
  border-radius: 4px;
  font-weight: 700; font-size: 12px; color: white;
}
.banner.p3 { background: var(--alarmHigh); }
.banner.p2 { background: var(--alarmMedium); color: #1a1a1a; }
.banner.p1 { background: var(--alarmLow); }
.banner.p3:not(.silenced) { animation: blink-banner 480ms infinite; }
.banner.p2:not(.silenced) { animation: blink-banner 1200ms infinite; }
.banner.silenced { opacity: .75; }

.tbody {
  flex: 1; min-height: 0;
  display: flex;
  cursor: pointer;
}
.waves { flex: 1; min-width: 0; display: flex; flex-direction: column; }
/* portrait phone: curves / CTG on top, numbers below */
.tile.portrait .tbody { flex-direction: column; }
.tile.portrait .waves { flex: none; height: 52%; }
.tile.portrait.vent .waves { height: 40%; }
.tile.portrait .ctgwrap { flex: none; height: 60%; }
.wrow { position: relative; flex: 1; min-height: 0; }
.wrow canvas { position: absolute; left: 0; top: 2px; width: 100%; height: calc(100% - 4px); }
.wrow .wlabel { position: absolute; left: 4px; top: 0; font-size: 10px; font-weight: 700; pointer-events: none; }
.wrow .wunit { position: absolute; right: 4px; top: 0; font-size: 9px; color: var(--textMuted); pointer-events: none; }
.grid-on .wrow canvas {
  background-image:
    linear-gradient(to right, var(--gridLine) 1px, transparent 1px),
    linear-gradient(to bottom, var(--gridLine) 1px, transparent 1px);
  background-size: 18.9px 18.9px;
}

.ctgwrap { position: relative; flex: 1; min-width: 0; margin: 2px; }
.ctgwrap canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.ctgzoom { position: absolute; top: 3px; right: 6px; display: flex; gap: 4px; }
.ctgzoom button, .ctgzoom span {
  height: 22px; min-width: 22px; padding: 0 5px;
  border-radius: 4px; border: 1px solid rgba(255,255,255,.35);
  background: rgba(0,0,0,.45); color: #e6edf5;
  font-size: 13px; font-weight: 700; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.ctgzoom span { font-size: 11px; color: #cfe0f0; cursor: default; border-color: rgba(255,255,255,.25); }
.ctgzoom .yz { font-size: 10px; }

.overlay {
  position: absolute; left: 0; right: 0; bottom: 0; top: 26px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  background: rgba(11, 14, 17, .85);
  z-index: 5; text-align: center; padding: 8px;
}
.overlay .og { font-size: 34px; }
.overlay .ot { font-size: 16px; font-weight: 700; }
.overlay .os { font-size: 11px; color: var(--textMuted); }
.overlay.stale { color: var(--alarmHigh); }
.overlay.connected { color: var(--alarmMedium); }

/* ------------------------------------------------------------ numerics -- */
.num { min-width: 0; min-height: 0; overflow: hidden; position: relative; --s: 1; }
.num.fill { flex: 1; }
.ncol { position: absolute; inset: 0; display: flex; flex-direction: column; gap: 2px;
  padding: calc(6px * var(--s)); }
.nl { display: flex; align-items: baseline; gap: 5px; font-weight: 700; line-height: 1.35;
  font-size: max(9px, calc(13px * var(--s))); }
.nl .u { font-weight: 400; color: var(--textMuted); }
.nl .r { margin-left: auto; font-weight: 400; }
.nv { font-family: var(--mono); font-weight: 600; line-height: 1.3;
  font-size: max(12px, calc(var(--em) * 1px * var(--s))); white-space: nowrap; }
.nrow { display: flex; gap: calc(8px * var(--s)); }
.nrow > div { display: flex; flex-direction: column; }
.nbig { position: absolute; inset: 0; display: grid; grid-template-columns: repeat(3, 1fr);
  align-content: start; column-gap: calc(18px * var(--s)); row-gap: calc(6px * var(--s));
  padding: calc(12px * var(--s)); }
.nbig .span2 { grid-column: span 2; }
.fbig { position: absolute; inset: 10px; display: grid; gap: 8px 14px; }
.fbig .fc { display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 0; overflow: hidden; }
.fbig .fl { display: flex; gap: 5px; align-items: baseline; font-weight: 700; }
.fbig .fv { font-family: var(--mono); font-weight: 600; line-height: 1; white-space: nowrap; }

.alarmv-3 { animation: alarm-v3 480ms infinite; }
.alarmv-2 { animation: alarm-v2 1200ms infinite; }
.alarmv-1 { color: var(--alarmLow) !important; }
@keyframes alarm-v3 { 0%, 100% { color: var(--alarmHigh); } 50% { color: color-mix(in srgb, var(--alarmHigh) 67%, white); } }
@keyframes alarm-v2 { 0%, 100% { color: var(--alarmMedium); } 50% { color: color-mix(in srgb, var(--alarmMedium) 67%, white); } }

/* ------------------------------------------------------------ ventilator -- */
.vent { min-width: 0; min-height: 0; overflow: hidden; position: relative; }
.vent.fill { flex: 1; }
.vside, .vcompact { position: absolute; inset: 0; display: flex; flex-direction: column; overflow: hidden; }
.vbig { position: absolute; inset: 0; overflow-y: auto; background: var(--bgTile); }
.vbig-in { display: flex; flex-direction: column; }
.vrow { display: flex; align-items: center; flex-wrap: wrap; }
.vgrid { display: grid; }
.pbox { position: relative; border-radius: 6px; border: 1px solid; display: flex; flex-direction: column; justify-content: center; min-width: 0; overflow: hidden; }
.pbox .bar { position: absolute; left: 1px; top: 1px; bottom: 1px; width: 3px; border-radius: 1.5px; }
.pbox .ph { display: flex; align-items: baseline; gap: 5px; white-space: nowrap; overflow: hidden; }
.pbox .ph b { flex: none; }
.pbox .ph span { overflow: hidden; text-overflow: ellipsis; }
.pbox .pv { display: flex; align-items: center; gap: 4px; }
.pbox .lim { font-family: var(--mono); line-height: 1.25; flex: none; }
.pbox .val { flex: 1; text-align: right; font-family: var(--mono); font-weight: 600; white-space: nowrap; overflow: hidden; line-height: 1.1; }
.sbox { display: inline-flex; flex-direction: column; align-items: center; border-radius: 5px;
  border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent);
  background: color-mix(in srgb, var(--accent) 9%, transparent); }
.sbox .sl { color: var(--textMuted); }
.sbox .sv { font-family: var(--mono); font-weight: 700; color: var(--accent); }
.sbox .su { color: var(--textMuted); margin-left: 3px; }
.kv { display: grid; }
.kvr { display: flex; align-items: center; gap: 6px; border-bottom: 1px solid color-mix(in srgb, var(--border) 45%, transparent); padding: 2px 0; min-width: 0; }
.kvr .k { flex: 1; min-width: 0; color: var(--textSecondary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kvr .v { font-family: var(--mono); font-weight: 700; white-space: nowrap; }
.kvr .u { color: var(--textMuted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: none; }
.vcard { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; }
.vcard > .ct { font-weight: 700; letter-spacing: .6px; padding-bottom: 6px; border-bottom: 1px solid var(--border); margin-bottom: 6px; }
.arow { display: flex; align-items: center; gap: 6px; border-radius: 4px; padding: 3px 6px; }
.arow .adot { flex: none; border-radius: 50%; }
.mode { border-radius: 4px; background: var(--accent); color: var(--onAccent); font-weight: 700; }
.state { display: inline-flex; align-items: center; gap: 5px; border-radius: 999px; border: 1px solid; font-weight: 700; }
.state i { border-radius: 50%; display: inline-block; }

/* ------------------------------------------------------------ bottom bar -- */
.bottombar {
  flex: none;
  height: 32px;
  display: flex; align-items: center; gap: 6px;
  padding: 0 8px;
  background: var(--surface);
  white-space: nowrap;
}
.bb-label { color: var(--textMuted); }
.bb-group { display: flex; gap: 4px; align-items: center; }
.bb-btn {
  position: relative;
  height: 24px; min-width: 32px; padding: 0 8px;
  border-radius: 5px; border: 1px solid var(--border);
  background: var(--surfaceAlt); color: var(--textPrimary);
  font-weight: 700; font-size: 12px; cursor: pointer;
}
.bb-btn.sel { background: var(--accent); color: var(--onAccent); border-color: var(--accent); }
.bb-btn:disabled { opacity: .35; cursor: default; }
.bb-btn .adot {
  position: absolute; top: -3px; right: -3px;
  width: 11px; height: 11px; border-radius: 50%;
  border: 1.5px solid var(--surface);
}
.bb-btn .adot.p3 { background: var(--alarmHigh); animation: blink-dot 480ms infinite; }
.bb-btn .adot.p2 { background: var(--alarmMedium); animation: blink-dot 1200ms infinite; }
.bb-btn .adot.p1 { background: var(--alarmLow); }
.pager .pg { color: var(--textMuted); font-family: var(--mono); font-size: 12px; padding: 0 2px; }
/* one tab per bed: the bed on screen highlighted, an alarm shown by its colour */
.bb-tabs {
  flex: 1; min-width: 0;
  display: flex; gap: 4px; align-items: center;
  overflow-x: auto; scrollbar-width: none;
}
.bb-tabs::-webkit-scrollbar { display: none; }
.bb-tab {
  flex: none; position: relative;
  height: 24px; padding: 0 10px;
  display: flex; align-items: center; gap: 6px;
  border-radius: 5px; border: 1px solid var(--border);
  background: var(--surfaceAlt); color: var(--textPrimary);
  font-weight: 700; font-size: 12px; cursor: pointer;
}
.bb-tab.sel { background: var(--accent); color: var(--onAccent); border-color: var(--accent); }
.bb-tab .tdot { width: 8px; height: 8px; border-radius: 50%; background: var(--online); }
.bb-tab .tdot.stale { background: var(--offline); }
.bb-tab .tdot.connected { background: var(--alarmMedium); }
.bb-tab.p3 { border-color: var(--alarmHigh); box-shadow: inset 0 0 0 1px var(--alarmHigh); }
.bb-tab.p2 { border-color: var(--alarmMedium); box-shadow: inset 0 0 0 1px var(--alarmMedium); }
.bb-tab.p1 { border-color: var(--alarmLow); }
.bb-tab.p3 .tdot { background: var(--alarmHigh); animation: blink-dot 480ms infinite; }
.bb-tab.p2 .tdot { background: var(--alarmMedium); animation: blink-dot 1200ms infinite; }
.bb-info { color: var(--textMuted); font-size: 11px; }

.offline {
  position: fixed; left: 50%; top: 46px; transform: translateX(-50%);
  z-index: 100;
  padding: 10px 18px; border-radius: 8px;
  background: #c0392b; color: white; font-weight: 700;
  border: 1px solid white;
  box-shadow: 0 4px 16px rgba(0,0,0,.4);
}

/* Phones / narrow windows: compact bars. */
@media (max-width: 760px) {
  .tb-sub, .tb-badge, .tb-link span { display: none; }
  #logoutBtn { font-size: 0; }
  #logoutBtn::before { content: "⎋"; font-size: 14px; }
  .tb-clock { font-size: 12px; }
  #bedCount, #version { display: none; }
}
