/* Cardwell Chatbot Widget Styles */

/* ── Reset for widget scope ─────────────────────────────────────────── */
#cw-chatbot *, #cw-chatbot *::before, #cw-chatbot *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

#cw-chatbot,
#cw-chatbot input,
#cw-chatbot button,
#cw-chatbot textarea {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* ── Floating Bubble ────────────────────────────────────────────────── */
#cw-chatbot-bubble-wrap {
  position: fixed;
  bottom: 6px;
  right: 6px;
  width: 120px;
  height: 120px;
  z-index: 99999;
  cursor: pointer;
}
#cw-chatbot-bubble {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 64px;
  height: 64px;
  border-radius: 50%;
  cursor: pointer;
  border: 3px solid #250c64;
  overflow: hidden;
  box-shadow: 0 4px 20px rgba(37, 12, 100, 0.35);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  animation: cw-pulse 3s ease-in-out infinite;
}
#cw-chatbot-bubble-wrap:hover #cw-chatbot-bubble {
  transform: translate(-50%, -50%) scale(1.08);
  box-shadow: 0 6px 28px rgba(37, 12, 100, 0.5);
}
#cw-chatbot-ring {
  position: absolute;
  top: 0;
  left: 0;
  width: 120px;
  height: 120px;
  animation: cw-ring-spin 18s linear infinite;
  pointer-events: none;
}
#cw-chatbot-ring svg {
  filter: drop-shadow(0 0 3px rgba(255,255,255,0.9)) drop-shadow(0 0 6px rgba(255,255,255,0.5));
}
#cw-chatbot-bubble-wrap:hover #cw-chatbot-ring {
  animation-play-state: paused;
}
@keyframes cw-ring-spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}
#cw-chatbot-bubble img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
@keyframes cw-pulse {
  0%, 100% { box-shadow: 0 4px 20px rgba(37, 12, 100, 0.35); }
  50% { box-shadow: 0 4px 20px rgba(37, 12, 100, 0.55), 0 0 0 8px rgba(37, 12, 100, 0.1); }
}

/* ── Chat Panel ─────────────────────────────────────────────────────── */
#cw-chatbot-panel {
  position: fixed;
  bottom: 100px;
  right: 24px;
  width: 380px;
  height: 520px;
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.18);
  z-index: 99998;
  display: none;
  flex-direction: column;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}
#cw-chatbot-panel.cw-open {
  display: flex;
}

/* ── Header ─────────────────────────────────────────────────────────── */
#cw-chatbot-header {
  background: #250c64;
  color: #fff;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}
#cw-chatbot-header img {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.3);
  object-fit: cover;
}
#cw-chatbot-header-info {
  flex: 1;
}
#cw-chatbot-header-name {
  font-weight: 700;
  font-size: 15px;
  line-height: 1.2;
}
#cw-chatbot-header-sub {
  font-size: 12px;
  opacity: 0.8;
}
#cw-chatbot-close {
  background: none;
  border: none;
  color: #fff;
  font-size: 22px;
  cursor: pointer;
  padding: 4px;
  line-height: 1;
  opacity: 0.7;
  transition: opacity 0.15s;
}
#cw-chatbot-close:hover { opacity: 1; }

/* ── Messages ───────────────────────────────────────────────────────── */
#cw-chatbot-messages {
  flex: 1;
  overflow-y: auto;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: #f9fafb;
  -webkit-overflow-scrolling: touch;
}
.cw-msg-wrapper {
  display: flex;
  flex-direction: column;
  max-width: 85%;
}
.cw-msg-wrapper-user {
  align-self: flex-end;
  align-items: flex-end;
}
.cw-msg-name {
  font-size: 11px;
  font-weight: 600;
  color: #9ca3af;
  margin-bottom: 3px;
  padding: 0 4px;
}
.cw-msg-name-user {
  text-align: right;
}
.cw-msg {
  max-width: 85%;
  padding: 14px 20px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: normal;
  overflow-wrap: break-word;
  overflow: visible;
  animation: cw-fadein 0.2s ease;
}
.cw-msg > p,
.cw-msg > div {
  margin: 0;
}
.cw-msg ul,
.cw-msg ol {
  margin: 0.35em 0;
  padding-left: 1.15em;
}
.cw-msg li {
  margin: 0.2em 0;
}
.cw-msg-wrapper .cw-msg {
  max-width: 100%;
}
.cw-msg-bot {
  align-self: flex-start;
  background: #fff;
  color: #1d2240;
  border: 1px solid #e5e7eb;
  border-bottom-left-radius: 6px;
  padding-left: 24px !important;
}
.cw-msg-user {
  align-self: flex-end;
  background: #ce0d2d;
  color: #fff;
  border-bottom-right-radius: 6px;
  padding-left: 24px !important;
}
.cw-msg-typing {
  align-self: flex-start;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-bottom-left-radius: 6px;
  padding: 10px 14px;
  color: #9ca3af;
  font-style: italic;
  font-size: 13px;
}
@keyframes cw-fadein {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ── Lead Capture Form ──────────────────────────────────────────────── */
#cw-chatbot-form {
  padding: 14px 16px;
  background: #fff;
  border-top: 1px solid #e5e7eb;
  display: none;
  flex-direction: column;
  gap: 8px;
  flex-shrink: 0;
}
#cw-chatbot-form.cw-show { display: flex; }
#cw-chatbot-form label {
  font-size: 12px;
  font-weight: 600;
  color: #374151;
}
#cw-chatbot-form input {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  font-size: 13px;
  outline: none;
  transition: border-color 0.15s;
}
#cw-chatbot-form input:focus {
  border-color: #250c64;
}
#cw-chatbot-form-submit {
  background: #250c64;
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
#cw-chatbot-form-submit:hover { background: #3a1a8a; }
#cw-chatbot-form-submit:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* ── Input bar ──────────────────────────────────────────────────────── */
#cw-chatbot-input-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid #e5e7eb;
  background: #fff;
  flex-shrink: 0;
}
#cw-chatbot-input {
  flex: 1;
  border: 1px solid #d1d5db;
  border-radius: 20px;
  padding: 10px 16px;
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s;
}
#cw-chatbot-input:focus {
  border-color: #250c64;
}
#cw-chatbot-send {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: #ce0d2d;
  border: none;
  color: #fff;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
  flex-shrink: 0;
}
#cw-chatbot-send:hover { background: #a80b24; }
#cw-chatbot-send:disabled { opacity: 0.5; cursor: not-allowed; }

/* ── Mobile ─────────────────────────────────────────────────────────── */
@media (max-width: 480px) {
  #cw-chatbot-panel {
    width: calc(100vw - 16px);
    left: 8px;
    right: 8px;
    /*
     * Bubble wrap: 120px tall, bottom = 4px + safe-area ≈ 4+34 = 38px on iPhone
     * Bubble wrap top edge = 38 + 120 = 158px from bottom.
     * Panel must start above that: 158px + 8px gap = 166px → use 144px + safe-area
     * (env() adds the same offset so net gap is always 140px above the ground).
     * Height: dvh minus bottom offset minus 16px top clearance.
     */
    bottom: calc(144px + env(safe-area-inset-bottom, 0px));
    height: calc(100dvh - 160px - env(safe-area-inset-bottom, 0px));
    height: calc(100vh - 160px);
    max-height: calc(100dvh - 160px - env(safe-area-inset-bottom, 0px));
    border-radius: 12px;
  }
  #cw-chatbot-bubble-wrap {
    bottom: calc(4px + env(safe-area-inset-bottom, 0px));
    right: 8px;
  }
}
