/* CMHA voice widget — high-contrast, large touch targets (glove-friendly). */
:root {
  --bg: #0f1620;
  --panel: #18222f;
  --ink: #f2f6fb;
  --muted: #9fb0c3;
  --line: #2a3848;
  --accent: #2f7de1;
  --live: #2bb673;
  --sos: #d8412f;
  --sos-ink: #fff;
  /* Control sizing — override from the admin's custom CSS to resize the buttons
     (the mic / "Crisis Support" bar and the language select share these). */
  --btn-height: 56px;
  --btn-radius: 12px;
}

* {
  box-sizing: border-box;
}
html,
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  height: 100%;
}

/* The stage: the optional 3D avatar pane, then the chat. It owns the viewport
   height so the widget can simply fill it. With no avatar it's an invisible
   wrapper and the layout is byte-for-byte what it was before. */
.stage {
  display: flex;
  align-items: stretch;
  justify-content: center;
  height: 100vh;
  height: 100dvh;
}

/* 3D avatar (Unity WebGL), left of the chat. Hidden — and, crucially, with no
   iframe src — until widget.js decides it should exist (see initAvatar3d).

   flex-GROW is deliberate: the pane takes whatever width the embed has spare,
   rather than the stage centring the pane+chat pair and leaving page background
   showing down one side. That gap read as a bug rather than as letterboxing,
   because the matching gap on the right is camouflaged by the chat panel being a
   near-identical shade, and there's none top or bottom — so it looked like a
   stray vertical stripe beside the avatar.

   The operator's configured width is therefore a MINIMUM, not an exact size. That
   is the better trade: embeds get resized by people who never see that setting,
   and an avatar that uses the extra room beats a stripe that looks broken. The
   cap matches the admin's own maximum (AVATAR3D_WIDTH_MAX) so a very wide embed
   can't hand the avatar an absurd share of the page. */
.avatar3d {
  flex: 1 1 var(--avatar3d-width, 380px);
  max-width: 900px;
  position: relative;
  background: var(--bg);
  border-right: 1px solid var(--line);
  overflow: hidden;
}
.avatar3d__frame {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
}
/* Something to look at while a very large build streams in, and what stays on
   screen if it never arrives. Covered once the frame reports it loaded. */
.avatar3d__note {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}
.avatar3d.is-ready .avatar3d__note {
  display: none;
}
/* Phones get the chat alone. A Unity build is hundreds of megabytes, which is
   not something to hand a visitor on cellular — widget.js also refuses to create
   the iframe at this size, so this rule is the belt to that braces. */
@media (max-width: 760px) {
  .avatar3d {
    display: none;
  }
}

