/* ================================================
   Diamond Dave Chatbot Styles
   Diamond Masonry & Waterproofing
   ================================================ */

/* --- Chatbot Toggle Button --- */
.chatbot-toggle {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  width: 62px;
  height: 62px;
  background-color: #1B4F8A;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 20px rgba(27, 79, 138, 0.5);
  z-index: 9999;
  transition: transform 0.25s ease, background-color 0.25s ease;
}

.chatbot-toggle:hover {
  transform: scale(1.08);
  background-color: #163E6E;
}

.chatbot-toggle-icon {
  font-size: 1.5rem;
  color: #ffffff;
  transition: transform 0.25s ease;
  line-height: 1;
}

.chatbot-toggle.open .chatbot-toggle-icon-chat {
  display: none;
}

.chatbot-toggle.open .chatbot-toggle-icon-close {
  display: block;
}

.chatbot-toggle-icon-close {
  display: none;
  font-size: 1.25rem;
}

/* Pulse ring animation */
.chatbot-toggle::before {
  content: '';
  position: absolute;
  inset: -6px;
  border-radius: 50%;
  border: 2px solid rgba(27, 79, 138, 0.5);
  animation: chatbot-pulse 2.5s ease-out infinite;
}

@keyframes chatbot-pulse {
  0% { transform: scale(1); opacity: 0.8; }
  100% { transform: scale(1.45); opacity: 0; }
}

/* Notification badge */
.chatbot-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  width: 20px;
  height: 20px;
  background-color: #D4A017;
  color: #1C1C1C;
  border-radius: 50%;
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Open Sans', sans-serif;
}

/* --- Tooltip --- */
.chatbot-tooltip {
  position: fixed;
  bottom: 7rem;
  right: 2rem;
  background-color: #1B4F8A;
  color: #ffffff;
  padding: 0.75rem 1rem;
  border-radius: 8px 8px 0 8px;
  font-size: 0.85rem;
  font-family: 'Open Sans', sans-serif;
  max-width: 220px;
  line-height: 1.4;
  box-shadow: 0 4px 20px rgba(0,0,0,0.3);
  z-index: 9998;
  animation: tooltip-in 0.3s ease;
  cursor: pointer;
}

.chatbot-tooltip::after {
  content: '';
  position: absolute;
  bottom: -8px;
  right: 18px;
  border: 8px solid transparent;
  border-top-color: #1B4F8A;
  border-bottom: none;
}

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

.chatbot-tooltip-close {
  position: absolute;
  top: 4px;
  right: 6px;
  background: none;
  border: none;
  color: rgba(255,255,255,0.6);
  cursor: pointer;
  font-size: 0.9rem;
  line-height: 1;
  padding: 2px 4px;
}

