*,
*::before,
*::after {
  box-sizing: border-box;
}

/* PWA shell update (browser / home-screen; hidden on TV until a version bumps). */
.sw-update-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 10050;
  width: 100%;
  padding: 0.625rem max(1rem, env(safe-area-inset-right, 0px)) 0.625rem
    max(1rem, env(safe-area-inset-left, 0px));
  padding-top: max(0.625rem, env(safe-area-inset-top, 0px));
  box-sizing: border-box;
  background: rgba(11, 31, 51, 0.96);
  border-bottom: 1px solid rgba(255, 255, 255, 0.14);
  color: #fff;
  font-size: clamp(0.875rem, 2.8vw + 0.45rem, 1rem);
  line-height: 1.35;
}

.sw-update-banner[hidden] {
  display: none !important;
}

.sw-update-banner-inner {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.625rem 1rem;
  text-align: left;
}

.sw-update-banner-text {
  flex: 1 1 auto;
  min-width: 0;
}

.sw-update-banner-reload {
  flex: 0 0 auto;
  margin: 0;
  cursor: pointer;
  padding: 0.45rem 1.1rem;
  min-height: 44px;
  font-family: inherit;
  font-size: 0.9375rem;
  font-weight: 700;
  line-height: 1.2;
  color: #0b1f33;
  background: #38bdf8;
  border: 2px solid #fff;
  border-radius: 8px;
  -webkit-tap-highlight-color: rgba(0, 0, 0, 0.1);
  touch-action: manipulation;
}

.sw-update-banner-reload:focus,
.sw-update-banner-reload:focus-visible {
  outline: 3px solid #fff;
  outline-offset: 3px;
}

html.is-tv-shell .sw-update-banner {
  display: none !important;
}

/*
  Primary brand/decor family — driven by --display-hue (degrees).
  Platform admin sets per screen; display-boot applies it on <html>.
  Default 205 matches the previous hard-coded blue chrome.
*/
:root {
  --display-hue: 205;
  --display-deepest: hsl(var(--display-hue), 60%, 6%);
  --display-deep: hsl(var(--display-hue), 60%, 10%);
  --display-base: hsl(var(--display-hue), 65%, 12%);
  --display-panel: hsl(var(--display-hue), 61%, 16%);
  --display-card: hsl(var(--display-hue), 56%, 20%);
  --display-border: hsl(var(--display-hue), 52%, 25%);
  --display-header-from: hsl(var(--display-hue), 79%, 28%);
  --display-header-to: hsl(var(--display-hue), 80%, 22%);
  --display-accent-mid: hsl(var(--display-hue), 89%, 48%);
  --display-accent: hsl(var(--display-hue), 93%, 60%);
  --display-accent-light: hsl(var(--display-hue), 95%, 74%);
  --display-accent-pale: hsl(var(--display-hue), 95%, 86%);
  --display-veil: hsla(var(--display-hue), 78%, 5%, 0.82);
  --display-diag-bg: hsla(var(--display-hue), 85%, 5%, 0.92);
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: #000;
  color: #f8fafc;
}

/* Must beat .display-setup { display: flex } or [hidden] panels stay visible */
[hidden] {
  display: none !important;
}

.display-setup {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  text-align: center;
  background: #f5f7fa;
  color: #1a1a1a;
  overflow: auto;
}

.display-setup code {
  background: #e8edf3;
  padding: 0.15rem 0.4rem;
  border-radius: 0.25rem;
}

.display-setup .muted {
  color: #64748b;
}

.pair-intro {
  margin: 0.35rem 0 0;
  max-width: 28rem;
  color: #334155;
  line-height: 1.4;
}

.pair-panel {
  margin: 1rem 0 1.5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.85rem;
  max-width: 28rem;
  width: 100%;
}

.pair-code {
  margin: 0.5rem 0 0;
  font-size: clamp(2.75rem, 12vw, 5.5rem);
  font-weight: 800;
  letter-spacing: 0.35em;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
  padding-left: 0.35em;
  color: #0f172a;
}

.pair-status {
  margin: 0;
  font-weight: 600;
  font-size: 1rem;
  min-height: 1.25rem;
}

.pair-status.pair-error {
  color: #b91c1c;
}

.display-preload {
  position: fixed;
  inset: 0;
  z-index: 10000;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  text-align: center;
  background: var(--display-base);
  color: #f8fafc;
}

.display-preload[hidden] {
  display: none !important;
}

.display-preload h1 {
  margin: 0.35rem 0 0;
  font-size: clamp(1.75rem, 4vw, 2.5rem);
  font-weight: 800;
  letter-spacing: -0.02em;
}

.preload-eyebrow {
  margin: 0;
  font-size: 0.85rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--display-accent-light);
}

.preload-file {
  margin: 1.25rem 0 0;
  max-width: min(36rem, 90vw);
  min-height: 1.4em;
  font-size: 1rem;
  font-weight: 600;
  color: #cbd5e1;
  word-break: break-all;
}

.preload-bar {
  margin-top: 1rem;
  width: min(28rem, 80vw);
  height: 0.7rem;
  border-radius: 999px;
  background: var(--display-card);
  overflow: hidden;
}

.preload-bar-fill {
  height: 100%;
  width: 0%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--display-accent-mid), var(--display-accent));
  transition: width 0.2s ease;
}

