:root {
  --bg-canvas: #FAF8F5;
  --bg-card: #FFFFFF;
  --bg-subtle: #F1EDE6;
  --border-hairline: #E2DCD3;
  --brand-primary: #183A4A;
  --brand-primary-soft: #E4EEF2;
  --accent-terracotta: #D95D39;
  --accent-terracotta-soft: #FCECE7;
  --status-safe: #237A57;
  --status-safe-soft: #E3F5EC;
  --status-warning: #C97A10;
  --status-warning-soft: #FEF3C7;
  --status-sos: #C81E1E;
  --status-sos-soft: #FEE2E2;
  --text-primary: #122028;
  --text-secondary: #4E616B;
  --text-hint: #7A8B94;
  /* Darker text shades for small words on the soft tints (readable contrast, 4.5:1 or more) */
  --accent-terracotta-ink: #A8401F;
  --status-warning-ink: #8A5200;
  --status-sos-ink: #C81E1E;
  --accent-terracotta-strong: #B5482A; /* filled terracotta buttons: white words at 5:1 */
  --map-bg: #ECE9E1;
  --topbar-h: 62px;
  --tabbar-h: 68px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

body.dark-theme {
  --bg-canvas: #0F1A20;
  --bg-card: #16252D;
  --bg-subtle: #1F323C;
  --border-hairline: #283F4B;
  --brand-primary: #5BB0D4;
  --brand-primary-soft: #1B3644;
  --accent-terracotta: #EE7752;
  --accent-terracotta-soft: #3B231C;
  --text-primary: #F4F7F8;
  --text-secondary: #A9BCC6;
  --text-hint: #758C98;
  --accent-terracotta-ink: #EE7752;
  --status-warning-ink: #F2B35A;
  --status-sos-ink: #F87171;
  /* Fjord Night status tints (dark), so light words on them stay readable; SOS buttons keep their red */
  --status-safe: #34D399;
  --status-safe-soft: #12352A;
  --status-warning-soft: #3A2C12;
  --status-sos-soft: #3A1C1C;
  --map-bg: #1F323C;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg-canvas);
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, 'Inter', 'Segoe UI', Roboto, sans-serif;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ---- Top bar: one row that never wraps (brand, Haven picker with Invite / Join, Chat, SOS) ---- */
.topbar {
  height: var(--topbar-h);
  flex-shrink: 0;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border-hairline);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px;
  gap: 12px;
  z-index: 20;
  min-width: 0;
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex-shrink: 0;
}
.brand-lockup img { width: 38px; height: 38px; border-radius: 10px; }
.brand-text { min-width: 0; }
.brand-title { font-weight: 800; font-size: 16px; letter-spacing: -0.02em; }
.brand-sub { font-size: 12px; color: var(--text-secondary); }
.topbar .brand-title, .topbar .brand-sub { white-space: nowrap; }

.haven-switcher {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-subtle);
  padding: 4px 4px 4px 14px;
  border-radius: 999px;
  border: 1px solid var(--border-hairline);
  min-width: 0;
  flex: 0 1 auto;
}
.haven-label { font-size: 11px; font-weight: 700; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.04em; }
.haven-switcher select {
  border: none;
  background: transparent;
  color: var(--text-primary);
  font-weight: 700;
  font-size: 14px;
  min-width: 0;
  max-width: 260px;
  text-overflow: ellipsis;
  cursor: pointer;
  padding: 6px 2px;
  border-radius: 8px;
}
.haven-switcher select:disabled { cursor: default; color: var(--text-secondary); }
.haven-switcher select option { color: #122028; background: #FFFFFF; }
.invite-btn { border-radius: 999px; padding: 6px 12px; white-space: nowrap; }
.invite-btn .btn-ico { font-weight: 800; margin-right: 4px; }
.chat-btn { white-space: nowrap; display: inline-flex; align-items: center; gap: 6px; }
.key-pill {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  font-weight: 700;
  background: var(--bg-card);
  color: var(--brand-primary);
  padding: 3px 8px;
  border-radius: 999px;
  border: 1px solid var(--border-hairline);
}

.top-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.sos-btn .sos-ico { margin-right: 4px; }

/* Visible keyboard focus everywhere (mouse clicks do not show it) */
:focus-visible { outline: 3px solid var(--brand-primary); outline-offset: 2px; }
body.dark-theme :focus-visible { outline-color: #F4F7F8; }
.sos-btn:focus-visible { outline-color: var(--text-primary); }

button, .btn {
  border: 1px solid var(--border-hairline);
  background: var(--bg-card);
  color: var(--text-primary);
  padding: 8px 13px;
  border-radius: 10px;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.14s ease;
}
button:hover { border-color: var(--brand-primary); }
button.primary {
  background: var(--brand-primary);
  color: #FFFFFF;
  border-color: var(--brand-primary);
}
button.terracotta {
  background: var(--accent-terracotta-strong);
  color: #FFFFFF;
  border-color: var(--accent-terracotta-strong);
}
button.sos-btn {
  background: var(--status-sos);
  color: #FFFFFF;
  border-color: var(--status-sos);
  font-weight: 800;
  white-space: nowrap;
}
/* Fjord Night: the light blue buttons take dark words so they stay readable */
body.dark-theme button.primary,
body.dark-theme .main-tabs button.active { color: #0F1A20; }

.emergency-banner {
  background: var(--status-sos);
  color: #FFFFFF;
  padding: 10px 18px;
  display: none;
  align-items: center;
  justify-content: space-between;
  font-weight: 700;
  font-size: 14px;
  z-index: 25;
}
.emergency-banner.active { display: flex; }
.emergency-banner { gap: 10px 14px; flex-wrap: wrap; flex-shrink: 0; }
.emergency-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.emergency-link {
  background: #FFFFFF;
  color: #C81E1E;
  padding: 8px 12px;
  border-radius: 8px;
  text-decoration: none;
  font-size: 13px;
}
.emergency-cancel { background: #122028; color: #FFFFFF; border: 0; }
.emergency-link:focus-visible, .emergency-cancel:focus-visible { outline-color: #FFFFFF; }

.workspace {
  flex: 1;
  display: grid;
  grid-template-columns: 420px 1fr;
  min-height: 0;
}

.left-pane {
  background: var(--bg-canvas);
  border-right: 1px solid var(--border-hairline);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.main-tabs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  padding: 10px 12px 6px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border-hairline);
}
.main-tabs button {
  padding: 8px 6px;
  font-size: 12px;
  border-radius: 9px;
  background: var(--bg-subtle);
  border-color: transparent;
}
.main-tabs button.active {
  background: var(--brand-primary);
  color: #FFFFFF;
}

.sub-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  padding: 10px 12px 4px;
}
.sub-tabs button.active {
  background: var(--accent-terracotta-soft);
  color: var(--accent-terracotta-ink);
  border-color: var(--accent-terracotta);
}
.main-tabs .tab-ico { margin-right: 4px; }
.main-tabs button, .sub-tabs button { white-space: nowrap; }

.pane-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border-hairline);
  border-radius: 14px;
  padding: 13px;
  box-shadow: 0 2px 8px rgba(18, 32, 40, 0.03);
}
.card.selected {
  border: 2px solid var(--brand-primary);
}

.member-row {
  display: flex;
  align-items: flex-start;
  gap: 11px;
  cursor: pointer;
}
.avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  color: #FFFFFF;
  font-weight: 800;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  border: 2px solid #FFFFFF;
  box-shadow: 0 2px 6px rgba(0,0,0,0.14);
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
}
.badge.safe { background: var(--status-safe-soft); color: var(--status-safe); }
.badge.warn { background: var(--status-warning-soft); color: var(--status-warning-ink); }
.badge.sos { background: var(--status-sos-soft); color: var(--status-sos-ink); }
.badge.halo { background: var(--accent-terracotta-soft); color: var(--accent-terracotta-ink); }
.badge.slate { background: var(--brand-primary-soft); color: var(--brand-primary); }

