/* ─────────────────────────────────────────────────────────────────────────
   VINAR Life OS — Layout Shell
   Requires: tokens.css
   ───────────────────────────────────────────────────────────────────────── */

/* ── Reset ───────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { height: 100%; }

body {
  min-height: 100%;
  background: var(--bg);
  overscroll-behavior: none;
}

/* ── App shell ───────────────────────────────────────────────────────────── */
.app-shell {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  position: relative;
}

/* ── Page header ─────────────────────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px var(--sp-4) 12px;
  position: sticky;
  top: 0;
  z-index: 30;
  background: var(--bg);
  /* subtle bottom border only when scrolled — toggled via JS */
}

.page-header.scrolled {
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(16px);
  background: rgba(11, 21, 32, 0.85);
}

[data-theme="light"] .page-header.scrolled {
  background: rgba(240, 244, 248, 0.85);
}

.page-header-left  { display: flex; align-items: center; gap: var(--sp-3); }
.page-header-right { display: flex; align-items: center; gap: var(--sp-3); }

/* Back button */
.back-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px 0;
  text-decoration: none;
  transition: color var(--ease);
}

.back-btn:hover { color: var(--text-1); }

.back-btn svg {
  width: 16px;
  height: 16px;
}

/* ── Page content ────────────────────────────────────────────────────────── */
.page-content {
  flex: 1;
  overflow-y: auto;
  padding: 0 var(--sp-4);
  padding-bottom: calc(var(--nav-h) + var(--nav-safe) + var(--sp-4));
  -webkit-overflow-scrolling: touch;
}

/* Full-bleed content (no horizontal padding) */
.page-content-flush {
  flex: 1;
  overflow-y: auto;
  padding-bottom: calc(var(--nav-h) + var(--nav-safe) + var(--sp-4));
  -webkit-overflow-scrolling: touch;
}

/* ── Section spacing ─────────────────────────────────────────────────────── */
.section { margin-bottom: var(--sp-5); }
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--sp-3);
}

/* ── Bottom Navigation ───────────────────────────────────────────────────── */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  background: rgba(11, 21, 32, 0.95);
  border-top: 1px solid var(--border);
  backdrop-filter: blur(24px) saturate(1.6);
  -webkit-backdrop-filter: blur(24px) saturate(1.6);
  z-index: 50;
  display: flex;
  align-items: stretch;
  padding-bottom: var(--nav-safe);
}

[data-theme="light"] .bottom-nav {
  background: rgba(240, 244, 248, 0.95);
}

/* Nav item */
.ni {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 10px 4px 6px;
  text-decoration: none;
  color: var(--text-3);
  position: relative;
  transition: color var(--ease);
  cursor: pointer;
  border: none;
  background: none;
  font-family: inherit;
}

.ni:hover { color: var(--text-2); }

.ni.active { color: var(--teal); }

/* Teal top bar for active item */
.ni.active::before {
  content: '';
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 24px;
  height: 2px;
  background: linear-gradient(90deg, var(--teal), var(--violet));
  border-radius: 0 0 3px 3px;
}

/* Nav icon */
.ni svg {
  width: 22px;
  height: 22px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex-shrink: 0;
}

.ni.active svg { stroke-width: 2.2; }

/* Nav label */
.ni-label {
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.02em;
  line-height: 1;
}

/* Badge on nav item */
.ni-badge {
  position: absolute;
  top: 6px;
  right: calc(50% - 14px);
  min-width: 14px;
  height: 14px;
  background: var(--teal);
  color: #0B1520;
  border-radius: var(--r-full);
  font-size: 9px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 3px;
}

/* ── FAB — Floating Action Button ────────────────────────────────────────── */
.fab {
  position: fixed;
  bottom: calc(var(--nav-h) + var(--nav-safe) + 16px);
  right: max(16px, calc(50vw - 240px + 16px)); /* right edge inside app shell */
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--teal);
  color: #0B1520;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 16px rgba(15, 212, 160, 0.45);
  z-index: 40;
  transition: all var(--ease);
  text-decoration: none;
}

.fab:hover {
  box-shadow: 0 6px 24px rgba(15, 212, 160, 0.6);
  transform: translateY(-2px);
}

.fab svg {
  width: 22px;
  height: 22px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ── Session drawer ──────────────────────────────────────────────────────── */
.drawer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--ease-slow);
}

.drawer-overlay.open { opacity: 1; pointer-events: all; }

.drawer {
  position: fixed;
  top: 0;
  left: 50%;
  transform: translateX(calc(-50% - 100vw));
  width: min(300px, 80vw);
  height: 100dvh;
  background: var(--s1);
  border-right: 1px solid var(--border-md);
  z-index: 101;
  padding: var(--sp-5) var(--sp-4);
  overflow-y: auto;
  transition: transform var(--ease-slow);
}

/* Center within app shell */
@media (min-width: 480px) {
  .drawer {
    left: calc(50% - 240px);
    transform: translateX(-100%);
  }
}

.drawer.open {
  transform: translateX(calc(-50% + 0px));
}

@media (min-width: 480px) {
  .drawer.open { transform: translateX(0); }
}

/* ── No-nav pages (Immersive / Flow) ─────────────────────────────────────── */
/* Add class="no-nav" to <body> on pages that should hide the bottom nav     */
.no-nav .bottom-nav { display: none !important; }

.no-nav .page-content,
.no-nav .page-content-flush {
  padding-bottom: var(--sp-4);
}

/* ── Responsive: 2-pane for tablet+ ─────────────────────────────────────── */
@media (min-width: 768px) {
  .app-shell { max-width: 100%; }

  .two-pane {
    display: grid;
    grid-template-columns: 280px 1fr;
    min-height: 100dvh;
    max-width: 1100px;
    margin: 0 auto;
  }

  .two-pane-left {
    border-right: 1px solid var(--border);
    height: 100dvh;
    overflow-y: auto;
    position: sticky;
    top: 0;
  }

  .two-pane-right {
    height: 100dvh;
    overflow-y: auto;
    padding: var(--sp-6);
  }

  /* Hide bottom nav on 2-pane layout */
  .two-pane ~ .bottom-nav { display: none; }
}

/* ── Shell back header (Discover Chart, Archetype, …) — Sprint 4 UX ─────────
   Shared shell: sticky row, back link touch ≥44px, title centered. */
.back-header.shell-back-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px 10px;
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.shell-back-header a.back-header__link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
  min-height: 44px;
  min-width: 44px;
  padding: 8px 10px 8px 4px;
  box-sizing: border-box;
  font-size: 13px;
  color: var(--teal);
  text-decoration: none;
}

.shell-back-header a.back-header__link span {
  line-height: 1.2;
}

.shell-back-header .bh-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-1);
  flex: 1;
  text-align: center;
  padding-right: 60px; /* visual balance vs back link */
}
