/* ==========================================================================
   Shell frame (wave C1, lane C1-A)

   The frame every page and island sits in: the body region and its optional
   rail, the height each island root holds until its content arrives, the
   loading placeholder, the footer's touch targets and the reduced variant.
   Navigation rules do not live here: the rail and top bar are
   shell-desktop.css (lane C1-C), the phone header, tab bar and sheet are
   shell-phone.css (lane C1-D). theme.css still holds the outer boxes of the
   rail (.app-sidebar) and the top bar (.top-bar) and the content offsets
   beside the rail; the old drawer, dock and phone header rules are gone.
   ========================================================================== */

:root {
  /* One screen. svh is the small viewport, so a phone's toolbar never makes a
     reserved region taller than what is visible. */
  --shell-screen: 100vh;

  /* Pointer tiers (DESIGN.md s5): touch 44, coarse from 768px 40, fine 30.
     Every tier is above the 24 by 24 AA floor (WCAG 2.5.8). */
  --shell-target: 44px;
}

@supports (height: 100svh) {
  :root {
    --shell-screen: 100svh;
  }
}

@media (pointer: coarse) and (min-width: 768px) {
  :root {
    --shell-target: 40px;
  }
}

@media (pointer: fine) {
  :root {
    --shell-target: 30px;
  }
}

/* --------------------------------------------------------------------------
   Body region and the opt-in rail (D3)

   .shell-body is a plain column, so a page without a rail lays out exactly as
   before. A page that fills {% block page_rail %} with
   <aside class="shell-rail"> gets the rail under the content on narrow
   screens and beside it from the wide step of the ladder (1280px,
   design-tokens.md breakpoints), where the content still keeps 560px next to
   the 220px sidebar and a 400px rail. An empty block renders nothing and
   reserves no width.
   -------------------------------------------------------------------------- */

.shell-body {
  display: flex;
  flex: 1 0 auto;
  flex-direction: column;
  min-width: 0;
}

.shell-main {
  min-width: 0;
}

.shell-rail {
  width: 100%;
  margin-block-start: var(--space-lg);
}

@media (min-width: 1280px) {
  .shell-body:has(> .shell-rail) {
    flex-direction: row;
    align-items: flex-start;
    gap: var(--space-lg);
  }

  .shell-body:has(> .shell-rail) > .shell-main {
    flex: 1 1 0;
  }

  .shell-body > .shell-rail {
    flex: 0 0 var(--rail-width, 400px);
    width: var(--rail-width, 400px);
    margin-block-start: 0;
  }
}

/* The bottom bar of the phone shell (D2), which covers everything up to
   1023.98px; the desktop shell starts at 1024px. It exists when lane C1-D's tab
   bar partial emits its root; until then nothing is reserved. */
@media (max-width: 1023.98px) {
  body:has(#shell-tabbar-root) .shell-frame {
    padding-bottom: calc(var(--bottom-nav-height, 64px) + env(safe-area-inset-bottom, 0px));
  }
}

/* --------------------------------------------------------------------------
   Height reservation (L8-001)

   A lazy island mounts into an empty root, and everything after the root used
   to jump when its content arrived (CLS up to 1.2 on a phone). Each root
   declares what it holds, here, per breakpoint; one rule applies it; the mount
   helper in frontend/src/main.tsx sets data-island-ready on the root when the
   island has put its content there, and the reservation lets go.

   Two kinds of root:
     a page body (the island IS the page) holds one screen, so the footer and
       anything after it start below the fold before and after the island
       arrives, whatever its final height;
     a component with a fixed geometry holds exactly that geometry.

   The rule has no specificity (:where), so a root with a min-height of its
   own, such as #home-root, keeps it.
   -------------------------------------------------------------------------- */

:where([id$="-root"]:not([data-island-ready])) {
  min-height: var(--island-reserve, auto);
}

/* page bodies */
#home-feed-root,
#dashboard-widgets-root,
#create-activity-root,
#messages-app-root,
#community-list-root,
#community-detail-root,
#thread-detail-root,
#notification-inbox-root,
#calendar-day-root {
  --island-reserve: var(--shell-screen);
}

/* components with a fixed geometry: the month grid is 686px tall at every width */
#event-calendar-root {
  --island-reserve: 686px;
}

/* Islands that fill in stages (the dashboard and the home feed fetch their
   sections one by one, and each section lands at a different height) reveal
   when settled: the placeholder stays up and the content, mounted in
   .shell-island-content, is held out of sight and out of the flow until the
   mount helper marks the root ready. */
#dashboard-widgets-root {
  --island-reveal: settled;
}

[data-island-ready] > [data-island-placeholder] {
  display: none;
}

[id$="-root"]:not([data-island-ready]):has(> .shell-island-content) {
  position: relative;
}

[id$="-root"]:not([data-island-ready]) > .shell-island-content {
  position: absolute;
  inset-block-start: 0;
  inset-inline: 0;
  visibility: hidden;
  pointer-events: none;
}

/* A failed island shows its message at once. */
[id$="-root"]:not([data-island-ready]) > .shell-island-content:has(.error-boundary-fallback) {
  position: static;
  visibility: visible;
  pointer-events: auto;
}

