/* The page chrome: top bar, KPI strip, queue rail, stage overlays, timeline, analysis drawer and
   what-if, tab bar, hover tip and toasts, with their responsive rules. The patient card and the room
   panel live in panels.css; tracking, targets, heat, the analysis tabs and presentation in
   insights.css. */

/* ---------- Top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  min-height: var(--topbar-h);
  padding: var(--sp-2) var(--sp-3) var(--sp-2) var(--sp-4);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: none;
  padding-right: var(--sp-4);
  border-right: 1px solid var(--line);
}

.brand__mark {
  width: 42px;
  height: 21px;
}

.brand__loop,
.brand__bar {
  fill: none;
  stroke-width: 4.6;
  stroke-linecap: round;
}

.brand__loop--sky,
.brand__bar--sky {
  stroke: var(--sky);
}

.brand__loop--signal,
.brand__bar--signal {
  stroke: var(--signal);
}

.brand__text {
  display: flex;
  align-items: baseline;
  gap: 7px;
  white-space: nowrap;
}

.brand__name {
  font-size: var(--fs-16);
  font-weight: 700;
  letter-spacing: 0.01em;
}

.brand__product {
  font-size: var(--fs-16);
  font-weight: 500;
  color: var(--sky-strong);
}

.topbar__source {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  min-width: 0;
}

.topbar__tools {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  margin-left: auto;
}

/* Date picker */
.date-picker {
  position: relative;
}

.date-picker__button {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  height: 36px;
  padding: 0 var(--sp-2) 0 var(--sp-3);
  border-radius: var(--r-sm);
  border: 1px solid var(--line);
  background: rgba(17, 42, 64, 0.7);
  font-size: var(--fs-13);
  font-weight: 500;
  white-space: nowrap;
  transition: border-color var(--dur-fast) var(--ease-out);
}

.date-picker__button:hover,
.date-picker__button[aria-expanded="true"] {
  border-color: var(--line-strong);
  background: var(--ink-700);
}

.date-picker__count {
  padding: 1px 7px;
  border-radius: var(--r-pill);
  background: rgba(255, 255, 255, 0.07);
  color: var(--text-2);
  font-size: var(--fs-12);
  font-variant-numeric: tabular-nums;
}

.date-picker__count:empty {
  display: none;
}

.icon--chevron {
  width: 16px;
  height: 16px;
  color: var(--text-3);
}

.date-picker__popover {
  position: absolute;
  z-index: 45;
  top: calc(100% + 6px);
  left: 0;
  width: 320px;
  max-height: min(420px, 70vh);
  overflow-y: auto;
  padding: 6px;
  border-radius: var(--r-md);
  background: var(--glass-strong);
  -webkit-backdrop-filter: var(--glass-blur);
  backdrop-filter: var(--glass-blur);
  border: 1px solid var(--line-strong);
  box-shadow: var(--shadow-float);
  scrollbar-width: thin;
}

.date-option {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr) auto;
  grid-template-rows: auto auto;
  column-gap: var(--sp-2);
  row-gap: 4px;
  align-items: center;
  padding: 8px 10px;
  border-radius: var(--r-sm);
  cursor: pointer;
}

.date-option:hover,
.date-option[data-active="true"] {
  background: rgba(255, 255, 255, 0.06);
}

.date-option[aria-selected="true"] {
  background: var(--sky-wash);
}

.date-option__check {
  grid-row: 1 / span 2;
  width: 16px;
  height: 16px;
  color: var(--sky-strong);
  stroke-width: 2.4;
  visibility: hidden;
}

.date-option[aria-selected="true"] .date-option__check {
  visibility: visible;
}

.date-option__date {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  font-size: var(--fs-13);
  font-weight: 500;
}

.date-option__count {
  color: var(--text-2);
  font-size: var(--fs-12);
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.date-option__bar {
  grid-column: 2 / span 2;
  height: 3px;
  border-radius: 2px;
  background: rgba(150, 196, 226, 0.1);
  overflow: hidden;
}

.date-option__bar > span {
  display: block;
  height: 100%;
  width: calc(var(--fill, 0) * 100%);
  border-radius: 2px;
  background: var(--sky);
}

.date-option[data-busiest="true"] .date-option__bar > span {
  background: var(--state-waiting);
}

.date-option[data-empty="true"] .date-option__date {
  color: var(--text-3);
}

.date-picker__empty {
  padding: var(--sp-4);
  color: var(--text-3);
  text-align: center;
}

/* Live button */
.live-button {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 36px;
  padding: 0 var(--sp-3);
  border-radius: var(--r-pill);
  border: 1px solid rgba(240, 75, 68, 0.5);
  color: #ffc1bd;
  font-size: var(--fs-13);
  font-weight: 600;
  white-space: nowrap;
  transition:
    background-color var(--dur-fast) var(--ease-out),
    color var(--dur-fast) var(--ease-out);
}

.live-button:hover {
  background: var(--signal-wash);
}

.live-button__dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--signal);
}

