/*
 * ═══════════════════════════════════════════════════════════
 *  NESTABD · SEGMENTED NAVIGATION SYSTEM · Phase 56
 *  One reusable component for ALL tab / chip / segment nav.
 *
 *  Applies to:
 *    .sn-wrap--module  →  Topnav tabs  (Verify / Builders / Legal / NCLT)
 *    .sn-wrap--city    →  City selector (GBN / GGM / GZB / FBD …)
 *    .sn-wrap--filter  →  Dashboard filter bar (All / Residential …)
 *    .sn-wrap--detail  →  Project detail tabs (Overview / Documents …)
 *
 *  NOT applied to: Investment Tools (card grid — separate component).
 *
 *  Architecture:
 *    .sn-wrap           → Outer scroll container + fade masks
 *      .sn-track        → Flex row of items
 *        .sn-item       → Individual tab / chip / button
 *        .sn-item--soon → Coming-soon disabled variant
 *
 *  Phase 56 guarantee:
 *    • Zero duplicate CSS rules across navigation contexts
 *    • Zero horizontal page scroll introduced
 *    • Zero business logic touched
 * ═══════════════════════════════════════════════════════════
 */

/* ─── 1. SCROLL CONTAINER ─────────────────────────────────── */

.sn-wrap {
  position: relative;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  -ms-overflow-style: none;
  /* Scroll snapping: each item snaps into view */
  scroll-snap-type: x proximity;
  /* Prevent this container from creating horizontal page overflow */
  max-width: 100%;
  /* Fade indicators via mask — always rendered, opacity controlled by JS class */
  -webkit-mask-image: var(--sn-mask, linear-gradient(to right, black 100%, black 100%));
  mask-image:         var(--sn-mask, linear-gradient(to right, black 100%, black 100%));
  transition: mask-image 0.15s ease, -webkit-mask-image 0.15s ease;
}

.sn-wrap::-webkit-scrollbar { display: none; }

/* Fade-left: content runs off left edge */
.sn-wrap.sn-has-scroll-left {
  --sn-mask: linear-gradient(to right,
    transparent 0px,
    black 28px,
    black 100%
  );
}

/* Fade-right: content runs off right edge */
.sn-wrap.sn-has-scroll-right {
  --sn-mask: linear-gradient(to right,
    black 0%,
    black calc(100% - 28px),
    transparent 100%
  );
}

/* Both fades simultaneously */
.sn-wrap.sn-has-scroll-left.sn-has-scroll-right {
  --sn-mask: linear-gradient(to right,
    transparent 0px,
    black 28px,
    black calc(100% - 28px),
    transparent 100%
  );
}

/* ─── 2. INNER TRACK ──────────────────────────────────────── */

.sn-track {
  display: inline-flex;
  flex-wrap: nowrap;
  gap: var(--sn-gap, 6px);
  padding: var(--sn-pad, 0);
  /* Ensure track doesn't constrain scroll */
  min-width: max-content;
}

/* ─── 3. BASE ITEM ────────────────────────────────────────── */

.sn-item {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  /* Touch target: WCAG 2.5.5 — 44×44 px minimum */
  min-height: 44px;
  min-width: 44px;
  padding: var(--sn-item-pad, 8px 16px);
  border: none;
  border-radius: 999px;
  font-family: var(--font-body, 'DM Sans', sans-serif);
  font-size: var(--sn-fs, 13px);
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  text-decoration: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.16s ease, color 0.16s ease, box-shadow 0.16s ease, opacity 0.16s ease;
  /* Scroll snap: each item snaps into view */
  scroll-snap-align: start;
  /* Prevent items from shrinking */
  flex-shrink: 0;
  /* Keyboard focus — visible ring */
  outline: none;
  position: relative;
}

