:root {
  --bg: #06101c;
  --panel: rgba(11, 21, 35, 0.92);
  --panel-2: rgba(17, 30, 48, 0.88);
  --stroke: rgba(122, 151, 191, 0.22);
  --text: #edf4ff;
  --muted: #9fb0c8;
  --cyan: #5fd4d6;
  --blue: #6f95ff;
  --green: #5cff8b;
  --yellow: #ffe95d;
  --red: #ff7175;
  --white-wave: #f4f6fb;
  --radius: 18px;
  --font-scale: 1;
  color-scheme: dark;
  font-family: "Segoe UI", "Aptos", "Trebuchet MS", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  margin: 0;
  background:
    radial-gradient(circle at 8% 0%, rgba(95, 212, 214, 0.18), transparent 28rem),
    radial-gradient(circle at 95% 8%, rgba(111, 149, 255, 0.18), transparent 30rem),
    linear-gradient(145deg, #06101c 0%, #071322 58%, #030915 100%);
  color: var(--text);
}

body {
  overflow-x: hidden;
}

button,
input,
select,
a {
  font: inherit;
}

button,
.primary-link,
.topnav a {
  border: 1px solid var(--stroke);
  border-radius: 14px;
  background: rgba(24, 38, 59, 0.88);
  color: var(--text);
  text-decoration: none;
  cursor: pointer;
  transition: transform 160ms ease, border-color 160ms ease, background 160ms ease;
}

button:hover,
.primary-link:hover,
.topnav a:hover {
  transform: translateY(-1px);
  border-color: rgba(95, 212, 214, 0.62);
}

.app-shell {
  width: min(1200px, calc(100vw - 24px));
  min-height: 100svh;
  margin: 0 auto;
  padding: 16px 0 18px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 74px;
  margin-bottom: 14px;
  padding: 14px 18px;
  border: 1px solid var(--stroke);
  border-radius: 22px;
  background: rgba(6, 16, 28, 0.8);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.24);
  backdrop-filter: blur(20px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
  color: var(--text);
  text-decoration: none;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: linear-gradient(135deg, rgba(95, 212, 214, 0.38), rgba(111, 149, 255, 0.16));
  color: #9ffff4;
  font-weight: 800;
  letter-spacing: 0.04em;
}

.brand strong {
  display: block;
  font-size: clamp(1.45rem, 2.2vw, 2rem);
  line-height: 1;
}

.brand small {
  display: block;
  margin-top: 6px;
  color: var(--muted);
}

.topnav {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.topnav a,
.topnav button,
.primary-link {
  padding: 12px 16px;
}

.topnav a.active {
  background: linear-gradient(135deg, rgba(95, 212, 214, 0.35), rgba(111, 149, 255, 0.28));
  border-color: rgba(95, 212, 214, 0.65);
}

.session-panel {
  display: grid;
  grid-template-columns: minmax(220px, 0.72fr) minmax(0, 1fr);
  gap: 14px;
  align-items: center;
  margin-bottom: 14px;
  padding: 12px 16px;
  border: 1px solid var(--stroke);
  border-radius: 20px;
  background: rgba(9, 20, 34, 0.78);
  backdrop-filter: blur(16px);
}

.session-copy {
  display: grid;
  gap: 3px;
}

.session-copy span {
  color: var(--cyan);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.session-copy strong {
  font-size: 1.2rem;
}

.session-copy small {
  color: var(--muted);
}

.session-actions {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.session-actions button,
.session-actions input {
  min-height: 42px;
}

.session-actions button {
  padding: 9px 12px;
}

.session-actions input {
  width: 100px;
  border: 1px solid var(--stroke);
  border-radius: 13px;
  background: rgba(3, 10, 18, 0.72);
  color: var(--text);
  font-weight: 800;
  letter-spacing: 0.14em;
  padding: 0 12px;
  text-align: center;
}

.session-actions input::placeholder {
  color: var(--muted);
  font-weight: 600;
  letter-spacing: 0;
}

.session-panel.is-remote {
  border-color: rgba(95, 212, 214, 0.5);
  box-shadow: 0 0 40px rgba(95, 212, 214, 0.08);
}

.monitor-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 14px;
  align-items: start;
}

.monitor-stack {
  display: grid;
  gap: 10px;
  min-width: 0;
}

.vital-row {
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr);
  min-height: clamp(118px, calc((100svh - 168px) / 4), 160px);
  border: 1px solid var(--stroke);
  border-radius: var(--radius);
  background: rgba(5, 12, 22, 0.86);
  overflow: hidden;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.015);
}

.metric {
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-width: 0;
  padding: 18px 16px 16px;
}

.metric-label {
  color: var(--muted);
  font-size: calc(0.78rem * var(--font-scale));
  letter-spacing: 0.14em;
}

.metric-value {
  align-self: end;
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-size: calc(clamp(3.2rem, 7vw, 5.2rem) * var(--font-scale));
  font-weight: 800;
  line-height: 0.86;
  text-shadow: 0 0 20px currentColor;
}

.metric-value small {
  color: var(--muted);
  font-size: calc(1.7rem * var(--font-scale));
  text-shadow: none;
}

.metric-value.is-live {
  filter: brightness(1.18);
}

.bp-value {
  font-size: calc(clamp(2.2rem, 5vw, 3.6rem) * var(--font-scale));
}

.etco2-value {
  gap: 16px;
  font-size: calc(clamp(2.9rem, 6vw, 4.5rem) * var(--font-scale));
}

.etco2-value small {
  font-weight: 700;
  white-space: nowrap;
}

.metric-note {
  min-height: 1.2em;
  color: var(--muted);
  font-size: calc(0.86rem * var(--font-scale));
}

.metric-hr {
  color: var(--green);
}

.metric-spo2 {
  color: var(--yellow);
}

.metric-bp {
  color: var(--red);
}

.metric-etco2 {
  color: var(--white-wave);
}

.wave-stage {
  position: relative;
  min-width: 0;
  margin: 12px 12px 12px 0;
  border: 1px solid rgba(122, 151, 191, 0.14);
  border-radius: 16px;
  background:
    linear-gradient(rgba(116, 135, 164, 0.055) 1px, transparent 1px),
    linear-gradient(90deg, rgba(116, 135, 164, 0.055) 1px, transparent 1px),
    rgba(7, 14, 24, 0.94);
  background-size: 100% 25%, 7.15% 100%, auto;
  overflow: hidden;
}

.wave-stage::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(90deg, transparent 0%, rgba(255, 255, 255, 0.025) 50%, transparent 100%);
  mix-blend-mode: screen;
}

