/* =========================================
   DATERO - Sistema de Diseño Global v2.0
   Fuente de la Verdad para Temas y Variables
   ========================================= */

/* ⚠️ ADVERTENCIA CRÍTICA:
   
   NUNCA uses valores rgba() hardcodeados directamente en tu CSS.
   
   ❌ MAL:  background: rgba(255, 255, 255, 0.5);
   ✅ BIEN: background: var(--gradient-secondary);
   
   ❌ MAL:  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.5);
   ✅ BIEN: box-shadow: var(--inset-highlight-normal);
   
   Usar colores hardcodeados rompe el sistema de temas y causa
   que el modo oscuro se vea claro al hacer focus/hover en elementos.
   
   SIEMPRE usa las variables CSS definidas en este archivo para
   asegurar que los colores se adapten correctamente al tema activo.
   ========================================= */

/* =========================================
   1. VARIABLES CSS - MODO CLARO
   ========================================= */

:root {
  /* Colores Base - Modo Claro */
  --bg-primary: #ffffff;
  --bg-secondary: #fafafa;
  --bg-tertiary: #f5f5f5;
  
  --text-primary: #171717;
  --text-secondary: #525252;
  --text-tertiary: #a3a3a3;
  
  --border-color: #e5e5e5;
  --border-default: #e5e5e5;
  --border-hover: #d4d4d4;
  
  --accent-primary: #e73a39;
  --accent-hover: #c92a29;
  --accent-light: #fef2f2;
  
  /* Colores para Glass Effect */
  --card-bg: rgba(255, 255, 255, 0.7);
  --card-border: rgba(255, 255, 255, 0.8);
  --shadow-color: rgba(0, 0, 0, 0.1);
  
  /* Fondos sólidos para dropdowns */
  --dropdown-bg: rgba(255, 255, 255, 1);
  --dropdown-border: rgba(229, 229, 229, 1);
  
  /* Colores Semánticos */
  --title-color: #2563eb;
  --subtitle-color: #059669;
  --category-bg: #eef2ff;
  --category-text: #4f46e5;
  
  /* Colores de Estado - Modo Claro */
  --color-success: #10b981;
  --color-success-bg: #d1fae5;
  --color-success-text: #065f46;
  --color-error: #ef4444;
  --color-error-bg: #fee2e2;
  --color-error-text: #991b1b;
  --color-warning: #f59e0b;
  --color-warning-bg: #fef3c7;
  --color-warning-text: #92400e;
  --color-info: #3b82f6;
  --color-info-bg: #dbeafe;
  --color-info-text: #1e40af;
  
  /* Gradientes para Elementos Flotantes */
  --shape-1: linear-gradient(135deg, #e73a39 0%, #ff6b6b 100%);
  --shape-2: linear-gradient(135deg, #ff6b6b 0%, #fca5a5 100%);
  --shape-3: linear-gradient(135deg, #e73a39 0%, #dc2626 100%);
  
  /* Sombras Modernas */
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.05);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
  
  /* Efectos de luz interna - Modo Claro */
  --inset-highlight-subtle: inset 0 1px 0 rgba(255, 255, 255, 0.4);
  --inset-highlight-normal: inset 0 1px 0 rgba(255, 255, 255, 0.5);
  --inset-highlight-strong: inset 0 1px 0 rgba(255, 255, 255, 0.6);
  --inset-highlight-light: inset 0 1px 0 rgba(255, 255, 255, 0.3);
  --inset-highlight-minimal: inset 0 1px 0 rgba(255, 255, 255, 0.1);
  
  /* Colores secundarios para gradientes - Modo Claro */
  --gradient-secondary: rgba(255, 255, 255, 0.5);
  
  /* Sistema de Espaciado Responsive */
  --spacing-xs: clamp(0.25rem, 1vw, 0.5rem);
  --spacing-sm: clamp(0.5rem, 1.5vw, 0.75rem);
  --spacing-md: clamp(0.75rem, 2vw, 1rem);
  --spacing-lg: clamp(1rem, 3vw, 1.5rem);
  --spacing-xl: clamp(1.5rem, 4vw, 2rem);
  --spacing-2xl: clamp(2rem, 5vw, 3rem);
  --spacing-3xl: clamp(3rem, 6vw, 4rem);
  
  /* Tamaños de Fuente Responsive */
  --text-xs: 0.75rem;
  --text-sm: 0.875rem;
  --text-base: 1rem;
  --text-lg: 1.125rem;
  --text-xl: 1.25rem;
  --text-2xl: 1.5rem;
  --text-3xl: 1.875rem;
  --text-4xl: 2.25rem;
  
  /* Border Radius */
  --radius-sm: 0.375rem;
  --radius-md: 0.5rem;
  --radius-lg: 0.75rem;
  --radius-xl: 1rem;
  --radius-2xl: 1.5rem;
  
  /* Touch Targets */
  --touch-min: 44px;
  --touch-target-min: 44px;
  
  /* Z-index Scale */
  --z-base: 1;
  --z-dropdown: 10;
  --z-sticky: 20;
  --z-modal-overlay: 50;
  --z-modal-content: 60;
  --z-toast: 100;
}

/* =========================================
   2. VARIABLES CSS - MODO OSCURO
   ========================================= */

[data-theme="dark"] {
  /* Colores Base - Modo Oscuro */
  --bg-primary: #0f172a;
  --bg-secondary: #1e293b;
  --bg-tertiary: #334155;
  
  --text-primary: #f8fafc;
  --text-secondary: #e2e8f0;
  --text-tertiary: #cbd5e1;
  
  --border-color: #475569;
  --border-default: #404040;
  --border-hover: #525252;
  
  --accent-primary: #e73a39;
  --accent-hover: #ef4444;
  --accent-light: #450a0a;
  
  /* Glass Effect para Modo Oscuro */
  --card-bg: rgba(30, 41, 59, 0.95);
  --card-border: rgba(71, 85, 105, 0.6);
  --shadow-color: rgba(0, 0, 0, 0.5);
  
  /* Fondos sólidos para dropdowns */
  --dropdown-bg: rgba(30, 41, 59, 1);
  --dropdown-border: rgba(71, 85, 105, 1);
  
  /* Colores Semánticos */
  --title-color: #60a5fa;
  --subtitle-color: #34d399;
  --category-bg: rgba(79, 70, 229, 0.25);
  --category-text: #e0e7ff;
  
  /* Colores de Estado - Modo Oscuro */
  --color-success: #10b981;
  --color-success-bg: #10b981;
  --color-success-text: #ffffff;
  --color-error: #ef4444;
  --color-error-bg: #ef4444;
  --color-error-text: #ffffff;
  --color-warning: #f59e0b;
  --color-warning-bg: #f59e0b;
  --color-warning-text: #ffffff;
  --color-info: #3b82f6;
  --color-info-bg: #3b82f6;
  --color-info-text: #ffffff;
  
  /* Gradientes para Modo Oscuro */
  --shape-1: linear-gradient(135deg, #991b1b 0%, #dc2626 100%);
  --shape-2: linear-gradient(135deg, #dc2626 0%, #ef4444 100%);
  --shape-3: linear-gradient(135deg, #7f1d1d 0%, #991b1b 100%);
  
  /* Sombras para Modo Oscuro */
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.5);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.7), 0 2px 4px -2px rgba(0, 0, 0, 0.6);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.8), 0 4px 6px -4px rgba(0, 0, 0, 0.7);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.9), 0 8px 10px -6px rgba(0, 0, 0, 0.8);
  
  /* Efectos de luz interna - Modo Oscuro */
  --inset-highlight-subtle: inset 0 1px 0 rgba(255, 255, 255, 0.05);
  --inset-highlight-normal: inset 0 1px 0 rgba(255, 255, 255, 0.08);
  --inset-highlight-strong: inset 0 1px 0 rgba(255, 255, 255, 0.1);
  --inset-highlight-light: inset 0 1px 0 rgba(255, 255, 255, 0.03);
  --inset-highlight-minimal: inset 0 1px 0 rgba(255, 255, 255, 0.02);
  
  /* Colores secundarios para gradientes - Modo Oscuro */
  --gradient-secondary: rgba(30, 41, 59, 0.5);
}

/* =========================================
   3. RESET Y BASE
   ========================================= */

*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

html,
body {
  width: 100%;
  max-width: 100vw;
  overflow-x: hidden;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-tap-highlight-color: transparent;
  background: linear-gradient(135deg, var(--bg-primary) 0%, var(--bg-secondary) 50%, var(--bg-tertiary) 100%) !important;
  color: var(--text-primary) !important;
}

/* CRITICAL: Forzar colores de body en modo oscuro */
[data-theme="dark"] body {
  background: linear-gradient(135deg, #0f172a 0%, #1e293b 50%, #334155 100%) !important;
  color: #f8fafc !important;
}

/* Transiciones de tema solo cuando está completamente cargado (previene flash en modo oscuro) */
html:not(.no-transitions) body {
  transition: background 0.5s cubic-bezier(0.4, 0, 0.2, 1), color 0.3s ease;
}

/* Prevenir overflow en todos los elementos */
* {
  max-width: 100%;
}

/* =========================================
   4. UTILIDADES DE TEMA
   ========================================= */

.bg-theme-primary {
  background-color: var(--bg-primary);
}

.bg-theme-secondary {
  background-color: var(--bg-secondary);
}

.bg-theme-tertiary {
  background-color: var(--bg-tertiary);
}

.text-theme-primary {
  color: var(--text-primary);
}

.text-theme-secondary {
  color: var(--text-secondary);
}

.text-theme-tertiary {
  color: var(--text-tertiary);
}

.border-theme {
  border-color: var(--border-default);
}

.border-theme-hover:hover {
  border-color: var(--border-hover);
}

.accent-primary {
  color: var(--accent-primary);
}

.bg-accent-primary {
  background-color: var(--accent-primary);
}

.bg-accent-hover:hover {
  background-color: var(--accent-hover);
}

/* =========================================
   5. BOTONES BASE
   ========================================= */

.btn-primary {
  padding: clamp(0.75rem, 2vw, 1rem) clamp(1.25rem, 3vw, 1.75rem);
  min-height: var(--touch-target-min);
  border-radius: var(--radius-lg);
  font-weight: 600;
  background-color: var(--accent-primary);
  color: white;
  border: none;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: background-color 0.2s ease, box-shadow 0.2s ease, opacity 0.2s ease;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.btn-primary:hover {
  background-color: var(--accent-hover);
  box-shadow: 0 4px 12px rgba(231, 58, 57, 0.3);
}

.btn-primary:active {
  opacity: 0.9;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.btn-primary:focus-visible {
  outline: 3px solid var(--accent-primary);
  outline-offset: 3px;
}

.btn-secondary {
  padding: clamp(0.75rem, 2vw, 1rem) clamp(1.25rem, 3vw, 1.75rem);
  min-height: var(--touch-target-min);
  border-radius: var(--radius-lg);
  font-weight: 600;
  background-color: var(--bg-tertiary);
  color: var(--text-primary);
  border: 2px solid var(--border-default);
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: background-color 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.btn-secondary:hover {
  background-color: var(--bg-secondary);
  border-color: var(--border-hover);
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.1);
}

.btn-secondary:active {
  opacity: 0.9;
}

.btn-secondary:focus-visible {
  outline: 3px solid var(--accent-primary);
  outline-offset: 3px;
}

/* =========================================
   6. CARDS BASE
   ========================================= */

.card {
  padding: clamp(1rem, 3vw, 1.5rem);
  border-radius: var(--radius-lg);
  background-color: var(--bg-primary);
  border: 1px solid var(--border-default);
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.3s ease, border-color 0.3s ease;
  overflow: hidden;
  max-width: 100%;
}

.card:hover {
  box-shadow: var(--shadow-md);
}

.card-interactive {
  cursor: pointer;
}

.card-interactive:hover {
  border-color: var(--accent-primary);
  box-shadow: var(--shadow-lg);
}

.card-interactive:focus-visible {
  outline: 3px solid var(--accent-primary);
  outline-offset: 2px;
}

.card > * {
  max-width: 100%;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

/* Glass Card Effect */
.glass-card {
  background: var(--card-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--card-border);
}

/* =========================================
   7. INPUTS BASE
   ========================================= */

.input-field {
  width: 100%;
  min-height: var(--touch-target-min);
  padding: clamp(0.75rem, 2vw, 1rem) clamp(1rem, 2.5vw, 1.25rem);
  font-size: max(16px, 1rem);
  border-radius: var(--radius-md);
  background-color: var(--bg-secondary);
  border: 2px solid var(--border-default);
  color: var(--text-primary);
  transition: border-color 0.2s ease, box-shadow 0.2s ease, background-color 0.2s ease;
  -webkit-tap-highlight-color: transparent;
  -webkit-appearance: none;
  appearance: none;
}

.input-field:focus {
  outline: none;
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px var(--accent-light);
  background-color: var(--bg-primary);
}

.input-field::placeholder {
  color: var(--text-tertiary);
  opacity: 0.7;
}

.input-field:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  background-color: var(--bg-tertiary);
}

/* Autocompletado */
.input-field:-webkit-autofill,
.input-field:-webkit-autofill:hover,
.input-field:-webkit-autofill:focus {
  -webkit-text-fill-color: var(--text-primary);
  -webkit-box-shadow: 0 0 0px 1000px var(--bg-secondary) inset;
  transition: background-color 5000s ease-in-out 0s;
}

/* =========================================
   8. BADGES Y TAGS
   ========================================= */

.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.25rem 0.75rem;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 500;
}

.badge-primary {
  background-color: var(--accent-light);
  color: var(--accent-primary);
}

.badge-secondary {
  background-color: var(--bg-tertiary);
  color: var(--text-secondary);
}

/* =========================================
   9. SCROLLBAR PERSONALIZADO
   ========================================= */

::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: var(--bg-secondary);
}

::-webkit-scrollbar-thumb {
  background: var(--border-default);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--border-hover);
}

/* =========================================
   10. ANIMACIONES GLOBALES
   ========================================= */

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slideUp {
  from {
    transform: translateY(10px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

@keyframes scaleIn {
  from {
    transform: scale(0.95);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

@keyframes float {
  0%, 100% {
    transform: translateY(0) rotate(0deg);
  }
  50% {
    transform: translateY(-30px) rotate(180deg);
  }
}

.animate-fade-in,
.fade-in {
  animation: fadeIn 0.3s ease-in-out;
}

.animate-fade-in-up {
  animation: slideUp 0.4s ease-out;
}

.animate-slide-up,
.slide-up {
  animation: slideUp 0.4s ease-out;
}

.animate-scale-in {
  animation: scaleIn 0.2s ease-out;
}

.animate-spin {
  animation: spin 0.6s linear infinite;
}

/* =========================================
   11. UTILIDADES DE ACCESIBILIDAD
   ========================================= */

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

.focus-visible:focus-visible {
  outline: 2px solid var(--accent-primary);
  outline-offset: 2px;
}

/* =========================================
   12. MEDIA QUERIES - RESPONSIVE
   ========================================= */

/* Tablet (768px+) */
@media (min-width: 768px) {
  :root {
    --text-2xl: 1.875rem;
    --text-3xl: 2.25rem;
    --text-4xl: 3rem;
  }
}

/* Desktop (1024px+) */
@media (min-width: 1024px) {
  :root {
    --text-3xl: 2.5rem;
    --text-4xl: 3.5rem;
  }
}

/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* Dark Mode Preference */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg-primary: #171717;
    --bg-secondary: #0a0a0a;
    --bg-tertiary: #262626;
    --text-primary: #fafafa;
    --text-secondary: #a3a3a3;
    --text-tertiary: #737373;
    --border-default: #404040;
    --border-hover: #525252;
  }
}

/* =========================================
   CRITICAL FIX: Prevenir cambios de tema en inputs
   ========================================= */

/* CRITICAL: Forzar html y body a mantener tema */
html {
  background-color: var(--bg-primary) !important;
}

html[data-theme="dark"] {
  background-color: #0f172a !important;
}

html[data-theme="light"] {
  background-color: #ffffff !important;
}

/* Forzar inputs de búsqueda a mantener transparencia en todos los estados */
input[type="text"],
input[type="search"],
input[id*="search"],
input[class*="search"] {
  background-color: transparent !important;
  color: var(--text-primary) !important;
}

input[type="text"]:focus,
input[type="search"]:focus,
input[id*="search"]:focus,
input[class*="search"]:focus,
input[type="text"]:active,
input[type="search"]:active,
input[id*="search"]:active,
input[class*="search"]:active {
  background-color: transparent !important;
  color: var(--text-primary) !important;
}

/* Prevenir cambio de colores en autocompletado */
input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus,
input:-webkit-autofill:active {
  -webkit-text-fill-color: var(--text-primary) !important;
  -webkit-box-shadow: 0 0 0px 1000px transparent inset !important;
  transition: background-color 5000s ease-in-out 0s !important;
}

/* Print Styles */
@media print {
  .no-print {
    display: none !important;
  }
  
  body {
    background: white;
    color: black;
  }
  
  .card {
    border: 1px solid #ddd;
    box-shadow: none;
  }
}
