/**
 * THEME TOGGLE STYLES
 * Dark/Light Mode Toggle Button & Theme Variables
 */

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

[data-theme="light"] {
  /* Base Colors - MAXIMUM CONTRAST */
  --black-carbon: #000000;
  --beige-warm: #f8f8f8;
  --beige-muted: #e5e5e5;
  --copper-warm: #8b4513;
  --gold-soft: #b8860b;

  /* Background - Pure white for maximum contrast */
  --bg-base: #ffffff;
  --bg-elevated: #fafafa;
  --bg-overlay: rgba(255, 255, 255, 0.98);

  /* Text - High contrast colors for readability */
  --text-primary: #000000;
  --text-secondary: #333333;
  --text-muted: #555555;
  --text-inverse: #ffffff;

  /* Borders - More visible */
  --border-subtle: rgba(0, 0, 0, 0.12);
  --border-medium: rgba(0, 0, 0, 0.25);
  --border-strong: rgba(0, 0, 0, 0.4);

  /* Shadows - Stronger for better depth */
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.18);
  --shadow-md: 0 4px 8px rgba(0, 0, 0, 0.15);
  --shadow-lg: 0 10px 24px rgba(0, 0, 0, 0.2);
  --shadow-xl: 0 20px 48px rgba(0, 0, 0, 0.25);

  /* Brand Colors - Darker for better contrast on white */
  --copper-warm: #a0522d;
  --gold-soft: #b8860b;
  --sage-green: #556b2f;
  --cream-light: #f5f1ea;

  /* Status Colors */
  --success-base: #16a34a;
  --success-light: #dcfce7;
  --success-dark: #166534;

  --error-base: #dc2626;
  --error-light: #fee2e2;
  --error-dark: #991b1b;

  --warning-base: #ea580c;
  --warning-light: #ffedd5;
  --warning-dark: #9a3412;

  --info-base: #0284c7;
  --info-light: #e0f2fe;
  --info-dark: #075985;

  /* Hero Overlay - Light but maintains text readability */
  --hero-overlay: linear-gradient(
    135deg,
    rgba(255, 255, 255, 0.85) 0%,
    rgba(250, 250, 250, 0.9) 100%
  );

  /* Testimonial Background */
  --testimonial-bg: rgba(255, 255, 255, 0.9);

  /* Newsletter Background */
  --newsletter-gradient: linear-gradient(
    135deg,
    rgba(160, 82, 45, 0.08) 0%,
    rgba(184, 134, 11, 0.08) 100%
  );
}

/* ============================================
   DARK MODE VARIABLES (explicit for consistency)
   ============================================ */

[data-theme="dark"] {
  /* Text - High contrast on dark background */
  --text-primary: #fafafa;
  --text-secondary: #e0e0e0;
  --text-muted: #b0b0b0;
  --text-inverse: #000000;

  /* Background */
  --bg-base: #0a0908;
  --bg-elevated: #1a1715;
  --bg-overlay: rgba(10, 9, 8, 0.95);

  /* Borders */
  --border-subtle: rgba(255, 255, 255, 0.08);
  --border-medium: rgba(255, 255, 255, 0.15);
  --border-strong: rgba(255, 255, 255, 0.25);
}

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

.theme-toggle {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  margin: 0 var(--space-xs);
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: all var(--duration-fast) var(--ease-out);
  color: var(--text-primary);
  overflow: hidden;
}

.theme-toggle:hover {
  background: var(--bg-base);
  border-color: var(--border-medium);
  transform: scale(1.05);
}

.theme-toggle:focus {
  outline: 3px solid var(--copper-warm);
  outline-offset: 2px;
}

.theme-toggle:active {
  transform: scale(0.95);
}

/* Theme Icons */
.theme-icon {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 20px;
  height: 20px;
  opacity: 0;
  transition: opacity var(--duration-base) var(--ease-out),
              transform var(--duration-base) var(--ease-out);
}

/* Show sun icon in dark mode */
.theme-toggle--dark .theme-icon--light {
  opacity: 1;
  transform: translate(-50%, -50%) rotate(0deg);
}

.theme-toggle--dark .theme-icon--dark {
  opacity: 0;
  transform: translate(-50%, -50%) rotate(180deg);
}

/* Show moon icon in light mode */
.theme-toggle--light .theme-icon--light {
  opacity: 0;
  transform: translate(-50%, -50%) rotate(-180deg);
}

.theme-toggle--light .theme-icon--dark {
  opacity: 1;
  transform: translate(-50%, -50%) rotate(0deg);
}

/* Smooth theme transitions */
:root {
  --theme-transition-duration: 300ms;
}

html.theme-transitioning * {
  transition: background-color var(--theme-transition-duration) var(--ease-out),
              border-color var(--theme-transition-duration) var(--ease-out),
              color var(--theme-transition-duration) var(--ease-out) !important;
}

/* Prevent transition on first load */
html:not(.theme-loaded) * {
  transition: none !important;
}

/* Mark as loaded after first paint */
@keyframes theme-loaded {
  to {
    opacity: 1;
  }
}

html {
  animation: theme-loaded 1ms;
  animation-fill-mode: forwards;
}

html.theme-loaded {
  /* Theme transitions enabled */
}

