/* ================================
   🎨 SISTEMA DE TEMAS CROSS-PLATFORM
   Compatible con iOS, Android, Windows, macOS

   NOTA: Las variables CSS base ahora están en variables.css
   Este archivo solo contiene componentes específicos del theme
   ================================ */

/* ================================
   TOGGLE DE MODO OSCURO
   ================================ */
.theme-toggle {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  background: var(--bg-secondary);
  border: 2px solid var(--border);
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: var(--transition);
  flex-shrink: 0;
}

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

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

.theme-toggle-icon {
  width: 20px;
  height: 20px;
  color: var(--text-secondary);
  transition: var(--transition);
}

.theme-toggle:hover .theme-toggle-icon {
  color: var(--primary);
}

/* Animación del icono al cambiar de tema */
.theme-toggle.transitioning .theme-toggle-icon {
  animation: iconRotate 0.3s ease-in-out;
}

@keyframes iconRotate {
  0% {
    transform: rotate(0deg) scale(1);
  }
  50% {
    transform: rotate(180deg) scale(0.8);
  }
  100% {
    transform: rotate(360deg) scale(1);
  }
}

/* Ocultar/mostrar iconos según el tema */
[data-theme="light"] .theme-toggle .icon-moon {
  display: block;
}

[data-theme="light"] .theme-toggle .icon-sun {
  display: none;
}

[data-theme="dark"] .theme-toggle .icon-moon {
  display: none;
}

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

/* Texto del toggle móvil */
.theme-toggle-text {
  font-weight: 500;
}

[data-theme="light"] .theme-toggle-text::before {
  content: "Modo Oscuro";
}

[data-theme="dark"] .theme-toggle-text::before {
  content: "Modo Claro";
}

/* Ocultar el texto original y usar ::before */
[data-theme="light"] .theme-toggle-text,
[data-theme="dark"] .theme-toggle-text {
  font-size: 0;
}

[data-theme="light"] .theme-toggle-text::before,
[data-theme="dark"] .theme-toggle-text::before {
  font-size: 1rem;
}

/* ================================
   COMPATIBILIDAD CROSS-PLATFORM
   ================================ */

/* === iOS Safari === */
@supports (-webkit-touch-callout: none) {
  /* Asegurar que el tap highlight sea visible pero sutil */
  * {
    -webkit-tap-highlight-color: rgba(14, 165, 233, 0.1);
  }

  /* Mejorar el scroll suave en iOS */
  body {
    -webkit-overflow-scrolling: touch;
  }

  /* Fix para el notch de iPhone */
  @supports (padding-top: env(safe-area-inset-top)) {
    .main-header {
      padding-top: env(safe-area-inset-top);
    }

    .mobile-nav {
      padding-bottom: env(safe-area-inset-bottom);
    }
  }
}

/* === Android === */
@media (pointer: coarse) {
  /* Hacer los botones más grandes en dispositivos touch */
  button,
  .nav-item,
  .mobile-nav-item {
    min-height: 44px;
    min-width: 44px;
  }
}

/* === Windows === */
@media (prefers-contrast: high) {
  /* Mejorar contraste para Windows High Contrast Mode */
  :root {
    --border: hsl(214, 32%, 70%);
    --shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.3);
  }

  [data-theme="dark"] {
    --border: hsl(215, 25%, 40%);
  }
}

/* === macOS === */
@supports (backdrop-filter: blur(20px)) {
  .main-header,
  .mobile-nav,
  .glass-card {
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
  }
}

/* ================================
   MEJORAS RESPONSIVE MOBILE-FIRST
   ================================ */

/* === Base: Móviles (hasta 640px) === */
.main-header {
  position: sticky;
  top: 0;
  width: 100%;
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border-bottom: 1px solid var(--glass-border);
  z-index: var(--z-sticky);
  transition: var(--transition);
}

.header-container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3) var(--space-4);
  max-width: 1400px;
  margin: 0 auto;
  gap: var(--space-4);
}

/* === Tablets: 640px - 1024px === */
@media (min-width: 640px) {
  .header-container {
    padding: var(--space-4) var(--space-6);
  }
}

/* === Desktop: 1024px+ === */
@media (min-width: 1024px) {
  .header-container {
    padding: var(--space-4) var(--space-8);
  }
}

/* === Large Desktop: 1440px+ === */
@media (min-width: 1440px) {
  .header-container {
    padding: var(--space-6) var(--space-12);
  }
}

/* ================================
   ICONOS - COMPATIBILIDAD UNIVERSAL
   ================================ */

/* Asegurar que todos los iconos se rendericen correctamente */
[data-lucide] {
  display: inline-block;
  width: 1em;
  height: 1em;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
  vertical-align: middle;
}

/* Fix para iconos en iOS */
@supports (-webkit-touch-callout: none) {
  [data-lucide] {
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
  }
}

