/* ── Section Navigator — Phase 2 inline editor ───────────────────────────
   Collapsible left-side drawer showing page structure.
   Only visible in inline-edit-active mode.
   ─────────────────────────────────────────────────────────────────────── */

.section-nav {
  position: fixed;
  top: 50%;
  left: 0;
  transform: translateY(-50%);
  z-index: 9500;
  display: none;        /* shown only in edit mode via JS */
  align-items: flex-start;
  pointer-events: none;
}
.inline-edit-active .section-nav {
  display: flex;
  pointer-events: none; /* container is pass-through; children set their own */
}
/* Tab handle is always tappable in edit mode */
.inline-edit-active .section-nav .section-nav-tab {
  pointer-events: auto;
}

/* ── Tab handle (always visible in edit mode) ────────────────────────── */
.section-nav-tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  width: 2.5rem;
  padding: 0.75rem 0;
  border-radius: 0 0.6rem 0.6rem 0;
  background: #ffffff;
  border: 1px solid rgba(148, 163, 184, 0.3);
  border-left: none;
  box-shadow: 3px 0 12px rgba(15, 23, 42, 0.1);
  cursor: pointer;
  transition: background 150ms ease, box-shadow 150ms ease;
  color: #64748b;
  flex-shrink: 0;
}
.section-nav-tab:hover {
  background: #f8fafc;
  color: var(--theme-primary, #6366f1);
  box-shadow: 4px 0 16px rgba(var(--theme-primary-rgb, 99,102,241), 0.15);
}
.section-nav-tab-icon {
  font-size: 0.9rem;
}
.section-nav-tab-label {
  font-size: 0.52rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  line-height: 1;
}

/* ── Drawer body ─────────────────────────────────────────────────────── */
.section-nav-body {
  width: 220px;
  max-height: min(80vh, 600px);
  display: flex;
  flex-direction: column;
  background: #ffffff;
  border-radius: 0 0.85rem 0.85rem 0;
  border: 1px solid rgba(148, 163, 184, 0.25);
  border-left: none;
  box-shadow: 6px 0 28px rgba(15, 23, 42, 0.12);
  overflow: hidden;
  /* Hidden state */
  transform: translateX(-100%);
  opacity: 0;
  pointer-events: none;
  transition: transform 280ms cubic-bezier(0.22, 1, 0.36, 1),
              opacity 240ms ease;
}
.section-nav.is-open .section-nav-body {
  transform: translateX(0);
  opacity: 1;
  pointer-events: auto;
}

/* ── Header ──────────────────────────────────────────────────────────── */
.section-nav-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.65rem 0.75rem;
  border-bottom: 1px solid rgba(148, 163, 184, 0.18);
  flex-shrink: 0;
  background: #f8fafc;
}
.section-nav-title {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #475569;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.section-nav-title i { color: var(--theme-primary, #6366f1); }
.section-nav-close {
  width: 1.5rem;
  height: 1.5rem;
  border-radius: 0.3rem;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  color: #94a3b8;
  background: none;
  border: none;
  cursor: pointer;
  transition: color 130ms ease, background 130ms ease;
}
.section-nav-close:hover { color: #1e293b; background: #e2e8f0; }

/* ── Section list ────────────────────────────────────────────────────── */
.section-nav-list {
  list-style: none;
  margin: 0;
  padding: 0.3rem;
  overflow-y: auto;
  flex: 1;
}

.section-nav-row {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.35rem 0.4rem;
  border-radius: 0.45rem;
  border: 1px solid transparent;
  cursor: default;
  transition: background 120ms ease, border-color 120ms ease;
  user-select: none;
}
.section-nav-row:hover {
  background: #f1f5f9;
  border-color: rgba(148, 163, 184, 0.25);
}
.section-nav-row.section-nav-row--dragging {
  opacity: 0.4;
}
.section-nav-row.section-nav-row--hidden .section-nav-name {
  opacity: 0.38;
  text-decoration: line-through;
}
.section-nav-row.section-nav-row--drop-above {
  border-top: 2px solid var(--theme-primary, #6366f1);
}
.section-nav-row.section-nav-row--drop-below {
  border-bottom: 2px solid var(--theme-primary, #6366f1);
}
.section-nav-row.section-nav-highlighted {
  background: rgba(var(--theme-primary-rgb, 99,102,241), 0.08);
  border-color: rgba(var(--theme-primary-rgb, 99,102,241), 0.3);
}

/* Grip handle */
.section-nav-grip {
  color: #cbd5e1;
  font-size: 0.65rem;
  cursor: grab;
  flex-shrink: 0;
  width: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.1rem 0;
}
.section-nav-grip:active { cursor: grabbing; }
.section-nav-grip:hover { color: #94a3b8; }

/* Section name button */
.section-nav-name {
  flex: 1;
  min-width: 0;
  background: none;
  border: none;
  padding: 0;
  font-size: 0.78rem;
  font-weight: 500;
  color: #334155;
  text-align: left;
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: color 120ms ease;
}
.section-nav-name:hover { color: var(--theme-primary, #6366f1); }

/* Action buttons */
.section-nav-actions {
  display: flex;
  align-items: center;
  gap: 0.15rem;
  flex-shrink: 0;
  opacity: 0;
  transition: opacity 150ms ease;
}
.section-nav-row:hover .section-nav-actions { opacity: 1; }
.section-nav-btn {
  width: 1.5rem;
  height: 1.5rem;
  border-radius: 0.3rem;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.65rem;
  color: #94a3b8;
  background: none;
  border: none;
  cursor: pointer;
  transition: color 130ms ease, background 130ms ease;
}
.section-nav-btn:hover { background: #e2e8f0; color: #334155; }
.section-nav-btn.section-nav-layout:hover { color: var(--theme-primary, #6366f1); }
.section-nav-btn.section-nav-vis:hover { color: #f59e0b; }
.section-nav-btn.section-nav-settings:hover { color: var(--theme-primary, #6366f1); }
.section-nav-btn.section-nav-delete:hover { color: #ef4444; background: #fef2f2; }
.section-nav-row--hidden .section-nav-vis { color: #cbd5e1; }

/* ── Add Section ─────────────────────────────────────────────────────── */
.section-nav-add {
  padding: 0.4rem 0.5rem 0.3rem;
  border-top: 1px solid rgba(148, 163, 184, 0.15);
  flex-shrink: 0;
  position: relative;
}
.section-nav-add-btn {
  width: 100%;
  display: flex; align-items: center; gap: 0.4rem;
  padding: 0.38rem 0.5rem;
  border: 1px dashed rgba(148, 163, 184, 0.35);
  border-radius: 0.4rem;
  background: none; color: #94a3b8;
  font-size: 0.74rem; font-weight: 600; cursor: pointer;
  transition: color 120ms ease, border-color 120ms ease, background 120ms ease;
}
.section-nav-add-btn:hover { color: var(--theme-primary, #6366f1); border-color: rgba(var(--theme-primary-rgb, 99,102,241), 0.4); background: rgba(var(--theme-primary-rgb, 99,102,241), 0.04); }
.section-nav-add-btn:disabled { opacity: 0.4; cursor: default; }
.section-nav-add-picker {
  position: absolute;
  bottom: calc(100% + 4px);
  left: 0.5rem; right: 0.5rem;
  background: #ffffff;
  border: 1px solid rgba(148, 163, 184, 0.25);
  border-radius: 0.55rem;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.14);
  overflow: hidden;
  z-index: 10;
  display: none;
}
.section-nav-add-picker.is-open { display: block; }
.section-nav-add-picker-title {
  padding: 0.45rem 0.65rem;
  font-size: 0.62rem; font-weight: 700; letter-spacing: 0.08em;
  text-transform: uppercase; color: #94a3b8;
  border-bottom: 1px solid rgba(148, 163, 184, 0.15);
  background: #f8fafc;
}
.section-nav-add-picker-list {
  max-height: 200px;
  overflow-y: auto;
  padding: 0.25rem;
}
.section-nav-add-option {
  display: block; width: 100%;
  padding: 0.35rem 0.5rem;
  border: none; background: none;
  font-size: 0.77rem; font-weight: 500; color: #334155;
  text-align: left; cursor: pointer; border-radius: 0.35rem;
  transition: background 100ms ease, color 100ms ease;
}
.section-nav-add-option:hover { background: rgba(var(--theme-primary-rgb, 99,102,241), 0.08); color: var(--theme-primary, #6366f1); }
.section-nav-add-option:disabled { opacity: 0.4; cursor: default; }
.section-nav-add-picker-empty {
  padding: 0.5rem 0.65rem;
  font-size: 0.72rem; color: #94a3b8; text-align: center;
}

/* dark mode for add section */
:is(body.theme-dark, body.ui-mode-dark, body.public-site-body.preset-mode-dark) .section-nav-add-picker {
  background: rgba(18, 24, 38, 0.99);
  border-color: rgba(148, 163, 184, 0.16);
}
:is(body.theme-dark, body.ui-mode-dark, body.public-site-body.preset-mode-dark) .section-nav-add-picker-title {
  background: rgba(22, 30, 46, 0.95); color: rgba(148, 163, 184, 0.7);
  border-bottom-color: rgba(148, 163, 184, 0.12);
}
:is(body.theme-dark, body.ui-mode-dark, body.public-site-body.preset-mode-dark) .section-nav-add-option {
  color: rgba(226, 232, 240, 0.8);
}

/* ── Hint + footer ───────────────────────────────────────────────────── */
.section-nav-hint {
  font-size: 0.62rem;
  color: #94a3b8;
  padding: 0.3rem 0.75rem;
  letter-spacing: 0.02em;
  flex-shrink: 0;
}
.section-nav-footer {
  border-top: 1px solid rgba(148, 163, 184, 0.18);
  padding: 0.4rem 0.75rem;
  background: #f8fafc;
  flex-shrink: 0;
}

/* ── Section selection ring on the page ──────────────────────────────── */
.section-nav-ring {
  outline: 2px solid rgba(var(--theme-primary-rgb, 99,102,241), 0.6) !important;
  outline-offset: 2px;
  transition: outline-color 150ms ease !important;
}

/* ── Responsive ──────────────────────────────────────────────────────── */
@media (max-width: 767px) {
  /* Convert to a full-width bottom sheet on mobile */
  .section-nav {
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    transform: none;
    z-index: 9700; /* above hero drawer & toolbar */
    display: none;
    align-items: stretch;
    flex-direction: column;
  }
  .inline-edit-active .section-nav {
    display: flex;
  }

  /* Hide the left-rail tab handle on mobile — open via "Map" toolbar button */
  .section-nav .section-nav-tab {
    display: none;
  }

  /* Backdrop is a sibling div injected by JS — see section-navigator.js */
  .section-nav-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
    z-index: 9690;
    opacity: 0;
    pointer-events: none;
    transition: opacity 220ms ease;
  }
  .section-nav-backdrop.is-visible {
    opacity: 1;
    pointer-events: auto;
  }

  .section-nav-body {
    width: 100%;
    max-width: 100%;
    max-height: 72vh;
    height: auto;
    border-radius: 1rem 1rem 0 0;
    border: 1px solid rgba(148, 163, 184, 0.22);
    border-bottom: none;
    box-shadow: 0 -8px 28px rgba(15, 23, 42, 0.18);
    transform: translateY(calc(100% + 4px));
    transition: transform 280ms cubic-bezier(0.22, 1, 0.36, 1), opacity 220ms ease;
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  .section-nav.is-open .section-nav-body {
    transform: translateY(0);
  }

  /* Grab handle at top of bottom sheet for affordance */
  .section-nav-body::before {
    content: '';
    display: block;
    width: 2.25rem;
    height: 0.25rem;
    margin: 0.45rem auto 0.1rem;
    border-radius: 999px;
    background: rgba(148, 163, 184, 0.45);
    flex-shrink: 0;
  }

  /* Slightly larger touch targets in the list */
  .section-nav-row {
    padding: 0.55rem 0.55rem;
    gap: 0.45rem;
  }
  .section-nav-name {
    font-size: 0.88rem;
    padding: 0.15rem 0;
  }
  .section-nav-actions {
    opacity: 1; /* always visible on touch */
    gap: 0.25rem;
  }
  .section-nav-btn {
    width: 2rem;
    height: 2rem;
    font-size: 0.78rem;
  }
  .section-nav-grip {
    width: 1.5rem;
    font-size: 0.78rem;
  }
}

/* Dark-mode bottom-sheet polish */
:is(body.theme-dark, body.ui-mode-dark, body.public-site-body.preset-mode-dark) .section-nav-body {
  background: rgba(18, 24, 38, 0.99);
  border-color: rgba(148, 163, 184, 0.16);
}
:is(body.theme-dark, body.ui-mode-dark, body.public-site-body.preset-mode-dark) .section-nav-header,
:is(body.theme-dark, body.ui-mode-dark, body.public-site-body.preset-mode-dark) .section-nav-footer {
  background: rgba(22, 30, 46, 0.95);
  border-color: rgba(148, 163, 184, 0.14);
}
:is(body.theme-dark, body.ui-mode-dark, body.public-site-body.preset-mode-dark) .section-nav-title,
:is(body.theme-dark, body.ui-mode-dark, body.public-site-body.preset-mode-dark) .section-nav-name {
  color: rgba(226, 232, 240, 0.85);
}

/* Inline rename input for the navbar jump-pill label */
.section-nav-rename-input {
  flex: 1;
  min-width: 0;
  background: var(--public-card-bg, #ffffff);
  border: 1px solid var(--theme-primary, #2563eb);
  border-radius: 0.4rem;
  padding: 0.15rem 0.4rem;
  font-size: 0.78rem;
  font-weight: 500;
  color: #0f172a;
  outline: none;
}
:is(body.theme-dark, body.ui-mode-dark, body.public-site-body.preset-mode-dark) .section-nav-rename-input {
  background: var(--public-card-bg, rgba(16, 28, 52, 0.96));
  color: rgba(226, 232, 240, 0.95);
}
:is(body.theme-dark, body.ui-mode-dark, body.public-site-body.preset-mode-dark) .section-nav-row:hover {
  background: rgba(255, 255, 255, 0.05);
  border-color: rgba(148, 163, 184, 0.2);
}
