/*
 * MGEveryday Sidebar Component — v1.0
 * Companion to mge-brand.css — requires brand tokens to be loaded first.
 *
 * Two states: expanded (220px) ↔ icons-only (56px).
 * Mobile (<992px): offcanvas sheet, always expanded.
 */

/* ============================================
   Sidebar variables
   ============================================ */
:root {
  --sidebar-width: 220px;
  --sidebar-collapsed: 56px;
}

/* ============================================
   Sidebar — core container
   ============================================ */
.mge-sidebar {
  width: var(--sidebar-width);
  height: calc(100vh - var(--navbar-h));
  overflow-y: auto;
  overflow-x: hidden;
  transition: width 200ms ease;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  scrollbar-width: thin;
  border-right: 1px solid var(--bs-border-color);
}

/* ── Icons-only state ── */
.mge-sidebar.icons-only {
  width: var(--sidebar-collapsed);
}

/* ============================================
   Section label
   ============================================ */
.mge-sidebar .sidebar-label {
  font-family: var(--mge-font-mono);
  font-size: .58rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--bs-secondary-color);
  padding: .65rem .85rem .2rem;
  white-space: nowrap;
  overflow: hidden;
  transition: opacity 200ms;
}
.mge-sidebar.icons-only .sidebar-label {
  opacity: 0;
  height: 0;
  padding: 0;
  margin: 0;
  overflow: hidden;
}

/* ============================================
   Nav link
   ============================================ */
.mge-sidebar .sidebar-link {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .38rem .85rem;
  font-size: .8rem;
  font-weight: 500;
  color: var(--bs-body-color);
  text-decoration: none;
  border-radius: 6px;
  margin: 1px 6px;
  white-space: nowrap;
  transition: background 100ms, color 100ms;
  position: relative;
}
.mge-sidebar .sidebar-link:hover {
  background: var(--bs-tertiary-bg);
  color: var(--bs-emphasis-color);
  text-decoration: none;
}
.mge-sidebar .sidebar-link.active {
  background: color-mix(in srgb, var(--mge-primary) 12%, transparent);
  color: var(--mge-primary);
  font-weight: 600;
}
.mge-sidebar .sidebar-link.active::before {
  content: '';
  position: absolute;
  left: -6px; top: 4px; bottom: 4px;
  width: 3px;
  border-radius: 2px;
  background: var(--mge-primary);
}
.mge-sidebar .sidebar-link i.sidebar-icon {
  font-size: .95rem;
  width: 20px;
  text-align: center;
  flex-shrink: 0;
}
.mge-sidebar .sidebar-link .link-text {
  overflow: hidden;
  transition: opacity 150ms, width 200ms;
}
.mge-sidebar .sidebar-link .badge {
  font-size: .55rem;
  margin-left: auto;
}

/* ── Icons-only: hide text ── */
.mge-sidebar.icons-only .sidebar-link {
  justify-content: center;
  padding: .45rem;
  margin: 1px 4px;
  gap: 0;
}
.mge-sidebar.icons-only .sidebar-link .link-text,
.mge-sidebar.icons-only .sidebar-link .badge,
.mge-sidebar.icons-only .sidebar-link .chevron {
  width: 0; opacity: 0; overflow: hidden; position: absolute;
}

/* ============================================
   Category toggle
   ============================================ */
.mge-sidebar .sidebar-cat {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .38rem .85rem;
  font-size: .8rem;
  font-weight: 600;
  color: var(--bs-body-color);
  background: none;
  border: none;
  border-radius: 6px;
  margin: 1px 6px;
  white-space: nowrap;
  cursor: pointer;
  width: calc(100% - 12px);
  text-align: left;
  transition: background 100ms;
}
.mge-sidebar .sidebar-cat:hover {
  background: var(--bs-tertiary-bg);
}
.mge-sidebar .sidebar-cat.active {
  color: var(--mge-primary);
}
.mge-sidebar .sidebar-cat.active i.sidebar-icon {
  color: var(--mge-primary);
}
.mge-sidebar .sidebar-cat i.sidebar-icon {
  font-size: .95rem;
  width: 20px;
  text-align: center;
  flex-shrink: 0;
}
.mge-sidebar .sidebar-cat .chevron {
  margin-left: auto;
  font-size: .55rem;
  transition: transform 200ms;
  color: var(--bs-secondary-color);
}
.mge-sidebar .sidebar-cat[aria-expanded="true"] .chevron {
  transform: rotate(90deg);
}
.mge-sidebar.icons-only .sidebar-cat {
  justify-content: center;
  padding: .45rem;
  margin: 1px 4px;
  gap: 0;
}
.mge-sidebar.icons-only .sidebar-cat .link-text,
.mge-sidebar.icons-only .sidebar-cat .chevron {
  width: 0; opacity: 0; overflow: hidden; position: absolute;
}

