/**
 * IP SEGURIDAD PWA - Styles
 * Version 2.1.0
 * Mobile-First Responsive Design
 * Compatible: iOS 12+, Android 5+, Chrome, Firefox, Safari, Edge
 */

/* ============================================
   RESET Y BASE
   ============================================ */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

:root {
  /* Colores principales */
  --color-primary: #1E88E5;
  --color-primary-dark: #0D47A1;
  --color-primary-light: #2196F3;
  --color-secondary: #42A5F5;

  /* Colores de fondo */
  --bg-light: #FFFFFF;
  --bg-dark: #0A0E27;
  --bg-card-light: #F5F5F5;
  --bg-card-dark: #1A1F3A;

  /* Texto */
  --text-light: #212121;
  --text-light-secondary: #757575;
  --text-dark: #FFFFFF;
  --text-dark-secondary: #B0B0B0;

  /* Sombras */
  --shadow-sm: 0 2px 4px rgba(0,0,0,0.1);
  --shadow-md: 0 4px 8px rgba(0,0,0,0.15);
  --shadow-lg: 0 8px 16px rgba(0,0,0,0.2);
  --shadow-3d: 5px 5px 10px rgba(0,0,0,0.15), -5px -5px 10px rgba(255,255,255,0.1);

  /* Transiciones */
  --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-size-adjust: 100%;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', sans-serif;
  min-height: 100vh;
  min-height: -webkit-fill-available;
  background: var(--bg-light);
  color: var(--text-light);
  transition: var(--transition);
  overflow-x: hidden;

  /* Safe area para iOS */
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* Modo oscuro */
body.dark-mode {
  background: var(--bg-dark);
  color: var(--text-dark);
}

/* ============================================
   BANNER DE ACTUALIZACIÓN
   ============================================ */
.update-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  background: linear-gradient(135deg, var(--color-primary), var(--color-primary-dark));
  color: white;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  z-index: 9999;
  box-shadow: var(--shadow-lg);
  animation: slideDown 0.3s ease;
}

@keyframes slideDown {
  from {
    transform: translateY(-100%);
  }
  to {
    transform: translateY(0);
  }
}

.update-banner p {
  font-weight: 600;
  font-size: 14px;
}

.update-btn {
  background: white;
  color: var(--color-primary);
  border: none;
  padding: 8px 16px;
  border-radius: 20px;
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
  transition: var(--transition);
}

.update-btn:active {
  transform: scale(0.95);
}

/* ============================================
   PANTALLA PRINCIPAL
   ============================================ */
.main-screen {
  min-height: 100vh;
  min-height: -webkit-fill-available;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px;
  position: relative;
}

/* Toggle de tema */
.theme-toggle {
  position: fixed;
  top: 20px;
  right: 20px;
  width: 50px;
  height: 50px;
  border-radius: 50%;
  border: none;
  background: var(--bg-card-light);
  box-shadow: var(--shadow-md);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  transition: var(--transition);
  z-index: 100;
}

body.dark-mode .theme-toggle {
  background: var(--bg-card-dark);
}

.theme-toggle:hover {
  transform: scale(1.1) rotate(15deg);
  box-shadow: var(--shadow-lg);
}

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

/* Logo */
.logo-container {
  margin-bottom: 24px;
  animation: logoFloat 3s ease-in-out infinite;
}

@keyframes logoFloat {
  0%, 100% {
    transform: translateY(0px);
  }
  50% {
    transform: translateY(-10px);
  }
}

.logo {
  width: 180px;
  height: auto;
  display: block;
  filter: drop-shadow(0 4px 8px rgba(0,0,0,0.1));
}

/* Título y tagline */
.company-title {
  font-size: 32px;
  font-weight: 800;
  text-align: center;
  margin-bottom: 12px;
  letter-spacing: 2px;
  background: linear-gradient(135deg, var(--color-primary), var(--color-primary-dark));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.tagline {
  font-size: 13px;
  font-weight: 600;
  text-align: center;
  color: var(--text-light-secondary);
  margin-bottom: 48px;
  letter-spacing: 1.5px;
  text-transform: uppercase;
}

body.dark-mode .tagline {
  color: var(--text-dark-secondary);
}

/* Container de botones */
.button-container {
  width: 100%;
  max-width: 400px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* Botones base */
.btn {
  width: 100%;
  padding: 18px 28px;
  border: none;
  border-radius: 28px;
  font-family: inherit;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  transition: var(--transition);
  position: relative;
  overflow: hidden;

  /* Efecto 3D con sombras múltiples */
  box-shadow: var(--shadow-3d), inset 0 1px 0 rgba(255,255,255,0.3);
}

.btn:hover {
  transform: translateY(-4px);
  box-shadow:
    7px 7px 15px rgba(0,0,0,0.2),
    -7px -7px 15px rgba(255,255,255,0.15),
    inset 0 1px 0 rgba(255,255,255,0.4);
}

.btn:active {
  transform: translateY(-1px);
  box-shadow:
    3px 3px 6px rgba(0,0,0,0.2) inset,
    -3px -3px 6px rgba(255,255,255,0.05) inset;
}

.btn-icon {
  font-size: 24px;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.2));
}