.preload-pct {
  margin: 0.65rem 0 0;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  color: #e2e8f0;
}

.preload-audio-btn {
  margin-top: 1.25rem;
  appearance: none;
  border: 0;
  border-radius: 0.65rem;
  padding: 0.85rem 1.35rem;
  font: inherit;
  font-weight: 700;
  font-size: 1.05rem;
  color: #0b1f33;
  background: #38bdf8;
  cursor: pointer;
}

.preload-audio-btn[hidden] {
  display: none !important;
}

.preload-audio-btn:focus-visible {
  outline: 3px solid #f8fafc;
  outline-offset: 3px;
}

.pair-wa {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.45rem;
  margin-top: 0.25rem;
}

.pair-wa-qr {
  width: 200px;
  height: 200px;
  max-width: min(200px, 55vw);
  max-height: min(200px, 28vh);
  object-fit: contain;
  background: #fff;
  border: 1px solid #cbd5e1;
  border-radius: 0.5rem;
  padding: 0.45rem;
}

.pair-wa-caption {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
  color: #334155;
  max-width: 18rem;
  line-height: 1.35;
}

.pair-refresh {
  font: inherit;
  font-weight: 600;
  padding: 0.45rem 0.85rem;
  border: 1px solid #cbd5e1;
  border-radius: 0.35rem;
  background: #fff;
  color: var(--display-header-from);
  cursor: pointer;
}

.launch-form {
  margin: 1.25rem 0;
  text-align: left;
  max-width: 22rem;
  width: 100%;
}

.launch-form label {
  display: block;
  font-weight: 600;
  margin-bottom: 0.35rem;
  font-size: 0.9rem;
}

.launch-row {
  display: flex;
  gap: 0.5rem;
}

.launch-row input {
  flex: 1;
  font: inherit;
  padding: 0.55rem 0.65rem;
  border: 1px solid #cbd5e1;
  border-radius: 0.35rem;
}

.launch-row button {
  font: inherit;
  font-weight: 600;
  padding: 0.55rem 0.9rem;
  border: none;
  border-radius: 0.35rem;
  background: var(--display-header-from);
  color: #fff;
  cursor: pointer;
}

.display-stage {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: #000;
  /*
    Size container so the 16:9 root can letterbox against the visible
    fixed shell (Safari toolbars) instead of inflated 100vh.
  */
  container-type: size;
  container-name: stage;
}

.display-root {
  /*
    Stage size: fill the fixed shell by default (Android 9 WebView often
    lacks CSS min()). Newer engines get true 16:9 letterbox below.
  */
  position: relative;
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--display-base);
  container-type: size;
  container-name: display;
  /*
    Stage unit = 1% of stage height.
    Default 7.2px = 720p design (NOT 1vh — old Android WebViews mis-report vh).
    JS sets --su from .display-root clientHeight once laid out (Safari-safe).
  */
  --su: 7.2px;
  /* Type scale relative to --su (1 = original design). */
  --fs: 1;
  font-size: calc(2.2 * var(--su) * var(--fs));
}

/* Letterbox 16:9 inside the fixed stage; cap with % so we never exceed the shell. */
@supports (width: min(1px, 2px)) {
  .display-root {
    width: min(100%, calc(100vh * 16 / 9));
    height: min(100%, calc(100vw * 9 / 16));
  }
}

/* Dynamic viewport units track Safari/Chrome iOS toolbar show/hide. */
@supports (width: min(1px, 2px)) and (height: 100dvh) {
  .display-root {
    width: min(100%, calc(100dvh * 16 / 9));
    height: min(100%, calc(100dvw * 9 / 16));
  }
}

/* Prefer the fixed stage's own size (most accurate on WebKit). */
@supports (width: min(1px, 2px)) and (height: 1cqh) {
  .display-root {
    width: min(100cqw, calc(100cqh * 16 / 9));
    height: min(100cqh, calc(100cqw * 9 / 16));
  }
}

.offline-banner {
  position: absolute;
  inset: 0;
  z-index: 6;
  display: flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  margin: 0;
  padding: 0 calc(1.5 * var(--su));
  border: 0;
  background: #b45309;
  color: #fff;
  text-align: center;
  font-weight: 600;
  font-size: calc(3 * var(--su) * var(--fs));
  line-height: 1.25;
}

.offline-banner[hidden] {
  display: none !important;
}

.display-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: calc(1.5 * var(--su));
  padding: calc(1.1 * var(--su)) calc(1.85 * var(--su)) calc(1 * var(--su));
  background: linear-gradient(180deg, var(--display-header-from) 0%, var(--display-header-to) 100%);
  border-bottom: calc(0.28 * var(--su)) solid var(--display-accent);
}

.display-header-main {
  flex: 1 1 auto;
  min-width: 0;
}

.display-header-meta {
  display: flex;
  flex-direction: row;
  align-items: baseline;
  justify-content: flex-end;
  gap: calc(0.75 * var(--su));
  flex: 0 1 auto;
  min-width: 0;
}

.display-clinic {
  margin: 0;
  font-size: calc(1.4 * var(--su) * var(--fs));
  text-transform: uppercase;
  letter-spacing: 0.06em;
  opacity: 0.85;
}

