/* ===================================================
   THEME BACKGROUND SYSTEM
   Dynamic background images based on theme
   Version: 1.0
   =================================================== */

/* ===================================================
   BODY BACKGROUND STYLING
   =================================================== */

/* ===================================================
   BODY BASE STYLING
   =================================================== */

body {
  position: relative;
  min-height: 100vh;
  background-color: transparent !important; /* Override mbaai.css */
  z-index: 0;
}

/* ===================================================
   FIXED BACKGROUND LAYER (Mobile-Optimized)
   Uses pseudo-element for true fixed background
   =================================================== */

body::after {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-size: cover;
  background-position: center center;
  background-repeat: no-repeat;
  transition: background-image 0.5s ease-in-out;
  z-index: -2; /* Behind overlay */
  pointer-events: none;
}

/* Dark Theme Background */
body[data-theme="dark"]::after {
  background-image: url('/assets/dark-bg.webp');
}

/* Light Theme Background */
body[data-theme="light"]::after {
  background-image: url('/assets/light-bg.webp');
}

/* ===================================================
   BACKGROUND OVERLAY (Optional Enhancement)
   Adds subtle overlay for better content readability
   =================================================== */

body::before {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: -1; /* Above background, below content */
  pointer-events: none;
  transition: background-color 0.5s ease-in-out;
}

/* Dark theme overlay - 10% darker */
body[data-theme="dark"]::before {
  background-color: rgba(0, 0, 0, 0.7);
}

/* Light theme overlay - 10% lighter */
body[data-theme="light"]::before {
  background-color: rgba(255, 255, 255, 0.7);
}

/* ===================================================
   SMOOTH THEME TRANSITION
   =================================================== */

html {
  scroll-behavior: smooth;
}

html,
body {
  transition: background-color 0.3s ease-in-out, background-image 0.5s ease-in-out;
}

/* ===================================================
   Z-INDEX HIERARCHY
   Ensure proper stacking order
   =================================================== */

/* Background layer (lowest) */
body::after {
  z-index: -2; /* Background image */
}

body::before {
  z-index: -1; /* Overlay */
}

/* Content layers (above background) - NO z-index to avoid stacking context issues */
.container,
.container-fluid,
.login-container,
.register-container,
.chat-container,
main {
  position: relative;
  /* z-index removed - was blocking sidebar on mobile */
}

/* Main content - NO z-index on mobile to allow sidebar overlay */
.main-content {
  position: relative;
}

@media (min-width: 768px) {
  /* Only set z-index on desktop where sidebar is fixed */
  .main-content {
    z-index: 1;
  }
}

/* Theme toggle button (always on top) */
.theme-toggle-container {
  z-index: 9999 !important; /* Above all app content including chat-page-wrapper */
}

/* Theme toggle - HIDDEN on app pages (moved to sidebar) */
body:not(.login-page):not(.register-page) .theme-toggle-container {
  display: none; /* Theme toggle now in sidebar */
}

/* Theme toggle - Centered position for login/register pages */
body.login-page .theme-toggle-container,
body.register-page .theme-toggle-container {
  position: absolute;
  top: 2rem;
  left: 50%;
  transform: translateX(-50%);
}

/* Modals and overlays (highest) */
.modal,
.modal-backdrop,
.dropdown-menu {
  z-index: 1055;
}

/* ===================================================
   PRINT STYLES
   Remove background for printing
   =================================================== */

@media print {
  body::after,
  body::before {
    display: none !important;
  }
  
  body {
    background-color: white !important;
  }
}

/* ===================================================
   ACCESSIBILITY - REDUCED MOTION
   =================================================== */

@media (prefers-reduced-motion: reduce) {
  body,
  body::before,
  body::after {
    transition: none !important;
  }
}

/* ===================================================
   FALLBACK COLORS
   In case images don't load
   =================================================== */

body[data-theme="dark"]::after {
  background-color: #0a0a0a; /* Dark fallback */
}

body[data-theme="light"]::after {
  background-color: #f5f5f5; /* Light fallback */
}

body[data-theme="light"] {
  background-color: #ffffff;
}

/* ===================================================
   LOADING STATE
   Show placeholder while image loads
   =================================================== */

body.loading-background {
  background-color: var(--mono-50);
}

body[data-theme="dark"].loading-background {
  background-color: #0a0a0a;
}

body[data-theme="light"].loading-background {
  background-color: #f5f5f5;
}

