*, *::before, *::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-behavior: smooth;
  /* What shows when the page is pulled past its top (pull to refresh,
     rubber-band) or while a page loads: the header pink, so the top of the
     screen stays one continuous colour (Mandy's 10/02 recording). body
     paints the cream over the page itself. */
  background: #fae3ee;
}
html:has(body.mobile-launch) { background: #963545; }

/* Native-app shell tweaks: applied only inside the Capacitor iOS WebView
   (entry.ts tags <html> + <body> with .capacitor-native on bootstrap).
   Web visitors see normal scrollbars + the OS-default tap highlight. */
html.capacitor-native,
body.capacitor-native,
.capacitor-native * {
  -webkit-tap-highlight-color: transparent;
  scrollbar-width: none;       /* Firefox; harmless in WebKit */
  -ms-overflow-style: none;    /* legacy Edge */
}
.capacitor-native ::-webkit-scrollbar,
.capacitor-native::-webkit-scrollbar {
  width: 0;
  height: 0;
  display: none;
}

/* Smooth cross-fade between hx-boost page swaps via the View Transitions
   API. Safari 18+ supports it; older WebKits fall back to no transition
   (no error, just a less polished swap). */
@view-transition { navigation: auto; }
::view-transition-old(root),
::view-transition-new(root) {
  animation-duration: 180ms;
  animation-timing-function: cubic-bezier(0.22, 0.61, 0.36, 1);
}

/* Pull-to-refresh indicator — created from entry.ts on native bootstrap,
   so the styles only matter when we're inside Capacitor. Slides down as
   the user pulls; brand-accent ring when armed; spins during the swap. */
#comomity-ptr {
  position: fixed;
  top: max(env(safe-area-inset-top), 12px);
  left: 50%;
  margin-left: -22px;
  width: 44px; height: 44px;
  display: flex;
  align-items: center; justify-content: center;
  background: rgba(250, 247, 242, 0.92);
  backdrop-filter: saturate(140%) blur(14px);
  -webkit-backdrop-filter: saturate(140%) blur(14px);
  border-radius: 50%;
  box-shadow: 0 4px 16px rgba(28, 27, 26, 0.12);
  opacity: 0;
  z-index: 50;
  pointer-events: none;
  transform: translateY(-72px);
  transition: opacity 160ms ease-out;
}
#comomity-ptr.armed svg { stroke: var(--color-accent-text); }
#comomity-ptr.spinning svg { animation: comomity-ptr-spin 0.7s linear infinite; }
@keyframes comomity-ptr-spin { to { transform: rotate(360deg); } }

/* htmx top-of-screen progress bar. base.html toggles body.htmx-loading
   on htmx:beforeRequest / htmx:afterRequest. Brand-accent indeterminate
   slide so any wait — dyno warm-up, slow CSS, big template — feels
   acknowledged instead of frozen. */
#comomity-progress {
  position: fixed;
  top: env(safe-area-inset-top); left: 0; right: 0;  /* below the notch, or it's invisible in the app */
  height: 3px;
  background: var(--color-accent);
  transform: translateX(-100%);
  opacity: 0;
  pointer-events: none;
  z-index: 9999;
  transition: opacity 160ms ease-out;
}
body.htmx-loading #comomity-progress {
  opacity: 1;
  animation: comomity-progress-slide 1.2s cubic-bezier(0.4, 0, 0.2, 1) infinite;
}
@keyframes comomity-progress-slide {
  0%   { transform: translateX(-100%); }
  50%  { transform: translateX(20%); }
  100% { transform: translateX(120%); }
}

body {
  margin: 0;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-sans);
  font-size: var(--fs-base);
  line-height: 1.5;
  min-height: 100vh;
  min-height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  /* `overflow-x: clip` (not `hidden`) so .page-hero's negative-margin
     bleed doesn't create a horizontal scrollbar on narrow viewports,
     while still allowing position: sticky on descendants. */
  overflow-x: clip;
}

/* Status-bar band. body's top padding reserves the safe area above the
   page; this paints it in the header colour so the pink gradient runs up
   behind the clock instead of leaving a cream strip (Mandy's 9/30
   walkthrough). Fixed, so content scrolling under the clock is covered the
   way native iOS apps do it. Pages whose header isn't the pink hero
   override --chrome-top-bg via their body class. Sits below the
   pull-to-refresh indicator (50) and above the bottom nav (40). */