.display-screen {
  margin: calc(0.22 * var(--su)) 0 0;
  font-size: calc(3 * var(--su) * var(--fs));
  font-weight: 700;
}

.display-clock {
  margin: 0;
  font-size: calc(3 * var(--su) * var(--fs));
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  opacity: 0.9;
  white-space: nowrap;
}

.boot-status {
  margin: 0;
  font-size: calc(1 * var(--su) * var(--fs));
  line-height: 1.2;
  color: #fde68a;
  opacity: 0.8;
  white-space: nowrap;
  max-width: 14em;
  overflow: hidden;
  text-overflow: ellipsis;
}

.boot-status:empty {
  display: none;
}

.display-body {
  flex: 1;
  display: flex;
  min-height: 0;
}

.health-panel {
  position: relative;
  z-index: 1;
  flex: 0 0 70%;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  padding: 0;
  background: var(--display-panel);
  border-right: calc(0.2 * var(--su)) solid var(--display-border);
  overflow: hidden;
  isolation: isolate;
}

.health-panel-main {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 0 calc(1.5 * var(--su)) calc(0.75 * var(--su));
}

/* Layout composer: inactive zones stay out of flow without fighting flash/hidden. */
[data-zone].zone-off {
  display: none !important;
}

.ad-panel {
  position: relative;
  z-index: 2;
  isolation: isolate;
  flex: 0 0 30%;
  display: flex;
  flex-direction: column;
  /* Keep ad column from collapsing when native overlay has no HTML media child. */
  min-width: max(9rem, 22%);
  min-height: 0;
  align-self: stretch;
  background: var(--display-deep);
}

/* On-device ad/media diagnostics (TV settings or ?diag=1). */
.ad-diag {
  position: fixed;
  z-index: 90;
  left: calc(0.8 * var(--su, 8px));
  bottom: calc(0.8 * var(--su, 8px));
  width: min(52vw, 520px);
  max-height: min(46vh, 420px);
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 8px 10px;
  box-sizing: border-box;
  background: var(--display-diag-bg);
  border: 1px solid hsla(var(--display-hue), 93%, 60%, 0.45);
  color: #e2e8f0;
  font-family: ui-monospace, Consolas, monospace;
  font-size: 11px;
  line-height: 1.35;
  pointer-events: none;
}

.ad-diag[hidden] {
  display: none !important;
}

.ad-diag-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  color: var(--display-accent);
}

.ad-diag-hint {
  color: #94a3b8;
  font-size: 10px;
}

.ad-diag-summary {
  color: #fbbf24;
  word-break: break-word;
}

.ad-diag-log {
  margin: 0;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  white-space: pre-wrap;
  word-break: break-word;
  color: #cbd5e1;
}

.ad-stage {
  /* Shrink-wrap padding + 9:16 media; leftover column height goes to .ad-label. */
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  width: 100%;
  box-sizing: border-box;
  padding: calc(1.1 * var(--su));
  overflow: hidden;
  position: relative;
  /* Hold 9:16 box even when ExoPlayer removes <video> / leaves only a slot. */
  min-width: 0;
  min-height: calc(var(--ad-media-h, 16rem) + 2.2 * var(--su));
}

/*
 * Visible media viewport is 9:16. --ad-media-w/h are set by JS to whole device
 * pixels (sharper WebView rescale). Fallback is fluid 9:16 before snap runs.
 */
.ad-stage > img,
.ad-stage > video,
.ad-stage > .ad-html,
.ad-stage > .ad-placeholder,
.ad-stage > .ad-native-slot {
  display: block;
  flex: 0 0 auto;
  width: var(--ad-media-w, 100%);
  height: var(--ad-media-h, auto);
  min-width: var(--ad-media-w, 9rem);
  min-height: var(--ad-media-h, 16rem);
  max-width: 100%;
  aspect-ratio: 9 / 16;
  box-sizing: border-box;
  border-radius: calc(0.5 * var(--su));
}

/* Cover crops; never stretch/squash intrinsic image or video pixels. */
.ad-stage > img,
.ad-stage > video {
  object-fit: cover;
  object-position: center;
}

/* Invisible layout holder while ExoPlayer paints the overlay. */
.ad-stage > .ad-native-slot {
  background: var(--display-deep);
  pointer-events: none;
  visibility: hidden;
}

/* Warmup still sizes the stage; keep the native slot out of flex flow. */
.ad-stage > img.ad-warmup-still + .ad-native-slot {
  position: absolute;
  left: 50%;
  top: calc(1.1 * var(--su));
  transform: translateX(-50%);
  margin: 0;
  visibility: hidden;
}

/* Lobby ads: no browser chrome (big play, cast/PiP, scrubbers). */
.ad-stage video {
  background: var(--display-deep);
  pointer-events: none;
}

.ad-stage video.ad-video-pending {
  opacity: 0;
}

.ad-stage video::-webkit-media-controls,
.ad-stage video::-webkit-media-controls-enclosure,
.ad-stage video::-webkit-media-controls-panel,
.ad-stage video::-webkit-media-controls-overlay-enclosure,
.ad-stage video::-webkit-media-controls-overlay-play-button,
.ad-stage video::-webkit-media-controls-start-playback-button,
.ad-stage video::-webkit-media-controls-play-button {
  display: none !important;
  -webkit-appearance: none !important;
  opacity: 0 !important;
  width: 0 !important;
  height: 0 !important;
  pointer-events: none !important;
}