.live-button[aria-pressed="true"] {
  background: var(--signal);
  border-color: var(--signal);
  color: #fff;
}

.live-button[aria-pressed="true"] .live-button__dot {
  background: #fff;
  animation: pulse 1.6s var(--ease-in-out) infinite;
}

@keyframes pulse {
  50% {
    opacity: 0.35;
  }
}

/* Search */
.search {
  position: relative;
  display: flex;
  align-items: center;
}

.search__icon {
  position: absolute;
  left: 10px;
  width: 16px;
  height: 16px;
  color: var(--text-3);
  pointer-events: none;
}

.search__input {
  width: 124px;
  height: 36px;
  padding: 0 var(--sp-3) 0 32px;
  border-radius: var(--r-sm);
  border: 1px solid var(--line);
  background: rgba(4, 14, 24, 0.55);
  font-size: var(--fs-13);
  font-variant-numeric: tabular-nums;
  transition:
    border-color var(--dur-fast) var(--ease-out),
    width var(--dur-mid) var(--ease-out);
}

.search__input::placeholder {
  color: var(--text-3);
}

.search__input:focus {
  width: 148px;
  border-color: var(--sky-line);
}

.search__input::-webkit-search-cancel-button {
  filter: invert(0.7);
}

.search__message {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 45;
  padding: 4px 10px;
  border-radius: var(--r-sm);
  background: var(--glass-strong);
  border: 1px solid rgba(240, 75, 68, 0.45);
  color: #ffc1bd;
  font-size: var(--fs-12);
  white-space: nowrap;
}

.search__message:empty {
  display: none;
}

/* ---------- KPI strip ---------- */
.kpis {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  padding: var(--sp-3) 0;
}

.kpi {
  display: grid;
  grid-template-rows: auto auto auto;
  align-content: start;
  min-width: 0;
  padding: 0 var(--sp-5);
  border-left: 1px solid var(--line);
}

.kpi:first-child {
  border-left: 0;
}

.kpi__label {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--text-2);
  font-size: var(--fs-13);
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.kpi__label::before {
  content: "";
  flex: none;
  width: 3px;
  height: 12px;
  border-radius: 2px;
  background: var(--kpi-accent, var(--line-strong));
}

.kpi[data-kpi="inHospital"] {
  --kpi-accent: var(--sky);
}

.kpi[data-kpi="waiting"],
.kpi[data-kpi="avgWait"] {
  --kpi-accent: var(--state-waiting);
}

.kpi[data-kpi="busiest"] {
  --kpi-accent: var(--signal);
}

.kpi[data-kpi="left"] {
  --kpi-accent: var(--state-left);
}

.kpi[data-kpi="avgTotal"] {
  --kpi-accent: var(--state-service);
}

.kpi__value {
  display: flex;
  align-items: baseline;
  gap: 5px;
  min-height: 34px;
  margin-top: 2px;
  font-size: var(--fs-28);
  font-weight: 600;
  line-height: 1.2;
  white-space: nowrap;
}

.kpi__value.skeleton {
  width: 60%;
  height: 28px;
  min-height: 0;
  margin-top: 6px;
}

.kpi__number {
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}

.kpi__unit {
  color: var(--text-2);
  font-size: var(--fs-13);
  font-weight: 500;
}

.kpi[role="button"] {
  cursor: pointer;
  border-radius: var(--r-sm);
  transition: background-color var(--dur-fast) var(--ease-out);
}

.kpi[role="button"]:hover {
  background: rgba(255, 255, 255, 0.04);
}

.kpi[role="button"]:hover .kpi__value {
  color: var(--sky-strong);
}

.kpi--busiest .kpi__value {
  font-size: var(--fs-18);
  line-height: 34px;
  overflow: hidden;
  text-overflow: ellipsis;
  display: block;
}

