/* ============================================================
   ASESOR LEGAL IA — Light Premium Edition 2026
   Fondo blanco · Navy · Dorado · Azul profesional
   ============================================================ */

:root {
  --bg-page:      #f0f4f8;
  --bg-chat:      #f8fafc;
  --bg-bot:       #ffffff;
  --bg-user:      #1a2744;
  --navy:         #1a2744;
  --navy-light:   #253560;
  --gold:         #c9a227;
  --gold-light:   #e8b830;
  --gold-glow:    rgba(201, 162, 39, 0.2);
  --accent:       #2563eb;
  --accent-light: #3b82f6;
  --accent-glow:  rgba(37, 99, 235, 0.15);
  --text-dark:    #0f172a;
  --text-body:    #334155;
  --text-muted:   #94a3b8;
  --border:       #e2e8f0;
  --border-gold:  rgba(201, 162, 39, 0.3);
  --header-bg:    #ffffff;
  --shadow-sm:    0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md:    0 4px 16px rgba(0,0,0,0.08);
  --shadow-lg:    0 10px 40px rgba(0,0,0,0.12);
  --transition:   0.2s ease;
  --error-text:   #dc2626;
}

/* ============================================================
   RESET
   ============================================================ */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
               Helvetica, Arial, sans-serif;
  background-color: var(--bg-page);
  color: var(--text-body);
  line-height: 1.6;
  min-height: 100vh;
}

/* Fondo claro con gradiente sutil */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(ellipse at 15% 40%, rgba(37, 99, 235, 0.04) 0%, transparent 55%),
    radial-gradient(ellipse at 85% 20%, rgba(201, 162, 39, 0.06) 0%, transparent 50%),
    radial-gradient(ellipse at 50% 85%, rgba(26, 39, 68, 0.04)  0%, transparent 55%),
    #f0f4f8;
  pointer-events: none;
}

::selection {
  background: rgba(37, 99, 235, 0.15);
  color: var(--text-dark);
}

::-webkit-scrollbar       { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: var(--bg-page); }
::-webkit-scrollbar-thumb { background: var(--gold); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--gold-light); }

code {
  font-family: "Courier New", Courier, monospace;
  background: rgba(26, 39, 68, 0.07);
  color: var(--navy);
  padding: 0.15em 0.4em;
  border-radius: 4px;
  font-size: 0.88em;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ============================================================
   PARALLAX BACKGROUND — manchas sutiles claras
   ============================================================ */
#parallax-bg {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
}

.chat-page.authenticated #parallax-bg {
  display: none;
}

.parallax-layer {
  position: absolute;
  border-radius: 50%;
  filter: blur(90px);
  transition: transform 0.12s ease-out;
}

@keyframes floatShape {
  0%, 100% { transform: translateY(0) translateX(0); }
  33%       { transform: translateY(-18px) translateX(8px); }
  66%       { transform: translateY(10px) translateX(-8px); }
}

.layer-1 {
  width: 600px; height: 600px;
  top: -150px; left: -200px;
  background: var(--gold);
  opacity: 0.12;
  animation: floatShape 12s ease-in-out infinite;
}

.layer-2 {
  width: 440px; height: 440px;
  top: 20%; right: -140px;
  background: var(--accent);
  opacity: 0.08;
  animation: floatShape 9s ease-in-out infinite reverse;
}

.layer-3 {
  width: 350px; height: 350px;
  bottom: -80px; left: 38%;
  background: var(--navy);
  opacity: 0.07;
  animation: floatShape 15s ease-in-out infinite 3s;
  clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
  border-radius: 0;
}

/* ============================================================
   LOGIN OVERLAY / LIGHTBOX — blanco sobre fondo difuminado
   ============================================================ */
#login-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(6px) saturate(120%);
  -webkit-backdrop-filter: blur(6px) saturate(120%);
  transition: opacity 0.3s ease;
}

#login-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.login-modal {
  background: #ffffff;
  border: 1px solid var(--border);
  box-shadow:
    0 25px 60px rgba(15, 23, 42, 0.18),
    0 0 0 1px rgba(255,255,255,0.8) inset;
  border-radius: 24px;
  padding: 48px 40px;
  max-width: 400px;
  width: 90%;
  text-align: center;
  position: relative;
}

