/* Remote modal v2 (GoodQA #55, Tisha Becker's 2026-09-29 spec) + the device row.
 *
 * Self-contained: every rule is scoped under `.rm-*`, nothing here restyles the
 * legacy device menu (#deviceMenuOverlay) or any shared class. Loaded on every
 * page load but INERT while the flag is off (js/remote-modal.js
 * REMOTE_MODAL_V2 = false): no element carries these classes until the flag is on.
 *
 * DEVIATIONS FROM THE SPEC, each on purpose (recorded again in
 * plans/LANE-remote-modal-u1-u2-20260929.md):
 *   D1  Close button 44x44 (spec: 36). The spec's own section 8 demands 44px targets.
 *   D2  Green TEXT is #1F7A46 (5.34:1 on white), not #3FA66C (3.05:1). #3FA66C is
 *       kept only where it is decoration (nothing uses it now).
 *   D3  Gray TEXT is #5B6472 (5.98:1), not #8A93A3 (3.1:1). The "›" chevron is
 *       decorative but uses #5B6472 too so one grey exists.
 *   D4  Website-tile icon stroke is #1F7A46 on #E3F5EA (spec #3FA66C, 2.69:1 < 3:1).
 *   D5  Chips, rotation pills, More options, Open buttons are 44px tall (the
 *       prototype's padding gives ~33-40px).
 *   D6  Text never below 13.5px.
 *   D7  Field/chip/option/pill EDGES are #6B7485 (4.7:1 on white), not the prototype's
 *       ~16% ink (about 1.4:1): a control's boundary needs 3:1 (WCAG 1.4.11).
 *       Tile edges stay the spec's light 1px: the tile's icon+label identify it.
 *   D8  Lock/Add-time icon strokes are #5A48C0 / #A8630A (spec #6D5BD0 / #C2760A) so
 *       each clears 3:1 on its own tint. The tints and every other icon colour are the spec's.
 * Every text/background pair below is MEASURED in a real browser by
 * platform/test/remote-modal-a11y-ui.test.js ("CONTRAST measured").
 */

.rm-backdrop {
  --rm-ink: #16233F;
  --rm-gray: #5B6472;
  --rm-green: #1F7A46;
  --rm-red: #C0342C;
  --rm-red-tint: #FCE4E4;
  --rm-red-ink: #8E2620;
  --rm-amber-ink: #7A4A06;
  --rm-amber-tint: #FDF1DF;
  --rm-seg: #F1F3F6;
  --rm-sub: #F7F9FB;
  --rm-line: rgba(22, 35, 63, 0.12);
  --rm-focus: #1B4A73;
  --rm-edge: #6B7485;
  --rm-font: 'Nunito', system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --rm-font-display: 'Quicksand', var(--rm-font);
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  box-sizing: border-box;
  background: rgba(22, 35, 63, 0.5);
  font-family: var(--rm-font);
}

html.rm-lock, html.rm-lock body { overflow: hidden; }

.rm-panel {
  position: relative;
  box-sizing: border-box;
  width: 100%;
  max-width: 440px;
  max-height: 88vh;
  max-height: 88dvh;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 26px;
  border-radius: 26px;
  background: #fff;
  color: var(--rm-ink);
  box-shadow: 0 24px 60px rgba(22, 35, 63, 0.25);
  font-size: 14px;
  line-height: 1.4;
}
.rm-panel:focus { outline: none; }
.rm-panel *, .rm-panel *::before, .rm-panel *::after { box-sizing: border-box; }

/* <480px: a full-width bottom sheet. */
@media (max-width: 479.98px) {
  .rm-backdrop { align-items: flex-end; padding: 0; }
  .rm-panel {
    max-width: none;
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
    padding-bottom: calc(26px + env(safe-area-inset-bottom, 0px));
  }
}

@media (prefers-reduced-motion: no-preference) {
  .rm-panel { animation: rm-rise 160ms ease-out; }
  @keyframes rm-rise { from { transform: translateY(12px); opacity: 0; } to { transform: none; opacity: 1; } }
}

