/* ─── Profile screens — page-scoped layout glue ──────────────────────────────
   Everything that *is* a component now lives in the CityFox library. This
   file holds only:
   - the page shell shared by profile / settings / routes / goals
   - per-page layout helpers (grids and stacks) that compose published
     components but aren't components themselves
   When you reach for a token, color, or chrome here, push it down to the
   library instead.
   ────────────────────────────────────────────────────────────────────────── */

html, body {
  margin: 0;
  background: var(--surface-page);
  color: var(--text-body);
  font-family: var(--font-family-text);
  -webkit-font-smoothing: antialiased;
}

/* Honour the [hidden] attribute even when a published component sets
   `display: flex` on the same element (cf-list-item-content does). Without
   this the in-flight edit form on Settings renders next to the read-only
   row instead of replacing it. */
[hidden] { display: none !important; }

/* Anchor-styled buttons (e.g. Done on Goals, See all links) shouldn't
   carry the default browser underline. */
a.cf-btn { text-decoration: none; }

/* ─── Featured-routes panel ─────────────────────────────────────────────────
   Partial overlay below the map header: covers the map content area while the
   header + tabs stay visible/clickable. `top` is set in JS to the live header
   height so the panel starts exactly under the tab bar. */
.featured-panel {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  top: 0;                       /* JS overrides with the header height */
  z-index: 500;                /* above the map, below modals/auth overlay */
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--surface-page);
}
.featured-panel[hidden] { display: none; }
/* While Featured is active, hide the route-planner chrome that otherwise
   floats above the map (and would bleed over this panel): the route top
   sheet and the map-tap hint. */
body.featured-open #routePanel,
body.featured-open #mapTapHint,
body.featured-open .leaflet-control-container { display: none !important; }
.featured-panel .cf-page-body {
  display: flex; flex-direction: column;
  gap: var(--scale-400);
  /* Tighter side padding than the profile screens so the cards are wider. */
  padding: var(--scale-400) var(--scale-300) var(--scale-1600);
}
/* Cards fill the equally-padded column (the library default pins a fixed
   mobile-frame width, which left them off-centre in the panel). */
.featured-panel .cf-card { width: auto; margin: 0; }
/* (Legacy override `.featured-panel .cf-card.activity .cf-card-meta {
   flex-direction: column }` removed — featured cards now render as
   `.cf-card.shop`, which has its own header layout via `.cf-card-header` +
   `.cf-card-toprow`. The activity-card override no longer applies.) */

/* Featured filter trigger chips (Sort by / City / Type / Loop) — a single
   horizontal, scrollable row pinned to the top of the panel. Each chip opens
   the full filter sheet (#featuredFilterSheet); Loop toggles directly. Built by
   app.js _renderFeaturedFilters. The dropdowns are NOT inside this bar anymore
   (they're a separate full sheet), so the row can scroll horizontally without
   clipping anything. */
.featured-filters {
  display: flex; gap: var(--scale-200); align-items: center;
  padding: var(--scale-300);
  position: sticky; top: 0; z-index: 20;
  background: var(--surface-page);
  border-bottom: var(--border-w-sm) solid var(--border-subtle);
  overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none;
}
.featured-filters::-webkit-scrollbar { display: none; }
.featured-filters[hidden] { display: none; }
.featured-filters .ff-chip { flex-shrink: 0; }
/* Icon-only "general filter" chip on the left of the filter bar (matches the
   leftmost slider icon in the Figma frame). Square, no text gap, same height
   as the text chips so the row aligns. */
.featured-filters .ff-chip.ff-chip-icon {
  width: 40px;
  padding: 0;
  justify-content: center;
}
.featured-filters .ff-chip.ff-chip-icon .ph { font-size: 18px; }

/* ─── Featured-route deep-link preview (#/featured/<id>) — full-screen view ──
   body.featured-link-open turns the main screen into a route preview: the top
   bar shrinks to Back + Share (quiz-open pattern), the live map strip (pan +
   zoom) fills the top ~45%, and a fixed bottom panel carries the route info.
   The Start CTA is pinned to the panel's bottom — the info scrolls, it never
   does. Above the map layers and featured panel (500), below modals (1400). */
