/* ── CSS Variables ───────────────────────────────────────────────────────── */
:root {
  --sidebar-width: 260px;
  --sidebar-collapsed-width: 68px;
  --sidebar-bg: #1a1d2e;
  --topbar-height: 64px;
}

/* ── Base sidebar ────────────────────────────────────────────────────────── */
.sidebar {
  background: var(--sidebar-bg);
  width: var(--sidebar-width);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  padding: 1rem;
  z-index: 1040;
  transition: transform 0.25s ease, width 0.25s ease;
}

/* ── Overlay (mobile only) ───────────────────────────────────────────────── */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 1039;
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}
.sidebar-overlay.active {
  display: block;
}

/* ── Mobile toggle button ────────────────────────────────────────────────── */
/* ── Mobile toggle button ────────────────────────────────────────────────── */
.sidebar-toggle {
  display: none;  /* hidden by default on ALL sizes */
  position: fixed;
  top: 14px;
  left: 14px;
  z-index: 1050;
  width: 40px;
  height: 40px;
  border-radius: 8px;
  padding: 0;
  align-items: center;
  justify-content: center;
  background: var(--sidebar-bg, #1a1d2e);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: #fff;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

/* Only show on mobile */
@media (max-width: 575px) {
  .sidebar-toggle {
    display: flex;
  }
}

/* ── Desktop (≥992px): full sidebar, sticky ──────────────────────────────── */
@media (min-width: 992px) {
  .sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    overflow-x: hidden;
    width: var(--sidebar-width);
  }

  .sidebar-label { display: inline; }
  .sidebar-brand-text { display: inline; }

  .sidebar .nav-link {
    display: flex;
    align-items: center;
    white-space: nowrap;
  }

  .sidebar-toggle { display: none; }
  .sidebar-overlay { display: none !important; }
}

/* ── Tablet (576px–991px): icon-only sticky sidebar ─────────────────────── */
@media (min-width: 576px) and (max-width: 991px) {
  .sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    width: var(--sidebar-collapsed-width);
    overflow: hidden;
    padding: 1rem 0.4rem;
    align-items: center;
  }

  .sidebar-label { display: none; }
  .sidebar-brand-text { display: none; }

  .sidebar-brand {
    justify-content: center;
    margin-bottom: 1.5rem !important;
  }

  .sidebar .nav-link {
    justify-content: center;
    padding: 0.7rem;
    width: 100%;
  }

  .sidebar .nav-link i {
    font-size: 1.25rem;
    margin: 0 !important;
  }

  .sidebar .dropdown-toggle {
    justify-content: center;
  }

  .sidebar .avatar-sm {
    margin: 0;
  }

  .sidebar-toggle { display: none; }
  .sidebar-overlay { display: none !important; }

  /* Tooltip on hover for icon-only mode */
  .sidebar .nav-link {
    position: relative;
  }
}

/* ── Mobile (<576px): off-canvas drawer ──────────────────────────────────── */
@media (max-width: 575px) {
  /* Layout wrapper */
  .app-layout .d-flex {
    display: block !important;
  }

  /* Sidebar is off-canvas, fixed */
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    width: var(--sidebar-width);
    overflow-y: auto;
    transform: translateX(-100%);
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.4);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-label { display: inline; }
  .sidebar-brand-text { display: inline; }

  .sidebar .nav-link {
    display: flex;
    align-items: center;
  }

  /* Toggle button visible */
  .sidebar-toggle {
    display: flex;
  }

  /* Main content takes full width, add top padding for toggle button */
  .main-content {
    width: 100% !important;
    padding-top: calc(var(--topbar-height) + 0px);
  }

  /* Topbar offset for hamburger */
  .topbar {
    padding-left: 64px !important;
  }
}

/* ── Sidebar nav link styles ─────────────────────────────────────────────── */
.sidebar .nav-link {
  color: rgba(255, 255, 255, 0.6);
  border-radius: 8px;
  padding: 0.6rem 0.85rem;
  font-size: 0.875rem;
  transition: background 0.15s ease, color 0.15s ease;
}

.sidebar .nav-link:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.08);
}

.sidebar .nav-link.active {
  color: #fff;
  background: #4361ee;
  font-weight: 600;
}

/* ── Scrollbar ───────────────────────────────────────────────────────────── */
.sidebar::-webkit-scrollbar { width: 3px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }
.sidebar::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.12);
  border-radius: 3px;
}