/*
 * Sidebar — slide-over sheet (mobile + desktop). Neutral surface so the green top bar
 * stays the primary chrome; links use normal content colors + subtle mint active state.
 */

.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  /* Cover full viewport including mobile browser chrome / safe areas (100vh can fall short on iOS) */
  height: 100%;
  min-height: 100dvh;
  min-height: -webkit-fill-available;
  z-index: 1040;
  pointer-events: none;
  visibility: hidden;
  transition: visibility var(--transition-base);
  --sidebar-top-offset: var(--nav-fixed-height);
}

body.sidebar-open {
  overflow: hidden;
  touch-action: none;
}

.sidebar.show {
  visibility: visible;
  pointer-events: auto;
}

.sidebar-backdrop {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: var(--backdrop-scrim);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  opacity: 0;
  transition: opacity var(--transition-base);
}

.sidebar.show .sidebar-backdrop {
  opacity: 1;
}

.sidebar-content {
  position: absolute;
  top: var(--sidebar-top-offset);
  left: 0;
  width: 280px;
  max-width: 85vw;
  height: calc(100% - var(--sidebar-top-offset));
  background: var(--bg-surface);
  border-right: 1px solid var(--border-primary);
  border-radius: 0 var(--radius-xl) var(--radius-xl) 0;
  box-shadow: var(--shadow-xl);
  transform: translateX(-100%);
  transition: transform var(--transition-base);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar.show .sidebar-content {
  transform: translateX(0);
}

.sidebar-nav {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: var(--space-4) 0;
  padding-bottom: max(var(--space-6), 80px);
  display: flex;
  flex-direction: column;
}

.sidebar-section {
  padding: 0 var(--space-4);
}

/* Program section headers (UPN / UPYu / …) */
.sidebar-group-label {
  padding: var(--space-3) var(--space-4) var(--space-1);
  margin: 0;
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-tertiary);
  line-height: 1.2;
}

.sidebar-section-bottom {
  margin-top: auto;
  padding-bottom: var(--space-4);
}

.sidebar-divider {
  margin: var(--space-4) var(--space-4);
  border-color: var(--border-primary);
  border-top: none;
  border-bottom: 1px solid var(--border-primary);
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  color: var(--text-secondary);
  text-decoration: none;
  border-radius: var(--radius-md);
  transition: background var(--transition-fast), color var(--transition-fast), box-shadow var(--transition-fast);
  margin-bottom: var(--space-1);
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  font-size: var(--font-ui-label);
  font-weight: 500;
  cursor: pointer;
  min-height: 44px;
}

.sidebar-link:hover {
  background: var(--list-row-hover-bg);
  color: var(--text-primary);
}

.sidebar-link.active {
  background: var(--list-row-active-bg);
  box-shadow: inset 0 0 0 1px var(--border-secondary);
  color: var(--accent-primary);
  font-weight: 600;
}

.sidebar-link:active {
  transform: translateY(1px);
}

.sidebar-link-icon {
  font-size: 1.25rem;
  width: 24px;
  text-align: center;
  flex-shrink: 0;
}

.sidebar-link-text {
  flex: 1;
}

.sidebar-signout-form {
  width: 100%;
  margin: 0;
  padding: 0;
}

/* Sign out — readable on light + dark surfaces */
.sidebar-link-signout {
  color: var(--danger-fg);
}

.sidebar-link-signout:hover {
  background: var(--danger-bg-hover);
  color: var(--danger-fg-strong);
}

.sidebar-signout-form .sidebar-link {
  margin-bottom: 0;
}

/*
 * Locale + theme segmented controls — same tokens as .sidebar-link (mint active, neutral idle).
 * Navbar chrome keeps default Bootstrap; these rules are scoped to the slide-over sheet only.
 */
.sidebar .sidebar-section .locale-switcher,
.sidebar .sidebar-section .theme-switcher {
  justify-content: center;
  width: 100%;
}

