/* Profile — /my_profile (UX backlog 2.6, D-55; pages/my_profile.py).
   The Instagram profile model: identity block, icon tab strip, 3-column tile
   grid. Scoped on `.sp-profile` (the page shell; `.profile-page-shell` stays on
   the same element for zz_site_chrome.css's active-nav rule). The Edit sheet is
   a portaled Mantine Drawer scoped on `.sp-profile-sheet` — the same bottom
   sheet pattern the Chart page uses (zz_compare.css §sheets).
   Geometry: ≤ 767 px the phone layout (77 px avatar, stats beside it, full
   width buttons, 2 px grid gap); ≥ 768 px the desktop layout (150 px avatar
   left, 935 px column — Instagram web, 4 px grid gap). Tokens: --spc-* from
   zz_site_chrome.css (dark chrome; no light variant on this route). */

/* First paint: 00_theme_bootstrap.js stamps `sp-route-profile` on <html>/<body>
   before the tree mounts, so the route is dark from the start (a reload used to
   flash styles.css's light --sp-surface-page until .sp-profile arrived). The
   :has() form covers client-side navigation and keeps the paint after mount. */
html.sp-route-profile,
body.sp-route-profile,
body:where([data-sp-has~="profile"]):not(.sp-s) {
  color-scheme: dark;
  background: var(--sp-bg) !important;
}

body.sp-route-profile #app-container,
body:where([data-sp-has~="profile"]):not(.sp-s) #app-container {
  background-color: var(--sp-bg) !important;
}

.sp-profile {
  --pf-bg: var(--spc-bg, var(--sp-bg));
  --pf-chrome: var(--spc-chrome, var(--sp-chrome));
  --pf-surface: var(--spc-surface, var(--sp-surface));
  --pf-track: var(--spc-track, var(--sp-chip));
  --pf-border: var(--spc-border, var(--sp-border-strong));
  --pf-text: var(--spc-text, var(--sp-text));
  --pf-text-2: var(--spc-text-2, var(--sp-text-2));
  --pf-muted: var(--spc-muted, var(--sp-text-3));
  --pf-accent: var(--spc-accent, var(--sp-accent));
  --pf-display: var(--spc-display, "Bricolage Grotesque", sans-serif);
  --pf-ui: var(--spc-ui, "Instrument Sans", sans-serif);
  --pf-gap: 2px;
  --pf-avatar: 77px;

  min-height: calc(100vh - var(--sp-header-h, 62px));
  background: var(--pf-bg);
  color: var(--pf-text);
  font-family: var(--pf-ui);
}

.sp-profile__inner {
  width: 100%;
  max-width: 935px;
  margin: 0 auto;
  padding: 14px 0 32px;
}

/* ---- identity block ------------------------------------------------------- */

.sp-profile__head {
  display: grid;
  gap: 12px;
  padding: 0 16px;
}

.sp-profile__identity {
  display: flex;
  align-items: center;
  gap: 24px;
}

.sp-profile .sp-profile__avatar.mantine-Avatar-root {
  flex: 0 0 auto;
  width: var(--pf-avatar);
  height: var(--pf-avatar);
  min-width: var(--pf-avatar);
  font-family: var(--pf-display);
  font-size: calc(var(--pf-avatar) * 0.34);
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--pf-text);
  background: var(--pf-surface);
  border: 1px solid var(--pf-border);
  border-radius: 50%; /* Mantine's radius="xl" is 32 px, not a circle */
  /* the 2 px ring + 2 px gap Instagram draws round an avatar with a story */
  box-shadow: 0 0 0 2px var(--pf-bg), 0 0 0 3.5px var(--pf-border);
}

.sp-profile .sp-profile__avatar .mantine-Avatar-image,
.sp-profile .sp-profile__avatar .mantine-Avatar-placeholder {
  border-radius: 50%;
}

.sp-profile .sp-profile__avatar .mantine-Avatar-placeholder {
  background: transparent;
  color: inherit;
  font: inherit;
}

.sp-profile .sp-profile__avatar .mantine-Avatar-image {
  object-fit: cover;
}

.sp-profile__stats {
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  text-align: center;
}