.kpi__sub {
  min-height: 18px;
  color: var(--text-3);
  font-size: var(--fs-12);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-variant-numeric: tabular-nums;
}

/* ---------- Queue rail ---------- */
.queues {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.queues__columns,
.queue-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 46px 62px;
  column-gap: var(--sp-2);
}

.queues__columns {
  padding: 0 calc(var(--sp-2) + 10px) 6px;
  color: var(--text-3);
  font-size: var(--fs-11);
  font-weight: 500;
  text-align: right;
}

.queues__legend {
  display: flex;
  align-items: center;
  gap: 6px;
  text-align: left;
}

.queues__legend-mark {
  width: 3px;
  height: 11px;
  border-radius: 2px;
  background: var(--signal);
}

.queues__body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 0 var(--sp-2) var(--sp-3);
  scrollbar-width: thin;
  scrollbar-color: var(--ink-600) transparent;
}

.queue-zone + .queue-zone {
  margin-top: 2px;
  border-top: 1px solid var(--line);
  padding-top: 2px;
}

.queue-row {
  position: relative;
  grid-template-rows: auto 5px;
  row-gap: 5px;
  align-items: center;
  width: 100%;
  padding: 8px 10px 7px;
  border-radius: var(--r-sm);
  text-align: left;
  transition: background-color var(--dur-fast) var(--ease-out);
}

.queue-row:hover {
  background: rgba(255, 255, 255, 0.05);
}

.queue-row--header {
  grid-template-rows: auto;
  padding-bottom: 4px;
}

.queue-row--header:hover {
  background: none;
}

.queue-row[aria-current="true"] {
  background: var(--sky-wash);
  box-shadow: inset 0 0 0 1px var(--sky-line);
}

.queue-row__name {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  font-size: var(--fs-13);
  font-weight: 500;
}

.queue-row__label {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.queue-row--zone .queue-row__name {
  font-weight: 600;
}

.queue-row--place .queue-row__name {
  padding-left: 18px;
  color: var(--text-2);
}

.zone-swatch {
  flex: none;
  width: 10px;
  height: 10px;
  border-radius: 3px;
  background: var(--zone-color, var(--text-3));
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.18) inset;
}

.queue-row__count,
.queue-row__avg {
  text-align: right;
  font-size: var(--fs-13);
  font-variant-numeric: tabular-nums;
}

.queue-row__count {
  font-weight: 600;
}

.queue-row__avg {
  color: var(--text-2);
}

.queue-row__unit {
  margin-left: 2px;
  color: var(--text-3);
  font-size: var(--fs-11);
}

.queue-row__bar {
  grid-column: 1 / -1;
  height: 5px;
  border-radius: 3px;
  background: rgba(150, 196, 226, 0.08);
  overflow: hidden;
}

.queue-row--place .queue-row__bar {
  margin-left: 18px;
}

.queue-row__bar > span {
  display: block;
  height: 100%;
  width: calc(var(--fill, 0) * 100%);
  border-radius: 3px;
  background: var(--state-waiting);
  transition: width var(--dur-slow) var(--ease-out);
}

.queue-row.is-bottleneck .queue-row__bar > span {
  background: var(--signal);
}

.queue-row.is-bottleneck::before {
  content: "";
  position: absolute;
  left: 0;
  top: 9px;
  bottom: 9px;
  width: 3px;
  border-radius: 2px;
  background: var(--signal);
}

.queue-row.is-idle .queue-row__count {
  color: var(--text-3);
  font-weight: 500;
}

.queues__empty {
  padding: var(--sp-6) var(--sp-4);
  color: var(--text-3);
  text-align: center;
}

/* ---------- Stage: tools, overlays, legend ---------- */
.stage__overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: var(--sp-6);
}

.state-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-3);
  max-width: 380px;
  padding: var(--sp-6) var(--sp-8);
  text-align: center;
  border-radius: var(--r-lg);
  background: var(--glass-strong);
  -webkit-backdrop-filter: var(--glass-blur);
  backdrop-filter: var(--glass-blur);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-float);
}

.state-card--loading {
  flex-direction: row;
  gap: 10px;
  padding: 10px var(--sp-5);
  border-radius: var(--r-pill);
  color: var(--text-2);
  font-size: var(--fs-13);
}

.state-card__icon {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-2);
}