.sidebar .sidebar-section .locale-switcher.btn-group,
.sidebar .sidebar-section .theme-switcher.btn-group {
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--bg-elevated);
}

/*
 * Dark: recessed track — idle segments stay flat/muted; selected is the only green-tint “on” chip.
 */
html[data-theme="dark"] .sidebar .sidebar-section .locale-switcher.btn-group,
html[data-theme="dark"] .sidebar .sidebar-section .theme-switcher.btn-group {
  background: var(--bg-primary);
}

/*
 * Locale / theme segments: override global outline-secondary hovers so inactive chips stay neutral
 * on the sidebar track (buttons.css uses a brand wash elsewhere).
 */
.sidebar .sidebar-section .locale-switcher .btn.btn-outline-secondary,
.sidebar .sidebar-section .theme-switcher .btn.btn-outline-secondary {
  --bs-btn-color: var(--text-secondary);
  --bs-btn-bg: transparent;
  --bs-btn-border-color: var(--border-primary);
  --bs-btn-hover-color: var(--text-primary);
  --bs-btn-hover-bg: var(--list-row-hover-bg);
  --bs-btn-hover-border-color: var(--border-secondary);
  --bs-btn-active-color: var(--text-primary);
  --bs-btn-active-bg: var(--list-row-hover-bg);
  --bs-btn-active-border-color: var(--border-secondary);
  color: var(--text-secondary) !important;
  background-color: transparent !important;
  border-color: var(--border-primary) !important;
}

/*
 * Dark: outline borders read like “selected” chips — drop inner borders, mute labels to tertiary.
 */
html[data-theme="dark"] .sidebar .sidebar-section .locale-switcher .btn.btn-outline-secondary,
html[data-theme="dark"] .sidebar .sidebar-section .theme-switcher .btn.btn-outline-secondary {
  --bs-btn-color: var(--text-tertiary);
  --bs-btn-border-color: transparent;
  color: var(--text-tertiary) !important;
  border-color: transparent !important;
}

html[data-theme="light"] .sidebar .sidebar-section .locale-switcher .btn.btn-outline-secondary,
html[data-theme="light"] .sidebar .sidebar-section .theme-switcher .btn.btn-outline-secondary {
  --bs-btn-hover-bg: var(--bg-hover);
  --bs-btn-active-bg: var(--bg-hover);
}

/* Light: track is --bg-elevated — list-row-hover is too close; use --bg-hover for visible lift */
html[data-theme="light"] .sidebar .sidebar-section .locale-switcher .btn.btn-outline-secondary:hover,
html[data-theme="light"] .sidebar .sidebar-section .theme-switcher .btn.btn-outline-secondary:hover,
html[data-theme="light"] .sidebar .sidebar-section .locale-switcher .btn.btn-outline-secondary:focus,
html[data-theme="light"] .sidebar .sidebar-section .theme-switcher .btn.btn-outline-secondary:focus,
html[data-theme="light"] .sidebar .sidebar-section .locale-switcher .btn.btn-outline-secondary:focus-visible,
html[data-theme="light"] .sidebar .sidebar-section .theme-switcher .btn.btn-outline-secondary:focus-visible,
html[data-theme="light"] .sidebar .sidebar-section .locale-switcher .btn.btn-outline-secondary:active,
html[data-theme="light"] .sidebar .sidebar-section .theme-switcher .btn.btn-outline-secondary:active {
  color: var(--text-primary) !important;
  background-color: var(--bg-hover) !important;
  border-color: var(--border-secondary) !important;
}

