/* ================================================================
   ORION Observatory — Layout
   App shell, sidebar, responsive grid
   ================================================================ */

/* ── App Shell ──
   Fixed to the viewport (not min-height) with overflow:hidden so the
   document itself never scrolls — .main-content below is the single
   scroll container. Two nested min-height:100vh boxes, one of them also
   overflow-y:auto, was the "scroll does nothing until I flick twice" bug
   (finding 06): neither box was ever actually height-constrained, so the
   auto scroller never engaged and the whole document scrolled instead.
   100dvh (dynamic viewport height) after the 100vh fallback so iOS
   Safari's collapsing URL bar doesn't leave a stale viewport height. */
.app-shell {
  display: flex;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  position: relative;
}

/* ── Starfield Canvas (behind everything) ── */
#starfield-canvas {
  position: fixed;
  inset: 0;
  z-index: var(--z-starfield);
  pointer-events: none;
}

/* ── Sidebar ── */
.sidebar {
  position: fixed;
  left: 0;
  top: 0;
  bottom: 0;
  width: 262px;
  flex: 0 0 262px;
  z-index: var(--z-sidebar);
  display: flex;
  flex-direction: column;
  gap: 22px;
  padding: 26px 0 20px;
  background: linear-gradient(180deg, rgba(255,255,255,0.016), rgba(0,0,0,0.08) 34%, rgba(0,0,0,0.28));
  border-right: 1px solid var(--c-hair);
  backdrop-filter: var(--glass-blur-lg);
  -webkit-backdrop-filter: var(--glass-blur-lg);
  transition: transform var(--t-slow) var(--ease-out);
}

/* ── Logo ── */
.brand-lockup {
  display: flex;
  align-items: flex-start;
  justify-content: flex-start;
  padding: 0 0 0 16px;
}

.brand-lockup__content {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}

.brand-lockup__name {
  display: inline-block;
  font-family: var(--f-brand);
  font-size: var(--fs-xl);
  font-weight: 600;
  letter-spacing: 0.42em;
  line-height: 1;
  color: #fff;
  margin-left: 0;
  position: relative;
}

.brand-lockup__rail {
  position: relative;
  width: 124px;
  height: 10px;
  margin-top: 6px;
  margin-left: 4px;
  background:
    radial-gradient(55% 48% at 50% 57%, rgba(255,255,255,0.14), transparent 72%),
    linear-gradient(90deg, transparent 0%, rgba(255,255,255,0.02) 16%, rgba(255,255,255,0.34) 50%, rgba(255,255,255,0.02) 84%, transparent 100%);
  opacity: 0.54;
}

.brand-lockup__rail::before {
  content: "";
  position: absolute;
  left: 12px;
  right: 12px;
  top: 5px;
  height: 1px;
  background: linear-gradient(90deg, transparent 0%, rgba(255,255,255,0.22) 20%, rgba(255,255,255,0.74) 50%, rgba(255,255,255,0.22) 80%, transparent 100%);
  box-shadow: 0 0 8px rgba(255,255,255,0.28);
}

.brand-lockup__rail::after {
  content: "";
  position: absolute;
  left: 30px;
  right: 30px;
  top: 8px;
  height: 4px;
  background: radial-gradient(50% 100% at 50% 0%, rgba(255,255,255,0.22), transparent 70%);
  filter: blur(3px);
}

.brand-lockup__tag {
  font-family: var(--f-mono);
  font-size: var(--fs-micro);
  letter-spacing: 0.26em;
  color: var(--faint);
  margin-top: 7px;
  text-transform: uppercase;
}

/* ── Navigation ── */
.sidebar__nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
  overflow-y: auto;
  padding-right: 2px;
}

.nav-item {
  display: flex;
  flex-direction: column;
  gap: 5px;
  align-items: flex-start;
  text-align: left;
  width: 100%;
  padding: 11px 22px;
  border-radius: 12px;
  cursor: pointer;
  background: transparent;
  border: 1px solid transparent;
  color: rgba(244,244,246,0.58);
  transition: background .15s, color .15s, border-color .15s, box-shadow .15s;
}

.nav-item__cat {
  font-family: var(--f-mono);
  font-size: var(--fs-micro);
  letter-spacing: 0.22em;
  color: rgba(244,244,246,0.38);
  padding-left: 2px;
}

.nav-item__label {
  display: flex;
  align-items: center;
  gap: 12px;
}

.nav-item__dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  border: 1.5px solid rgba(244,244,246,0.34);
  background: transparent;
  flex: 0 0 9px;
}

.nav-item__text {
  font-size: var(--fs-base);
  font-weight: 400;
  letter-spacing: 0.01em;
  color: rgba(244,244,246,0.8);
}

.nav-item:hover {
  background: rgba(255, 255, 255, 0.018);
  color: var(--text);
}

.nav-item:hover .nav-item__cat,
.nav-item:hover .nav-item__text {
  color: rgba(244,244,246,0.72);
}

