/* Variables CSS para tema consistente */
:root {
  --primary-color: #6366f1;
  --primary-hover: #4f46e5;
  --secondary-color: #f3f4f6;
  --secondary-hover: #e5e7eb;
  --success-color: #10b981;
  --error-color: #ef4444;
  --warning-color: #f59e0b;
  --text-primary: #111827;
  --text-secondary: #6b7280;
  --background: #ffffff;
  --surface: #f9fafb;
  --border: #e5e7eb;
  --border-hover: #d1d5db;
  --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 -1px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
}

/* Modo oscuro */
@media (prefers-color-scheme: dark) {
  :root {
    --primary-color: #818cf8;
    --primary-hover: #6366f1;
    --secondary-color: #374151;
    --secondary-hover: #4b5563;
    --success-color: #34d399;
    --error-color: #f87171;
    --warning-color: #fbbf24;
    --text-primary: #f9fafb;
    --text-secondary: #d1d5db;
    --background: #111827;
    --surface: #1f2937;
    --border: #374151;
    --border-hover: #4b5563;
  }
}

/* Reset y estilos base */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 
               'Helvetica Neue', Arial, sans-serif;
  background: var(--background);
  color: var(--text-primary);
  line-height: 1.6;
  font-size: 16px;
  min-height: 100vh;
  transition: all 0.3s ease;
}

/* Layout principal */
.app-container {
  min-height: 100vh;
  background: linear-gradient(135deg, var(--background) 0%, var(--surface) 100%);
  padding: 1rem;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.header {
  text-align: center;
  margin-bottom: 2rem;
  max-width: 600px;
}

.header h1 {
  font-size: 2.5rem;
  font-weight: 800;
  background: linear-gradient(135deg, var(--primary-color), var(--primary-hover));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 0.5rem;
  letter-spacing: -0.02em;
}

.header p {
  color: var(--text-secondary);
  font-size: 1.1rem;
  margin-bottom: 1rem;
}

/* Tarjeta principal */
.main-card {
  background: var(--surface);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  padding: 2rem;
  width: 100%;
  max-width: 600px;
  border: 1px solid var(--border);
  transition: all 0.3s ease;
}

.main-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
}

/* Video y canvas */
.media-container {
  position: relative;
  margin-bottom: 1.5rem;
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: #000;
  box-shadow: var(--shadow-md);
}

#video {
  width: 100%;
  height: auto;
  max-height: 400px;
  object-fit: cover;
  display: block;
  border-radius: var(--radius-lg);
  transform: scaleX(-1); /* Efecto espejo para cámara frontal */
}

#preview {
  width: 100%;
  height: auto;
  max-height: 400px;
  object-fit: cover;
  display: block;
  border-radius: var(--radius-lg);
}

#canvas {
  display: none;
}

/* Controles de cámara */
.camera-controls {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-bottom: 1.5rem;
  justify-content: center;
}

.camera-controls .btn {
  flex: 1;
  min-width: 120px;
}

/* Botones */
.btn {
  padding: 0.875rem 1.5rem;
  border: none;
  border-radius: var(--radius-md);
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  text-decoration: none;
  position: relative;
  overflow: hidden;
}

.btn:before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent);
  transition: left 0.5s;
}

.btn:hover:before {
  left: 100%;
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary-color), var(--primary-hover));
  color: white;
  box-shadow: var(--shadow-md);
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-lg);
}

.btn-secondary {
  background: var(--secondary-color);
  color: var(--text-primary);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: var(--secondary-hover);
  border-color: var(--border-hover);
  transform: translateY(-1px);
}

.btn-success {
  background: linear-gradient(135deg, var(--success-color), #059669);
  color: white;
  box-shadow: var(--shadow-md);
}

.btn-success:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-lg);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none !important;
  box-shadow: var(--shadow-sm) !important;
}

.btn:disabled:before {
  display: none;
}

/* Acciones principales */
.main-actions {
  display: flex;
  gap: 1rem;
  margin-bottom: 1.5rem;
  justify-content: center;
}

.main-actions .btn {
  flex: 1;
  max-width: 200px;
}

/* Sección de archivo fallback */
.fallback-section {
  margin-bottom: 1.5rem;
}

.fallback-section details {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 1rem;
}

.fallback-section summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--text-secondary);
  padding: 0.5rem;
  border-radius: var(--radius-sm);
  transition: all 0.2s ease;
}