/* The live video pane. Same slot as the 3D pane; a persona uses one or the other. */
.avatar-video {
  flex: 1 1 var(--avatar3d-width, 380px);
  max-width: 900px;
  position: relative;
  background: #0b0d10;
  border-right: 1px solid var(--line);
  overflow: hidden;
}
.avatar-video__el {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
/* The face box: photo and live video share it, and it is what scales. At rest
   (no live track) it sits at 80% in the centre of the pane; when the track
   arrives it eases up to full size with a small overshoot and settle, and eases
   back down when the call ends. One curve both ways, so the two moves rhyme. */
.avatar-video__face {
  position: absolute;
  inset: 0;
  transform: scale(0.8);
  transform-origin: 50% 50%;
  transition: transform 720ms cubic-bezier(0.34, 1.45, 0.64, 1);
  will-change: transform;
}
.avatar-video.is-ready .avatar-video__face {
  transform: scale(1);
}
@media (prefers-reduced-motion: reduce) {
  .avatar-video__face {
    transition: none;
  }
}
/* The still photo stays under the video for the whole call. The <video> paints
   black from the moment a track is attached until its first frame decodes, so
   it is kept transparent until the widget sees frames (has-frames), then fades
   in over the photo — the scale-up runs on the photo, and the face simply
   starts moving. Coming back, the video fades out and the photo is already there. */
.avatar-video__el {
  position: relative;
  opacity: 0;
  transition: opacity 320ms ease;
}
.avatar-video.has-frames .avatar-video__el {
  opacity: 1;
}
/* The still photo under the video: same crop as the live track, so the switch
   from one to the other is a face starting to move, not a layout change. */
.avatar-video__photo {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.avatar-video__photo:not([src]) {
  display: none;
}
/* A quiet strip along the bottom while the live track is on its way. */
.avatar-video__note {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 8px 12px;
  text-align: center;
  color: #e6ebf0;
  font-size: 12px;
  background: linear-gradient(to top, rgba(11, 13, 16, 0.75), rgba(11, 13, 16, 0));
}
.avatar-video.is-ready .avatar-video__note {
  display: none;
}
@media (max-width: 760px) {
  .avatar-video {
    display: none;
  }
}

/* Fixed-height column: header + resources + controls stay put; only the chat
   body scrolls. Height comes from the stage above (which tracks the dynamic
   viewport on mobile via 100dvh). */
.widget {
  max-width: 440px;
  margin: 0 auto;
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--panel);
  position: relative; /* anchor for the avatar dropdown overlay */
}
/* With an avatar alongside, the PAIR is what gets centred. The widget's own auto
   margins would otherwise absorb every pixel of free space and strand the avatar
   against the far left edge, with a gulf between it and the chat. */
.stage.has-avatar > .widget {
  margin: 0;
}

/* Three columns on a wide embed: face (or 3D build) · conversation · rail.
   widget.js adds has-rail when the embed is wide enough (≥1040px with a face
   pane, ≥760px without one) and moves the sources,
   feedback and notice into the rail; the chat then grows past its single-column
   cap so the transcript keeps the middle. */
.rail {
  flex: 0 0 300px;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--panel);
  border-left: 1px solid var(--line);
  overflow: hidden;
}
.rail[hidden] {
  display: none;
}
.stage.has-rail > .widget {
  margin: 0;
  max-width: 640px;
  flex: 1 1 440px;
}
.rail__empty {
  margin: 0;
  padding: 18px;
  font-size: 13px;
  color: var(--muted);
}
.rail:has(.resources:not([hidden])) .rail__empty {
  display: none;
}
/* Inside the rail the sources take the height that is spare and scroll on their
   own; the drag grip stays in the chat column and is hidden with the rail on. */
.rail > .resources {
  flex: 1 1 auto;
  max-height: none;
  border-top: 0;
  padding-top: 14px;
}
.rail > .rate {
  margin-top: 12px;
}
.rail > .widget__disclaimer {
  margin-top: auto;
}

.widget__head {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
}
.widget__title {
  font-weight: 700;
  letter-spacing: 0.02em;
  /* Take the middle space so the status stays pinned right (was space-between). */
  flex: 1 1 auto;
  /* Without this the title is the only flexible item in a nowrap row, so it
     absorbs every shortfall by wrapping — see the phone rule below. */
  min-width: 0;
}

/* PHONES — two rows, because four things do not fit on one.
   `.widget__head` is a nowrap flex row, and the title is its only flexible
   item, so the title absorbed the entire shortfall: at 320px it was rendering
   "CMHA Assistant - Doug (English)" FOUR lines deep in a 71px column, making
   the header a fifth of the screen before a word had been said.

   Row 1 is who you are talking to; row 2 is the state and the control. Nothing
   is dropped or shortened — in particular the mute pill keeps its word, which
   it carries on purpose so it reads as a voice on/off control rather than a
   mystery glyph.

   Keyed on the viewport rather than the widget, because the widget is capped at
   440px and is comfortable at that width; this is specifically the phone case. */
