/* ===========================================================================
   The shell — one markup tree, three device grammars.

     < 768px    App bar + single-column stream + fixed bottom tab bar
     768–1199   Icon rail + header + fluid 2-column canvas
     ≥ 1200px   Persistent labelled sidebar + header + bounded dashboard canvas

   The bottom tab bar and the sidebar are mutually exclusive: whichever one is
   mounted, the other is display:none. Nothing is ever "a phone layout stretched
   across a monitor", and nothing is ever "a desktop table squeezed onto a phone".
   =========================================================================== */

.app-root { min-height: 100dvh; }

.boot {
  min-height: 100dvh;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: var(--sp-5);
  color: var(--brand);
}
.boot__mark { width: 56px; height: 56px; animation: boot-pulse 1.8s var(--ease) infinite; }
.boot__bar {
  display: block; width: 132px; height: 3px;
  background: var(--line); border-radius: var(--r-pill); overflow: hidden;
}
.boot__bar i {
  display: block; width: 40%; height: 100%;
  background: var(--brand); border-radius: inherit;
  animation: boot-slide 1.25s var(--ease) infinite;
}
@keyframes boot-pulse { 0%, 100% { opacity: 0.55; } 50% { opacity: 1; } }
@keyframes boot-slide { 0% { transform: translateX(-110%); } 100% { transform: translateX(360%); } }

.app-boot-error {
  margin: 0 auto;
  max-width: 44rem;
  padding: var(--sp-3) var(--sp-4);
  color: var(--ink);
  font-size: var(--fs-sm);
}

/* --------------------------------------------------------------------------
   Frame
   -------------------------------------------------------------------------- */
.shell {
  min-height: 100dvh;
  display: grid;
  grid-template-columns: 1fr;
}

.shell__main {
  min-width: 0;
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

.canvas {
  flex: 1;
  width: 100%;
  max-width: var(--canvas-max);
  margin-inline: auto;
  padding: var(--gutter);
  padding-left: max(var(--gutter), env(safe-area-inset-left));
  padding-right: max(var(--gutter), env(safe-area-inset-right));
  padding-bottom: calc(var(--tabbar-h) + var(--sp-6) + env(safe-area-inset-bottom));
}

/* --------------------------------------------------------------------------
   App bar
   -------------------------------------------------------------------------- */
.appbar {
  position: sticky;
  top: 0;
  z-index: var(--z-header);
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  min-height: var(--header-h);
  padding: var(--sp-2) var(--gutter);
  padding-top: max(var(--sp-2), env(safe-area-inset-top));
  padding-left: max(var(--gutter), env(safe-area-inset-left));
  padding-right: max(var(--gutter), env(safe-area-inset-right));
  background: color-mix(in srgb, var(--canvas) 82%, transparent);
  backdrop-filter: saturate(150%) blur(18px);
  -webkit-backdrop-filter: saturate(150%) blur(18px);
  border-bottom: 1px solid var(--line-faint);
}
.appbar__titles { min-width: 0; flex: 1; display: grid; }
.appbar__title {
  font-size: 1.02rem;
  font-weight: 650;
  letter-spacing: var(--tracking-tight);
  line-height: 1.2;
}
.appbar__sub {
  font-size: var(--fs-xs);
  color: var(--ink-3);
  line-height: 1.3;
}
.appbar__actions { display: flex; align-items: center; gap: var(--sp-2); }

.appbar__brand { display: none; align-items: center; gap: 0.55rem; }
.appbar__brand { color: var(--brand); }
.appbar__brand svg { width: 26px; height: 26px; }
.appbar__brand b { font-weight: 680; letter-spacing: -0.02em; }

/* --------------------------------------------------------------------------
   Sidebar / rail
   -------------------------------------------------------------------------- */
.sidebar {
  display: none;
  /* Sticky, not fixed. A fixed sidebar leaves the grid to place the main column
     in track 1 — underneath the sidebar — so the app renders behind its own
     navigation. Sticky keeps it pinned while it still occupies its track. */
  position: sticky;
  top: 0;
  align-self: start;
  height: 100dvh;
  width: 100%;
  z-index: var(--z-nav);
  flex-direction: column;
  gap: var(--sp-2);
  padding: var(--sp-4) var(--sp-3);
  padding-top: max(var(--sp-4), env(safe-area-inset-top));
  padding-bottom: max(var(--sp-4), env(safe-area-inset-bottom));
  background: var(--canvas-deep);
  border-right: 1px solid var(--line);
  overflow-y: auto;
  overscroll-behavior: contain;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: var(--sp-2) var(--sp-2) var(--sp-4);
  min-width: 0;
}
.brand__mark {
  width: 34px; height: 34px; flex: none;
  color: var(--brand);
}
.brand__mark svg { width: 100%; height: 100%; }
.brand__name {
  font-size: 1.02rem; font-weight: 680; letter-spacing: -0.02em;
  line-height: 1.1;
}
.brand__tag {
  display: block;
  font-size: var(--fs-micro); font-weight: 600; letter-spacing: var(--tracking-label);
  text-transform: uppercase; color: var(--ink-3);
}

.nav-group { display: grid; gap: 2px; margin-bottom: var(--sp-3); }
.nav-group__label {
  padding: var(--sp-2) var(--sp-3) var(--sp-1);
  font-size: var(--fs-micro); font-weight: 680;
  letter-spacing: var(--tracking-label); text-transform: uppercase;
  color: var(--ink-3);
}

.nav-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.6rem var(--sp-3);
  border-radius: var(--r-sm);
  color: var(--ink-2);
  font-size: 0.9rem;
  font-weight: 560;
  transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}