:root { --chrome-top-bg: #fae3ee; }
body::before {
  content: "";
  position: fixed;
  top: 0; left: 0; right: 0;
  height: env(safe-area-inset-top);
  background: var(--chrome-top-bg);
  z-index: 45;
  pointer-events: none;
}

/* Pull to refresh slides .app-shell down; paint the gap it opens in the
   header pink instead of the body's cream (Mandy's 10/02 recording). */
.app-shell { position: relative; }
.app-shell::before {
  content: "";
  position: absolute;
  left: 0; right: 0;
  bottom: 100%;
  height: 200px;
  background: var(--chrome-top-bg);
  pointer-events: none;
}

img, svg, video { max-width: 100%; height: auto; display: block; }

h1, h2, h3 {
  font-family: var(--font-serif);
  font-weight: 500;
  letter-spacing: -0.01em;
  margin: 0 0 var(--space-3);
  line-height: 1.2;
}
h1 { font-size: var(--fs-3xl); }
h2 { font-size: var(--fs-2xl); }
h3 { font-size: var(--fs-xl); }

/* ── Brand wordmark ──────────────────────────────────────────────────────
   The Comomity logotype: "co" + "mom" + "ity", with the middle
   "mom" carried in cherry-blossom pink (matching the primary logo). Used in
   the app chrome — login, nav, admin topbar — instead of plain text. */
.wordmark {
  font-family: var(--font-sans);
  font-weight: 600;
  letter-spacing: var(--tracking-snug);
  color: var(--color-accent);
  text-transform: lowercase;
  line-height: 1;
  white-space: nowrap;
}
.wordmark__mom { color: var(--color-pink); }
/* On burgundy backgrounds, the wordmark inverts: cream + pink. */
.wordmark--invert { color: var(--color-bg); }

/* ── Emblem watermark ────────────────────────────────────────────────────
   The co-mom-ity mark blown up and bled off a corner as an ambient graphic,
   the way the brand boards use it. Drop `.has-emblem` on a positioned,
   overflow-hidden panel. Inherits currentColor at low opacity. */
.has-emblem { position: relative; overflow: hidden; }
.has-emblem > * { position: relative; z-index: 1; }
.has-emblem::after {
  content: "";
  position: absolute;
  right: -8%;
  bottom: -28%;
  width: 62%;
  aspect-ratio: 867 / 543;
  background: currentColor;
  opacity: 0.06;
  pointer-events: none;
  z-index: 0;
  -webkit-mask: url("/static/icons/emblem.9bd03d15ba31.svg") right bottom / contain no-repeat;
          mask: url("/static/icons/emblem.9bd03d15ba31.svg") right bottom / contain no-repeat;
}

p { margin: 0 0 var(--space-4); }
p:last-child { margin-bottom: 0; }

a {
  color: var(--color-accent-text);
  text-decoration: none;
}
a:hover, a:focus-visible { text-decoration: underline; }

:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}

.app-shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
}

.app-header {
  padding: var(--space-4) var(--space-5);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}

.app-header__brand {
  display: inline-flex;
  align-items: center;
}
/* SVG wordmark in the logged-out header: height-constrained so the bar
   keeps its size at mobile widths; width follows the aspect ratio. */
.app-header__brand img {
  display: block;
  height: 22px;
  width: auto;
}
.app-header__brand:hover { text-decoration: none; }

.app-header__nav {
  display: flex;
  gap: var(--space-3);
  align-items: center;
}
.app-header__nav a, .app-header__nav button {
  font-size: var(--fs-sm);
}

.app-main {
  flex: 1;
  width: 100%;
  max-width: var(--content-max);
  margin: 0 auto;
  padding: var(--space-5) var(--space-5) var(--space-7);
}
/* A hero that opens the page sits flush under the status-bar band, so the
   band and the hero gradient read as one wash. */
.app-main > .page-hero:first-child { margin-top: calc(-1 * var(--space-5)); }

.app-footer {
  padding: var(--space-5);
  text-align: center;
  color: var(--color-text-muted);
  font-size: var(--fs-xs);
}

.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  box-shadow: var(--shadow-sm);
}

/* Elevated card — opt-in for surfaces that should feel touchable: session
   cards, library resource cards, group/member cards. Lifts on hover. The
   transition is short enough to feel responsive on a phone tap. */