.sn-item:focus-visible {
  outline: 2.5px solid var(--sn-focus-ring, #fff);
  outline-offset: 2px;
}

/* Disabled (coming-soon) items */
.sn-item--soon,
.sn-item[aria-disabled="true"] {
  cursor: default;
  pointer-events: none;
}

/* ─── 4. MODULE NAVIGATION (topnav dark bg) ───────────────── */

.sn-wrap--module {
  --sn-gap: 8px;
  --sn-pad: 0;
  --sn-fs: 13px;
  --sn-item-pad: 8px 16px;
  --sn-focus-ring: #fff;
}

.sn-wrap--module .sn-item {
  background: rgba(255, 255, 255, 0.08);
  color: rgba(255, 255, 255, 0.8);
}

.sn-wrap--module .sn-item:hover:not(.active):not([aria-selected="true"]) {
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
}

.sn-wrap--module .sn-item.active,
.sn-wrap--module .sn-item[aria-selected="true"] {
  background: rgba(255, 255, 255, 0.22);
  color: #fff;
  box-shadow: 0 12px 30px rgba(15, 27, 76, 0.14);
}

/* Mobile: slightly smaller font, already handled by --sn-fs override below */
@media (max-width: 768px) {
  .sn-wrap--module {
    --sn-fs: 12px;
    --sn-item-pad: 8px 16px;
  }
}

/* ─── 5. CITY SELECTOR (topnav, dark bg) ─────────────────── */

.sn-wrap--city {
  --sn-gap: 6px;
  --sn-pad: 0;
  --sn-fs: 11px;
  --sn-item-pad: 5px 11px;
  --sn-focus-ring: #fff;
}

.sn-wrap--city .sn-item {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: rgba(255, 255, 255, 0.75);
  border-radius: 999px;
  font-size: 11px;
  /* City pills are slightly shorter — override 44px for in-topnav layout only */
  min-height: 32px;
}

.sn-wrap--city .sn-item.active,
.sn-wrap--city .sn-item[aria-selected="true"] {
  background: #0D9488;
  border-color: transparent;
  color: #d9fff6;
  font-weight: 700;
}

.sn-wrap--city .sn-item--soon,
.sn-wrap--city .sn-item[aria-disabled="true"] {
  opacity: 0.5;
}

/* "Soon" badge inside city item */
.sn-soon-tag {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.4px;
  opacity: 0.75;
  margin-left: 3px;
}

/* ─── 6. DASHBOARD FILTER BAR (light surface) ─────────────── */

.sn-wrap--filter {
  --sn-gap: 8px;
  --sn-pad: 0;
  --sn-fs: 13px;
  --sn-item-pad: 7px 18px;
  --sn-focus-ring: var(--navy, #0F1B4C);
}

/* Light theme override */
.sn-wrap--filter.sn-has-scroll-left,
.sn-wrap--filter.sn-has-scroll-right,
.sn-wrap--filter.sn-has-scroll-left.sn-has-scroll-right {
  /* Override white masks on light bg */
  --sn-mask-color-fade: var(--surface, #fff);
}

.sn-wrap--filter .sn-item {
  background: rgba(255, 255, 255, 0.9);
  border: 1.5px solid rgba(15, 27, 76, 0.12);
  color: var(--text-mid, #4A5568);
  border-radius: 22px;
  font-family: var(--font-body, 'DM Sans', sans-serif);
}

.sn-wrap--filter .sn-item:hover:not(.active):not([aria-selected="true"]) {
  border-color: var(--navy, #0F1B4C);
  color: var(--navy, #0F1B4C);
  background: #f8faff;
}

.sn-wrap--filter .sn-item.active,
.sn-wrap--filter .sn-item[aria-selected="true"] {
  background: linear-gradient(135deg, var(--navy, #0F1B4C), var(--navy-light, #1E2F6F));
  border-color: transparent;
  color: #fff;
  box-shadow: 0 8px 20px rgba(15, 27, 76, 0.16);
}

@media (max-width: 768px) {
  .sn-wrap--filter {
    --sn-fs: 12px;
    --sn-item-pad: 8px 14px;
  }
}

/* ─── 7. PROJECT DETAIL TABS (white card surface) ─────────── */

.sn-wrap--detail {
  --sn-gap: 4px;
  --sn-pad: 0;
  --sn-fs: 13px;
  --sn-item-pad: 7px 16px;
  --sn-focus-ring: var(--navy, #0F1B4C);
}

.sn-wrap--detail .sn-item {
  background: transparent;
  border-radius: 7px;
  color: var(--text-muted, #64748B);
  font-weight: 500;
  /* Detail tabs: inherit 44px min-height from base .sn-item */
}

.sn-wrap--detail .sn-item:hover:not(.active):not([aria-selected="true"]) {
  color: var(--text-mid, #4A5568);
  background: rgba(15, 27, 76, 0.04);
}

.sn-wrap--detail .sn-item.active,
.sn-wrap--detail .sn-item[aria-selected="true"] {
  background: var(--surface, #fff);
  color: var(--navy, #0F1B4C);
  box-shadow: 0 2px 12px rgba(15, 27, 76, 0.08);
  font-weight: 600;
}

/* ─── 8. LAYOUT INTEGRATION OVERRIDES ────────────────────── */

/*
 * The .filter-bar container is kept for structural/spacing purposes.
 * The inner .sn-wrap replaces the old .filter-btn child flow.
 */
.filter-bar {
  /* Keep flex alignment — sn-wrap is now a flex child */
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: nowrap;
}

.filter-bar .sn-wrap--filter {
  /* Allow sn-wrap to grow and scroll within the filter-bar */
  flex: 1;
  min-width: 0;
}

/*
 * The .tabs container on the detail screen is replaced entirely
 * by .sn-wrap--detail. Keep legacy .tabs class for any external
 * CSS that targets it for spacing/padding.
 */
.tabs {
  background: var(--bg, #F8F9FC);
  padding: 6px 8px;
  border-radius: 10px;
  margin-bottom: 12px;
}

/*
 * The .nav-tabs container in topnav is replaced by .sn-wrap--module.
 * The topnav layout requires flex: full-width row on mobile.
 */
.topnav .sn-wrap--module {
  width: 100%;
}

@media (max-width: 768px) {
  /* Module nav wraps to full-width row below topnav logo on mobile */
  .topnav .sn-wrap--module {
    order: 3;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    padding: 6px 0 10px;
  }

  /* City selector: no border, compact in header row */
  .topnav-logo .sn-wrap--city {
    max-width: calc(100vw - 200px);
  }
}

/* ─── 9. STICKY SUPPORT ───────────────────────────────────── */

/*
 * Dashboard filter bar sticky: sticks just below the ticker.
 * Opt in with .filter-bar--sticky (added when sticky behaviour needed).
 */
.filter-bar--sticky {
  position: sticky;
  top: var(--topnav-h, 68px);
  z-index: 95;
  background: var(--surface, #fff);
  border-bottom: 1px solid rgba(15, 27, 76, 0.08);
  box-shadow: 0 4px 12px rgba(15, 27, 76, 0.04);
}

/* Detail tab row sticky */
.sn-wrap--detail.sn-sticky {
  position: sticky;
  top: calc(var(--topnav-h, 68px) + 32px); /* below topnav + ticker */
  z-index: 90;
  background: var(--bg, #F8F9FC);
  border-bottom: 1px solid rgba(15, 27, 76, 0.06);
  padding: 6px 8px;
  margin-bottom: 0;
}

/* ─── 10. DESKTOP ENHANCEMENTS ────────────────────────────── */

@media (min-width: 769px) {
  .sn-wrap--module {
    --sn-fs: 13px;
  }

  .sn-wrap--filter {
    --sn-fs: 13px;
  }

  /* On desktop, module tabs no longer need to scroll */
  .topnav .sn-wrap--module {
    overflow: visible;
  }

  .topnav .sn-wrap--module .sn-track {
    min-width: unset;
  }
}

/* ─── 11. REDUCED MOTION ──────────────────────────────────── */

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

/* ─── 12. INVESTMENT TOOLS SCALABILITY PREP ───────────────── */
/*
 * Investment Tools remains a card grid (NOT segmented nav).
 * These selectors prepare the category architecture for future
 * filtering without visually changing anything today.
 * data-it-category="calculators|ai-tools|legal|research|finance"
 * is now present on each tool card in tools.js but hidden by default.
 */
.it-category-filter {
  display: none; /* Hidden until category filtering is needed */
}
