/* ═══════════════════════════════════════════════════════════════════
   FRASEG · Asesor Virtual v4.0 — Estilos del widget
   ───────────────────────────────────────────────────────────────────
   Diseño e implementación: Edilberto Díaz Salazar
   Copyright (c) 2026 Edilberto Díaz Salazar. Todos los derechos reservados.
   Huella: EDS-FRG-4.0-Q7K3 / CSS
   ═══════════════════════════════════════════════════════════════════ */

#fraseg-chat {
  --eds-navy: #0D1B2E;
  --eds-navy-2: #16294a;
  --eds-gold: #C0A030;
  --eds-gold-soft: #f6efd6;
  --eds-ink: #1d2733;
  --eds-muted: #6b7686;
  --eds-line: #e6e9ef;
  --eds-bg: #f5f7fa;
  --eds-bot: #ffffff;
  --eds-wa: #1fa855;
  --eds-ok: #2ecc71;
  --eds-off: #f0a020;
  --eds-radius: 18px;
  --eds-font: 'DM Sans', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 9999;
  font-family: var(--eds-font);
  color: var(--eds-ink);
}
#fraseg-chat *, #fraseg-chat *::before, #fraseg-chat *::after { box-sizing: border-box; }

/* ── Botón flotante ─────────────────────────────────────────────── */
#fraseg-chat #chat-toggle {
  width: 64px; height: 64px; border-radius: 50%;
  border: 2px solid var(--eds-gold);
  background: radial-gradient(circle at 30% 30%, var(--eds-navy-2), var(--eds-navy));
  box-shadow: 0 10px 30px rgba(13, 27, 46, .35);
  display: grid; place-items: center; cursor: pointer; position: relative;
  transition: transform .25s ease, box-shadow .25s ease;
  padding: 0;
}
#fraseg-chat #chat-toggle:hover { transform: translateY(-2px) scale(1.04); box-shadow: 0 14px 34px rgba(13, 27, 46, .45); }
#fraseg-chat #chat-toggle:focus-visible { outline: 3px solid var(--eds-gold); outline-offset: 3px; }
#fraseg-chat #chat-toggle svg { width: 28px; height: 28px; stroke: var(--eds-gold); }
#fraseg-chat #chat-toggle::after {
  content: ''; position: absolute; inset: -6px; border-radius: 50%;
  border: 2px solid var(--eds-gold); opacity: 0; animation: eds-pulse 2.6s ease-out 3s 3;
}
#fraseg-chat.abierto #chat-toggle::after { animation: none; }
#fraseg-chat #chat-notif {
  position: absolute; top: -4px; right: -4px; min-width: 22px; height: 22px; padding: 0 6px;
  border-radius: 11px; background: #e74c3c; color: #fff; font-size: 12px; font-weight: 700;
  display: none; align-items: center; justify-content: center; border: 2px solid #fff;
}
#fraseg-chat #chat-teaser {
  position: absolute; right: 76px; bottom: 10px; width: max-content; max-width: 240px;
  background: #fff; color: var(--eds-ink); padding: 10px 14px; border-radius: 14px 14px 4px 14px;
  box-shadow: 0 8px 24px rgba(13, 27, 46, .18); font-size: 14px; line-height: 1.35;
  opacity: 0; transform: translateY(6px); pointer-events: none; transition: all .35s ease;
}
#fraseg-chat #chat-teaser.visible { opacity: 1; transform: none; pointer-events: auto; cursor: pointer; }
#fraseg-chat.abierto #chat-teaser { display: none; }

/* ── Ventana ────────────────────────────────────────────────────── */
#fraseg-chat #chat-window {
  position: absolute; right: 0; bottom: 80px;
  width: 390px; height: min(640px, calc(100vh - 120px));
  background: var(--eds-bg); border-radius: var(--eds-radius);
  box-shadow: 0 24px 60px rgba(13, 27, 46, .28), 0 0 0 1px rgba(13, 27, 46, .06);
  display: flex; flex-direction: column; overflow: hidden;
  opacity: 0; transform: translateY(16px) scale(.98); transform-origin: bottom right;
  pointer-events: none; visibility: hidden;
  transition: opacity .25s ease, transform .25s ease, visibility 0s linear .25s;
}
#fraseg-chat #chat-window.open {
  opacity: 1; transform: none; pointer-events: auto; visibility: visible;
  transition: opacity .25s ease, transform .25s ease;
}

