/**
 * @file styles.css
 * @version 2.0.0
 * @description Hoja de estilos principal para Aura. Define variables CSS, temas (claro/oscuro),
 * animaciones del avatar, diseño adaptable (responsive) y estilos de accesibilidad.
 */
@font-face {
  font-family: 'Outfit';
  src: url('../assets/fonts/Outfit-Variable.woff2') format('woff2');
  font-weight: 100 900;
  font-display: swap;
}

:root {
  --bg-base: #0f172a;
  --bg-surface: #1e293b;
  --bg-surface-hover: #334155;
  --bg-surface-alpha: rgba(30, 41, 59, 0.8);
  --primary: #0ea5e9;
  --primary-light: rgba(14, 165, 233, 0.15);
  --accent: #8b5cf6;
  --accent-light: rgba(139, 92, 246, 0.15);
  --teal: #14b8a6;
  --teal-light: rgba(20, 184, 166, 0.15);
  --text: #f8fafc;
  --text-muted: #94a3b8;
  --border: #334155;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
  --radius: 16px;
  --radius-sm: 8px;

  /* Avatar emotion colors */
  --emo-neutral: #0ea5e9;
  --emo-happy: #f59e0b;
  --emo-sad: #64748b;
  --emo-surprised: #10b981;
  --emo-thinking: #d946ef;
}

body.light-theme {
  --bg-base: #f8fafc;
  --bg-surface: #ffffff;
  --bg-surface-hover: #f1f5f9;
  --bg-surface-alpha: rgba(255, 255, 255, 0.8);
  --primary: #0284c7;
  --primary-light: rgba(2, 132, 199, 0.15);
  --accent: #7c3aed;
  --accent-light: rgba(124, 58, 237, 0.15);
  --teal: #0d9488;
  --teal-light: rgba(13, 148, 136, 0.15);
  --text: #0f172a;
  --text-muted: #475569;
  --border: #cbd5e1;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.08);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: "Outfit", sans-serif;
  background: var(--bg-base);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* ========================
   PANTALLA DE BIENVENIDA
======================== */
#welcome-screen {
  position: fixed;
  inset: 0;
  background: radial-gradient(circle at top right, var(--bg-surface), var(--bg-base));
  display: flex;
  z-index: 1000;
  padding: 20px;
  overflow-y: auto;
}

.welcome-card {
  background: var(--bg-surface-alpha);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px 36px;
  max-width: 500px;
  width: 100%;
  text-align: center;
  box-shadow: var(--shadow);
  animation: slideUp 0.5s ease;
  margin: auto;
}

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

.welcome-avatar {
  width: 110px;
  height: 110px;
  margin: 0 auto 16px;
  animation: float 3s ease-in-out infinite;
}

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

.welcome-card h1 {
  font-size: 2.3rem;
  color: var(--primary);
  margin-bottom: 4px;
  font-weight: 800;
  letter-spacing: 1px;
}

.welcome-card .tagline {
  font-size: 0.95rem;
  color: var(--text-muted);
  margin-bottom: 20px;
}

.disclaimer-box {
  background: rgba(20, 184, 166, 0.1);
  border: 1px solid var(--teal);
  border-radius: var(--radius-sm);
  padding: 14px;
  margin: 16px 0;
  text-align: left;
}

.disclaimer-box .disclaimer-title {
  font-weight: 700;
  color: var(--teal);
  font-size: 0.85rem;
  text-transform: uppercase;
  margin-bottom: 6px;
}

.disclaimer-box p {
  font-size: 0.85rem;
  color: var(--text);
  line-height: 1.4;
}

.inputs-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 16px;
}

.name-input-wrap {
  margin: 12px 0;
  text-align: left;
}

.name-input-wrap label {
  display: block;
  font-size: 0.85rem;
  margin-bottom: 6px;
  color: var(--text-muted);
}

.name-input-wrap input,
.name-input-wrap select {
  width: 100%;
  padding: 12px 16px;
  background: var(--bg-base);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  font-family: "Outfit", sans-serif;
  font-size: 1rem;
  outline: none;
  transition: border-color 0.2s;
}

.name-input-wrap input:focus,
.name-input-wrap select:focus {
  border-color: var(--primary);
}

.btn-start {
  width: 100%;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  padding: 14px;
  font-family: "Outfit", sans-serif;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: 1px;
  cursor: pointer;
  margin-top: 10px;
  transition: background 0.2s, transform 0.1s;
}

.btn-start:hover {
  background: #0284c7;
  transform: translateY(-2px);
}

.theme-btn-welcome {
  position: absolute;
  top: 20px;
  right: 20px;
  z-index: 10;
}

/* ========================
   LAYOUT PRINCIPAL
======================== */
#app {
  display: none;
  width: 100%;
  max-width: 1200px;
  height: 100vh;
  padding: 0 20px 20px;
  flex-direction: column;
}

/* HEADER */
.app-header {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 20px 0 16px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 24px;
}

