/* ════════════════════════════════════════════════════════════════
   App shell — logged-in layout
   Activated by `body.has-app-shell` (set by chrome.js when the page
   has `data-app-shell="true"` AND a session is present).

   Desktop:  fixed left sidebar (260px) + slim top bar + main column
   Mobile:   slim top bar + bottom tab bar (5 tabs) + slide-out sidebar
   ════════════════════════════════════════════════════════════════ */

:root {
  --shell-sidebar-w: 260px;
  --shell-topbar-h: 56px;
  --shell-tabbar-h: 64px;
  --shell-bg: #FAFAF6;
  --shell-surface: #FFFFFF;
  --shell-ink: #0E1E1E;
  --shell-ink-2: #1F2D2D;
  --shell-ink-3: #4A5757;
  --shell-ink-4: #768181;
  --shell-line: rgba(14, 30, 30, 0.08);
  --shell-line-strong: rgba(14, 30, 30, 0.14);
  --shell-accent: #0E8479;
  --shell-accent-strong: #07564F;
  --shell-accent-soft: rgba(14, 132, 121, 0.10);
}

body.has-app-shell {
  background: var(--shell-bg);
  /* Reserve room for the sidebar at left, tabbar at bottom (mobile),
     topbar at top. The main content sits in the remaining area. */
  padding-top: var(--shell-topbar-h);
  padding-left: var(--shell-sidebar-w);
  padding-bottom: 0;
  min-height: 100vh;
}

/* The marketing nav and footer get hidden on shell pages — chrome.js
   already swaps the markup, but pages that render the nav before
   chrome.js fires get a flash if we don't gate it. */
body.has-app-shell .nav,
body.has-app-shell .footer-mark { display: none !important; }

/* ─── Top bar ─────────────────────────────────────────────────── */
body.has-app-shell .shell-topbar {
  position: fixed;
  top: 0;
  left: var(--shell-sidebar-w);
  right: 0;
  height: var(--shell-topbar-h);
  z-index: 90;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 18px;
  background: var(--shell-surface);
  border-bottom: 1px solid var(--shell-line);
}
.shell-topbar-toggle {
  display: none;
  appearance: none;
  border: 0;
  background: transparent;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  cursor: pointer;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
}
.shell-topbar-toggle span {
  display: block;
  width: 18px;
  height: 2px;
  background: var(--shell-ink-2);
  border-radius: 2px;
}
.shell-topbar-toggle:hover { background: rgba(14, 30, 30, 0.04); }

.shell-topbar-logo {
  display: none; /* desktop hides the logo (sidebar has it); mobile shows */
  align-items: center;
  gap: 8px;
  text-decoration: none;
  color: inherit;
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: -0.01em;
}
.shell-topbar-spacer { flex: 1; }
.shell-topbar-action,
.shell-topbar-avatar {
  appearance: none;
  border: 0;
  background: transparent;
  width: 40px;
  height: 40px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--shell-ink-2);
  cursor: pointer;
  text-decoration: none;
  position: relative;
  overflow: hidden;
}
.shell-topbar-action:hover,
.shell-topbar-avatar:hover { background: rgba(14, 30, 30, 0.04); }
.shell-topbar-avatar img { width: 100%; height: 100%; object-fit: cover; }
.shell-topbar-avatar { background: linear-gradient(140deg, var(--shell-accent), var(--shell-accent-strong)); color: #fff; font-weight: 700; }
.shell-avatar-seed { font-size: 0.95rem; }

/* Account dropdown menu */
.shell-account-menu {
  position: fixed;
  top: calc(var(--shell-topbar-h) - 4px);
  right: 14px;
  width: 260px;
  background: var(--shell-surface);
  border: 1px solid var(--shell-line);
  border-radius: 14px;
  box-shadow: 0 16px 40px rgba(14,30,30,0.16), 0 4px 12px rgba(14,30,30,0.06);
  display: grid;
  gap: 2px;
  padding: 12px;
  z-index: 100;
}
.shell-account-menu[hidden] { display: none; }
.shell-account-head {
  display: grid;
  gap: 2px;
  padding: 4px 8px 12px;
  border-bottom: 1px solid var(--shell-line);
  margin-bottom: 6px;
}
.shell-account-head strong { font-size: 0.95rem; }
.shell-account-head .muted { font-size: 0.8rem; color: var(--shell-ink-4); }
.shell-account-menu a,
.shell-account-menu button {
  appearance: none;
  border: 0;
  background: transparent;
  text-decoration: none;
  color: var(--shell-ink-2);
  font: inherit;
  font-size: 0.92rem;
  text-align: left;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.shell-account-menu a:hover,
.shell-account-menu button:hover { background: rgba(14, 30, 30, 0.05); }
.shell-signout { color: var(--shell-ink-2); }
.shell-signout:hover { color: var(--shell-accent-strong); }

/* ─── Sidebar ─────────────────────────────────────────────────── */
.shell-sidebar {
  position: fixed;
  left: 0;
  top: 0;
  bottom: 0;
  width: var(--shell-sidebar-w);
  background: var(--shell-surface);
  border-right: 1px solid var(--shell-line);
  display: grid;
  grid-template-rows: auto 1fr auto;
  z-index: 95;
  overflow: hidden;
}
.shell-sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--shell-line);
  font-weight: 700;
  letter-spacing: -0.01em;
  font-size: 1.1rem;
}
.shell-sidebar-brand img { border-radius: 8px; }