.state-card__icon .icon {
  width: 22px;
  height: 22px;
}

.state-card--error .state-card__icon {
  background: var(--signal-wash);
  color: #ff9d97;
}

.state-card__title {
  font-size: var(--fs-18);
  font-weight: 600;
  line-height: var(--lh-tight);
}

.state-card__detail {
  color: var(--text-3);
  font-size: var(--fs-12);
}

.state-card__actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--sp-2);
  margin-top: var(--sp-1);
}

.stage__bottom {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-2);
}

.hint {
  transition: opacity var(--dur-slow) var(--ease-out);
  padding: 4px 12px;
  border-radius: var(--r-pill);
  background: rgba(6, 20, 32, 0.66);
  color: var(--text-2);
  font-size: var(--fs-12);
}

.hint.is-leaving {
  opacity: 0;
}

.legend {
  display: flex;
  gap: var(--sp-4);
  padding: 6px var(--sp-4);
  border-radius: var(--r-pill);
  background: var(--glass);
  -webkit-backdrop-filter: var(--glass-blur);
  backdrop-filter: var(--glass-blur);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-panel);
  color: var(--text-2);
  font-size: var(--fs-12);
  font-weight: 500;
}

.legend__item {
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.legend__swatch {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--swatch);
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.12);
}

.legend__item[data-state="waiting"] {
  --swatch: var(--state-waiting);
}

.legend__item[data-state="service"] {
  --swatch: var(--state-service);
}

.legend__item[data-state="walking"] {
  --swatch: var(--state-walking);
}

/* Staff are not a patient state: a divider sets them apart. */
.legend__item[data-state="staff"] {
  --swatch: var(--staff-coat);
  padding-left: var(--sp-3);
  border-left: 1px solid var(--line);
}

.legend__item[data-state="staff"] .legend__swatch {
  box-shadow: 0 0 0 1.5px var(--staff-ring);
}

/* ---------- Timeline ---------- */
.timeline {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: var(--sp-5);
  padding: var(--sp-3) var(--sp-5) var(--sp-3) var(--sp-3);
}

.timeline__controls {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
}

.play-button {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  flex: none;
  border-radius: 50%;
  background: var(--sky);
  color: var(--text-on-accent);
  box-shadow: 0 6px 18px rgba(56, 182, 236, 0.32);
  transition:
    background-color var(--dur-fast) var(--ease-out),
    transform var(--dur-fast) var(--ease-out);
}

.play-button:hover {
  background: var(--sky-strong);
}

.play-button:active {
  transform: scale(0.96);
}

.play-button__icon {
  width: 22px;
  height: 22px;
  fill: currentColor;
}

.play-button__icon--pause,
.play-button[data-playing="true"] .play-button__icon--play {
  display: none;
}

.play-button[data-playing="true"] .play-button__icon--pause {
  display: block;
}

.segmented--speed .segmented__option {
  min-width: 42px;
  padding: 0 var(--sp-2);
  font-variant-numeric: tabular-nums;
}

.scrubber {
  min-width: 0;
}

.scrubber__track {
  position: relative;
  height: 52px;
  border-radius: var(--r-sm);
  background: rgba(4, 14, 24, 0.45);
  border: 1px solid var(--line);
  overflow: visible;
}

.scrubber__track:has(.scrubber__input:focus-visible) {
  box-shadow: var(--focus-ring);
}

.scrubber__curve {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.scrubber__progress {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: calc(var(--progress, 0) * 100%);
  border-radius: var(--r-sm) 0 0 var(--r-sm);
  background: linear-gradient(
    90deg,
    rgba(56, 182, 236, 0.04),
    rgba(56, 182, 236, 0.12)
  );
  pointer-events: none;
}

.scrubber__head {
  position: absolute;
  top: -5px;
  bottom: -5px;
  left: calc(var(--progress, 0) * 100%);
  width: 2px;
  margin-left: -1px;
  border-radius: 1px;
  background: var(--text-1);
  box-shadow: 0 0 0 3px rgba(56, 182, 236, 0.3);
  pointer-events: none;
}

.scrubber__head::before {
  content: "";
  position: absolute;
  top: -4px;
  left: -5px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--text-1);
  box-shadow: 0 0 0 3px var(--sky);
}

.scrubber__peak {
  position: absolute;
  top: 3px;
  left: calc(var(--peak, 0) * 100%);
  transform: translateX(-50%);
  pointer-events: none;
}