.modal-logo {
  max-width: 200px;
  width: 100%;
  height: auto;
  display: block;
  margin: 0 auto 20px;
  filter: drop-shadow(0 4px 12px rgba(201, 162, 39, 0.25));
}

/* Separador dorado a azul */
.modal-divider {
  width: 60px;
  height: 3px;
  background: linear-gradient(90deg, var(--gold), var(--accent));
  border-radius: 3px;
  margin: 0 auto 24px;
}

.modal-title {
  font-family: 'Inter', sans-serif;
  font-size: 17px;
  font-weight: 700;
  color: var(--navy);
  letter-spacing: -0.01em;
  margin-bottom: 28px;
}

.form-group {
  margin-bottom: 18px;
  text-align: left;
}

.form-group label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 7px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.form-group input {
  width: 100%;
  background: #f8fafc;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  color: var(--text-dark);
  font-family: inherit;
  padding: 11px 16px;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
  font-size: 16px; /* evitar zoom iOS */
}

.form-group input:focus {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px var(--gold-glow);
  background: #ffffff;
}

.form-group input::placeholder {
  color: var(--text-muted);
  font-size: 14px;
}

.btn-primary {
  width: 100%;
  background: linear-gradient(135deg, var(--navy) 0%, var(--navy-light) 100%);
  color: #ffffff;
  border: none;
  border-radius: 12px;
  font-size: 0.95rem;
  font-weight: 700;
  font-family: inherit;
  height: 50px;
  cursor: pointer;
  transition: box-shadow var(--transition), transform var(--transition);
  margin-top: 10px;
  box-shadow: 0 4px 18px rgba(26, 39, 68, 0.3);
  letter-spacing: 0.03em;
}

.btn-primary:hover {
  box-shadow: 0 8px 28px rgba(26, 39, 68, 0.4);
  transform: translateY(-2px);
}

.btn-primary:active {
  transform: scale(0.98) translateY(0);
  box-shadow: 0 2px 8px rgba(26, 39, 68, 0.2);
}

.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.spinner {
  display: inline-block;
  width: 15px;
  height: 15px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #ffffff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  vertical-align: middle;
  margin-right: 6px;
}

.error-msg {
  display: none;
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: 8px;
  color: #dc2626;
  font-size: 0.82rem;
  padding: 9px 12px;
  margin-top: 12px;
  text-align: center;
}

.error-msg.visible {
  display: block;
}

/* ============================================================
   CHAT PAGE — Layout
   ============================================================ */
.chat-page {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background: transparent;
}

/* ============================================================
   HEADER — blanco con sombra y borde dorado inferior
   ============================================================ */
.chat-header {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--header-bg);
  border-bottom: 2px solid var(--gold);
  padding: 0 20px;
  height: 64px;
  z-index: 10;
  box-shadow: var(--shadow-md);
}

.chat-header-brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.header-logo-img {
  height: 44px;
  width: auto;
  object-fit: contain;
  display: block;
  flex-shrink: 0;
}

.header-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.header-info h1 {
  font-family: 'Inter', sans-serif;
  font-size: 15px;
  font-weight: 700;
  color: var(--navy);
  letter-spacing: -0.01em;
}

.header-status {
  display: flex;
  align-items: center;
  gap: 6px;
}

@keyframes pulse {
  0%, 100% { opacity: 1; box-shadow: 0 0 0 0 rgba(37, 99, 235, 0.4); }
  50%       { opacity: 0.8; box-shadow: 0 0 0 4px rgba(37, 99, 235, 0); }
}

.status-dot {
  width: 8px;
  height: 8px;
  background: var(--accent);
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
  animation: pulse 2s ease-in-out infinite;
}

