/* ═══════════════════════════════════════════════════════
   Chat Widget — Jornada Control / Landing Page
   ═══════════════════════════════════════════════════════ */

:root {
  --chat-accent: #3b82f6;
  --chat-accent-dark: #1d4ed8;
  --chat-success: #10b981;
  --chat-bg: #ffffff;
  --chat-surface: #f8fafc;
  --chat-border: #e2e8f0;
  --chat-text: #0f172a;
  --chat-muted: #64748b;
  --chat-input-bg: #f1f5f9;
  --chat-shadow: 0 24px 64px rgba(0,0,0,.18), 0 4px 16px rgba(0,0,0,.1);
  --chat-radius: 18px;
  --chat-z: 9990;
}

/* ── Floating Button ── */
#chat-fab {
  position: fixed;
  bottom: 28px;
  right: 28px;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: linear-gradient(135deg, #3b82f6, #1d4ed8);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 28px rgba(59,130,246,.45);
  transition: transform .22s cubic-bezier(.34,1.56,.64,1), box-shadow .22s ease;
  z-index: var(--chat-z);
  outline: none;
}
#chat-fab:hover {
  transform: scale(1.1);
  box-shadow: 0 12px 36px rgba(59,130,246,.55);
}
#chat-fab:active { transform: scale(.96); }
#chat-fab svg { width: 26px; height: 26px; fill: #fff; transition: opacity .2s; }
#chat-fab .chat-fab-close { display: none; }
#chat-fab.is-open .chat-fab-icon { display: none; }
#chat-fab.is-open .chat-fab-close { display: block; }

/* Unread dot */
#chat-fab-badge {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 12px;
  height: 12px;
  background: #ef4444;
  border-radius: 50%;
  border: 2px solid #fff;
  display: none;
}
#chat-fab-badge.visible { display: block; }

/* Pulse ring */
#chat-fab::before {
  content: '';
  position: absolute;
  inset: -6px;
  border-radius: 50%;
  border: 2px solid rgba(59,130,246,.4);
  animation: chat-pulse 2.4s ease infinite;
}
@keyframes chat-pulse {
  0%,100% { transform: scale(1); opacity: 0.8; }
  50%      { transform: scale(1.18); opacity: 0; }
}

/* ── Panel ── */
#chat-panel {
  position: fixed;
  bottom: 100px;
  right: 28px;
  width: 360px;
  max-height: 560px;
  background: var(--chat-bg);
  border-radius: var(--chat-radius);
  box-shadow: var(--chat-shadow);
  display: flex;
  flex-direction: column;
  z-index: var(--chat-z);
  overflow: hidden;
  opacity: 0;
  transform: translateY(16px) scale(.97);
  pointer-events: none;
  transition: opacity .25s ease, transform .25s cubic-bezier(.34,1.56,.64,1);
}
#chat-panel.is-open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: all;
}

/* Header */
.chat-header {
  background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
  padding: 18px 20px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}
.chat-header-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: linear-gradient(135deg, #3b82f6, #1d4ed8);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  color: #fff;
  flex-shrink: 0;
}
.chat-header-info { flex: 1; }
.chat-header-name {
  font-size: 14px;
  font-weight: 700;
  color: #fff;
  letter-spacing: -.2px;
}
.chat-header-status {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-top: 2px;
  font-size: 11.5px;
  color: #94a3b8;
}
.chat-status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #10b981;
  flex-shrink: 0;
}
.chat-header-close {
  background: none;
  border: none;
  cursor: pointer;
  color: #64748b;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s, color .15s;
}
.chat-header-close:hover { background: rgba(255,255,255,.1); color: #fff; }
.chat-header-close svg { width: 16px; height: 16px; fill: currentColor; }

/* Body */
.chat-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  background: var(--chat-surface);
  min-height: 0;
}
.chat-body::-webkit-scrollbar { width: 4px; }
.chat-body::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 4px; }

/* Greeting */
.chat-greeting { margin-bottom: 18px; }
.chat-greeting-bubble {
  background: #fff;
  border: 1px solid var(--chat-border);
  border-radius: 14px 14px 14px 4px;
  padding: 12px 15px;
  font-size: 13.5px;
  line-height: 1.55;
  color: var(--chat-text);
  box-shadow: 0 2px 8px rgba(0,0,0,.04);
}
.chat-greeting-time {
  font-size: 11px;
  color: var(--chat-muted);
  margin-top: 5px;
  padding-left: 4px;
}