.btn:hover .btn-icon {
  transform: scale(1.1);
}

/* Botón Instalar - DESTACADO */
.btn-install {
  background: linear-gradient(145deg, var(--color-primary-light), var(--color-primary));
  color: white;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-size: 15px;
}

.btn-install:hover {
  background: linear-gradient(145deg, var(--color-secondary), var(--color-primary-light));
}

/* Botón Primary */
.btn-primary {
  background: linear-gradient(145deg, var(--color-primary), var(--color-primary-dark));
  color: white;
}

.btn-primary:hover {
  background: linear-gradient(145deg, var(--color-primary-light), var(--color-primary));
}

/* Botón Secondary */
.btn-secondary {
  background: linear-gradient(145deg, var(--color-primary-dark), #0A3D91);
  color: white;
}

.btn-secondary:hover {
  background: linear-gradient(145deg, var(--color-primary), var(--color-primary-dark));
}

/* Versión */
.version {
  position: fixed;
  bottom: 10px;
  right: 10px;
  font-size: 11px;
  color: var(--text-light-secondary);
  opacity: 0.5;
  font-weight: 600;
}

body.dark-mode .version {
  color: var(--text-dark-secondary);
}

/* ============================================
   MODALES - Base
   ============================================ */
.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.modal.active {
  display: flex;
}

.modal-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
}

.modal-content {
  position: relative;
  background: var(--bg-light);
  border-radius: 24px;
  max-width: 500px;
  width: 100%;
  max-height: 90vh;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
  z-index: 1001;
  margin: 20px;
  animation: modalSlideUp 0.3s ease;
}

body.dark-mode .modal-content {
  background: var(--bg-card-dark);
}

@keyframes modalSlideUp {
  from {
    opacity: 0;
    transform: translateY(50px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.modal-header {
  padding: 20px;
  border-bottom: 1px solid rgba(0,0,0,0.1);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

body.dark-mode .modal-header {
  border-bottom-color: rgba(255,255,255,0.1);
}

.modal-header h2 {
  font-size: 20px;
  font-weight: 700;
}

.modal-close {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: rgba(0,0,0,0.05);
  font-size: 24px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}

.modal-close:hover {
  background: rgba(0,0,0,0.1);
  transform: rotate(90deg);
}

.modal-close:active {
  transform: rotate(90deg) scale(0.9);
}

body.dark-mode .modal-close {
  background: rgba(255,255,255,0.1);
}

body.dark-mode .modal-close:hover {
  background: rgba(255,255,255,0.2);
}

.modal-body {
  padding: 24px;
  overflow-y: auto;
  max-height: calc(90vh - 140px);
}

.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid rgba(0,0,0,0.1);
  display: flex;
  justify-content: flex-end;
  gap: 12px;
}

body.dark-mode .modal-footer {
  border-top-color: rgba(255,255,255,0.1);
}

/* ============================================
   MODAL DE CHAT - Layout Fijo CRÍTICO
   ============================================ */
.chat-modal-content {
  display: flex;
  flex-direction: column;
  height: 80vh;
  max-height: 700px;
}

/* Header fijo arriba */
.chat-header {
  flex-shrink: 0;
  padding: 20px;
  background: linear-gradient(135deg, var(--color-primary), var(--color-primary-dark));
  color: white;
  border-radius: 24px 24px 0 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.chat-title {
  font-size: 18px;
  font-weight: 700;
  margin: 0;
}

.chat-header .modal-close {
  background: rgba(255,255,255,0.2);
  color: white;
}

.chat-header .modal-close:hover {
  background: rgba(255,255,255,0.3);
}

/* Área de mensajes con scroll - CRÍTICO */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--bg-card-light);

  /* Scroll suave */
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}

body.dark-mode .chat-messages {
  background: var(--bg-dark);
}

/* Scrollbar personalizado */
.chat-messages::-webkit-scrollbar {
  width: 6px;
}

.chat-messages::-webkit-scrollbar-track {
  background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
  background: rgba(0,0,0,0.2);
  border-radius: 10px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
  background: rgba(0,0,0,0.3);
}

/* Mensajes */
.message {
  display: flex;
  animation: messageSlideIn 0.3s ease;
}

@keyframes messageSlideIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.message-bot {
  justify-content: flex-start;
}

.message-user {
  justify-content: flex-end;
}

.message-content {
  max-width: 80%;
  padding: 12px 16px;
  border-radius: 16px;
  font-size: 15px;
  line-height: 1.5;
  word-wrap: break-word;
}

.message-bot .message-content {
  background: white;
  color: var(--text-light);
  border-bottom-left-radius: 4px;
  box-shadow: var(--shadow-sm);
}

body.dark-mode .message-bot .message-content {
  background: var(--bg-card-dark);
  color: var(--text-dark);
}

.message-user .message-content {
  background: linear-gradient(135deg, var(--color-primary), var(--color-primary-dark));
  color: white;
  border-bottom-right-radius: 4px;
  box-shadow: var(--shadow-md);
}

/* Typing indicator */
.typing-indicator {
  display: none;
  padding: 12px 16px;
  background: white;
  border-radius: 16px;
  border-bottom-left-radius: 4px;
  width: fit-content;
  box-shadow: var(--shadow-sm);
}

body.dark-mode .typing-indicator {
  background: var(--bg-card-dark);
}

.typing-indicator.active {
  display: block;
}

.typing-indicator span {
  display: inline-block;
  width: 8px;
  height: 8px;
  background: var(--color-primary);
  border-radius: 50%;
  margin-right: 4px;
  animation: typingDot 1.4s infinite;
}

.typing-indicator span:nth-child(2) {
  animation-delay: 0.2s;
}

.typing-indicator span:nth-child(3) {
  animation-delay: 0.4s;
  margin-right: 0;
}

@keyframes typingDot {
  0%, 60%, 100% {
    transform: translateY(0);
    opacity: 0.5;
  }
  30% {
    transform: translateY(-8px);
    opacity: 1;
  }
}

/* Input container fijo abajo - CRÍTICO */
.chat-input-container {
  flex-shrink: 0;
  padding: 16px;
  background: var(--bg-light);
  border-top: 1px solid rgba(0,0,0,0.1);
  border-radius: 0 0 24px 24px;
  display: flex;
  gap: 12px;
  align-items: center;
}

body.dark-mode .chat-input-container {
  background: var(--bg-card-dark);
  border-top-color: rgba(255,255,255,0.1);
}

.chat-input {
  flex: 1;
  padding: 12px 16px;
  border: 2px solid rgba(0,0,0,0.1);
  border-radius: 20px;
  font-family: inherit;
  font-size: 16px; /* MÍNIMO 16px para evitar zoom en iOS */
  outline: none;
  transition: var(--transition);
  background: var(--bg-card-light);
  color: var(--text-light);
}

body.dark-mode .chat-input {
  background: var(--bg-dark);
  border-color: rgba(255,255,255,0.2);
  color: var(--text-dark);
}

.chat-input:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(30,136,229,0.1);
}

.chat-send {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, var(--color-primary), var(--color-primary-dark));
  color: white;
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
  box-shadow: var(--shadow-md);
}

