/* WhatsApp Look & Feel UI Theme */
:root {
  --wa-header-bg: #008069;
  --wa-header-text: #ffffff;
  --wa-chat-bg: #efeae2;
  --wa-bubble-in: #ffffff;
  --wa-bubble-out: #d9fdd3;
  --wa-bubble-text: #111b21;
  --wa-bubble-time: #667781;
  --wa-ticks-blue: #53bdeb;
  --wa-btn-primary: #00a884;
  --wa-btn-text: #ffffff;
  --wa-input-bg: #ffffff;
  --wa-input-icon: #54656f;
  --wa-radius: 8px;
  --wa-quick-reply-bg: #ffffff;
  --wa-quick-reply-border: #00a884;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html {
  height: 100%;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Segoe UI', Helvetica, Arial, sans-serif;
  background-color: #111b21;
  color: var(--wa-bubble-text);
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

.chat-app {
  width: 100%;
  max-width: 480px;
  height: 100%;
  height: 100dvh;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  background-color: var(--wa-chat-bg);
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
  overflow: hidden;
}

/* Header */
.chat-header {
  flex: 0 0 auto;
  min-height: 60px;
  background-color: var(--wa-header-bg);
  color: var(--wa-header-text);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: max(6px, env(safe-area-inset-top)) 12px 6px 12px;
  z-index: 20;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
}

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

.back-btn {
  background: none;
  border: none;
  color: #ffffff;
  cursor: pointer;
  display: flex;
  align-items: center;
}

.avatar-container {
  position: relative;
  width: 40px;
  height: 40px;
}

.avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background-color: #128c7e;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.online-indicator {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 11px;
  height: 11px;
  background-color: #25d366;
  border-radius: 50%;
  border: 2px solid var(--wa-header-bg);
}

.chat-info {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}

.chat-name {
  font-size: 16px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 5px;
}

.verified-badge {
  display: inline-block;
}

.chat-status {
  font-size: 12px;
  opacity: 0.9;
}

.progress-pill {
  background-color: rgba(255, 255, 255, 0.2);
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 500;
}

/* Body & Wallpaper */
.chat-body {
  flex: 1 1 0px;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  background-color: var(--wa-chat-bg);
  background-image: radial-gradient(#d3cbbe 1px, transparent 1px);
  background-size: 16px 16px;
  position: relative;
}

.encryption-notice {
  align-self: center;
  background-color: #ffeecd;
  color: #54656f;
  font-size: 11.5px;
  line-height: 1.3;
  padding: 6px 12px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 12px;
  text-align: center;
  max-width: 90%;
  box-shadow: 0 1px 0.5px rgba(11,20,26,.1);
}

.messages-container {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* Burbujas de Chat */
.message-row {
  display: flex;
  flex-direction: column;
  margin-bottom: 4px;
  animation: fadeIn 0.15s ease-out;
}

.message-row.bot {
  align-items: flex-start;
}

.message-row.user {
  align-items: flex-end;
}

.bubble {
  max-width: 84%;
  padding: 8px 12px 6px;
  border-radius: 8px;
  font-size: 14.5px;
  line-height: 1.4;
  position: relative;
  word-break: break-word;
  box-shadow: 0 1px 0.5px rgba(11,20,26,.13);
}

.bubble.bot-bubble {
  background-color: var(--wa-bubble-in);
  border-top-left-radius: 0;
}

.bubble.user-bubble {
  background-color: var(--wa-bubble-out);
  border-top-right-radius: 0;
}

.bubble-meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  margin-top: 3px;
  float: right;
  margin-left: 10px;
}

.time {
  font-size: 10.5px;
  color: var(--wa-bubble-time);
}

.double-tick {
  color: var(--wa-ticks-blue);
  display: flex;
  align-items: center;
}

/* Botones Rápidos (Quick Replies) */
.quick-replies-container {
  flex: 0 0 auto;
  padding: 8px 12px;
  background: rgba(239, 234, 226, 0.95);
  backdrop-filter: blur(4px);
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  max-height: 160px;
  overflow-y: auto;
  border-top: 1px solid rgba(0, 0, 0, 0.05);
  z-index: 15;
}

.quick-reply-btn {
  background-color: #ffffff;
  color: var(--wa-btn-primary);
  border: 1.5px solid var(--wa-btn-primary);
  padding: 8px 14px;
  border-radius: 20px;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
  transition: all 0.15s ease;
  display: flex;
  align-items: center;
  gap: 6px;
}

.quick-reply-btn:hover, .quick-reply-btn:active {
  background-color: var(--wa-btn-primary);
  color: #ffffff;
  transform: translateY(-1px);
}

/* Typing Indicator */
.typing-indicator {
  display: flex;
  align-items: flex-start;
  margin-top: 6px;
}

.typing-bubble {
  background-color: var(--wa-bubble-in);
  padding: 10px 14px;
  border-radius: 8px;
  border-top-left-radius: 0;
  display: flex;
  gap: 4px;
  align-items: center;
  box-shadow: 0 1px 0.5px rgba(11,20,26,.13);
}

.dot {
  width: 6px;
  height: 6px;
  background-color: #667781;
  border-radius: 50%;
  animation: bounce 1.2s infinite ease-in-out;
}

.dot:nth-child(2) { animation-delay: 0.2s; }
.dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
  40% { transform: translateY(-4px); opacity: 1; }
}

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