.scrubber__peak-label {
  display: block;
  padding: 0 6px;
  border-radius: var(--r-pill);
  background: rgba(6, 20, 32, 0.78);
  border: 1px solid rgba(255, 182, 72, 0.5);
  color: #ffd79c;
  font-size: var(--fs-11);
  font-weight: 600;
  line-height: 16px;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.scrubber__input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
  touch-action: none;
}

.scrubber__ticks {
  position: relative;
  height: 16px;
  margin-top: 4px;
}

.scrubber__tick[data-edge="start"] {
  transform: none;
}

.scrubber__tick[data-edge="end"] {
  transform: translateX(-100%);
}

.speed-cycle {
  display: none;
  min-width: 52px;
  height: 34px;
  padding: 0 var(--sp-3);
  border-radius: var(--r-sm);
  border: 1px solid var(--line);
  background: rgba(4, 14, 24, 0.55);
  font-size: var(--fs-13);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.scrubber__tick {
  position: absolute;
  top: 0;
  transform: translateX(-50%);
  color: var(--text-3);
  font-size: var(--fs-11);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.clock {
  display: grid;
  justify-items: end;
  gap: 2px;
  min-width: 168px;
  transition: opacity var(--dur-mid) var(--ease-out);
}

[data-view="loading"] .clock,
[data-view="error"] .clock,
[data-view="invalid"] .clock {
  opacity: 0.35;
}

.clock__time {
  display: flex;
  align-items: baseline;
  font-variant-numeric: tabular-nums;
}

.clock__hm {
  font-size: var(--fs-44);
  font-weight: 600;
  line-height: 1;
  letter-spacing: -0.02em;
}

.clock__s {
  margin-left: 2px;
  color: var(--text-3);
  font-size: var(--fs-20);
  font-weight: 500;
}

.clock__meta {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-2);
  font-size: var(--fs-12);
  white-space: nowrap;
}

.clock__live {
  padding: 0 7px;
  border-radius: var(--r-pill);
  background: var(--signal);
  color: #fff;
  font-size: var(--fs-11);
  font-weight: 700;
  line-height: 17px;
}

.clock__updated {
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
}

.clock__updated[data-failed="true"] {
  color: #ffb2ad;
}

.clock__next {
  color: var(--state-waiting);
  font-weight: 600;
}

.keys {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 4px;
  color: var(--text-3);
  font-size: var(--fs-11);
  white-space: nowrap;
}

.keys dt {
  display: flex;
  gap: 2px;
}

.keys dd {
  margin-right: 6px;
}

/* ---------- Analysis drawer ---------- */
.drawer__head {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-4) var(--sp-3) var(--sp-3) var(--sp-5);
}

.drawer__head .icon-button {
  margin-left: auto;
}

.drawer__title {
  font-size: var(--fs-20);
  font-weight: 600;
  line-height: var(--lh-tight);
}

.drawer__body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: var(--sp-4) var(--sp-5) var(--sp-6);
  scrollbar-width: thin;
  scrollbar-color: var(--ink-600) transparent;
}

.insights {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--sp-2);
  padding: 0 var(--sp-5) var(--sp-3);
}

.insight {
  display: grid;
  align-content: start;
  gap: 2px;
  min-width: 0;
  padding: 10px 12px;
  border-radius: var(--r-md);
  background: rgba(4, 14, 24, 0.5);
  border: 1px solid var(--line);
}

.insight__label {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-2);
  font-size: var(--fs-12);
  font-weight: 500;
}

.insight__label::before {
  content: "";
  width: 3px;
  height: 11px;
  border-radius: 2px;
  background: var(--insight-accent, var(--sky));
}

.insight[data-insight="bottleneck"] {
  --insight-accent: var(--signal);
}

.insight[data-insight="longStay"] {
  --insight-accent: var(--state-waiting);
}

