/* ── CSS custom properties ────────────────────────────────────────────── */
:root {
  --cs-bg: #0f172a;
  --cs-border: rgba(148, 163, 184, 0.08);
  --cs-shadow: 0px 25px 50px -12px #00000040;
  --cs-accent: #0284c7;
  --cs-accent-hover: #0369a1;
  --cs-accent-glow: rgba(2, 132, 199, 0.18);
  --cs-text: #94a3b8;
  --cs-text-bright: #e2e8f0;
  --cs-text-muted: #475569;
  --cs-icon-size: 20px;
  --cs-width-expanded: 256px;
  --cs-width-collapsed: 60px;
  --cs-transition: 0.28s cubic-bezier(0.4, 0, 0.2, 1);
  --cs-radius: 10px;
  --cs-item-radius: 8px;
  --cs-z: 9999;
}

/* ── Brand wordmark ───────────────────────────────────────────────────── */
.cs-brand {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  padding: 0;
}

.cs-brand__wordmark {
  display: flex;
  align-items: center;
  gap: 0;
  text-decoration: none;
  white-space: nowrap;
  overflow: hidden;
}

.cs-brand__name {
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif !important;
  font-weight: 400;
  font-size: 16px;
  line-height: 24px;
  color: #0f172a;
  padding-bottom: 8px;
  flex-shrink: 0;
}

.cs-brand__divider {
  display: inline-block;
  width: 1px;
  height: 20px;
  background: rgba(15, 23, 42, 0.2);
  margin: 0 12px;
  flex-shrink: 0;
}

.cs-brand__tagline {
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif !important;
  font-weight: 700;
  font-size: 18px;
  line-height: 28px;
  color: #0a0a0a;
  opacity: 1;
  transition:
    opacity var(--cs-transition),
    width var(--cs-transition);
  overflow: hidden;
}

/* Hide tagline + divider when collapsed */
.cs-sidebar--collapsed .cs-brand__tagline,
.cs-sidebar--collapsed .cs-brand__divider {
  opacity: 0;
  width: 0;
  margin: 0;
  pointer-events: none;
}

/* ── Base sidebar shell ───────────────────────────────────────────────── */
.cs-sidebar {
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  width: var(--cs-width-expanded);
  background: var(--cs-bg);
  border-right: 1px solid var(--cs-border);
  box-shadow: var(--cs-shadow);
  display: flex;
  flex-direction: column;
  z-index: var(--cs-z);
  transition: width var(--cs-transition);
  overflow: hidden;
  overflow-y: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
}
.cs-sidebar::-webkit-scrollbar {
  display: none;
}

/* ── FIX 1 & 3: Only push content when sidebar actually exists,
   and NEVER transition on initial load (no fly-in animation).
   The body transition is intentionally removed here — it caused the
   page content to animate/fly-in on every page load.
   Sidebar width transitions on .cs-sidebar itself are sufficient. ──── */
body.cs-expanded {
  padding-left: var(--cs-width-expanded);
}
body.cs-collapsed {
  padding-left: var(--cs-width-collapsed);
}

/* ── FIX 1: On pages where #cs-sidebar doesn't exist, body classes
   must NOT add padding. The .has-cs-sidebar class is only added by JS
   when the sidebar element is found, so scope padding rules to it. ─── */
body:not(.has-cs-sidebar).cs-expanded,
body:not(.has-cs-sidebar).cs-collapsed {
  padding-left: 0 !important;
}

/* ── FIX 3: Remove the body transition entirely to prevent content
   flying in from right on page load. The sidebar itself transitions
   its own width which is all that's needed visually. ─────────────── */
body {
  /* NO transition here — this was causing the fly-in bug */
}

/* Collapsed state */
.cs-sidebar--collapsed {
  width: var(--cs-width-collapsed);
}

/* ── Toggle button ────────────────────────────────────────────────────── */
.cs-toggle {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  width: 100%;
  height: 52px;
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 0 18px;
  transition: background var(--cs-transition);
}
.cs-toggle:hover {
  background: transparent;
}
.cs-toggle:focus {
  background: transparent;
}

/* Hamburger lines */
.cs-toggle__icon {
  display: flex;
  flex-direction: column;
  gap: 4px;
  width: 20px;
}
.cs-toggle__icon span {
  display: block;
  height: 1.5px;
  background: var(--cs-text);
  border-radius: 2px;
  transition:
    transform var(--cs-transition),
    opacity var(--cs-transition),
    width var(--cs-transition);
  transform-origin: left center;
}
.cs-sidebar--expanded .cs-toggle__icon span:nth-child(1) {
  transform: rotate(45deg) translate(1px, -1px);
}
.cs-sidebar--expanded .cs-toggle__icon span:nth-child(2) {
  opacity: 0;
  width: 0;
}
.cs-sidebar--expanded .cs-toggle__icon span:nth-child(3) {
  transform: rotate(-45deg) translate(1px, 1px);
}

