/* ==========================================================================
   Layout — app shell: rail + topbar + page, collapsing to a mobile bottom nav
   ========================================================================== */
.shell {
  display: grid;
  grid-template-columns: var(--rail) minmax(0, 1fr);
  min-height: 100svh;
}

/* ---------------------------------------------------------------- Rail --- */
.rail {
  position: sticky; top: 0; z-index: 60;
  height: 100svh;
  display: flex; flex-direction: column;
  gap: var(--s-5);
  padding: var(--s-5) var(--s-4);
  background: var(--surface);
  border-right: 1px solid var(--line);
  overflow-y: auto;
  transition: background-color var(--d-base) var(--e-inout),
              border-color var(--d-base) var(--e-inout);
}

.rail-brand {
  display: flex; align-items: center; gap: var(--s-3);
  padding: var(--s-2);
  border-radius: var(--r-md);
}
.rail-brand .logo-mark { width: 42px; height: 42px; flex: none; }
.rail-brand-text { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
.rail-brand-text b {
  font-family: var(--font-head); font-size: var(--t-md);
  font-weight: 600; letter-spacing: -.02em;
}
.rail-brand-text span {
  font-size: var(--t-xs); color: var(--ink-soft);
  letter-spacing: .08em; text-transform: uppercase; font-weight: 600;
}

.rail-nav { display: flex; flex-direction: column; gap: 2px; }
.rail-heading {
  font-size: var(--t-xs); font-weight: 700; letter-spacing: .1em;
  text-transform: uppercase; color: var(--ink-faint);
  padding: 0 var(--s-3) var(--s-2);
}

.nav-item {
  position: relative;
  display: flex; align-items: center; gap: var(--s-3);
  min-height: 44px;                     /* touch target */
  padding: var(--s-2) var(--s-3);
  border-radius: var(--r-sm);
  color: var(--ink-soft); font-weight: 500;
  text-align: left;
  transition: background-color var(--d-fast) var(--e-out),
              color var(--d-fast) var(--e-out);
}
.nav-item svg { width: 19px; height: 19px; flex: none; }
.nav-item:hover { background: var(--surface-3); color: var(--ink); }
.nav-item[aria-current="page"] { background: var(--accent-wash); color: var(--accent-ink); font-weight: 600; }
/* Active marker slides between items rather than blinking on */
.nav-item[aria-current="page"]::before {
  content: ""; position: absolute; left: calc(var(--s-4) * -1);
  top: 50%; width: 3px; height: 22px; border-radius: 0 3px 3px 0;
  background: var(--accent);
  transform: translateY(-50%);
  animation: markerIn var(--d-base) var(--e-out-expo) both;
}
@keyframes markerIn { from { transform: translateY(-50%) scaleY(.2); opacity: 0; } }
.nav-count {
  margin-left: auto; font-size: var(--t-xs); font-weight: 700;
  min-width: 22px; height: 20px; padding: 0 6px;
  display: grid; place-items: center;
  border-radius: var(--r-pill);
  background: var(--surface-3); color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
}
/* --accent is a fill colour, not a text background: white on it is 2.5:1.
   --accent-ink is the text-safe tone in BOTH themes — dark in light mode,
   light in dark mode — so the label must be --surface, not a literal white. */
.nav-item[aria-current="page"] .nav-count { background: var(--accent-ink); color: var(--surface); }

.rail-foot { margin-top: auto; display: grid; gap: var(--s-3); }

/* ------------------------------------------------------------- Topbar --- */
.topbar {
  position: sticky; top: 0; z-index: 50;
  height: var(--topbar);
  display: flex; align-items: center; gap: var(--s-3);
  padding: 0 var(--s-5);
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(1.6) blur(14px);
  -webkit-backdrop-filter: saturate(1.6) blur(14px);
  border-bottom: 1px solid transparent;
  transition: border-color var(--d-base) var(--e-out),
              background-color var(--d-base) var(--e-out);
}
.topbar.is-stuck { border-bottom-color: var(--line); }

.crumb { display: flex; align-items: center; gap: var(--s-2); min-width: 0; }
.crumb-root { color: var(--ink-faint); font-size: var(--t-sm); white-space: nowrap; }
.crumb svg { width: 14px; height: 14px; color: var(--ink-faint); flex: none; }
.crumb-name {
  font-weight: 600; font-family: var(--font-head);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  max-width: 30ch;
}
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: var(--s-2); }

/* --------------------------------------------------------------- Page --- */
.page {
  width: min(1180px, 100%);
  margin-inline: auto;
  padding: var(--s-5) var(--s-5) var(--s-8);
  display: grid; gap: var(--s-5);
}
.view { display: grid; gap: var(--s-5); }
.view[hidden] { display: none !important; }

/* --------------------------------------------------------- Mobile nav --- */
.mobile-nav { display: none; }

@media (max-width: 1024px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .rail { display: none; }
  .page { padding: var(--s-4) var(--s-4) calc(var(--mobile-nav-h) + env(safe-area-inset-bottom) + var(--s-6)); }
  .topbar { padding: 0 var(--s-4); }
  .crumb-name { max-width: 18ch; }

  .mobile-nav {
    position: fixed; z-index: 70;
    left: 0; right: 0; bottom: 0;
    display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
    padding: var(--s-2) var(--s-2) calc(var(--s-2) + env(safe-area-inset-bottom));
    background: color-mix(in srgb, var(--surface) 90%, transparent);
    backdrop-filter: saturate(1.6) blur(18px);
    -webkit-backdrop-filter: saturate(1.6) blur(18px);
    border-top: 1px solid var(--line);
  }
  .mobile-nav button {
    display: grid; justify-items: center; gap: 3px;
    min-height: 52px; padding: var(--s-2) var(--s-1);
    border-radius: var(--r-sm);
    color: var(--ink-faint); font-size: var(--t-xs); font-weight: 600;
    transition: color var(--d-fast) var(--e-out);
  }
  .mobile-nav button svg { width: 21px; height: 21px; transition: transform var(--d-base) var(--e-out-expo); }
  .mobile-nav button[aria-current="page"] { color: var(--accent-ink); }
  .mobile-nav button[aria-current="page"] svg { transform: translateY(-2px) scale(1.08); }
  .mobile-nav button:active svg { transform: scale(.9); }
}

@media (max-width: 600px) {
  .page { padding-inline: var(--s-3); }
  :root { --t-3xl: 1.85rem; --t-4xl: 2.15rem; --t-2xl: 1.4rem; }
}