.card-elevated {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  transition: transform 160ms ease, box-shadow 160ms ease, border-color 160ms ease;
}
.card-elevated:hover,
a.card-elevated:hover,
a.card-elevated:focus-visible {
  transform: translateY(-2px);
  box-shadow: var(--shadow-card-hover);
  border-color: var(--color-border-strong);
  text-decoration: none;
}

/* Page hero — warm gradient panel that holds the page title + lede on
   every user-facing screen. Replaces the bare H1-on-cream open with a
   soft horizon line so the page feels framed.

   Usage: wrap the title block in `<header class="page-hero">…</header>`
   at the top of the page content. Optional `.page-hero--soft` for screens
   that already have a strong visual (live session player). */
.page-hero {
  position: relative;
  padding: var(--space-3) var(--space-5) var(--space-5);
  margin-block: 0 var(--space-3);
  /* Auto-bleed: clamp the negative margin to whatever the parent's
     horizontal padding actually is. Pages whose <main> uses .app-main
     (24px padding) get -24px bleed; pages whose <main> has no padding
     (Library, Settings, Group, Sessions — they override main_class to
     use their own wider container) get 0px bleed. Either way the hero's
     text sits 24px from the viewport edge because the internal padding
     is constant. */
  margin-inline: max(calc(50% - 50vw), calc(-1 * var(--space-5)));
  background: var(--gradient-hero);
  overflow: hidden;
}
@media (min-width: 768px) {
  .page-hero {
    padding: var(--space-5) var(--space-5) var(--space-6);
    margin-bottom: var(--space-4);
  }
}
.page-hero--soft {
  background: var(--gradient-hero-soft);
}
.page-hero__eyebrow {
  display: inline-block;
  font-size: var(--fs-xs);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--color-accent-text);
  font-weight: 600;
  margin-bottom: var(--space-2);
}
.page-hero h1 {
  margin: 0 0 var(--space-2);
  font-size: var(--fs-2xl);
  line-height: 1.15;
}
@media (min-width: 768px) {
  .page-hero h1 { font-size: var(--fs-3xl); }
}
.page-hero p {
  color: var(--color-text-muted);
  margin: 0;
  max-width: 32rem;
  font-size: var(--fs-sm);
}
@media (min-width: 768px) {
  .page-hero p { font-size: var(--fs-base); }
}
.page-hero__meta {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2) var(--space-4);
  margin-top: var(--space-3);
  font-size: var(--fs-sm);
  color: var(--color-text-muted);
}
.page-hero__back {
  display: inline-block;
  font-size: var(--fs-sm);
  color: var(--color-text-muted);
  margin-bottom: var(--space-2);
}

/* Friendly empty-state block — used wherever a list could be empty. The
   centered card with a tinted icon feels intentional vs. the previous
   left-aligned "Nothing yet" line. */
.empty-state {
  background: var(--color-surface);
  border: 1px dashed var(--color-border-strong);
  border-radius: var(--radius-lg);
  padding: var(--space-7) var(--space-5);
  text-align: center;
  max-width: 36rem;
  margin: 0 auto;
}
.empty-state__icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--color-accent-tint);
  color: var(--color-accent-text);
  margin: 0 auto var(--space-4);
  font-size: 1.5rem;
}
.empty-state h2,
.empty-state h3 {
  margin: 0 0 var(--space-2);
  font-size: var(--fs-xl);
}
.empty-state p {
  color: var(--color-text-muted);
  margin: 0 auto var(--space-4);
  max-width: 28rem;
}
.empty-state p:last-child { margin-bottom: 0; }

/* Avatar circle — 32px default. Initials get the deterministic palette
   index via inline style coming from the templatetag. */
.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  font-size: var(--fs-sm);
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--color-accent-fg);
  flex-shrink: 0;
  user-select: none;
}
.avatar--photo { overflow: hidden; }
.avatar--photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: inherit;
  display: block;
}
.avatar--lg { width: 48px; height: 48px; font-size: var(--fs-base); }
.avatar--xl { width: 72px; height: 72px; font-size: var(--fs-xl); }
.avatar--p1 { background: var(--avatar-1); }
.avatar--p2 { background: var(--avatar-2); }
.avatar--p3 { background: var(--avatar-3); }
.avatar--p4 { background: var(--avatar-4); }
.avatar--p5 { background: var(--avatar-5); }
.avatar-row {
  display: inline-flex;
  align-items: center;
  gap: calc(-1 * var(--space-2));
}
.avatar-row .avatar {
  margin-left: -8px;
  border: 2px solid var(--color-bg);
}
.avatar-row .avatar:first-child { margin-left: 0; }