.header-avatar {
  width: 50px;
  height: 50px;
  cursor: pointer;
  transition: transform 0.2s;
}

.header-avatar:hover {
  transform: scale(1.1);
}

.header-info h2 {
  font-size: 1.4rem;
  color: var(--text);
}

.header-info .status {
  font-size: 0.8rem;
  color: var(--teal);
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 6px;
}

.status-dot {
  width: 8px;
  height: 8px;
  background: var(--teal);
  border-radius: 50%;
  animation: pulse 2s infinite;
}

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

.header-controls {
  margin-left: auto;
}

.a11y-bar {
  display: flex;
  gap: 10px;
}

.icon-btn {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  cursor: pointer;
  font-size: 1rem;
  transition: all 0.2s;
}

.icon-btn:hover, .icon-btn.active {
  background: var(--primary-light);
  border-color: var(--primary);
  color: var(--primary);
}

/* MAIN LAYOUT */
.chat-layout {
  display: grid;
  grid-template-columns: 1fr 300px;
  gap: 24px;
  align-items: stretch;
  flex: 1;
  min-height: 0;
}



/* CHAT AREA */
.chat-container {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  height: 100%;
}

.messages-area {
  padding: 24px;
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
  scroll-behavior: smooth;
}

/* Messages */
.message {
  display: flex;
  gap: 12px;
  animation: msgIn 0.3s ease;
  max-width: 85%;
}

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

.message.user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.msg-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.9rem;
}

.msg-avatar.agent-avatar {
  background: var(--primary-light);
  color: var(--primary);
}
.msg-avatar.user-avatar {
  background: var(--accent-light);
  color: var(--accent);
}

.msg-bubble {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 18px;
  font-size: 0.95rem;
  line-height: 1.6;
}

.message.user .msg-bubble {
  background: var(--primary-light);
  border-color: var(--primary);
}

.msg-bubble strong {
  color: var(--primary);
  font-weight: 700;
}

/* Typing */
.typing-indicator {
  display: flex;
  gap: 6px;
  padding: 14px 18px;
  align-items: center;
}

.typing-indicator span {
  width: 8px;
  height: 8px;
  background: var(--primary);
  border-radius: 50%;
  animation: typing 1.4s infinite;
}
.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing {
  0%, 100% { transform: translateY(0); opacity: 0.5; }
  50% { transform: translateY(-5px); opacity: 1; }
}

/* Quick reply */
.quick-replies {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding: 10px 24px 0;
}

.qr-btn {
  background: transparent;
  border: 1px solid var(--accent);
  color: var(--accent);
  border-radius: 20px;
  padding: 8px 16px;
  font-family: "Outfit", sans-serif;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.2s;
}

.qr-btn:hover {
  background: var(--accent);
  color: white;
}

/* Input area */
.input-area {
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 12px;
  align-items: flex-end;
  background: var(--bg-surface);
}

.msg-input {
  flex: 1;
  background: var(--bg-base);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  font-family: "Outfit", sans-serif;
  font-size: 1rem;
  resize: none;
  outline: none;
  min-height: 46px;
  max-height: 120px;
  transition: border-color 0.2s;
}

.msg-input:focus {
  border-color: var(--primary);
}

.send-btn, .voice-btn {
  background: var(--bg-surface-hover);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  width: 46px;
  height: 46px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
  font-size: 1.1rem;
}

.send-btn:hover, .voice-btn:hover {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
}

.voice-btn.listening {
  background: #ef4444;
  border-color: #ef4444;
  color: white;
  animation: pulseListen 1s infinite;
}

@keyframes pulseListen {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4); }
  50% { box-shadow: 0 0 0 10px rgba(239, 68, 68, 0); }
}

/* SIDEBAR */
.sidebar {
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
}

.avatar-card, .progress-card, .api-panel, .tip-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}

.avatar-big {
  width: 90px;
  height: 90px;
  margin: 0 auto 10px;
  display: block;
}

.emotion-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-align: center;
  text-transform: uppercase;
  margin-bottom: 4px;
}

.emotion-name {
  font-size: 1.2rem;
  color: var(--primary);
  text-align: center;
  font-weight: 600;
}

.emotion-dots {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-top: 12px;
}

.emotion-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--border);
  cursor: pointer;
  transition: transform 0.2s;
}

.emotion-dot.active {
  transform: scale(1.3);
}
.emotion-dot[data-emo="neutral"] { background: var(--emo-neutral); }
.emotion-dot[data-emo="happy"] { background: var(--emo-happy); }
.emotion-dot[data-emo="thinking"] { background: var(--emo-thinking); }
.emotion-dot[data-emo="surprised"] { background: var(--emo-surprised); }

/* Progress Card */
.progress-card h3, .api-panel h3, .tip-card h3 {
  font-size: 1.05rem;
  margin-bottom: 10px;
  color: var(--text);
}

.interest-tag {
  display: inline-block;
  background: var(--accent-light);
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 12px;
  padding: 6px 12px;
  font-size: 0.85rem;
  margin: 4px 2px;
}