.map-stage {
  position: relative;
  min-height: 0;
  min-width: 0;
  background: var(--map-bg);
}
#mapCanvas {
  width: 100%;
  height: 100%;
  position: relative;
  z-index: 0; /* keeps the map's own layers (zoom, credits) under our buttons and menu */
}

/* Map controls: "Map style" (menu) and "Fit Entire Haven", top right */
.map-controls {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 520; /* its menu opens over Safe Ping and the status line */
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
}
.map-style { position: relative; }
.map-ctl {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 40px;
  box-shadow: 0 2px 8px rgba(18, 32, 40, 0.14);
  white-space: nowrap;
}
.map-ctl[aria-expanded="true"] { border-color: var(--brand-primary); background: var(--brand-primary-soft); }
.map-style-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 210px;
  background: var(--bg-card);
  border: 1px solid var(--border-hairline);
  border-radius: 12px;
  box-shadow: 0 12px 30px rgba(18, 32, 40, 0.18);
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.map-style-menu[hidden] { display: none; }
.map-style-menu button {
  text-align: left;
  border-color: transparent;
  background: transparent;
  min-height: 40px;
  white-space: nowrap;
}
.map-style-menu button:hover { background: var(--bg-subtle); border-color: transparent; }
.map-style-menu button[aria-pressed="true"] { background: var(--brand-primary-soft); color: var(--brand-primary); }
.map-style-menu button[aria-pressed="true"]::after { content: "  ✓"; }
.map-style-menu #togglePoisBtn { margin-top: 4px; border-top: 1px solid var(--border-hairline); border-radius: 0 0 8px 8px; padding-top: 10px; }

/* Live sync + the chosen person's Journey Log line, bottom left (clear of Google's logo) */
.map-status {
  position: absolute;
  left: 12px;
  bottom: 32px;
  z-index: 500;
  max-width: calc(100% - 210px);
  background: var(--bg-card);
  border: 1px solid var(--border-hairline);
  border-radius: 12px;
  padding: 8px 12px;
  font-size: 12px;
  line-height: 1.35;
  box-shadow: 0 2px 8px rgba(18, 32, 40, 0.1);
}
.live-dot { color: var(--status-safe); margin-right: 8px; white-space: nowrap; }
.live-dot[data-state="reconnecting"] { color: var(--status-warning-ink); }
.live-dot[data-state="off"] { color: var(--text-secondary); }
.route-label { color: var(--text-secondary); }
.route-label:empty { display: none; }

/* Safe Ping, bottom right of the map (white with a terracotta ring: dark words stay readable) */
.safe-ping-btn {
  position: absolute;
  right: 12px;
  bottom: 32px;
  z-index: 500;
  max-width: 190px;
  min-height: 44px;
  background: var(--bg-card);
  color: var(--text-primary);
  border: 2px solid var(--accent-terracotta);
  border-radius: 999px;
  box-shadow: 0 4px 14px rgba(18, 32, 40, 0.2);
  line-height: 1.25;
}
button.safe-ping-btn.terracotta { background: var(--bg-card); color: var(--text-primary); border-color: var(--accent-terracotta); }
.safe-ping-btn:hover { background: var(--accent-terracotta-soft); }

/* No Haven yet: nothing to ping, chat about or frame on the map */
body.no-haven .safe-ping-btn,
body.no-haven #chatToggleBtn,
body.no-haven #inviteBtn,
body.no-haven #fitAllBtn,
body.no-haven .map-status { display: none; }