.lede {
  color: var(--color-text-muted);
  font-size: var(--fs-lg);
  margin-bottom: var(--space-5);
}

.muted { color: var(--color-text-muted); }

.stack > * + * { margin-top: var(--space-4); }
.stack-tight > * + * { margin-top: var(--space-2); }
.stack-loose > * + * { margin-top: var(--space-6); }

.progress {
  display: flex;
  gap: var(--space-2);
  margin-bottom: var(--space-5);
}
.progress__step {
  flex: 1;
  height: 3px;
  background: var(--color-border);
  border-radius: 0;
}
.progress__step--active { background: var(--color-accent); }
.progress__step--complete { background: var(--color-text); }

.cta-row {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  margin-top: var(--space-5);
}
@media (min-width: 480px) {
  .cta-row { flex-direction: row; }
  .cta-row > * { flex: 1; }
}

.alert {
  border-radius: var(--radius-md);
  padding: var(--space-4);
  font-size: var(--fs-sm);
  border: 1px solid var(--color-border);
}
.alert--error {
  background: #fbecec;
  border-color: #f3cfcf;
  color: #7a2222;
}
.alert--info {
  background: #f3eee5;
  border-color: var(--color-border);
  color: var(--color-text);
}

.legal-doc {
  font-size: var(--fs-base);
  line-height: 1.65;
}
.legal-doc h2 { font-size: var(--fs-xl); margin-top: var(--space-5); }
.legal-doc h3 { font-size: var(--fs-lg); margin-top: var(--space-4); }

.invite-code-row {
  display: flex;
  align-items: stretch;
  gap: var(--space-2);
  margin-top: var(--space-3);
}
.invite-code-row__code,
.invite-code-row__url {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  align-items: center;
  padding: 0 var(--space-3);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  font-family: var(--font-mono, ui-monospace, "SF Mono", Menlo, monospace);
  font-size: var(--fs-sm);
  color: var(--color-text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.invite-code-row__code {
  letter-spacing: 0.08em;
  font-weight: 600;
}
.invite-code-row__btn {
  flex: 0 0 auto;
  white-space: nowrap;
}

.scroll-box {
  max-height: 14rem;
  overflow-y: auto;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  padding: var(--space-4);
  font-size: var(--fs-sm);
  line-height: 1.55;
  white-space: pre-wrap;
}

/* ─── In-app photo viewer (static/js/lightbox.js) ─────────────────────── */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 10000;
  background: rgba(10, 10, 10, 0.94);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(env(safe-area-inset-top) + 3rem) 0.5rem calc(env(safe-area-inset-bottom) + 1rem);
  animation: lightbox-in 160ms ease-out;
}
.lightbox__img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  opacity: 0;
  transition: opacity 160ms ease;
  touch-action: pinch-zoom;
}
.lightbox.is-loaded .lightbox__img { opacity: 1; }
.lightbox.is-loaded .lightbox__spinner { display: none; }
.lightbox__close {
  position: absolute;
  top: calc(env(safe-area-inset-top) + 0.5rem);
  right: 0.75rem;
  width: 44px;
  height: 44px;
  border-radius: 999px;
  border: 0;
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  font-size: 1.75rem;
  line-height: 1;
  cursor: pointer;
}
.lightbox__spinner, .btn.is-busy::after {
  width: 28px;
  height: 28px;
  border-radius: 999px;
  border: 3px solid rgba(255, 255, 255, 0.25);
  border-top-color: #fff;
  animation: comomity-spin 0.7s linear infinite;
}
.lightbox__spinner { position: absolute; }
html.lightbox-open, html.lightbox-open body { overflow: hidden; }
@keyframes lightbox-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes comomity-spin { to { transform: rotate(360deg); } }

/* ─── Tap feel + busy buttons ─────────────────────────────────────────── */
/* No double-tap-zoom delay on controls; a little press feedback like a
   native button. */
a, button, .btn, label, summary { touch-action: manipulation; }
.btn:active:not(:disabled) { transform: scale(0.98); }
.card:active, .member-card:active, .notif-card:active, .shared-card:active { transform: scale(0.995); }