.nav-item svg { width: 19px; height: 19px; flex: none; opacity: 0.9; }
.nav-item__label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-item[aria-current="page"] {
  background: var(--brand-wash);
  color: var(--ink);
}
.nav-item[aria-current="page"]::before {
  content: "";
  position: absolute; left: 0; top: 50%;
  width: 3px; height: 18px;
  margin-top: -9px;
  border-radius: 0 3px 3px 0;
  background: var(--brand);
}
@media (hover: hover) and (pointer: fine) {
  .nav-item:hover { background: var(--s2); color: var(--ink); }
  .nav-item[aria-current="page"]:hover { background: var(--brand-wash); }
}

.nav-item__badge {
  min-width: 20px; height: 20px; padding: 0 6px;
  display: grid; place-items: center;
  border-radius: var(--r-pill);
  background: var(--brand); color: var(--on-brand);
  font-size: var(--fs-micro); font-weight: 720;
  font-variant-numeric: tabular-nums;
}

.sidebar__foot { margin-top: auto; display: grid; gap: var(--sp-2); padding-top: var(--sp-3); }

.who {
  display: flex; align-items: center; gap: 0.65rem;
  padding: 0.6rem var(--sp-3);
  border-radius: var(--r-sm);
  border: 1px solid var(--line);
  background: var(--s1);
  min-width: 0;
}
.who__avatar {
  width: 30px; height: 30px; flex: none;
  display: grid; place-items: center;
  border-radius: var(--r-pill);
  background: var(--brand); color: var(--on-brand);
  font-weight: 720; font-size: var(--fs-sm);
}
.who__name { font-size: var(--fs-sm); font-weight: 620; line-height: 1.2; }
.who__meta { font-size: var(--fs-micro); color: var(--ink-3); }

/* --------------------------------------------------------------------------
   Bottom tab bar (mobile, thumb zone)
   -------------------------------------------------------------------------- */
/* `position: fixed` pins to the LAYOUT viewport, which on a mobile browser is
   taller than the pixels you can actually see while the URL bar is collapsing —
   so the bar slides off the bottom of the screen as you scroll, which is exactly
   the bug this rule exists to kill. `--tabbar-shift` is written by
   trackTabbarViewport() in app.js from window.visualViewport and pulls the bar
   back onto the visible area; with no visualViewport support it stays 0 and the
   bar behaves as before. translate3d keeps it on its own compositing layer so
   the blur is not repainted on every scroll frame. */
.tabbar {
  position: fixed;
  inset: auto 0 0 0;
  z-index: var(--z-nav);
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  align-items: stretch;
  min-height: var(--tabbar-h);
  padding-bottom: env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--canvas) 88%, transparent);
  backdrop-filter: saturate(160%) blur(20px);
  -webkit-backdrop-filter: saturate(160%) blur(20px);
  border-top: 1px solid var(--line);
  box-shadow: 0 -8px 24px -18px rgba(0, 0, 0, 0.9);
  transform: translate3d(0, var(--tabbar-shift, 0px), 0);
  will-change: transform;
}
/* Without a working backdrop filter the translucent fill turns into a smear of
   half-legible content behind the labels. Fall back to the opaque canvas. */
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .tabbar { background: var(--canvas); }
}
/* The on-screen keyboard is not the URL bar: a tab bar riding on top of it is
   in the way of the thing being typed. Native apps drop it, so this does too. */