html[data-theme="dark"] .sidebar .sidebar-section .locale-switcher .btn.btn-outline-secondary:hover,
html[data-theme="dark"] .sidebar .sidebar-section .theme-switcher .btn.btn-outline-secondary:hover,
html[data-theme="dark"] .sidebar .sidebar-section .locale-switcher .btn.btn-outline-secondary:focus,
html[data-theme="dark"] .sidebar .sidebar-section .theme-switcher .btn.btn-outline-secondary:focus,
html[data-theme="dark"] .sidebar .sidebar-section .locale-switcher .btn.btn-outline-secondary:focus-visible,
html[data-theme="dark"] .sidebar .sidebar-section .theme-switcher .btn.btn-outline-secondary:focus-visible,
html[data-theme="dark"] .sidebar .sidebar-section .locale-switcher .btn.btn-outline-secondary:active,
html[data-theme="dark"] .sidebar .sidebar-section .theme-switcher .btn.btn-outline-secondary:active {
  color: var(--text-secondary) !important;
  background-color: rgba(255, 255, 255, 0.07) !important;
  border-color: transparent !important;
}

/*
 * Selected segment: mint fill like .sidebar-link.active (bootstrap_overrides .btn-primary uses
 * !important green — we win with scoped !important here).
 */
.sidebar .sidebar-section .locale-switcher .btn.btn-primary,
.sidebar .sidebar-section .theme-switcher .btn.btn-primary,
.sidebar .sidebar-section .locale-switcher .btn.btn-primary:hover,
.sidebar .sidebar-section .theme-switcher .btn.btn-primary:hover,
.sidebar .sidebar-section .locale-switcher .btn.btn-primary:focus,
.sidebar .sidebar-section .theme-switcher .btn.btn-primary:focus,
.sidebar .sidebar-section .locale-switcher .btn.btn-primary:focus-visible,
.sidebar .sidebar-section .theme-switcher .btn.btn-primary:focus-visible,
.sidebar .sidebar-section .locale-switcher .btn.btn-primary:active,
.sidebar .sidebar-section .theme-switcher .btn.btn-primary:active,
.sidebar .sidebar-section .locale-switcher .btn.btn-primary.active,
.sidebar .sidebar-section .theme-switcher .btn.btn-primary.active {
  --bs-btn-color: var(--accent-primary);
  --bs-btn-bg: var(--list-row-active-bg);
  --bs-btn-border-color: var(--border-secondary);
  --bs-btn-hover-color: var(--accent-primary-hover);
  --bs-btn-hover-bg: var(--list-row-active-bg);
  --bs-btn-hover-border-color: var(--accent-primary);
  --bs-btn-active-color: var(--accent-primary);
  --bs-btn-active-bg: var(--list-row-active-bg);
  --bs-btn-active-border-color: var(--accent-primary);
  --bs-btn-focus-shadow-rgb: var(--accent-primary-rgb);
  color: var(--accent-primary) !important;
  background-color: var(--list-row-active-bg) !important;
  border-color: var(--border-secondary) !important;
  box-shadow: inset 0 0 0 1px var(--border-secondary);
  font-weight: 600;
}

/*
 * Dark: selected must read as the only “on” state — green-tint fill + light mint label (not slate + green text).
 */
