/* Friends on the map (A2): account button, friend markers, the friends panel and the consent dialog.
   Builds on the tokens in map.css. */

[hidden] { display: none !important; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- Map controls ---------- */

#account { position: relative; overflow: visible; }
.account-initials {
  display: grid; place-items: center;
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--c, var(--navy)); color: #fff;
  font-size: 12px; font-weight: 600; letter-spacing: .02em;
}
.control-group:has(#account) { overflow: visible; }
.badge {
  position: absolute; top: -4px; right: -4px;
  min-width: 18px; height: 18px; padding: 0 5px;
  display: grid; place-items: center;
  border-radius: 999px; border: 2px solid #fff;
  background: var(--badge); color: #fff;
  font-size: 10px; font-weight: 700; line-height: 1;
}
#friends-toggle[aria-pressed="true"] { color: var(--accent); }
#friends-toggle[aria-pressed="true"] svg { fill: rgb(var(--accent-rgb) / .15); }

/* Messages from the map must show above the friends panel */
.toast { z-index: 6; }

/* Sharing status pill under the location chip */
.sharing-pill {
  border: 0; font: inherit; font-size: 13px; font-weight: 600;
  color: #fff; background: var(--live);
  display: inline-flex; align-items: center; gap: 7px;
  cursor: pointer;
  -webkit-backdrop-filter: none; backdrop-filter: none;
}
.sharing-pill::before {
  content: ""; width: 7px; height: 7px; border-radius: 50%; background: #fff;
  animation: pulse 1.6s ease-in-out infinite;
}
.sharing-pill.paused { background: #8a6d00; }
.sharing-pill.paused::before { animation: none; opacity: .7; }
.sharing-pill:focus-visible { outline: 3px solid var(--focus-ring); outline-offset: 2px; }

/* ---------- Friend markers on the map ---------- */

.friend-marker {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 0; border: 0; background: none; cursor: pointer;
  font: inherit;
  transition: opacity .3s var(--ease);
}
.friend-avatar {
  display: grid; place-items: center;
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--c); color: #fff;
  border: 3px solid #fff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, .3);
  font-size: 12px; font-weight: 700;
  transition: transform .2s var(--ease);
}
.friend-marker:hover .friend-avatar, .friend-marker:focus-visible .friend-avatar { transform: scale(1.1); }
.friend-marker:focus-visible { outline: none; }
.friend-marker:focus-visible .friend-avatar { box-shadow: 0 0 0 3px rgb(var(--accent-rgb) / .6); }
.friend-label {
  padding: 1px 7px; border-radius: 999px;
  background: var(--glass-solid);
  color: var(--text);
  font-size: 11px; font-weight: 600; white-space: nowrap;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .15);
}
.friend-marker.stale { opacity: .55; }
.friend-marker.stale .friend-avatar { filter: grayscale(.6); }