@media (max-width: 460px) {
  .widget__head {
    display: grid;
    /* Col 1 holds the avatar (or collapses to nothing when it is hidden, which
       it is until the injected avatar list is read). */
    grid-template-columns: auto 1fr auto auto;
    grid-template-areas: "avatar title dot mute";
    column-gap: 10px;
    row-gap: 8px;
    padding: 12px 14px;
  }
  .widget__head > .widget__avatar {
    grid-area: avatar;
  }
  .widget__head > .widget__title {
    grid-area: title;
    font-size: 15px;
  }
  .widget__head > .widget__dot {
    grid-area: dot;
  }
  .widget__head > .widget__mute {
    grid-area: mute;
    justify-self: end;
  }
}

/* Mute toggle — text-only mode. A LABELED pill (icon + word) so it's obviously a
   voice on/off control, not a mystery glyph. Sits right of the status in the
   header so it's reachable at any time (including mid-answer, to cut playback). */
.widget__mute {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 34px;
  padding: 0 12px;
  font-size: 13px;
  font-weight: 600;
  line-height: 1;
  white-space: nowrap;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #21303f;
  color: inherit;
  cursor: pointer;
}
.widget__mute .mute-label {
  letter-spacing: 0.01em;
}
.widget__mute:hover {
  filter: brightness(1.2);
}
.widget__mute:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
/* Muted = text-only. Amber so it reads as a deliberate mode, not an error. */
.widget__mute[aria-pressed="true"] {
  border-color: #f0b429;
  background: #3a2f00;
}

/* Demo/testing-only "Reset daily greeting" button. Hidden by default (widget.js
   reveals it only on ?rt / ?dev), so it never appears in a real embed. Subtle: a
   quiet dev affordance, not part of the product chrome. */
.widget__devreset {
  flex: 0 0 auto;
  align-self: center;
  margin: 0 0 10px;
  padding: 4px 10px;
  font-size: 11px;
  letter-spacing: 0.02em;
  color: var(--muted, #8aa0b4);
  background: transparent;
  border: 1px dashed var(--line);
  border-radius: 8px;
  cursor: pointer;
  opacity: 0.7;
}
.widget__devreset:hover {
  opacity: 1;
}
.widget__devreset:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Per-tenant avatar in the header + its picker. All optional — absent avatars
   leave the header exactly as before. */
.widget__avatar {
  position: relative;
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 2px solid var(--line);
  border-radius: 50%;
  background: #21303f;
  cursor: pointer;
}
.widget__avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
  display: block;
}
/* Voice is fixed once a conversation starts — the caret goes away so the picker
   doesn't look available mid-session. */
.widget__avatar.is-locked {
  cursor: default;
  opacity: 0.85;
}
.widget__avatar.is-locked::after {
  display: none;
}
.widget__avatar[aria-expanded="true"] {
  border-color: var(--accent);
}
/* Dropdown caret — only when there's more than one avatar to choose from. */
.widget__avatar.has-picker::after {
  content: "▾";
  position: absolute;
  right: -3px;
  bottom: -3px;
  width: 16px;
  height: 16px;
  line-height: 14px;
  font-size: 10px;
  text-align: center;
  color: #fff;
  background: var(--accent);
  border-radius: 50%;
  border: 2px solid var(--panel);
}

/* Picker: an OVERLAY dropdown anchored under the avatar — takes no layout space
   (was an inline row). A vertical list of face + name rows. Starts closed; the
   [hidden] rule must beat `.avatar-picker { display:flex }` on specificity, or
   the picker renders open on load. */
.avatar-picker[hidden] {
  display: none;
}
.avatar-picker {
  position: absolute;
  top: 62px;
  left: 14px;
  z-index: 30;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 190px;
  max-height: 56vh;
  overflow-y: auto;
  padding: 6px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.45);
}
.avatar-option {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 7px 9px;
  background: none;
  border: 1px solid transparent;
  border-radius: 9px;
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  text-align: left;
  cursor: pointer;
}
.avatar-option img {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--line);
}
.avatar-option span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.avatar-option:hover {
  background: #21303f;
}
.avatar-option[aria-selected="true"] img {
  border-color: var(--accent);
}
/* Call state.
   The header carries a DOT (colour only, at a glance); the WORDS sit in a
   full-width strip directly above the buttons, where the next action is. The
   old header chip was sized for one word and wrapped anything longer into a
   six-line blob beside the title. One line, never wraps: a phrase that does not
   fit is cut with an ellipsis rather than pushing the buttons down. */