.insight__value {
  font-size: var(--fs-20);
  font-weight: 600;
  line-height: 1.3;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.insight__sub {
  color: var(--text-3);
  font-size: var(--fs-12);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tabs {
  display: flex;
  gap: var(--sp-1);
  padding: 0 var(--sp-5);
  border-bottom: 1px solid var(--line);
}

.tab {
  position: relative;
  height: 40px;
  padding: 0 var(--sp-3);
  color: var(--text-2);
  font-size: var(--fs-13);
  font-weight: 500;
  white-space: nowrap;
}

.tab:hover {
  color: var(--text-1);
}

.tab[aria-selected="true"] {
  color: var(--text-1);
  font-weight: 600;
}

.tab[aria-selected="true"]::after {
  content: "";
  position: absolute;
  left: var(--sp-3);
  right: var(--sp-3);
  bottom: -1px;
  height: 2px;
  border-radius: 2px;
  background: var(--sky);
}

.tab-panel {
  display: grid;
  gap: var(--sp-6);
}

/* What-if */
.what-if {
  display: grid;
  gap: var(--sp-5);
}

.what-if__group-title {
  margin-bottom: var(--sp-2);
  color: var(--text-2);
  font-size: var(--fs-12);
  font-weight: 600;
}

.slider-row {
  display: grid;
  grid-template-columns: minmax(0, 132px) minmax(0, 1fr) 64px;
  align-items: center;
  gap: var(--sp-3);
  padding: 5px 0;
}

.slider-row__label {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  font-size: var(--fs-13);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.slider-row__value {
  text-align: right;
  font-size: var(--fs-13);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.slider-row__value[data-changed="true"] {
  color: var(--sky-strong);
}

.range {
  width: 100%;
  height: 20px;
  margin: 0;
  background: transparent;
  -webkit-appearance: none;
  appearance: none;
  cursor: pointer;
}

.range::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 2px;
  background: linear-gradient(
    90deg,
    var(--sky) calc(var(--fill, 0) * 100%),
    rgba(150, 196, 226, 0.18) calc(var(--fill, 0) * 100%)
  );
}

.range::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  margin-top: -6px;
  border-radius: 50%;
  background: var(--text-1);
  box-shadow:
    0 0 0 3px var(--ink-900),
    0 0 0 4px var(--sky-line);
}

.range::-moz-range-track {
  height: 4px;
  border-radius: 2px;
  background: rgba(150, 196, 226, 0.18);
}

.range::-moz-range-progress {
  height: 4px;
  border-radius: 2px;
  background: var(--sky);
}

.range::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border: 0;
  border-radius: 50%;
  background: var(--text-1);
}

.range:focus-visible {
  box-shadow: none;
}

.range:focus-visible::-webkit-slider-thumb {
  box-shadow: var(--focus-ring);
}

.what-if__actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
}

.deltas {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fs-13);
}

.deltas th,
.deltas td {
  padding: 8px 6px;
  border-bottom: 1px solid var(--line);
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.deltas th:first-child,
.deltas td:first-child {
  text-align: left;
  white-space: normal;
}

.deltas tr.is-warning th,
.deltas tr.is-warning td:nth-child(3) {
  color: var(--sev-warning);
}

.deltas thead th {
  color: var(--text-3);
  font-size: var(--fs-12);
  font-weight: 500;
}

.delta {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-weight: 600;
}

.delta__arrow {
  width: 14px;
  height: 14px;
  stroke-width: 2;
}

.delta[data-direction="better"] {
  color: var(--sev-good);
}

.delta[data-direction="worse"] {
  color: var(--sev-critical);
}

.delta[data-direction="same"] {
  color: var(--text-3);
}

.delta__word {
  color: var(--text-3);
  font-size: var(--fs-11);
  font-weight: 500;
}

.notice {
  display: grid;
  justify-items: start;
  gap: var(--sp-3);
  padding: var(--sp-4);
  border-radius: var(--r-md);
  border: 1px dashed var(--line-strong);
  color: var(--text-2);
}

/* ---------- Tab bar (phones) ---------- */
.tabbar__item {
  display: grid;
  justify-items: center;
  align-content: center;
  gap: 2px;
  color: var(--text-3);
  font-size: var(--fs-11);
  font-weight: 500;
}

.tabbar__item .icon {
  width: 20px;
  height: 20px;
}

.tabbar__item[aria-pressed="true"] {
  color: var(--sky-strong);
}

/* ---------- Hover tip and toasts ---------- */
.hover-tip {
  padding: 5px 10px;
  border-radius: var(--r-sm);
  background: var(--glass-strong);
  border: 1px solid var(--line-strong);
  box-shadow: var(--shadow-panel);
  font-size: var(--fs-12);
  font-weight: 600;
  white-space: nowrap;
  transform: translate(12px, -50%);
}

.hover-tip__phase {
  margin-left: 6px;
  color: var(--text-2);
  font-weight: 500;
}

.toast {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: 8px 8px 8px 14px;
  border-radius: var(--r-pill);
  background: var(--glass-strong);
  border: 1px solid var(--line-strong);
  box-shadow: var(--shadow-float);
  font-size: var(--fs-13);
  pointer-events: auto;
  animation: toast-in var(--dur-mid) var(--ease-out);
}

.toast__text {
  white-space: nowrap;
}

.toast--warning {
  border-color: rgba(250, 178, 25, 0.5);
}

.toast .tool-button {
  height: 30px;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(-6px);
  }
}