.sent-pin {
  width: 26px; height: 34px;
  background: var(--c);
  clip-path: path("M13 34C13 34 0 20 0 13a13 13 0 0 1 26 0c0 7-13 21-13 21z");
  box-shadow: 0 2px 6px rgba(0, 0, 0, .3);
}
.sent-pin::after { content: ""; position: absolute; left: 8px; top: 8px; width: 10px; height: 10px; border-radius: 50%; background: #fff; }

/* Friend popup */
.friend-popup .maplibregl-popup-content {
  padding: 14px;
  border-radius: var(--radius);
  background: var(--glass-solid);
  -webkit-backdrop-filter: var(--blur);
  backdrop-filter: var(--blur);
  box-shadow: var(--shadow);
  font: inherit;
}
.friend-popup .maplibregl-popup-close-button { font-size: 18px; width: 28px; height: 28px; border-radius: 0 var(--radius) 0 8px; }
.friend-popup.maplibregl-popup-anchor-bottom .maplibregl-popup-tip { border-top-color: var(--glass-solid); }
.friend-popup.maplibregl-popup-anchor-top .maplibregl-popup-tip { border-bottom-color: var(--glass-solid); }
.popup-head { display: flex; align-items: center; gap: 10px; margin: 0 18px 12px 0; }
.popup-head strong { display: block; font-size: 15px; }
.popup-meta { font-size: 12px; color: var(--muted); }
.popup-card .signal-row { margin-bottom: 10px; }

/* ---------- Panel (bottom sheet on phones, side card on larger screens) ---------- */

.sheet {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  max-height: min(78vh, 720px);
  display: flex; flex-direction: column;
  border: 0;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  background: var(--glass-thick);
  -webkit-backdrop-filter: var(--blur-thick);
  backdrop-filter: var(--blur-thick);
  box-shadow: var(--shadow-sheet);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 5;
  transform: translateY(105%);
  transition: transform var(--dur-slow) var(--ease-sheet);
}
.sheet.open { transform: none; }
.sheet:not(.open) { pointer-events: none; }
@media (min-width: 700px) {
  .sheet {
    left: var(--gutter); right: auto; bottom: max(16px, env(safe-area-inset-bottom));
    width: 380px;
    max-height: calc(100vh - 92px - max(16px, env(safe-area-inset-bottom)));
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    transform: translateY(24px) scale(.98); opacity: 0;
    transition: transform var(--dur) var(--ease-sheet), opacity var(--dur) var(--ease);
  }
  .sheet.open { transform: none; opacity: 1; }
}

.sheet-header {
  display: flex; align-items: center; gap: 4px;
  padding: 8px 12px 10px var(--space-5);
  border-bottom: 1px solid var(--separator);
}
.sheet-header h2 { flex: 1; margin: 0; font-size: var(--text-title); font-weight: 700; letter-spacing: var(--tracking-title); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sheet-icon {
  width: 36px; height: 36px; flex: none;
  display: grid; place-items: center;
  border: 0; border-radius: 50%;
  background: var(--separator-soft); color: var(--text);
  cursor: pointer;
}
.sheet-back { margin-left: -8px; background: none; }
.sheet-icon svg, .icon-btn svg, .chip-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.sheet-icon:focus-visible, .icon-btn:focus-visible, .btn:focus-visible, .chip-btn:focus-visible, .link:focus-visible { outline: 3px solid var(--focus-ring); outline-offset: 1px; }

.sheet-body {
  overflow-y: auto; overscroll-behavior: contain;
  padding: var(--space-4) var(--space-5) var(--space-5);
  font-size: 14px; line-height: 1.4;
}
/* Moving between the panel's screens (friends list ↔ chat): the new screen slides in from the side it lives on */
.sheet-body.view-in > * { animation: view-in var(--dur) var(--ease-out) both; }
.sheet-body.view-in.back > * { animation-name: view-back; }
@keyframes view-in { from { opacity: 0; transform: translateX(24px); } }
@keyframes view-back { from { opacity: 0; transform: translateX(-24px); } }
.sheet-body p { margin: 0 0 12px; }
.intro { color: var(--text); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.grow { flex: 1; min-width: 0; }
.grow strong, .grow > span, .grow small { display: block; overflow: hidden; text-overflow: ellipsis; }
.grow small, .grow > span { font-size: 13px; color: var(--muted); }

.demo-note {
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(240, 138, 28, .12);
  color: #7a4300;
  font-size: 13px;
}

.group { padding: 14px 0 4px; border-top: 1px solid var(--separator); }
.group h3 { margin: 0 0 10px; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 40px; padding: 0 16px;
  border: 0; border-radius: 10px;
  background: var(--fill-2); color: var(--text);
  font: inherit; font-size: 15px; font-weight: 600; text-decoration: none;
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease), transform .12s var(--ease-out);
}
.btn:hover { background: var(--fill-hover); }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-hover); }
.btn.danger { color: var(--destructive); }
.btn.small { height: 32px; padding: 0 12px; font-size: 13px; border-radius: 8px; }
.btn.block { width: 100%; }
.button-row { display: flex; flex-wrap: wrap; gap: 8px; }
.link { border: 0; background: none; padding: 0; color: var(--accent); font: inherit; cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }
.sheet-body a, .dialog a { color: var(--accent); }

