/* ============================================================================
   CHAT-WIDGET.CSS — Asistente WhatsApp simulado
   Bot IA tipo WhatsApp Web · Mant & Service · Calama
   ============================================================================ */

.chat-launcher {
  position: fixed;
  bottom: var(--space-6);
  right: var(--space-6);
  z-index: var(--z-chat);
  display: inline-flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4) var(--space-3) var(--space-3);
  background: var(--color-whatsapp);
  color: white;
  border: none;
  border-radius: var(--radius-pill);
  font-family: var(--font-body);
  font-weight: 600;
  font-size: var(--type-sm);
  cursor: pointer;
  box-shadow: 0 8px 28px rgba(37, 211, 102, 0.40), 0 4px 8px rgba(0, 0, 0, 0.15);
  transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}

.chat-launcher:hover {
  transform: translateY(-3px);
  box-shadow: 0 12px 32px rgba(37, 211, 102, 0.50), 0 8px 16px rgba(0, 0, 0, 0.18);
}

.chat-launcher-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  background: white;
  color: var(--color-whatsapp);
  border-radius: 50%;
  flex-shrink: 0;
}

.chat-launcher-text { line-height: 1.1; text-align: left; }

.chat-launcher-text small {
  display: block;
  font-size: 0.7rem;
  opacity: 0.85;
  font-weight: 500;
}

.chat-launcher-pulse {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 12px;
  height: 12px;
  background: #FF3B30;
  border-radius: 50%;
  border: 2px solid white;
  animation: chat-pulse 2s infinite;
}

@keyframes chat-pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50%      { transform: scale(1.15); opacity: 0.85; }
}

@media (max-width: 767px) {
  .chat-launcher {
    bottom: calc(var(--space-16) + env(safe-area-inset-bottom) + var(--space-4));
  }

  .chat-launcher-text { display: none; }

  .chat-launcher {
    padding: var(--space-2);
    border-radius: 50%;
  }
}

/* ============================================================================
   CHAT WINDOW
   ============================================================================ */

.chat-window {
  position: fixed;
  bottom: calc(var(--space-6) + 60px);
  right: var(--space-6);
  width: 380px;
  max-width: calc(100vw - 32px);
  height: 600px;
  max-height: calc(100vh - 100px);
  background: #ECE5DD;
  border-radius: var(--radius-lg);
  box-shadow:
    0 20px 60px rgba(0, 0, 0, 0.30),
    0 8px 16px rgba(0, 0, 0, 0.15);
  z-index: var(--z-chat);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: scale(0.92) translateY(20px);
  opacity: 0;
  pointer-events: none;
  transition: transform var(--transition-spring), opacity var(--transition-fast);
}

.chat-window--open {
  transform: scale(1) translateY(0);
  opacity: 1;
  pointer-events: all;
}

@media (max-width: 767px) {
  .chat-window {
    bottom: 0;
    right: 0;
    left: 0;
    width: 100%;
    max-width: 100%;
    height: 100dvh;
    max-height: 100dvh;
    border-radius: 0;
  }
}

/* Chat header */
.chat-header {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-4);
  background: linear-gradient(135deg, var(--mas-blue) 0%, var(--mas-blue-deep) 100%);
  color: white;
  flex-shrink: 0;
}

.chat-avatar {
  width: 44px;
  height: 44px;
  background: white;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  position: relative;
}

.chat-avatar-status {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 12px;
  height: 12px;
  background: #5DD49F;
  border-radius: 50%;
  border: 2px solid white;
}

.chat-info {
  flex: 1;
  min-width: 0;
}

.chat-info-name {
  font-family: var(--font-body);
  font-weight: 700;
  font-size: var(--type-base);
  line-height: 1.2;
}

.chat-info-status {
  font-family: var(--font-body);
  font-size: 0.75rem;
  opacity: 0.85;
  margin-top: 2px;
}

.chat-actions {
  display: flex;
  gap: var(--space-2);
}

.chat-action {
  background: rgba(255, 255, 255, 0.10);
  border: none;
  color: white;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background var(--transition-fast);
}

.chat-action:hover { background: rgba(255, 255, 255, 0.18); }

/* Chat body */
.chat-body {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-4);
  background-color: #ECE5DD;
  background-image:
    radial-gradient(circle at 25px 25px, rgba(0, 0, 0, 0.02) 1px, transparent 1px),
    radial-gradient(circle at 75px 75px, rgba(0, 0, 0, 0.02) 1px, transparent 1px);
  background-size: 100px 100px;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.chat-day-marker {
  align-self: center;
  background: rgba(255, 255, 255, 0.7);
  font-family: var(--font-body);
  font-size: 0.7rem;
  color: #54656F;
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-sm);
  margin: var(--space-3) 0;
  font-weight: 500;
}

/* Messages */
.chat-msg {
  max-width: 78%;
  padding: var(--space-3) var(--space-4);
  font-family: var(--font-body);
  font-size: var(--type-sm);
  line-height: 1.45;
  word-wrap: break-word;
  position: relative;
  border-radius: var(--radius-md);
  animation: msg-in 0.25s ease forwards;
}