.ad-stage > .ad-html {
  overflow: auto;
  font-size: calc(1.5 * var(--su) * var(--fs));
}

.ad-placeholder {
  margin: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: calc(1.5 * var(--su));
  color: #64748b;
}

/*
  Campaign timeline between stage and label.
  .ad-progress-on uses !important so it wins over [hidden]{display:none!important}
  on stubborn WebViews. JS also applies inline fallbacks (stale CSS cache).
*/
.ad-progress {
  display: none;
  flex: 0 0 auto;
  flex-grow: 0;
  flex-shrink: 0;
  width: 100%;
  height: 3px;
  height: calc(0.4 * var(--su));
  min-height: 3px;
  background: var(--display-deepest);
  position: relative;
  z-index: 1;
  box-sizing: border-box;
}

.ad-progress.ad-progress-on {
  display: block !important;
  visibility: visible !important;
  opacity: 1 !important;
}

.ad-progress-track {
  position: relative;
  height: 100%;
  width: 100%;
  overflow: hidden;
  background: hsl(var(--display-hue), 40%, 14%);
}

.ad-progress-fill {
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  width: 0%;
  background: var(--display-accent);
  background: linear-gradient(
    90deg,
    var(--display-accent-mid),
    var(--display-accent)
  );
  z-index: 1;
  pointer-events: none;
}

.ad-progress-segments {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  display: flex;
  z-index: 2;
  pointer-events: none;
}

.ad-progress-seg {
  min-width: 0;
  box-sizing: border-box;
  border-right: 1px solid rgba(255, 255, 255, 0.4);
}

.ad-progress-seg:last-child {
  border-right: none;
}

.ad-label {
  flex: 1 1 auto;
  margin: 0;
  padding: calc(1.25 * var(--su));
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  background: var(--display-deepest);
  min-height: calc(2.2 * var(--su));
  min-width: 0;
  box-sizing: border-box;
}

.ad-label-stack {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: calc(0.55 * var(--su));
  width: 100%;
  max-width: 100%;
  min-width: 0;
}

.ad-sponsor-tag {
  margin: 0;
  flex: 0 0 auto;
  font-size: calc(1.05 * var(--su) * var(--fs));
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #64748b;
}

.ad-sponsor-message {
  margin: 0;
  flex: 0 0 auto;
  display: block;
  width: 100%;
  max-width: 100%;
  font-size: calc(2.05 * var(--su) * var(--fs));
  font-weight: 650;
  line-height: 1.2;
  letter-spacing: 0.01em;
  color: #e2e8f0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: center;
}

.ad-sponsor-message[hidden] {
  display: none;
}

.health-panel h2 {
  margin: 0 0 calc(0.6 * var(--su));
  font-size: calc(1.55 * var(--su) * var(--fs) * 1.5);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #94a3b8;
}

/* Dark full-bleed bars that separate Now serving / Waiting / Doctors */
.display-stage *:focus,
.display-stage *:focus-visible,
html.is-tv-shell *:focus,
html.is-tv-shell *:focus-visible {
  outline: none !important;
  box-shadow: none !important;
  -webkit-tap-highlight-color: transparent;
}

.panel-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: calc(1 * var(--su));
  flex: 0 0 auto;
  box-sizing: border-box;
  margin: 0 calc(-1.5 * var(--su)) calc(0.85 * var(--su));
  padding: calc(0.55 * var(--su)) calc(1.5 * var(--su));
  background: var(--display-deep);
  border-top: 1px solid var(--display-border);
  border-bottom: 1px solid var(--display-border);
}

.panel-section-head h2 {
  margin: 0;
  font-size: calc(1.55 * var(--su) * var(--fs) * 1.5);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #94a3b8;
}

.health-panel .panel-section-head h2 {
  margin: 0;
}

.now-serving {
  flex: 0 0 auto;
  margin-bottom: calc(0.35 * var(--su));
  min-width: 0;
}

.now-serving-body {
  display: flex;
  flex-direction: row;
  align-items: stretch;
  gap: calc(0.75 * var(--su));
  min-width: 0;
}

.now-serving-body .panel-viewport {
  flex: 1 1 auto;
  min-width: 0;
}

.now-serving-list,
.serving-strip,
.serving-page {
  display: grid;
  gap: calc(0.65 * var(--su));
}

.serving-page {
  grid-template-columns: 1fr 1fr 1fr;
  align-content: start;
  align-items: stretch;
  width: 100%;
  box-sizing: border-box;
}

.serving-page .empty-hint {
  grid-column: 1 / -1;
}

.serving-strip-col {
  display: flex;
  flex-direction: column;
  flex-wrap: nowrap;
  align-items: stretch;
  gap: calc(0.65 * var(--su));
  width: 100%;
}

.serving-strip-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: calc(0.65 * var(--su));
  align-items: stretch;
  width: 100%;
  box-sizing: border-box;
}

.serving-strip-col > .empty-hint {
  margin: 0;
}

