/* css/switcher.css — owned by the **switcher** agent (CONTRACTS.md §2).
   Island switcher (desktop pill), phone chip rail, hover/focus preview card,
   first-visit locate dialog, toast. REDESIGN-SPEC §3.2, §4.1, §6.

   Tokens only. The redesign tokens (--frame, --tile, --tile-2, --tile-track,
   --font-display) are written with a fallback to the older token they alias
   (spec §2.2), so this sheet renders correctly whether or not app.css has
   them yet — never with a literal colour. */

/* ---- placement of our own mounts (by id — CONTRACTS §6 rule 4) ---------- */

#island-switcher { position: relative; min-width: 0; }

@media (max-width: 767.98px) {
  #island-switcher { display: none; }

  /* Sticky under the (static, on phone) header, spec §4.1. The 8 px fade lets
     tiles scroll "under" the rail instead of being guillotined at its edge. */
  #island-rail {
    position: sticky;
    top: 0;
    z-index: 40;
    padding-top: env(safe-area-inset-top, 0px);
    background: var(--frame, var(--bg));
  }
  #island-rail::after {
    content: "";
    position: absolute;
    left: 0; right: 0; top: 100%;
    height: 8px;
    background: linear-gradient(var(--frame, var(--bg)), transparent);
    pointer-events: none;
  }
}
@media (min-width: 768px) {
  #island-rail { display: none; }
}

/* ---- shared option look ------------------------------------------------- */

