/**
 * Dark/Light Mode Theme Toggle
 */

/* ==================== LIGHT MODE VARIABLES ==================== */

[data-theme="light"] {
  --bg-primary: #f5f7fa;
  --bg-secondary: #ffffff;
  --bg-tertiary: #e8ecf1;
  --accent-primary: #6366f1;
  --accent-secondary: #8b5cf6;
  --accent-success: #10b981;
  --accent-warning: #f59e0b;
  --accent-danger: #ef4444;
  --text-primary: #1e293b;
  --text-secondary: #475569;
  --text-tertiary: #64748b;
  --border-primary: rgba(0, 0, 0, 0.08);
  --border-accent: rgba(99, 102, 241, 0.3);
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.04);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.08);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.08);
}

/* ==================== THEME TOGGLE BUTTON ==================== */

.theme-toggle {
  position: relative;
  width: 60px;
  height: 32px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid var(--border-primary);
  border-radius: 16px;
  cursor: pointer;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  padding: 4px;
}

.theme-toggle:hover {
  background: rgba(255, 255, 255, 0.15);
  border-color: var(--border-accent);
}

.theme-toggle-slider {
  position: absolute;
  width: 24px;
  height: 24px;
  background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
  border-radius: 50%;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
  left: 4px;
}

.theme-toggle-slider i {
  font-size: 0.75rem;
  color: white;
}

/* Light mode - slider moves right */
[data-theme="light"] .theme-toggle-slider {
  left: calc(100% - 28px);
  background: linear-gradient(135deg, #f59e0b, #f97316);
}

/* Icons */
.theme-toggle .icon-moon,
.theme-toggle .icon-sun {
  position: absolute;
  font-size: 0.875rem;
  transition: all 0.3s ease;
  pointer-events: none;
}

.theme-toggle .icon-moon {
  left: 8px;
  color: var(--text-secondary);
}

.theme-toggle .icon-sun {
  right: 8px;
  color: var(--text-secondary);
}

[data-theme="light"] .theme-toggle .icon-moon {
  opacity: 0.5;
}

[data-theme="light"] .theme-toggle .icon-sun {
  opacity: 1;
  color: var(--accent-warning);
}

[data-theme="dark"] .theme-toggle .icon-moon {
  opacity: 1;
  color: var(--accent-primary);
}

[data-theme="dark"] .theme-toggle .icon-sun {
  opacity: 0.5;
}

/* ==================== LIGHT MODE STYLES ==================== */

[data-theme="light"] body {
  background: var(--bg-primary) !important;
  color: var(--text-primary) !important;
}

[data-theme="light"] .card,
[data-theme="light"] .bot-card,
[data-theme="light"] .stat-card {
  background: var(--bg-secondary) !important;
  border-color: var(--border-primary) !important;
  color: var(--text-primary) !important;
}

[data-theme="light"] .dock-navbar {
  background: rgba(255, 255, 255, 0.95) !important;
  border-color: var(--border-primary) !important;
  box-shadow: 
    0 8px 32px rgba(0, 0, 0, 0.08),
    0 0 0 1px rgba(0, 0, 0, 0.05) !important;
}

[data-theme="light"] .dock-links a {
  color: var(--text-secondary) !important;
}

[data-theme="light"] .dock-links a:hover,
[data-theme="light"] .dock-links a.active {
  color: var(--text-primary) !important;
}

[data-theme="light"] input,
[data-theme="light"] select,
[data-theme="light"] textarea {
  background: var(--bg-tertiary) !important;
  border-color: var(--border-primary) !important;
  color: var(--text-primary) !important;
}

[data-theme="light"] input::placeholder,
[data-theme="light"] textarea::placeholder {
  color: var(--text-tertiary) !important;
}

[data-theme="light"] .stat-card::after {
  opacity: 0.1 !important;
}

[data-theme="light"] .bot-card .stat-item {
  background: rgba(99, 102, 241, 0.05);
  border-color: var(--border-primary);
}

[data-theme="light"] table thead {
  background: rgba(99, 102, 241, 0.05);
}

[data-theme="light"] table td {
  border-color: var(--border-primary);
}

[data-theme="light"] table tr:hover {
  background: rgba(99, 102, 241, 0.03);
}

[data-theme="light"] .modal {
  background: rgba(0, 0, 0, 0.5) !important;
}

[data-theme="light"] .modal-content {
  background: var(--bg-secondary) !important;
  border-color: var(--border-primary) !important;
}

[data-theme="light"] .mobile-menubar {
  background: rgba(255, 255, 255, 0.98);
}

[data-theme="light"] ::-webkit-scrollbar-track {
  background: var(--bg-tertiary);
}

[data-theme="light"] ::-webkit-scrollbar-thumb {
  background: rgba(99, 102, 241, 0.3);
}

/* ==================== SMOOTH TRANSITIONS ==================== */

body,
.card,
.bot-card,
.stat-card,
.dock-navbar,
input,
select,
textarea,
.modal-content {
  transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease !important;
}

/* ==================== THEME TOGGLE IN NAVBAR ==================== */

.dock-navbar .theme-toggle {
  margin-left: 8px;
}

/* Mobile: Show theme toggle in navbar */
@media (max-width: 768px) {
  .dock-navbar .theme-toggle {
    display: flex !important;
    width: 52px;
    height: 32px;
    margin-left: 0;
  }
  
  .dock-navbar .theme-toggle-slider {
    width: 24px;
    height: 24px;
  }
  
  /* Hide theme toggle from mobile menu */
  .mobile-menubar .theme-toggle-wrapper,
  .mobile-menubar .theme-toggle {
    display: none !important;
  }
}

/* ==================== PREFERENCE PERSISTENCE ==================== */

/* System preference detection */
@media (prefers-color-scheme: light) {
  :root:not([data-theme]) {
    --bg-primary: #ffffff;
    --bg-secondary: #f8f9fa;
    --text-primary: #1a1a1a;
  }
}

/* ==================== LOADING STATE ==================== */

.theme-toggle.loading {
  pointer-events: none;
  opacity: 0.6;
}

.theme-toggle.loading .theme-toggle-slider {
  animation: pulse 1s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* ==================== ACCESSIBILITY ==================== */

.theme-toggle:focus {
  outline: 2px solid var(--accent-primary);
  outline-offset: 2px;
}

.theme-toggle[aria-pressed="true"] .theme-toggle-slider {
  left: calc(100% - 28px);
}

/* Screen reader only text */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}