.serving-card {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: calc(0.7 * var(--su)) calc(1.25 * var(--su));
  align-items: center;
  box-sizing: border-box;
  min-width: 0;
  padding: calc(1 * var(--su)) calc(1.25 * var(--su));
  background: var(--display-card);
  border-radius: calc(0.75 * var(--su));
  border-left: calc(0.45 * var(--su)) solid #fbbf24;
}

.serving-card.recalled {
  animation: flash-recall 1s ease-in-out infinite;
  border-left-color: #f97316;
}

.serving-card--empty {
  pointer-events: none;
}

.serving-card--empty .serving-token,
.serving-card--empty .serving-room,
.serving-card--empty .serving-patient,
.serving-card--empty .serving-doctor,
.serving-card--empty .serving-specialty {
  visibility: hidden;
}

@keyframes flash-recall {
  0%,
  100% {
    background: var(--display-card);
  }
  50% {
    background: #7c2d12;
  }
}

.serving-id {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: calc(0.3 * var(--su));
  min-width: 0;
}

.serving-token {
  font-size: calc(5.9 * var(--su) * var(--fs));
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  color: #fde68a;
}

.serving-room {
  font-size: calc(2.4 * var(--su) * var(--fs));
  font-weight: 700;
  line-height: 1.15;
  color: var(--display-accent-light);
}

.serving-meta {
  min-width: 0;
  font-size: calc(2.1 * var(--su) * var(--fs));
  text-align: right;
}

.serving-meta .serving-patient,
.serving-meta strong.serving-patient {
  display: block;
  font-size: calc(2.3 * var(--su) * var(--fs));
  font-weight: 700;
  line-height: 1.15;
  margin-bottom: calc(0.25 * var(--su));
}

.serving-doctor {
  font-weight: 600;
  line-height: 1.2;
  color: #e2e8f0;
}

.serving-card .serving-doctor.roster-marquee {
  display: block;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  /* Match patient + specialty; switch to left only while marqueing */
  text-align: right;
}

.serving-card .serving-doctor.roster-marquee.is-overflow {
  text-align: left;
}

.serving-specialty {
  margin-top: calc(0.15 * var(--su));
  font-size: calc(2.1 * var(--su) * var(--fs));
  line-height: 1.2;
  color: #94a3b8;
}

.queue-section {
  --qscale: 1.25;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  margin-bottom: calc(0.35 * var(--su));
}

.panel-viewport {
  position: relative;
  overflow: hidden;
  min-width: 0;
  min-height: 0;
}

.queue-section .panel-viewport {
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}

.roster-section .panel-viewport {
  flex: 0 0 auto;
  /* Height follows roster card content */
  height: auto;
  overflow: hidden;
}

.panel-track {
  will-change: transform;
  transition: transform 0.65s cubic-bezier(0.22, 0.61, 0.36, 1);
}

.panel-track[data-axis="x"] {
  display: flex;
  flex-direction: row;
  align-items: stretch;
}

/* Continuous roster strip: one row of all cards; track shifts by one card */
.panel-track.is-strip {
  display: block;
  width: max-content;
  max-width: none;
}

.panel-track.is-strip-y {
  width: 100%;
  height: max-content;
}

.panel-track.is-strip-y .serving-strip-col {
  width: 100%;
}

.panel-track.is-strip .roster-grid-row {
  width: max-content;
  max-width: none;
}

.panel-track.is-jumping {
  transition: none;
}

.queue-list {
  list-style: none;
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  overflow: hidden;
  /* Legacy multi-column page layout (non-strip fallback) */
  columns: 2;
  column-fill: auto;
  column-gap: calc(1.1 * var(--su) * var(--qscale));
  column-rule: 1px solid var(--display-border);
}

/* Continuous waiting strip: columns in a row; track shifts by one column */
.queue-strip-row {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  align-items: stretch;
  gap: calc(1.1 * var(--su) * var(--qscale));
  width: max-content;
  max-width: none;
  overflow: hidden;
  box-sizing: border-box;
}

.panel-track.is-strip .queue-strip-row {
  height: 100%;
}

.queue-section .panel-track.is-strip {
  height: 100%;
}

.queue-column {
  list-style: none;
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  overflow: hidden;
  height: 100%;
}

.queue-column + .queue-column {
  border-left: 1px solid var(--display-border);
}

/* Pager pages fill the viewport; non-paged fallback kept for older markup */
.queue-section > .queue-list {
  flex: 1;
  min-height: 0;
  height: 100%;
}

.queue-list li,
.queue-column li {
  display: grid;
  grid-template-columns: calc(8.2 * var(--su) * var(--qscale)) 1fr auto;
  gap: calc(1.1 * var(--su) * var(--qscale));
  padding: calc(0.6 * var(--su) * var(--qscale)) calc(0.75 * var(--su) * var(--qscale));
  border-bottom: 1px solid var(--display-border);
  font-size: calc(1.9 * var(--su) * var(--fs) * var(--qscale));
  break-inside: avoid;
  page-break-inside: avoid;
}

.queue-list .token-num,
.queue-column .token-num {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--display-accent-pale);
}

.queue-list .held,
.queue-column .held {
  opacity: 0.65;
  font-style: italic;
}

/* By specialty — pages of 4×2 cards; height locked to waiting viewport */
.specialty-strip {
  align-items: stretch;
  height: 100%;
}