/* Submit buttons go busy while the request is in flight (base.html), so
   a slow connection doesn't invite a second tap and a double charge. */
.btn.is-busy {
  position: relative;
  color: transparent !important;
  pointer-events: none;
}
.btn.is-busy::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 18px;
  height: 18px;
  margin: -9px 0 0 -9px;
  border-width: 2px;
  border-color: currentColor;
  border-color: rgba(127, 127, 127, 0.35);
  border-top-color: var(--color-text);
}
.btn--primary.is-busy::after, .btn--accent.is-busy::after { border-top-color: #fff; }

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0);
  white-space: nowrap; border: 0;
}

/* ⋯ overflow menus (report-sheet.js closes them on outside tap). */
.kebab { position: relative; flex: none; }
.kebab > summary { list-style: none; }
.kebab > summary::-webkit-details-marker { display: none; }
.kebab__toggle {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 999px;
  color: var(--color-text-muted);
  cursor: pointer;
}
.kebab__toggle:hover, .kebab[open] > .kebab__toggle { background: var(--color-pink-tint); color: var(--color-text); }
.kebab__menu {
  position: absolute;
  right: 0;
  top: calc(100% + 4px);
  z-index: 20;
  min-width: 168px;
  padding: var(--space-1);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
}
.kebab--up .kebab__menu { top: auto; bottom: calc(100% + 4px); }
.kebab__menu form { margin: 0; }
.kebab__item {
  display: block;
  width: 100%;
  padding: 10px var(--space-3);
  border: 0;
  border-radius: var(--radius-sm);
  background: none;
  font: inherit;
  font-size: var(--fs-sm);
  color: var(--color-text);
  text-align: left;
  cursor: pointer;
}
.kebab__item:hover { background: var(--color-pink-tint); }
.kebab__item--danger { color: var(--color-error); }

/* Bottom sheet (report). */
dialog.sheet {
  width: 100%;
  max-width: 480px;
  margin: auto auto 0;
  padding: 0;
  border: 0;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  background: var(--color-surface);
  color: var(--color-text);
}
@media (min-width: 600px) { dialog.sheet { margin: auto; border-radius: var(--radius-lg); } }
dialog.sheet::backdrop { background: rgba(28, 27, 26, 0.4); }
.sheet__body { display: grid; gap: var(--space-3); padding: var(--space-5) var(--space-4) calc(var(--space-4) + env(safe-area-inset-bottom)); }
.sheet__title { margin: 0; font-size: var(--fs-lg); }
.sheet__lede { margin: -4px 0 0; font-size: var(--fs-sm); color: var(--color-text-muted); }
.sheet__reasons { display: grid; gap: var(--space-2); }
.sheet__error { margin: 0; color: var(--color-error); font-size: var(--fs-sm); }
.sheet__actions { display: flex; gap: var(--space-2); justify-content: flex-end; }
.sheet__list { display: grid; border: 1px solid var(--color-border); border-radius: var(--radius-md); overflow: hidden; }
.sheet__action {
  padding: 14px var(--space-4);
  border: 0;
  border-bottom: 1px solid var(--color-border);
  background: var(--color-surface);
  font: inherit;
  color: var(--color-text);
  text-align: left;
  cursor: pointer;
}
.sheet__action:last-child { border-bottom: 0; }
.sheet__action--danger { color: var(--color-error); }
.btn.sheet__danger { background: var(--color-error); border-color: var(--color-error); color: #fff; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(88px + env(safe-area-inset-bottom));
  z-index: 1000;
  transform: translateX(-50%);
  max-width: calc(100% - 32px);
  padding: 10px var(--space-4);
  border-radius: 999px;
  background: var(--color-text);
  color: var(--color-bg);
  font-size: var(--fs-sm);
  box-shadow: var(--shadow-md);
  transition: opacity 300ms ease;
}
.toast--out { opacity: 0; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* In-app stand-in for prices / checkout (billing/_in_app_notice.html). */
.in-app-notice { display: grid; gap: var(--space-3); }
.in-app-notice p { margin: 0; font-size: var(--fs-sm); color: var(--color-text-muted); }
.in-app-notice--off { margin: 0; font-size: var(--fs-sm); color: var(--color-text-muted); text-align: center; }