body.featured-link-open .route-panel { display: none; }
body.featured-link-open .app-top-bar .cf-top-bar-goal-right,
body.featured-link-open .app-top-bar .app-tabs-row,
body.featured-link-open .app-top-bar #coinsDisplay { display: none !important; }
body.featured-link-open .app-feedback-btn { display: none !important; }
/* My-location stays available on the preview's map strip — lifted above the
   bottom panel, same pattern as body.quiz-open lifts it above the quiz sheet. */
body.featured-link-open .app-locate-btn {
  bottom: calc(55vh + var(--scale-400));
  bottom: calc(55dvh + var(--scale-400));
  top: auto;
}
/* Back + Share surface only in this mode (base rule mirrors .app-quiz-back-btn). */
.app-top-bar .app-flp-back-btn,
.app-top-bar .app-flp-share-btn { display: none; }
body.featured-link-open .app-top-bar .app-flp-back-btn { display: inline-flex; gap: var(--scale-200); }
body.featured-link-open .app-top-bar .app-flp-share-btn { display: inline-flex; margin-left: auto; }
body.featured-link-open .app-top-bar .app-flp-share-btn i { font-size: var(--scale-600); }

.featured-link-preview {
  position: fixed; left: 0; right: 0; bottom: 0;
  z-index: 600;
  height: 55vh; height: 55dvh;      /* map keeps a hair under half the screen */
  display: flex; flex-direction: column;
  background: var(--surface-page);
  border-radius: var(--radius-xlg) var(--radius-xlg) 0 0;
  box-shadow: var(--shadow-up);
}
.featured-link-preview[hidden] { display: none; }
/* Scrollable info area — expanding Show more / How it works scrolls here
   while the CTA below stays pinned. */
.flp-scroll {
  flex: 1 1 auto; min-height: 0;
  overflow-y: auto; -webkit-overflow-scrolling: touch;
  display: flex; flex-direction: column;
  gap: var(--scale-300);
  padding: var(--scale-500) var(--scale-400) var(--scale-200);
}
/* Screen title wraps freely (base .cf-card-title is a one-line card row). */
.flp-title { white-space: normal; overflow: visible; text-overflow: unset; }
.flp-desc.is-clamped {
  display: -webkit-box; -webkit-box-orient: vertical;
  -webkit-line-clamp: 1; line-clamp: 1;
  overflow: hidden;
}
.flp-show-more {
  background: none; border: 0; padding: 0;
  align-self: flex-start;
  color: var(--text-action);
  cursor: pointer;
}
/* 3 stat columns (Distance · Stops · Loop) — outside .cf-card.shop the base
   .cf-card-stats grid is 4-col. */
.flp-stats { grid-template-columns: repeat(3, 1fr); margin: var(--scale-200) 0; }
.flp-how-title { margin: var(--scale-200) 0 0; }
.flp-cta {
  flex-shrink: 0;
  padding: var(--scale-300) var(--scale-400)
           calc(var(--scale-300) + env(safe-area-inset-bottom));
  border-top: var(--border-w-sm) solid var(--border-subtle);
}

/* ─── Featured filter sheet ──────────────────────────────────────────────────
   Full bottom-sheet "Filter" modal (Figma: Featured routes › all filters).
   Collapsible Sort by / City / Type sections + a Loop row, with a sticky
   "Show N results" apply button. */
/* Centered modal — 48-px (Scale/1200) top/bottom inset from the screen edges,
   horizontally centered (max-width 480 with a small mobile gutter). */
.ff-sheet {
  position: fixed; inset: 0; z-index: 1400;
  display: flex; align-items: center; justify-content: center;
  padding: var(--scale-1200) var(--scale-400);
}
.ff-sheet[hidden] { display: none; }
.ff-sheet-backdrop { position: absolute; inset: 0; background: var(--surface-modal); }
.ff-sheet-panel {
  position: relative; width: 100%; max-width: 480px;
  height: 100%;                                   /* All filters — fills the 48-inset area */
  background: var(--surface-page);
  border-radius: var(--radius-xlg);               /* centered modal — all corners rounded */
  display: flex; flex-direction: column; overflow: hidden;
  box-shadow: var(--shadow-up);
}
/* Focused (single-filter) views end where the list ends — size to content, but
   still cap + scroll when long. The full "All filters" modal stays tall above.
   Show results stays pinned to the MODAL's bottom (footer is a flex child). */