.status-text {
  font-size: 12px;
  color: var(--accent);
  font-weight: 500;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-pdf-global {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: var(--gold);
  border: none;
  color: #ffffff;
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
  padding: 7px 14px;
  border-radius: 8px;
  font-weight: 600;
  min-height: 36px;
  transition: background var(--transition), box-shadow var(--transition),
              transform var(--transition);
  box-shadow: 0 2px 8px var(--gold-glow);
}

.btn-pdf-global:hover {
  background: var(--gold-light);
  box-shadow: 0 4px 14px rgba(201,162,39,0.35);
  transform: translateY(-1px);
}

.btn-pdf-global:active { transform: scale(0.97); }

.btn-logout {
  background: transparent;
  border: 1.5px solid var(--border);
  color: var(--text-muted);
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
  padding: 7px 14px;
  border-radius: 8px;
  transition: border-color var(--transition), color var(--transition),
              background var(--transition);
  font-weight: 500;
  min-height: 36px;
}

.btn-logout:hover {
  border-color: var(--navy);
  color: var(--navy);
  background: var(--bg-page);
}

@media (max-width: 480px) {
  .btn-pdf-global { padding: 6px 10px; font-size: 11px; }
  .btn-pdf-global span { display: none; }
}

/* ============================================================
   MESSAGES AREA
   ============================================================ */
#messages {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 22px max(16px, calc(50% - 390px));
  background: transparent;
}

/* ============================================================
   ANIMACIONES
   ============================================================ */
@keyframes slideInLeft {
  from { opacity: 0; transform: translateX(-15px); }
  to   { opacity: 1; transform: translateX(0); }
}

@keyframes slideInRight {
  from { opacity: 0; transform: translateX(15px); }
  to   { opacity: 1; transform: translateX(0); }
}

/* ============================================================
   MENSAJES USUARIO — navy con texto blanco
   ============================================================ */
.message.user {
  display: flex;
  flex-direction: column;
  align-self: flex-end;
  align-items: flex-end;
  max-width: 65%;
  animation: slideInRight 0.22s ease-out forwards;
}

.message.user .bubble {
  background: var(--navy);
  color: #ffffff;
  border-radius: 18px 4px 18px 18px;
  padding: 11px 16px;
  font-size: 0.93rem;
  word-break: break-word;
  line-height: 1.55;
  box-shadow: var(--shadow-sm);
}

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

/* ============================================================
   MENSAJES ASISTENTE — blanco con borde dorado izquierdo
   ============================================================ */
.message.assistant {
  display: grid;
  grid-template-columns: 36px 1fr;
  grid-template-rows: auto auto;
  column-gap: 10px;
  align-self: flex-start;
  max-width: 75%;
  animation: slideInLeft 0.22s ease-out forwards;
}

.bot-avatar {
  grid-column: 1;
  grid-row: 1;
  align-self: end;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  overflow: hidden;
  flex-shrink: 0;
  background: #f1f5f9;
  border: 2px solid var(--gold);
  box-shadow: 0 2px 8px var(--gold-glow);
}

.bot-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.message.assistant .bubble {
  grid-column: 2;
  grid-row: 1;
  background: var(--bg-bot);
  color: var(--text-body);
  border: 1px solid var(--border);
  border-left: 3px solid var(--gold);
  border-radius: 4px 18px 18px 18px;
  padding: 12px 16px;
  font-size: 0.93rem;
  word-break: break-word;
  line-height: 1.65;
  box-shadow: var(--shadow-sm);
  min-width: 0;
}

.message.assistant .message-meta {
  grid-column: 2;
  grid-row: 2;
}

/* Cursor de escritura */
.message.assistant.streaming .bubble::after {
  content: '▌';
  color: var(--gold);
  animation: cursorBlink 0.7s step-end infinite;
  margin-left: 1px;
  font-size: 0.9em;
}

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