.rm-sr {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* Form controls take the panel's font -- UNLESS their own rule names one.
   GoodQA #114 (demo lane design note): this used to be `.rm-panel button`
   (specificity 0,1,1), which outranked every control's own `font:` (0,1,0), so
   tabs, tiles, options, pills and buttons all rendered in the BODY face (Nunito)
   although each asks for --rm-font-display. Tisha's spec: Quicksand for
   headings, buttons and labels (app.css @font-face loads it). `:where()` drops
   the element part, so this rule (0,1,0) still beats a page-wide `button {}`
   rule but loses, by coming first, to each control's own font below. */
.rm-panel :where(button, select, input) { font-family: inherit; }
.rm-panel button { cursor: pointer; }
.rm-panel [aria-disabled="true"] { cursor: not-allowed; }

/* A real outline, never a box-shadow: forced-colors erases shadows. */
.rm-panel :focus-visible,
.rm-row-pill:focus-visible,
.rm-controls-link:focus-visible {
  outline: 3px solid var(--rm-focus);
  outline-offset: 2px;
}

/* ------------------------------------------------------------------ header */
.rm-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 6px; }
.rm-title {
  margin: 0; min-width: 0; overflow-wrap: anywhere;
  font: 800 18px/1.25 var(--rm-font-display); color: var(--rm-ink);
}
.rm-title:focus { outline: none; }
.rm-close {
  flex: none; width: 44px; height: 44px; padding: 0; border: 0; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--rm-seg); color: var(--rm-gray);
}
.rm-close svg { width: 18px; height: 18px; }

/* ------------------------------------------------------- segmented control */
.rm-seg {
  display: flex; gap: 0; padding: 4px; border-radius: 999px; background: var(--rm-seg);
}
.rm-tabs { margin: 10px 0 16px; }
.rm-seg-btn {
  flex: 1 1 0; min-width: 0; min-height: 44px; padding: 6px 10px;
  border: 2px solid transparent; border-radius: 999px; background: transparent;
  color: var(--rm-gray); font: 700 14px/1.2 var(--rm-font-display);
}
.rm-seg-btn[aria-selected="true"],
.rm-seg-btn[aria-checked="true"] {
  background: #fff; color: var(--rm-ink); box-shadow: 0 1px 4px rgba(22, 35, 63, 0.15);
}
.rm-seg-btn[aria-disabled="true"] { opacity: 1; color: var(--rm-gray); text-decoration: line-through; text-decoration-color: transparent; }

/* ------------------------------------------------------------------ status */
.rm-status { margin: 0 0 16px; font-size: 14.5px; color: var(--rm-gray); overflow-wrap: anywhere; }
.rm-status .rm-status-note { display: block; margin-top: 2px; }