/* ---------- Medium widths ---------- */
@media (max-width: 1279.98px) {
  .kpi {
    padding: 0 var(--sp-3);
  }

  .kpi__value {
    font-size: var(--fs-24);
  }

  .kpi__label {
    font-size: var(--fs-12);
  }

  .brand__product {
    display: none;
  }

  .keys {
    display: none;
  }

  .stage__tools {
    top: 0;
  }

  .clock {
    min-width: 0;
  }
}

@media (max-width: 1023.98px) {
  .topbar {
    flex-wrap: wrap;
    row-gap: var(--sp-2);
  }

  .topbar__tools {
    margin-left: auto;
  }

  .kpis {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    row-gap: var(--sp-3);
  }

  .kpi:nth-child(4) {
    border-left: 0;
  }

  .timeline {
    grid-template-columns: auto minmax(0, 1fr);
    grid-template-areas:
      "controls clock"
      "scrubber scrubber";
    gap: var(--sp-3);
  }

  .timeline__controls {
    grid-area: controls;
  }

  .scrubber {
    grid-area: scrubber;
  }

  .clock {
    grid-area: clock;
  }
}

/* ---------- Phones ---------- */
@media (max-width: 767.98px) {
  .topbar {
    gap: var(--sp-2);
    padding: var(--sp-2);
  }

  .brand {
    padding-right: 0;
    border-right: 0;
  }

  .brand__name {
    font-size: var(--fs-14);
  }

  .topbar__source {
    order: 3;
    width: 100%;
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
  }

  .topbar__source::-webkit-scrollbar {
    display: none;
  }

  .topbar__tools .tool-button,
  #analysis-button {
    display: none;
  }

  .search__input {
    width: 96px;
  }

  .search__input:focus {
    width: 120px;
  }

  .kpis {
    display: flex;
    gap: 0;
    padding: var(--sp-2) 0;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    scrollbar-width: none;
  }

  .kpis::-webkit-scrollbar {
    display: none;
  }

  .kpi {
    flex: 0 0 38%;
    padding: 0 var(--sp-3);
    scroll-snap-align: start;
  }

  .kpi:nth-child(4) {
    border-left: 1px solid var(--line);
  }

  .kpi__value {
    font-size: var(--fs-20);
    min-height: 28px;
  }

  .kpi--busiest .kpi__value {
    font-size: var(--fs-14);
    line-height: 28px;
  }

  .legend {
    gap: var(--sp-3);
    padding: 4px var(--sp-3);
  }

  .hint {
    display: none;
  }

  .timeline {
    padding: var(--sp-2) var(--sp-3);
    gap: var(--sp-2);
  }

  .play-button {
    width: 40px;
    height: 40px;
  }

  .segmented--speed {
    display: none;
  }

  .speed-cycle {
    display: inline-block;
  }

  .clock__meta {
    font-size: var(--fs-11);
  }

  .scrubber__track {
    height: 40px;
  }

  .clock__hm {
    font-size: var(--fs-28);
  }

  .clock__s {
    font-size: var(--fs-14);
  }

  .insights {
    gap: 6px;
  }

  .insight {
    padding: 8px 10px;
  }

  .insight__value {
    font-size: var(--fs-16);
  }

  .slider-row {
    grid-template-columns: minmax(0, 104px) minmax(0, 1fr) 56px;
  }
}

/* ---------- Scrubber curve ---------- */
.scrubber__area {
  fill: var(--sky);
  fill-opacity: 0.16;
}

.scrubber__line {
  fill: none;
  stroke: var(--sky);
  stroke-width: 1.5;
  stroke-opacity: 0.85;
  stroke-linejoin: round;
}

.scrubber__line--waiting {
  stroke: var(--state-waiting);
  stroke-opacity: 0.9;
}
