/* ─── Profile page (profile.html / profile.js) ─────────────────────────
   An identity header (photo, name, @username, counts), then one section
   at a time behind tabs: Profile · Account · Preferences · Connections ·
   AI · Your apps. Uses style.css tokens; nothing here may be wider than
   the screen (the tab bar scrolls inside itself). */

.pf-main { max-width: 760px; margin: 0 auto; padding: 1.5rem 1.25rem 3rem; overflow-x: clip; }
.pf-back { display: inline-block; margin-bottom: 1rem; color: var(--text-muted); text-decoration: none; font-size: 0.88rem; }
.pf-back:hover { color: var(--primary); }

/* ─── Identity header ─── */
.pf-hero { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; grid-template-areas: "avatar text actions" "avatar stats actions";
  gap: 0.6rem 1.25rem; align-items: center; padding: 1.4rem; border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface); }
.pf-hero-avatar { grid-area: avatar; position: relative; display: block; cursor: pointer; border-radius: 50%; }
.pf-hero-avatar .avatar-preview { width: 96px; height: 96px; font-size: 2rem; }
.pf-hero-avatar:focus-within .avatar-preview, .pf-hero-avatar:hover .avatar-preview { box-shadow: 0 0 0 3px var(--primary-border); }
.pf-hero-camera { position: absolute; right: -2px; bottom: -2px; width: 32px; height: 32px; border-radius: 50%;
  display: grid; place-items: center; background: var(--primary); color: #fff; border: 3px solid var(--surface); }
.pf-hero-camera svg { width: 16px; height: 16px; }
.pf-hero-text { grid-area: text; min-width: 0; align-self: end; }
.pf-hero-name { font-size: 1.45rem; font-weight: 700; letter-spacing: -0.01em; margin: 0; overflow-wrap: anywhere; line-height: 1.2; }
.pf-hero-handle { margin: 0.15rem 0 0; color: var(--text-muted); font-size: 0.95rem; overflow-wrap: anywhere; }
.pf-hero-bio { margin: 0.45rem 0 0; font-size: 0.95rem; line-height: 1.45; overflow-wrap: anywhere; }
.pf-hero-stats { grid-area: stats; align-self: start; margin: 0; display: flex; flex-wrap: wrap; gap: 0.25rem 1.1rem; font-size: 0.88rem; color: var(--text-muted); }
.pf-hero-stats b { color: var(--text); font-weight: 700; }
.pf-hero-stats small { font-size: inherit; }
.pf-hero-actions { grid-area: actions; display: flex; flex-direction: column; gap: 0.5rem; align-items: stretch; }
.pf-hero-actions .btn-ghost, .pf-hero-actions .btn-primary { display: inline-flex; align-items: center; justify-content: center; width: auto;
  padding: 0.6rem 1rem; font-size: 0.875rem; text-align: center; text-decoration: none; white-space: nowrap; }
.pf-hero-actions [hidden] { display: none !important; }

/* ─── Install the app (P16) ─── */
.pf-install { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; grid-template-areas: "icon text action" "hint hint hint";
  align-items: center; gap: 0.35rem 0.9rem; margin-top: 1rem; padding: 1rem 1.1rem;
  border: 1px solid var(--primary-border); border-radius: var(--radius-lg); background: var(--surface); }
.pf-install[hidden] { display: none; }
.pf-install-icon { grid-area: icon; align-self: start; width: 44px; height: 44px; border-radius: 12px; }
.pf-install-text { grid-area: text; min-width: 0; }
.pf-install-text strong { display: block; font-size: 0.95rem; }
.pf-install-text p { margin: 0.15rem 0 0; color: var(--text-muted); font-size: 0.84rem; line-height: 1.45; }
.pf-install > .btn-primary { grid-area: action; width: auto; padding: 0.6rem 1.1rem; font-size: 0.875rem; white-space: nowrap; }
.pf-install-hint { grid-area: hint; margin: 0.4rem 0 0; color: var(--text-muted); font-size: 0.78rem; line-height: 1.45; text-align: center; }
.pf-install [hidden] { display: none !important; }
/* The APK download: icon, label and "v1.0.0 · 1.1 MB" in one button. */
.pf-apk { display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem; text-decoration: none; }
.pf-apk:hover { text-decoration: none; }
.pf-apk-icon { width: 18px; height: 18px; flex: 0 0 auto; }
.pf-apk-label { font-weight: 600; }
.pf-apk-meta { font-size: 0.75rem; font-weight: 500; opacity: 0.8; padding-left: 0.5rem; border-left: 1px solid currentColor; }
.pf-apk-meta:empty { display: none; }
.pref-row .pf-apk { width: auto; padding: 0.6rem 1.1rem; font-size: 0.875rem; }

/* ─── Tabs ─── */
/* A pill bar on wide screens; a 3 × 2 grid on phones, so every section
   is in sight and nothing scrolls sideways. */
.pf-tabs { position: sticky; top: 0; z-index: 5; margin: 1.25rem -1.25rem 1rem; padding: 0.5rem 1.25rem; background: var(--bg); }
.pf-tabs-scroll { display: flex; gap: 0.35rem; overflow-x: auto; scrollbar-width: none;
  padding: 0.25rem; border: 1px solid var(--border); border-radius: 999px; background: var(--surface); }
.pf-tabs-scroll::-webkit-scrollbar { display: none; }
.pf-tabs button { flex: 1 0 auto; font: inherit; font-size: 0.875rem; font-weight: 500; padding: 0.5rem 0.95rem; border: none; border-radius: 999px;
  background: none; color: var(--text-muted); cursor: pointer; white-space: nowrap; transition: background 0.15s, color 0.15s; }
.pf-tabs button:hover { color: var(--text); }
.pf-tabs button[aria-selected="true"] { background: var(--primary); color: #fff; }
.pf-tabs button:focus-visible { outline: none; box-shadow: var(--focus-ring); }

/* ─── Panels and cards ─── */
.pf-panel { display: grid; gap: 1rem; }
.pf-panel[hidden] { display: none; }
.pf-card { padding: 1.4rem; border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface); min-width: 0; }
.pf-card-title { font-size: 1.05rem; font-weight: 600; margin: 0 0 0.35rem; letter-spacing: -0.01em; }
summary.pf-card-title { cursor: pointer; margin: 0; }
details[open] > summary.pf-card-title { margin-bottom: 0.6rem; }
.blocked-list { list-style: none; padding: 0; margin: 0.8rem 0 0; display: grid; gap: 0.5rem; }
.blocked-list li { display: flex; align-items: center; gap: 0.6rem; }
.blocked-list a { color: var(--text); text-decoration: none; font-weight: 500; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.blocked-list small { color: var(--text-muted); font-weight: 400; }
.pf-note { color: var(--text-muted); font-size: 0.84rem; line-height: 1.5; margin: 0.35rem 0 0; }
.pf-note em { font-style: normal; color: var(--text); }
.pf-note a { color: var(--primary); }
.pf-soon { text-align: center; margin-top: 0.25rem; }

.pf-field { margin-top: 1.1rem; min-width: 0; }
.pf-field > label { display: block; font-size: 0.8rem; font-weight: 600; color: var(--text); margin-bottom: 0.35rem; }
.pf-field input, .pf-handle input { width: 100%; min-width: 0; padding: 0.65rem 0.85rem; background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text); font: inherit; font-size: 0.95rem; transition: border-color 0.15s, box-shadow 0.15s; }
.pf-field input:focus, .pf-handle input:focus { outline: none; border-color: var(--primary); box-shadow: var(--focus-ring); background: var(--surface); }
.pf-handle { display: flex; align-items: stretch; }
.pf-handle-at { display: grid; place-items: center; padding: 0 0.7rem; border: 1px solid var(--border); border-right: none;
  border-radius: var(--radius-sm) 0 0 var(--radius-sm); background: var(--bg); color: var(--text-muted); font-weight: 600; }
.pf-handle input { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.pf-field .handle-suggest { margin-top: 0.5rem; }

.pf-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 0.6rem 1rem; margin-top: 1.2rem; }
.pf-actions .btn-primary, .pf-actions .btn-ghost { width: auto; padding: 0.6rem 1.2rem; font-size: 0.875rem; }
.pf-actions .settings-msg { margin: 0; min-height: 0; flex: 1 1 12rem; }
.pf-actions .settings-msg:empty { display: none; }

/* Photo controls in the Profile tab; the file input itself stays out of the layout. */
.pf-photo { margin-top: 1rem; }
.pf-photo-buttons { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.pf-photo-buttons .btn-ghost { width: auto; padding: 0.55rem 1rem; font-size: 0.85rem; cursor: pointer; }
.pf-photo-buttons [hidden] { display: none !important; }
.pf-photo .settings-msg:empty { display: none; }
.pf-file { position: fixed; left: 0; top: 0; width: 1px; height: 1px; opacity: 0; pointer-events: none; }

.pf-danger { border-color: var(--danger-text); }
.pf-danger summary { color: var(--danger-text); }
.pf-card .profile-grid { margin-top: 1rem; }
.pf-card .included-ai { margin: 0.9rem 0 0; max-width: none; }
.pf-panel .pack-list { display: grid; gap: 1rem; }
.pf-panel .pack-card { margin: 0; }

@media (max-width: 640px) {
  .pf-main { padding: 0.75rem 1rem 2.5rem; }
  .pf-back { margin-bottom: 0.75rem; }
  .pf-hero { grid-template-columns: auto minmax(0, 1fr); grid-template-areas: "avatar text" "stats stats" "actions actions";
    padding: 1.1rem; gap: 0.9rem 1rem; }
  .pf-hero-text { align-self: center; }
  .pf-hero-avatar .avatar-preview { width: 72px; height: 72px; font-size: 1.5rem; }
  .pf-hero-camera { width: 26px; height: 26px; border-width: 2px; }
  .pf-hero-camera svg { width: 14px; height: 14px; }
  .pf-hero-name { font-size: 1.2rem; }
  .pf-hero-handle, .pf-hero-bio { font-size: 0.9rem; }
  .pf-hero-stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0; padding: 0.6rem 0; border-radius: var(--radius-sm); background: var(--bg); }
  .pf-hero-stats span { display: flex; flex-direction: column; align-items: center; gap: 0.1rem; min-width: 0; padding: 0 0.2rem; text-align: center; }
  .pf-hero-stats small { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .pf-hero-stats span + span { border-left: 1px solid var(--border); }
  .pf-hero-stats b { font-size: 1.1rem; }
  .pf-hero-stats small { font-size: 0.72rem; }
  .pf-install { grid-template-columns: auto minmax(0, 1fr); grid-template-areas: "icon text" "action action" "hint hint"; row-gap: 0.75rem; }
  .pf-install > .btn-primary { width: 100%; min-height: 48px; font-size: 0.95rem; margin-top: 0.15rem; }
  .pf-install-hint { margin-top: -0.25rem; }
  .pf-hero-actions .btn-ghost, .pf-hero-actions .btn-primary { width: 100%; }
  .pf-tabs { position: static; margin: 1rem 0 0.9rem; padding: 0; background: none; }
  .pf-tabs-scroll { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0.3rem; border-radius: 14px; overflow: visible; }
  .pf-tabs button { padding: 0.6rem 0.25rem; border-radius: 10px; font-size: 0.82rem; overflow: hidden; text-overflow: ellipsis; }
  .pf-panel { gap: 0.75rem; }
  .pf-card { padding: 1.1rem; }
  .pf-actions .btn-primary { flex: 1 1 auto; }
  .info-list > div { flex-direction: column; gap: 0.15rem; }
  .info-list dd { text-align: left; }
  .profile-grid { grid-template-columns: 1fr; }
  .service-header { flex-wrap: wrap; }
}
/* Very narrow phones: the four stats go 2 × 2. */
@media (max-width: 359px) {
  .pf-hero-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); row-gap: 0.5rem; }
  .pf-hero-stats span:nth-child(3) { border-left: none; }
}
/* Phones under 400px: the version goes under the label. */
@media (max-width: 399px) {
  .pf-install > .pf-apk { flex-wrap: wrap; row-gap: 0.1rem; white-space: normal; padding: 0.6rem 0.75rem; }
  .pf-install > .pf-apk .pf-apk-meta { flex-basis: 100%; text-align: center; border-left: none; padding-left: 0; }
}
