/* ============================================================
   platform-shell.css — Shared operator nav-shell (the rail)
   The lateral-nav spine that makes the consoles feel like ONE
   system. Dark glass, cyan active state, smooth hover.
   Consumes --ps-* tokens from design-tokens.css.
   CSP-clean: no @import, no external url(), no inline JS.

   Z-INDEX / HEADER OFFSET CONTRACT
   --------------------------------
   .ps-rail sits at z-index 40 (see the declaration below for why) — above
   normal page content, below page headers and every auth overlay.
   The rail spans the full viewport height (top:0; bottom:0) on the
   left edge. Page fixed headers should reserve their left edge:
   account for the rail width via `left: var(--ps-rail-w)` (76px) so
   they do not slide under the rail. body.ps-has-rail applies
   `padding-left: 76px` to push static page content clear of the rail.
   Under 768px the rail collapses to icon-only 56px and the body
   padding follows (--ps-rail-w-sm).
   ============================================================ */

:root {
  --ps-rail-w: 76px;
  --ps-rail-w-sm: 56px;
}

/* ---------- Body offset (added by platform-shell.js) ---------- */
body.ps-has-rail {
  padding-left: var(--ps-rail-w);
}

/* ---------- The rail ---------- */
.ps-rail {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--ps-rail-w);
  /* 900 → 40 (Review Gate 2026-08-07). At 900 the rail painted ON TOP of every
   * full-screen auth gate and was clickable there: platform.html .login-overlay
   * (z-100) and the #authOverlay (z-50) on the five analytics pages. An anonymous
   * visitor got working operator navigation floating over the login screen —
   * not an auth bypass, since every target re-gates, but operator chrome that
   * must not exist pre-auth. Measured via elementFromPoint(30,450) → .ps-rail.
   *
   * 40 sits below every overlay AND below the page headers (.cc-/.dc-/.mc-header,
   * all z-50). Safe: those headers are offset clear of the rail's 76px strip, so
   * losing the stacking contest costs nothing. Fixing it here covers all 11 pages;
   * raising .login-overlay instead would have fixed only platform.html. */
  z-index: 40;

  display: flex;
  flex-direction: column;
  align-items: stretch;

  box-sizing: border-box;
  padding: var(--ps-s3) var(--ps-s1);
  gap: var(--ps-s1);

  font-family: var(--ps-font-sans);

  /* Dark glass */
  background: color-mix(in srgb, var(--ps-bg) 78%, transparent);
  -webkit-backdrop-filter: blur(18px) saturate(150%);
  backdrop-filter: blur(18px) saturate(150%);
  border-right: 1px solid var(--ps-border);
  box-shadow: var(--ps-shadow-lg);

  overflow-x: hidden;
  overflow-y: auto;
  scrollbar-width: thin;
}

/* ---------- Brand (top) ---------- */
.ps-rail__brand {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 44px;
  margin-bottom: var(--ps-s2);
  border-radius: var(--ps-radius);
  color: var(--ps-primary);
  text-decoration: none;
  font-family: var(--ps-font-mono);
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: 0.04em;
  user-select: none;
  flex: 0 0 auto;
}

.ps-rail__brand:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px var(--ps-bg), 0 0 0 4px var(--ps-primary-dim);
}

.ps-rail__brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.ps-rail__brand-mark svg {
  width: 26px;
  height: 26px;
  display: block;
}

/* ---------- Nav container ---------- */
.ps-rail__nav {
  display: flex;
  flex-direction: column;
  gap: var(--ps-s1);
  flex: 1 1 auto;
}

/* ---------- Rail item ---------- */
.ps-rail__item {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;

  box-sizing: border-box;
  /* Reserve room for icon + up to 2 label lines so single-line and
     two-line items share a consistent row height. */
  min-height: 60px;
  padding: var(--ps-s2) 2px;
  border-radius: var(--ps-radius);
  border: 1px solid transparent;

  color: var(--ps-text-dim);
  text-decoration: none;
  cursor: pointer;
  user-select: none;

  transition: background-color 0.16s ease, color 0.16s ease,
    border-color 0.16s ease, box-shadow 0.16s ease, transform 0.06s ease;
}

.ps-rail__item-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  flex: 0 0 auto;
}

.ps-rail__item-icon svg {
  width: 22px;
  height: 22px;
  display: block;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.ps-rail__item-label {
  font-size: 0.625rem; /* 10px — readable on the 76px rail */
  font-weight: 600;
  line-height: 1.1;
  letter-spacing: 0;
  text-align: center;
  max-width: 100%;
  /* Allow up to 2 lines so full labels ("Memory Center",
     "Content Center") fit within the 76px rail without ellipsis. */
  white-space: normal;
  overflow-wrap: break-word;
  word-break: normal;
  hyphens: auto;
  -webkit-hyphens: auto;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
}

.ps-rail__item:hover {
  color: var(--ps-text);
  background: color-mix(in srgb, var(--ps-primary) 10%, transparent);
  border-color: color-mix(in srgb, var(--ps-primary) 22%, transparent);
}

.ps-rail__item:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px var(--ps-bg), 0 0 0 4px var(--ps-primary-dim);
}

.ps-rail__item:active {
  transform: translateY(1px);
}

/* ---------- Active state (cyan) ---------- */
.ps-rail__item.is-active {
  color: var(--ps-primary);
  background: color-mix(in srgb, var(--ps-primary) 16%, transparent);
  border-color: color-mix(in srgb, var(--ps-primary) 38%, transparent);
}

/* Left accent bar on the active item */
.ps-rail__item.is-active::before {
  content: '';
  position: absolute;
  left: -2px;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 60%;
  border-radius: 0 var(--ps-radius-sm) var(--ps-radius-sm) 0;
  background: var(--ps-primary);
  box-shadow: 0 0 8px var(--ps-primary);
}

.ps-rail__item.is-active:hover {
  color: var(--ps-primary);
  background: color-mix(in srgb, var(--ps-primary) 20%, transparent);
}

/* ============================================================
   Responsive — under 768px collapse to icon-only 56px rail.
   (Stays a left rail; narrower. Labels hidden, icons centered.)
   ============================================================ */
@media (max-width: 768px) {
  body.ps-has-rail {
    padding-left: var(--ps-rail-w-sm);
  }

  .ps-rail {
    width: var(--ps-rail-w-sm);
    padding: var(--ps-s2) 4px;
  }

  .ps-rail__brand {
    height: 40px;
    font-size: 0;
  }

  .ps-rail__brand-mark svg {
    width: 24px;
    height: 24px;
  }

  .ps-rail__item-label {
    display: none;
  }

  .ps-rail__item {
    padding: var(--ps-s2) 0;
  }
}

/* Honour reduced-motion */
@media (prefers-reduced-motion: reduce) {
  .ps-rail__item,
  .ps-rail__brand,
  .ps-btn {
    transition: none;
  }
}