/* ===================================================
   THEME TOGGLE BUTTON STYLING
   Modern toggle switch with liquid glass effect
   =================================================== */

/* Toggle Container */
.theme-toggle-container {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.25rem;
  max-width: 100px; /* Prevent container from being too wide */
  background: linear-gradient(
    135deg,
    rgba(255, 255, 255, 0.15),
    rgba(255, 255, 255, 0.05)
  );
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 50px;
  box-shadow: 
    0 4px 16px rgba(0, 0, 0, 0.2),
    inset 0 1px 0 rgba(255, 255, 255, 0.1);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.theme-toggle-container:hover {
  background: linear-gradient(
    135deg,
    rgba(255, 255, 255, 0.2),
    rgba(255, 255, 255, 0.08)
  );
  border-color: rgba(255, 255, 255, 0.3);
  box-shadow: 
    0 6px 20px rgba(0, 0, 0, 0.25),
    inset 0 1px 0 rgba(255, 255, 255, 0.15);
}

/* Individual Toggle Button - Circle Style */
.theme-toggle-btn {
  position: relative;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 2px solid transparent;
  background: transparent;
  color: rgba(255, 255, 255, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  overflow: hidden;
}

.theme-toggle-btn::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: linear-gradient(
    135deg,
    rgba(255, 255, 255, 0.1),
    rgba(255, 255, 255, 0.05)
  );
  opacity: 0;
  transition: opacity 0.3s ease;
}

.theme-toggle-btn:hover::before {
  opacity: 1;
}

.theme-toggle-btn:hover {
  color: rgba(255, 255, 255, 0.9);
  transform: scale(1.05);
}

.theme-toggle-btn i {
  font-size: 1.1rem;
  position: relative;
  z-index: 1;
}

/* Active State - Glass Filled Circle */
.theme-toggle-btn.active {
  background: linear-gradient(
    135deg,
    rgba(255, 255, 255, 0.3),
    rgba(255, 255, 255, 0.15)
  );
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  border-color: rgba(255, 255, 255, 0.4);
  color: rgba(255, 255, 255, 1);
  box-shadow: 
    0 4px 12px rgba(0, 0, 0, 0.3),
    inset 0 1px 2px rgba(255, 255, 255, 0.3),
    0 0 20px rgba(255, 255, 255, 0.1);
}

.theme-toggle-btn.active::before {
  opacity: 0;
}

/* Ripple Effect on Click */
.theme-toggle-btn::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: radial-gradient(
    circle at center,
    rgba(255, 255, 255, 0.4) 0%,
    rgba(255, 255, 255, 0.2) 40%,
    transparent 70%
  );
  transform: scale(0);
  opacity: 0;
  transition: transform 0.5s cubic-bezier(0.34, 1.56, 0.64, 1), 
              opacity 0.3s ease-out;
}

.theme-toggle-btn:active::after {
  transform: scale(1.5);
  opacity: 1;
  transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1), 
              opacity 0.2s ease-in;
}

/* Light Theme Adjustments */
body[data-theme="light"] .theme-toggle-container {
  background: linear-gradient(
    135deg,
    rgba(0, 0, 0, 0.08),
    rgba(0, 0, 0, 0.04)
  );
  border-color: rgba(0, 0, 0, 0.15);
  box-shadow: 
    0 4px 16px rgba(0, 0, 0, 0.1),
    inset 0 1px 0 rgba(255, 255, 255, 0.5);
}

body[data-theme="light"] .theme-toggle-container:hover {
  background: linear-gradient(
    135deg,
    rgba(0, 0, 0, 0.12),
    rgba(0, 0, 0, 0.06)
  );
  border-color: rgba(0, 0, 0, 0.2);
}

body[data-theme="light"] .theme-toggle-btn {
  color: rgba(0, 0, 0, 0.5);
}

body[data-theme="light"] .theme-toggle-btn::before {
  background: linear-gradient(
    135deg,
    rgba(0, 0, 0, 0.08),
    rgba(0, 0, 0, 0.04)
  );
}

body[data-theme="light"] .theme-toggle-btn:hover {
  color: rgba(0, 0, 0, 0.8);
}

