/* ============================================
   InfluenceHub – Theme toggle reduced motion + dark contrast
   - WCAG AA contrast fix for .theme-toggle and .theme-icon
     in both light and dark mode.
   - prefers-reduced-motion guard: disables the icon
     cross-fade / rotation transitions on the theme
     switcher so users who prefer reduced motion are
     not exposed to motion.
   - 44px minimum touch target (WCAG 2.5.5).
   - Focus-visible ring for keyboard users.
   - Forced-colors (Windows High Contrast) support.
   ============================================ */

/* ---------- Base: 44px minimum touch target ---------- */

.theme-toggle {
  /* WCAG 2.5.5 – minimum 44x44px touch target for mobile users */
  min-height: 44px;
  min-width: 44px;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 0.75rem;
  border: 1px solid #e2e8f0;
  background: #ffffff;
  color: #334155;
  transition: background-color 0.15s ease, border-color 0.15s ease,
    color 0.15s ease, box-shadow 0.15s ease;
}

.theme-toggle:hover {
  border-color: #c4b5fd;
  color: #6d28d9;
  background: #f5f3ff;
}

/* ---------- Dark mode contrast (WCAG AA) ----------
   Light mode:
     - toggle surface: #ffffff
     - icon color: #334155 on #ffffff = 10.9:1 (passes AA)
   Dark mode:
     - toggle surface: #0f172a
     - icon color: #e2e8f0 on #0f172a = 13.6:1 (passes AA)
*/

.dark .theme-toggle {
  background: #0f172a;
  border-color: #334155;
  color: #e2e8f0;
}

.dark .theme-toggle:hover {
  background: #1e293b;
  border-color: #7c3aed;
  color: #c4b5fd;
}

/* ---------- Theme icons ---------- */

.theme-icon {
  width: 1.25rem;
  height: 1.25rem;
  flex-shrink: 0;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

/* Light mode: sun visible, moon hidden */
.theme-icon-sun {
  opacity: 1;
  transform: rotate(0deg) scale(1);
}

.theme-icon-moon {
  opacity: 0;
  transform: rotate(-90deg) scale(0.6);
  position: absolute;
}

/* Dark mode: moon visible, sun hidden */
.dark .theme-icon-sun {
  opacity: 0;
  transform: rotate(90deg) scale(0.6);
  position: absolute;
}

.dark .theme-icon-moon {
  opacity: 1;
  transform: rotate(0deg) scale(1);
  position: static;
}

/* ---------- Dark-mode contrast fix (WCAG AA) ----------
   Re-assert icon colors with !important so generic dark-mode
   text utilities cannot reduce the contrast below AA.

   Light mode: #334155 on #ffffff = 10.9:1 (passes AA)
   Dark mode:  #e2e8f0 on #0f172a = 13.6:1 (passes AA)
*/

.theme-toggle {
  color: #334155 !important;
}

.dark .theme-toggle {
  color: #e2e8f0 !important;
}

/* ---------- Focus-visible ring (keyboard) ---------- */

.theme-toggle:focus-visible {
  outline: 2px solid #7c3aed;
  outline-offset: 2px;
  box-shadow:
    0 0 0 2px #ffffff,
    0 0 0 6px rgba(124, 58, 237, 0.35);
}

.dark .theme-toggle:focus-visible {
  outline-color: #c4b5fd;
  box-shadow:
    0 0 0 2px #0f172a,
    0 0 0 6px rgba(196, 181, 253, 0.45);
}

/* ---------- Fallback for browsers without :focus-visible ---------- */

@supports not selector(:focus-visible) {
  .theme-toggle:focus {
    outline: 2px solid #7c3aed;
    outline-offset: 2px;
    box-shadow:
      0 0 0 2px #ffffff,
      0 0 0 6px rgba(124, 58, 237, 0.35);
  }

  .dark .theme-toggle:focus {
    outline-color: #c4b5fd;
    box-shadow:
      0 0 0 2px #0f172a,
      0 0 0 6px rgba(196, 181, 253, 0.45);
  }
}

/* ---------- prefers-reduced-motion guard ----------
   The theme switcher cross-fades and rotates the sun/moon icons
   when the theme changes. Users who prefer reduced motion should
   see the state change instantly, with no motion. */

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

  /* Neutralise any hover/focus/active transform on the toggle */
  .theme-toggle:hover,
  .theme-toggle:focus,
  .theme-toggle:focus-visible,
  .theme-toggle:active {
    transform: none !important;
    transition: none !important;
  }

  /* Icons must not animate, rotate or scale */
  .theme-icon,
  .theme-icon-sun,
  .theme-icon-moon {
    transition: none !important;
    animation: none !important;
    transform: none !important;
  }

  /* Keep the visibility toggle (opacity) but remove the rotation/scale
     so the icon swap is instant and motion-free. */
  .theme-icon-sun {
    opacity: 1;
    transform: none !important;
  }

  .theme-icon-moon {
    opacity: 0;
    transform: none !important;
  }

  .dark .theme-icon-sun {
    opacity: 0;
    transform: none !important;
  }

  .dark .theme-icon-moon {
    opacity: 1;
    transform: none !important;
  }

  /* Keep the focus ring visible but static (no animated halo) */
  .theme-toggle:focus-visible {
    box-shadow:
      0 0 0 2px #ffffff,
      0 0 0 6px rgba(124, 58, 237, 0.35) !important;
  }

  .dark .theme-toggle:focus-visible {
    box-shadow:
      0 0 0 2px #0f172a,
      0 0 0 6px rgba(196, 181, 253, 0.45) !important;
  }
}

/* ---------- Forced colors (Windows High Contrast) ---------- */

@media (forced-colors: active) {
  .theme-toggle {
    border: 1px solid CanvasText;
    color: CanvasText;
    background: Canvas;
  }

  .theme-toggle:hover {
    background: Highlight;
    color: HighlightText;
  }

  .theme-toggle:focus-visible,
  .theme-toggle:focus {
    outline: 2px solid Highlight;
    outline-offset: 2px;
    box-shadow: none;
    background: Highlight;
    color: HighlightText;
  }

  .theme-icon {
    color: CanvasText;
  }
}
