/* Enhanced Automatic Theme System CSS */
/* This CSS provides better auto-detection and smooth transitions */

/* Root variables for theme colors */
:root {
  /* Light mode (default) */
  --bg-primary: #ffffff;
  --bg-secondary: #f8f9fa;
  --bg-card: #ffffff;
  --text-primary: #212529;
  --text-secondary: #6c757d;
  --border-color: #dee2e6;
  --shadow: rgba(0, 0, 0, 0.1);
  
  /* Theme transition */
  --theme-transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease;
}

/* Auto theme - follows system preference */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg-primary: #121212;
    --bg-secondary: #1e1e1e;
    --bg-card: #2d2d2d;
    --text-primary: #ffffff;
    --text-secondary: #b3b3b3;
    --border-color: #404040;
    --shadow: rgba(0, 0, 0, 0.3);
  }
}

/* Explicit dark theme */
[data-theme="dark"] {
  --bg-primary: #121212;
  --bg-secondary: #1e1e1e;
  --bg-card: #2d2d2d;
  --text-primary: #ffffff;
  --text-secondary: #b3b3b3;
  --border-color: #404040;
  --shadow: rgba(0, 0, 0, 0.3);
}

/* Explicit light theme */
[data-theme="light"] {
  --bg-primary: #ffffff;
  --bg-secondary: #f8f9fa;
  --bg-card: #ffffff;
  --text-primary: #212529;
  --text-secondary: #6c757d;
  --border-color: #dee2e6;
  --shadow: rgba(0, 0, 0, 0.1);
}

/* Apply theme variables to common elements */
body {
  background-color: var(--bg-primary);
  color: var(--text-primary);
  transition: var(--theme-transition);
}

/* Cards and containers */
.card, 
.container,
.modal,
.dropdown-menu {
  background-color: var(--bg-card);
  border-color: var(--border-color);
  transition: var(--theme-transition);
}

/* Text elements */
h1, h2, h3, h4, h5, h6 {
  color: var(--text-primary);
  transition: var(--theme-transition);
}

p, span, div {
  color: var(--text-primary);
  transition: var(--theme-transition);
}

.text-muted,
.text-secondary {
  color: var(--text-secondary) !important;
}

/* Input elements */
input, 
textarea, 
select {
  background-color: var(--bg-card);
  color: var(--text-primary);
  border-color: var(--border-color);
  transition: var(--theme-transition);
}

/* Theme toggle button enhancements */
#themeToggle {
  position: relative;
  overflow: hidden;
}

#themeToggle::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(45deg, transparent, rgba(255,255,255,0.1), transparent);
  transform: translateX(-100%);
  transition: transform 0.3s ease;
}

#themeToggle:hover::before {
  transform: translateX(100%);
}

/* Smooth theme switching animation */
* {
  transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease;
}

/* Preserve specific animations */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.fade-in {
  animation: fadeIn 0.3s ease;
}

/* Accessibility improvements */
@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
    animation: none !important;
  }
}

/* High contrast support */
@media (prefers-contrast: high) {
  :root {
    --border-color: #000000;
  }
  
  [data-theme="dark"] {
    --border-color: #ffffff;
  }
}

/* Print styles */
@media print {
  * {
    background-color: white !important;
    color: black !important;
    box-shadow: none !important;
  }
}

/* Loading state for theme */
.theme-loading {
  visibility: hidden;
}

.theme-loaded {
  visibility: visible;
}