.shell-sidebar-nav {
  overflow-y: auto;
  padding: 12px 10px 18px;
  display: grid;
  gap: 14px;
  /* Subtle scrollbar styling — Safari/Firefox aware */
  scrollbar-width: thin;
  scrollbar-gutter: stable;
}
.shell-nav-group ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 1px;
}
.shell-nav-group-label {
  font-size: 0.66rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 700;
  color: var(--shell-ink-4);
  padding: 0 10px 6px;
}
.shell-nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 10px;
  text-decoration: none;
  color: var(--shell-ink-3);
  font-size: 0.92rem;
  font-weight: 500;
  position: relative;
  transition: background 0.12s, color 0.12s;
}
.shell-nav-item:hover {
  background: rgba(14, 30, 30, 0.04);
  color: var(--shell-ink-2);
}
.shell-nav-item.is-active {
  background: var(--shell-accent-soft);
  color: var(--shell-accent-strong);
  font-weight: 600;
}
.shell-nav-item.is-active::before {
  content: "";
  position: absolute;
  left: -10px;
  top: 7px;
  bottom: 7px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--shell-accent-strong);
}
.shell-nav-icon {
  width: 22px;
  height: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  opacity: 0.85;
}
.shell-nav-item:hover .shell-nav-icon,
.shell-nav-item.is-active .shell-nav-icon { opacity: 1; }
.shell-nav-label {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Sidebar foot — account row + sign-out */
.shell-sidebar-foot {
  border-top: 1px solid var(--shell-line);
  padding: 12px;
  display: grid;
  gap: 6px;
  background: var(--shell-bg);
}
.shell-sidebar-account {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-radius: 10px;
  text-decoration: none;
  color: inherit;
  transition: background 0.12s;
}
.shell-sidebar-account:hover { background: rgba(14, 30, 30, 0.05); }
.shell-sidebar-avatar {
  width: 36px;
  height: 36px;
  border-radius: 999px;
  background: linear-gradient(140deg, var(--shell-accent), var(--shell-accent-strong));
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 700;
  overflow: hidden;
  flex-shrink: 0;
}
.shell-sidebar-avatar img { width: 100%; height: 100%; object-fit: cover; }
.shell-sidebar-account-text {
  display: grid;
  gap: 2px;
  min-width: 0;
}
.shell-sidebar-account-text strong {
  font-size: 0.9rem;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.shell-sidebar-account-text .muted {
  font-size: 0.74rem;
  color: var(--shell-ink-4);
}
.shell-sidebar-signout {
  appearance: none;
  border: 1px solid transparent;
  background: transparent;
  color: var(--shell-ink-3);
  font: inherit;
  font-size: 0.86rem;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border-radius: 8px;
  cursor: pointer;
  text-align: left;
  width: 100%;
}
.shell-sidebar-signout:hover {
  background: rgba(201, 52, 58, 0.08);
  color: var(--shell-accent-strong);
  border-color: rgba(14, 30, 30, 0.10);
}

/* ─── Sidebar mobile slide-out ────────────────────────────────── */
.shell-sidebar-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(14, 30, 30, 0.42);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  z-index: 94;
}

/* ─── Bottom tab bar (mobile) ─────────────────────────────────── */
.shell-tabbar {
  display: none;
}
.shell-tab {
  display: inline-grid;
  place-items: center;
  gap: 2px;
  padding: 8px 0;
  text-decoration: none;
  color: var(--shell-ink-3);
  flex: 1;
  font-size: 0.7rem;
  font-weight: 500;
  position: relative;
  transition: color 0.12s;
}
.shell-tab.is-active { color: var(--shell-accent-strong); font-weight: 700; }
.shell-tab.is-active::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 50%;
  transform: translateX(-50%);
  width: 22px;
  height: 3px;
  border-radius: 999px;
  background: var(--shell-accent-strong);
}
.shell-tab-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
}
.shell-tab-label { letter-spacing: 0.01em; }