/* Map pins: centre each label on its spot, however long it is */
.edc-pin { display: flex; justify-content: center; color: #122028; }
/* A group pin's list (people close together). Map pop-ups are white in both themes, so fixed colours here. */
.pin-group-list { min-width: 210px; max-width: 280px; color: #122028; font-size: 14px; }
.pin-group-title { font-weight: 800; margin: 0 0 6px; }
.pin-group-list button.pin-group-row, .pin-group-list button.pin-group-zoom {
  display: flex; align-items: center; gap: 10px; width: 100%; min-height: 44px; margin-top: 6px; padding: 6px 10px;
  background: #FFFFFF; color: #122028; border: 1px solid #E2DCD3; border-radius: 10px; text-align: left; font-size: 14px;
}
.pin-group-list button.pin-group-zoom { justify-content: center; font-weight: 700; color: #183A4A; }
.pin-group-list button:hover { border-color: #183A4A; }
.pin-group-face {
  flex: 0 0 auto; width: 30px; height: 30px; border-radius: 50%; color: #FFFFFF; font-weight: 800; font-size: 12px;
  display: flex; align-items: center; justify-content: center;
}
.pin-group-text { display: flex; flex-direction: column; min-width: 0; }
.pin-group-text span { color: #4E616B; font-size: 13px; font-weight: 400; overflow-wrap: anywhere; }
.pin-group-text span.pin-group-sos { color: #B01A1A; font-weight: 700; }

.chat-drawer {
  position: fixed;
  right: 18px;
  bottom: 72px;
  width: 360px;
  max-height: 480px;
  background: var(--bg-card);
  border: 1px solid var(--border-hairline);
  border-radius: 16px;
  box-shadow: 0 16px 40px rgba(18, 32, 40, 0.16);
  display: none;
  flex-direction: column;
  z-index: 800;
}
.chat-drawer.open { display: flex; }
.chat-head { padding: 10px 10px 10px 14px; border-bottom: 1px solid var(--border-hairline); display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.icon-btn { min-width: 40px; min-height: 40px; padding: 4px 8px; }
.chat-presets { padding: 8px 12px; display: flex; gap: 6px; flex-wrap: wrap; border-top: 1px solid var(--border-hairline); }
.chat-presets .card-note { margin: 0; width: 100%; }
.chat-form { padding: 8px 12px 12px; display: flex; gap: 6px; }
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 300px;
}
.msg-bubble {
  background: var(--bg-subtle);
  border-radius: 12px;
  padding: 8px 11px;
  font-size: 13px;
}
.msg-bubble.alert {
  background: var(--accent-terracotta-soft);
  border-left: 3px solid var(--accent-terracotta);
}

input[type="text"], input[type="number"], input[type="password"], select.input {
  width: 100%;
  padding: 8px 10px;
  border-radius: 9px;
  border: 1px solid var(--border-hairline);
  background: var(--bg-canvas);
  color: var(--text-primary);
  font-size: 13px;
}

.row-wrap { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.small-label { font-size: 11px; font-weight: 700; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.04em; }

.radar-bar {
  height: 8px;
  border-radius: 999px;
  background: var(--bg-subtle);
  overflow: hidden;
  margin-top: 6px;
}
.radar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent-terracotta), var(--status-safe));
  transition: width 0.25s ease;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(18, 32, 40, 0.58);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.modal-backdrop.open { display: flex; }
.modal-card {
  width: min(440px, 92vw);
  max-height: calc(100dvh - 24px);
  overflow-y: auto;
  background: var(--bg-card);
  border-radius: 18px;
  padding: 22px;
  border: 2px solid var(--status-sos);
  text-align: center;
}

.modal-card.calm { border-color: var(--brand-primary); text-align: left; }
.modal-card.calm h3 { margin: 0 0 6px; }
.pin-field-label { display: block; font-size: 12px; font-weight: 600; color: var(--text-secondary); margin: 10px 0 4px; }
input.pin-input { text-align: center; font-size: 18px; letter-spacing: 6px; }
.form-error { color: var(--status-sos-ink); font-size: 12px; font-weight: 600; min-height: 16px; margin-top: 8px; }
.modal-actions { display: flex; gap: 8px; margin-top: 12px; }
.modal-actions > button { flex: 1; }

button:disabled { opacity: 0.5; cursor: not-allowed; }
button:disabled:hover { border-color: var(--border-hairline); }
button.danger-outline { color: var(--status-sos-ink); border-color: var(--status-sos); background: var(--bg-card); }
button.danger-outline:hover { background: var(--status-sos-soft); }
.danger-zone { margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--border-hairline); }

/* Notice bar: errors from any button, in the server's plain words */
.notice-bar {
  position: fixed;
  top: 72px;
  left: 50%;
  transform: translateX(-50%);
  max-width: min(560px, 92vw);
  padding: 10px 16px;
  border-radius: 12px;
  font-size: 13px;
  font-weight: 600;
  box-shadow: 0 10px 30px rgba(18, 32, 40, 0.16);
  z-index: 1300;
  display: none;
}
.notice-bar.open { display: block; }
.notice-bar.sticky { cursor: pointer; }
.notice-bar.error { background: var(--status-sos-soft); color: var(--status-sos-ink); border: 1px solid var(--status-sos); }
.notice-bar.info { background: var(--brand-primary-soft); color: var(--brand-primary); border: 1px solid var(--brand-primary); }

/* Sign-in screen (Sunlit Porcelain) */
.auth-screen {
  position: fixed;
  inset: 0;
  z-index: 1200;
  background: var(--bg-canvas);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  overflow-y: auto;
}
.auth-screen[hidden] { display: none; }
.auth-card {
  width: min(400px, 100%);
  background: var(--bg-card);
  border: 1px solid var(--border-hairline);
  border-radius: 18px;
  padding: 26px 24px 20px;
  box-shadow: 0 16px 40px rgba(18, 32, 40, 0.08);
}
.auth-card form[hidden] { display: none; }
.auth-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.auth-brand img { width: 44px; height: 44px; border-radius: 12px; }
.auth-label { display: block; font-size: 12px; font-weight: 700; color: var(--text-secondary); margin: 4px 0 6px; }
.auth-card input[type="email"], .auth-card input[type="text"] {
  width: 100%;
  padding: 11px 12px;
  border-radius: 10px;
  border: 1px solid var(--border-hairline);
  background: var(--bg-canvas);
  color: var(--text-primary);
  font-size: 15px;
}
.auth-card input:focus { outline: 2px solid var(--brand-primary); outline-offset: 1px; }
input.code-input { text-align: center; font-size: 24px !important; letter-spacing: 10px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.auth-submit { width: 100%; margin-top: 12px; padding: 11px 13px; font-size: 14px; }
.auth-text { font-size: 13px; margin: 0 0 12px; color: var(--text-primary); }
.auth-hint { font-size: 12px; color: var(--text-secondary); margin: 10px 0 0; }
.auth-notice { font-size: 13px; color: var(--brand-primary); background: var(--brand-primary-soft); border-radius: 10px; padding: 8px 11px; margin: 0 0 14px; }
.auth-notice:empty { display: none; }
.auth-links { display: flex; justify-content: space-between; gap: 8px; margin-top: 10px; }
button.link-btn { background: none; border: none; padding: 4px 0; color: var(--brand-primary); font-size: 12px; text-decoration: underline; }
.auth-foot { font-size: 11px; color: var(--text-hint); margin: 12px 0 0; border-top: 1px solid var(--border-hairline); padding-top: 10px; }

input[type="email"] {
  width: 100%;
  padding: 8px 10px;
  border-radius: 9px;
  border: 1px solid var(--border-hairline);
  background: var(--bg-canvas);
  color: var(--text-primary);
  font-size: 13px;
}


/* Round 2 (2 Dec 2026): plain notes and calm empty states instead of blank boxes */
.card-note { font-size: 12px; color: var(--text-secondary); margin: 8px 0 0; line-height: 1.45; }
.empty-note { font-size: 12px; color: var(--text-secondary); line-height: 1.45; }
.chat-messages .empty-note { padding: 14px 4px; text-align: center; }
.trip-hidden-why { font-weight: 400; color: var(--text-secondary); }
/* Keeper tag codes are EDC- plus 26 letters/digits: let them wrap instead of pushing the card wider */
.tag-code { font-size: 11px; color: var(--text-secondary); margin-top: 4px; overflow-wrap: anywhere; }
.tag-code code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11px; color: var(--text-primary); }
.halo-points { margin: 0 0 4px; padding-left: 18px; font-size: 13px; line-height: 1.5; }
.halo-points li { margin: 4px 0; }
.map-style-menu button[hidden] { display: none; }

/* Round 3 (2 Dec 2026): Haven card, join requests, admin buttons */
.form-info { color: var(--brand-primary); font-size: 12px; font-weight: 600; min-height: 0; margin-top: 8px; }
.form-info:empty { display: none; }
.small-btn { padding: 4px 9px; font-size: 11px; }
.danger-solid { background: var(--status-sos); color: #fff; border-color: var(--status-sos); }
.choose-admin-note { margin: 10px 0 0; padding: 8px 10px; border-radius: 9px; font-size: 12px; font-weight: 600;
  background: var(--status-warning-soft); color: var(--text-primary); border: 1px solid var(--status-warning); }
.requests-block { margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--border-hairline); }
.requests-title { font-size: 12px; font-weight: 700; color: var(--accent-terracotta); margin-bottom: 6px; }
.request-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 5px 0; font-size: 13px; }
.key-pill[hidden] { display: none; }
#msgCountBadge[hidden] { display: none; }
.key-text { letter-spacing: 2px; color: var(--text-primary); }
.emergency-link-expiry { font-size: 11px; color: #fff; opacity: 0.92; align-self: center; }
.emergency-link-expiry:empty { display: none; }
/* SOS on its way (busy server or no connection): the bar says so in readable words; the button pulses */
.emergency-banner.sending .emergency-link-expiry { font-size: 14px; opacity: 1; }
#sosHeaderBtn.sending .sos-ico, #sosHeaderBtn.sending .sos-guardian { display: none; }
#sosHeaderBtn.sending { animation: sos-sending 1.2s ease-in-out infinite; cursor: progress; }
@keyframes sos-sending { 50% { opacity: 0.72; } }
@media (prefers-reduced-motion: reduce) { #sosHeaderBtn.sending { animation: none; } }
#emergencyLiveLink[hidden] { display: none; }
.medical-line { margin-top: 8px; font-size: 12px; color: var(--status-sos-ink); }

/* ===================================================================================================
   Browser phone layout (3 Dec 2026)
   Wide windows: Haven list on the left, map on the right (as before), in one tidy top bar.
   Phones and narrow windows (under 900 px): slim top bar, full-width map, content below it, the
   four sections as a bottom bar, and Guardian SOS as a big red round button in the middle of that bar.
   =================================================================================================== */

@media (min-width: 900px) and (max-width: 1180px) {
  .topbar .brand-sub { display: none; }
  .workspace { grid-template-columns: 380px 1fr; }
  .main-tabs .tab-ico { display: none; }
  .main-tabs button, .sub-tabs button { padding-left: 4px; padding-right: 4px; }
}
@media (min-width: 900px) and (max-width: 1060px) {
  .topbar .brand-text { display: none; }
  .invite-btn { width: 36px; height: 36px; padding: 0; }
  .invite-btn .btn-label { display: none; }
  .invite-btn .btn-ico { margin: 0; font-size: 18px; }
}

/* ===================================================================================================
   Redesign (3 Dec 2026, evening): Ali asked for "less text, more interactive tabs, motion where it helps",
   the same on Android, phone browsers and the Mac. Mirrors Android round 8 (MapHome.kt):
   map first; the cards are a sheet over the map on phones (low / half / full) and a side panel on wide
   windows; a status chip; People · Places · Keepers with a sliding indicator; one-line rows; details on tap.
   =================================================================================================== */

.ico { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }

/* Top bar: logo (and name on wide windows), Haven chip, Invite, Chat, SOS */
.topbar { justify-content: flex-start; }
.top-actions { margin-left: auto; }
.haven-chip {
  display: inline-flex; align-items: center; gap: 6px; min-height: 44px; min-width: 0; max-width: 340px;
  padding: 6px 14px; border-radius: 999px; background: var(--bg-subtle); border: 1px solid var(--border-hairline);
  font-size: 15px; font-weight: 700; color: var(--text-primary);
}
.haven-chip-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip-caret { color: var(--text-secondary); font-size: 14px; }
button.invite-btn {
  display: inline-flex; align-items: center; gap: 6px; min-height: 44px; padding: 0 14px; border-radius: 12px;
  background: var(--brand-primary); border-color: var(--brand-primary); color: #FFFFFF; font-size: 14px; font-weight: 700;
}
body.dark-theme button.invite-btn { color: #0F1A20; }
.chat-btn { position: relative; min-height: 44px; }

/* Map: small round buttons (top right), a small "● Live" chip (top left), Safe Ping (bottom right) */
.map-controls { gap: 10px; }
.round-ctl {
  width: 48px; height: 48px; padding: 0; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  background: var(--bg-card); color: var(--text-primary); border: 1px solid var(--border-hairline);
  box-shadow: 0 2px 8px rgba(18, 32, 40, 0.18);
}
.round-ctl[aria-pressed="true"] { background: var(--brand-primary-soft); color: var(--brand-primary); }
.round-ctl[hidden] { display: none; }
.map-status { top: 12px; bottom: auto; left: 12px; border-radius: 16px; padding: 6px 12px; font-size: 14px; max-width: calc(100% - 92px); }
.map-status .live-dot { margin-right: 6px; }
.route-label { display: block; }
button.safe-ping {
  position: absolute; right: 12px; bottom: 30px; z-index: 500; display: inline-flex; align-items: center; gap: 6px;
  padding: 0; background: transparent; border: 0; box-shadow: none; min-height: 52px; color: var(--text-primary);
}
.safe-ping-label {
  background: var(--bg-card); color: var(--text-primary); border-radius: 999px; padding: 6px 11px; font-size: 14px;
  font-weight: 700; box-shadow: 0 2px 6px rgba(18, 32, 40, 0.18); white-space: nowrap;
}
.safe-ping-round {
  width: 52px; height: 52px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  background: var(--accent-terracotta-strong); color: #FFFFFF; box-shadow: 0 6px 14px rgba(181, 72, 42, 0.35);
}
.safe-ping-round .ico { width: 26px; height: 26px; stroke-width: 2.2; }
button.safe-ping:hover { background: transparent; }
button.safe-ping:hover .safe-ping-round { filter: brightness(1.08); }
body.no-haven .safe-ping, body.no-haven #mapSubTabs, body.no-haven #centreMeBtn, body.no-haven #fitAllBtn { display: none; }

/* The cards (side panel on wide windows; a sheet on phones, below) */
.sheet-handle { display: none; }
.sheet-head { padding: 10px 12px 0; }
.sheet-head:empty { display: none; }
.status-chip {
  display: inline-flex; align-items: center; gap: 8px; min-height: 40px; padding: 6px 14px; border-radius: 999px;
  background: var(--bg-subtle); border: 1px solid var(--border-hairline); font-size: 14px; font-weight: 700; color: var(--text-primary);
}
.status-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.dot-live { background: var(--status-safe); }
.dot-paused { background: var(--status-warning); }
.dot-halo { background: var(--accent-terracotta); }
.dot-none { background: var(--text-secondary); }
.main-tabs button { display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.main-tabs .ico { width: 18px; height: 18px; }

.seg-tabs {
  --seg-i: 0; position: relative; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr));
  margin: 10px 12px 4px; padding: 3px; height: 44px; border-radius: 12px; background: var(--bg-subtle); flex-shrink: 0;
}
.seg-tabs[hidden] { display: none; }
.seg-indicator {
  position: absolute; top: 3px; bottom: 3px; left: 3px; width: calc((100% - 6px) / 3); border-radius: 10px;
  background: var(--bg-card); box-shadow: 0 1px 4px rgba(18, 32, 40, 0.16); transform: translateX(calc(var(--seg-i) * 100%));
}
.seg-tabs button {
  position: relative; z-index: 1; min-height: 38px; padding: 0 4px; border: 0; border-radius: 10px; background: transparent;
  font-size: 14px; font-weight: 600; color: var(--text-secondary); white-space: nowrap;
}
.seg-tabs button:hover { border-color: transparent; color: var(--text-primary); }
.seg-tabs button.active { color: var(--text-primary); font-weight: 800; }
.seg-count { font-weight: 600; color: var(--text-secondary); }
.pane-scroll { gap: 4px; }

/* One-line rows */
.person-row, .keeper-row, .place-main {
  display: flex; align-items: center; gap: 12px; width: 100%; min-height: 64px; padding: 6px 8px; border: 0;
  border-radius: 14px; background: transparent; text-align: left; color: var(--text-primary); font-weight: 400;
}
.person-row:hover, .keeper-row:hover, .place-main:hover { background: var(--bg-subtle); border-color: transparent; }
.person-row.selected { background: var(--brand-primary-soft); }
.row-text { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.row-text strong, .row-text h3 { font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-line { font-size: 14px; font-weight: 400; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
span.row-line:has(.line-main) { display: flex; min-width: 0; }
.line-main { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.line-age { flex-shrink: 0; }
.avatar-wrap { position: relative; width: 50px; height: 50px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.avatar-wrap::before { content: ""; position: absolute; inset: 3px; border-radius: 50%; background: var(--status-safe); opacity: 0; }
.person-row .avatar, .panel-head .avatar {
  width: 44px; height: 44px; border: 3px solid var(--bg-card); box-shadow: 0 0 0 2.5px var(--ring, var(--border-hairline)); position: relative;
}
.ring-live { --ring: var(--status-safe); }
.ring-paused { --ring: var(--status-warning); }
.ring-halo { --ring: var(--accent-terracotta); }
.ring-sos { --ring: var(--status-sos); }
.ring-none { --ring: var(--border-hairline); }
.bat-pill { flex-shrink: 0; font-size: 13px; font-weight: 700; padding: 3px 8px; border-radius: 999px; background: var(--status-safe-soft); color: var(--status-safe); }
.bat-pill.low { background: var(--status-sos-soft); color: var(--status-sos-ink); }
.section-label { font-size: 13px; font-weight: 800; color: var(--text-secondary); margin: 8px 4px 2px; }
.section-label.warm { color: var(--accent-terracotta-ink); }
.request-card { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 14px; background: var(--accent-terracotta-soft); }
.request-card.plain { background: transparent; padding: 4px 8px; }
.add-row { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 8px; padding: 4px 0 6px; }
.add-row .radius-pick { width: auto; }
.place-row { display: flex; align-items: center; gap: 4px; }
.place-main { flex: 1; min-height: 56px; }
.place-ico { width: 44px; height: 44px; border-radius: 50%; background: var(--bg-subtle); display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
/* Dark mode: a light chip behind the small place pictures (art README) */
body.dark-theme .place-ico { background: #E9EEF0; }
.place-art { width: 34px; height: 34px; object-fit: contain; }
.drive-card {
  display: flex; align-items: center; gap: 12px; width: 100%; min-height: 72px; margin-top: 12px; padding: 10px 12px;
  border: 0; border-radius: 16px; background: var(--bg-subtle); color: var(--text-primary); text-align: left; font-weight: 400;
}
.drive-card:hover { border-color: transparent; filter: brightness(0.98); }
.drive-art { width: 56px; height: 56px; object-fit: contain; flex-shrink: 0; }
.drive-card .chev { font-size: 24px; color: var(--text-secondary); }
.place-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--brand-primary); box-shadow: 0 0 0 4px var(--bg-card); }
button.del-btn { width: 44px; height: 44px; border: 0; background: transparent; color: var(--text-secondary); font-size: 16px; }
.keeper-tools { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.pane-scroll button.link-btn, .modal-card button.link-btn {
  background: transparent; border: 0; color: var(--brand-primary); font-weight: 700; min-height: 44px; padding: 4px 8px;
}
.keeper-tile {
  width: 40px; height: 40px; border-radius: 12px; display: flex; align-items: center; justify-content: center; flex-shrink: 0;
  background: var(--accent-terracotta-soft); color: var(--accent-terracotta-ink); font-weight: 800;
}
.keeper-tile.lost { background: var(--status-sos-soft); color: var(--status-sos-ink); }
.lost-pill { flex-shrink: 0; font-size: 12px; font-weight: 800; padding: 3px 8px; border-radius: 999px; background: var(--status-sos-soft); color: var(--status-sos-ink); }
.empty-state { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 4px; padding: 22px 12px; color: var(--text-secondary); font-size: 14px; }
.empty-state strong { color: var(--text-primary); font-size: 16px; }
.empty-art { width: 96px; height: 96px; object-fit: contain; margin-bottom: 8px; }
.empty-art.small { display: block; width: 88px; height: 88px; margin: 0 auto 6px; }
.empty-art.wide { display: block; width: 140px; height: 140px; margin: 0 auto 4px; }
.skeleton-row { height: 58px; border-radius: 14px; background: var(--bg-subtle); }

/* Dialogs: one person, what you share, a place, a Keeper, Invite, your Havens */
.panel-head { display: flex; align-items: center; gap: 12px; margin-bottom: 6px; }
.panel-head h3 { margin: 0; }
.panel-line { margin: 8px 0 0; font-size: 15px; line-height: 1.45; }
.panel-line.muted { color: var(--text-secondary); }
.panel-line.warm { color: var(--accent-terracotta-ink); }
.panel-line.safe { color: var(--status-safe); font-weight: 700; }
.panel-line:empty { display: none; }
.action-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.action-row > * { flex: 1 1 auto; text-align: center; }
.toggle-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; width: 100%; min-height: 52px; padding: 8px 4px;
  background: transparent; border: 0; border-bottom: 1px solid var(--border-hairline); border-radius: 0; text-align: left;
  font-size: 16px; font-weight: 600; color: var(--text-primary); cursor: pointer;
}
.toggle-row:hover { background: transparent; border-color: var(--border-hairline); }
.switch, input.switch-input {
  appearance: none; -webkit-appearance: none; position: relative; flex-shrink: 0; width: 46px; height: 28px; margin: 0;
  border-radius: 999px; background: var(--border-hairline); cursor: pointer;
}
.switch::after, input.switch-input::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #FFFFFF;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
}
.toggle-row[aria-checked="true"] .switch, input.switch-input:checked { background: var(--status-safe); }
.toggle-row[aria-checked="true"] .switch::after, input.switch-input:checked::after { transform: translateX(18px); }
.key-big {
  margin-top: 8px; padding: 14px; border-radius: 14px; background: var(--bg-subtle); text-align: center; user-select: all;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-weight: 800; font-size: 30px; letter-spacing: 4px; color: var(--brand-primary);
}
.haven-list { display: flex; flex-direction: column; gap: 6px; margin: 6px 0 4px; }
button.haven-row {
  display: flex; align-items: center; gap: 10px; min-height: 48px; text-align: left; background: transparent;
  border: 1px solid var(--border-hairline); border-radius: 12px; font-size: 15px;
}
button.haven-row.current { border-color: var(--brand-primary); background: var(--brand-primary-soft); }
.haven-dot { width: 12px; height: 12px; border-radius: 50%; border: 2px solid var(--brand-primary); flex-shrink: 0; }
.haven-row.current .haven-dot { background: var(--brand-primary); }

/* The SOS countdown: the same 5 seconds and buttons as before; a ring fills while it counts */
.sos-ring { position: relative; width: 132px; height: 132px; margin: 10px auto; }
.sos-ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.sos-ring circle { fill: none; stroke-width: 9; }
.sos-ring-track { stroke: var(--status-sos-soft); }
.sos-ring-fill { stroke: var(--status-sos); stroke-linecap: round; stroke-dasharray: 326.73; stroke-dashoffset: 0; }
.sos-ring-num { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 44px; font-weight: 900; color: var(--status-sos); }

/* ---- Phones and narrow windows (under 900 px) ---- */
@media (max-width: 899px) {
  :root { --topbar-h: 60px; --nav-h: calc(var(--tabbar-h) + var(--safe-bottom)); }
  body { font-size: 15px; }

  /* Slim top bar: logo, Haven chip, Invite, Chat (its own layer above the bottom bar) */
  .topbar { padding: 0 12px; gap: 8px; position: relative; z-index: 950; }
  .brand-lockup img { width: 36px; height: 36px; }
  .topbar .brand-text { display: none; }
  .haven-chip { flex: 1 1 auto; max-width: none; font-size: 16px; padding: 6px 12px; }
  button.invite-btn { flex-shrink: 0; padding: 0 10px; }
  .top-actions { margin-left: 0; }
  .chat-btn { width: 44px; height: 44px; padding: 0; justify-content: center; border-radius: 12px; }
  .chat-btn .btn-label { display: none; }
  #msgCountBadge {
    position: absolute; top: -6px; right: -6px; min-width: 22px; height: 22px; padding: 0 6px;
    justify-content: center; font-size: 14px; line-height: 1; border: 2px solid var(--bg-card);
  }

  /* Guardian SOS: always on screen, big, red, round, in the middle of the bottom bar */
  #sosHeaderBtn {
    position: fixed; z-index: 900; left: 50%; bottom: calc(var(--safe-bottom) + 10px); transform: translateX(-50%);
    width: 68px; height: 68px; padding: 0; border-radius: 50%; font-size: 19px; letter-spacing: 0.04em;
    display: flex; align-items: center; justify-content: center;
    box-shadow: 0 0 0 4px var(--bg-card), 0 8px 20px rgba(200, 30, 30, 0.4);
  }
  #sosHeaderBtn .sos-ico, #sosHeaderBtn .sos-guardian { display: none; }
  #sosHeaderBtn.sending { font-size: 14px; letter-spacing: 0; }

  /* Map behind, the sheet over its lower part; the map's box ends where the sheet starts */
  .workspace { display: block; position: relative; padding: 0; background: var(--map-bg); }
  .map-stage { position: absolute; left: 0; right: 0; top: 0; bottom: calc(var(--nav-h) + var(--sheet-h, 50%)); height: auto; border: 0; }
  #sheet {
    position: absolute; left: 0; right: 0; bottom: var(--nav-h); height: var(--sheet-h, 50%); z-index: 600;
    display: flex; flex-direction: column; overflow: hidden; background: var(--bg-card); border: 0;
    border-radius: 22px 22px 0 0; box-shadow: 0 -6px 24px rgba(18, 32, 40, 0.16);
  }
  body[data-section="other"] #sheet { top: 0; height: auto; border-radius: 0; box-shadow: none; }
  body[data-section="other"] .sheet-handle { display: none; }
  .sheet-handle {
    display: flex; align-items: center; justify-content: center; width: 100%; min-height: 44px; height: 44px; flex-shrink: 0;
    margin-bottom: -10px; padding: 0; border: 0; border-radius: 22px 22px 0 0; background: transparent; cursor: grab; touch-action: none;
  }
  .sheet-handle span { width: 40px; height: 5px; border-radius: 99px; background: var(--border-hairline); }
  .sheet-handle:hover { border-color: transparent; }
  .sheet-head { padding: 2px 14px 0; }
  .pane-scroll { padding: 6px 12px 28px; touch-action: pan-y; }
  body.sheet-dragging #sheet, body.sheet-dragging .map-stage { transition: none !important; }
  body.map-short .map-controls { flex-direction: row; }
  body.map-short .safe-ping-label { display: none; }
  body.map-short .map-status .route-label { display: none; }

  /* The four sections as a bottom bar, with the SOS in the middle */
  .main-tabs {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 850; height: var(--nav-h);
    padding: 6px 2px calc(6px + var(--safe-bottom));
    grid-template-columns: repeat(2, minmax(0, 1fr)) 72px repeat(2, minmax(0, 1fr));
    gap: 0; border-top: 1px solid var(--border-hairline); border-bottom: 0; box-shadow: 0 -2px 12px rgba(18, 32, 40, 0.06);
  }
  .main-tabs button:nth-child(3) { grid-column: 4; }
  .main-tabs button:nth-child(4) { grid-column: 5; }
  .left-pane .main-tabs button {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-height: 56px;
    padding: 2px 0; font-size: 14px; letter-spacing: -0.02em; white-space: nowrap; color: var(--text-secondary);
    background: transparent; border-color: transparent; border-radius: 12px;
  }
  .main-tabs .ico { width: 22px; height: 22px; }
  .main-tabs button.active,
  body.dark-theme .main-tabs button.active { background: var(--brand-primary-soft); color: var(--brand-primary); }

  /* Map buttons and Safe Ping just above the sheet */
  .map-controls { top: 10px; right: 10px; }
  .map-status { top: 10px; left: 10px; max-width: calc(100% - 80px); }
  button.safe-ping { right: 10px; bottom: 28px; }

  /* Haven Chat: a sheet above the bottom bar, full width */
  .chat-drawer {
    left: 8px; right: 8px; width: auto; bottom: calc(var(--nav-h) + 18px);
    max-height: calc(100dvh - var(--topbar-h) - var(--nav-h) - 30px);
  }
  .chat-messages { max-height: none; min-height: 96px; }
  .msg-bubble { font-size: 15px; }
  .icon-btn { min-width: 44px; min-height: 44px; }

  /* Alert banner: words on top, buttons below, nothing cut off */
  .emergency-banner { flex-direction: column; align-items: stretch; padding: 10px 12px; font-size: 15px; }
  .emergency-link, .emergency-cancel { min-height: 44px; display: inline-flex; align-items: center; justify-content: center; font-size: 14px; flex: 1 1 auto; }
  .emergency-link-expiry { font-size: 14px; flex-basis: 100%; order: 3; }

  .notice-bar { top: calc(var(--topbar-h) + 8px); width: calc(100vw - 24px); font-size: 14px; }
  .modal-card { width: calc(100vw - 24px); padding: 18px; }
  .modal-card h3 { font-size: 18px; }

  /* Tap targets of 44 px or more, words of 14 px or more */
  .left-pane button, .chat-drawer button, .modal-card button, .auth-card button, .emergency-banner button { min-height: 44px; font-size: 15px; }
  .left-pane .seg-tabs button { font-size: 14px; }
  .left-pane a.btn, .modal-card a.btn { min-height: 44px; font-size: 15px; display: inline-flex; align-items: center; justify-content: center; text-decoration: none; }
  .small-btn { padding: 6px 12px; }
  input[type="text"], input[type="number"], input[type="password"], input[type="email"], select.input, textarea {
    font-size: 16px; min-height: 44px;
  }
  input.pin-input { font-size: 20px; }
  #paneContent input[type="checkbox"]:not(.switch-input) { width: 22px; height: 22px; vertical-align: middle; }
  #paneContent label:has(input[type="checkbox"]) { display: inline-flex; align-items: center; gap: 6px; min-height: 44px; }

  .badge { font-size: 14px; padding: 3px 9px; }
  .bat-pill, .lost-pill { font-size: 14px; }
  .small-label { font-size: 14px; text-transform: none; letter-spacing: 0; }
  .card-note, .empty-note, .form-error, .form-info, .tag-code, .tag-code code, .requests-title, .request-row,
  .medical-line, .choose-admin-note, .pin-field-label, .halo-points, .auth-label, .auth-text, .auth-hint,
  .auth-notice, .auth-foot, button.link-btn, .section-label { font-size: 14px; }
  .auth-foot { color: var(--text-secondary); }
  .brand-sub { font-size: 14px; }
  .leaflet-popup-content, .gm-style .gm-style-iw-d { font-size: 14px; }
  .pin-group-face, .pin-group-text span { font-size: 14px; }

  /* The page's own cards and pins set some small sizes inline: lift them to 14 px on phones */
  #paneContent [style*="font-size:10px"], #paneContent [style*="font-size:11px"],
  #paneContent [style*="font-size:12px"], #paneContent [style*="font-size:13px"],
  .chat-drawer [style*="font-size:10px"], .chat-drawer [style*="font-size:11px"],
  .chat-drawer [style*="font-size:12px"], .chat-drawer [style*="font-size:13px"],
  .modal-card [style*="font-size:10px"], .modal-card [style*="font-size:11px"],
  .modal-card [style*="font-size:12px"], .modal-card [style*="font-size:13px"],
  .edc-pin [style*="font-size:10px"], .edc-pin [style*="font-size:11px"],
  .edc-pin [style*="font-size:12px"], .edc-pin [style*="font-size:13px"] { font-size: 14px !important; }
}

/* Very narrow phones: Invite shows its icon only */
@media (max-width: 379px) {
  button.invite-btn .btn-label { display: none; }
  button.invite-btn { width: 44px; padding: 0; justify-content: center; }
}

/* Small tablets / big phones on their side: room for the name next to the logo */
@media (min-width: 600px) and (max-width: 899px) {
  .topbar .brand-text { display: block; }
  .topbar .brand-sub { display: none; }
  .haven-chip { max-width: 420px; }
}

/* Phone on its side: cards on the left, map on the right (as Android), same bottom bar */
@media (max-width: 899px) and (max-height: 500px) and (orientation: landscape) {
  .workspace { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); padding-bottom: var(--nav-h); }
  .map-stage, #sheet { position: relative; inset: auto; height: auto; bottom: auto; border-radius: 0; box-shadow: none; }
  .map-stage { order: 2; border-left: 1px solid var(--border-hairline); }
  .sheet-handle { display: none; }
}

/* Wide windows: the side panel */
@media (min-width: 900px) {
  .workspace { grid-template-columns: 420px 1fr; }
  #sheet { background: var(--bg-canvas); }
}

/* ---- Motion: subtle (150–300 ms), and none at all when the device asks for less motion ---- */
@media (prefers-reduced-motion: no-preference) {
  #sheet { transition: height 280ms cubic-bezier(0.2, 0.9, 0.3, 1.04); }
  .map-stage { transition: bottom 280ms cubic-bezier(0.2, 0.9, 0.3, 1.04); }
  .seg-indicator { transition: transform 250ms cubic-bezier(0.3, 0.8, 0.3, 1); }
  #paneContent[data-enter="right"] > * { animation: enter-right 240ms ease-out both; }
  #paneContent[data-enter="left"] > * { animation: enter-left 240ms ease-out both; }
  .avatar-wrap.live::before { animation: live-pulse 1.4s linear infinite; }
  .pin-live > div:first-child { animation: pin-pulse 1.8s ease-out infinite; }
  .pin-drop { animation: pin-drop 280ms cubic-bezier(0.3, 1.4, 0.5, 1) both; }
  body.own-alert-on #sosHeaderBtn:not(.sending) { animation: sos-beat 1.4s ease-in-out infinite; }
  .sos-ring-fill { animation: sos-fill 5s linear forwards; }
  .modal-backdrop.open { animation: fade-in 160ms ease-out; }
  .modal-backdrop.open .modal-card { animation: card-in 220ms cubic-bezier(0.2, 0.9, 0.3, 1); }
  .skeleton-row {
    background: linear-gradient(90deg, var(--bg-subtle) 0%, var(--bg-card) 50%, var(--bg-subtle) 100%);
    background-size: 200% 100%; animation: shimmer 1.2s linear infinite;
  }
  .round-ctl, .person-row, .keeper-row, .place-main, .status-chip, .haven-chip, .safe-ping-round { transition: background-color 150ms ease, transform 150ms ease; }
  .round-ctl:active, .person-row:active, .keeper-row:active, .place-main:active, .status-chip:active, .safe-ping:active .safe-ping-round { transform: scale(0.97); }
  .switch::after, input.switch-input::after { transition: transform 180ms ease; }
  .switch, input.switch-input { transition: background-color 180ms ease; }
}
@keyframes enter-right { from { opacity: 0; transform: translateX(18px); } to { opacity: 1; transform: none; } }
@keyframes enter-left { from { opacity: 0; transform: translateX(-18px); } to { opacity: 1; transform: none; } }
@keyframes live-pulse { 0% { opacity: 0.45; transform: scale(1); } 100% { opacity: 0; transform: scale(1.35); } }
@keyframes pin-pulse { 0% { box-shadow: 0 0 0 0 rgba(35, 122, 87, 0.45); } 100% { box-shadow: 0 0 0 12px rgba(35, 122, 87, 0); } }
@keyframes pin-drop { from { opacity: 0; transform: translateY(-14px); } to { opacity: 1; transform: none; } }
@keyframes sos-beat { 0%, 100% { scale: 1; } 50% { scale: 1.07; } }
@keyframes sos-fill { from { stroke-dashoffset: 326.73; } to { stroke-dashoffset: 0; } }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes card-in { from { opacity: 0; transform: translateY(14px) scale(0.98); } to { opacity: 1; transform: none; } }
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: -100% 0; } }

/* ---- What's new: once after an update (EDC teal header, "NEW IN" pill, icon rows, one "Got it") ---- */
.wn-backdrop {
  position: fixed; inset: 0; z-index: 990; display: flex; align-items: center; justify-content: center; padding: 16px;
  background: rgba(18, 32, 40, 0.58);
}
.wn-card {
  width: min(440px, 100%); max-height: calc(100dvh - 32px); display: flex; flex-direction: column; overflow: hidden;
  background: var(--bg-card); border: 1px solid var(--border-hairline); border-radius: 26px;
  box-shadow: 0 24px 60px rgba(18, 32, 40, 0.35);
}
.wn-head { padding: 22px 22px 20px; color: #FFFFFF; background: linear-gradient(135deg, #24566B 0%, #183A4A 55%, #10293A 100%); flex-shrink: 0; }
.wn-head-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.wn-logo { display: flex; padding: 6px; border-radius: 16px; background: rgba(255, 255, 255, 0.92); }
.wn-logo img { width: 40px; height: 40px; display: block; }
.wn-pill {
  padding: 4px 11px; border-radius: 999px; background: #B5482A; color: #FFFFFF;
  font-size: 14px; font-weight: 800; letter-spacing: 0.04em; white-space: nowrap;
}
.wn-head h2 { margin: 16px 0 0; font-size: 24px; line-height: 1.25; font-weight: 800; letter-spacing: -0.01em; }
.wn-rows { padding: 20px 22px 4px; display: flex; flex-direction: column; gap: 16px; overflow-y: auto; }
.wn-row { display: flex; align-items: flex-start; gap: 14px; }
.wn-ico {
  width: 42px; height: 42px; border-radius: 13px; flex-shrink: 0; display: flex; align-items: center; justify-content: center;
  background: var(--accent-terracotta-soft); color: var(--accent-terracotta-ink);
}
.wn-row .row-text strong { font-size: 16px; white-space: normal; }
.wn-text { font-size: 14px; line-height: 1.45; color: var(--text-secondary); margin-top: 2px; }
.wn-foot { padding: 18px 22px 20px; flex-shrink: 0; }
.wn-foot button.wn-done { width: 100%; min-height: 50px; border-radius: 14px; font-size: 16px; font-weight: 800; }
@media (prefers-reduced-motion: no-preference) {
  .wn-backdrop { animation: fade-in 180ms ease-out; }
  .wn-card { animation: card-in 260ms cubic-bezier(0.2, 0.9, 0.3, 1); }
  .wn-row { animation: wn-row-in 320ms cubic-bezier(0.2, 0.8, 0.3, 1) both; animation-delay: calc(120ms + var(--i, 0) * 70ms); }
}
@keyframes wn-row-in { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }

/* ===================================================================================================
   Re-match to Android round 8's final screens (3 Dec 2026, ~21:50; ../EDC Family Safety & GPS Android/docs/redesign)
   =================================================================================================== */

/* Sheet title row: the Haven's name (or a person's), the status chip on the right */
.sheet-title-row { display: flex; align-items: center; gap: 8px; min-width: 0; }
.sheet-title { flex: 1; min-width: 0; margin: 0; font-size: 20px; font-weight: 800; letter-spacing: -0.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sheet-title-row .status-chip { flex-shrink: 0; }
.back-btn { font-size: 22px; border: 0; background: transparent; padding: 0; width: 44px; min-height: 44px; }

/* Three round icon tabs; the chosen one is filled dark, wider, and shows its word and count */
.icon-tabs { display: flex; gap: 8px; margin: 10px 12px 6px; flex-shrink: 0; }
.icon-tabs[hidden] { display: none; }
.icon-tabs button {
  flex: 1 1 0; min-width: 0; height: 48px; padding: 0 10px; border: 0; border-radius: 999px;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--bg-subtle); color: var(--text-secondary); font-size: 15px; font-weight: 800; white-space: nowrap;
}
.icon-tabs button:hover { border-color: transparent; color: var(--text-primary); }
.icon-tabs button .tab-word { display: none; overflow: hidden; text-overflow: ellipsis; }
.icon-tabs button.active { flex-grow: 2.2; background: var(--text-primary); color: var(--bg-card); }
.icon-tabs button.active .tab-word { display: inline; }
.icon-tabs .ico { width: 21px; height: 21px; flex-shrink: 0; }

/* Person rows: the battery on the avatar's corner, problems in red with (!) on the right, charging on the right */
.avatar-wrap .bat-badge {
  position: absolute; right: -6px; bottom: -2px; z-index: 1; padding: 0 4px; border-radius: 999px; line-height: 16px;
  background: var(--bg-card); color: var(--text-primary); border: 1px solid var(--border-hairline);
  font-size: 11px; font-weight: 800;
}
.avatar-wrap .bat-badge.low { background: var(--status-sos); color: #FFFFFF; border-color: var(--status-sos); }
.row-line.problem { color: var(--status-sos-ink); font-weight: 600; }
.problem-ico {
  flex-shrink: 0; width: 26px; height: 26px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  background: var(--status-sos-soft); color: var(--status-sos-ink); font-weight: 900; font-size: 15px;
}
.charge-ico { flex-shrink: 0; color: var(--status-safe); font-size: 18px; }
button.add-person-btn {
  display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%; min-height: 52px; margin-top: 8px;
  border: 1px solid var(--border-hairline); border-radius: 14px; background: var(--bg-card); font-size: 16px; font-weight: 700;
}

/* A person's page in the sheet: their line, pills, Directions · Street View · Haven chat, the drive card */
.person-page { display: flex; flex-direction: column; gap: 4px; padding: 0 4px 8px; }
.person-page-line .row-line { font-size: 16px; color: var(--text-primary); }
.action-tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(0, 1fr)); gap: 8px; margin-top: 12px; }
.action-tile {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; min-height: 76px;
  padding: 8px 4px; border: 0; border-radius: 16px; background: var(--bg-subtle); color: var(--text-primary);
  font-size: 14px; font-weight: 700; text-decoration: none; text-align: center;
}
.action-tile:hover { border-color: transparent; filter: brightness(0.98); }
.group-rows { display: flex; flex-direction: column; gap: 2px; margin-top: 4px; }

/* The map couldn't load: a small note on the map, with Retry */
.map-fail {
  position: absolute; left: 12px; right: 12px; bottom: 90px; z-index: 530; display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; border-radius: 16px; background: var(--bg-card); color: var(--text-primary);
  border: 1px solid var(--border-hairline); box-shadow: 0 8px 24px rgba(18, 32, 40, 0.2); font-size: 14px; font-weight: 600;
}
.map-fail[hidden] { display: none; }
.map-fail span { flex: 1; }
.map-fail button { min-height: 44px; flex-shrink: 0; }

/* Floating Haven pill, settings and chat: only on phones' Map tab (below) */
.map-top { display: none; }
.map-badge {
  position: absolute; top: -4px; right: -4px; min-width: 22px; height: 22px; padding: 0 6px; border-radius: 999px;
  display: flex; align-items: center; justify-content: center; background: var(--accent-terracotta-strong); color: #FFFFFF;
  font-size: 14px; font-weight: 800; border: 2px solid var(--bg-card);
}
.map-badge[hidden] { display: none; }
.map-haven-pill {
  display: inline-flex; align-items: center; gap: 6px; min-height: 48px; max-width: calc(100% - 128px); padding: 0 16px;
  border-radius: 999px; background: var(--bg-card); color: var(--text-primary); border: 1px solid var(--border-hairline);
  box-shadow: 0 2px 8px rgba(18, 32, 40, 0.18); font-size: 16px; font-weight: 800;
}

/* Sign-in: the welcome picture above the card */
.auth-screen { flex-direction: column; gap: 4px; }
.auth-art { width: 150px; height: 150px; object-fit: contain; flex-shrink: 0; }
@media (max-height: 700px) { .auth-art { display: none; } }

@media (max-width: 899px) {
  /* Map tab: no top bar (as Android); the SOS stays in the bottom bar */
  body[data-section="map"] .topbar { height: 0; min-height: 0; padding: 0; border: 0; box-shadow: none; overflow: visible; }
  body[data-section="map"] .topbar .brand-lockup,
  body[data-section="map"] .topbar #havenChip,
  body[data-section="map"] .topbar #inviteBtn,
  body[data-section="map"] .topbar #chatToggleBtn { display: none; }
  body[data-section="map"] .map-top {
    display: flex; align-items: center; justify-content: space-between; gap: 8px;
    position: absolute; top: 10px; left: 10px; right: 10px; z-index: 525;
  }
  body[data-section="map"] .map-top .round-ctl { position: relative; flex-shrink: 0; }
  body[data-section="map"] .map-controls { top: 68px; }
  body[data-section="map"] .map-status { top: 68px; }
  body.map-short[data-section="map"] .map-status { display: none; }
  .avatar-wrap .bat-badge { font-size: 14px; line-height: 18px; right: -10px; }
  #sosHeaderBtn.cancel-mode { font-size: 16px; letter-spacing: 0; }
}
@media (prefers-reduced-motion: no-preference) {
  .icon-tabs button { transition: flex-grow 220ms ease, background-color 220ms ease, color 220ms ease; }
}
/* Phones: three round map buttons, as Android (centre on me, map style, emergency places); "show everyone" stays on wide windows */
@media (max-width: 899px) { #fitAllBtn { display: none; } }
/* Phone on its side: the map is short, so its round buttons sit in a row (as on short upright maps) */
@media (max-width: 899px) and (max-height: 500px) and (orientation: landscape) {
  .map-controls { flex-direction: row; }
}
