/* ─────────────────────────────────────────────────────────────────────────
   sidenav.css — vertical sidebar nav. JS-generated (#side-nav-v2 in
   js/app.js _ensureSideNav) so it doesn't inherit any of nav.css's
   horizontal layout quirks. The old .nav-bottom-row is hidden entirely
   by the same JS, and its .nav-tab children are MOVED (not cloned) into
   the new sidebar to preserve click handlers + perms-driven display:none.
   Toggle: #nav-sidebar-toggle (edge pill) flips body.sidebar-collapsed.
   ───────────────────────────────────────────────────────────────────────── */

/* --- Layout tokens -------------------------------------------------------- */
/* Shrink --nav-h to just the top-row height so the empty 40px band where
   .nav-bottom-row used to live disappears. .tab-panel uses var(--nav-h)
   for its padding-top, so this automatically reclaims the empty bar. */
:root {
  --nav-h: 46px;
  --side-nav-w: 220px;
  --side-nav-top: 46px;
}
#main-nav { height: auto !important; min-height: 46px; }
.nav-top-row { height: 46px !important; }
#side-nav-v2 {
  position: fixed;
  left: 0;
  top: var(--side-nav-top);
  bottom: 0;
  width: var(--side-nav-w);
  display: flex !important;
  flex-direction: column;
  gap: 4px;
  padding: 16px 10px;
  background: rgba(8, 14, 22, 0.92);
  backdrop-filter: blur(16px) saturate(140%);
  -webkit-backdrop-filter: blur(16px) saturate(140%);
  border-right: 1px solid rgba(56, 189, 248, 0.10);
  z-index: 40;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
  scrollbar-color: rgba(56,189,248,0.45) rgba(255,255,255,0.04);
  transition: transform 0.32s cubic-bezier(0.22, 1, 0.36, 1);
}
#side-nav-v2::-webkit-scrollbar { width: 6px; }
#side-nav-v2::-webkit-scrollbar-thumb { background: rgba(56,189,248,0.40); border-radius: 6px; }

/* Make the moved .nav-tab buttons render as full-width sidebar rows. The
   important flags defeat the nav-tab-in @keyframe + nth-child animation
   chain that was leaving them at opacity:0. */
#side-nav-v2 .nav-tab {
  display: flex !important;
  align-items: center !important;
  justify-content: flex-start !important;
  width: 100% !important;
  padding: 11px 14px 11px 16px !important;
  text-align: left !important;
  white-space: nowrap !important;
  overflow: hidden !important;
  text-overflow: ellipsis !important;
  border: none !important;
  border-left: 3px solid transparent !important;
  border-radius: 8px !important;
  font-family: var(--font-body) !important;
  font-size: 12.5px !important;
  font-weight: 600 !important;
  letter-spacing: 0.08em !important;
  text-transform: uppercase !important;
  color: rgba(226, 232, 240, 0.82) !important;
  background: transparent !important;
  cursor: pointer !important;
  opacity: 1 !important;
  visibility: visible !important;
  transform: none !important;
  animation: none !important;
  transition: background 0.18s ease, color 0.18s ease, border-left-color 0.18s ease !important;
}
#side-nav-v2 .nav-tab:hover {
  background: rgba(56, 189, 248, 0.08) !important;
  color: var(--text-primary) !important;
}
#side-nav-v2 .nav-tab.active {
  background: rgba(56, 189, 248, 0.16) !important;
  color: rgba(56, 189, 248, 1) !important;
  border-left-color: rgba(56, 189, 248, 0.95) !important;
}
/* The active-pill ::after from nav.css was for the horizontal strip — kill it */
#side-nav-v2 .nav-tab.active::after { display: none !important; }

/* Tabs hidden by perms (inline style="display:none") stay hidden */
#side-nav-v2 .nav-tab[style*="display: none"],
#side-nav-v2 .nav-tab[style*="display:none"] { display: none !important; }

/* --- Edge toggle — half-pill that hugs the right edge of the sidebar -----
   When the sidebar is open it sits at left: var(--side-nav-w); when
   collapsed it slides back with the sidebar so it remains visible at
   left: 0. The chevron flips direction with .is-collapsed. */
.sidenav-edge-toggle {
  position: fixed;
  left: var(--side-nav-w);
  top: 50%;
  transform: translate(-50%, -50%);   /* straddle the sidebar's right edge */
  width: 28px;
  height: 56px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(8, 14, 22, 0.95);
  border: 1px solid rgba(56, 189, 248, 0.35);
  border-radius: 16px;
  color: rgba(56, 189, 248, 0.95);
  cursor: pointer;
  z-index: 45;          /* above sidebar (40), below modals */
  box-shadow: 4px 0 18px rgba(0, 0, 0, 0.40),
              0 0 14px rgba(56, 189, 248, 0.15);
  transition: left 0.32s cubic-bezier(0.22, 1, 0.36, 1),
              background var(--t-fast) var(--ease-out),
              border-color var(--t-fast) var(--ease-out),
              color var(--t-fast) var(--ease-out);
}
.sidenav-edge-toggle:hover {
  background: rgba(56, 189, 248, 0.18);
  border-color: rgba(56, 189, 248, 0.65);
  color: #04050f;
}
.sidenav-edge-toggle svg { transition: transform 0.32s cubic-bezier(0.22, 1, 0.36, 1); }
body.sidebar-collapsed .sidenav-edge-toggle {
  left: 0;
}
body.sidebar-collapsed .sidenav-edge-toggle svg { transform: scaleX(-1); }