.widget__dot,
.widget__state-dot {
  flex: 0 0 auto;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--muted);
}
.widget__state {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  padding: 6px 18px;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--muted);
  border-top: 1px solid var(--line);
  background: var(--panel);
}
.widget__state-text {
  flex: 1 1 auto;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
[data-state="live"] > .widget__state-dot,
.widget__dot[data-state="live"] {
  background: var(--live);
  box-shadow: 0 0 0 4px rgba(72, 214, 122, 0.2);
  animation: pulse 1.1s infinite;
}
.widget__state[data-state="live"] {
  color: var(--live);
}
[data-state="connecting"] > .widget__state-dot,
[data-state="thinking"] > .widget__state-dot,
.widget__dot[data-state="connecting"],
.widget__dot[data-state="thinking"] {
  background: #d6b94a;
}
.widget__state[data-state="connecting"],
.widget__state[data-state="thinking"] {
  color: #e8cf6a;
}
[data-state="speaking"] > .widget__state-dot,
.widget__dot[data-state="speaking"] {
  background: var(--accent);
  animation: pulse 1.1s infinite;
}
.widget__state[data-state="speaking"] {
  color: #fff;
}
[data-state="error"] > .widget__state-dot,
.widget__dot[data-state="error"] {
  background: var(--sos);
}
.widget__state[data-state="error"] {
  color: #ff9a9a;
}
.widget__body {
  flex: 1 1 auto;
  min-height: 0; /* the flexbox fix: lets the body shrink + scroll instead of pushing the header off-screen */
  padding: 18px;
  overflow-y: auto;
}
.widget__hint {
  color: var(--muted);
}

/* Floating "jump to newest". Sits just above the controls footer, centred over
   the transcript. Small and low-contrast on purpose — it's an escape hatch, not
   a call to action, and it must never compete with Talk or Crisis Support.
   `hidden` is toggled by widget.js, hence the explicit display rule.
   Positioned against `.widget` (see the sibling-of-the-scroller note below), so
   the offset must clear the controls row PLUS the disclaimer below it, not just
   guess at the controls' height — 84px sat inside the controls row (measured:
   an 85px-tall controls footer with a 2-line disclaimer under it), landing
   directly on top of the Stop button whenever both were visible at once. */
.widget__jump {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(130px + env(safe-area-inset-bottom));
  z-index: 5;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
}
.widget__jump:hover {
  border-color: var(--accent);
}
.widget__jump[hidden] {
  display: none;
}

.transcript {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.line {
  padding: 10px 14px;
  border-radius: 14px;
  max-width: 85%;
  white-space: pre-wrap;
}
.line--user {
  align-self: flex-end;
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.line--agent {
  align-self: flex-start;
  background: #21303f;
  border-bottom-left-radius: 4px;
}

/* A quiet aside from the widget itself (e.g. "voice didn't play") — clearly not
   part of what the assistant said. */
.line--note {
  background: transparent;
  border: 1px dashed var(--line);
  color: var(--muted);
  font-size: 13px;
  font-style: italic;
}

/* Rendered-markdown agent lines: real lists instead of run-on text. */
.line--rich {
  white-space: normal;
}
.line--rich .md-p {
  margin: 0;
}
.line--rich .md-p + .md-p,
.line--rich .md-p + ul,
.line--rich .md-p + ol,
.line--rich ul + .md-p,
.line--rich ol + .md-p {
  margin-top: 6px;
}
.line--rich ul,
.line--rich ol {
  margin: 4px 0;
  padding-left: 20px;
}
.line--rich li {
  margin: 3px 0;
}
.line--rich strong {
  color: #fff;
}
.line--rich code {
  background: rgba(255, 255, 255, 0.1);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 0.92em;
}

/* Resources: pinned below the scrollable chat, never pushes the layout. Caps its
   own height and scrolls if there are many sources. */
.resources {
  flex: 0 0 auto;
  /* Until the reader drags the grip above, the panel sizes to its content and
     stops at 30vh. A drag sets an inline height and clears the cap. */
  max-height: 30vh;
  overflow-y: auto;
  padding: 10px 18px 12px;
  background: #141d28;
}

/* The grip carries the dividing line, so the panel below it doesn't draw a
   second one. Hidden with the panel it resizes. */
.resources__grip {
  flex: 0 0 auto;
  height: 11px;
  position: relative;
  cursor: ns-resize;
  border-top: 1px solid var(--line);
  background: #141d28;
  touch-action: none;
}
.resources__grip::after {
  content: "";
  position: absolute;
  top: 4px;
  left: 50%;
  width: 34px;
  height: 3px;
  margin-left: -17px;
  border-radius: 2px;
  background: var(--line);
}
.resources__grip:hover::after,
.resources__grip:focus-visible::after {
  background: var(--accent);
}
.resources__grip:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}
.resources__grip[hidden] {
  display: none;
}
.resources__title {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 6px;
}
.citations {
  margin: 0;
  padding: 0;
  list-style: none;
  color: var(--ink);
  font-size: 13px;
}
.citations li {
  padding: 4px 0;
}
.citations li::before {
  content: "📄 ";
}
.citations a.cite-link {
  color: var(--accent);
  text-decoration: none;
}
.citations a.cite-link:hover {
  text-decoration: underline;
}

/* Helpful / not helpful. Deliberately quiet: it should be findable but never
   compete with Talk or Crisis Support for attention. */
.rate {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 18px 8px;
  font-size: 13px;
  color: var(--muted);
}
.rate[hidden] {
  display: none;
}
.rate__btn {
  background: none;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--ink);
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  padding: 4px 10px;
}
.rate__btn:hover {
  border-color: var(--accent);
}
.rate__btn[disabled] {
  opacity: 0.45;
  cursor: default;
}
.rate__thanks {
  color: var(--live);
}
.report {
  margin: 0 18px 14px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  padding-top: 10px;
}
.report__toggle {
  background: none;
  border: 0;
  color: var(--muted);
  font: inherit;
  font-size: 12px;
  cursor: pointer;
  padding: 0;
}
.report__toggle:hover {
  color: var(--ink);
  text-decoration: underline;
}
.report__panel {
  margin-top: 8px;
}
.report__name,
.report__note {
  width: 100%;
  box-sizing: border-box;
  background: rgba(255, 255, 255, 0.04);
  color: var(--ink);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 10px;
  padding: 8px;
  font: inherit;
  font-size: 13px;
  resize: vertical;
}
.report__name {
  margin-bottom: 6px;
}
.report__row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 8px;
}
.report__status {
  color: var(--muted);
  font-size: 12px;
}
.report__send {
  background: var(--accent);
  color: #fff;
  border: 0;
  border-radius: 10px;
  padding: 8px 14px;
  font: inherit;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
}
.report__send:disabled {
  opacity: 0.55;
  cursor: default;
}