/* ============================================
   Sub-items (inside category)
   ============================================ */
.mge-sidebar .sidebar-sub {
  padding-left: .6rem;
}
.mge-sidebar.icons-only .sidebar-sub {
  display: none !important;
}
.mge-sidebar .sidebar-sub .sidebar-link {
  font-size: .76rem;
  padding: .28rem .75rem;
  font-weight: 400;
  gap: .5rem;
}
.mge-sidebar .sidebar-sub .sidebar-link i.sidebar-icon {
  font-size: .85rem;
}

/* ============================================
   Module sub-items (Phase 5 — nested within categories)
   ============================================ */
.sidebar-sub .sidebar-sub-link {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.3rem 0.75rem 0.3rem 2.25rem;
  font-size: 0.8125rem;
  color: var(--bs-body-color);
  text-decoration: none;
  border-radius: var(--bs-border-radius);
  white-space: nowrap;
  overflow: hidden;
  transition: background-color 0.15s;
}
.sidebar-sub .sidebar-sub-link:hover {
  background-color: var(--bs-tertiary-bg);
}
.sidebar-sub .sidebar-sub-link.active {
  background-color: color-mix(in srgb, var(--mge-primary) 12%, transparent);
  color: var(--mge-primary);
  font-weight: 600;
}
[data-bs-theme="dark"] .sidebar-sub .sidebar-sub-link:hover {
  background-color: rgba(255,255,255,.08);
}
.sidebar-sub .sidebar-sub-link .bi {
  font-size: 0.875rem;
  flex-shrink: 0;
}
.sidebar-sub-divider {
  border-top: 1px solid var(--bs-border-color);
  margin: 0.25rem 1.5rem;
}

/* ============================================
   Spacer & bottom section
   ============================================ */
.sidebar-spacer {
  flex: 1;
}
.sidebar-bottom {
  border-top: 1px solid var(--bs-border-color);
  padding-top: .35rem;
  margin-top: .35rem;
}

/* ============================================
   Collapse handle (thin bar between sidebar & content)
   ============================================ */
.sidebar-handle {
  width: 14px;
  flex-shrink: 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-left: 1px solid var(--bs-border-color);
  transition: background 120ms;
  -webkit-user-select: none;
  user-select: none;
}
.sidebar-handle:hover {
  background: var(--bs-tertiary-bg);
}
.sidebar-handle i {
  font-size: .55rem;
  color: var(--bs-secondary-color);
  transition: transform 200ms;
}
.sidebar-handle.is-collapsed i {
  transform: rotate(180deg);
}

/* ============================================
   Admin view toggle
   ============================================ */
.admin-view-toggle {
  font-size: var(--sidebar-font);
  padding: var(--sidebar-link-py) var(--sidebar-link-px);
  color: var(--bs-body-color);
}
.admin-view-toggle:hover {
  background: var(--bs-tertiary-bg);
}
.mge-sidebar.icons-only .admin-view-toggle .link-text {
  display: none;
}

/* ============================================
   B2B shop selector
   ============================================ */
.sidebar-shop-selector {
  padding-top: .25rem;
}
.sidebar-shop-selector .sidebar-link {
  font-weight: 600;
}
.mge-sidebar.icons-only .sidebar-shop-selector .link-text { display: none; }
.mge-sidebar.icons-only .sidebar-shop-selector #shopSelectorList { display: none; }

/* ============================================
   Offcanvas mobile overrides
   ============================================ */
.offcanvas .mge-sidebar {
  width: 100% !important;
  height: auto;
  border-right: none;
}
