/* ============================================================
   layout.css — Macro-level grid regions per DESIGNSTANDARD §2.
   Region templates use grid; component-level uses flexbox
   inside these regions.
   ============================================================ */

/* ---------- Public shell (auth pages, landing) ---------------
   Centered card on a full-viewport canvas. */
.SLYstyles.public-shell {
  min-height: 100vh;
  /* Matches the app shell: the visible viewport, not the tallest the
     mobile browser chrome ever lets it be. */
  min-height: 100dvh;
  display: grid;
  grid-template-rows: 1fr auto;
  background: var(--color-bg-secondary);
}
.SLYstyles.public-shell__main {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-8) var(--space-4);
  padding-left: max(var(--space-4), env(safe-area-inset-left));
  padding-right: max(var(--space-4), env(safe-area-inset-right));
}
.SLYstyles.public-shell__footer {
  text-align: center;
  padding: var(--space-4);
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}

/* ---------- App shell (authenticated pages) ------------------
   Desktop: sidebar | (header / main / footer).
   Mobile (<= --bp-tablet): single column with bottom nav. */
.SLYstyles.app-shell {
  height: 100vh;
  /* dvh tracks the *visible* viewport, so the mobile bottom-nav is not
     parked under the browser's collapsing URL bar. 100vh stays first as
     the fallback for engines without dvh. */
  height: 100dvh;
  display: grid;
  grid-template-areas:
    "sidebar header"
    "sidebar main"
    "sidebar footer";
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  /* minmax(0, 1fr) lets the main track shrink so its overflow-y:auto
     actually scrolls — otherwise the whole page scrolls and any
     position:sticky inside main never sticks. */
  grid-template-rows: var(--header-height) minmax(0, 1fr) var(--footer-height);
  background: var(--color-bg-secondary);
}

.SLYstyles.app-shell__sidebar { grid-area: sidebar; background: var(--color-surface); border-right: 1px solid var(--color-border); }

/* Compact rail. One variable carries the whole change: the grid column
   narrows, and so does anything else measured from --sidebar-width (the
   reader's floating chapter arrows, for one). Docked widths only — below
   the breakpoint the sidebar is a drawer at its own width, and
   connector.sidebarCompact.js sheds the attribute there anyway. */
@media (min-width: 769px) {
  :root[data-sidebar-compact="true"] {
    --sidebar-width: 76px;
  }

  .SLYstyles.app-shell {
    transition: grid-template-columns var(--t-base) var(--ease);
  }
}

@media (prefers-reduced-motion: reduce) {
  .SLYstyles.app-shell { transition: none; }
}
/* z-index: the color menu hangs out of this bar over the scrolling
   main region. A later grid item would paint on top of that overflow
   without a stacking context here. Stays under the mobile drawer (60). */
.SLYstyles.app-shell__header  { grid-area: header; position: relative; z-index: 30; background: var(--color-surface); border-bottom: 1px solid var(--color-border); display: flex; align-items: center; padding: 0 var(--space-6); justify-content: space-between; }
.SLYstyles.app-shell__main    { grid-area: main;    overflow-y: auto; overflow-x: hidden; padding: var(--space-6); }
.SLYstyles.app-shell__footer  { grid-area: footer;  background: var(--color-surface); border-top: 1px solid var(--color-border); display: flex; align-items: center; justify-content: center; padding: 0 var(--space-4); color: var(--color-text-muted); font-size: var(--text-sm); }
.SLYstyles.app-shell__mobile-nav { display: none; }

/* WHY: At tablet and below, the sidebar leaves the grid and becomes an
        off-canvas drawer; the bottom-nav takes over as the primary nav.
        Per DESIGNSTANDARD §1 (desktop-first) + project.config.md
        SIDEBAR_BREAKPOINT. */