.specialty-page {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  grid-template-rows: repeat(2, minmax(0, 1fr));
  gap: calc(0.75 * var(--su) * var(--qscale));
  box-sizing: border-box;
  min-width: 0;
  min-height: 0;
  height: 100%;
  overflow: hidden;
}

.specialty-page--empty {
  display: flex;
  align-items: center;
  justify-content: center;
  grid-template-columns: none;
  grid-template-rows: none;
}

.specialty-page--empty .empty-hint {
  margin: 0;
  font-size: calc(1.9 * var(--su) * var(--fs) * var(--qscale));
  color: #94a3b8;
}

.specialty-card {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  gap: calc(0.35 * var(--su) * var(--qscale));
  box-sizing: border-box;
  min-width: 0;
  min-height: 0;
  height: 100%;
  overflow: hidden;
  padding: calc(0.85 * var(--su) * var(--qscale)) calc(1 * var(--su) * var(--qscale));
  background: var(--display-card);
  border-radius: calc(0.75 * var(--su));
  border-left: calc(0.4 * var(--su)) solid var(--display-accent-pale, #38bdf8);
}

.specialty-card--empty {
  pointer-events: none;
  /* Empty slots stay visible so the 4×2 grid never collapses. */
  opacity: 0.45;
  border-left-color: rgba(148, 163, 184, 0.35);
}

.specialty-name {
  margin: 0;
  font-size: calc(2 * var(--su) * var(--fs) * var(--qscale));
  font-weight: 650;
  line-height: 1.3;
  letter-spacing: 0.02em;
  color: #e2e8f0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.specialty-count-line {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: calc(0.25 * var(--su) * var(--qscale)) calc(0.65 * var(--su) * var(--qscale));
  margin: 0;
  min-width: 0;
}

.specialty-count {
  margin: 0;
  font-size: calc(1.5 * var(--su) * var(--fs) * var(--qscale));
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--display-accent-pale, #38bdf8);
}

.specialty-held,
.specialty-more {
  margin: 0;
  font-size: calc(1.25 * var(--su) * var(--fs) * var(--qscale));
  line-height: 1.15;
  color: #94a3b8;
}

.specialty-footer {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: calc(0.35 * var(--su) * var(--qscale)) calc(0.75 * var(--su) * var(--qscale));
  margin: calc(0.1 * var(--su) * var(--qscale)) 0 0;
  min-width: 0;
}

.specialty-held {
  font-style: italic;
  opacity: 0.9;
}

.specialty-doctors {
  margin: calc(0.15 * var(--su) * var(--qscale)) 0 0;
  font-size: calc(1.25 * var(--su) * var(--fs) * var(--qscale));
  line-height: 1.15;
  font-weight: 550;
  font-variant-numeric: tabular-nums;
  color: #94a3b8;
}

.specialty-doctors--none {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  margin: calc(0.25 * var(--su) * var(--qscale)) 0 0;
  height: calc(1.7 * var(--su) * var(--fs) * var(--qscale));
  padding: 0 calc(0.6 * var(--su) * var(--qscale));
  border-radius: calc(0.35 * var(--su));
  line-height: 1;
  font-weight: 700;
  color: #fff;
  background: #dc2626;
  vertical-align: middle;
  overflow: hidden;
  animation: specialty-nodocs-blink 1s steps(1, end) infinite;
}

.specialty-doctors--none .specialty-doctors-label {
  display: block;
  line-height: 1;
  -webkit-font-smoothing: antialiased;
}

/* Android TV WebView bold metrics sit optically high — nudge only in the APK shell. */
html.is-tv-shell .specialty-doctors--none .specialty-doctors-label {
  transform: translateY(0.08em);
}

@keyframes specialty-nodocs-blink {
  0%,
  49% {
    opacity: 1;
    visibility: visible;
  }
  50%,
  100% {
    opacity: 0;
    visibility: hidden;
  }
}

.specialty-tokens {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: calc(0.4 * var(--su) * var(--qscale)) calc(0.7 * var(--su) * var(--qscale));
  margin: calc(0.15 * var(--su) * var(--qscale)) 0 0;
  min-width: 0;
}

.specialty-tokens .token-num {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  font-size: calc(1.85 * var(--su) * var(--fs) * var(--qscale));
  line-height: 1.1;
  color: var(--display-accent-pale, #38bdf8);
}

.specialty-tokens .token-num--range {
  font-size: calc(2.1 * var(--su) * var(--fs) * var(--qscale));
  letter-spacing: 0.02em;
}

.specialty-card .specialty-count-line {
  justify-content: center;
}

.specialty-card .specialty-tokens {
  justify-content: center;
}

.roster-section {
  --rscale: 1.5;
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.panel-scroll-meter {
  position: relative;
  flex: 0 0 auto;
  width: calc(18 * var(--su) * var(--rscale, 1.5));
  max-width: 56%;
  height: calc(0.55 * var(--su) * var(--rscale, 1.5));
  min-height: 4px;
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.28);
  overflow: hidden;
  opacity: 0.85;
}

.panel-scroll-meter-y {
  width: calc(0.55 * var(--su) * var(--rscale, 1.5));
  min-width: 4px;
  max-width: none;
  height: auto;
  align-self: stretch;
  min-height: calc(4 * var(--su));
}

.panel-scroll-meter-y .panel-scroll-meter-thumb {
  width: 100%;
  height: 40%;
  left: 0;
  top: 0;
}

.panel-scroll-meter[hidden] {
  display: none !important;
}

.panel-scroll-meter-thumb {
  position: absolute;
  left: 0;
  top: 0;
  height: 100%;
  width: 40%;
  border-radius: inherit;
  background: hsla(var(--display-hue), 95%, 74%, 0.85);
  transform: none;
  transition: left 0.65s cubic-bezier(0.22, 0.61, 0.36, 1),
    top 0.65s cubic-bezier(0.22, 0.61, 0.36, 1), width 0.2s ease, height 0.2s ease;
  will-change: left, top, width, height;
}

.panel-scroll-meter-thumb.is-jumping {
  transition: none;
}

.roster-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(calc(14.8 * var(--su) * var(--rscale)), 1fr));
  gap: calc(0.6 * var(--su) * var(--rscale));
  overflow: hidden;
  min-width: 0;
  box-sizing: border-box;
  align-content: start;
}