/* ------------------------------------------------------------------- tiles */
.rm-grid {
  display: grid; gap: 10px; margin-bottom: 14px;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
}
@media (min-width: 360px) { .rm-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.rm-tile {
  display: flex; flex-direction: column; align-items: center; justify-content: flex-start; gap: 8px;
  min-width: 0; min-height: 44px; padding: 17px 8px;
  border: 1px solid var(--rm-line); border-radius: 18px; background: #fff; color: var(--rm-ink);
  font: 700 14px/1.25 var(--rm-font-display); text-align: center; overflow-wrap: anywhere; hyphens: auto;
}
.rm-tile-icon {
  width: 44px; height: 44px; border-radius: 50%; flex: none;
  display: flex; align-items: center; justify-content: center;
}
.rm-tile-icon svg { width: 20px; height: 20px; }
.rm-tile-sub { display: block; font: 700 13.5px/1.25 var(--rm-font); color: var(--rm-gray); }
.rm-tile[aria-busy="true"] .rm-tile-sub { color: var(--rm-amber-ink); }
/* Active = 2px border + tint. Padding gives the extra px back so nothing shifts. */
.rm-tile.is-active { border-width: 2px; padding: 16px 7px; }
.rm-tile.is-active.is-danger { border-color: var(--rm-red); background: var(--rm-red-tint); }
.rm-tile[aria-expanded="true"] { border-color: var(--rm-focus); }
.rm-tile[aria-disabled="true"] { color: var(--rm-gray); }

.rm-ic-lock   { background: #ECE8FB; color: #5A48C0; }
.rm-ic-time   { background: var(--rm-amber-tint); color: #A8630A; }
.rm-ic-touch  { background: var(--rm-red-tint); color: var(--rm-red); }
.rm-ic-app    { background: #E8F1FA; color: #2B6CB0; }
.rm-ic-web    { background: #E3F5EA; color: #1F7A46; }
.rm-ic-volume { background: #EEF1F4; color: #5B6472; }

.rm-notice {
  margin: 0 0 14px; padding: 12px 14px; border-radius: 14px;
  background: var(--rm-red-tint); color: var(--rm-red-ink); font-size: 13.5px; line-height: 1.45;
}
.rm-notice.is-warn { background: var(--rm-amber-tint); color: var(--rm-amber-ink); }

/* ------------------------------------------------------------------ panels */
.rm-sub-panel { margin: 0 0 14px; padding: 16px; border-radius: 16px; background: var(--rm-sub); }
.rm-sub-panel[hidden] { display: none; }
.rm-sub-title { margin: 0 0 10px; font: 800 14.5px/1.3 var(--rm-font-display); color: var(--rm-ink); }
.rm-row-inline { display: flex; gap: 8px; align-items: stretch; flex-wrap: wrap; }
.rm-row-inline > .rm-field { flex: 1 1 140px; min-width: 0; }
.rm-field {
  min-height: 44px; padding: 10px 13px; border: 1px solid var(--rm-edge); border-radius: 11px;
  background: #fff; color: var(--rm-ink); font-size: 14px;
}
.rm-field::placeholder { color: var(--rm-gray); opacity: 1; }
.rm-field-error { margin: 8px 0 0; color: var(--rm-red-ink); font-size: 13.5px; }
.rm-field-error[hidden] { display: none; }
.rm-btn {
  flex: none; min-height: 44px; padding: 0 20px; border: 0; border-radius: 11px;
  background: linear-gradient(135deg, #1B4A73 0%, #2C6F9E 100%); color: #fff;
  font: 700 14px/1 var(--rm-font-display);
}
.rm-btn[aria-disabled="true"] { background: #5B6472; }
.rm-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.rm-chip {
  flex: 1 1 80px; min-height: 44px; padding: 0 12px; border-radius: 11px;
  border: 1px solid var(--rm-edge); background: #fff; color: var(--rm-ink);
  font: 700 14px/1.2 var(--rm-font-display);
}
.rm-chip[aria-disabled="true"] { color: var(--rm-gray); }
.rm-chip[aria-busy="true"] { border-style: dashed; }
.rm-hint { margin: 8px 0 0; font-size: 13.5px; color: var(--rm-gray); }

.rm-options { display: flex; flex-direction: column; gap: 8px; }
.rm-option {
  min-height: 44px; padding: 10px 14px; border-radius: 11px; text-align: left;
  display: flex; align-items: center; gap: 10px;
  border: 1px solid var(--rm-edge); background: #fff; color: var(--rm-ink);
  font: 700 14px/1.25 var(--rm-font-display);
  /* "Let {child} adjust volume" carries a child's name: a long one wraps
     inside the option instead of pushing it past the sheet at 320px. */
  min-width: 0; overflow-wrap: anywhere;
}
.rm-option::before {
  content: ''; flex: none; width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--rm-gray); background: #fff;
}
.rm-option[aria-checked="true"] { border-width: 2px; border-color: var(--rm-focus); background: #E8F1FA; padding: 9px 13px; }
.rm-option[aria-checked="true"]::before { border-color: var(--rm-focus); background: var(--rm-focus); box-shadow: inset 0 0 0 3px #fff; }
.rm-option[aria-busy="true"] { border-style: dashed; }

/* --------------------------------------------------- volume level slider */
/* GoodQA #115 (Tisha 2026-09-30): a percent slider under the three volume
   options. role="slider" on a div (js/remote-modal.js buildVolSlider). The
   44px-tall element IS the hit area; the 28px thumb is drawn inside it. The
   rail is inset by half a thumb so the thumb stays inside the panel at 0 and at
   100 (no sideways scroll at 320px). Colour keeps the product's meanings: the
   parent's own adjustment and a device-confirmed level are brand blue, a level
   on its way to the device is amber (waiting), the confirmed sentence is green.
   No level reported = no thumb, no fill: nothing is drawn that the device did
   not say. */
.rm-vol-level { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--rm-line); }
.rm-vol-head { display: flex; align-items: baseline; justify-content: space-between; flex-wrap: wrap; gap: 4px 12px; }
.rm-vol-label { font: 800 14px/1.3 var(--rm-font-display); color: var(--rm-ink); }
.rm-vol-value { font: 800 15px/1.3 var(--rm-font-display); color: var(--rm-ink); font-variant-numeric: tabular-nums; }
.rm-vol-slider {
  position: relative; height: 44px; margin-top: 2px; border-radius: 12px;
  cursor: pointer; touch-action: pan-y; -webkit-user-select: none; user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.rm-vol-rail {
  position: absolute; left: 14px; right: 14px; top: 50%; height: 6px; margin-top: -3px;
  border-radius: 999px; background: var(--rm-edge);
}
.rm-vol-fill { position: absolute; left: 0; top: 0; bottom: 0; width: 0; border-radius: inherit; background: var(--rm-focus); }
.rm-vol-thumb {
  position: absolute; top: 50%; left: 0; width: 28px; height: 28px; margin: -14px 0 0 -14px;
  border-radius: 50%; background: var(--rm-focus); border: 3px solid #fff;
  box-shadow: 0 0 0 1px var(--rm-focus), 0 1px 4px rgba(22, 35, 63, 0.3);
}
.rm-vol-slider.is-unset .rm-vol-thumb { display: none; }
.rm-vol-slider.is-requested .rm-vol-fill,
.rm-vol-slider.is-requested .rm-vol-thumb { background: #A8630A; }
.rm-vol-slider.is-requested .rm-vol-thumb { box-shadow: 0 0 0 1px #A8630A, 0 1px 4px rgba(22, 35, 63, 0.3); }
.rm-vol-status { margin: 4px 0 0; font-size: 13.5px; line-height: 1.4; color: var(--rm-gray); overflow-wrap: anywhere; }
.rm-vol-status[data-rm-vol-state="held"] { color: var(--rm-green); }
.rm-vol-status[data-rm-vol-state="requested"],
.rm-vol-status[data-rm-vol-state="busy"] { color: var(--rm-amber-ink); }
/* Motion only when it is welcome, and never under the parent's finger. */
@media (prefers-reduced-motion: no-preference) {
  .rm-vol-fill { transition: width 140ms ease-out; }
  .rm-vol-thumb { transition: left 140ms ease-out; }
  .rm-vol-slider.is-adjusting .rm-vol-fill,
  .rm-vol-slider.is-adjusting .rm-vol-thumb { transition: none; }
}

.rm-modeblock { margin: 0 0 8px; }
.rm-mode-note { margin: 8px 4px 0; font-size: 13.5px; color: var(--rm-gray); }
.rm-mode-note[hidden] { display: none; }

.rm-more {
  display: flex; align-items: center; justify-content: center; gap: 6px; width: 100%; min-height: 44px;
  margin-top: 10px; padding: 10px; border: 0; background: none; color: var(--rm-gray);
  font: 700 14.5px/1.2 var(--rm-font-display);
}
.rm-more-body { margin-top: 6px; }
.rm-more-body[hidden] { display: none; }
.rm-more-sec { padding: 14px 4px; border-bottom: 1px solid var(--rm-line); }
.rm-more-sec > .rm-sub-title { font-size: 14px; }
.rm-pills { display: flex; flex-wrap: wrap; gap: 6px; }
.rm-pill {
  min-height: 44px; padding: 0 14px; border-radius: 999px;
  border: 1px solid var(--rm-edge); background: #fff; color: var(--rm-ink);
  font: 700 14px/1.2 var(--rm-font-display);
}
.rm-pill[aria-checked="true"] { border-width: 2px; border-color: var(--rm-focus); background: #E8F1FA; padding: 0 13px; }
.rm-pill[aria-busy="true"] { border-style: dashed; }
.rm-linkrow {
  display: flex; align-items: center; justify-content: space-between; width: 100%; min-height: 44px;
  padding: 10px 4px; border: 0; background: none; color: var(--rm-ink); text-align: left;
  font: 700 14px/1.2 var(--rm-font-display);
}
.rm-linkrow .rm-chev { color: var(--rm-gray); }

/* -------------------------------------------------------------------- live */
.rm-live { margin: 0; padding: 0; }
.rm-live-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 0; border-bottom: 1px solid var(--rm-line);
}
.rm-live-row:last-of-type { border-bottom: 0; }
.rm-live-row dt { margin: 0; font-size: 14px; color: var(--rm-gray); }
.rm-live-row dd { margin: 0; text-align: right; font: 700 14.5px/1.3 var(--rm-font-display); color: var(--rm-ink); overflow-wrap: anywhere; }
.rm-live-row dd.is-fresh { color: var(--rm-green); }
.rm-capture { margin-top: 14px; }
.rm-capture-btn {
  display: flex; align-items: center; justify-content: center; gap: 9px; width: 100%; min-height: 48px; padding: 0 14px;
  border: 0; border-radius: 999px; background: var(--rm-ink); color: #fff;
  font: 700 14.5px/1.2 var(--rm-font-display);
}
.rm-capture-btn svg { width: 18px; height: 18px; flex: none; }
.rm-capture-btn[aria-disabled="true"] { background: #5B6472; }
.rm-capture-btn.is-secondary { background: #fff; color: var(--rm-ink); border: 1px solid var(--rm-edge); margin-top: 10px; }
.rm-shot { margin: 0; }
.rm-shot img { display: block; width: 100%; aspect-ratio: 16 / 10; object-fit: cover; border-radius: 16px; background: #EEF1F4; }
.rm-shot figcaption { margin-top: 6px; font-size: 13.5px; color: var(--rm-gray); }

/* ------------------------------------------------------- alerts and toasts */
.rm-alerts { display: flex; flex-direction: column; gap: 8px; margin: 0 0 14px; }
.rm-alerts:empty { display: none; }
.rm-alert {
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 8px;
  padding: 10px 14px; border-radius: 14px; background: var(--rm-amber-tint); color: var(--rm-amber-ink); font-size: 13.5px;
}
.rm-alert.is-failed { background: var(--rm-red-tint); color: var(--rm-red-ink); }
.rm-alert button {
  min-height: 44px; padding: 0 16px; border-radius: 999px; border: 1px solid currentColor;
  background: #fff; color: var(--rm-ink); font: 700 14px/1 var(--rm-font-display);
}
.rm-toast {
  position: sticky; bottom: 0; margin-top: 12px; padding: 10px 14px; border-radius: 12px;
  background: var(--rm-ink); color: #fff; font-size: 13.5px; text-align: center;
  /* A snackbar sits over the bottom of the scroll area for ~4.5s: it must never eat a tap meant for the control under it. */
  pointer-events: none;
}
.rm-toast:empty { display: none; }

/* -------------------------------------------------------------- device row */
/* Used on the Devices page, Home kid cards and Child Controls. Wraps on narrow
   screens; the identity block has a floor so the status text never slides
   under the pill. #devices twin beats that page's own `.device-quick-row` rule. */
.rm-row, #devices .device-quick-row.rm-row {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-start; gap: 12px;
  width: 100%; min-width: 0; min-height: 0; padding: 12px 0; box-sizing: border-box;
  border-top: 1px solid rgba(22, 35, 63, 0.12);
}
#devices .device-quick-row.rm-row { padding: 12px 16px; }
#devices .device-quick-row.rm-row:first-child { border-top: 0; } /* the list's own border is the divider */
.rm-row-id { flex: 1 1 140px; min-width: 140px; }
.rm-row-name { font: 700 15px/1.3 var(--rm-font-display, 'Quicksand', sans-serif); color: #16233F; overflow-wrap: anywhere; }
.rm-row-status { font-size: 13.5px; font-weight: 700; line-height: 1.3; color: #5B6472; overflow-wrap: anywhere; }
.rm-row-status.is-online { color: #1F7A46; }
.rm-row-pill {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; flex: none;
  min-height: 44px; min-width: 44px; padding: 0 18px; border: 0; border-radius: 999px;
  background: #16233F; color: #fff; white-space: nowrap; cursor: pointer;
  font: 700 14px/1 'Quicksand', 'Nunito', system-ui, sans-serif;
}
.rm-row-pill svg { width: 15px; height: 15px; flex: none; }
.rm-controls-link {
  display: inline-flex; align-items: center; min-height: 44px; margin-top: 4px; padding: 0 2px;
  border: 0; background: none; color: #1B4A73; cursor: pointer;
  font: 700 14px/1.2 'Quicksand', 'Nunito', system-ui, sans-serif;
}
.rm-controls-link:hover { text-decoration: underline; }
.rm-linked { margin: 0; }
.rm-linked-title { margin: 0 0 4px; font: 800 16px/1.3 'Quicksand', 'Nunito', system-ui, sans-serif; color: #16233F; }

/* ----------------------------------------------------------- forced colours */
@media (forced-colors: active) {
  .rm-backdrop { background: Canvas; }
  .rm-panel { border: 2px solid CanvasText; background: Canvas; color: CanvasText; }
  .rm-panel button, .rm-panel select, .rm-panel input { border: 2px solid ButtonText; background: ButtonFace; color: ButtonText; forced-color-adjust: auto; }
  .rm-panel :focus-visible, .rm-row-pill:focus-visible, .rm-controls-link:focus-visible { outline: 3px solid Highlight; outline-offset: 2px; }
  .rm-tile.is-active { border: 4px solid Highlight; padding: 14px 5px; }
  .rm-seg-btn[aria-selected="true"], .rm-seg-btn[aria-checked="true"],
  .rm-option[aria-checked="true"], .rm-pill[aria-checked="true"] { border: 4px solid Highlight; }
  .rm-tile[aria-expanded="true"] { border-color: Highlight; border-width: 4px; }
  .rm-option[aria-checked="true"]::before { background: Highlight; border-color: Highlight; }
  .rm-seg-btn[aria-disabled="true"], .rm-tile[aria-disabled="true"], .rm-btn[aria-disabled="true"], .rm-chip[aria-disabled="true"],
  .rm-capture-btn[aria-disabled="true"] { border-style: dashed; color: GrayText; }
  .rm-tile-icon { background: Canvas; border: 1px solid CanvasText; color: CanvasText; }
  .rm-notice, .rm-alert, .rm-toast, .rm-sub-panel { border: 1px solid CanvasText; background: Canvas; color: CanvasText; }
  .rm-row-pill { border: 2px solid ButtonText; background: ButtonFace; color: ButtonText; }
  /* The slider is drawn with backgrounds, which forced colours would erase:
     system colours, kept on purpose. A level on its way gets a dashed thumb. */
  .rm-vol-rail { background: CanvasText; forced-color-adjust: none; }
  .rm-vol-fill { background: Highlight; forced-color-adjust: none; }
  .rm-vol-thumb { background: Highlight; border: 3px solid Canvas; box-shadow: none; outline: 2px solid CanvasText; forced-color-adjust: none; }
  .rm-vol-slider.is-requested .rm-vol-fill, .rm-vol-slider.is-requested .rm-vol-thumb { background: Highlight; }
  .rm-vol-slider.is-requested .rm-vol-thumb { outline-style: dashed; }
}