.tabbar.is-stowed {
  transform: translate3d(0, 110%, 0);
  transition: transform var(--t-base) var(--ease);
}
.tab {
  position: relative;
  display: grid;
  justify-items: center;
  align-content: center;
  gap: 3px;
  padding: 6px 2px 8px;
  color: var(--ink-3);
  font-size: var(--fs-micro);
  font-weight: 600;
  touch-action: manipulation;
}
.tab svg { width: 22px; height: 22px; }
.tab[aria-current="page"] { color: var(--brand-ink); }
.tab[aria-current="page"]::before {
  content: "";
  position: absolute; top: 0; left: 50%;
  width: 26px; height: 2px; margin-left: -13px;
  border-radius: 0 0 3px 3px;
  background: var(--brand);
}
.tab__dot {
  position: absolute;
  top: 5px; left: calc(50% + 8px);
  width: 8px; height: 8px;
  border-radius: var(--r-pill);
  background: var(--brand);
  border: 2px solid var(--canvas);
}

/* --------------------------------------------------------------------------
   Tier 2 — tablet / compact laptop: the rail
   -------------------------------------------------------------------------- */
@media (min-width: 768px) {
  .tabbar { display: none; }

  .shell { grid-template-columns: var(--rail-w) 1fr; }
  .sidebar {
    display: flex;
    padding-inline: 10px;
    align-items: stretch;
  }
  .canvas { padding-bottom: var(--sp-7); }

  .brand { justify-content: center; padding: var(--sp-2) 0 var(--sp-5); }
  .brand__text, .nav-group__label, .nav-item__label, .who__name, .who__meta { display: none; }

  .nav-item {
    justify-content: center;
    padding: 0.7rem 0;
  }
  .nav-item svg { width: 21px; height: 21px; }
  .nav-item[aria-current="page"]::before { left: -10px; }
  .nav-item__badge {
    position: absolute; top: 4px; right: 6px;
    min-width: 16px; height: 16px; padding: 0 4px;
    font-size: 9px;
  }
  .who { justify-content: center; padding: 0.5rem 0; }
  .sidebar__foot .btn__label { display: none; }
  .sidebar__foot .btn { justify-content: center; padding-inline: 0; }
}

/* --------------------------------------------------------------------------
   Tier 3 — wide desktop: the labelled sidebar
   -------------------------------------------------------------------------- */
@media (min-width: 1200px) {
  .shell { grid-template-columns: var(--sidebar-w) 1fr; }
  .sidebar { padding-inline: var(--sp-3); }

  .brand { justify-content: flex-start; padding: var(--sp-2) var(--sp-2) var(--sp-5); }
  .brand__text, .nav-group__label, .nav-item__label, .who__name, .who__meta { display: block; }
  .nav-item { justify-content: flex-start; padding: 0.6rem var(--sp-3); }
  .nav-item svg { width: 19px; height: 19px; }
  .nav-item[aria-current="page"]::before { left: -12px; }
  .nav-item__badge { position: static; min-width: 20px; height: 20px; padding: 0 6px; font-size: var(--fs-micro); }
  .who { justify-content: flex-start; padding: 0.6rem var(--sp-3); }
  .sidebar__foot .btn { justify-content: flex-start; padding-inline: var(--sp-3); }
  .sidebar__foot .btn__label { display: inline; }

  .appbar { padding-block: var(--sp-3); }
}

/* On mobile the brand belongs in the app bar, since there is no sidebar. */
@media (max-width: 767px) {
  .appbar__brand { display: flex; }
  .appbar__brand + .appbar__titles .appbar__title { font-size: 0.95rem; }
}

/* On the coach itself the "Ask coach" shortcut points at the page you are on. */
body[data-route="/coach"] .appbar [data-ask] { display: none; }

/* Each navigation swaps in a fresh <main>, so this plays once per page change —
   repaints inside a view replace the children, not the outlet, and stay still. */
.canvas { animation: view-in 280ms var(--ease-out); }
@keyframes view-in { from { opacity: 0; transform: translateY(6px); } }

/* The active tab gets a soft pill behind its icon, not just a hairline. */
.tab svg { transition: transform var(--t-base) var(--ease-out); }
.tab[aria-current="page"] svg {
  transform: translateY(-1px) scale(1.06);
  filter: drop-shadow(0 4px 10px var(--brand-glow));
}
.tab:active svg { transform: scale(0.9); }
