/* ═══════════════════════════════════════════════════════════════════════
   FIRST SALE SOCIETY — 2 · LAYOUT & SHELL
   App frame: left sidebar, course nav, progress, desktop header pills,
   mobile header, #main content column, panel-header, scroll-to-top,
   and the persistent overlay shells (hidden by default).
   ═══════════════════════════════════════════════════════════════════════ */

/* ─────────────────────────────────────────────────────────────
   APP FRAME
   ───────────────────────────────────────────────────────────── */
#sidebar {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--border);
  z-index: 100;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
}

#main {
  margin-left: var(--sidebar-w);
  min-height: 100vh;
  background: var(--bg);
}

/* Sidebar logo plate (component sets bg via inline style) */
#sidebar > div:first-of-type { position: sticky; top: 0; z-index: 2; }
#sidebar > div:first-of-type img {
  border-radius: 14px !important;
  box-shadow: var(--shadow-sm);
}

/* ─────────────────────────────────────────────────────────────
   SIDEBAR PROGRESS (thin bar pinned at very top of the sidebar)
   ───────────────────────────────────────────────────────────── */
.sidebar-progress-bar {
  position: sticky;
  top: 0;
  height: 3px;
  width: 100%;
  background: var(--border);
  z-index: 5;
  flex: none;
}
.sidebar-progress-fill {
  height: 100%;
  width: 0;
  background: var(--grad);
  transition: width 0.4s ease;
}

/* ─────────────────────────────────────────────────────────────
   NAV
   ───────────────────────────────────────────────────────────── */
.sidebar-nav {
  flex: 1 1 auto;
  padding: 8px 0 16px;
}

.nav-phase-group { margin: 0 0 14px; }

.nav-section-label {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 18px 6px;
  font-family: var(--font-body);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text3);
}
.nav-section-icon { flex: none; color: var(--text3); opacity: 0.9; }

/* Operator Resources — a visually distinct card, set apart from course phases */
.nav-resources-group {
  margin: 8px 10px 20px;
  padding: 4px 0 10px;
  background: linear-gradient(180deg, var(--accent-glow2), transparent), var(--surface2);
  border: 1px solid var(--border);
  border-radius: 14px;
}
.nav-resources-group .nav-section-label.sr { color: var(--accent); padding-left: 14px; }
.nav-resources-group .nav-section-icon { color: var(--accent); opacity: 1; }
.nav-resources-group .nav-item { margin-inline: 8px; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 11px;
  margin: 1px 10px;
  padding: 8px 12px;
  border-radius: 9px;
  color: var(--text2);
  font-family: var(--font-body);
  font-size: 13.5px;
  font-weight: 450;
  line-height: 1.3;
  text-decoration: none;
  position: relative;
  transition: background 0.16s ease, color 0.16s ease;
}
.nav-item:hover { background: var(--glass-d); color: var(--heading); }

.nav-item .num {
  flex: none;
  min-width: 22px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text3);
  font-variant-numeric: tabular-nums;
  text-align: center;
}
/* emoji icons in the resources group render a touch larger */
.nav-resources-group .nav-item .num { font-size: 15px; }
/* per-module line icon sits centered in the number slot */
.nav-item .num svg.nav-mod-icon { display: block; margin: 0 auto; }