/* Crisis safety card — a FLOATING overlay above the controls, not an inline flex
   item. As inline content it could grow tall enough to push the controls past the
   widget's `overflow:hidden` bottom edge (the "buttons pushed off screen" bug).
   As an overlay it consumes no column height, so the header and controls are ALWAYS
   visible; it caps its own height and scrolls internally if the viewport is short. */
.crisis {
  position: absolute;
  left: 14px;
  right: 14px;
  bottom: calc(88px + env(safe-area-inset-bottom));
  z-index: 40;
  max-height: calc(100% - 168px);
  overflow-y: auto;
  padding: 16px;
  border: 2px solid var(--sos);
  border-radius: 14px;
  background: #2a1714;
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.55);
}
.crisis__title {
  font-weight: 700;
  margin-bottom: 8px;
}
.crisis__lines {
  margin: 0 0 12px;
  padding-left: 18px;
}
.crisis__lines li {
  margin: 6px 0;
}
.crisis__close {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 14px;
  cursor: pointer;
}

/* Standing disclaimer — a small, muted, always-visible footer. Replaces the
   per-response disclaimer (which trained banner-blindness). flex:0 0 auto so it
   never scrolls away; it's part of the fixed chrome below the chat. */
.widget__disclaimer {
  flex: 0 0 auto;
  margin: 0;
  padding: 6px 18px calc(6px + env(safe-area-inset-bottom));
  font-size: 11px;
  line-height: 1.35;
  color: var(--muted);
  text-align: center;
  border-top: 1px solid var(--line);
  background: var(--panel);
}
.widget__disclaimer[hidden] {
  display: none;
}