.fallback-section summary:hover {
  background: var(--secondary-color);
  color: var(--text-primary);
}

.file-input-wrapper {
  margin-top: 1rem;
  position: relative;
}

#fileInput {
  width: 100%;
  padding: 0.75rem;
  border: 2px dashed var(--border);
  border-radius: var(--radius-md);
  background: var(--background);
  color: var(--text-primary);
  cursor: pointer;
  transition: all 0.2s ease;
}

#fileInput:hover {
  border-color: var(--primary-color);
  background: var(--surface);
}

/* Estado y mensajes */
.status-message {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 1rem;
  text-align: center;
  font-size: 0.95rem;
  color: var(--text-secondary);
  transition: all 0.3s ease;
  min-height: 50px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 1rem;
}

.status-message.success {
  background: linear-gradient(135deg, #ecfdf5, #d1fae5);
  border-color: var(--success-color);
  color: #065f46;
  padding: 1.5rem;
}

.status-message.error {
  background: linear-gradient(135deg, #fef2f2, #fecaca);
  border-color: var(--error-color);
  color: #991b1b;
}

/* Success Banner Styling */
.success-banner {
  text-align: center;
  width: 100%;
}

.success-icon {
  font-size: 3rem;
  margin-bottom: 0.75rem;
  animation: scaleIn 0.5s ease-out;
}

.success-title {
  font-size: 1.5rem;
  font-weight: 700;
  color: #047857;
  margin-bottom: 1rem;
  animation: fadeIn 0.6s ease-out;
}

.success-details {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 1rem;
  font-size: 0.95rem;
}

.detail-item {
  padding: 0.5rem;
  background: rgba(16, 185, 129, 0.1);
  border-radius: var(--radius-sm);
  color: #065f46;
}

.detail-item strong {
  color: #047857;
  margin-right: 0.5rem;
}

.success-link {
  display: inline-block;
  padding: 0.75rem 1.5rem;
  background: linear-gradient(135deg, var(--success-color), #059669);
  color: white;
  border-radius: var(--radius-md);
  font-weight: 600;
  text-decoration: none;
  margin-top: 0.5rem;
  transition: all 0.3s ease;
  box-shadow: var(--shadow-md);
}

.success-link:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
  background: linear-gradient(135deg, #059669, #047857);
}

.redirect-info {
  margin-top: 1rem;
  font-size: 0.9rem;
  color: #059669;
  font-style: italic;
  animation: pulse 2s ease-in-out infinite;
}

@keyframes scaleIn {
  0% { 
    transform: scale(0);
    opacity: 0;
  }
  50% {
    transform: scale(1.2);
  }
  100% { 
    transform: scale(1);
    opacity: 1;
  }
}

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

.status-message a {
  color: var(--primary-color);
  text-decoration: none;
  font-weight: 600;
  transition: color 0.2s ease;
}

.status-message a:hover {
  color: var(--primary-hover);
  text-decoration: underline;
}

/* Utilidades */
.hidden {
  display: none !important;
}

.loading {
  opacity: 0.7;
  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 transparent;
  border-top: 2px solid var(--primary-color);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* Animaciones */
@keyframes fadeIn {
  from { 
    opacity: 0; 
    transform: translateY(10px); 
  }
  to { 
    opacity: 1; 
    transform: translateY(0); 
  }
}

@keyframes slideIn {
  from { 
    transform: translateX(-20px); 
    opacity: 0; 
  }
  to { 
    transform: translateX(0); 
    opacity: 1; 
  }
}

.fade-in {
  animation: fadeIn 0.3s ease-out;
}

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

/* Responsive Design */
@media (max-width: 768px) {
  .app-container {
    padding: 0.5rem;
  }
  
  .header h1 {
    font-size: 2rem;
  }
  
  .main-card {
    padding: 1.5rem;
    margin: 0.5rem;
  }
  
  .camera-controls {
    flex-direction: column;
  }
  
  .camera-controls .btn {
    flex: none;
    min-width: auto;
  }
  
  .main-actions {
    flex-direction: column;
  }
  
  .main-actions .btn {
    max-width: none;
  }
}

@media (max-width: 480px) {
  .header h1 {
    font-size: 1.75rem;
  }
  
  .main-card {
    padding: 1rem;
  }
  
  .btn {
    padding: 0.75rem 1rem;
    font-size: 0.9rem;
  }
}