.nav-check {
  margin-left: auto;
  width: 15px; height: 15px;
  border-radius: 50%;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Completed module — filled green dot with checkmark, independent of active state */
.nav-item.completed .nav-check {
  background: var(--green, #1d8a4e);
}
.nav-item.completed .num { color: var(--green, #1d8a4e); }

/* ─────────────────────────────────────────────────────────────
   SIDEBAR PROGRESS BAR — sits above the module search box
   ───────────────────────────────────────────────────────────── */
.sidebar-progress {
  padding: 10px 16px 14px;
}
.sidebar-progress-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 6px;
}
.sidebar-progress-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text3);
}
.sidebar-progress-count {
  font-size: 11.5px;
  font-weight: 700;
  color: var(--heading);
  font-variant-numeric: tabular-nums;
}
.sidebar-progress-track {
  width: 100%;
  height: 6px;
  border-radius: 4px;
  background: var(--surface3, var(--border));
  overflow: hidden;
}
.sidebar-progress-fill {
  height: 100%;
  border-radius: 4px;
  background: var(--grad);
  transition: width 0.3s ease;
}

/* Active item — gradient rail + accent text */
.nav-item.active {
  background: var(--accent-glow);
  color: var(--accent);
  font-weight: 600;
}
.nav-item.active .num { color: var(--accent); }
.nav-item.active::before {
  content: '';
  position: absolute;
  left: -10px; top: 7px; bottom: 7px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--grad);
}
.nav-item.active .nav-check {
  background: var(--grad);
  box-shadow: inset 0 0 0 2px var(--surface);
}

/* ─────────────────────────────────────────────────────────────
   DESKTOP HEADER CONTROLS — glass pills, fixed top-right
   ───────────────────────────────────────────────────────────── */
#desktop-header-controls {
  position: fixed;
  top: 16px; right: 20px;
  z-index: 90;
  display: flex;
  align-items: center;
  gap: 10px;
}
.dhc-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 36px;
  padding: 0 15px;
  border-radius: var(--r-pill);
  border: 1px solid var(--border2);
  background: var(--glass);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 500;
  letter-spacing: -0.01em;
  text-decoration: none;
  cursor: pointer;
  transition: border-color 0.18s ease, background 0.18s ease, color 0.18s ease;
}
.dhc-btn:hover {
  border-color: var(--border3);
  background: var(--surface);
  color: var(--heading);
}
.dhc-icon { font-size: 15px; line-height: 1; }

/* ─────────────────────────────────────────────────────────────
   MOBILE HEADER — hidden on desktop
   ───────────────────────────────────────────────────────────── */
#mobile-header { display: none; }
.mh-center { display: flex; flex-direction: column; align-items: center; line-height: 1.15; min-width: 0; }
.mh-logo { font-family: var(--font-display); font-size: 15px; font-weight: 600; color: var(--heading); letter-spacing: -0.01em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mh-phase-tag { font-size: 11px; color: var(--text2); margin-top: 1px; }
.mh-phase-tag:empty { display: none; }

.hdr-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px; height: 40px;
  border-radius: var(--r-pill);
  border: 1px solid var(--border2);
  background: var(--glass);
  color: var(--text);
  cursor: pointer;
  flex: none;
  transition: border-color 0.18s ease, background 0.18s ease, color 0.18s ease;
}
.hdr-btn:hover, .hdr-btn:active { border-color: var(--accent); color: var(--accent); background: var(--accent-glow2); }
.hdr-btn svg { width: 20px; height: 20px; stroke: currentColor; stroke-width: 2; stroke-linecap: round; fill: none; }
.hdr-btn svg[fill] path { fill: currentColor; }

/* Sidebar slide-in backdrop (mobile) */
#sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  backdrop-filter: blur(2px);
  z-index: 95;
}

/* ─────────────────────────────────────────────────────────────
   PANEL HEADER — slim brand bar at top of some modules
   ───────────────────────────────────────────────────────────── */
/* ─────────────────────────────────────────────────────────────
   PANEL HEADER — slim document subtitle line
   ───────────────────────────────────────────────────────────── */
.panel-header {
  max-width: var(--content-max);
  margin: 0 auto;
  padding: 6px var(--content-pad) 0;
  display: flex;
  align-items: center;
}
/* "First Sale Society" — already in sidebar, redundant here */
.panel-header-logo { display: none; }
/* "Product Testing Playbook · 2026" — keep as a tiny muted document label */
.panel-header-brand { display: flex; align-items: center; }
.panel-header-sub {
  font-size: 11px;
  font-weight: 500;
  color: var(--text3);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}


/* ─────────────────────────────────────────────────────────────
   SCROLL-TO-TOP
   ───────────────────────────────────────────────────────────── */
