/* ============================================================
   GLOBAL SIDE NAVIGATION  ·  shared across every portfolio page

   Two desktop states, one shared visual language:

   >= 1640px  →  persistent expanded rail
                 · case studies keep their existing in-grid
                   .cs-rail (see css/case.css) — untouched
                 · the homepage gets .pf-snav-rail, a fixed rail
                   that sits in the left gutter and NEVER affects
                   the position of the centred page content
   < 1640px   →  the rail collapses to a slim left-edge trigger
                 that opens an overlay drawer (this file)

   1640px is the point where a 1320px-wide centred layout still
   leaves enough gutter for the rail (and where the case-study
   grid stops compressing its content column).

   Depends only on tokens from css/hero.css (--mono, --cyan,
   --muted, --dim, --border, --border-strong, --bg-2, --text,
   --cyan-glow) plus --pf-ubar-h from css/utility-bar.css.
   ============================================================ */

:root {
  --pf-topbar-h: 84px;   /* measured + kept in sync by js/side-nav.js */
  --pf-snav-w: 176px;
}

/* ============ HOMEPAGE PERSISTENT RAIL (>= 1640px) ============ */

.pf-snav-rail {
  display: none;                       /* enabled only at >= 1640px */
  position: fixed;
  z-index: 15;
  top: 132px;
  /* 100vw ignores the root zoom — divide by --pf-scale so the rail
     stays in the gutter beside the 1320px layout at any content scale */
  left: max(10px, calc((100vw / var(--pf-scale, 1) - 1320px) / 2 - var(--pf-snav-w)));
  width: var(--pf-snav-w);
  flex-direction: column;
  gap: 4px;
  padding: 8px 0;
  max-height: calc(100vh - 132px - var(--pf-ubar-h, 42px) - 28px);
  overflow: auto;
}

.pf-snav-rail-link {
  position: relative;
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: 0.2em;
  color: var(--dim);
  text-decoration: none;
  padding: 9px 0 9px 18px;
  border-left: 1px solid var(--border);
  transition: color 0.25s, border-color 0.25s;
}

.pf-snav-rail-link::before {
  content: '';
  position: absolute;
  left: -3px;
  top: 50%;
  width: 5px;
  height: 5px;
  margin-top: -2.5px;
  border-radius: 50%;
  background: rgba(125, 180, 255, 0.25);
  transition: background 0.25s, box-shadow 0.25s;
}

.pf-snav-rail-link:hover { color: var(--muted); }

.pf-snav-rail-link.active {
  color: var(--cyan);
  border-color: rgba(56, 189, 248, 0.45);
}

.pf-snav-rail-link.active::before {
  background: var(--cyan);
  box-shadow: 0 0 8px var(--cyan-glow);
}

.pf-snav-rail-link.is-disabled {
  color: var(--dim);
  opacity: 0.45;
  cursor: default;
}

/* ============ EDGE TRIGGER (< 1640px) ============ */

.pf-snav-trigger {
  display: none;                       /* enabled only below 1640px */
  position: fixed;
  z-index: 40;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  align-items: center;
  justify-content: center;
  width: 30px;                         /* compact visible handle (interaction zone is wider — js/side-nav.js) */
  height: 68px;
  margin: 0;
  padding: 0;
  border: 1px solid var(--border-strong, rgba(125, 180, 255, 0.28));
  border-left: 0;
  border-radius: 0 10px 10px 0;
  background: rgba(13, 18, 28, 0.94);
  -webkit-backdrop-filter: blur(7px);
  backdrop-filter: blur(7px);
  color: var(--cyan, #38bdf8);
  cursor: pointer;
  transition: color 0.18s, background 0.18s, border-color 0.18s, box-shadow 0.18s;
}

.pf-snav-trigger svg {
  width: 13px;
  height: 13px;
  display: block;
  opacity: 0.82;
  transition: opacity 0.18s;
}

/* :hover = pointer on the handle · .is-hot = pointer in the wider interaction zone */
.pf-snav-trigger:hover,
.pf-snav-trigger.is-hot {
  border-color: rgba(56, 189, 248, 0.55);
  background: rgba(56, 189, 248, 0.1);
  box-shadow: 0 0 14px rgba(56, 189, 248, 0.18);
}

.pf-snav-trigger:hover svg,
.pf-snav-trigger.is-hot svg { opacity: 1; }

.pf-snav-trigger:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 2px;
}

/* ============ DRAWER + BACKDROP (< 1640px) ============ */