/* Markdown en burbuja */
.message.assistant .bubble p            { margin: 0 0 0.55em; }
.message.assistant .bubble p:last-child { margin-bottom: 0; }
.message.assistant .bubble h2           { font-size: 1.02rem; font-weight: 700; color: var(--navy); margin: 0.8em 0 0.4em; border-bottom: 1px solid var(--border); padding-bottom: 4px; }
.message.assistant .bubble h3           { font-size: 0.97rem; font-weight: 600; color: var(--navy); margin: 0.6em 0 0.3em; }
.message.assistant .bubble h4           { font-size: 0.93rem; font-weight: 600; color: var(--navy-light); margin: 0.4em 0 0.2em; }
.message.assistant .bubble ul           { padding-left: 1.3em; margin: 0.3em 0; }
.message.assistant .bubble li           { margin-bottom: 0.25em; }
.message.assistant .bubble strong       { color: var(--navy); font-weight: 700; }
.message.assistant .bubble em           { color: var(--accent); font-style: italic; }
.message.assistant .bubble table        { border-collapse: collapse; width: 100%; margin: 0.5em 0; font-size: 0.88rem; }
.message.assistant .bubble th           { background: var(--navy); color: #fff; padding: 6px 10px; text-align: left; font-weight: 600; }
.message.assistant .bubble td           { padding: 5px 10px; border-bottom: 1px solid var(--border); }
.message.assistant .bubble tr:last-child td { border-bottom: none; }

/* ============================================================
   MESSAGE META — timestamp + botones PDF/copiar
   ============================================================ */
.message-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 5px;
  padding: 0 2px;
  flex-wrap: wrap;
}

.timestamp {
  font-size: 10px;
  color: var(--text-muted);
  letter-spacing: 0.04em;
  margin-left: auto;
}

.btn-copy {
  background: transparent;
  border: 1px solid var(--border);
  cursor: pointer;
  color: var(--text-muted);
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 5px;
  transition: color var(--transition), background var(--transition),
              border-color var(--transition);
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-family: inherit;
  min-height: 26px;
}

.btn-copy:hover {
  color: var(--navy);
  border-color: var(--navy);
  background: var(--bg-page);
}

.btn-copy.copied {
  color: #16a34a;
  border-color: #86efac;
  background: #f0fdf4;
}

.btn-pdf:hover {
  color: var(--accent);
  border-color: var(--accent);
  background: rgba(37, 99, 235, 0.05);
}

/* ============================================================
   INDICADOR "Analizando..." — puntos azules
   ============================================================ */
.analyzing {
  display: flex;
  align-items: center;
  gap: 10px;
  align-self: flex-start;
  animation: slideInLeft 0.22s ease-out forwards;
}

.analyzing::before {
  content: '';
  width: 36px;
  height: 36px;
  min-width: 36px;
  border-radius: 50%;
  background: #f1f5f9 url('ialegal.jpg') center / cover no-repeat;
  border: 2px solid var(--gold);
  box-shadow: 0 0 10px var(--gold-glow);
  display: block;
  flex-shrink: 0;
  animation: avatarPulse 2s ease-in-out infinite;
}

@keyframes avatarPulse {
  0%, 100% { box-shadow: 0 0 6px var(--gold-glow); }
  50%       { box-shadow: 0 0 16px rgba(201, 162, 39, 0.4); }
}

.analyzing-dots {
  display: flex;
  gap: 5px;
  align-items: center;
  background: #ffffff;
  border: 1px solid var(--border);
  border-left: 3px solid var(--gold);
  border-radius: 4px 18px 18px 18px;
  padding: 12px 16px;
  box-shadow: var(--shadow-sm);
}

.analyzing-dots span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  display: inline-block;
  animation: typingBounce 0.8s infinite ease-in-out;
  opacity: 0.5;
}

.analyzing-dots span:nth-child(1) { animation-delay: 0s; }
.analyzing-dots span:nth-child(2) { animation-delay: 0.15s; }
.analyzing-dots span:nth-child(3) { animation-delay: 0.30s; }

@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0);   opacity: 0.4; }
  30%            { transform: translateY(-7px); opacity: 1; }
}

.analyzing > span {
  font-size: 12px;
  color: var(--accent);
  font-weight: 500;
}

/* ============================================================
   CHAT FOOTER — blanco con borde dorado superior
   ============================================================ */
.chat-footer {
  flex-shrink: 0;
  background: #ffffff;
  border-top: 2px solid var(--gold);
  padding: 14px max(16px, calc(50% - 390px));
  padding-bottom: calc(14px + env(safe-area-inset-bottom));
  z-index: 10;
  box-shadow: 0 -2px 12px rgba(0,0,0,0.06);
}