/* User info card (logged in) */
.chat-user-card {
  background: #fff;
  border: 1px solid var(--chat-border);
  border-radius: 12px;
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 11px;
  margin-bottom: 16px;
}
.chat-user-card-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, #3b82f6, #8b5cf6);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}
.chat-user-card-name { font-size: 13px; font-weight: 600; color: var(--chat-text); }
.chat-user-card-sub { font-size: 11.5px; color: var(--chat-muted); margin-top: 1px; }
.chat-auto-badge {
  margin-left: auto;
  font-size: 10.5px;
  font-weight: 600;
  background: #dcfce7;
  color: #166534;
  padding: 2px 8px;
  border-radius: 20px;
  white-space: nowrap;
}

/* Form fields */
.chat-field { margin-bottom: 10px; }
.chat-field label {
  display: block;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--chat-muted);
  text-transform: uppercase;
  letter-spacing: .5px;
  margin-bottom: 5px;
}
.chat-input {
  width: 100%;
  background: var(--chat-input-bg);
  border: 1.5px solid var(--chat-border);
  border-radius: 10px;
  padding: 9px 12px;
  font-size: 13.5px;
  color: var(--chat-text);
  font-family: inherit;
  transition: border-color .18s, box-shadow .18s;
  box-sizing: border-box;
  outline: none;
}
.chat-input:focus {
  border-color: var(--chat-accent);
  box-shadow: 0 0 0 3px rgba(59,130,246,.12);
  background: #fff;
}
.chat-input.is-error {
  border-color: #ef4444;
  box-shadow: 0 0 0 3px rgba(239,68,68,.1);
}
.chat-textarea { resize: none; min-height: 90px; }

/* Error hint */
.chat-field-error {
  font-size: 11.5px;
  color: #ef4444;
  margin-top: 4px;
  display: none;
}
.chat-field-error.visible { display: block; }

/* Success state */
.chat-success {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px 16px;
  gap: 12px;
}
.chat-success.visible { display: flex; }
.chat-success-icon {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: linear-gradient(135deg, #10b981, #059669);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 24px rgba(16,185,129,.3);
}
.chat-success-icon svg { width: 28px; height: 28px; fill: #fff; }
.chat-success h3 { font-size: 15px; font-weight: 700; color: var(--chat-text); margin: 0; }
.chat-success p { font-size: 13px; color: var(--chat-muted); line-height: 1.5; margin: 0; }
.chat-success-new {
  margin-top: 4px;
  background: none;
  border: 1.5px solid var(--chat-border);
  border-radius: 8px;
  padding: 7px 16px;
  font-size: 13px;
  color: var(--chat-muted);
  cursor: pointer;
  font-family: inherit;
  transition: border-color .15s, color .15s;
}
.chat-success-new:hover { border-color: var(--chat-accent); color: var(--chat-accent); }

/* Footer / Send */
.chat-footer {
  flex-shrink: 0;
  padding: 14px 20px 16px;
  background: var(--chat-bg);
  border-top: 1px solid var(--chat-border);
}
.chat-send-btn {
  width: 100%;
  background: linear-gradient(135deg, var(--chat-accent), var(--chat-accent-dark));
  border: none;
  border-radius: 11px;
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  padding: 11px 0;
  cursor: pointer;
  font-family: inherit;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: opacity .18s, transform .15s;
  letter-spacing: -.1px;
}
.chat-send-btn:hover { opacity: .92; }
.chat-send-btn:active { transform: scale(.98); }
.chat-send-btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.chat-send-btn svg { width: 16px; height: 16px; fill: #fff; }
.chat-spinner {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255,255,255,.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: chat-spin .7s linear infinite;
  display: none;
}
.chat-send-btn.loading .chat-spinner { display: block; }
.chat-send-btn.loading .chat-send-label { display: none; }
.chat-send-btn.loading svg { display: none; }

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

/* Rate limit notice */
.chat-ratelimit {
  text-align: center;
  font-size: 11.5px;
  color: var(--chat-muted);
  margin-top: 8px;
  display: none;
}
.chat-ratelimit.visible { display: block; }

/* ── Mobile ── */
@media (max-width: 480px) {
  #chat-panel {
    right: 0;
    bottom: 0;
    width: 100%;
    max-height: 92dvh;
    border-radius: var(--chat-radius) var(--chat-radius) 0 0;
  }
  #chat-fab {
    bottom: 20px;
    right: 20px;
  }
}