body[data-theme="light"] .theme-toggle-btn.active {
  background: linear-gradient(
    135deg,
    rgba(0, 0, 0, 0.15),
    rgba(0, 0, 0, 0.08)
  );
  border-color: rgba(0, 0, 0, 0.25);
  color: rgba(0, 0, 0, 1);
  box-shadow: 
    0 4px 12px rgba(0, 0, 0, 0.15),
    inset 0 1px 2px rgba(0, 0, 0, 0.1),
    0 0 20px rgba(0, 0, 0, 0.05);
}

body[data-theme="light"] .theme-toggle-btn::after {
  background: rgba(0, 0, 0, 0.2);
}

/* Alternative: Switch Toggle Style */
.theme-switch {
  position: relative;
  width: 60px;
  height: 32px;
  background: linear-gradient(
    135deg,
    rgba(255, 255, 255, 0.1),
    rgba(255, 255, 255, 0.05)
  );
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 50px;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 
    0 2px 8px rgba(0, 0, 0, 0.2),
    inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

.theme-switch:hover {
  background: linear-gradient(
    135deg,
    rgba(255, 255, 255, 0.15),
    rgba(255, 255, 255, 0.08)
  );
  border-color: rgba(255, 255, 255, 0.2);
}

.theme-switch::before {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 24px;
  height: 24px;
  background: linear-gradient(
    135deg,
    rgba(255, 255, 255, 0.9),
    rgba(255, 255, 255, 0.7)
  );
  border-radius: 50%;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 
    0 2px 6px rgba(0, 0, 0, 0.3),
    inset 0 1px 1px rgba(255, 255, 255, 0.5);
}

.theme-switch.active::before {
  left: 31px;
  background: linear-gradient(
    135deg,
    rgba(255, 255, 255, 1),
    rgba(255, 255, 255, 0.8)
  );
  box-shadow: 
    0 2px 8px rgba(0, 0, 0, 0.4),
    inset 0 1px 1px rgba(255, 255, 255, 0.6);
}

/* Icons in Switch */
.theme-switch i {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.75rem;
  transition: opacity 0.3s ease;
  z-index: 0;
}

.theme-switch .bi-sun-fill {
  left: 8px;
  color: rgba(255, 200, 0, 0.8);
}

.theme-switch .bi-moon-fill {
  right: 8px;
  color: rgba(200, 220, 255, 0.8);
}

/* ===================================================
   THEME TOGGLE IN SIDEBAR
   =================================================== */

.theme-toggle-sidebar .theme-toggle-btn {
  padding: 0.75rem 1rem;
  border-radius: 8px;
  font-size: 0.875rem;
  font-weight: 500;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Dark Theme - Active Dark button (Blue highlight) */
body[data-theme="dark"] .theme-toggle-sidebar .theme-toggle-btn[data-theme="dark"].active {
  background: linear-gradient(135deg, rgb(148 152 179 / 44%), rgb(34 84 194 / 45%));
  border-color: rgba(59, 130, 246, 0.5);
  color: #fff;
  box-shadow: 0 4px 12px rgb(0 0 0 / 51%), inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

/* Dark Theme - Active Light button (Gold highlight) */
body[data-theme="dark"] .theme-toggle-sidebar .theme-toggle-btn[data-theme="light"].active {
  background: linear-gradient(
    135deg,
    rgba(251, 191, 36, 0.8),
    rgba(245, 158, 11, 0.9)
  );
  border-color: rgba(251, 191, 36, 0.5);
  color: #fff;
  box-shadow: 
    0 4px 12px rgba(251, 191, 36, 0.4),
    inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

/* Light Theme - Active Light button (Gold highlight) */
body[data-theme="light"] .theme-toggle-sidebar .theme-toggle-btn[data-theme="light"].active {
  background: linear-gradient(135deg, rgb(251 191 36 / 40%), rgb(245 158 11 / 65%));
  border-color: rgb(188 135 0 / 16%);
  color: #fff;
  box-shadow: 0 4px 12px rgba(251, 191, 36, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

/* Light Theme - Active Dark button (Blue highlight) */
body[data-theme="light"] .theme-toggle-sidebar .theme-toggle-btn[data-theme="dark"].active {
  background: linear-gradient(
    135deg,
    rgba(59, 130, 246, 0.8),
    rgba(37, 99, 235, 0.9)
  );
  border-color: rgba(59, 130, 246, 0.5);
  color: #fff;
  box-shadow: 
    0 4px 12px rgba(59, 130, 246, 0.3),
    inset 0 1px 0 rgba(255, 255, 255, 0.2);
}