@keyframes msg-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.chat-msg-time {
  font-size: 0.65rem;
  color: rgba(0, 0, 0, 0.45);
  margin-left: var(--space-2);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.chat-msg--bot {
  align-self: flex-start;
  background: white;
  color: #111B21;
  border-top-left-radius: 2px;
}

.chat-msg--bot::before {
  content: "";
  position: absolute;
  top: 0;
  left: -8px;
  width: 0;
  height: 0;
  border: 8px solid transparent;
  border-right-color: white;
  border-top-color: white;
  border-left-width: 0;
  border-bottom-width: 0;
}

.chat-msg--user {
  align-self: flex-end;
  background: #D9FDD3;
  color: #111B21;
  border-top-right-radius: 2px;
}

.chat-msg--user::before {
  content: "";
  position: absolute;
  top: 0;
  right: -8px;
  width: 0;
  height: 0;
  border: 8px solid transparent;
  border-left-color: #D9FDD3;
  border-top-color: #D9FDD3;
  border-right-width: 0;
  border-bottom-width: 0;
}

.chat-msg-text { display: block; }

.chat-msg-meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-1);
  margin-top: var(--space-1);
}

.chat-msg-checks {
  font-size: 0.85rem;
  color: var(--mas-blue);
  line-height: 1;
}

/* Quick replies / chips */
.chat-quick-replies {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  align-self: flex-start;
  max-width: 90%;
  margin-top: var(--space-2);
}

.chat-quick-reply {
  background: white;
  color: var(--mas-blue);
  border: 1px solid var(--mas-blue);
  border-radius: var(--radius-pill);
  padding: var(--space-2) var(--space-4);
  font-family: var(--font-body);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.chat-quick-reply:hover {
  background: var(--mas-blue);
  color: white;
}

/* Typing indicator */
.chat-typing {
  align-self: flex-start;
  background: white;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  border-top-left-radius: 2px;
  display: inline-flex;
  align-items: center;
  gap: 3px;
}

.chat-typing-dot {
  width: 7px;
  height: 7px;
  background: #54656F;
  border-radius: 50%;
  animation: typing-bounce 1.4s infinite ease-in-out both;
}

.chat-typing-dot:nth-child(1) { animation-delay: -0.32s; }
.chat-typing-dot:nth-child(2) { animation-delay: -0.16s; }

@keyframes typing-bounce {
  0%, 80%, 100% { transform: scale(0.7); opacity: 0.5; }
  40%           { transform: scale(1); opacity: 1; }
}

/* Card-style rich message (servicios, agendamiento) */
.chat-card {
  background: white;
  border-radius: var(--radius-md);
  overflow: hidden;
  align-self: flex-start;
  max-width: 90%;
  border-top-left-radius: 2px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.06);
}

.chat-card-header {
  background: var(--mas-blue);
  color: white;
  padding: var(--space-3) var(--space-4);
  font-family: var(--font-body);
  font-weight: 700;
  font-size: var(--type-sm);
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.chat-card-body {
  padding: var(--space-4);
  font-family: var(--font-body);
  font-size: 0.85rem;
  color: #111B21;
  line-height: 1.5;
}

.chat-card-body strong { color: var(--mas-blue-deep); }

.chat-card-body ul {
  list-style: none;
  padding: 0;
  margin: var(--space-2) 0;
}

.chat-card-body li {
  padding: var(--space-1) 0;
  display: flex;
  align-items: start;
  gap: var(--space-2);
}

.chat-card-body li::before {
  content: "→";
  color: var(--mas-blue);
  font-weight: 700;
  flex-shrink: 0;
}

.chat-card-cta {
  display: block;
  background: #F7F8FA;
  padding: var(--space-3) var(--space-4);
  text-align: center;
  font-family: var(--font-body);
  font-weight: 600;
  font-size: var(--type-sm);
  color: var(--mas-blue);
  text-decoration: none;
  border-top: 1px solid rgba(0, 0, 0, 0.06);
  transition: background var(--transition-fast);
}

.chat-card-cta:hover {
  background: var(--mas-blue-tint);
  color: var(--mas-blue-deep);
  text-decoration: none;
}

/* Footer / input */
.chat-footer {
  padding: var(--space-3);
  background: #F0F2F5;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-shrink: 0;
  border-top: 1px solid rgba(0, 0, 0, 0.05);
}

.chat-input {
  flex: 1;
  background: white;
  border: none;
  border-radius: var(--radius-pill);
  padding: var(--space-3) var(--space-4);
  font-family: var(--font-body);
  font-size: var(--type-sm);
  color: #111B21;
  outline: none;
  transition: box-shadow var(--transition-fast);
}

.chat-input:focus {
  box-shadow: 0 0 0 2px var(--mas-blue);
}

.chat-send {
  background: var(--mas-blue);
  color: white;
  border: none;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: background var(--transition-fast), transform var(--transition-fast);
}

.chat-send:hover { background: var(--mas-blue-deep); transform: scale(1.05); }
.chat-send:disabled { background: #BDC3C7; cursor: not-allowed; }

/* Disclaimer below */
.chat-disclaimer {
  font-family: var(--font-body);
  font-size: 0.65rem;
  color: #54656F;
  text-align: center;
  padding: var(--space-2) var(--space-4);
  background: #F0F2F5;
  border-top: 1px solid rgba(0, 0, 0, 0.05);
}
