/* ============================================
   SIDEBAR NAVIGATION - FB Developer Style
   ============================================ */

/* --- Layout variables --- */
:root {
  --sidebar-width: 220px;
  --sidebar-bg: #1b1f27;
  --sidebar-border: #2d3343;
  --sidebar-text: #9ba3b5;
  --sidebar-text-hover: #e1e4ea;
  --sidebar-text-active: #ffffff;
  --sidebar-active-bg: rgba(99, 102, 241, 0.15);
  --sidebar-active-accent: #818cf8;
  --sidebar-hover-bg: rgba(255, 255, 255, 0.06);
  --sidebar-section-label: #5c6478;
  --sidebar-transition: 0.2s ease;
}

/* --- Hide legacy top header --- */
header:not(.sidebar-topbar),
.unified-header,
.nav-container {
  display: none !important;
}

/* ============================================
   SIDEBAR SHELL
   ============================================ */
.app-sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--sidebar-width);
  height: 100vh;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--sidebar-border);
  display: flex;
  flex-direction: column;
  z-index: 900;
  overflow: hidden;
  transition: width var(--sidebar-transition);
}

/* ============================================
   BRAND / LOGO
   ============================================ */
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1.25rem 1.25rem 1rem;
  cursor: pointer;
  flex-shrink: 0;
  transition: opacity 0.2s;
}

.sidebar-brand:hover {
  opacity: 0.85;
}

/* Style the captured logo from the old header inside the sidebar */
.sidebar-brand .logo-placeholder {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, #6366f1, #818cf8);
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ffffff;
  flex-shrink: 0;
}

.sidebar-brand .logo-placeholder img {
  max-width: 100%;
  max-height: 100%;
  border-radius: 8px;
}

.sidebar-brand-icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, #6366f1, #818cf8);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ffffff;
  flex-shrink: 0;
}

.sidebar-brand-icon svg {
  width: 20px;
  height: 20px;
}

.sidebar-brand-name {
  font-size: 1.125rem;
  font-weight: 700;
  color: #ffffff;
  letter-spacing: -0.02em;
  white-space: nowrap;
  overflow: hidden;
}

/* ============================================
   SCROLLABLE NAV AREA
   ============================================ */
.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0.5rem 0;
  scrollbar-width: thin;
  scrollbar-color: var(--sidebar-border) transparent;
}

.sidebar-nav::-webkit-scrollbar {
  width: 4px;
}

.sidebar-nav::-webkit-scrollbar-track {
  background: transparent;
}

.sidebar-nav::-webkit-scrollbar-thumb {
  background: var(--sidebar-border);
  border-radius: 4px;
}

/* ============================================
   SECTION GROUPS
   ============================================ */
.sidebar-section {
  margin-bottom: 0.25rem;
}

.sidebar-section-label {
  padding: 0.75rem 1.25rem 0.375rem;
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--sidebar-section-label);
  white-space: nowrap;
  overflow: hidden;
}

/* ============================================
   NAV ITEMS
   ============================================ */
.sidebar-nav-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5625rem 1.25rem;
  margin: 1px 0.5rem;
  border-radius: 8px;
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 0.875rem;
  font-weight: 500;
  transition: background var(--sidebar-transition),
              color var(--sidebar-transition);
  position: relative;
  cursor: pointer;
}

.sidebar-nav-item:hover {
  background: var(--sidebar-hover-bg);
  color: var(--sidebar-text-hover);
}

.sidebar-nav-item.active {
  background: var(--sidebar-active-bg);
  color: var(--sidebar-text-active);
}

.sidebar-nav-item.active::before {
  content: '';
  position: absolute;
  left: -0.5rem;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 60%;
  border-radius: 0 3px 3px 0;
  background: var(--sidebar-active-accent);
}

.sidebar-nav-item-icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.7;
}

.sidebar-nav-item.active .sidebar-nav-item-icon {
  opacity: 1;
}

.sidebar-nav-item-icon svg {
  width: 18px;
  height: 18px;
}

.sidebar-nav-item-label {
  flex: 1;
  line-height: 1.3;
}