.chatbot-tooltip-close:hover { color: #ffffff; }

/* --- Chatbot Panel --- */
.chatbot-panel {
  position: fixed;
  bottom: 6rem;
  right: 2rem;
  width: 380px;
  height: 550px;
  background-color: #1C1C1C;
  border: 1px solid #1B4F8A;
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  box-shadow: 0 8px 40px rgba(0,0,0,0.5), 0 0 0 1px rgba(27,79,138,0.2);
  z-index: 9998;
  overflow: hidden;
  transform: scale(0.9) translateY(20px);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.3s ease, opacity 0.3s ease;
  transform-origin: bottom right;
}

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

/* Panel Header */
.chatbot-header {
  background: linear-gradient(135deg, #163E6E, #1B4F8A);
  padding: 1rem 1.25rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-shrink: 0;
  border-bottom: 1px solid rgba(255,255,255,0.1);
}

.chatbot-avatar {
  width: 42px;
  height: 42px;
  background-color: rgba(255,255,255,0.15);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  flex-shrink: 0;
}

.chatbot-header-info {
  flex: 1;
}

.chatbot-name {
  font-family: 'Oswald', sans-serif;
  font-size: 1rem;
  font-weight: 700;
  color: #ffffff;
  letter-spacing: 0.05em;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.chatbot-status {
  font-size: 0.75rem;
  color: rgba(255,255,255,0.7);
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.status-dot {
  width: 7px;
  height: 7px;
  background-color: #4ade80;
  border-radius: 50%;
  animation: status-blink 2s infinite;
}

@keyframes status-blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.chatbot-header-close {
  background: none;
  border: none;
  color: rgba(255,255,255,0.6);
  cursor: pointer;
  font-size: 1.25rem;
  padding: 4px;
  transition: color 0.2s;
  line-height: 1;
}

.chatbot-header-close:hover { color: #ffffff; }

/* Emergency banner */
.chatbot-emergency-banner {
  background-color: #8B2500;
  padding: 0.5rem 1rem;
  text-align: center;
  font-size: 0.78rem;
  color: #ffffff;
  font-family: 'Open Sans', sans-serif;
  display: none;
  animation: emergency-flash 1s ease infinite alternate;
}

.chatbot-emergency-banner a {
  color: #FFD700;
  font-weight: 700;
  text-decoration: none;
}

@keyframes emergency-flash {
  from { background-color: #8B2500; }
  to { background-color: #6B1C00; }
}

/* Messages Area */
.chatbot-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  scrollbar-width: thin;
  scrollbar-color: #444 transparent;
}

.chatbot-messages::-webkit-scrollbar { width: 4px; }
.chatbot-messages::-webkit-scrollbar-track { background: transparent; }
.chatbot-messages::-webkit-scrollbar-thumb { background-color: #444; border-radius: 4px; }

/* Message Bubbles */
.chat-message {
  display: flex;
  gap: 0.6rem;
  max-width: 90%;
  animation: message-in 0.25s ease;
}

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

.chat-message.bot { align-self: flex-start; }
.chat-message.user { align-self: flex-end; flex-direction: row-reverse; }

.chat-message-avatar {
  width: 28px;
  height: 28px;
  background-color: #1B4F8A;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  flex-shrink: 0;
  margin-top: auto;
}

.chat-bubble {
  padding: 0.65rem 0.9rem;
  border-radius: 12px;
  font-size: 0.875rem;
  line-height: 1.55;
  font-family: 'Open Sans', sans-serif;
}

.chat-message.bot .chat-bubble {
  background-color: #2A2A2A;
  color: #CCCCCC;
  border: 1px solid #3A3A3A;
  border-bottom-left-radius: 4px;
}

.chat-message.user .chat-bubble {
  background-color: #1B4F8A;
  color: #ffffff;
  border-bottom-right-radius: 4px;
}

.chat-bubble a {
  color: #D4A017;
  text-decoration: underline;
}

/* Emergency message style */
.chat-message.emergency .chat-bubble {
  background-color: rgba(139, 37, 0, 0.3);
  border: 1px solid #8B2500;
  color: #ffffff;
}

/* Typing indicator */
.chat-typing {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 0.65rem 0.9rem;
  background-color: #2A2A2A;
  border: 1px solid #3A3A3A;
  border-radius: 12px;
  border-bottom-left-radius: 4px;
  width: fit-content;
}

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

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

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

/* Quick Replies */
.chat-quick-replies {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.25rem;
  padding-left: 34px;
}

.quick-reply-btn {
  background-color: transparent;
  border: 1px solid #1B4F8A;
  color: #1B4F8A;
  border-radius: 20px;
  padding: 0.35rem 0.85rem;
  font-size: 0.78rem;
  font-family: 'Open Sans', sans-serif;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.quick-reply-btn:hover {
  background-color: #1B4F8A;
  color: #ffffff;
}

/* Lead form in chat */
.chat-form {
  background-color: #2A2A2A;
  border: 1px solid #3A3A3A;
  border-radius: 12px;
  border-bottom-left-radius: 4px;
  padding: 1rem;
  width: 100%;
}

.chat-form h5 {
  font-family: 'Oswald', sans-serif;
  font-size: 0.9rem;
  color: #ffffff;
  margin-bottom: 0.75rem;
}

.chat-input-group {
  margin-bottom: 0.6rem;
}

.chat-input-group label {
  display: block;
  font-size: 0.7rem;
  color: #999;
  margin-bottom: 0.25rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-family: 'Oswald', sans-serif;
}

.chat-input {
  width: 100%;
  background-color: #3A3A3A;
  border: 1px solid #444;
  border-radius: 4px;
  color: #ffffff;
  font-size: 0.85rem;
  padding: 0.5rem 0.75rem;
  font-family: 'Open Sans', sans-serif;
  transition: border-color 0.2s;
}

.chat-input:focus {
  outline: none;
  border-color: #1B4F8A;
}

.chat-input::placeholder { color: #555; }

.chat-form-btn {
  width: 100%;
  background-color: #D4A017;
  color: #1C1C1C;
  border: none;
  border-radius: 4px;
  padding: 0.6rem;
  font-family: 'Oswald', sans-serif;
  font-size: 0.9rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
  margin-top: 0.25rem;
  transition: background-color 0.2s;
}

.chat-form-btn:hover { background-color: #B8880F; }

/* Input Area */
.chatbot-input-area {
  padding: 0.75rem 1rem;
  border-top: 1px solid #333;
  display: flex;
  gap: 0.5rem;
  align-items: flex-end;
  flex-shrink: 0;
  background-color: #222;
}

.chatbot-input {
  flex: 1;
  background-color: #2A2A2A;
  border: 1px solid #444;
  border-radius: 20px;
  color: #ffffff;
  font-size: 0.875rem;
  padding: 0.6rem 1rem;
  font-family: 'Open Sans', sans-serif;
  resize: none;
  max-height: 100px;
  overflow-y: auto;
  transition: border-color 0.2s;
  line-height: 1.4;
}

.chatbot-input:focus {
  outline: none;
  border-color: #1B4F8A;
}

.chatbot-input::placeholder { color: #555; }

.chatbot-send {
  width: 38px;
  height: 38px;
  background-color: #1B4F8A;
  border: none;
  border-radius: 50%;
  color: #ffffff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.2s, transform 0.2s;
  flex-shrink: 0;
}

.chatbot-send:hover {
  background-color: #163E6E;
  transform: scale(1.05);
}

.chatbot-send:disabled {
  background-color: #333;
  cursor: not-allowed;
  transform: none;
}

/* Footer note */
.chatbot-footer-note {
  text-align: center;
  padding: 0.4rem 0.75rem 0.6rem;
  font-size: 0.68rem;
  color: #555;
  font-family: 'Open Sans', sans-serif;
  background-color: #222;
}

.chatbot-footer-note a { color: #1B4F8A; }

/* --- Tablet / mid-range: lift chatbot above the fixed cta-bar --- */
@media (min-width: 481px) and (max-width: 767px) {
  .chatbot-toggle {
    bottom: calc(58px + env(safe-area-inset-bottom) + 1rem);
    right: 1.25rem;
  }

  .chatbot-tooltip {
    bottom: calc(58px + env(safe-area-inset-bottom) + 5.5rem);
    right: 1.25rem;
  }

  .chatbot-panel {
    bottom: calc(58px + env(safe-area-inset-bottom) + 5rem);
    right: 1.25rem;
  }
}

@media (min-width: 768px) and (max-width: 1024px) {
  .chatbot-toggle {
    bottom: calc(64px + env(safe-area-inset-bottom) + 1rem);
  }

  .chatbot-tooltip {
    bottom: calc(64px + env(safe-area-inset-bottom) + 5.5rem);
  }

  .chatbot-panel {
    bottom: calc(64px + env(safe-area-inset-bottom) + 5rem);
  }
}

/* --- Mobile Chatbot --- */
@media (max-width: 480px) {
  .chatbot-panel {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    top: auto;
    width: 100vw;
    max-width: 100vw;
    height: 80vh;
    border-radius: 16px 16px 0 0;
    box-sizing: border-box;
    transform-origin: bottom center;
    overflow: hidden;
    z-index: 10000;
    padding-bottom: calc(58px + env(safe-area-inset-bottom));
  }

  .chatbot-messages {
    max-width: 100%;
    overflow-x: hidden;
  }

  .chat-message {
    max-width: 95%;
  }

  .chat-bubble {
    word-break: break-word;
    overflow-wrap: break-word;
  }

  .chat-quick-replies {
    max-width: 100%;
    overflow-x: hidden;
  }

  .quick-reply-btn {
    white-space: normal;
    text-align: left;
  }

  .chatbot-input-area {
    box-sizing: border-box;
    width: 100%;
  }

  .chatbot-toggle {
    bottom: calc(58px + env(safe-area-inset-bottom) + 1.25rem);
    right: 1.25rem;
  }

  .chatbot-tooltip {
    bottom: calc(58px + env(safe-area-inset-bottom) + 5.5rem);
    right: 1.25rem;
    max-width: calc(100vw - 2.5rem);
    box-sizing: border-box;
  }
}