/* Cabecera */
#fraseg-chat .chat-header {
  display: flex; align-items: center; gap: 12px; padding: 14px 14px 14px 16px;
  background: linear-gradient(135deg, var(--eds-navy) 0%, var(--eds-navy-2) 100%);
  color: #fff; border-bottom: 3px solid var(--eds-gold);
}
#fraseg-chat .chat-avatar {
  width: 42px; height: 42px; border-radius: 12px; flex: none;
  background: rgba(192, 160, 48, .14); border: 1px solid rgba(192, 160, 48, .55);
  display: grid; place-items: center;
}
#fraseg-chat .chat-avatar svg { width: 22px; height: 22px; stroke: var(--eds-gold); fill: none; }
#fraseg-chat .chat-header-info { flex: 1; min-width: 0; line-height: 1.25; }
#fraseg-chat .chat-header-info strong { display: block; font-family: 'Playfair Display', Georgia, serif; font-size: 16.5px; letter-spacing: .2px; }
#fraseg-chat #chat-estado { font-size: 12.5px; color: rgba(255, 255, 255, .78); display: flex; align-items: center; gap: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#fraseg-chat .dot-estado { width: 8px; height: 8px; border-radius: 50%; background: #9aa4b2; flex: none; }
#fraseg-chat .dot-estado.on { background: var(--eds-ok); box-shadow: 0 0 0 3px rgba(46, 204, 113, .25); }
#fraseg-chat .dot-estado.off { background: var(--eds-off); }
#fraseg-chat .chat-hbtn {
  width: 34px; height: 34px; border-radius: 10px; border: 0; background: transparent; color: rgba(255, 255, 255, .8);
  display: grid; place-items: center; cursor: pointer; transition: background .2s, color .2s; padding: 0; font-size: 16px;
}
#fraseg-chat .chat-hbtn:hover { background: rgba(255, 255, 255, .1); color: #fff; }
#fraseg-chat .chat-hbtn:focus-visible { outline: 2px solid var(--eds-gold); }
#fraseg-chat .chat-hbtn svg { width: 18px; height: 18px; stroke: currentColor; fill: none; }

/* Mensajes */
#fraseg-chat #chat-messages {
  flex: 1; overflow-y: auto; padding: 18px 14px 8px; display: flex; flex-direction: column; gap: 10px;
  scroll-behavior: smooth; overscroll-behavior: contain;
}
#fraseg-chat #chat-messages::-webkit-scrollbar { width: 6px; }
#fraseg-chat #chat-messages::-webkit-scrollbar-thumb { background: #cfd5de; border-radius: 3px; }
#fraseg-chat .msg { display: flex; gap: 8px; align-items: flex-end; max-width: 100%; animation: eds-in .28s ease both; }
#fraseg-chat .msg.user { justify-content: flex-end; }
#fraseg-chat .msg-avatar {
  width: 28px; height: 28px; border-radius: 9px; flex: none; background: var(--eds-navy); color: var(--eds-gold);
  font-family: 'Playfair Display', Georgia, serif; font-weight: 700; font-size: 14px; display: grid; place-items: center;
}
#fraseg-chat .msg-col { display: flex; flex-direction: column; gap: 6px; max-width: 84%; min-width: 0; }
#fraseg-chat .msg.user .msg-col { align-items: flex-end; }
#fraseg-chat .msg-bubble {
  padding: 10px 14px; border-radius: 16px; font-size: 14.5px; line-height: 1.5; word-wrap: break-word; overflow-wrap: anywhere;
}
#fraseg-chat .msg.bot .msg-bubble { background: var(--eds-bot); border: 1px solid var(--eds-line); border-bottom-left-radius: 5px; box-shadow: 0 1px 2px rgba(13, 27, 46, .04); }
#fraseg-chat .msg.user .msg-bubble { background: var(--eds-navy); color: #fff; border-bottom-right-radius: 5px; }
#fraseg-chat .msg-bubble strong { font-weight: 700; color: inherit; }
#fraseg-chat .msg.bot .msg-bubble strong { color: var(--eds-navy); }
#fraseg-chat .msg-bubble a { color: #0b6aa2; font-weight: 600; text-decoration: underline; text-underline-offset: 2px; }
#fraseg-chat .msg-bubble ul { margin: 6px 0 2px; padding-left: 18px; }
#fraseg-chat .msg-bubble li { margin: 2px 0; }
#fraseg-chat .msg-bubble p { margin: 0 0 8px; }
#fraseg-chat .msg-bubble p:last-child { margin-bottom: 0; }
#fraseg-chat .msg-hora { font-size: 11px; color: var(--eds-muted); padding: 0 4px; }