.ff-sheet.ff-focused .ff-sheet-panel { height: auto; max-height: 100%; }
/* All-filters view: 24-px (Scale/600) gap after each collapsible group. */
.ff-sheet:not(.ff-focused) .ff-sheet-body { display: flex; flex-direction: column; gap: var(--scale-600); }
/* Header mirrors the design-system Nav-bar (.cf-top-bar.nav-bar): leading slot
   (close X) hugs the left edge, trailing slot (Clear) hugs the right via
   space-between, and the title is absolutely centred so it stays centred
   regardless of the two slots' differing widths. */
.ff-sheet-head {
  position: relative;                  /* anchor for the absolutely-centred title */
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--scale-400) var(--scale-500);
  border-bottom: var(--border-w-sm) solid var(--border-subtle);
  flex-shrink: 0;                      /* fixed header — only the body scrolls */
}
.ff-sheet-x { flex-shrink: 0; }        /* leading slot — visuals from cf-btn ghost icon-only */
.ff-sheet-title {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  margin: 0; white-space: nowrap; pointer-events: none;   /* keep the slots clickable underneath */
  font-family: var(--font-family-headings); font-weight: var(--font-weight-bold);
  font-size: var(--text-h6-size); line-height: var(--text-h6-line-height); color: var(--text-headings);
}
.ff-sheet-clear {
  flex-shrink: 0;                      /* trailing slot — pinned right by space-between */
  background: none; border: none; padding: var(--scale-100);
  font-size: var(--text-body-md-size); font-weight: var(--font-weight-bold);
  color: var(--text-action); cursor: pointer;
}
.ff-sheet-body { flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; }
/* Footer = Figma "bottom bar": grey #F6F6F5 fill behind the full-width
   Show-results button, 16/24 padding, 1px Border/Subtle hairline on top. */
.ff-sheet-foot {
  padding: var(--scale-400) var(--scale-600);
  border-top: var(--border-w-sm) solid var(--border-subtle);
  background: var(--surface-background);
  flex-shrink: 0;                      /* sticky footer — only the body scrolls */
}
.ff-sheet-apply { width: 100%; justify-content: center; }

/* Collapsible section */
/* Section header = library Separator · Group title (.cf-separator.group-title +
   .cf-separator-group-title), which owns the layout / heading typography. The
   app only adds the pointer + the optional selected-count Indicator + caret. */
.ff-sec-head { cursor: pointer; }
.ff-sec-caret { flex-shrink: 0; transition: transform .15s ease; color: var(--icon-default); }
.ff-sec.is-open .ff-sec-caret { transform: rotate(180deg); }
.ff-sec-body { display: none; }
.ff-sec.is-open .ff-sec-body { display: block; }

/* Sort-group bands use the library Separator component (.cf-separator ·
   Type=Default) — built in _buildFilterSheet; no app CSS needed here. */

/* Selectable rows use the library List-item-with-action component
   (.cf-list-item.with-action): 24-px inset content + divider, body-sm title on
   the left, radio (md) / checkbox control on the right. The component owns the
   layout, inset and hairline divider; here we only reset the <button> chrome so
   the whole row stays tappable. "Last row of each list group drops the divider"
   is done in JS by stripping .with-divider (matches Figma 2316:19741). */
.ff-sheet button.cf-list-item {
  background: none; border: none; cursor: pointer; text-align: left;
  font: inherit; color: inherit;
}
body.ff-sheet-open { overflow: hidden; }
.cf-card-description { color: var(--text-body); margin-top: var(--scale-100); }

/* ─── SPA screens ───────────────────────────────────────────────────────────
   Each profile-area screen is a full-viewport overlay above the map. The hash
   router toggles the `hidden` attribute. `.cf-page` sets display:flex, so the
   default [hidden]{display:none} UA rule is overridden — force it back. */
.spa-screen {
  position: fixed;
  inset: 0;
  z-index: 2000;
}
.spa-screen[hidden] { display: none !important; }

/* Pin the top bar inside the scrolling screen so it never scrolls away.
   Root cause of bugs #1 (profile header vanished) and #3 (routes header
   disappeared on long-list filters): the bar lived inside the scroll
   container and scrolled off with the content. */