#scroll-top-btn {
  position: fixed;
  bottom: 24px; right: 24px;
  width: 44px; height: 44px;
  border-radius: 50%;
  border: 1px solid var(--border2);
  background: var(--glass);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  color: var(--text);
  font-size: 18px;
  cursor: pointer;
  z-index: 80;
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity 0.2s ease, transform 0.2s ease, background 0.2s ease, border-color 0.2s ease;
}
#scroll-top-btn.visible { opacity: 1; pointer-events: auto; transform: translateY(0); }
#scroll-top-btn:hover { background: var(--accent); border-color: var(--accent); color: #fff; box-shadow: var(--shadow-md); }
/* On mobile, lift it above the sticky bottom action bar + clear the home bar */
@media (max-width: 768px) {
  #scroll-top-btn {
    bottom: calc(76px + env(safe-area-inset-bottom, 0px));
    right: 16px;
    width: 42px; height: 42px;
  }
}

/* ─────────────────────────────────────────────────────────────
   PERSISTENT OVERLAY SHELLS — hidden by default (JS toggles open)
   (full styling lives in file 4; here we just keep them out of the way)
   ───────────────────────────────────────────────────────────── */
#glossary-modal,
#stage-complete-overlay { display: none; }

/* ─────────────────────────────────────────────────────────────
   RESPONSIVE — collapse sidebar into a drawer ≤ 980px
   ───────────────────────────────────────────────────────────── */
@media (max-width: 980px) {
  #desktop-header-controls { display: none; }
  #mobile-header {
    display: flex;
    align-items: center;
    gap: 10px;
    position: sticky;
    top: 0;
    z-index: 90;
    height: 56px;
    padding: 0 14px;
    padding-top: env(safe-area-inset-top, 0px);
    height: calc(56px + env(safe-area-inset-top, 0px));
    background: var(--glass);
    backdrop-filter: saturate(180%) blur(20px);
    -webkit-backdrop-filter: saturate(180%) blur(20px);
    border-bottom: 1px solid var(--border);
  }
  .mh-center { flex: 1 1 auto; }
  /* 44px Apple-HIG tap targets in the header */
  .hdr-btn { width: 44px; height: 44px; }

  #sidebar {
    transform: translateX(-100%);
    transition: transform 0.28s cubic-bezier(0.4,0,0.2,1);
    box-shadow: var(--shadow-lg);
    width: min(86vw, 320px);
    padding-top: env(safe-area-inset-top, 0px);
  }
  /* MobileSidebarController toggles .open on #sidebar and #sidebar-backdrop */
  #sidebar.open { transform: translateX(0); }
  #sidebar-backdrop.open { display: block; }

  #main { margin-left: 0; }

  /* ── Drawer search ── */
  .nav-search-wrap {
    position: sticky;
    top: 0;
    z-index: 2;
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 8px 10px 10px;
    padding: 0 12px;
    height: 40px;
    background: var(--surface2);
    border: 1px solid var(--border2);
    border-radius: var(--r-pill);
  }
  .nav-search-icon { flex: none; color: var(--text3); }
  .nav-search {
    flex: 1 1 auto;
    min-width: 0;
    height: 100%;
    border: none;
    background: none;
    color: var(--text);
    font-family: var(--font-body);
    font-size: 15px; /* ≥16px-ish avoids iOS zoom; 15 acceptable with viewport lock */
    outline: none;
  }
  .nav-search::placeholder { color: var(--text3); }
  .nav-search::-webkit-search-cancel-button { -webkit-appearance: none; }

  /* ── 44px nav rows in the drawer ── */
  .nav-item {
    min-height: 44px;
    padding-top: 9px;
    padding-bottom: 9px;
    font-size: 14.5px;
  }
  .nav-section-label { padding-top: 14px; }
}

/* The search input only belongs in the mobile drawer */
@media (min-width: 981px) {
  .nav-search-wrap { display: none; }
}