.sweep-line {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 4;
  width: 2px;
  pointer-events: none;
  background: linear-gradient(to bottom, transparent, rgba(153, 236, 255, 0.96), transparent);
  box-shadow:
    0 0 12px rgba(95, 212, 214, 0.95),
    0 0 34px rgba(95, 212, 214, 0.28);
  opacity: 0.86;
}

@keyframes sweep-line {
  from {
    left: -4px;
  }
  to {
    left: 100%;
  }
}

.ct-chart,
.ct-chart svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.ct-grids,
.ct-labels,
.ct-point {
  display: none;
}

.ct-line {
  fill: none;
  stroke-width: 3px;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.ecg_waveform .ct-line {
  stroke: var(--green);
  filter: drop-shadow(0 0 5px rgba(92, 255, 139, 0.75));
}

.pleth_waveform .ct-line {
  stroke: var(--yellow);
  filter: drop-shadow(0 0 5px rgba(255, 233, 93, 0.72));
}

.bp_waveform .ct-line {
  stroke: var(--red);
  filter: drop-shadow(0 0 5px rgba(255, 113, 117, 0.72));
}

.etco2_waveform .ct-line {
  stroke: var(--white-wave);
  filter: drop-shadow(0 0 5px rgba(244, 246, 251, 0.72));
}

.wipe_in svg {
  clip-path: inset(0 100% 0 0);
  animation: wipe-in 5s linear forwards;
}

.wipe_out svg {
  clip-path: inset(0 0 0 0);
  animation: wipe-out 5s linear forwards;
}

.etco2_waveform.wipe_in svg,
.etco2_waveform.wipe_out svg {
  animation-duration: 10s;
}

@keyframes wipe-in {
  to {
    clip-path: inset(0 0 0 0);
  }
}

@keyframes wipe-out {
  to {
    clip-path: inset(0 0 0 100%);
  }
}

.monitor-footer {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 70px;
  padding: 12px 16px;
  border: 1px solid var(--stroke);
  border-radius: var(--radius);
  background: rgba(12, 24, 39, 0.82);
}

.monitor-footer .primary-link {
  margin-left: auto;
  background: linear-gradient(135deg, var(--cyan), var(--blue));
  color: #031322;
  border: 0;
}

input[type="range"] {
  accent-color: var(--cyan);
}

.display-panel {
  position: sticky;
  top: 12px;
  padding: 16px;
  border: 1px solid var(--stroke);
  border-radius: 22px;
  background: rgba(17, 30, 48, 0.82);
  backdrop-filter: blur(16px);
}

.display-panel.is-collapsed .button-grid,
.display-panel.is-collapsed p {
  display: none;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: start;
}

.panel-head h2 {
  margin: 10px 0 8px;
  font-size: 1.05rem;
}

.panel-head p {
  margin: 0 0 14px;
  color: var(--muted);
  line-height: 1.45;
}

.button-grid,
.preset-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.button-grid button,
.preset-grid button {
  min-height: 48px;
  padding: 10px;
}

.button-grid button.is-active {
  background: linear-gradient(135deg, rgba(95, 212, 214, 0.86), rgba(111, 149, 255, 0.92));
  color: #04111e;
}

.is-hidden {
  display: none !important;
}

.wave-hidden .wave-stage {
  opacity: 0.08;
}

.wave-hidden .ct-chart {
  display: none;
}

.control-page {
  display: grid;
  gap: 14px;
}

.control-hero,
.control-card,
.control-actions {
  border: 1px solid var(--stroke);
  border-radius: 22px;
  background: rgba(11, 21, 35, 0.86);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.16);
}