.sp-profile__stat {
  display: grid;
  gap: 1px;
  min-width: 0;
}

.sp-profile__stat-n {
  font-family: var(--pf-display);
  font-size: 18px;
  font-weight: 800;
  line-height: 1.1;
  letter-spacing: -0.02em;
  color: var(--pf-text);
}

.sp-profile__stat-l {
  font-size: 13px;
  line-height: 1.2;
  color: var(--pf-text-2);
}

.sp-profile__bio {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.sp-profile__name {
  font-family: var(--pf-display);
  font-size: 15px;
  font-weight: 700;
  line-height: 1.25;
  letter-spacing: -0.01em;
  color: var(--pf-text);
  overflow-wrap: anywhere;
}

.sp-profile__meta {
  font-size: 13px;
  line-height: 1.35;
  color: var(--pf-muted);
  overflow-wrap: anywhere;
}

.sp-profile__actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

/* ---- buttons (Instagram's secondary pill: track fill, no border) --------- */

.sp-profile-btn,
.sp-profile-sheet .sp-profile-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 34px;
  padding: 0 14px;
  border: 0;
  border-radius: 8px;
  background: var(--pf-track, var(--sp-chip));
  color: var(--pf-text, var(--sp-text));
  font-family: var(--pf-ui, "Instrument Sans", sans-serif);
  font-size: 14px;
  font-weight: 600;
  line-height: 1;
  text-decoration: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 120ms ease, color 120ms ease;
}

.sp-profile-btn:hover,
.sp-profile-sheet .sp-profile-btn:hover {
  background: var(--pf-border, var(--sp-border-strong));
  color: var(--pf-text, var(--sp-text));
  text-decoration: none;
}

.sp-profile-btn--primary,
.sp-profile-sheet .sp-profile-btn--primary {
  background: var(--pf-accent, var(--sp-accent));
  color: var(--sp-bg);
}

.sp-profile-btn--primary:hover,
.sp-profile-sheet .sp-profile-btn--primary:hover {
  background: var(--spc-accent-hover, var(--sp-accent-hover));
  color: var(--sp-bg);
}

/* ---- tab strip (icon tabs, top border, 1 px underline on the active one) -- */

.sp-profile__tabs {
  display: flex;
  justify-content: stretch;
  margin-top: 18px;
  border-top: 1px solid var(--pf-border);
}

.sp-profile__tab {
  flex: 1 1 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  margin-top: -1px;
  padding: 0;
  border: 0;
  border-top: 1px solid transparent;
  background: transparent;
  color: var(--pf-muted);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: color 120ms ease;
}

.sp-profile__tab:hover {
  color: var(--pf-text-2);
}

.sp-profile__tab.is-active {
  color: var(--pf-text);
  border-top-color: var(--pf-text);
}

/* ---- grid ----------------------------------------------------------------- */

.sp-profile__grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--pf-gap);
}

.sp-profile__grid--videos .sp-profile-tile:not(.sp-profile-tile--video) {
  display: none;
}

.sp-profile-tile {
  position: relative;
  display: block;
  aspect-ratio: 1 / 1;
  overflow: hidden;
  background: var(--pf-surface);
  color: var(--pf-text);
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}

.sp-profile-tile:hover {
  text-decoration: none;
  color: var(--pf-text);
}

.sp-profile-tile__video {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #000;
  pointer-events: none;
}

.sp-profile-tile__badge {
  position: absolute;
  top: 8px;
  right: 8px;
  display: inline-flex;
  color: #fff;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.6));
}

/* video tile caption: the question over a bottom gradient (an animated chart's
   first frame is nearly empty, so the frame alone does not identify the post) */
.sp-profile-tile__caption {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
  padding: 26px 8px 8px;
  background: linear-gradient(180deg, rgba(0, 0, 0, 0) 0%, rgba(0, 0, 0, 0.72) 100%);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.25;
  letter-spacing: -0.01em;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
}