/* Tarjeta de acción (WhatsApp) */
#fraseg-chat .msg-accion {
  display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%;
  background: var(--eds-wa); color: #fff !important; text-decoration: none !important;
  border-radius: 12px; padding: 12px 14px; font-weight: 700; font-size: 14.5px;
  box-shadow: 0 6px 16px rgba(31, 168, 85, .3); transition: transform .15s, box-shadow .15s, filter .15s;
}
#fraseg-chat .msg-accion:hover { transform: translateY(-1px); filter: brightness(1.05); box-shadow: 0 8px 20px rgba(31, 168, 85, .38); }
#fraseg-chat .msg-accion svg { width: 18px; height: 18px; fill: #fff; flex: none; }
#fraseg-chat .msg-accion.enviado { background: #e9f8ef; color: var(--eds-wa) !important; box-shadow: none; border: 1px solid #bfe9cf; }
#fraseg-chat .msg-accion.enviado svg { fill: var(--eds-wa); }

/* Escribiendo… */
#fraseg-chat .typing .msg-bubble { display: flex; gap: 4px; padding: 14px 16px; }
#fraseg-chat .typing .dot { width: 7px; height: 7px; border-radius: 50%; background: #aab3c0; animation: eds-bounce 1.2s infinite ease-in-out; }
#fraseg-chat .typing .dot:nth-child(2) { animation-delay: .15s; }
#fraseg-chat .typing .dot:nth-child(3) { animation-delay: .3s; }

/* Sugerencias (chips) */
#fraseg-chat #chat-chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 4px 14px 10px; }
#fraseg-chat #chat-chips:empty { display: none; }
#fraseg-chat .chip {
  border: 1.5px solid var(--eds-gold); background: #fff; color: var(--eds-navy);
  border-radius: 999px; padding: 7px 13px; font: 600 13px/1.1 var(--eds-font); cursor: pointer;
  transition: background .18s, color .18s, transform .18s; animation: eds-in .3s ease both;
}
#fraseg-chat .chip:hover { background: var(--eds-gold-soft); transform: translateY(-1px); }
#fraseg-chat .chip:focus-visible { outline: 2px solid var(--eds-navy); outline-offset: 2px; }

/* Entrada */
#fraseg-chat .chat-input-area {
  display: flex; align-items: flex-end; gap: 8px; padding: 10px 12px; background: #fff; border-top: 1px solid var(--eds-line); margin: 0;
}
#fraseg-chat #chat-input {
  flex: 1; resize: none; border: 1.5px solid var(--eds-line); border-radius: 14px; padding: 10px 14px;
  font: 15px/1.4 var(--eds-font); color: var(--eds-ink); background: var(--eds-bg); max-height: 110px; min-height: 42px;
  outline: none; transition: border-color .2s, background .2s;
}
#fraseg-chat #chat-input:focus { border-color: var(--eds-gold); background: #fff; }
#fraseg-chat #chat-input:disabled { opacity: .6; }
#fraseg-chat #chat-send {
  width: 42px; height: 42px; border-radius: 12px; border: 0; flex: none; cursor: pointer;
  background: var(--eds-navy); display: grid; place-items: center; transition: background .2s, transform .15s; padding: 0;
}
#fraseg-chat #chat-send:hover:not(:disabled) { background: var(--eds-navy-2); transform: scale(1.04); }
#fraseg-chat #chat-send:disabled { opacity: .45; cursor: default; }
#fraseg-chat #chat-send svg { width: 18px; height: 18px; stroke: var(--eds-gold); fill: none; }
#fraseg-chat .chat-legal {
  font-size: 11px; color: var(--eds-muted); text-align: center; padding: 0 14px 10px; background: #fff; line-height: 1.4;
}
#fraseg-chat .chat-legal a { color: var(--eds-muted); text-decoration: underline; }

/* ── Móvil: pantalla completa ───────────────────────────────────── */
@media (max-width: 520px) {
  #fraseg-chat { right: 16px; bottom: 16px; }
  #fraseg-chat #chat-window {
    position: fixed; inset: 0; width: 100%; height: 100%; height: 100dvh; border-radius: 0; bottom: 0;
  }
  #fraseg-chat.abierto #chat-toggle { display: none; }
  #fraseg-chat #chat-teaser { right: 72px; }
  #fraseg-chat #chat-input { font-size: 16px; } /* evita zoom en iOS */
}

/* ── Animaciones ────────────────────────────────────────────────── */
@keyframes eds-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes eds-bounce { 0%, 80%, 100% { transform: translateY(0); opacity: .5; } 40% { transform: translateY(-5px); opacity: 1; } }
@keyframes eds-pulse { 0% { opacity: .7; transform: scale(1); } 100% { opacity: 0; transform: scale(1.35); } }
@media (prefers-reduced-motion: reduce) {
  #fraseg-chat *, #fraseg-chat *::before, #fraseg-chat *::after { animation: none !important; transition: none !important; }
}