/* Pager + live: keep doctors on a single horizontal row */
.roster-grid-row {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  align-items: stretch;
  gap: calc(0.6 * var(--su) * var(--rscale));
  overflow: hidden;
  height: auto;
}

.roster-grid-row .roster-card {
  flex: 1 1 0;
  min-width: 0;
  height: auto;
  align-self: stretch;
}

.roster-card {
  padding: calc(0.75 * var(--su) * var(--rscale)) calc(0.9 * var(--su) * var(--rscale));
  background: var(--display-card);
  border-radius: calc(0.5 * var(--su) * var(--rscale));
  font-size: calc(1.55 * var(--su) * var(--fs) * var(--rscale));
  box-sizing: border-box;
  min-width: 0;
  overflow: hidden;
  text-align: center;
}

.roster-card .roster-marquee,
.serving-card .roster-marquee {
  display: block;
  width: 100%;
  max-width: 100%;
  overflow: hidden;
  white-space: nowrap;
  line-height: 1.25;
}

.roster-card .doc-name {
  font-weight: 700;
  margin-bottom: calc(0.22 * var(--su) * var(--rscale));
}

.roster-card .doc-specialty {
  margin-bottom: 0;
}

.roster-room {
  margin-top: calc(0.15 * var(--su) * var(--rscale));
  font-size: 0.8em;
}

.roster-marquee-inner {
  display: inline-block;
  white-space: nowrap;
  will-change: transform;
  transform: translateX(0);
}

.roster-marquee.is-overflow .roster-marquee-inner {
  animation: roster-marquee-pingpong var(--marquee-duration, 4s) ease-in-out infinite alternate;
}

@keyframes roster-marquee-pingpong {
  0%,
  12% {
    transform: translateX(0);
  }
  88%,
  100% {
    transform: translateX(var(--marquee-shift, 0));
  }
}

.roster-status {
  display: inline-block;
  margin-top: calc(0.3 * var(--su) * var(--rscale));
  padding: calc(0.18 * var(--su) * var(--rscale)) calc(0.65 * var(--su) * var(--rscale));
  border-radius: 999px;
  font-size: calc(1.15 * var(--su) * var(--fs) * var(--rscale));
  font-weight: 700;
  text-transform: uppercase;
}

.roster-status.available {
  background: #064e3b;
  color: #6ee7b7;
}

.roster-status.in_consultation {
  background: #78350f;
  color: #fcd34d;
}

.roster-status.on_break {
  background: #374151;
  color: #d1d5db;
}

.roster-status.out_of_office {
  background: #450a0a;
  color: #fca5a5;
}

.ticker-bar {
  position: relative;
  flex: 0 0 auto;
  background: var(--display-deepest);
  border-top: calc(0.2 * var(--su)) solid var(--display-border);
  overflow: hidden;
  padding: calc(1.3 * var(--su)) 0;
}

.ticker-track {
  display: inline-block;
  white-space: nowrap;
  padding-left: 100%;
  animation: ticker-scroll 40s linear infinite;
  font-size: calc(3.4 * var(--su) * var(--fs));
  color: #e2e8f0;
}

.ticker-track.paused {
  animation: none;
  padding-left: calc(1.5 * var(--su));
}

@keyframes ticker-scroll {
  0% {
    transform: translateX(0);
  }
  100% {
    transform: translateX(-100%);
  }
}

.empty-hint {
  color: #64748b;
  font-size: calc(1.5 * var(--su) * var(--fs));
  margin: calc(0.35 * var(--su)) 0;
}

/* Call flash — clipped to .health-panel only; never covers .ad-panel */
.health-panel > .announce-flash {
  position: absolute;
  inset: 0;
  z-index: 80;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(2 * var(--su));
  background: var(--display-veil);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.health-panel > .announce-flash[hidden] {
  display: none !important;
}

.health-panel > .announce-flash.is-visible {
  opacity: 1;
  pointer-events: auto;
}

.announce-flash-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: calc(1.1 * var(--su));
  width: min(92%, calc(52 * var(--su)));
  padding: calc(3.2 * var(--su)) calc(4 * var(--su));
  text-align: center;
  background: var(--display-panel);
  border: calc(0.35 * var(--su)) solid var(--display-accent);
  border-radius: calc(1.4 * var(--su));
  box-shadow: 0 calc(1.2 * var(--su)) calc(3.5 * var(--su)) rgba(0, 0, 0, 0.45);
}