.chat-send:active {
  transform: scale(0.95);
}

.chat-send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  animation: pulse 1.5s infinite;
}

@keyframes pulse {
  0%, 100% {
    opacity: 0.5;
    transform: scale(1);
  }
  50% {
    opacity: 0.7;
    transform: scale(1.05);
  }
}

/* ============================================
   MODAL PEQUEÑO (iOS Instructions)
   ============================================ */
.modal-small {
  max-width: 360px;
}

.ios-instructions {
  line-height: 1.6;
}

.ios-instructions ol {
  margin: 16px 0 16px 24px;
}

.ios-instructions li {
  margin-bottom: 12px;
}

/* ============================================
   INPUTS Y FORMS
   ============================================ */
.input-codigo {
  width: 100%;
  padding: 14px;
  border: 2px solid rgba(0,0,0,0.1);
  border-radius: 12px;
  font-family: inherit;
  font-size: 18px;
  text-align: center;
  font-weight: 700;
  letter-spacing: 4px;
  margin: 16px 0;
  outline: none;
  transition: var(--transition);
}

body.dark-mode .input-codigo {
  background: var(--bg-dark);
  border-color: rgba(255,255,255,0.2);
  color: var(--text-dark);
}

.input-codigo:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(30,136,229,0.1);
}

.error-message {
  color: #EF4444;
  font-size: 13px;
  margin-top: 8px;
  min-height: 20px;
}

/* ============================================
   RESPONSIVE - Desktop
   ============================================ */
@media (min-width: 768px) {
  .logo {
    width: 220px;
  }

  .company-title {
    font-size: 42px;
  }

  .tagline {
    font-size: 14px;
  }

  .button-container {
    max-width: 450px;
  }

  .btn {
    font-size: 17px;
    padding: 20px 32px;
  }

  .chat-modal-content {
    max-height: 650px;
  }

  .modal-content {
    margin: 40px;
  }
}

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

.no-scroll {
  overflow: hidden;
}

/* Prevent zoom on iOS */
@media screen and (-webkit-min-device-pixel-ratio: 0) {
  select,
  textarea,
  input {
    font-size: 16px;
  }
}

/* Print styles */
@media print {
  .theme-toggle,
  .update-banner,
  .version {
    display: none;
  }
}
