/*
 * site/chapter-map.css — the in-lesson Chapter Map rail.
 *
 * PHASE 1: read-only rendering. PHASE 2: desktop expand/collapse chrome —
 * a real toggle button, a minimal collapsed-state indicator (current
 * section number), and the width transition between the two. PHASE 3:
 * desktop navigation — implemented rows (`navigation:'direct'|'parent'` in
 * the frozen map) render as real `<a href>`s and get a clickable
 * affordance (cursor, hover, focus-visible); `navigation:'none'` rows
 * (always the planned ones) stay visually and functionally inert. PHASE 4
 * (this pass): the mobile overlay drawer — the SAME `.cmap-rail` element
 * used for the desktop rail becomes a slide-in drawer below 900px (see the
 * final media query), plus the mobile top bar that fixes the pre-existing
 * NCERT-activity-tag / teleprompter collision by reserving real layout
 * height instead of floating the tag over the stage. Still no completion
 * state, no progress tracking, no persistence. See
 * content/light-chapter-map.js (frozen) and the approved Chapter Map
 * architecture proposal for what's deferred (lessonAnchor, progress).
 *
 * Lives INSIDE the immersive lesson overlay (site.css `.lesson-overlay`),
 * not the public website shell — so it speaks the immersive lesson's own
 * design language (design/tokens.css: --stage-2, --ink, --ink-soft,
 * --ink-faint, --ray-out), with literal fallbacks so it renders correctly
 * even if that stylesheet hasn't been injected yet — the same defensive
 * pattern site.css's own `.lesson-overlay` rules already use.
 *
 * TYPOGRAPHY/STYLE PASS (screen-by-screen redesign, reflection-of-light):
 * font-family now leads with Manrope (already loaded by topic-page.mjs's
 * <head> — this file lives in the PARENT document, not the frozen iframe,
 * so it can use it) and the current-state/accent colour now uses the
 * canonical TextbookLive product palette (--mint #A9E8CF, --text #F7FAF8,
 * --text-secondary #C5D8D1, --text-muted #91AFA4) instead of the lesson
 * stage's own aqua accent (--ray-out) — this rail is navigation chrome,
 * not part of the physics stage, so it speaks the product's own voice.
 * Layout, breakpoints, toggle/drawer mechanics and navigation are
 * unchanged — every edit below is color/weight/spacing only.
 *
 * This file OVERRIDES site.css's `.lesson-overlay` layout (column ->
 * row-with-rail) rather than editing site.css directly — site.css itself
 * stays untouched, and only topic pages that load this stylesheet get the
 * rail; nothing else changes.
 *
 * V1 state language (approved): ● current, ○ available, ◇ NCERT activity
 * number, muted "Coming soon" for planned. No ✓/completed anywhere yet —
 * the frozen iframe lessons can't reliably report completion, so no state
 * pretends otherwise.
 *
 * Expanding/collapsing is a pure CSS width change on .cmap-rail (see
 * site/lesson-mount.js for the ~10-line toggle handler) — it never touches
 * bodyEl or the mounted lesson, so the lesson is never reloaded, restarted,
 * or reset by this control.
 */

.lesson-overlay { flex-direction: row; }

.cmap-rail {
  flex: 0 0 300px;
  height: 100%;
  overflow: hidden; /* clips the section list while collapsing — the list itself scrolls via its own inner element */
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  background: rgba(0, 0, 0, 0.14);
  border-right: 1px solid rgba(191, 224, 207, 0.16);
  font-family: 'Manrope', var(--font-family, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif);
  transition: flex-basis 0.2s ease;
}
.cmap-rail.is-collapsed { flex-basis: 60px; }

@media (prefers-reduced-motion: reduce) {
  .cmap-rail { transition: none; }
}

/* ---- top bar: toggle + collapsed-state indicator ---- */
.cmap-rail-top {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 10px;
  min-height: 60px; /* matches the collapsed rail width — a comfortable, non-precision touch target either way */
  box-sizing: border-box;
}
.cmap-rail.is-collapsed .cmap-rail-top { flex-direction: column; padding: 12px 6px; }

