/* Youpi P1 · Amigos: the "Círculos | Amigos" tabs, the friends sheet (same dialog look as the Círculo: dialog.circle-sheet),
 * search by @, requests, the friends list, the invite link/QR, and the request badges on the Círculo entry points.
 * Loaded at the uppi:css:p1 anchor, BEFORE v140/v141/wave1: rules that touch shared classes use two classes or more.
 * Tokens: the --circle-* set of v140-circle.css (light and dark). */

/* ---------- Tabs (top of both sheets) ---------- */
.friends-tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; border-radius: 16px; background: var(--circle-raised); }
.friends-tabs .friends-tab {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 0;
  min-height: 44px;
  margin: 0;
  padding: 0 12px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--circle-muted);
  font: 700 14px/1.2 'DM Sans', system-ui, sans-serif;
  cursor: pointer;
}
.friends-tabs .friends-tab > .ui-icon { width: 18px; height: 18px; flex: 0 0 18px; }
.friends-tabs .friends-tab[aria-current="page"] { background: var(--circle-surface); color: var(--circle-ink); box-shadow: 0 1px 2px rgba(15, 26, 46, .1), 0 0 0 1px var(--circle-line); cursor: default; }
.friends-tabs .friends-tab[aria-current="page"] > .ui-icon { color: var(--circle-accent); }
.friends-tabs .friends-tab:focus-visible { outline: 3px solid var(--circle-accent); outline-offset: 2px; }
@media (hover: hover) { .friends-tabs .friends-tab:not([aria-current="page"]):hover { background: var(--circle-accent-soft); color: var(--circle-accent); } }
.friends-badge {
  display: inline-grid;
  place-items: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 10px;
  background: var(--circle-friends-ink, #c4381f);
  color: #fff;
  font: 800 11.5px/1 'DM Sans', system-ui, sans-serif;
}
:root[data-theme=dark] .friends-badge { color: #2b0e07; }

/* ---------- Sheet body ---------- */
.friends-sheet .circle-sheet-body { gap: 18px; }
.friends-sheet .friends-status[data-tone="success"] { color: var(--circle-live-ink); font-weight: 700; }
.friends-sheet :is(.friends-status, .friends-search-status)[data-tone="error"] { color: var(--circle-danger); font-weight: 700; }
:root[data-theme=dark] .friends-sheet :is(.friends-status, .friends-search-status)[data-tone="error"] { color: #ff9b89; }
.friends-section { display: grid; gap: 8px; }
.friends-section > h3, .friends-card-head h3 {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  color: var(--circle-muted);
  font: 700 12px/1.3 'DM Sans', system-ui, sans-serif;
  letter-spacing: .05em;
  text-transform: uppercase;
}
.friends-count { display: inline-grid; place-items: center; min-width: 22px; height: 20px; padding: 0 6px; border-radius: 10px; background: var(--circle-accent-soft); color: var(--circle-accent); font-size: 11.5px; letter-spacing: 0; }
.friends-incoming .friends-count { background: var(--circle-friends-soft); color: var(--circle-friends-ink); }
.friends-card { display: grid; gap: 12px; padding: 14px; border: 1px solid var(--circle-line); border-radius: 18px; background: var(--circle-surface); }
.friends-card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 24px; }
.friends-card-head .circle-btn-text { min-height: 44px; margin: -10px -6px -10px 0; font-size: 13.5px; }
.friends-card-text { margin: 0; color: var(--circle-muted); font-size: 13.5px; line-height: 1.45; }
.friends-sheet .friends-card > .circle-btn { width: 100%; }
.friends-sheet .friends-note { display: flex; gap: 8px; align-items: flex-start; }
.friends-sheet .friends-note .ui-icon { width: 18px; height: 18px; flex: 0 0 18px; margin-top: 1px; color: var(--circle-accent); }
.friends-sheet .friends-empty { margin: 0; }
.friends-foot-actions { display: flex; justify-content: center; }
.friends-renew-note { justify-content: center; margin-top: -14px !important; }

/* @ field: a fixed "@" before the input (search and "Seu @") */
.friends-at-field {
  display: flex;
  align-items: center;
  min-width: 0;
  min-height: 48px;
  border: 1px solid var(--circle-line);
  border-radius: 14px;
  background: var(--circle-surface);
  color: var(--circle-ink);
}
.friends-at-field:focus-within { border-color: var(--circle-accent); outline: 3px solid color-mix(in srgb, var(--circle-accent) 40%, transparent); }
.friends-at { flex: none; padding: 0 2px 0 14px; color: var(--circle-muted); font: 700 16px/1 'DM Sans', system-ui, sans-serif; }
.friends-sheet .friends-at-field input {
  flex: 1 1 auto;
  width: 100%;
  min-width: 0;
  min-height: 46px;
  margin: 0;
  padding: 0 14px 0 2px;
  border: 0;
  border-radius: 14px;
  background: transparent;
  color: var(--circle-ink);
  font: 500 16px 'DM Sans', system-ui, sans-serif;
  outline: none;
}
.friends-sheet .circle-field .friends-at-field input:not([type="range"]) { min-height: 46px; padding: 0 14px 0 2px; border: 0; background: transparent; }
.friends-sheet .friends-at-field input:focus-visible, .friends-sheet .circle-field .friends-at-field input:focus-visible { outline: none; }
.friends-at-field-lg .friends-at, .friends-sheet .friends-at-field-lg input { font-size: 18px; font-weight: 700; }
.friends-sheet .friends-at-field input[aria-invalid="true"] { color: var(--circle-danger); }
#friends-handle-hint[data-tone="error"] { color: var(--circle-danger); font-weight: 700; }
:root[data-theme=dark] #friends-handle-hint[data-tone="error"] { color: #ff9b89; }
.friends-search { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; margin: 0; }
.friends-sheet .friends-search-go { padding: 0 14px; }
.friends-hint { margin-top: -4px !important; }

/* Search result / invite sender: initials only (no photo before the request is accepted) */
.friends-result {
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr);
  align-items: center;
  gap: 8px 12px;
  padding: 12px;
  border-radius: 16px;
  background: var(--circle-raised);
}
.friends-result-action { grid-column: 1 / -1; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.friends-result-action > .circle-btn-primary { flex: 1 1 auto; }
.friends-result-note { grid-column: 1 / -1; margin: 0; color: var(--circle-live-ink); font-size: 13px; font-weight: 700; line-height: 1.4; }
.friends-who { background: var(--circle-accent-soft); }
.friends-row-main { min-width: 0; }
.friends-row-main strong { display: block; overflow: hidden; font-size: 15px; text-overflow: ellipsis; white-space: nowrap; }
.friends-row-main small { display: block; margin-top: 2px; overflow: hidden; color: var(--circle-muted); font-size: 12.5px; text-overflow: ellipsis; white-space: nowrap; }
.friends-inline-handle { color: var(--circle-muted); font-weight: 500; }
.friends-chip { display: inline-flex; align-items: center; gap: 6px; min-height: 36px; padding: 0 12px; border-radius: 18px; background: var(--circle-live-soft); color: var(--circle-live-ink); font-size: 13px; font-weight: 700; line-height: 1.3; }
.friends-chip .ui-icon { width: 16px; height: 16px; flex: 0 0 16px; }
.friends-chip[data-tone="muted"] { min-height: 0; padding: 8px 12px; border-radius: 12px; background: var(--circle-surface); color: var(--circle-muted); }

/* Requests (received, sent, blocked people) */
.friends-list { display: grid; gap: 8px; margin: 0; padding: 0; list-style: none; }
.friends-request {
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr);
  align-items: center;
  gap: 10px 12px;
  padding: 12px;
  border: 1px solid var(--circle-line);
  border-radius: 16px;
  background: var(--circle-surface);
}
.friends-incoming .friends-request { border-color: color-mix(in srgb, var(--circle-friends-ink) 35%, var(--circle-line)); background: color-mix(in srgb, var(--circle-friends-soft) 55%, var(--circle-surface)); }
.friends-row-actions { grid-column: 1 / -1; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.friends-sheet .friends-row-actions > .circle-btn { min-height: 44px; padding: 0 14px; }
.friends-sheet .friends-row-actions > .circle-btn-primary, .friends-sheet .friends-row-actions > .circle-btn-secondary { flex: 1 1 88px; }
.friends-sheet .friends-row-actions > .circle-btn-text { margin-left: auto; }
.friends-incoming .friends-row-actions > [data-friends-confirm] { color: var(--circle-danger); }
:root[data-theme=dark] .friends-incoming .friends-row-actions > [data-friends-confirm] { color: #ff9b89; }
.friends-request.is-outgoing, .friends-request.is-blocked { grid-template-columns: 40px minmax(0, 1fr) auto; }
/* Requests say who and how: the second line wraps instead of being cut ("@ana · enviado há 2 min"). */
.friends-request .friends-row-main small { white-space: normal; overflow-wrap: anywhere; }
.friends-request.is-outgoing .friends-row-actions, .friends-request.is-blocked .friends-row-actions { grid-column: auto; }

/* Friends list (rows open the friend) */
.friends-sheet .friends-row { grid-template-columns: 40px minmax(0, 1fr) 16px; }
.friends-sheet .friends-friends { margin: 0 -8px; }

/* Seu @ */
.friends-handle { margin: -4px 0 0; overflow-wrap: anywhere; color: var(--circle-ink); font: 700 20px/1.2 'Bricolage Grotesque', 'DM Sans', sans-serif; letter-spacing: -.01em; }
.friends-sheet .friends-switch input { accent-color: var(--circle-button); }

/* Invite link / QR */
.friends-qr { display: grid; justify-items: center; gap: 8px; margin: 0; }
.friends-qr-code { width: min(216px, 64vw); aspect-ratio: 1; overflow: hidden; border: 1px solid var(--circle-line); border-radius: 18px; background: #fff; }
.friends-qr-code svg { display: block; width: 100%; height: 100%; }
.friends-qr-code[data-loading="true"] { background: linear-gradient(90deg, #f1f3f8, #fff, #f1f3f8); }
:root[data-theme=dark] .friends-qr-code { border-color: transparent; box-shadow: 0 0 0 4px #fff; }
.friends-qr figcaption { color: var(--circle-muted); font-size: 12.5px; }

/* One friend */
.friends-hero { grid-template-columns: 64px minmax(0, 1fr); }
.friends-sheet .circle-foot [data-friends-confirm^="block:"] { color: var(--circle-danger); }
:root[data-theme=dark] .friends-sheet .circle-foot [data-friends-confirm^="block:"] { color: #ff9b89; }
.friends-sheet .circle-foot [data-friends-confirm^="block:"] .ui-icon { width: 16px; height: 16px; }

/* Both tabs keep one height, so switching Círculos ↔ Amigos does not jump (views without tabs size to their content). */
@media (max-width: 600px) {
  html body dialog.circle-sheet:has(.friends-tabs) { min-height: min(620px, 82dvh); }
}
@media (min-width: 601px) {
  html body dialog.circle-sheet:has(.friends-tabs) { min-height: min(620px, calc(100dvh - 40px)); }
}
@media (max-width: 359px) {
  .friends-tabs .friends-tab { gap: 6px; padding: 0 8px; }
  .friends-sheet .friends-search-go { padding: 0 12px; }
}

/* ---------- Request badges on the Círculo entry points (friends.mjs sets data-friend-requests) ---------- */
html body.map-shell #mobile-nav .circle-menu-entry[data-friend-requests] { position: relative; }
html body.map-shell #mobile-nav .circle-menu-entry[data-friend-requests]::before {
  content: attr(data-friend-requests);
  position: absolute;
  top: 5px;
  left: 26px;
  display: grid;
  place-items: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--circle-friends-ink, #c4381f);
  box-shadow: 0 0 0 2px var(--circle-surface);
  color: #fff;
  font: 800 10.5px/1 'DM Sans', system-ui, sans-serif;
  pointer-events: none;
}
html body .map-panel .circle-pill[data-friend-requests] .circle-pill-open { position: relative; }
html body .map-panel .circle-pill[data-friend-requests] .circle-pill-open::after {
  content: '';
  position: absolute;
  right: 5px;
  bottom: 6px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--circle-friends-ink, #c4381f);
  box-shadow: 0 0 0 2px var(--circle-surface);
  pointer-events: none;
}
:root[data-theme=dark] body.map-shell #mobile-nav .circle-menu-entry[data-friend-requests]::before { color: #2b0e07; }