.icon-btn {
  position: relative;
  width: 36px; height: 36px; flex: none;
  display: grid; place-items: center;
  border: 0; border-radius: 50%;
  background: var(--separator-soft); color: var(--text);
  cursor: pointer;
}
.icon-btn:hover { background: var(--fill-hover); }
.icon-btn .badge { top: -3px; right: -3px; }

.chip-btn {
  display: inline-flex; align-items: center; gap: 5px;
  height: 32px; padding: 0 12px;
  border: 1px solid rgb(var(--navy-rgb) / .14); border-radius: 999px;
  background: #fff; color: var(--text);
  font: inherit; font-size: 13px; font-weight: 500; white-space: nowrap;
  cursor: pointer;
}
.chip-btn:hover { border-color: var(--accent); color: var(--accent); }
.chip-btn svg { width: 14px; height: 14px; stroke: var(--accent); }
.signal-row { display: flex; flex-wrap: wrap; gap: 6px; }

/* Forms */
.form { display: flex; flex-direction: column; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 5px; font-size: 13px; font-weight: 600; color: var(--muted); }
.field input, .inline-form input {
  height: 42px; padding: 0 12px;
  border: 1px solid rgb(var(--navy-rgb) / .16); border-radius: 10px;
  background: #fff; color: var(--text);
  font: inherit; font-size: 16px; font-weight: 400;
}
.field input:focus, .inline-form input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgb(var(--accent-rgb) / .25); }
.inline-form { display: flex; gap: 8px; margin-bottom: 8px; }
.inline-form input { flex: 1; min-width: 0; }
.check, .radio { display: flex; align-items: flex-start; gap: 8px; font-size: 14px; cursor: pointer; }
.check input, .radio input { margin: 2px 0 0; width: 17px; height: 17px; accent-color: var(--accent); flex: none; }
.form-error { margin: 0 0 8px; padding: 8px 10px; border-radius: 8px; background: rgba(229, 54, 47, .1); color: var(--destructive); font-size: 13px; }
.form-error.info { background: rgb(var(--accent-rgb) / .1); color: #0b4f99; }
.hint { font-size: 13px; color: var(--muted); }

.segmented {
  display: grid; grid-template-columns: 1fr 1fr;
  padding: 3px; margin-bottom: 14px;
  border-radius: 10px; background: var(--fill-2);
}
.segmented button {
  height: 32px; border: 0; border-radius: 8px; background: none;
  font: inherit; font-size: 14px; font-weight: 600; color: var(--muted); cursor: pointer;
}
.segmented button[aria-selected="true"] { background: #fff; color: var(--text); box-shadow: 0 1px 3px var(--stroke); }

/* Switch */
.switch-row { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; cursor: pointer; }
.switch-row strong { font-size: 15px; }
input[role="switch"] {
  appearance: none; -webkit-appearance: none;
  position: relative; flex: none;
  width: 51px; height: 31px; margin: 0;
  border-radius: 999px; background: rgb(var(--navy-rgb) / .18);
  cursor: pointer;
  transition: background .2s var(--ease);
}
input[role="switch"]::after {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 27px; height: 27px; border-radius: 50%;
  background: #fff; box-shadow: 0 2px 4px rgba(0, 0, 0, .25);
  transition: transform .2s var(--ease);
}
input[role="switch"]:checked { background: var(--switch-on); }
input[role="switch"]:checked::after { transform: translateX(20px); }
input[role="switch"]:focus-visible { outline: 3px solid var(--focus-ring); outline-offset: 2px; }

.audience { border: 0; margin: 0 0 8px; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.checklist { list-style: none; margin: 2px 0 0 25px; padding: 0; display: flex; flex-direction: column; gap: 6px; }

/* Lists */
.list { list-style: none; margin: 0; padding: 0; }
.row { display: flex; align-items: center; gap: 10px; padding: 8px 0; }
.row + .row { border-top: 1px solid var(--separator-soft); }
.request { background: rgb(var(--accent-rgb) / .06); margin: 0 -10px 6px; padding: 8px 10px; border-radius: 10px; }
.empty { padding: 6px 0; }
.me-row { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.me-row .grow strong { font-size: 16px; }

.avatar {
  display: grid; place-items: center; flex: none;
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--c); color: #fff;
  font-size: 13px; font-weight: 700;
}
.me-avatar { width: 44px; height: 44px; font-size: 15px; }

/* Chat (iMessage-style bubbles) */
.chat-log {
  list-style: none; margin: 0 0 12px; padding: 2px 8px 4px;
  display: flex; flex-direction: column;
  min-height: 160px; max-height: 42vh; overflow-y: auto;
}
.chat-log .empty { align-self: center; margin-top: 40px; }
.chat-time {
  align-self: center;
  margin: 14px 0 4px;
  font-size: 11px; font-weight: 500; color: var(--muted);
}
.chat-time:first-child { margin-top: 2px; }
.bubble {
  position: relative;
  max-width: 75%;
  margin-top: 8px;
  padding: 7px 13px;
  border-radius: 19px;
  display: flex; flex-direction: column; gap: 1px;
  font-size: 15px; line-height: 1.32;
}
.bubble.cont, .chat-time + .bubble { margin-top: 2px; }
.bubble.mine { align-self: flex-end; background: var(--accent); color: #fff; }
.bubble.theirs { align-self: flex-start; background: #eceef0; color: var(--text); }   /* opaque, so the tail doesn't show a seam */
/* The curled tail on the last bubble of a group, drawn in the bubble's own colour */
.bubble.tail::before {
  content: ""; position: absolute; bottom: 0;
  width: 20px; height: 20px;
  background: inherit;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3E%3Cpath d='M0 0H13C13 9 15 16 20 20C15 20.5 10 19.5 6.5 17.5C5 19 2.5 20 0 20Z'/%3E%3C/svg%3E") no-repeat center / 100% 100%;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3E%3Cpath d='M0 0H13C13 9 15 16 20 20C15 20.5 10 19.5 6.5 17.5C5 19 2.5 20 0 20Z'/%3E%3C/svg%3E") no-repeat center / 100% 100%;
}
.bubble.mine.tail::before { right: -6px; }
.bubble.theirs.tail::before { left: -6px; transform: scaleX(-1); }
.bubble .text { position: relative; white-space: pre-wrap; overflow-wrap: anywhere; }
.bubble.signal .text { font-weight: 600; }
.signal-tag { position: relative; font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; opacity: .7; }
.bubble .link { position: relative; align-self: flex-start; font-size: 14px; font-weight: 600; text-decoration: none; }
.bubble.mine .link { color: #fff; }
.receipt { align-self: flex-end; margin: 3px 4px 0 0; font-size: 11px; font-weight: 500; color: var(--muted); }
.bubble.pop { animation: bubble-pop .32s cubic-bezier(.2, .9, .3, 1.15); }
.bubble.mine.pop { transform-origin: 100% 100%; }
.bubble.theirs.pop { transform-origin: 0 100%; }
@keyframes bubble-pop { from { opacity: 0; transform: scale(.8) translateY(8px); } }
.chat-form { margin: 12px 0 0; }
.chat-form input { border-radius: 21px; }
.chat-form .btn { border-radius: 21px; }

/* ---------- Consent dialog ---------- */

.dialog {
  width: min(420px, calc(100% - 32px));
  padding: 22px;
  border: 0; border-radius: var(--radius-lg);
  background: var(--glass-solid);
  -webkit-backdrop-filter: var(--blur-thick);
  backdrop-filter: var(--blur-thick);
  box-shadow: 0 20px 60px rgb(var(--navy-rgb) / .3);
  color: var(--text);
  font-size: 14px; line-height: 1.45;
}
.dialog::backdrop { background: rgb(var(--navy-rgb) / .35); -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px); }
.dialog[open] { animation: alert-in var(--dur) var(--ease-out); }
.dialog[open]::backdrop { animation: fade var(--dur) var(--ease); }
@keyframes alert-in { from { opacity: 0; transform: scale(1.08); } }
.dialog h2 { margin: 0 0 12px; font-size: var(--text-title); letter-spacing: var(--tracking-title); }
.dialog ul { margin: 0 0 12px; padding-left: 20px; display: flex; flex-direction: column; gap: 6px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