/* ── Expanded: hide icons, show text only ─────────────────────────────── */
.cs-sidebar--expanded .cs-nav__icon {
  display: none;
}

.cs-sidebar--expanded .cs-nav__link {
  gap: 0;
}

/* ── Brand / logo area ────────────────────────────────────────────────── */
.cs-brand {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 14px 10px;
  overflow: hidden;
  min-height: 62px;
}
.cs-brand__icon-link {
  flex-shrink: 0;
  display: block;
  line-height: 0;
}
.cs-brand__site-icon {
  width: 32px;
  height: 32px;
  border-radius: 6px;
  object-fit: contain;
}
.cs-brand__text {
  flex: 1;
  overflow: hidden;
  opacity: 1;
  transition:
    opacity var(--cs-transition),
    width var(--cs-transition);
  white-space: nowrap;
}
.cs-sidebar--collapsed .cs-brand__text {
  opacity: 0;
  width: 0;
  pointer-events: none;
}
.cs-brand .site-branding,
.cs-brand .site-title {
  margin: 0;
  padding: 0;
  line-height: 1;
}
.cs-brand .site-title a {
  font-size: 16px;
  font-weight: 700;
  color: var(--cs-text-bright);
  text-decoration: none;
  letter-spacing: 0.02em;
}
.cs-brand .bb-logo {
  max-height: 28px !important;
  width: auto !important;
}

/* ── Navigation wrapper ───────────────────────────────────────────────── */
.cs-nav {
  flex: 1;
  padding: 8px 0;
}
.cs-nav__list {
  list-style: none;
  margin: 0;
  padding: 0 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

/* ── Nav items ────────────────────────────────────────────────────────── */
.cs-nav__item {
  position: relative;
}

/* Shared link styles */
.cs-nav__link {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 9px 10px;
  border-radius: var(--cs-item-radius);
  text-decoration: none;
  color: var(--cs-text);
  font-size: 16px;
  font-weight: 600;
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif !important;
  line-height: 24px;
  background: transparent;
  border: none;
  cursor: pointer;
  transition:
    background var(--cs-transition),
    color var(--cs-transition);
  white-space: nowrap;
  overflow: hidden;
  text-align: left;
}
.cs-nav__link:hover {
  background: rgba(148, 163, 184, 0.08);
  color: var(--cs-text-bright);
}
.cs-nav__link:focus {
  background: rgba(148, 163, 184, 0.08);
  color: var(--cs-text-bright);
}
.cs-nav__link.is-active {
  background: #0284c7;
  color: #ffffff;
}
.cs-nav__link.is-active .cs-nav__icon svg,
.cs-nav__link.is-active .cs-nav__icon {
  color: #ffffff;
}

/* Trigger active: child page is current — same glow, icon inherits accent */
.cs-nav__link--trigger.is-active {
  background: var(--cs-accent-glow);
  color: #ffffff;
}

/* Icon */
.cs-nav__icon {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: var(--cs-icon-size);
  height: var(--cs-icon-size);
  color: inherit;
  transition: color var(--cs-transition);
}
.cs-nav__icon svg {
  width: 100%;
  height: 100%;
  display: block;
}

/* Label */
.cs-nav__label {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  opacity: 1;
  transition: opacity var(--cs-transition);
}

/* Chevron */
.cs-nav__chevron {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 1;
  transition:
    transform var(--cs-transition),
    opacity var(--cs-transition);
}
.cs-nav__link[aria-expanded="true"] .cs-nav__chevron {
  transform: rotate(180deg);
}

/* ── Collapsed state – hide labels & chevrons ─────────────────────────── */
.cs-sidebar--collapsed .cs-nav__label,
.cs-sidebar--collapsed .cs-nav__chevron {
  opacity: 0;
  pointer-events: none;
  width: 0;
  overflow: hidden;
}
/* ── Collapsed: hide text, centre icon perfectly ──────────────────────── */
.cs-sidebar--collapsed .cs-nav__link {
  display: flex !important;
  justify-content: center !important;
  align-items: center !important;
  padding-top: 9px !important;
  padding-bottom: 9px !important;
  padding-left: 12px !important;
  padding-right: 7px !important;
  gap: 0 !important;
  width: 100% !important;
}

.cs-sidebar--collapsed .cs-nav__link.is-active {
  display: flex !important;
  justify-content: center !important;
  align-items: center !important;
  padding-top: 9px !important;
  padding-bottom: 9px !important;
  padding-left: 12px !important;
  padding-right: 7px !important;
  gap: 0 !important;
}

.cs-sidebar--collapsed .cs-nav__icon {
  display: flex;
  flex-shrink: 0;
  width: var(--cs-icon-size);
  height: var(--cs-icon-size);
  margin: 0 auto;
}

/* ── Inline Dropdown (expanded state only) ────────────────────────────── */
.cs-dropdown {
  list-style: none;
  margin: 2px 0 0;
  padding: 0;
  background: transparent;
  border-radius: var(--cs-item-radius);
  overflow: hidden;
  max-height: 0;
  display: block;
  transition: max-height 0.28s cubic-bezier(0.4, 0, 0.2, 1);
}
.cs-dropdown[hidden] {
  display: block !important;
  max-height: 0 !important;
  pointer-events: none;
  border-color: transparent;
}
.cs-dropdown > * {
  overflow: hidden;
}
.cs-dropdown.is-open {
  max-height: 500px;
}

/* Hide inline dropdowns entirely when collapsed (flyout handles it) */
.cs-sidebar--collapsed .cs-dropdown {
  display: none !important;
}

.cs-dropdown__link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px 8px 42px;
  font-size: 16px;
  font-weight: 600;
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif !important;
  color: #94a3b8;
  text-decoration: none;
  transition:
    background var(--cs-transition),
    color var(--cs-transition);
  white-space: nowrap;
}
.cs-dropdown__link:hover {
  background: rgba(148, 163, 184, 0.07);
  color: var(--cs-text-bright);
}
.cs-dropdown__link.is-active {
  color: #ffffff;
  background: #0284c7;
}