/* ============================================
   LIGHT MODE SPECIFIC ADJUSTMENTS
   ============================================ */

[data-theme="light"] .hero-overlay {
  background: var(--hero-overlay);
}

[data-theme="light"] .hero h1,
[data-theme="light"] .hero h2,
[data-theme="light"] .hero p {
  color: #000000;
  text-shadow: 0 1px 3px rgba(255, 255, 255, 0.8);
}

[data-theme="light"] .hero .subtitle {
  color: #333333;
}

[data-theme="light"] .card {
  box-shadow: var(--shadow-md);
}

[data-theme="light"] .btn-hero.primary {
  background: #8b4513;
  color: #ffffff;
  box-shadow: 0 4px 16px rgba(139, 69, 19, 0.3);
}

[data-theme="light"] .btn-hero.primary:hover {
  background: #a0522d;
  box-shadow: 0 6px 20px rgba(160, 82, 45, 0.4);
}

[data-theme="light"] .btn-hero.secondary {
  background: transparent;
  color: #000000;
  border: 2px solid #000000;
}

[data-theme="light"] .btn-hero.secondary:hover {
  background: #000000;
  color: #ffffff;
}

[data-theme="light"] .testimonial-card {
  background: var(--testimonial-bg);
  backdrop-filter: blur(10px);
  box-shadow: var(--shadow-md);
}

[data-theme="light"] .newsletter {
  background: var(--newsletter-gradient);
}

/* Additional contrast improvements for common elements */
[data-theme="light"] .btn {
  color: #000000;
  border-color: rgba(0, 0, 0, 0.3);
}

[data-theme="light"] .btn.primary {
  background: #8b4513;
  color: #ffffff;
  border-color: #8b4513;
}

[data-theme="light"] .btn.primary:hover {
  background: #a0522d;
  border-color: #a0522d;
}

[data-theme="light"] .muted {
  color: #555555;
}

[data-theme="light"] h1,
[data-theme="light"] h2,
[data-theme="light"] h3,
[data-theme="light"] h4,
[data-theme="light"] h5,
[data-theme="light"] h6 {
  color: #000000;
}

[data-theme="light"] p {
  color: #000000;
}

[data-theme="light"] a {
  color: #0066cc;
}

[data-theme="light"] a:hover {
  color: #004499;
}

[data-theme="light"] .card {
  background: #ffffff;
  color: #000000;
  border: 1px solid rgba(0, 0, 0, 0.1);
}

[data-theme="light"] .small {
  color: #333333;
}

[data-theme="light"] .badge {
  background: rgba(139, 69, 19, 0.1);
  color: #000000;
  border: 1px solid rgba(139, 69, 19, 0.2);
}

[data-theme="light"] .footer {
  background: linear-gradient(
    180deg,
    rgba(255, 255, 255, 0.98) 0%,
    rgba(250, 250, 250, 1) 100%
  );
  border-top: 2px solid var(--border-medium);
}

[data-theme="light"] code {
  background: rgba(0, 0, 0, 0.05);
  color: #c7254e;
}

[data-theme="light"] pre {
  background: rgba(0, 0, 0, 0.03);
  border: 1px solid var(--border-subtle);
}

/* Light mode scrollbar */
[data-theme="light"]::-webkit-scrollbar-track {
  background: #f1f1f1;
}

[data-theme="light"]::-webkit-scrollbar-thumb {
  background: #c0c0c0;
}

[data-theme="light"]::-webkit-scrollbar-thumb:hover {
  background: #a0a0a0;
}

/* ============================================
   RESPONSIVE ADJUSTMENTS
   ============================================ */

@media (max-width: 768px) {
  .theme-toggle {
    width: 40px;
    height: 40px;
    margin: 0 var(--space-xxs);
  }

  .theme-icon {
    width: 18px;
    height: 18px;
  }
}

/* ============================================
   REDUCED MOTION
   ============================================ */

@media (prefers-reduced-motion: reduce) {
  .theme-toggle,
  .theme-icon {
    transition: none !important;
  }

  html.theme-transitioning * {
    transition: none !important;
  }
}

/* ============================================
   PRINT STYLES
   ============================================ */

@media print {
  .theme-toggle {
    display: none !important;
  }

  /* Force light theme for printing */
  :root {
    --bg-base: #ffffff;
    --text-primary: #000000;
    --text-secondary: #333333;
  }
}

/* ============================================
   HIGH CONTRAST MODE
   ============================================ */

@media (prefers-contrast: high) {
  .theme-toggle {
    border-width: 2px;
  }

  [data-theme="light"] {
    --text-primary: #000000;
    --text-secondary: #333333;
    --bg-base: #ffffff;
    --border-medium: rgba(0, 0, 0, 0.5);
  }
}

/* ============================================
   THEME TOGGLE POSITIONING
   ============================================ */

/* Position toggle button in navigation */
.nav .theme-toggle {
  order: 10; /* Place at end of flex container */
  margin-left: auto;
}

/* If nav is not flex, use float */
.nav:not([style*="display: flex"]) .theme-toggle {
  float: right;
}

@media (max-width: 768px) {
  .nav .theme-toggle {
    /* On mobile, keep it visible and accessible */
    position: relative;
    margin-right: var(--space-sm);
  }
}