/* The concise line stays visible; Protocol §8's full seven statements sit behind
   it. The default disclosure triangle is dropped because the line is centred and
   a marker pulls it off-axis — the underline on hover/focus carries the affordance
   instead, and the element stays keyboard-operable either way. */
.widget__disclaimer > summary {
  list-style: none;
  cursor: pointer;
}
.widget__disclaimer > summary::-webkit-details-marker {
  display: none;
}
.widget__disclaimer > summary:hover,
.widget__disclaimer > summary:focus-visible {
  color: var(--fg, inherit);
  text-decoration: underline;
}
.widget__disclaimer > ul {
  margin: 8px auto 0;
  padding: 0;
  max-width: 46ch;
  list-style: none;
  text-align: left;
  /* The widget lives in a fixed-height iframe, and seven statements are taller
     than a short mobile embed. Bounded and scrollable, so opening the notice
     can never push the mic control out of reach. */
  max-height: 34vh;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.widget__disclaimer > ul > li {
  margin: 0 0 4px;
  padding-left: 12px;
  text-indent: -12px;
}
.widget__disclaimer > ul > li::before {
  content: "• ";
}

.widget__controls {
  flex: 0 0 auto; /* never shrink or get clipped — the mic/SOS must always show */
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 14px 18px calc(14px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: var(--panel); /* opaque, so the crisis overlay can't bleed under it */
}
.btn {
  border: none;
  border-radius: var(--btn-radius);
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  min-height: var(--btn-height);
  padding: 0 18px;
  display: inline-flex;
  align-items: center;
  gap: 10px;
}
.btn--mic {
  flex: 1;
  background: var(--accent);
  color: #fff;
}
.btn--mic[aria-pressed="true"] {
  background: var(--live);
  color: #052;
}
.btn--mic[aria-pressed="true"] .btn__dot {
  animation: pulse 1.1s infinite;
}
.btn__dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.85;
}
/* Push-to-talk. Big, because a thumb has to land on it mid-sentence; no text
   selection, no long-press menu, no scroll steal — the browser gets none of the
   gestures a held button would otherwise trigger. While the mic is open it turns
   the "live" colour and the meter fills from the left with the mic level. */
.btn--talk {
  flex: 2;
  position: relative;
  overflow: hidden;
  min-height: calc(var(--btn-height) + 8px);
  background: var(--accent);
  color: #fff;
  justify-content: center;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
.btn--talk[hidden] {
  display: none;
}
/* Until the assistant has joined (widget.js, talk.setReady): visibly not yet. */
.btn--talk:disabled {
  opacity: 0.55;
  cursor: progress;
}
.btn--talk[data-pressed="true"] {
  background: var(--live);
  color: #052;
}
.btn--talk[data-pressed="true"] .btn__dot {
  animation: pulse 1.1s infinite;
}
.btn--talk .btn__dot,
.btn--talk #talkLabel {
  position: relative; /* above the meter */
}
.btn__meter {
  position: absolute;
  inset: 0;
  transform-origin: left center;
  transform: scaleX(0);
  background: rgba(255, 255, 255, 0.28);
  transition: transform 60ms linear;
  pointer-events: none;
}
.btn--talk:focus-visible {
  outline: 3px solid var(--live);
  outline-offset: 2px;
}
/* During a push-to-talk call: the talk button and a red End share the top
   row (talk takes the width, End stays compact), and Crisis Support, where a
   tenant has it, gets the full row underneath — so the two red buttons never
   sit side by side and the talk button is never squeezed to a third of a row. */
.widget__controls[data-talk="push"] {
  flex-wrap: wrap;
}
.widget__controls[data-talk="push"] .btn--talk {
  flex: 1 1 auto;
}
.widget__controls[data-talk="push"] .btn--mic[aria-pressed="true"] {
  flex: 0 0 auto;
  min-height: calc(var(--btn-height) + 8px);
  background: var(--sos);
  color: var(--sos-ink);
}
.widget__controls[data-talk="push"] .btn--mic[aria-pressed="true"] .btn__dot {
  display: none;
}
.widget__controls[data-talk="push"] .btn--sos {
  flex: 1 0 100%;
  justify-content: center;
}
/* Stop — only visible while the assistant is speaking. Deliberately quieter than
   the mic and crisis buttons: it's a convenience, not something to draw the eye
   away from them. `hidden` is set/cleared by widget.js, hence the display rule
   below (a flex container would otherwise override the attribute). */
.btn--stop {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line);
  font-weight: 600;
}
.btn--stop:hover {
  border-color: var(--ink);
}
.btn--stop[hidden] {
  display: none;
}
.btn--sos {
  background: var(--sos);
  color: var(--sos-ink);
}
.lang {
  min-height: var(--btn-height);
  border-radius: var(--btn-radius);
  background: #21303f;
  color: var(--ink);
  border: 1px solid var(--line);
  padding: 0 10px;
}