/* text tile (a post without a video): category eyebrow, question, chart kind */
.sp-profile-tile--text {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 4px;
  padding: 10px;
  background:
    radial-gradient(120% 90% at 100% 0%, color-mix(in srgb, var(--sp-accent) 14%, transparent) 0%, color-mix(in srgb, var(--sp-accent) 0%, transparent) 55%),
    var(--pf-surface);
  border: 1px solid var(--pf-border);
}

.sp-profile-tile__eyebrow {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--pf-accent);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sp-profile-tile__title {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  overflow: hidden;
  font-family: var(--pf-display);
  font-size: 13px;
  font-weight: 700;
  line-height: 1.25;
  letter-spacing: -0.01em;
  color: var(--pf-text);
}

.sp-profile-tile__kind {
  position: absolute;
  top: 8px;
  right: 8px;
  display: inline-flex;
  color: var(--pf-muted);
}

.sp-profile-tile__draft {
  position: absolute;
  top: 8px;
  left: 8px;
  padding: 2px 6px;
  border-radius: 999px;
  background: rgba(13, 14, 18, 0.8);
  color: var(--pf-text-2);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.sp-profile-tile--draft .sp-profile-tile__title {
  color: var(--pf-text-2);
}

/* hover overlay (desktop pointer only): heart + likes, like Instagram web */
.sp-profile-tile__hover {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: rgba(0, 0, 0, 0.35);
  color: #fff;
  font-family: var(--pf-display);
  font-size: 15px;
  font-weight: 800;
}

@media (hover: hover) and (pointer: fine) {
  .sp-profile-tile:hover .sp-profile-tile__hover {
    display: flex;
  }
}

/* ---- empty states --------------------------------------------------------- */

.sp-profile__empty {
  grid-column: 1 / -1;
  display: grid;
  justify-items: center;
  gap: 6px;
  padding: 56px 24px;
  text-align: center;
}

.sp-profile__empty-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 62px;
  height: 62px;
  margin-bottom: 8px;
  border: 1.5px solid var(--pf-text);
  border-radius: 50%;
  color: var(--pf-text);
}

.sp-profile__empty-title {
  font-family: var(--pf-display);
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--pf-text);
}

.sp-profile__empty-text {
  font-size: 14px;
  color: var(--pf-text-2);
}

.sp-profile__empty-cta {
  margin-top: 6px;
  font-size: 14px;
  font-weight: 700;
  color: var(--pf-accent);
  text-decoration: none;
}

.sp-profile__empty-cta:hover {
  color: var(--spc-accent-hover, var(--sp-accent-hover));
  text-decoration: none;
}

/* the Videos tab with nothing to show: CSS-only (the grid hides text tiles) */
.sp-profile__empty--videos {
  display: none;
}

.sp-profile__grid--videos:not(:has(.sp-profile-tile--video)) .sp-profile__empty--videos {
  display: grid;
}

/* ---- edit sheet (portaled; mirrors .cmp-sheet) ---------------------------- */

.sp-profile-sheet .mantine-Drawer-overlay {
  background: rgba(8, 9, 12, 0.6) !important;
  backdrop-filter: blur(3px);
}

.sp-profile-sheet .mantine-Drawer-content {
  background: var(--spc-chrome, var(--sp-chrome));
  color: var(--spc-text, var(--sp-text));
  border-top: 1px solid var(--spc-border, var(--sp-border-strong));
  border-radius: 20px 20px 0 0;
  height: auto !important;
  max-height: 88vh !important;
}

.sp-profile-sheet .mantine-Drawer-header {
  background: var(--spc-chrome, var(--sp-chrome));
  height: auto;
  min-height: 0;
  padding-bottom: 4px;
}

.sp-profile-sheet .mantine-Drawer-title {
  font-family: var(--spc-display, "Bricolage Grotesque", sans-serif);
  font-size: 17px;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--spc-text, var(--sp-text));
  text-transform: none;
  text-align: left;
  width: auto;
  margin: 0;
}

.sp-profile-sheet .mantine-Drawer-close {
  color: var(--spc-muted, var(--sp-text-3));
}

.sp-profile-sheet .mantine-Drawer-close:hover {
  color: var(--spc-text, var(--sp-text));
  background: var(--spc-track, var(--sp-chip));
}

.sp-profile-sheet .mantine-Drawer-body {
  padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
}