.pf-snav-backdrop {
  position: fixed;
  z-index: 45;
  inset: var(--pf-topbar-h) 0 calc(var(--pf-ubar-h, 42px) + env(safe-area-inset-bottom, 0px)) 0;
  background: rgba(6, 9, 15, 0.55);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.pf-snav-backdrop.is-open {
  opacity: 1;
  pointer-events: auto;
}

.pf-snav-drawer {
  position: fixed;
  z-index: 46;
  top: var(--pf-topbar-h);
  bottom: calc(var(--pf-ubar-h, 42px) + env(safe-area-inset-bottom, 0px));
  left: 0;
  width: min(248px, 84vw);
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 16px 14px 20px;
  background: var(--bg-2, #0d121c);
  border-right: 1px solid var(--border);
  box-shadow: 18px 0 44px rgba(0, 0, 0, 0.4);
  transform: translateX(-100%);
  transition: transform 0.22s cubic-bezier(0.4, 0, 0.2, 1);
  overflow-y: auto;
  overscroll-behavior: contain;
}

.pf-snav-drawer.is-open { transform: translateX(0); }

.pf-snav-close {
  align-self: flex-end;
  width: 30px;
  height: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin: 0 0 8px;
  padding: 0;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 7px;
  color: var(--muted);
  cursor: pointer;
  transition: color 0.18s, border-color 0.18s;
}

.pf-snav-close:hover { color: var(--cyan); border-color: var(--border-strong); }
.pf-snav-close:focus-visible { outline: 2px solid var(--cyan); outline-offset: 2px; }
.pf-snav-close svg { width: 13px; height: 13px; display: block; }

.pf-snav-item {
  position: relative;
  display: block;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.18em;
  color: var(--dim);
  text-decoration: none;
  padding: 14px 10px 14px 20px;
  border-left: 1px solid var(--border);
  border-radius: 0 6px 6px 0;
  transition: color 0.2s, border-color 0.2s, background 0.2s;
}

.pf-snav-item::before {
  content: '';
  position: absolute;
  left: -3px;
  top: 50%;
  width: 5px;
  height: 5px;
  margin-top: -2.5px;
  border-radius: 50%;
  background: rgba(125, 180, 255, 0.25);
  transition: background 0.2s, box-shadow 0.2s;
}

.pf-snav-item:hover {
  color: var(--muted);
  background: rgba(56, 189, 248, 0.04);
}

.pf-snav-item.active {
  color: var(--cyan);
  border-color: rgba(56, 189, 248, 0.45);
}

.pf-snav-item.active::before {
  background: var(--cyan);
  box-shadow: 0 0 8px var(--cyan-glow);
}

.pf-snav-item:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: -2px;
  border-radius: 0 6px 6px 0;
}

.pf-snav-item.is-disabled {
  color: var(--dim);
  opacity: 0.5;
  cursor: default;
  pointer-events: none;
}

.pf-snav-item.pf-snav-back { margin-top: 10px; opacity: 0.9; }

.pf-snav-soon {
  margin-left: 8px;
  font-size: 8px;
  letter-spacing: 0.2em;
  color: var(--dim);
  border: 1px solid rgba(125, 180, 255, 0.15);
  padding: 2px 6px;
  border-radius: 100px;
  vertical-align: middle;
}

/* ============ STATE SWITCH ============

   js/side-nav.js sets  <html data-pf-snav="rail" | "drawer">  from the
   ZOOM-ADJUSTED viewport width (window.innerWidth / --pf-scale), so the
   persistent rail collapses to the drawer both when the window narrows
   AND when the content scale is turned up. The @media fallbacks keep a
   sensible state during the brief moment before the script runs.
   Threshold: 1640px — the point where a 1320px centred layout still
   leaves gutter for the rail and the case-study grid stops compressing. */

html[data-pf-snav="rail"] .pf-snav-rail { display: flex; }
html[data-pf-snav="rail"] .pf-snav-trigger { display: none !important; }
html[data-pf-snav="rail"] .pf-snav-drawer,
html[data-pf-snav="rail"] .pf-snav-backdrop { display: none !important; }

html[data-pf-snav="drawer"] .pf-snav-rail { display: none !important; }
html[data-pf-snav="drawer"] .pf-snav-trigger { display: inline-flex; }

@media (min-width: 1640px) {
  html:not([data-pf-snav]) .pf-snav-rail { display: flex; }
}
@media (max-width: 1639.98px) {
  html:not([data-pf-snav]) .pf-snav-rail { display: none; }
  html:not([data-pf-snav]) .pf-snav-trigger { display: inline-flex; }
}

/* ============ MOBILE ============ */

@media (max-width: 640px) {
  .pf-snav-trigger { width: 26px; height: 60px; }

  .pf-snav-drawer {
    width: min(284px, 86vw);
    padding: 14px 12px 18px;
  }

  .pf-snav-item {
    font-size: 11px;
    padding: 16px 12px 16px 20px;
  }
}

/* ============ REDUCED MOTION ============ */

@media (prefers-reduced-motion: reduce) {
  .pf-snav-drawer,
  .pf-snav-backdrop,
  .pf-snav-trigger,
  .pf-snav-trigger svg,
  .pf-snav-close,
  .pf-snav-item,
  .pf-snav-rail-link { transition: none !important; }
}