html[data-theme="dark"] .sidebar .sidebar-section .locale-switcher .btn.btn-primary,
html[data-theme="dark"] .sidebar .sidebar-section .theme-switcher .btn.btn-primary,
html[data-theme="dark"] .sidebar .sidebar-section .locale-switcher .btn.btn-primary:focus,
html[data-theme="dark"] .sidebar .sidebar-section .theme-switcher .btn.btn-primary:focus,
html[data-theme="dark"] .sidebar .sidebar-section .locale-switcher .btn.btn-primary:focus-visible,
html[data-theme="dark"] .sidebar .sidebar-section .theme-switcher .btn.btn-primary:focus-visible,
html[data-theme="dark"] .sidebar .sidebar-section .locale-switcher .btn.btn-primary:active,
html[data-theme="dark"] .sidebar .sidebar-section .theme-switcher .btn.btn-primary:active,
html[data-theme="dark"] .sidebar .sidebar-section .locale-switcher .btn.btn-primary.active,
html[data-theme="dark"] .sidebar .sidebar-section .theme-switcher .btn.btn-primary.active {
  --bs-btn-color: var(--list-row-link-active-fg);
  --bs-btn-bg: color-mix(in srgb, var(--accent-primary) 38%, var(--bg-surface));
  --bs-btn-border-color: rgba(var(--accent-primary-rgb), 0.42);
  --bs-btn-hover-color: var(--list-row-link-active-fg);
  --bs-btn-hover-bg: color-mix(in srgb, var(--accent-primary) 46%, var(--bg-surface));
  --bs-btn-hover-border-color: var(--accent-primary);
  --bs-btn-active-color: var(--list-row-link-active-fg);
  --bs-btn-active-bg: color-mix(in srgb, var(--accent-primary) 40%, var(--bg-surface));
  --bs-btn-active-border-color: var(--accent-primary);
  color: var(--list-row-link-active-fg) !important;
  background-color: color-mix(in srgb, var(--accent-primary) 38%, var(--bg-surface)) !important;
  border-color: rgba(var(--accent-primary-rgb), 0.42) !important;
  box-shadow:
    inset 0 0 0 1px rgba(var(--accent-primary-rgb), 0.35),
    0 0 0 1px rgba(var(--accent-primary-rgb), 0.18);
  font-weight: 600;
}

html[data-theme="dark"] .sidebar .sidebar-section .locale-switcher .btn.btn-primary:hover,
html[data-theme="dark"] .sidebar .sidebar-section .theme-switcher .btn.btn-primary:hover {
  color: var(--list-row-link-active-fg) !important;
  background-color: color-mix(in srgb, var(--accent-primary) 46%, var(--bg-surface)) !important;
  border-color: var(--accent-primary) !important;
}

.sidebar .sidebar-section .locale-switcher .btn:focus-visible,
.sidebar .sidebar-section .theme-switcher .btn:focus-visible {
  outline: none;
}

.sidebar .sidebar-section .locale-switcher .btn.btn-outline-secondary:focus-visible,
.sidebar .sidebar-section .theme-switcher .btn.btn-outline-secondary:focus-visible {
  box-shadow: 0 0 0 2px rgba(var(--accent-primary-rgb), 0.35) !important;
}

.sidebar .sidebar-section .locale-switcher .btn.btn-primary:focus-visible,
.sidebar .sidebar-section .theme-switcher .btn.btn-primary:focus-visible {
  box-shadow:
    inset 0 0 0 1px var(--border-secondary),
    0 0 0 2px rgba(var(--accent-primary-rgb), 0.35) !important;
}

html[data-theme="dark"] .sidebar .sidebar-section .locale-switcher .btn.btn-primary:focus-visible,
html[data-theme="dark"] .sidebar .sidebar-section .theme-switcher .btn.btn-primary:focus-visible {
  box-shadow:
    inset 0 0 0 1px rgba(var(--accent-primary-rgb), 0.45),
    0 0 0 2px rgba(var(--accent-primary-rgb), 0.35) !important;
}

@supports (padding: max(0px)) {
  .sidebar {
    --sidebar-top-offset: calc(var(--nav-fixed-height) + env(safe-area-inset-top));
  }

  .sidebar-nav {
    padding-bottom: max(80px, 80px + env(safe-area-inset-bottom));
  }
}

/* Standalone PWA: leave room for fixed bottom tab bar */
@media (max-width: 991.98px) {
  .sidebar-nav {
    padding-bottom: max(var(--space-12), env(safe-area-inset-bottom, 0px) + var(--space-4));
  }
}

@media (max-width: 991.98px) and (display-mode: standalone),
(max-width: 991.98px) and (display-mode: minimal-ui) {
  .sidebar-nav {
    padding-bottom: calc(var(--bottom-nav-clearance) + env(safe-area-inset-bottom, 0px) + var(--space-4));
  }
}

@media (min-width: 992px) {
  .sidebar-nav {
    padding-bottom: var(--space-6);
  }
}