.sp-profile-sheet .sp-profile-input .mantine-InputWrapper-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--spc-text-2, var(--sp-text-2));
}

.sp-profile-sheet .sp-profile-input .mantine-InputWrapper-description {
  color: var(--spc-muted, var(--sp-text-3));
}

.sp-profile-sheet .sp-profile-input .mantine-Input-input {
  min-height: 42px;
  background: var(--spc-surface, var(--sp-surface));
  border-color: var(--spc-border, var(--sp-border-strong));
  color: var(--spc-text, var(--sp-text));
}

.sp-profile-sheet .sp-profile-input .mantine-Input-input:disabled {
  opacity: 0.7;
}

.sp-profile-sheet .sp-profile-input .mantine-Input-input:focus {
  border-color: var(--spc-accent, var(--sp-accent));
}

.sp-profile-sheet .sp-profile-input .mantine-Input-section {
  color: var(--spc-muted, var(--sp-text-3));
}

.sp-profile-sheet .sp-profile-save-btn {
  width: 100%;
  min-height: 42px;
  margin-top: 4px;
}

/* ---- desktop (≥ 768): Instagram web ------------------------------------- */

@media (min-width: 768px) {
  .sp-profile {
    --pf-gap: 4px;
    --pf-avatar: 150px;
  }

  .sp-profile__inner {
    padding: 30px 20px 40px;
  }

  .sp-profile__head {
    grid-template-columns: auto 1fr;
    grid-template-areas:
      "avatar actions"
      "avatar stats"
      "avatar bio";
    column-gap: 64px;
    row-gap: 14px;
    align-items: start;
    padding: 0 0 8px;
  }

  .sp-profile__identity {
    display: contents;
  }

  .sp-profile .sp-profile__avatar.mantine-Avatar-root {
    grid-area: avatar;
    margin: 0 auto;
  }

  .sp-profile__stats {
    grid-area: stats;
    display: flex;
    gap: 40px;
    text-align: left;
  }

  .sp-profile__stat {
    display: inline-flex;
    align-items: baseline;
    gap: 5px;
  }

  .sp-profile__stat-n {
    font-size: 16px;
  }

  .sp-profile__stat-l {
    font-size: 15px;
    color: var(--pf-text);
  }

  .sp-profile__actions {
    grid-area: actions;
    display: flex;
    gap: 8px;
  }

  .sp-profile-btn {
    min-width: 120px;
  }

  .sp-profile__bio {
    grid-area: bio;
  }

  .sp-profile__name {
    font-size: 15px;
  }

  .sp-profile__tabs {
    justify-content: center;
    gap: 60px;
    margin-top: 24px;
  }

  .sp-profile__tab {
    flex: 0 0 auto;
    gap: 6px;
    min-height: 52px;
    padding: 0 2px;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
  }

  .sp-profile__tab .sp-visually-hidden {
    position: static !important;
    width: auto;
    height: auto;
    margin: 0;
    clip: auto;
    clip-path: none;
    overflow: visible;
  }

  .sp-profile__tab .iconify,
  .sp-profile__tab svg {
    width: 14px;
    height: 14px;
  }

  .sp-profile-tile__title {
    font-size: 15px;
    -webkit-line-clamp: 4;
  }

  .sp-profile-tile--text {
    padding: 16px;
  }

  .sp-profile-tile__eyebrow {
    font-size: 11px;
  }

  .sp-profile-tile__caption {
    padding: 36px 12px 12px;
    font-size: 13px;
  }

  /* the sheet on desktop: a centred card at the bottom, not a full-width bar.
     Mantine sizes a bottom drawer's content to 100 % width via --drawer-size on
     the flex item, hence the !important overrides. */
  .sp-profile-sheet .mantine-Drawer-inner {
    justify-content: center !important;
  }

  .sp-profile-sheet .mantine-Drawer-content {
    flex: 0 1 auto !important;
    width: min(560px, calc(100% - 32px)) !important;
    max-width: 560px !important;
    margin-bottom: 16px !important;
    border: 1px solid var(--spc-border, var(--sp-border-strong));
    border-radius: 20px;
  }
}