@media (max-width: 768px) {
  .SLYstyles.app-shell {
    grid-template-areas:
      "header"
      "main"
      "mobile-nav";
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: var(--header-height) minmax(0, 1fr) auto;
  }

  /* WHY the three-class selector: components.css loads after layout.css
     and sets `.SLYstyles.sidebar { display: flex }` at the same
     specificity, which silently beat a plain
     `.SLYstyles.app-shell__sidebar { display: none }` here — the sidebar
     stayed in the grid on phones and squeezed `main` to a sliver. Matching
     both classes outranks it. Do not simplify this selector. */
  .SLYstyles.app-shell__sidebar.sidebar {
    /* Off-canvas drawer: still rendered (and focusable once open) so every
       destination stays reachable — the 4-slot bottom bar cannot carry
       Library / Challenge / Live / Reminders / Notes / Nice Verse /
       Settings / Admin / Sign out. */
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 60;
    width: min(86vw, 300px);
    max-width: 100%;
    padding-top: max(var(--space-4), env(safe-area-inset-top));
    padding-bottom: max(var(--space-4), env(safe-area-inset-bottom));
    padding-left: env(safe-area-inset-left);
    overflow-y: auto;
    overscroll-behavior: contain;
    border-right: 1px solid var(--color-border);
    box-shadow: var(--shadow-lg);
    transform: translateX(-100%);
    visibility: hidden;
    transition: transform var(--t-base) var(--ease), visibility 0s linear var(--t-base);
  }

  [data-nav-open="true"] .SLYstyles.app-shell__sidebar.sidebar {
    transform: translateX(0);
    visibility: visible;
    transition: transform var(--t-base) var(--ease), visibility 0s;
  }

  .SLYstyles.app-shell__footer { display: none; }

  .SLYstyles.app-shell__main {
    padding: var(--space-4);
    padding-left: max(var(--space-4), env(safe-area-inset-left));
    padding-right: max(var(--space-4), env(safe-area-inset-right));
  }

  .SLYstyles.app-shell__header {
    padding: 0 var(--space-3);
    padding-left: max(var(--space-3), env(safe-area-inset-left));
    padding-right: max(var(--space-3), env(safe-area-inset-right));
    gap: var(--space-2);
  }

  .SLYstyles.app-shell__mobile-nav {
    grid-area: mobile-nav;
    display: flex;
    background: var(--color-surface);
    border-top: 1px solid var(--color-border);
    /* Clear the iOS home indicator. */
    padding-bottom: env(safe-area-inset-bottom);
  }

  /* Scrim behind the open drawer. Rendered on every authed page but inert
     until the drawer opens. */
  .SLYstyles.app-shell__scrim {
    position: fixed;
    inset: 0;
    z-index: 55;
    background: rgba(15, 23, 42, 0.45);
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--t-base) var(--ease);
  }

  [data-nav-open="true"] .SLYstyles.app-shell__scrim {
    opacity: 1;
    pointer-events: auto;
  }
}

/* The drawer is a phone/tablet affordance only — above the breakpoint the
   sidebar is a permanent grid region and the scrim must never exist. */
@media (min-width: 769px) {
  .SLYstyles.app-shell__scrim { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .SLYstyles.app-shell__sidebar.sidebar,
  .SLYstyles.app-shell__scrim {
    transition: none;
  }
}

/* ---------- Content max-width helper ------------------------- */
.SLYstyles.content-wrap {
  max-width: var(--content-max);
  margin: 0 auto;
  width: 100%;
}

/* WHY: 34 views set their own narrower max-width inline (notes 760,
   profile 560, auth 420, admin 1100 …) and most never added the auto
   margins to go with it, so those pages sat hard against the sidebar
   while the few that remembered sat centred. Centring them here fixes
   every page at once and stops the next view from inheriting the bug.
   On a child with no width limit, auto margins do nothing — this only
   takes effect where a max-width actually constrains the box. */
.SLYstyles.content-wrap > * {
  margin-left: auto;
  margin-right: auto;
}