/* --- Sidebar = re-purposed .nav-bottom-row -------------------------------- */
/* Top offset accounts for the top nav row (logo + dept + controls + user). */
:root {
  --side-nav-w: 220px;
  --side-nav-top: 64px;
}

.nav-bottom-row {
  position: fixed;
  left: 0;
  top: var(--side-nav-top);
  bottom: 0;
  width: var(--side-nav-w);
  height: auto;
  padding: 14px 8px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background: rgba(8, 14, 22, 0.78);
  backdrop-filter: blur(16px) saturate(140%);
  -webkit-backdrop-filter: blur(16px) saturate(140%);
  border-right: 1px solid rgba(255, 255, 255, 0.05);
  z-index: 40;
  transition: transform 0.32s cubic-bezier(0.22, 1, 0.36, 1);
}

/* Sliding pill from horizontal layout is hidden — for vertical we use
   per-tab .active styling instead (cyan left bar + bg). */
#nav-indicator { display: none !important; }

/* Tabs container scrolls vertically if there are too many. */
.nav-tabs {
  flex-direction: column;
  align-items: stretch;
  gap: 2px;
  flex: 1;
  overflow-x: hidden;
  overflow-y: auto;
  padding: 0;
  scrollbar-width: none;
}

/* Tabs: block-level rows, left-aligned text, cyan accent left-border on
   .active. We FORCE opacity:1 + animation:none because nav.css's
   .nav-tab-in keyframe leaves elements at opacity:0 with animation-fill-mode
   `both` — if the cascade timing is off, sidebar tabs stay invisible. */
.nav-tab,
.nav-tabs .nav-tab,
.nav-tab:nth-child(1),
.nav-tab:nth-child(2),
.nav-tab:nth-child(3),
.nav-tab:nth-child(4),
.nav-tab:nth-child(5),
.nav-tab:nth-child(6),
.nav-tab:nth-child(7),
.nav-tab:nth-child(8),
.nav-tab:nth-child(9),
.nav-tab:nth-child(10) {
  animation: none !important;
  animation-delay: 0s !important;
  opacity: 1 !important;
}
.nav-tab {
  display: flex !important;
  align-items: center;
  justify-content: flex-start;
  width: 100%;
  padding: 10px 14px 10px 16px;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  border-radius: 8px;
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(226, 232, 240, 0.78);       /* brighter than --text-muted */
  border-left: 3px solid transparent;
  background: transparent;
  transform: none;
  transition: background var(--t-fast) var(--ease-out),
              color var(--t-fast) var(--ease-out),
              border-left-color var(--t-fast) var(--ease-out);
}
/* Honor tabs that were hidden by perms — those have inline style display:none */
.nav-tab[style*="display: none"],
.nav-tab[style*="display:none"] { display: none !important; }

.nav-tab:hover {
  background: rgba(56,189,248,0.08);
  color: var(--text-primary);
  transform: none;
}
.nav-tab.active {
  background: rgba(56,189,248,0.14);
  color: rgba(56,189,248,1);
  border-left-color: rgba(56,189,248,0.95);
  box-shadow: inset 1px 0 0 rgba(56,189,248,0.18);
}

/* Content area shifts right by sidebar width. Apply on every dept dashboard. */
.dept-dashboard {
  padding-left: var(--side-nav-w);
  transition: padding-left 0.32s cubic-bezier(0.22, 1, 0.36, 1);
}

/* Top nav stays full-width (sits above the sidebar). Cancel inherited
   padding-left from .dept-dashboard so the logo doesn't shift in. */
.dept-dashboard #main-nav { margin-left: calc(-1 * var(--side-nav-w)); padding-left: var(--side-nav-w); }
body.sidebar-collapsed .dept-dashboard #main-nav { margin-left: 0; padding-left: 0; }

/* --- Collapsed state ------------------------------------------------------ */
body.sidebar-collapsed #side-nav-v2,
body.sidebar-collapsed .nav-bottom-row {
  transform: translateX(calc(-1 * (var(--side-nav-w) + 4px)));
  pointer-events: none;
}
body.sidebar-collapsed .dept-dashboard { padding-left: 0; }

/* --- Phone (≤ 768 px) ------------------------------------------------------ */
/* On small viewports, sidebar is collapsed by default. When opened it overlays
   the content (doesn't push) so we don't get a sliver of unusable column. */
@media (max-width: 768px) {
  .dept-dashboard { padding-left: 0; }
  .dept-dashboard #main-nav { margin-left: 0; padding-left: 0; }
  #side-nav-v2 {
    transform: translateX(calc(-1 * (var(--side-nav-w) + 4px)));
    pointer-events: none;
    box-shadow: 16px 0 40px rgba(0,0,0,0.45);
  }
  body:not(.sidebar-collapsed) #side-nav-v2 {
    transform: translateX(0);
    pointer-events: auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  .nav-bottom-row,
  .dept-dashboard,
  .dept-dashboard #main-nav,
  .nav-sidebar-toggle svg { transition: none; }
}