/* Subitem icons hidden — text-only subitems */
.cs-dropdown__icon {
  display: none;
}

/* ── Flyout popup (replaces dropdown in collapsed state) ──────────────── */
.cs-flyout {
  position: absolute;
  top: 0;
  left: 0;
  min-width: 190px;
  list-style: none;
  margin: 0;
  padding: 4px;
  background: #1e293b;
  border: 1px solid var(--cs-border);
  border-radius: var(--cs-radius);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  z-index: calc(var(--cs-z) + 10);
  overflow: hidden;
}
.cs-flyout[hidden] {
  display: none;
}

/* Flyout links share dropdown link styles */
.cs-flyout .cs-dropdown__link {
  padding: 9px 16px;
  font-size: 16px;
}

/* Small dot on collapsed trigger indicating it has children */
.cs-sidebar--collapsed .cs-nav__link--trigger::after {
  content: "";
  position: absolute;
  top: 6px;
  right: 6px;
  width: 5px;
  height: 5px;
  background: var(--cs-accent);
  border-radius: 50%;
}

/* ── Tooltip ──────────────────────────────────────────────────────────── */
.cs-sidebar--collapsed .cs-nav__link:not(.cs-nav__link--trigger) {
  position: relative;
}

.cs-tooltip {
  position: fixed;
  padding: 5px 10px;
  background: #1e293b;
  color: var(--cs-text-bright);
  font-size: 12px;
  font-weight: 500;
  border-radius: 6px;
  border: 1px solid var(--cs-border);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  white-space: nowrap;
  pointer-events: none;
  z-index: calc(var(--cs-z) + 20);
  opacity: 0;
  transition: opacity 0.12s ease;
}
.cs-tooltip.is-visible {
  opacity: 1;
}

/* ── Footer ───────────────────────────────────────────────────────────── */
.cs-sidebar__footer {
  flex-shrink: 0;
  padding: 10px 12px;
  border-top: 1px solid var(--cs-border);
}
.cs-sidebar__footer-inner {
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  white-space: nowrap;
}
.cs-sidebar__footer-copy {
  font-size: 10px;
  color: var(--cs-text-muted);
  opacity: 1;
  transition: opacity var(--cs-transition);
}
.cs-sidebar--collapsed .cs-sidebar__footer-copy {
  opacity: 0;
  width: 0;
  pointer-events: none;
}

/* ── Hide BuddyBoss default buddypanel ────────────────────────────────── */
body.has-cs-sidebar .buddypanel:not(#cs-sidebar) {
  display: none !important;
}
body.has-cs-sidebar.bb-buddypanel .site {
  margin-left: 0 !important;
}

/* ── FIX 3: Suppress any BuddyBoss transition on .site that causes fly-in ── */
body.has-cs-sidebar .site {
  transition: none !important;
  animation: none !important;
}