.nav-item--active {
  background: linear-gradient(90deg, rgba(255,255,255,0.092), rgba(255,255,255,0.036));
  border-color: rgba(255,255,255,0.22);
  color: var(--text);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.035), 0 0 24px rgba(var(--glow),0.055);
}

.nav-item--active .nav-item__dot {
  border: 1.5px solid var(--accent);
  background: var(--accent);
  box-shadow: 0 0 7px rgba(var(--glow),.86), 0 0 14px rgba(var(--glow),.30);
}

.nav-item--active .nav-item__cat {
  color: rgba(244,244,246,0.58);
}

.nav-item--active .nav-item__text {
  color: var(--text);
  font-weight: 400;
}
.nav-item__label {
  position: relative;
  z-index: 1;
}

/* ── Main Content Area ──
   Extracted from index.html's inline style (B1.3) so the mobile
   breakpoint can actually target it instead of fighting inline-style
   specificity. env(safe-area-inset-top) (B1.2/finding 06) pads the
   sticky header clear of a notch / Dynamic Island; the app opts into
   drawing under the status bar (apple-mobile-web-app-status-bar-style:
   black-translucent) and previously compensated nowhere. */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-4);
  padding: 16px 26px;
  padding-top: calc(16px + env(safe-area-inset-top, 0px));
  border-bottom: 1px solid var(--hair);
  position: sticky;
  top: 0;
  z-index: 5;
  background: rgba(7,7,8,0.72);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  min-height: 70px;
}

.app-header__left {
  flex: 1 1 auto;
  min-width: 0;
}

.app-header__title {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.app-header__right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 0 0 auto;
}

.theme-switch {
  display: flex;
  gap: 5px;
  border: 1px solid var(--hair);
  border-radius: 999px;
  padding: 4px;
  background: rgba(255,255,255,0.026);
}

.theme-switch__button {
  min-width: 82px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid transparent;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-family: var(--f-mono);
  font-size: var(--fs-micro);
  font-weight: 700;
  letter-spacing: 0.12em;
  padding: 6px 10px;
  text-transform: uppercase;
}

.theme-switch__button--active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--bg);
}

.theme-switch__code {
  opacity: 0.84;
}

.theme-switch__name {
  letter-spacing: 0.1em;
}

/* Sidebar-drawer instance of the theme switch (B1.3) — hidden on desktop,
   where the header keeps the original. Shown at <=768px, in the media
   query below, where the header drops it instead to keep the page title
   readable. Full-width buttons: the drawer is 280px, not the ~230px the
   header had to squeeze it into. */
.theme-switch--sidebar {
  display: none;
  margin: 0 20px;
}

/* The drawer (280px) is still narrower than three 82px-min buttons plus
   their gaps and padding — flex evenly instead of overflowing. Padding
   (not size) reaches the 44px touch-target floor: this instance is the
   one B1.3 designates as the reachable control, so it doesn't inherit
   the header instance's sub-44px height. */
.theme-switch--sidebar .theme-switch__button {
  flex: 1;
  min-width: 0;
  padding: 14px 4px;
}

.top-metrics {
  display: flex;
  align-items: center;
  gap: 14px;
  padding-left: 10px;
  border-left: 1px solid var(--hair);
}

.top-metric {
  min-width: 62px;
  text-align: right;
}

.top-metric__value {
  display: block;
  font-family: var(--f-mono);
  font-size: var(--fs-md);
  font-weight: 700;
  color: var(--text);
  line-height: 1;
}

.top-metric__label {
  display: block;
  font-family: var(--f-mono);
  font-size: var(--fs-micro);
  letter-spacing: 0.12em;
  color: var(--muted);
  line-height: 1.2;
  margin-top: 5px;
  text-transform: uppercase;
}

.cycle-widget {
  border: 1px solid var(--hair);
  border-radius: 14px;
  padding: 16px;
  background: var(--panel);
}

.cycle-widget__kicker {
  font-family: var(--f-mono);
  font-size: var(--fs-micro);
  letter-spacing: 0.2em;
  color: var(--muted);
  text-transform: uppercase;
}

.cycle-widget__body {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-top: 13px;
}

.cycle-widget__ring {
  position: relative;
  width: 50px;
  height: 50px;
  flex: 0 0 50px;
}

.cycle-widget__value {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--f-mono);
  font-size: var(--fs-sm);
  font-weight: 700;
  color: var(--text);
}

.cycle-widget__title {
  color: var(--text);
  font-size: var(--fs-base);
  font-weight: 600;
}

.cycle-widget__copy {
  color: var(--muted);
  font-size: var(--fs-xs);
  line-height: 1.45;
  margin-top: 3px;
}

.content-shell {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  margin-left: var(--sidebar-w);
  width: calc(100% - var(--sidebar-w));
}