.control-hero {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 22px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--cyan);
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.control-hero h1 {
  margin: 0 0 10px;
  font-size: clamp(2rem, 4vw, 3.4rem);
  line-height: 1;
}

.control-hero p:last-child {
  margin: 0;
  max-width: 62ch;
  color: var(--muted);
}

.control-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.span-2 {
  grid-column: span 2;
}

.control-card,
.control-actions {
  padding: 18px;
}

.control-card label {
  display: block;
  margin-bottom: 14px;
  color: var(--muted);
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.control-card select,
.control-card input[type="range"] {
  width: 100%;
}

.control-card select {
  min-height: 52px;
  padding: 0 14px;
  border: 1px solid var(--stroke);
  border-radius: 14px;
  background: #101c2e;
  color: var(--text);
}

.control-number {
  display: grid;
  grid-template-columns: 74px 1fr 74px;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}

.control-number output {
  display: grid;
  place-items: center;
  min-height: 58px;
  border-radius: 16px;
  background: rgba(3, 10, 18, 0.62);
  color: var(--cyan);
  font-size: 2rem;
  font-weight: 800;
}

.control-actions {
  display: flex;
  align-items: center;
  gap: 16px;
}

.apply-button {
  min-height: 54px;
  padding: 0 22px;
  border: 0;
  background: linear-gradient(135deg, var(--cyan), var(--blue));
  color: #04111e;
  font-weight: 800;
}

#controlStatus {
  color: var(--muted);
}

.alarm {
  animation: alarm-pulse 760ms ease-in-out infinite alternate;
}

@keyframes alarm-pulse {
  from {
    box-shadow: inset 0 0 0 1px rgba(255, 113, 117, 0.08);
  }
  to {
    box-shadow: inset 0 0 34px rgba(255, 113, 117, 0.18);
  }
}

@media (max-width: 1020px) {
  .app-shell {
    width: min(100vw - 16px, 760px);
    padding-top: 8px;
  }

  .monitor-grid {
    grid-template-columns: 1fr;
  }

  .display-panel {
    position: static;
  }

  .session-panel {
    grid-template-columns: 1fr;
  }

  .session-actions {
    justify-content: flex-start;
  }

  .vital-row {
    grid-template-columns: minmax(116px, 31vw) minmax(0, 1fr);
    min-height: clamp(104px, calc((100svh - 246px) / 4), 132px);
  }

  .metric {
    padding: 14px 10px;
  }

  .metric-value {
    font-size: calc(clamp(2.05rem, 8vw, 3.4rem) * var(--font-scale));
  }

  .bp-value,
  .etco2-value {
    font-size: calc(clamp(1.75rem, 7vw, 2.7rem) * var(--font-scale));
  }

  .metric-value small {
    font-size: calc(1.1rem * var(--font-scale));
  }
}

@media (max-width: 680px) {
  .topbar {
    align-items: stretch;
    flex-direction: column;
    padding: 12px;
  }

  .topnav {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .topnav a,
  .topnav button {
    text-align: center;
    padding: 10px;
  }

  .session-panel {
    padding: 12px;
  }

  .session-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .session-actions input {
    width: 100%;
  }

  .display-panel {
    padding: 12px;
  }

  .panel-head {
    align-items: center;
  }

  .button-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .button-grid button {
    min-height: 42px;
    font-size: 0.86rem;
  }

  .vital-row {
    grid-template-columns: minmax(96px, 28vw) minmax(0, 1fr);
    min-height: clamp(92px, calc((100svh - 286px) / 4), 118px);
    border-radius: 14px;
  }

  .wave-stage {
    margin: 8px 8px 8px 0;
    border-radius: 12px;
  }

  .metric-label {
    font-size: 0.62rem;
  }

  .metric-note {
    font-size: 0.68rem;
  }

  .bp-value {
    gap: 5px;
    font-size: calc(1.75rem * var(--font-scale));
    letter-spacing: -0.08em;
  }

  .etco2-value {
    gap: 7px;
    font-size: calc(2rem * var(--font-scale));
  }

  .etco2-value small {
    font-size: calc(0.92rem * var(--font-scale));
  }

  .ct-line {
    stroke-width: 2.35px;
  }

  .monitor-footer {
    gap: 8px;
    min-height: 58px;
    padding: 8px;
    overflow-x: auto;
  }

  .monitor-footer button,
  .monitor-footer .primary-link {
    white-space: nowrap;
    padding: 10px 12px;
  }

  .control-hero,
  .control-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .control-grid {
    grid-template-columns: 1fr;
  }

  .span-2 {
    grid-column: auto;
  }

  .control-number {
    grid-template-columns: 62px 1fr 62px;
  }

  .preset-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-height: 760px) and (min-width: 1021px) {
  .app-shell {
    width: min(1240px, calc(100vw - 20px));
    padding-top: 8px;
  }

  .topbar {
    min-height: 64px;
    margin-bottom: 10px;
    padding: 10px 16px;
  }

  .vital-row {
    min-height: calc((100svh - 152px) / 4);
  }

  .metric-value {
    font-size: calc(3.6rem * var(--font-scale));
  }

  .monitor-footer {
    min-height: 56px;
  }
}