/* Badge (e.g. pending appointment count) */
.sidebar-nav-badge {
  background: #ef4444;
  color: #ffffff;
  font-size: 0.6875rem;
  font-weight: 600;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

/* Status dot (e.g. diagnostic health indicator) */
.sidebar-nav-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  background: #cbd5e1;
}
.sidebar-nav-status-dot.pass {
  background: #10b981;
}
.sidebar-nav-status-dot.warning {
  background: #f59e0b;
}
.sidebar-nav-status-dot.fail {
  background: #ef4444;
  animation: diagNavPulse 2s infinite;
}
@keyframes diagNavPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* ============================================
   DIVIDER
   ============================================ */
.sidebar-divider {
  height: 1px;
  background: var(--sidebar-border);
  margin: 0.5rem 1.25rem;
}

/* ============================================
   THEME TOGGLE (above user section)
   ============================================ */
.sidebar-theme-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem 1.25rem;
  cursor: pointer;
  color: var(--sidebar-text);
  opacity: 0.5;
  transition: opacity 0.2s ease, color var(--sidebar-transition);
}

.sidebar-theme-toggle:hover {
  opacity: 1;
}

.sidebar-theme-icon {
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ============================================
   USER SECTION (pinned to bottom)
   ============================================ */
.sidebar-user {
  flex-shrink: 0;
  border-top: 1px solid var(--sidebar-border);
  padding: 0.75rem;
  position: relative;
}

.sidebar-user-trigger {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem;
  border-radius: 8px;
  cursor: pointer;
  transition: background var(--sidebar-transition);
  width: 100%;
  background: none;
  border: none;
  text-align: left;
  color: inherit;
  font-family: inherit;
}

.sidebar-user-trigger:hover {
  background: var(--sidebar-hover-bg);
}

.sidebar-user-avatar {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: linear-gradient(135deg, #6366f1, #818cf8);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ffffff;
  font-weight: 700;
  font-size: 0.8125rem;
  flex-shrink: 0;
}

.sidebar-user-info {
  flex: 1;
  overflow: hidden;
}

.sidebar-user-name {
  font-size: 0.8125rem;
  font-weight: 600;
  color: #e1e4ea;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-user-plan {
  font-size: 0.6875rem;
  color: var(--sidebar-section-label);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-user-chevron {
  color: var(--sidebar-section-label);
  flex-shrink: 0;
  transition: transform 0.2s;
}

.sidebar-user-trigger[aria-expanded="true"] .sidebar-user-chevron {
  transform: rotate(180deg);
}

/* ============================================
   USER DROPDOWN (pops up above user area)
   ============================================ */
.sidebar-user-dropdown {
  position: absolute;
  bottom: calc(100% + 0.375rem);
  left: 0.75rem;
  right: 0.75rem;
  background: #252a35;
  border: 1px solid var(--sidebar-border);
  border-radius: 10px;
  box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.35);
  z-index: 910;
  opacity: 0;
  visibility: hidden;
  transform: translateY(6px);
  transition: opacity 0.15s, visibility 0.15s, transform 0.15s;
  overflow: hidden;
}

.sidebar-user-dropdown.show {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.sidebar-dropdown-item {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 0.625rem 0.875rem;
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 0.8125rem;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
  cursor: pointer;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  font-family: inherit;
}

.sidebar-dropdown-item:hover {
  background: var(--sidebar-hover-bg);
  color: var(--sidebar-text-hover);
}

.sidebar-dropdown-item.danger {
  color: #f87171;
}

.sidebar-dropdown-item.danger:hover {
  background: rgba(239, 68, 68, 0.1);
  color: #f87171;
}

.sidebar-dropdown-divider {
  height: 1px;
  background: var(--sidebar-border);
  margin: 0.25rem 0;
}

.sidebar-dropdown-item svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  opacity: 0.7;
}

/* ============================================
   BODY LAYOUT - push content right
   ============================================ */
body.has-sidebar {
  padding-left: var(--sidebar-width);
  transition: padding-left var(--sidebar-transition);
}

/* flex:1 on main/.profile-page in modern-styles.css handles sticky footer */

/* ============================================
   MOBILE TOP BAR
   ============================================ */
.sidebar-topbar {
  display: none;
  position: sticky;
  top: 0;
  left: 0;
  right: 0;
  height: 56px;
  background: var(--sidebar-bg);
  border-bottom: 1px solid var(--sidebar-border);
  z-index: 899;
  align-items: center;
  justify-content: space-between;
  padding: 0 1rem;
}

.sidebar-topbar-brand {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  cursor: pointer;
}

/* Style the captured logo inside mobile topbar */
.sidebar-topbar-brand .logo-placeholder {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: linear-gradient(135deg, #6366f1, #818cf8);
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
}

.sidebar-topbar-brand .logo-placeholder img {
  max-width: 100%;
  max-height: 100%;
  border-radius: 6px;
}

.sidebar-topbar-brand-icon {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: linear-gradient(135deg, #6366f1, #818cf8);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
}

.sidebar-topbar-brand-icon svg {
  width: 18px;
  height: 18px;
}

.sidebar-topbar-brand-name {
  font-size: 1rem;
  font-weight: 700;
  color: #fff;
  letter-spacing: -0.02em;
}

.sidebar-topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* Hamburger button */
.sidebar-mobile-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  background: rgba(255, 255, 255, 0.08);
  border: none;
  border-radius: 8px;
  cursor: pointer;
  color: var(--sidebar-text);
  transition: background 0.15s, color 0.15s;
}

.sidebar-mobile-toggle:hover {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
}

/* Mobile mini-avatar in topbar */
.sidebar-topbar-avatar {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: linear-gradient(135deg, #6366f1, #818cf8);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 700;
  font-size: 0.75rem;
  cursor: pointer;
}

/* ============================================
   MOBILE OVERLAY & DRAWER
   ============================================ */
.sidebar-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 949;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s, visibility 0.25s;
}

.sidebar-overlay.show {
  opacity: 1;
  visibility: visible;
}

/* Mobile: sidebar becomes a drawer */
@media (max-width: 768px) {
  .app-sidebar {
    transform: translateX(-100%);
    z-index: 950;
    box-shadow: none;
    transition: transform 0.25s ease;
  }

  .app-sidebar.mobile-open {
    transform: translateX(0);
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.3);
  }

  .sidebar-topbar {
    display: flex;
  }

  .sidebar-mobile-toggle {
    display: flex;
  }

  body.has-sidebar {
    padding-left: 0;
  }

  .sidebar-mobile-close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    background: none;
    border: none;
    color: var(--sidebar-text);
    font-size: 1.25rem;
    cursor: pointer;
    border-radius: 6px;
    transition: background 0.15s;
    margin-left: auto;
    flex-shrink: 0;
  }

  .sidebar-mobile-close:hover {
    background: var(--sidebar-hover-bg);
    color: #fff;
  }
}

/* Desktop: hide mobile-only elements */
@media (min-width: 769px) {
  .sidebar-topbar {
    display: none !important;
  }

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

  .sidebar-mobile-close {
    display: none !important;
  }

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

/* ============================================
   LEGACY COMPAT - keep old IDs silent
   ============================================ */
#nav-menu,
#header-actions,
.main-navigation {
  display: none !important;
}

.mobile-nav-overlay {
  display: none !important;
}

/* ============================================
   RESPONSIVE TWEAKS
   ============================================ */
@media (max-width: 1024px) and (min-width: 769px) {
  :root {
    --sidebar-width: 200px;
  }
}

/* Z-index stacking: modals & toasts above sidebar */
.dialog-system-container,
.toast-container {
  z-index: 9999;
}

.modal {
  z-index: 1000;
}

/* Onboarding pulse ring on sidebar nav items */
@keyframes onboardingPulseRing {
  0% { transform: scale(1); opacity: 0.6; }
  70% { transform: scale(1.6); opacity: 0; }
  100% { transform: scale(1.6); opacity: 0; }
}

.sidebar-nav-item.onboarding-pulse {
  position: relative;
}

.sidebar-nav-item.onboarding-pulse::after {
  content: '';
  position: absolute;
  left: 1.25rem;
  top: 50%;
  width: 28px;
  height: 28px;
  margin-left: -4px;
  margin-top: -14px;
  border-radius: 50%;
  border: 2px solid #22c55e;
  animation: onboardingPulseRing 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
  pointer-events: none;
  z-index: 1;
}