.main-content {
  flex: 1;
  margin-left: 0;
  width: 100%;
  /* min-height:0, not 100vh (finding 06): .app-shell now gives this branch
     of the flex tree a fixed 100dvh to work with, and this is the one box
     that should actually scroll internally (overflow-y:auto is set inline
     on #app-content in index.html). A min-height of 100vh here fought the
     flex:1 sizing and meant this container's height always grew to fit its
     content instead of clipping to the viewport, so its own overflow-y:auto
     never had anything to do — the document element scrolled instead,
     which is the nested-scroller bug. */
  min-height: 0;
  display: flex;
  flex-direction: column;
  position: relative;
  z-index: var(--z-content);
  transition: margin var(--t-slow) var(--ease-out), width var(--t-slow) var(--ease-out);
}

.view {
  display: none;
  padding: var(--sp-8) var(--sp-8) var(--sp-16);
  width: 100%;
  max-width: 1400px;
  margin: 0 auto;
  animation: fadeSlideIn var(--t-slow) var(--ease-out);
}

.view--active {
  display: block;
}

@keyframes fadeSlideIn {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ── Mobile Bottom Nav ──
   height grows by env(safe-area-inset-bottom) (B1.2/finding 06) so the bar
   still reaches the true bottom edge under the home indicator, while
   padding-bottom of the same amount keeps the tab labels/icons themselves
   above it — .bottom-nav__item's height:100% resolves against the content
   box, i.e. inside that padding. */
.bottom-nav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom, 0px));
  z-index: var(--z-sidebar);
  background: rgba(6, 8, 15, 0.92);
  border-top: 1px solid var(--glass-border);
  backdrop-filter: var(--glass-blur-lg);
  -webkit-backdrop-filter: var(--glass-blur-lg);
  padding: 0 var(--sp-2);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

.bottom-nav__items {
  display: flex;
  align-items: center;
  justify-content: space-around;
  height: 100%;
  list-style: none;
}

.bottom-nav__item {
  display: flex;
  flex: 1 1 0;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: var(--sp-2);
  border-radius: var(--r-md);
  color: var(--c-white-muted);
  cursor: pointer;
  transition: color var(--t-fast) var(--ease-out);
  background: none;
  border: none;
  font-family: var(--f-body);
}

.bottom-nav__item--active {
  color: var(--accent);
}

.bottom-nav__item-icon {
  width: 22px;
  height: 22px;
}

.bottom-nav__item-label {
  font-size: var(--fs-micro);
  font-weight: 500;
  letter-spacing: 0.02em;
}

/* ── Mobile Menu Toggle ── */
.mobile-menu-toggle {
  display: none;
  position: fixed;
  top: var(--sp-4);
  left: var(--sp-4);
  z-index: calc(var(--z-sidebar) + 1);
  width: 40px;
  height: 40px;
  border-radius: var(--r-md);
  background: rgba(6, 8, 15, 0.85);
  border: 1px solid var(--glass-border);
  backdrop-filter: var(--glass-blur);
  color: var(--c-white);
  cursor: pointer;
  align-items: center;
  justify-content: center;
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: calc(var(--z-sidebar) - 1);
}

/* ── Responsive ── */
@media (max-width: 1024px) {
  .view {
    padding: var(--sp-6) var(--sp-6) var(--sp-12);
  }
}

@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
    width: 280px;
  }

  .sidebar--open {
    transform: translateX(0);
  }

  .sidebar-overlay--visible {
    display: block;
  }

  .mobile-menu-toggle {
    display: flex;
  }

  .bottom-nav {
    display: block;
  }

  .app-header {
    padding-left: 68px;
  }

  /* B1.3/finding 05: below 768px the sidebar is hidden, so the breadcrumb
     is the only thing telling you which of nine stations you're in — it
     used to be crushed to 2px by a theme switch (122px) and two top
     metrics that took the row first. The theme switch now lives in the
     sidebar drawer (.theme-switch--sidebar below); only Recall due stays
     in the header. .app-header__left already carries flex:1 1 auto +
     ellipsis at every width, so it just gets the room now. */
  .app-header__theme-switch {
    display: none;
  }

  .theme-switch--sidebar {
    display: flex;
  }

  .top-metric--readiness {
    display: none;
  }

  .top-metrics {
    gap: 8px;
    padding-left: 8px;
  }

  .top-metric {
    min-width: 42px;
  }

  .content-shell {
    margin-left: 0;
    width: 100%;
  }

  .main-content {
    margin-left: 0;
    width: 100%;
    padding-bottom: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom, 0px));
  }

  .view {
    padding: var(--sp-4) var(--sp-4) calc(var(--bottom-nav-h) + env(safe-area-inset-bottom, 0px) + var(--sp-8));
  }
}

@media (max-width: 480px) {
  .view {
    padding: var(--sp-3) var(--sp-3) calc(var(--bottom-nav-h) + env(safe-area-inset-bottom, 0px) + var(--sp-6));
  }
}