/* ── Accessibility: focus ring ────────────────────────────────────────── */
.cs-nav__link:focus-visible,
.cs-toggle:focus-visible {
  outline: 2px solid var(--cs-accent);
  outline-offset: 2px;
}

/* ── Mobile: sidebar becomes an off-canvas overlay ───────────────────── */
@media (max-width: 799px) {
  .cs-sidebar {
    transform: translateX(-100%);
    transition:
      transform var(--cs-transition),
      width var(--cs-transition);
    width: var(--cs-width-expanded) !important;
  }
  .cs-sidebar.cs-mobile-open {
    transform: translateX(0);
  }

  /* ── FIX 1: No padding on mobile regardless of body class ── */
  body.cs-expanded,
  body.cs-collapsed {
    padding-left: 0 !important;
    margin-left: 0 !important;
  }

  /* Overlay backdrop */
  .cs-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: calc(var(--cs-z) - 1);
  }
  .cs-overlay.is-visible {
    display: block;
  }
}

/* ── Injected mobile trigger button ─────────────────────────────── */
.cs-mobile-trigger {
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 6px;
}
.cs-mobile-trigger__icon {
  display: flex;
  flex-direction: column;
  gap: 5px;
  width: 20px;
}
.cs-mobile-trigger__icon span {
  display: block;
  height: 1.5px;
  background: #000000;
  border-radius: 2px;
}

/* ── FIX 2: Ensure the BB left panel icon wrap is always visible
   on mobile so our injected trigger is shown ─────────────────── */
@media (max-width: 799px) {
  .bb-left-panel-icon-wrap {
    display: flex !important;
    align-items: center;
  }
  /* Hide the default BB hamburger if it exists alongside ours */
  .bb-left-panel-icon-wrap .bb-icon-menu,
  .bb-left-panel-icon-wrap > a:not(.cs-mobile-trigger) {
    display: none !important;
  }
}

/* ── Prevent sidebar flash on page load ───────────────────────────────── */
html.cs-init-collapsed .cs-sidebar,
html.cs-init-expanded .cs-sidebar {
  transition: none !important;
}

/* ── FIX 3: Also suppress body transition during init ────────────────── */
html.cs-init-collapsed body,
html.cs-init-expanded body {
  transition: none !important;
}

@media (min-width: 800px) {
  html.cs-init-collapsed .cs-sidebar {
    width: var(--cs-width-collapsed) !important;
  }
  html.cs-init-expanded .cs-sidebar {
    width: var(--cs-width-expanded) !important;
  }
  html.cs-init-collapsed body {
    padding-left: var(--cs-width-collapsed) !important;
  }
  html.cs-init-expanded body {
    padding-left: var(--cs-width-expanded) !important;
  }
}

/* ── Split Dropdown Trigger Wrapper ─────────────────────────────────────── */
.cs-nav__link-wrapper {
  display: flex;
  align-items: stretch;
  width: 100%;
  border-radius: var(--cs-item-radius);
  transition: background var(--cs-transition);
  position: relative;
}
.cs-nav__link-wrapper:hover {
  background: rgba(148, 163, 184, 0.08);
}
.cs-nav__link-wrapper.is-active {
  background: #0284c7;
}

.cs-nav__link-wrapper .cs-nav__link {
  flex: 1;
  background: transparent !important;
}
.cs-nav__link-wrapper:hover .cs-nav__link {
  color: var(--cs-text-bright);
}
.cs-nav__link-wrapper.is-active .cs-nav__link {
  color: #ffffff;
}

.cs-nav__link-wrapper .cs-nav__link--trigger {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 10px;
  background: transparent;
  border: none;
  color: var(--cs-text);
  cursor: pointer;
}
.cs-nav__link-wrapper:hover .cs-nav__link--trigger {
  color: var(--cs-text-bright);
}
.cs-nav__link-wrapper.is-active .cs-nav__link--trigger {
  color: #ffffff;
}
.cs-nav__link-wrapper .cs-nav__link--trigger:focus-visible {
  outline: 2px solid var(--cs-accent);
  border-radius: 4px;
}
.cs-nav__link-wrapper .cs-nav__link--trigger[aria-expanded="true"] .cs-nav__chevron {
  transform: rotate(180deg);
}

/* Collapsed state handling for split trigger */
.cs-sidebar--collapsed .cs-nav__link-wrapper .cs-nav__link--trigger {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 2;
}
.cs-sidebar--collapsed .cs-nav__link-wrapper .cs-nav__chevron {
  display: none;
}
.cs-sidebar--collapsed .cs-nav__link-wrapper .cs-nav__link {
  position: relative;
  z-index: 1;
}