.spa-screen > .cf-top-bar {
  position: sticky;
  top: 0;
  z-index: 5;
  /* The screen is a flex column scroll container; without this the header
     (a flex item) is shrunk to fit and its overflow:hidden clips the hero
     avatar/name. Pin its natural height and let the body scroll instead. */
  flex-shrink: 0;
  /* Status-bar / notch inset — same treatment the map header gets from its
     shell, so the back button + title sit BELOW the notch instead of under it.
     Applied as padding-top ONLY (never the `padding` shorthand) so the
     variant's horizontal padding (nav-bar 8, large-title 0) is untouched and
     there's no cascade collision. The header's own background (surface, or the
     large-title hero image) extends up to fill the inset strip, and being on
     the sticky element it stays covered while the body scrolls. No scale-200
     floor here — uses the SAME max(env, scale-200) floor as the map-header
     shell so the back button sits at the identical y on both. Without it the
     header content jumps 8px when moving between a profile/SPA screen and the
     map (e.g. profile ↔ goals) on non-notch/desktop where env() is 0. The hero
     bg (absolute inset:0) still fills the whole padding box → stays flush. */
  padding-top: max(env(safe-area-inset-top, 0px), var(--scale-200));
}

.cf-page {
  width: 100%;
  margin: 0 auto;
  /* The iOS shell sets webView.scrollView.isScrollEnabled = false on the
     WKWebView so the map page (index.html) doesn't fight Leaflet's gestures.
     That kills document-level scroll on every subpage. Workaround: make
     .cf-page itself the scroll container with a fixed viewport height —
     WebKit honors inner-element overflow even when the outer WebView's
     scroll is disabled. `100dvh` falls back to `100vh` on browsers without
     dynamic-viewport support. */
  height: 100vh;
  height: 100dvh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;  /* momentum scroll on older WebKit */
  display: flex; flex-direction: column;
  background: var(--surface-page);
}
.cf-page-body {
  display: flex; flex-direction: column;
  padding-bottom: var(--scale-1600);
}
/* The published top bar is fixed-width for the index layout; the profile
   subpages stretch it edge to edge. */
.cf-page .cf-top-bar { width: 100%; }

/* Library cards (small / goal / activity) hard-code mobile-frame widths
   (173 / 342). On any wider viewport they leave huge empty gutters next
   to the layout. The profile pages place cards directly in the page
   shell with their own padding, so let them stretch to the container.
   Achievement cards are intentionally untouched — they live in fixed-size
   slots (unlocked-cities row, goals grid). */
/* Drop the library's fixed mobile-frame widths (173 / 342) for every
   small / goal / activity card on a profile-shell page — let the parent
   (flex column, grid cell) stretch them to fill its content area. */
.cf-page .cf-card.small,
.cf-page .cf-card.goal,
.cf-page .cf-card.activity { width: auto; }

/* Activity and Goal cards on the profile screen have no horizontal padding
   from the shell: on the static page they sit directly in `.cf-page-body`,
   on the SPA screen the renderer drops them into the `#profileLatestRoute`
   / `#profileGoal` host divs (themselves direct children of the body).
   Carve in 24-px (Scale/600) gutters via margins to align with the rest of
   the layout. Cards inside their own padded wrappers (`.cf-route-list`,
   which pads itself) are intentionally not matched, so they don't double up. */
.cf-page-body > .cf-card.goal,
.cf-page-body > .cf-card.activity,
#profileLatestRoute > .cf-card.activity,
#profileGoal > .cf-card.goal {
  margin-left: var(--scale-600);
  margin-right: var(--scale-600);
}

/* Breathing room below each Separator before the section content begins. */
.cf-page .cf-separator { margin-bottom: var(--scale-400); }

/* Breathing room below each Card before the next section starts. */
.cf-page .cf-card { margin-bottom: var(--scale-600); }