/* ─── Mobile breakpoint ───────────────────────────────────────── */
@media (max-width: 880px) {
  body.has-app-shell {
    padding-left: 0;
    padding-bottom: var(--shell-tabbar-h);
  }
  body.has-app-shell .shell-topbar {
    left: 0;
  }
  .shell-topbar-toggle { display: inline-flex; }
  .shell-topbar-logo { display: inline-flex; }

  .shell-sidebar {
    transform: translateX(-100%);
    transition: transform 0.24s cubic-bezier(0.16, 1, 0.3, 1);
    box-shadow: 16px 0 40px rgba(14,30,30,0.20);
  }
  .shell-sidebar.is-open { transform: translateX(0); }

  .shell-tabbar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--shell-tabbar-h);
    background: var(--shell-surface);
    border-top: 1px solid var(--shell-line);
    z-index: 95;
    display: flex;
    align-items: stretch;
    padding-bottom: env(safe-area-inset-bottom, 0);
  }
}

/* ─── Skip link / a11y ────────────────────────────────────────── */
body.has-app-shell .skip-link {
  z-index: 200;
}

/* Hide the marketing footer host inside shell pages. */
body.has-app-shell [data-chrome="footer"] { display: none !important; }

/* Some Tier-1 pages (cognitive, hydration, supplements, etc.) bake
   an in-page email + sign-out header into the layout. With the
   shell topbar already showing the avatar dropdown + sign-out, that
   in-page block is duplicative. Hide it. */
body.has-app-shell .tb-meta,
body.has-app-shell .tba-meta,
body.has-app-shell .log-meta,
body.has-app-shell .tba-page-meta,
body.has-app-shell .page-account-row { display: none !important; }

/* ─── Page-level padding compensation ─────────────────────────────
   The original logged-in pages were laid out for the marketing top
   nav (~64px), so they reserve a chunky padding-top (often 5-6rem
   or 96px) to clear it. The shell uses a slim 56px topbar, so any
   extra page padding is purely empty space. Trim the most-common
   wrappers when the shell is active so pages don't look like
   they're floating mid-screen.
   ───────────────────────────────────────────────────────────── */
body.has-app-shell .home-page { padding-top: 28px; padding-bottom: 60px; }
body.has-app-shell .tools-page { padding-top: 28px; padding-bottom: 60px; }
body.has-app-shell .account-shell { padding-top: 28px; padding-bottom: 60px; }
body.has-app-shell .what-if-hero { padding-top: 28px; }
body.has-app-shell .feed-page { padding-top: 28px; padding-bottom: 60px; }
body.has-app-shell .cog-page,
body.has-app-shell .meditate-page,
body.has-app-shell .protocols-page,
body.has-app-shell .screenings-page,
body.has-app-shell .family-page,
body.has-app-shell .genome-page,
body.has-app-shell .log-page,
body.has-app-shell .streak-page { padding-top: 28px; padding-bottom: 60px; }
body.has-app-shell main { padding-top: 0; }

/* Skinny rule for any page that uses a hero with `padding: 5-6rem 0`. */
body.has-app-shell .conversation-shell,
body.has-app-shell .doctor-shell,
body.has-app-shell .auth-shell { padding-top: 0; }

/* Tier-1 surfaces (supplements/hydration/body-protocols) tend to use
   `tools-daily.css` and a `.tba-shell` wrapper. Give the wrapper a
   uniform breath without the stale marketing-nav clearance. */
body.has-app-shell .tba-shell,
body.has-app-shell #main-content { padding-top: 28px; padding-bottom: 80px; }
body.has-app-shell .tba-hero { padding-top: 28px; }