.hw-switcher__opt,
.hw-rail__opt {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  flex: none;
  margin: 0;
  border: 0;
  border-radius: var(--r-pill);
  font-family: var(--font-display, var(--font-ui));
  font-size: 0.8125rem;           /* 13 */
  font-weight: 700;
  line-height: 1.2;
  white-space: nowrap;
  color: var(--text-dim);
  background: transparent;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.hw-switcher__opt[aria-checked="true"],
.hw-rail__opt[aria-checked="true"] {
  background: var(--text);
  color: var(--tile, var(--surface));
  font-weight: 800;
}
.hw-switcher__glyph,
.hw-rail__glyph { font-size: 0.75em; line-height: 1; }
/* Names never wrap or truncate: "Big Island" split over two lines reads as two tabs. */
.hw-switcher__name,
.hw-rail__name { white-space: nowrap; }

/* Calm (alerts answered, nothing posted anywhere): ○ in --text-faint, no colour.
   Unknown (◌) is faint by definition. */
.hw-switcher--calm .hw-glyph,
.hw-rail--calm .hw-glyph,
.hw-locate__islands--calm .hw-glyph,
.hw-preview__glyph--calm,
.hw-switcher .hw-glyph--unknown,
.hw-rail .hw-glyph--unknown,
.hw-locate .hw-glyph--unknown { color: var(--text-faint); }

/* On the inverted (--text) selected pill the level hue has to flip lightness:
   the dark theme's bright red is ~2.6:1 on near-white, the light theme's deep
   red ~2.4:1 on near-black. Mixing the SAME token toward --tile moves it away
   from --text in both themes at once (≥ 3.6:1 non-text contrast in each,
   measured), so one rule serves both and no theme-specific hex appears. */
.hw-switcher__opt[aria-checked="true"] .hw-glyph--extreme,
.hw-rail__opt[aria-checked="true"] .hw-glyph--extreme { color: color-mix(in srgb, var(--sev-extreme) 55%, var(--tile, var(--surface))); }
.hw-switcher__opt[aria-checked="true"] .hw-glyph--severe,
.hw-rail__opt[aria-checked="true"] .hw-glyph--severe { color: color-mix(in srgb, var(--sev-severe) 55%, var(--tile, var(--surface))); }
.hw-switcher__opt[aria-checked="true"] .hw-glyph--moderate,
.hw-rail__opt[aria-checked="true"] .hw-glyph--moderate { color: color-mix(in srgb, var(--sev-moderate) 55%, var(--tile, var(--surface))); }
.hw-switcher__opt[aria-checked="true"] .hw-glyph--none,
.hw-rail__opt[aria-checked="true"] .hw-glyph--none { color: color-mix(in srgb, var(--ok) 55%, var(--tile, var(--surface))); }
.hw-switcher--calm .hw-switcher__opt[aria-checked="true"] .hw-glyph,
.hw-rail--calm .hw-rail__opt[aria-checked="true"] .hw-glyph,
.hw-switcher__opt[aria-checked="true"] .hw-glyph--unknown,
.hw-rail__opt[aria-checked="true"] .hw-glyph--unknown {
  color: color-mix(in srgb, var(--text-faint) 55%, var(--tile, var(--surface)));
}

/* ---- desktop pill (5a / 5b) --------------------------------------------- */

.hw-switcher {
  display: flex;
  gap: 4px;
  padding: 4px;
  max-width: 100%;
  width: max-content;
  border-radius: var(--r-pill);
  background: var(--tile-2, var(--surface-2));
  /* Six islands fit from 768 up (the header wraps below 1100); this is a
     floor for a narrow window with a large default font, not the layout. */
  overflow-x: auto;
  scrollbar-width: none;
}
.hw-switcher::-webkit-scrollbar { display: none; }
.hw-switcher__opt {
  min-height: 34px;
  padding: 0 14px;
}
/* The pill IS --tile-2 (spec §2.4 segmented pill), so the spec's --tile-2
   hover would be invisible on it; one step deeper is. */
.hw-switcher__opt[aria-checked="false"]:hover {
  background: var(--tile-track, var(--surface-3));
  color: var(--text);
}
/* Inside a 4 px-padded scroller a 2 px offset ring is clipped; draw it inside. */
.hw-switcher__opt:focus-visible,
.hw-rail__opt:focus-visible { outline-offset: -2px; border-radius: var(--r-pill); }
.hw-switcher__opt[aria-checked="true"]:focus-visible,
.hw-rail__opt[aria-checked="true"]:focus-visible {
  outline-color: var(--accent);
  box-shadow: inset 0 0 0 4px var(--text);
}

/* Compact pill, 768–1279 px. At full size (~540 px) the pill wrapped the
   Full-data header onto a third row at 768 and 1024. Tighter padding, and
   a short name for the one long one: the full name is clipped (still read
   by screen readers), and the aria-hidden short name is shown instead. The
   preview card always uses the full name. */
.hw-switcher__short { display: none; }
@media (min-width: 768px) and (max-width: 1279.98px) {
  .hw-switcher { gap: 2px; padding: 3px; }
  .hw-switcher__opt { padding: 0 10px; gap: 5px; }
  .hw-switcher__short { display: inline; white-space: nowrap; }
  .hw-switcher__opt:has(.hw-switcher__short) .hw-switcher__name {
    position: absolute;
    width: 1px; height: 1px;
    margin: -1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }
}

/* ---- preview card (5b "Hover") ------------------------------------------ */

.hw-preview {
  position: absolute;
  z-index: 70;
  width: 230px;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--tile, var(--surface));
  color: var(--text);
  box-shadow: var(--shadow-3);
  border: 1px solid var(--border);
  font-family: var(--font-display, var(--font-ui));
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  /* 160 ms fade in (spec §6); visibility flips after the fade on the way out. */
  transition: opacity var(--dur-2, 160ms) var(--ease-out), visibility 0s linear var(--dur-2, 160ms);
}
.hw-preview--on {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transition: opacity var(--dur-2, 160ms) var(--ease-out), visibility 0s;
}
.hw-preview__title { font-size: 0.75rem; font-weight: 800; line-height: 1.35; }
.hw-preview__meta {
  margin-top: 2px;
  font-size: 0.6875rem;
  font-weight: 600;
  line-height: 1.4;
  color: var(--text-faint);
  font-variant-numeric: tabular-nums;
}

/* ---- phone chip rail (5c) ----------------------------------------------- */

.hw-rail {
  position: relative;          /* offsetLeft of chips, for scroll-into-view */
  display: flex;
  gap: 6px;
  padding: 8px 12px;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scroll-snap-type: x mandatory;
  scroll-padding-inline: 12px;
  scrollbar-width: none;
}
.hw-rail::-webkit-scrollbar { display: none; }
.hw-rail__opt {
  min-height: 40px;
  padding: 0 14px;
  gap: 6px;
  scroll-snap-align: start;
  background: var(--tile, var(--surface));
  box-shadow: var(--shadow-1);
}

@media (pointer: coarse) {
  .hw-switcher__opt,
  .hw-rail__opt { min-height: 44px; }
}

/* ---- first-visit dialog (5d) -------------------------------------------- */