.api-panel label {
  display: block;
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.api-panel select, .api-panel input {
  width: 100%;
  background: var(--bg-base);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px;
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
  font-family: "Outfit", sans-serif;
}

.tip-card {
  background: var(--bg-surface);
  border-left: 4px solid var(--primary);
}

.tip-card p {
  font-size: 0.9rem;
  line-height: 1.5;
  color: var(--text-muted);
}

/* Modal Info */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
}

.modal-content {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 30px;
  max-width: 500px;
  width: 90%;
  box-shadow: var(--shadow);
}

.modal-content h2 {
  color: var(--primary);
  margin-bottom: 16px;
}

.modal-content p {
  color: var(--text);
  font-size: 0.95rem;
  line-height: 1.6;
  margin-bottom: 12px;
}

.modal-logos {
  display: flex;
  gap: 16px;
  margin: 20px 0;
}

.logo-placeholder {
  background: var(--bg-base);
  border: 1px dashed var(--border);
  padding: 16px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  color: var(--text-muted);
  text-align: center;
  flex: 1;
}

/* FLASH */
.emotion-flash {
  position: fixed;
  inset: 0;
  opacity: 0;
  pointer-events: none;
  z-index: 9999;
  transition: opacity 0.5s;
}
.emotion-flash.flash {
  opacity: 0.15;
}

/* TTS BAR */
.tts-bar {
  background: var(--teal-light);
  border-left: 3px solid var(--teal);
  padding: 10px 16px;
  display: none;
  align-items: center;
  gap: 12px;
  font-size: 0.85rem;
  color: var(--teal);
  border-radius: 4px;
}
.tts-bar.active { display: flex; }

.tts-stop {
  margin-left: auto;
  background: none;
  border: 1px solid var(--teal);
  color: var(--teal);
  border-radius: 4px;
  padding: 4px 12px;
  cursor: pointer;
}

/* ACCESSIBILITY */
body.large-font {
  font-size: 1.2rem;
}
body.large-font .msg-bubble { font-size: 1.1rem; }
body.large-font .welcome-card p { font-size: 1.1rem; }

/* Modo de alto contraste: paleta negra/blanca/amarilla, bordes reforzados.
   Se aplica sobre cualquier tema (claro u oscuro) y tiene prioridad. */
body.high-contrast {
  --bg-base: #000000;
  --bg-surface: #000000;
  --bg-surface-hover: #1a1a1a;
  --bg-surface-alpha: #000000;
  --primary: #ffff00;
  --primary-light: #333300;
  --accent: #00ffff;
  --accent-light: #003333;
  --teal: #00ff00;
  --teal-light: #002200;
  --text: #ffffff;
  --text-muted: #ffffff;
  --border: #ffffff;
  --shadow: 0 0 0 1px #ffffff;
}

body.high-contrast .msg-bubble,
body.high-contrast .message.user .msg-bubble {
  background: #000000;
  border: 2px solid #ffffff;
}

body.high-contrast .interest-tag,
body.high-contrast .qr-btn,
body.high-contrast .icon-btn {
  border-width: 2px;
}

body.high-contrast .btn-start,
body.high-contrast .qr-btn:hover,
body.high-contrast .send-btn:hover,
body.high-contrast .voice-btn:hover {
  background: #ffff00;
  color: #000000;
  border-color: #ffff00;
}

body.high-contrast a,
body.high-contrast *:focus {
  outline: 2px solid #ffff00;
  outline-offset: 2px;
}

/* ========================
   RESPONSIVE DESIGN (MOBILE)
======================== */
@media (max-width: 768px) {
  #app {
    height: auto;
    min-height: 100vh;
    padding: 10px;
  }
  #welcome-screen {
    padding: 10px;
    overflow-y: auto;
    align-items: flex-start; /* Evita recortar arriba si es más grande que la pantalla */
  }
  .welcome-card {
    padding: 30px 20px;
    margin: 40px auto; /* Espacio para el botón de tema */
    max-height: none;
    overflow-y: visible;
  }
  .welcome-card h1 {
    font-size: 2rem;
  }
  .welcome-avatar {
    width: 80px;
    height: 80px;
  }
  .inputs-grid {
    grid-template-columns: 1fr;
  }
  .chat-layout {
    display: flex;
    flex-direction: column;
    gap: 16px;
  }
  .chat-container {
    height: 65vh;
    min-height: 400px;
  }
  .sidebar {
    overflow-y: visible;
  }
  .app-header {
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
    padding: 10px 0;
  }
  .header-info h2 {
    font-size: 1.2rem;
  }
  .header-controls {
    margin-left: 0;
    width: 100%;
    display: flex;
    justify-content: center;
  }
  .a11y-bar {
    width: 100%;
    justify-content: center;
  }
  .message {
    max-width: 95%;
  }
  .input-area {
    padding: 12px;
  }
  .msg-avatar {
    width: 30px;
    height: 30px;
    font-size: 0.8rem;
  }
}