.input-row {
  display: flex;
  align-items: flex-end;
  gap: 10px;
}

#input-msg {
  flex: 1;
  background: var(--bg-page);
  border: 1.5px solid var(--border);
  border-radius: 24px;
  color: var(--text-dark);
  font-family: inherit;
  line-height: 1.55;
  padding: 12px 20px;
  resize: none;
  min-height: 48px;
  max-height: 132px;
  overflow-y: auto;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
  font-size: 16px;
}

#input-msg:focus {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px var(--gold-glow);
  background: #ffffff;
}

#input-msg::placeholder {
  color: var(--text-muted);
}

.btn-send {
  width: 48px;
  height: 48px;
  min-width: 48px;
  background: linear-gradient(135deg, var(--navy) 0%, var(--navy-light) 100%);
  border: none;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: box-shadow var(--transition), transform var(--transition);
  box-shadow: 0 4px 14px rgba(26, 39, 68, 0.3);
  flex-shrink: 0;
}

.btn-send:hover {
  box-shadow: 0 6px 20px rgba(26, 39, 68, 0.4);
  transform: scale(1.06);
}

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

.btn-send:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.btn-send svg {
  width: 20px;
  height: 20px;
  fill: #ffffff;
}

.input-hint {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 7px;
  text-align: center;
  letter-spacing: 0.02em;
}

/* ============================================================
   MENSAJE DE BIENVENIDA — navy con dorado
   ============================================================ */
.welcome-msg {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
}

.welcome-msg h2 {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--navy);
  margin-bottom: 8px;
}

.welcome-msg p {
  font-size: 0.9rem;
  line-height: 1.6;
  max-width: 420px;
  margin: 0 auto;
}

/* ============================================================
   AVISO DE LÍMITE (sistema de evaluación)
   ============================================================ */
.aviso-limite {
  background: #fffbeb;
  border: 1px solid #fde68a;
  border-left: 3px solid var(--gold);
  border-radius: 8px;
  color: #92400e;
  font-size: 0.84rem;
  padding: 10px 14px;
  margin: 4px 0;
  align-self: center;
  max-width: 70%;
  text-align: center;
}

/* ============================================================
   RESPONSIVE — MÓVIL
   ============================================================ */
@media (max-width: 768px) {
  .message.user      { max-width: 78%; }
  .message.assistant { max-width: 88%; }
}

@media (max-width: 480px) {
  .chat-header { padding: 0 12px; height: 56px; }
  .header-logo-img { height: 36px; }
  .header-info h1  { font-size: 13px; }
  .status-text     { font-size: 11px; }
  .btn-logout      { font-size: 11px; padding: 5px 10px; }

  #messages {
    padding: 14px 10px;
    gap: 10px;
  }

  .message.user      { max-width: 86%; }
  .message.assistant { max-width: 92%; grid-template-columns: 30px 1fr; }

  .bot-avatar       { width: 30px; height: 30px; }
  .analyzing::before { width: 30px; height: 30px; min-width: 30px; }

  .message.assistant .bubble, .message.user .bubble {
    font-size: 14px;
    padding: 10px 13px;
  }

  .chat-footer  { padding: 10px 10px; padding-bottom: calc(10px + env(safe-area-inset-bottom)); }
  #input-msg    { padding: 10px 16px; min-height: 44px; }
  .btn-send     { width: 44px; height: 44px; min-width: 44px; }
  .btn-send svg { width: 18px; height: 18px; }
  .input-hint   { display: none; }

  .message-meta { gap: 4px; }
  .btn-copy     { font-size: 10px; padding: 3px 6px; }

  .login-modal  { padding: 32px 24px; border-radius: 18px; }
  .modal-logo   { max-width: 160px; }
  .modal-title  { font-size: 15px; }
  .btn-primary  { height: 46px; }

  .aviso-limite { max-width: 90%; font-size: 0.8rem; }
}

@media (max-width: 360px) {
  .message.assistant .bubble, .message.user .bubble {
    font-size: 13px;
  }
  .chat-header { height: 52px; }
  .header-logo-img { height: 32px; }
}