.cmap-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  min-width: 40px;
  min-height: 40px;
  padding: 8px 10px;
  border: 1px solid rgba(191, 224, 207, 0.22);
  border-radius: var(--radius-button, 10px);
  background: rgba(9, 32, 24, 0.4);
  color: var(--ink-soft, #bfe0cf);
  font: inherit;
  font-weight: 700;
  font-size: 0.78rem;
  cursor: pointer;
}
.cmap-rail.is-collapsed .cmap-toggle { padding: 8px; justify-content: center; }
.cmap-toggle:hover { background: rgba(9, 32, 24, 0.7); color: var(--ink, #f2fbf4); }
.cmap-toggle:focus-visible {
  outline: 2px solid #A9E8CF;
  outline-offset: 2px;
}
.cmap-toggle-chevron {
  display: inline-block;
  font-size: 1rem;
  line-height: 1;
  transition: transform 0.2s ease;
}
.cmap-rail.is-collapsed .cmap-toggle-chevron { transform: rotate(180deg); }
@media (prefers-reduced-motion: reduce) {
  .cmap-toggle-chevron { transition: none; }
}
.cmap-toggle-label { white-space: nowrap; }
.cmap-rail.is-collapsed .cmap-toggle-label { display: none; }

/* Collapsed-state mini indicator: current section number + a quiet dot.
   Nothing else — no titles, no per-item dots, no percentage. */
.cmap-collapsed-info {
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}
.cmap-rail.is-collapsed .cmap-collapsed-info { display: flex; }
.cmap-collapsed-section {
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--text-secondary, #C5D8D1);
}
.cmap-collapsed-dot {
  font-size: 0.7rem;
  color: #A9E8CF;
}

/* ---- mobile-only chrome (Phase 4) — all hidden by default; the final
   media query below is the ONLY place any of it becomes visible, so none
   of it can affect desktop. ---- */
.cmap-drawer-header,
.lesson-overlay-topbar,
.cmap-backdrop {
  display: none;
}
/* The drawer's own "Chapter Map ✕" header (mobile equivalent of the
   desktop expand/collapse toggle above). */
.cmap-drawer-title {
  margin: 0;
  font-size: 0.86rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--text, #F7FAF8);
}
.cmap-drawer-close {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  min-width: 40px;
  min-height: 40px;
  border: 1px solid rgba(191, 224, 207, 0.22);
  border-radius: var(--radius-button, 10px);
  background: rgba(9, 32, 24, 0.4);
  color: var(--ink-soft, #bfe0cf);
  font-size: 1rem;
  cursor: pointer;
}
.cmap-drawer-close:hover { background: rgba(9, 32, 24, 0.7); color: var(--ink, #f2fbf4); }
.cmap-drawer-close:focus-visible {
  outline: 2px solid #A9E8CF;
  outline-offset: 2px;
}

/* ---- scrollable section list (hidden, not removed, while collapsed —
   the rail's own overflow:hidden clips it; width stays fixed so nothing
   reflows/wraps mid-transition) ---- */
.cmap-rail-scroll {
  flex: 1 1 auto;
  overflow-y: auto;
  min-width: 284px; /* == expanded content width; prevents reflow while the rail's outer width animates */
  padding: 4px 16px 16px;
  box-sizing: border-box;
}
.cmap-rail.is-collapsed .cmap-rail-scroll { visibility: hidden; }

.cmap-rail-heading {
  margin: 0 0 20px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: rgba(169, 232, 207, 0.6); /* muted mint */
}

.cmap-section { margin-bottom: 20px; }
.cmap-section-title {
  margin: 0 0 8px;
  font-size: 0.66rem;
  font-weight: 600;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: rgba(169, 232, 207, 0.6); /* muted mint — small labels/metadata */
}
/* Fully-planned sections (today: 03-06) collapse to a single quiet line —
   no per-item lock icons, no visual noise, just "this exists, not yet". */
.cmap-section.is-planned { margin-bottom: 14px; }
.cmap-section.is-planned .cmap-section-title { opacity: 0.65; }
.cmap-section-status {
  margin: 0;
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--text-muted, #91AFA4);
}

.cmap-section-items { display: flex; flex-direction: column; gap: 1px; }

.cmap-item {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 7px 8px 7px 10px;
  border-left: 2px solid transparent; /* reserves the current-item indicator's width so text never shifts */
  border-radius: 8px;
  min-width: 0;
  /* rows are now sometimes a real <a> (navigable) and sometimes a <div>
     (disabled) — reset link defaults so both read identically at rest */
  text-decoration: none;
  color: inherit;
}
.cmap-item--activity { padding-left: 26px; }

/* navigable (navigation:'direct'|'parent') — a real destination, not a
   card/button: quiet hover/focus affordance only. Excludes the current
   item so its own highlight isn't fought by a hover tint. */
.cmap-item.is-navigable { cursor: pointer; }
.cmap-item.is-navigable:not(.is-current):hover,
.cmap-item.is-navigable:not(.is-current):focus-visible {
  background: rgba(169, 232, 207, 0.07);
}
.cmap-item.is-navigable:focus-visible {
  outline: 2px solid #A9E8CF;
  outline-offset: 2px;
}
/* navigation:'none' — always the planned items; no misleading hover, and
   never focusable (a non-link <div> is already skipped in tab order). */
.cmap-item.is-disabled { cursor: default; }

.cmap-marker {
  flex-shrink: 0;
  width: 1em;
  text-align: center;
  color: var(--text-muted, #91AFA4);
  font-size: 0.75rem;
  line-height: 1.4;
}
/* Activities already carry the ◇ activity-number marker below — the ○
   bullet on top of it is redundant noise (an activity is never itself
   "current", per the Chapter Map's navigation model), so hierarchy here
   comes from indentation + size + weight rather than a second symbol. */
.cmap-item--activity .cmap-marker { display: none; }

.cmap-item-title {
  min-width: 0;
  font-size: 0.86rem;
  font-weight: 500;
  line-height: 1.35;
  color: var(--text-secondary, #C5D8D1);
}
.cmap-item--primary .cmap-item-title { font-size: 0.9rem; }
/* activity children — smaller and lighter, reading as subordinate to
   their parent concept rather than an equally strong destination */
.cmap-item--activity .cmap-item-title { font-size: 0.78rem; font-weight: 400; color: var(--text-muted, #91AFA4); }

.cmap-activity-marker {
  flex-shrink: 0;
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-muted, #91AFA4);
}

/* current — restrained: a slim mint indicator (never a bright capsule),
   a quiet surface tint, and slightly brighter/heavier text. Never
   colour-only: the marker glyph itself also changes (●). Mint, not the
   lesson stage's aqua accent — this is product navigation chrome. */
.cmap-item.is-current {
  background: rgba(169, 232, 207, 0.10);
  border-left-color: #A9E8CF;
}
.cmap-item.is-current .cmap-marker,
.cmap-item.is-current .cmap-activity-marker { color: #A9E8CF; }
.cmap-item.is-current .cmap-item-title { color: var(--text, #F7FAF8); font-weight: 600; }

/* planned (individual item within an otherwise-active section, e.g.
   Activity 9.4) — mute the label only, never dim the whole row; a lesson
   learned earlier in this project when a blanket opacity made a "coming
   soon" panel read as broken rather than "not yet". */
.cmap-item-title { transition: none; }
.cmap-item.is-planned .cmap-item-title { color: var(--text-muted, #91AFA4); font-weight: 500; }
.cmap-planned-tag {
  margin-left: auto;
  flex-shrink: 0;
  font-size: 0.66rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--text-muted, #91AFA4);
  white-space: nowrap;
  align-self: center;
}

/* ============================================================
   MOBILE (Phase 4): the desktop permanent rail becomes a slide-in
   overlay drawer below 900px — same breakpoint the rest of the site
   treats as "mobile". The stage keeps essentially the full viewport
   width; the Chapter Map is reached through a compact trigger instead.
   ============================================================ */
@media (max-width: 900px) {
  .lesson-overlay { flex-direction: column; }

  /* ---- the trigger + mobile top bar (reserves real height above the
     stage, so nothing here ever floats over the lesson's own content —
     this is also what fixes the pre-existing Activity 9.3 / teleprompter
     collision: the tag now lives in this reserved band, not on top of
     the iframe). Hidden on desktop (default rule above). ---- */
  .lesson-overlay-topbar {
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    z-index: 10;
    background: var(--stage-2, #0d3226);
    border-bottom: 1px solid rgba(191, 224, 207, 0.16);
    padding-top: env(safe-area-inset-top);
  }
  .lesson-overlay-topbar-row {
    display: flex;
    align-items: center;
    min-height: 52px;
    padding: 6px 12px;
    box-sizing: border-box;
  }
  .cmap-mobile-trigger {
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 44px;
    padding: 8px 14px;
    border: 1px solid rgba(191, 224, 207, 0.22);
    border-radius: var(--radius-button, 10px);
    background: rgba(9, 32, 24, 0.4);
    color: var(--ink-soft, #bfe0cf);
    font: inherit;
    font-weight: 700;
    font-size: 0.85rem;
    cursor: pointer;
  }
  .cmap-mobile-trigger:hover,
  .cmap-mobile-trigger:focus-visible { background: rgba(9, 32, 24, 0.7); color: var(--ink, #f2fbf4); }
  .cmap-mobile-trigger:focus-visible {
    outline: 2px solid #A9E8CF;
    outline-offset: 2px;
  }
  /* the lesson's own floating "✕ Close" chip (site.css, top:10px) lands
     inside this same 52px row by simple arithmetic, not DOM placement —
     it keeps its existing absolute position/behaviour untouched. */

  /* the mobile-only activity tag: a second row inside the reserved top
     bar, in normal flow (not position:absolute like its desktop sibling
     in .lesson-overlay-body) — so it can never sit on top of the stage. */
  .lesson-overlay-topbar .ds-activity-tag--mobile {
    position: static;
    max-width: none;
    opacity: 1;
    pointer-events: auto;
    padding: 0 12px 10px;
  }
  /* the desktop copy (absolute, inside .lesson-overlay-body) would now
     collide with the reserved top bar's own space — hide it on mobile;
     the topbar copy above is the only one visible here. */
  .lesson-overlay-body > .ds-activity-tag:not(.ds-activity-tag--mobile) { display: none; }

  /* ---- the drawer itself: same .cmap-rail element as desktop, now an
     overlay panel instead of a permanent sidebar. Off-screen by default;
     .is-drawer-open slides it in (see site/lesson-mount.js). ---- */
  .cmap-rail {
    display: flex;
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 60;
    width: 90vw;
    max-width: 400px;
    flex-basis: auto;
    /* the desktop rail's translucent 14% black tint (base rule above)
       relies on sitting beside the stage, not over it — as a drawer it
       must fully occlude the lesson content behind it, so it needs a
       solid ground of its own instead. */
    background: var(--stage-2, #0d3226);
    box-shadow: 8px 0 24px rgba(3, 20, 14, 0.35);
    transform: translateX(-100%);
    transition: transform 0.25s ease;
  }
  .cmap-rail.is-drawer-open { transform: translateX(0); }
  /* Phase 2's collapse mechanics don't apply to a drawer — the drawer is
     either fully open or fully closed, never a narrow collapsed sliver.
     (JS never adds .is-collapsed on mobile since its only trigger, the
     desktop toggle button, is hidden here — these two rules are just
     defensive, e.g. against a collapse-then-shrink-viewport edge case.) */
  .cmap-rail.is-collapsed { flex-basis: auto; }
  .cmap-rail.is-collapsed .cmap-rail-scroll { visibility: visible; }
  .cmap-rail-scroll { min-width: 0; }

  /* desktop's toggle/collapsed-info chrome swaps for the drawer's own
     "Chapter Map ✕" header. */
  .cmap-toggle, .cmap-collapsed-info { display: none; }
  .cmap-drawer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
  }

  @media (prefers-reduced-motion: reduce) {
    .cmap-rail { transition: none; }
  }

  /* backdrop dims the sliver of lesson still visible beside the open
     drawer; tapping it closes the drawer (site/lesson-mount.js). */
  .cmap-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 50;
    background: rgba(3, 20, 14, 0.55);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
  }
  .cmap-backdrop.is-visible { opacity: 1; pointer-events: auto; }
  @media (prefers-reduced-motion: reduce) {
    .cmap-backdrop { transition: none; }
  }

  /* generous touch targets throughout the drawer's own item list */
  .cmap-item { min-height: 44px; box-sizing: border-box; }
}