/* Short viewports — a short embed, or ANY embed at high browser zoom, because
   zoom shrinks the viewport in CSS pixels (CMHA #452: at higher zoom the talk
   button sat below the bottom edge). The column is fixed-height with
   overflow:hidden, so every pixel of chrome above the controls is a pixel the
   controls can lose. The chat body already gives way (min-height: 0); the
   rating row and the issue reporter now give way too instead of holding their
   full height, and below 560px the chrome tightens so the buttons stay on
   screen. The controls themselves never shrink. */
.rate,
.report {
  flex-shrink: 1;
  min-height: 0;
  overflow-y: auto;
}
@media (max-height: 560px) {
  :root {
    --btn-height: 46px;
  }
  .widget__head {
    padding: 8px 14px;
  }
  .widget__body {
    padding: 10px 14px;
  }
  .resources {
    max-height: 20vh;
    padding: 6px 14px 8px;
  }
  .rate {
    margin-bottom: 4px;
  }
  .report {
    margin-bottom: 6px;
    padding-top: 6px;
  }
  .widget__state {
    min-height: 26px;
    padding: 3px 14px;
  }
  .widget__controls {
    gap: 8px;
    padding: 8px 14px calc(8px + env(safe-area-inset-bottom));
  }
  /* One row instead of two. Crisis Support moves to the front so the two red
     buttons (it and End) still never sit side by side. */
  .widget__controls[data-talk="push"] {
    flex-wrap: nowrap;
  }
  .widget__controls[data-talk="push"] .btn--sos {
    flex: 0 0 auto;
    order: -1;
    padding: 0 12px;
  }
  .widget__disclaimer > summary {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
}
/* Short AND narrow (a phone at high zoom): one row would crush the talk button,
   so Crisis Support keeps its own row — the buttons are smaller instead. */
@media (max-height: 560px) and (max-width: 400px) {
  .widget__controls[data-talk="push"] {
    flex-wrap: wrap;
  }
  .widget__controls[data-talk="push"] .btn--sos {
    flex: 1 0 100%;
    order: 0;
    min-height: 40px;
  }
}

@keyframes pulse {
  0%,
  100% {
    opacity: 0.3;
    transform: scale(0.85);
  }
  50% {
    opacity: 1;
    transform: scale(1.15);
  }
}
