/* ========================================
   Theme System
   ======================================== */

/* Light Theme (Default) */
:root {
  --theme-transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease;
}

/* Apply theme transition to all elements */
*,
*::before,
*::after {
  transition: var(--theme-transition);
}

/* Dark Theme Overrides */
[data-theme="dark"] {
  /* Background Colors */
  --bg-primary: #0f172a;
  --bg-secondary: #1e293b;
  --bg-tertiary: #334155;
  --bg-overlay: rgba(0, 0, 0, 0.8);
  
  /* Text Colors */
  --text-primary: #f1f5f9;
  --text-secondary: #cbd5e1;
  --text-muted: #94a3b8;
  --text-inverse: #0f172a;
  
  /* Border Colors */
  --border-color: #334155;
  --border-hover: #475569;
  
  /* Shadows (adjusted for dark theme) */
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.3), 0 2px 4px -1px rgba(0, 0, 0, 0.2);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.3), 0 4px 6px -2px rgba(0, 0, 0, 0.2);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.4), 0 10px 10px -5px rgba(0, 0, 0, 0.2);
}

/* Dark theme specific adjustments */
[data-theme="dark"] .navbar {
  background: rgba(15, 23, 42, 0.8);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

[data-theme="dark"] .hero-section {
  background: linear-gradient(135deg, #1e293b 0%, #334155 100%);
}

[data-theme="dark"] .card:hover {
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.4), 0 4px 6px -2px rgba(0, 0, 0, 0.2);
}

[data-theme="dark"] .form-input,
[data-theme="dark"] .form-select,
[data-theme="dark"] .form-textarea {
  background: var(--bg-tertiary);
}

[data-theme="dark"] .search-input {
  background: var(--bg-tertiary);
}

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

/* ========================================
   Reduced Motion Support
   ======================================== */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
  
  .page {
    animation: none;
  }
  
  .quick-card:hover,
  .nav-link:hover,
  .btn:hover {
    transform: none;
  }
}

/* ========================================
   Color Scheme Preference Detection
   ======================================== */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    /* Auto dark theme when system prefers dark and no theme is set */
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --bg-tertiary: #334155;
    --bg-overlay: rgba(0, 0, 0, 0.8);
    
    --text-primary: #f1f5f9;
    --text-secondary: #cbd5e1;
    --text-muted: #94a3b8;
    --text-inverse: #0f172a;
    
    --border-color: #334155;
    --border-hover: #475569;
    
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.3), 0 2px 4px -1px rgba(0, 0, 0, 0.2);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.3), 0 4px 6px -2px rgba(0, 0, 0, 0.2);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.4), 0 10px 10px -5px rgba(0, 0, 0, 0.2);
  }
}

/* ========================================
   Focus Visible Support (Better Accessibility)
   ======================================== */
.nav-link:focus-visible,
.btn:focus-visible,
.form-input:focus-visible,
.form-select:focus-visible,
.form-textarea:focus-visible,
.search-input:focus-visible {
  outline: 2px solid var(--primary-color);
  outline-offset: 2px;
}

/* Remove default focus styles when focus-visible is supported */
.nav-link:focus:not(:focus-visible),
.btn:focus:not(:focus-visible),
.form-input:focus:not(:focus-visible),
.form-select:focus:not(:focus-visible),
.form-textarea:focus:not(:focus-visible),
.search-input:focus:not(:focus-visible) {
  outline: none;
  box-shadow: none;
}

/* ========================================
   Print Styles
   ======================================== */
@media print {
  .navbar,
  .nav-controls,
  .search-container,
  .hero-actions,
  .btn {
    display: none !important;
  }
  
  .main-content {
    padding-top: 0;
  }
  
  .page {
    display: block !important;
  }
  
  body {
    background: white !important;
    color: black !important;
  }
  
  .card,
  .quick-card {
    border: 1px solid #000 !important;
    box-shadow: none !important;
    break-inside: avoid;
  }
}

/* ========================================
   Custom Theme Variables for Medical Context
   ======================================== */
.medical-theme {
  --primary-color: #059669; /* Medical green */
  --primary-hover: #047857;
  --accent-color: #dc2626; /* Medical red for urgent/important */
  --warning-color: #d97706; /* Amber for warnings */
  --success-color: #059669; /* Green for success */
  --info-color: #0284c7; /* Blue for information */
}

/* Apply medical theme when class is present */
.medical-theme .nav-brand .brand-text {
  background: linear-gradient(135deg, var(--primary-color), var(--accent-color));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* ========================================
   Animation Utilities
   ======================================== */
.fade-in {
  animation: fadeIn 0.3s ease-in-out;
}

.slide-in-up {
  animation: slideInUp 0.3s ease-out;
}

.slide-in-down {
  animation: slideInDown 0.3s ease-out;
}

@keyframes slideInUp {
  from {
    opacity: 0;
    transform: translateY(30px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes slideInDown {
  from {
    opacity: 0;
    transform: translateY(-30px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.pulse {
  animation: pulse 2s infinite;
}

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

/* Loading states */
.loading {
  opacity: 0.6;
  pointer-events: none;
  position: relative;
}

.loading::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 20px;
  height: 20px;
  margin: -10px 0 0 -10px;
  border: 2px solid var(--border-color);
  border-top: 2px solid var(--primary-color);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}