.announce-flash-label {
  margin: 0;
  font-size: calc(2.4 * var(--su) * var(--fs));
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #94a3b8;
}

.announce-flash-token {
  margin: 0;
  font-size: calc(14 * var(--su) * var(--fs));
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  line-height: 0.95;
  color: #fde68a;
  letter-spacing: 0.04em;
}

.announce-flash-patient {
  margin: 0;
  font-size: calc(3.6 * var(--su) * var(--fs));
  font-weight: 650;
  line-height: 1.15;
  color: #e2e8f0;
}

.announce-flash-room {
  margin: calc(0.6 * var(--su)) 0 0;
  font-size: calc(8 * var(--su) * var(--fs));
  font-weight: 800;
  line-height: 1.1;
  color: var(--display-accent-light);
}

.announce-flash-doctor {
  margin: 0;
  font-size: calc(3.2 * var(--su) * var(--fs));
  font-weight: 650;
  line-height: 1.15;
  color: #cbd5e1;
}

.announce-flash-doctor[hidden],
.announce-flash-patient[hidden] {
  display: none !important;
}

/* ── Reception layout: same roster + specialty strips as waiting, doctors on top ── */

.layout-reception .health-panel-main {
  display: flex;
  flex-direction: column;
}

.layout-reception .roster-section {
  order: 1;
  /* One row of doctor cards only — pager + meter for the rest */
  flex: 0 0 auto;
  min-height: 0;
  margin-bottom: calc(0.35 * var(--su));
}

.layout-reception .roster-section .panel-viewport {
  flex: 0 0 auto;
  min-height: 0;
  height: auto;
  overflow: hidden;
}

.layout-reception .roster-section .panel-track.is-strip .roster-grid-row {
  flex-wrap: nowrap;
  height: auto;
}

.layout-reception .queue-section {
  order: 2;
  flex: 1 1 0;
  min-height: 0;
  /* ~8% larger type than lobby waiting cards */
  --qscale: 1.35;
}

.layout-reception .counts-section {
  order: 3;
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  margin-bottom: calc(0.35 * var(--su));
  --rscale: 1.5;
}

.counts-grid {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  align-items: stretch;
  gap: calc(0.6 * var(--su) * var(--rscale, 1.5));
}

.count-card {
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: calc(0.35 * var(--su) * var(--rscale, 1.5));
  padding: calc(0.75 * var(--su) * var(--rscale, 1.5)) calc(0.9 * var(--su) * var(--rscale, 1.5));
  border-radius: calc(0.5 * var(--su) * var(--rscale, 1.5));
  background: var(--display-card);
  border: none;
  text-align: center;
  min-width: 0;
  box-sizing: border-box;
}

.count-card-value {
  margin: 0;
  font-size: calc(3.6 * var(--su) * var(--fs, 1) * var(--rscale, 1.5));
  font-weight: 800;
  line-height: 1;
  color: #f8fafc;
  font-variant-numeric: tabular-nums;
}

.count-card-label {
  margin: 0;
  font-size: calc(1.55 * var(--su) * var(--fs, 1) * var(--rscale, 1.5));
  font-weight: 650;
  color: #94a3b8;
  line-height: 1.2;
}

.count-card--requests .count-card-value {
  color: #fb923c;
}

.count-card--booked .count-card-value {
  color: #fbbf24;
}

.count-card--waiting .count-card-value {
  color: #38bdf8;
}

.count-card--called .count-card-value {
  color: #4ade80;
}

.count-card--held .count-card-value {
  color: #fb7185;
}

@media (max-width: 768px) {
  .display-body {
    flex-direction: column;
  }

  .health-panel,
  .ad-panel {
    flex: 1 1 auto;
  }

  .ad-panel {
    min-height: 25vh;
    min-height: 25dvh;
  }

  .counts-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  /* Narrow/stacked: fit 9:16 inside remaining panel; label still eats leftover. */
  .ad-stage {
    flex: 1 1 auto;
    min-height: calc(var(--ad-media-h, 16rem) + 2.2 * var(--su));
    display: flex;
    justify-content: center;
    align-items: center;
  }

  .ad-stage > img,
  .ad-stage > video,
  .ad-stage > .ad-html,
  .ad-stage > .ad-placeholder,
  .ad-stage > .ad-native-slot {
    width: var(--ad-media-w, auto);
    height: var(--ad-media-h, auto);
    min-width: var(--ad-media-w, 9rem);
    min-height: var(--ad-media-h, 16rem);
    max-width: 100%;
    max-height: 100%;
    aspect-ratio: 9 / 16;
  }

  .announce-flash-token {
    font-size: calc(10 * var(--su) * var(--fs));
  }

  .announce-flash-patient {
    font-size: calc(2.8 * var(--su) * var(--fs));
  }

  .announce-flash-room {
    font-size: calc(5.5 * var(--su) * var(--fs));
  }

  .announce-flash-doctor {
    font-size: calc(2.5 * var(--su) * var(--fs));
  }
}