/* The one loading placeholder (L8-017). The words are for assistive
   technology; the bars are decoration. */
.shell-island-placeholder {
  display: grid;
  align-content: start;
  gap: var(--space-md);
  padding-block: var(--space-md);
}

.shell-island-placeholder__bar {
  display: block;
  height: 5rem;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  background: var(--bg-card);
}

.shell-island-placeholder__bar:nth-child(2) {
  height: 9rem;
}

@media (prefers-reduced-motion: no-preference) {
  .shell-island-placeholder__bar {
    /* Three pulses, then still: nothing moves on its own for more than 5 s. */
    animation: shell-island-pulse 1.4s ease-in-out 3;
  }
}

@keyframes shell-island-pulse {
  50% {
    opacity: 0.55;
  }
}

/* --------------------------------------------------------------------------
   Footer (L2-002, L3-003)

   Links are touch-tier targets: 44px on a phone, 40px on a coarse pointer from
   768px, 30px on a fine one. The comma list of theme.css is kept for a fine
   pointer, where it reads as running text; below that the links are separate
   targets and the commas go.
   -------------------------------------------------------------------------- */

.shell-footer__links {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  margin-bottom: 0;
}

.shell-footer__links > a,
.shell-footer__links > .app-footer__link-button {
  display: inline-flex;
  align-items: center;
  min-height: var(--shell-target);
  padding: 0 var(--space-sm);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.shell-footer__links > .app-footer__link-button {
  appearance: none;
  background: transparent;
  border: 0;
  border-radius: 0;
  color: var(--link-color);
  font: inherit;
  cursor: pointer;
}

.shell-footer__links > :not(:last-child)::after {
  content: none;
}

@media (pointer: fine) {
  .shell-footer__links > a,
  .shell-footer__links > .app-footer__link-button {
    padding-inline: 0;
  }

  .shell-footer__links > :not(:last-child) {
    margin-inline-end: 0.3em;
  }

  .shell-footer__links > :not(:last-child)::after {
    content: ",";
  }
}

.shell-footer__legal {
  margin: 0;
}

/* --------------------------------------------------------------------------
   Reduced shell (L6-018): brand, step and exit

   A page opts in with {% block shell_variant %}reduced{% endblock %}. Only the
   bar shows; the sidebar, both headers and the floating buttons are hidden, so
   a first-run step is one task with one way out.
   -------------------------------------------------------------------------- */

.shell-reduced-bar {
  display: none;
}

body[data-shell="reduced"] .shell-reduced-bar {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  min-height: var(--topbar-height, 60px);
  padding: var(--space-sm) var(--container-pad, 16px);
  border-bottom: 1px solid var(--border-dark);
  background: var(--bg-secondary);
}

body[data-shell="reduced"] :is(
  .shell-sidebar,
  .shell-phone-header,
  .shell-topbar,
  .mobile-search-overlay,
  #bug-report-root,
  #onboarding-tour-root,
  #calendar-widget-btn,
  #calendar-widget-backdrop,
  #calendar-widget,
  #go-back-btn
) {
  display: none !important;
}

body[data-shell="reduced"] .app-content {
  margin-inline: 0;
  padding-bottom: 0;
}

.shell-reduced-bar__brand {
  font-family: var(--font-display);
  font-weight: 800;
  color: var(--text-primary);
  text-decoration: none;
}

.shell-reduced-bar__step {
  flex: 1;
  margin: 0;
  text-align: center;
  color: var(--text-secondary);
}

.shell-reduced-bar__exit a {
  display: inline-flex;
  align-items: center;
  min-height: var(--shell-target);
  color: var(--link-color);
}

/* --------------------------------------------------------------------------
   Consent panel (R2-004 and the leftovers of row W25b.F1 item g)

   The panel's own rules stay in templates/includes/cookie_consent_banner.html;
   what was added for this wave is here, so the page-local budget does not
   grow. Each selector names .cookie-consent first, because the inline style
   of the panel loads after this file.
   -------------------------------------------------------------------------- */

/* "Privacy details" is the third action of the panel, so it has the height of
   the two buttons above it: 44px on touch, 36px on a fine pointer (the md
   button tiers), not the 22px of a bare link. */
.cookie-consent .cookie-consent__link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
}

@media (pointer: fine) {
  .cookie-consent .cookie-consent__link {
    min-height: 36px;
  }
}

/* The panel is dark in both themes. A palette whose accent sits near it (a
   light purple's fill reads about as dark as the panel) would leave the
   choices without a visible edge, so each carries a light one. */
.cookie-consent .cookie-consent__actions [data-btn] {
  border: 1px solid rgba(255, 255, 255, 0.72);
}

/* The forced-colors and more-contrast block of theme.css rings every
   [tabindex]:focus-visible with !important. The panel is focused by script on
   open so that its name is read; one ring around the whole panel on each load
   is noise, and its controls keep their own rings. */
@media (forced-colors: active), (prefers-contrast: more) {
  .cookie-consent .cookie-consent__panel:focus-visible {
    outline: none !important;
  }
}