.hw-locate {
  width: min(420px, calc(100% - 32px));
  max-width: none;
  max-height: calc(100dvh - 32px);
  padding: 0;
  border: 0;
  border-radius: 24px;
  background: var(--tile, var(--surface));
  color: var(--text);
  box-shadow: var(--shadow-3);
  font-family: var(--font-display, var(--font-ui));
  overflow: auto;
}
.hw-locate::backdrop {
  background: color-mix(in srgb, var(--overlay-scrim) 70%, transparent);
}
/* Phone: a sheet floating 12 px off the bottom edge (5d), not a centred card. */
@media (max-width: 767.98px) {
  .hw-locate {
    width: calc(100% - 24px);
    margin: auto auto max(12px, env(safe-area-inset-bottom, 0px));
  }
}
.hw-locate__inner {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 20px 18px 16px;
}
.hw-locate__close {
  position: absolute;
  top: 8px; right: 8px;
  width: 36px; height: 36px;
  display: grid; place-items: center;
  border: 0;
  border-radius: var(--r-pill);
  background: transparent;
  color: var(--text-faint);
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
}
.hw-locate__close:hover { background: var(--tile-2, var(--surface-2)); color: var(--text); }
.hw-locate__icon {
  width: 44px; height: 44px;
  display: grid; place-items: center;
  border-radius: 14px;
  background: var(--tile-2, var(--surface-2));
  color: var(--accent);
  font-size: 1.25rem;
}
.hw-locate__title {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 800;
  line-height: 1.2;
  letter-spacing: -0.02em;
}
.hw-locate__body {
  margin: 0;
  font-size: 0.8125rem;
  font-weight: 500;
  line-height: 1.5;
  color: var(--text-dim);
}
/* Geometry and colour both set here: the primary action must never depend on
   another sheet having landed first. Same tokens as hw-btn--secondary (§2.4). */
.hw-locate__use {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 48px;
  padding: 12px 18px;
  border: 0;
  border-radius: 14px;
  background: var(--accent);
  color: var(--text-on-accent);
  font: inherit;
  font-size: 0.9375rem;
  font-weight: 800;
  cursor: pointer;
}
.hw-locate__use[aria-disabled="true"] { cursor: progress; opacity: 0.8; }
.hw-locate__islands {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}
.hw-locate__chip {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  min-height: 44px;
  padding: 6px;
  border: 0;
  border-radius: 12px;
  background: var(--tile-2, var(--surface-2));
  color: var(--text);
  font: inherit;
  font-size: 0.75rem;
  font-weight: 700;
  line-height: 1.2;
  text-align: center;
  cursor: pointer;
}
.hw-locate__chip:hover { background: var(--tile-track, var(--surface-3)); }
.hw-locate__glyph { font-size: 0.8em; line-height: 1; }
.hw-locate__foot {
  margin: 0;
  font-size: 0.6875rem;
  font-weight: 600;
  line-height: 1.4;
  color: var(--text-faint);
  text-align: center;
}

@media (pointer: coarse) {
  .hw-locate__close { width: 44px; height: 44px; top: 4px; right: 4px; }
}

/* ---- toast -------------------------------------------------------------- */

.hw-toast {
  position: fixed;
  left: 50%;
  bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  z-index: 80;
  width: max-content;
  max-width: min(440px, calc(100% - 32px));
  padding: 10px 16px;
  border-radius: 14px;
  background: var(--text);
  color: var(--tile, var(--surface));
  box-shadow: var(--shadow-3);
  font-family: var(--font-display, var(--font-ui));
  font-size: 0.8125rem;
  font-weight: 700;
  line-height: 1.4;
  text-align: center;
  transform: translate(-50%, 8px);
  /* Idle: invisible but still in the accessibility tree, so the live region
     is already "there" when the first message arrives. */
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--dur-2, 160ms) var(--ease-out), transform var(--dur-2, 160ms) var(--ease-out);
}
.hw-toast:empty { padding: 0; box-shadow: none; }
.hw-toast--on { opacity: 1; transform: translate(-50%, 0); }

/* ---- motion gate (same one the rest of the design system uses) ---------- */

html[data-motion="off"] .hw-preview,
html[data-motion="off"] .hw-toast { transition: none; }
@media (prefers-reduced-motion: reduce) {
  .hw-preview, .hw-toast { transition: none; }
  .hw-rail { scroll-behavior: auto; }
}