/* ─── profile.html ────────────────────────────────────────────────────────── */
.cf-profile-stats {
  display: grid;
  /* Four stats (Distance, Steps walked, Routes, Steps on routes) laid out 2×2.
     `minmax(0, 1fr)`, not `1fr`: a bare `1fr` floors each column at its
     min-content, so the card holding the widest value ("36.6k") refuses to
     shrink and steals width from its sibling. `minmax(0, 1fr)` pins both
     columns to the same width whatever the values are. The cards use the
     compact (`.cf-card-figure.sm`) figure so the value still fits that width. */
  grid-template-columns: repeat(2, minmax(0, 1fr));
  /* No `align-items` here on purpose. Equal card heights — label on the top
     edge, figure on the bottom edge, slack in between — are owned by
     `.cf-card.small` itself (`align-self: stretch`), so this grid must not
     re-declare them. */
  gap: var(--scale-200);
  padding: var(--scale-600) var(--scale-600) 0;
}
/* Unlocked cities mirrors the stats grid on top: responsive 3-column flow,
   8-px (Scale/200) gap. Achievement cards stretch to fill their cell instead
   of holding their fixed 109-px library width. */
.cf-profile-unlocked {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--scale-200);
  padding: 0 var(--scale-600) var(--scale-600);
}
.cf-profile-unlocked .cf-card.achievement { width: auto; }

/* Very narrow phones only, matching the shop's 340 cutoff in app.css. The
   compact figure needs ~77px for the widest value ("36.6k" at H6 beside a
   20-px glyph); a 340-px viewport leaves the card 60px of content, so the
   value breaks out past the card's right edge. Below the cutoff the figure
   stacks — glyph on its own line, value beneath it at the full content width
   (53px, enough for the same value). Above it the figure stays in one row:
   360 and 375 squeeze the right padding to 6 / 11px but keep the value
   inside the card, and stacking there would cost card height on the two
   commonest phone widths. */
@media (max-width: 340px) {
  .cf-profile-stats .cf-card-figure.sm {
    flex-direction: column;
    align-items: flex-start;
  }
}

/* Refer a friend — minimal block, code as monospaced chip + copy button. */
.cf-profile-referral {
  display: flex; flex-direction: column;
  gap: var(--scale-300);
  padding: 0 var(--scale-600) var(--scale-600);
}
.cf-profile-referral-copy { margin: 0; color: var(--text-label-light); }
.cf-profile-referral-row {
  display: flex; align-items: center; gap: var(--scale-300);
}
.cf-profile-referral-code {
  flex: 1;
  padding: var(--scale-300) var(--scale-400);
  background: var(--surface-action-ghost);
  border: var(--border-w-sm) solid var(--border-default);
  border-radius: var(--radius-md);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 1.1rem;
  letter-spacing: 0.08em;
  text-align: center;
  user-select: all;
}

.cf-profile-actions {
  display: flex; flex-direction: column;
  gap: var(--scale-300);
  padding: var(--scale-400) var(--scale-600);
}

/* ─── your-routes.html ────────────────────────────────────────────────────── */
.cf-route-filters {
  display: flex; gap: var(--scale-200);
  padding: var(--scale-400) var(--scale-600);
  overflow-x: auto;
  scrollbar-width: none;
}
.cf-route-filters::-webkit-scrollbar { display: none; }
.cf-route-list {
  display: flex; flex-direction: column;
  gap: var(--scale-400);
  padding: 0 var(--scale-600) var(--scale-400);
}

/* Route cards in the activity-card layout: the Figma design hierarchy is
   "date · city" (subtitle) above the route name (title). The published
   .cf-card-meta orders title first → flip with column-reverse. */
.cf-card.activity .cf-card-meta {
  flex-direction: column-reverse;
}

/* ─── your-goals.html ─────────────────────────────────────────────────────── */
.cf-goals-grid {
  display: grid;
  /* auto-fill keeps the achievement cards compact at any viewport: 3 cols
     at the 390 design width, more columns on wider screens, never single
     stretched columns. min cell width tuned to fit the lg goal-tracker
     (94px) + side padding. */
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: var(--scale-400);
  padding: var(--scale-400) var(--scale-600);
}
/* The Card achievement on a goals grid is narrower than usual (≈100px per
   3-col cell). The Set-as-goal button and Current-goal tag need to stretch
   to the cell and keep their label on one line. */
.cf-goals-grid .cf-card.achievement {
  display: flex; flex-direction: column;
  align-items: center;
  gap: var(--scale-200);
}
.cf-goals-grid .cf-card.achievement .cf-btn,
.cf-goals-grid .cf-card.achievement .cf-tag {
  width: 100%;
  justify-content: center;
  white-space: nowrap;
  padding-left: var(--scale-100);
  padding-right: var(--scale-100);
}
