/* Handset: one realistic phone for the Patient phone screen and the tour (see js/handset.js).
   Two bodies, same keys: a candybar keypad phone and a smartphone in a call. The body never
   grows with the call: the screen has a fixed size and the transcript scrolls inside it.
   Tokens only. Motion is transform and opacity; reduced motion turns it off. */

.ct-hs { display: flex; justify-content: center; width: 100%; }
.ct-hs__body {
  position: relative; display: flex; flex-direction: column; flex: none;
  background: var(--color-ink); color: var(--color-ink-inverse);
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--color-ink-inverse) 12%, transparent), var(--shadow-pill), var(--shadow-2);
}
/* Side buttons: volume on the left, power on the right. */
.ct-hs__body::before, .ct-hs__body::after {
  content: ""; position: absolute; width: 3px; border-radius: var(--radius-sm); background: var(--color-ink); pointer-events: none;
}
.ct-hs__body::before { left: -3px; top: 18%; height: 12%; }
.ct-hs__body::after { right: -3px; top: 24%; height: 8%; }
.ct-hs__glass { display: flex; flex-direction: column; min-height: 0; }
.ct-hs__screen { display: flex; flex-direction: column; gap: var(--space-2); min-height: 0; background: var(--color-surface); color: var(--color-ink); }

/* Keys, shared */
.ct-hs__key, .ct-hs__answer, .ct-hs__decline {
  font: inherit; border: 0; cursor: pointer; -webkit-tap-highlight-color: transparent;
  transition: transform 120ms var(--ease-out), background-color 150ms var(--ease-out), opacity 150ms var(--ease-out);
}
span.ct-hs__key, span.ct-hs__answer, span.ct-hs__decline { cursor: default; }
.ct-hs__key { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0; line-height: var(--leading-tight); min-width: 0; }
.ct-hs__digit { font-size: var(--text-xl); font-weight: var(--weight-medium); font-variant-numeric: tabular-nums; }
.ct-hs__abc, .ct-hs__hint { font-size: var(--text-xs); letter-spacing: 0.04em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.ct-hs__hint { font-weight: var(--weight-bold); letter-spacing: 0; }
button.ct-hs__key:active:not(:disabled), .ct-hs__key.is-pressed { transform: scale(0.94); }
button.ct-hs__answer:active:not(:disabled) .ct-hs__round, button.ct-hs__decline:active:not(:disabled) .ct-hs__round { transform: scale(0.94); }
.ct-hs button:disabled { cursor: not-allowed; }
.ct-hs button:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--color-ink), 0 0 0 5px var(--color-accent); }
.ct-hs__round { display: inline-grid; place-items: center; transition: transform 120ms var(--ease-out); }
.ct-hs__answer .ct-hs__round { background: var(--status-taken); color: var(--color-ink-inverse); }
.ct-hs__decline .ct-hs__round { background: var(--status-urgent); color: var(--color-ink-inverse); }

/* ---------- Smartphone in a call ---------- */
.ct-hs--touch { --hs-h: clamp(34rem, calc(100svh - 11.5rem), 44rem); }
.ct-hs--touch .ct-hs__body { height: var(--hs-h); aspect-ratio: 9 / 19; max-width: 100%; padding: 0.55rem; border-radius: 3rem; }
.ct-hs--touch .ct-hs__ear {
  position: absolute; z-index: 2; top: 1.1rem; left: 50%; transform: translateX(-50%);
  width: 5.25rem; height: 1.45rem; border-radius: var(--radius-pill); background: var(--color-ink);
}
.ct-hs--touch .ct-hs__glass {
  flex: 1; background: var(--color-surface); color: var(--color-ink); border-radius: 2.45rem; overflow: hidden;
  padding: 2.9rem var(--space-4) var(--space-4); gap: var(--space-3);
}
.ct-hs--touch .ct-hs__screen { flex: 1; }
.ct-hs--touch .ct-hs__pad { order: 2; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--space-2); }
.ct-hs--touch .ct-hs__key { min-height: var(--tap-min); padding: var(--space-1); border-radius: var(--radius-lg); background: var(--color-surface-sunken); color: var(--color-ink); }
.ct-hs--touch .ct-hs__digit { font-size: var(--text-lg); }
.ct-hs--touch .ct-hs__abc { color: var(--color-ink-muted); }
.ct-hs--touch .ct-hs__hint { color: var(--color-primary); }
.ct-hs--touch button.ct-hs__key:hover:not(:disabled) { background: var(--color-border); }
.ct-hs--touch .ct-hs__call { order: 3; display: grid; grid-template-columns: 1fr 1fr; justify-items: center; }
.ct-hs--touch .ct-hs__answer, .ct-hs--touch .ct-hs__decline {
  display: flex; flex-direction: column; align-items: center; gap: var(--space-1); background: transparent; color: var(--color-ink-muted);
  font-size: var(--text-xs); font-weight: var(--weight-medium); padding: 0;
}
.ct-hs--touch .ct-hs__round { width: 3.5rem; height: 3.5rem; border-radius: var(--radius-pill); }
.ct-hs--touch .ct-hs__round .ct-icon { width: 1.5em; height: 1.5em; }