/* Fix para iconos en navegadores antiguos */
[data-lucide] svg {
  display: block;
  width: 100%;
  height: 100%;
}

/* ================================
   ANIMACIONES OPTIMIZADAS
   ================================ */

/* Reducir animaciones para usuarios que lo prefieren */
@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;
  }
}

/* Optimización de performance para animaciones */
.theme-toggle,
.mobile-menu-btn,
.nav-item,
.mobile-nav-item {
  will-change: transform;
  transform: translateZ(0);
  -webkit-transform: translateZ(0);
}

/* ================================
   ACCESIBILIDAD
   ================================ */

/* Focus visible para navegación por teclado */
*:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* Mejorar contraste de texto en ambos temas */
::selection {
  background-color: hsla(var(--primary-h), var(--primary-s), var(--primary-l), 0.3);
  color: var(--text-primary);
}

/* ================================
   UTILIDADES RESPONSIVE
   ================================ */

/* Mostrar/ocultar en diferentes breakpoints */
.mobile-only {
  display: block;
}

.tablet-up {
  display: none;
}

.desktop-only {
  display: none;
}

@media (min-width: 640px) {
  .mobile-only {
    display: none;
  }

  .tablet-up {
    display: block;
  }
}

@media (min-width: 1024px) {
  .desktop-only {
    display: block;
  }
}

/* ================================
   MEJORAS DE PERFORMANCE
   ================================ */

/* Optimizar fuentes para todas las plataformas */
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
    'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
    sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

/* Optimizar imágenes */
img {
  max-width: 100%;
  height: auto;
  display: block;
}

/* Scroll suave en todos los navegadores */
html {
  scroll-behavior: smooth;
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
}

/* ================================
   DARK MODE TRANSITIONS
   ================================ */

/* Transición suave al cambiar de tema */
body,
.main-header,
.mobile-nav,
.nav-item,
.mobile-nav-item,
.dashboard-card,
.btn,
input,
textarea,
select {
  transition:
    background-color 0.3s ease,
    color 0.3s ease,
    border-color 0.3s ease,
    box-shadow 0.3s ease;
}

/* Prevenir flash al cargar */
.theme-loading {
  transition: none !important;
}

/* ================================
   GLOBAL COLOR FIXES
   Ensure proper contrast everywhere
   ================================ */

/* Override any inline white backgrounds to use theme variables */
body {
  background: var(--bg-primary);
  color: var(--text-primary);
}

/* Common card, panel, and container elements */
.card,
.panel,
.container,
.content-box,
.modal-content,
.results-container,
.stat-item,
.qr-modal-content,
.qr-code-box {
  background: var(--bg-primary) !important;
  color: var(--text-primary);
  border-color: var(--border);
}

/* Tables */
table,
.table,
.attendance-table {
  background: var(--bg-primary) !important;
  color: var(--text-primary);
}

table thead,
.table thead,
.attendance-table thead {
  background: var(--bg-secondary) !important;
  color: var(--text-primary);
}

table tbody tr,
.table tbody tr,
.attendance-table tbody tr {
  background: var(--bg-primary) !important;
  color: var(--text-primary);
  border-color: var(--border);
}

table tbody tr:hover,
.table tbody tr:hover,
.attendance-table tbody tr:hover {
  background: var(--bg-hover) !important;
}

/* Buttons with white backgrounds */
.btn-primary,
.tab-btn.active,
button.active {
  background: var(--primary) !important;
  color: var(--text-inverse) !important;
}

/* Inputs and form elements */
input,
textarea,
select,
.form-control {
  background: var(--bg-primary) !important;
  color: var(--text-primary) !important;
  border-color: var(--border) !important;
}

input:focus,
textarea:focus,
select:focus,
.form-control:focus {
  border-color: var(--primary) !important;
}

/* Modal backgrounds */
.modal,
.modal-dialog,
.modal-body,
.modal-header,
.modal-footer {
  background: var(--bg-primary);
  color: var(--text-primary);
  border-color: var(--border);
}

/* Alert and message boxes */
.alert,
.message-box,
.notification,
.toast {
  background: var(--bg-secondary);
  color: var(--text-primary);
  border-color: var(--border);
}

/* Badges and pills */
.badge,
.pill,
.tag {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

/* Headers and titles */
h1, h2, h3, h4, h5, h6 {
  color: var(--text-primary);
}

/* Links */
a {
  color: var(--primary);
}

a:hover {
  color: var(--primary-dark);
}

/* Paragraphs */
p {
  color: var(--text-secondary);
}

/* List items */
li {
  color: var(--text-primary);
}

/* Strong and bold */
strong, b {
  color: var(--text-primary);
}

/* Small and muted text */
small, .text-muted {
  color: var(--text-muted);
}