/* Footer / Input Bar */
.chat-footer {
  flex: 0 0 auto;
  padding: 8px 8px max(10px, env(safe-area-inset-bottom));
  background-color: #f0f2f5;
  display: flex;
  align-items: center;
  gap: 6px;
  z-index: 25;
  border-top: 1px solid rgba(0, 0, 0, 0.08);
}

.input-wrapper {
  flex: 1;
  background-color: var(--wa-input-bg);
  border-radius: 24px;
  display: flex;
  align-items: center;
  padding: 0 10px;
  height: 44px;
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.05);
}

.icon-btn {
  background: none;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 4px;
}

.input-wrapper input {
  flex: 1;
  border: none;
  outline: none;
  font-size: 16px;
  padding: 8px 8px;
  color: var(--wa-bubble-text);
  font-family: inherit;
}

.send-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background-color: var(--wa-btn-primary);
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
  transition: transform 0.1s ease;
}

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

/* Tarjeta de Finalización de Encuesta & Botón Cerrar */
.completion-card {
  align-self: center;
  background-color: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 16px;
  padding: 20px 24px;
  margin: 16px auto;
  max-width: 90%;
  text-align: center;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.08);
  animation: fadeIn 0.3s ease-out;
}

.completion-icon {
  font-size: 40px;
  margin-bottom: 8px;
  line-height: 1;
}

.completion-title {
  font-size: 17px;
  font-weight: 700;
  color: #111b21;
  margin-bottom: 6px;
}

.completion-desc {
  font-size: 13.5px;
  color: #667781;
  line-height: 1.45;
  margin-bottom: 16px;
}

.completion-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
}

.btn-close-window {
  background-color: #00a884;
  color: #ffffff;
  border: none;
  border-radius: 24px;
  padding: 10px 22px;
  font-size: 14.5px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  box-shadow: 0 2px 6px rgba(0, 168, 132, 0.35);
  transition: all 0.2s ease;
}

.btn-close-window:hover {
  background-color: #008f6f;
  transform: translateY(-1px);
  box-shadow: 0 4px 10px rgba(0, 168, 132, 0.45);
}

.btn-close-window:active {
  transform: scale(0.97);
}

.close-hint {
  margin-top: 14px;
  padding: 8px 12px;
  background-color: #f0fdf4;
  border: 1px solid #bbf7d0;
  border-radius: 8px;
  font-size: 12.5px;
  color: #166534;
  line-height: 1.4;
  animation: fadeIn 0.2s ease-out;
}

/* Footer cuando la encuesta finaliza */
.footer-completed-wrap {
  width: 100%;
  display: flex;
  justify-content: center;
  padding: 4px 0;
}

.btn-close-footer {
  width: 100%;
  max-width: 400px;
  background-color: #00a884;
  color: #ffffff;
  border: none;
  border-radius: 24px;
  padding: 12px 20px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  box-shadow: 0 2px 8px rgba(0, 168, 132, 0.35);
  transition: all 0.2s ease;
}

.btn-close-footer:hover {
  background-color: #008f6f;
}