/* ---------- Candybar keypad phone ---------- */
.ct-hs--keypad .ct-hs__body { width: min(100%, 19rem); padding: var(--space-3) var(--space-4) var(--space-4); border-radius: 2.75rem 2.75rem 2.25rem 2.25rem; }
.ct-hs--keypad .ct-hs__ear { display: block; width: 3.5rem; height: 0.35rem; margin: var(--space-1) auto var(--space-3); border-radius: var(--radius-pill); background: color-mix(in srgb, var(--color-ink-inverse) 28%, var(--color-ink)); }
.ct-hs--keypad .ct-hs__glass { gap: var(--space-3); }
.ct-hs--keypad .ct-hs__screen {
  height: 18rem; padding: var(--space-2) var(--space-3); border-radius: var(--radius-md); gap: var(--space-1);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--color-ink-inverse) 10%, var(--color-ink));
}
.ct-hs--keypad .ct-hs__call { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-3); margin-top: var(--space-1); }
.ct-hs--keypad .ct-hs__answer, .ct-hs--keypad .ct-hs__decline {
  display: flex; align-items: center; justify-content: center; gap: var(--space-2); min-height: var(--tap-min);
  border-radius: var(--radius-lg) var(--radius-lg) var(--radius-md) var(--radius-md);
  font-size: var(--text-sm); font-weight: var(--weight-bold); color: var(--color-ink-inverse);
}
.ct-hs--keypad .ct-hs__answer { background: var(--status-taken); }
.ct-hs--keypad .ct-hs__decline { background: var(--status-urgent); }
.ct-hs--keypad .ct-hs__round { background: transparent; }
.ct-hs--keypad .ct-hs__pad { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--space-2); }
.ct-hs--keypad .ct-hs__key {
  min-height: var(--tap-min); padding: var(--space-1); border-radius: var(--radius-md);
  background: color-mix(in srgb, var(--color-ink-inverse) 13%, var(--color-ink)); color: var(--color-ink-inverse);
  box-shadow: inset 0 -2px 0 color-mix(in srgb, var(--color-ink) 70%, transparent);
}
.ct-hs--keypad .ct-hs__abc { color: color-mix(in srgb, var(--color-ink-inverse) 70%, transparent); }
.ct-hs--keypad .ct-hs__hint { color: var(--color-accent); }
.ct-hs--keypad button.ct-hs__key:hover:not(:disabled) { background: color-mix(in srgb, var(--color-ink-inverse) 22%, var(--color-ink)); }

/* ---------- States ---------- */
/* Before a call the keys rest dimmed; while ringing the green key pulses; while a key is
   expected (and in the tour step about keys) 1, 2, 3 and 9 light up. */
.ct-hs button.ct-hs__key:disabled { opacity: 0.45; }
.ct-hs button.ct-hs__answer:disabled, .ct-hs button.ct-hs__decline:disabled { opacity: 0.45; }
.ct-hs.is-ringing .ct-hs__answer .ct-hs__round, .ct-hs--keypad.is-ringing .ct-hs__answer { animation: ct-hs-ring 1.2s var(--ease-out) infinite; }
.ct-hs.is-lit .ct-hs__key--care, .ct-hs.is-keys .ct-hs__key--care:not(:disabled) { background: var(--color-primary); color: var(--color-ink-inverse); }
.ct-hs.is-lit .ct-hs__key--care .ct-hs__hint, .ct-hs.is-keys .ct-hs__key--care:not(:disabled) .ct-hs__hint { color: var(--color-ink-inverse); }
@keyframes ct-hs-ring {
  0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--status-taken) 55%, transparent); }
  100% { box-shadow: 0 0 0 var(--space-4) transparent; }
}

/* ---------- The call on the Patient phone screen ---------- */
.ct-hs .ct-phone__status { font-size: var(--text-xs); }
.ct-hs .ct-phone__caller { padding: 0; }
.ct-hs .ct-phone__caller-name { font-size: var(--text-lg); }
.ct-hs .ct-phone__avatar { width: var(--space-7); height: var(--space-7); }
.ct-hs .ct-phone__avatar .ct-icon { width: 1.5em; height: 1.5em; }
.ct-hs.is-ringing .ct-phone__avatar { animation: ct-ring 1.4s ease-out infinite; }
.ct-hs__screen { overflow: hidden; }
/* Once answered, the caller shrinks to one row, as on a real phone, and the words get the room. */
.ct-hs.is-oncall .ct-phone__caller { flex-direction: row; justify-content: flex-start; gap: var(--space-2); text-align: left; }
.ct-hs.is-oncall .ct-phone__avatar { width: var(--space-6); height: var(--space-6); }
.ct-hs.is-oncall .ct-phone__avatar .ct-icon { width: 1.1em; height: 1.1em; }
.ct-hs.is-oncall .ct-phone__caller-name { font-size: var(--text-md); }
.ct-hs.is-oncall .ct-phone__caller-name { white-space: nowrap; }
.ct-hs.is-oncall #ph-sub { margin-left: auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ct-hs .ct-phone__transcript { flex: 1; min-height: 3rem; max-height: none; overflow-y: auto; overscroll-behavior: contain; font-size: var(--text-sm); scroll-behavior: smooth; }
.ct-hs .ct-phone__line { padding: var(--space-1) var(--space-2); }
.ct-hs .ct-phone__line-en { font-size: var(--text-xs); }
.ct-hs .ct-phone__live { min-height: 0; font-size: var(--text-xs); }
.ct-hs .ct-phone__live:empty { display: none; }
.ct-hs .ct-phone__state {
  min-height: var(--space-6); font-size: var(--text-sm); color: var(--color-ink-muted); justify-content: center;
  border-top: 1px solid var(--color-border); padding-top: var(--space-2); text-align: center;
}
.ct-hs .ct-phone__state.is-hint { color: var(--status-later); }
.ct-hs--keypad .ct-phone__state { min-height: 0; padding-top: var(--space-1); font-size: var(--text-xs); }
/* The small keypad display: no avatar, just the caller line. */
.ct-hs--keypad .ct-phone__avatar { display: none; }
.ct-hs--keypad .ct-phone__caller { flex-direction: row; justify-content: space-between; text-align: left; }
.ct-hs--keypad .ct-phone__caller-name { font-size: var(--text-md); }

@media (prefers-reduced-motion: reduce) {
  .ct-hs *, .ct-hs *::before, .ct-hs *::after { animation: none !important; transition: none !important; }
}

/* ---------- Patient phone page ---------- */
/* Desktop: the phone stays in view on the left while the controls scroll on the right.
   Narrow: heading, then the controls that ring it, then the phone, then the reply box. */
.ct-phone-page { display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); gap: var(--space-6) var(--space-7); align-items: start; }
.ct-phone-page__device { position: sticky; top: calc(var(--space-8) + var(--space-5)); }
@media (max-width: 899px) {
  .ct-phone-page { grid-template-columns: minmax(0, 1fr); gap: var(--space-5); }
  .ct-phone-page__side { display: contents; }
  .ct-phone-page__side > :nth-child(1) { order: 1; }
  .ct-phone-page__side > :nth-child(2) { order: 2; }
  .ct-phone-page__device { order: 3; position: static; }
  .ct-phone-page__side > :nth-child(n + 3) { order: 4; }
}
@media (max-height: 700px) and (min-width: 900px) { .ct-phone-page__device { position: static; } }

/* What Care Taker understood: the heard line and the dose record, next to the reply box. */
.ct-understood { display: flex; flex-direction: column; gap: var(--space-3); }
.ct-understood .ct-phone__chip:empty { display: none; }
