/* =====================================================================
   Address Solutions AI Sales Consultant — Chatbot Widget Styles
   Namespaced under #as-chatbot-root so it cannot collide with any
   existing site CSS. Uses the site's own --color-primary / --color-blue
   variables when present, with safe fallbacks otherwise.
   ===================================================================== */

#as-chatbot-root {
  --as-primary: var(--color-primary, #B51217);
  --as-primary-dark: var(--color-primary-dark, #8E0E12);
  --as-blue: var(--color-blue, #1B4E9B);
  --as-ink: var(--color-ink, #1A1A1A);
  --as-bg: #ffffff;
  --as-bg-alt: #F7F7F7;
  --as-border: #E7E7E7;
  --as-radius: 16px;
  --as-shadow: 0 12px 40px rgba(0,0,0,0.18);
  font-family: var(--font-body, 'Poppins', sans-serif);
  position: fixed;
  z-index: 999999;
  right: 20px;
  bottom: 20px;
}

#as-chatbot-root * { box-sizing: border-box; }

/* --- Floating launcher button ---------------------------------------- */
.as-launcher {
  width: 62px;
  height: 62px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--as-primary), var(--as-primary-dark));
  box-shadow: var(--as-shadow);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  transition: transform 0.25s ease, box-shadow 0.25s ease;
  position: relative;
}
.as-launcher:hover { transform: scale(1.06); }
.as-launcher svg { width: 28px; height: 28px; }
.as-launcher .as-dot {
  position: absolute;
  top: 2px; right: 2px;
  width: 14px; height: 14px;
  background: #23C55E;
  border: 2px solid #fff;
  border-radius: 50%;
}

/* --- Chat panel -------------------------------------------------------- */
/* Safe-zone math keeps the panel fully on-screen and below the fixed
   72px navbar (73px incl. border) with a 25px breathing gap, on every
   page, at every breakpoint. bottom-offset is the existing distance
   between the panel and the viewport bottom (unchanged). */
#as-chatbot-root {
  --as-navbar-safe: 98px; /* 73px fixed navbar + 25px gap below it */
}
.as-panel {
  position: fixed;
  right: 20px;
  bottom: 96px;
  width: 380px;
  max-width: calc(100vw - 32px);
  height: min(65vh, calc(100vh - var(--as-navbar-safe) - 96px));
  max-height: min(65vh, calc(100vh - var(--as-navbar-safe) - 96px));
  background: var(--as-bg);
  border-radius: var(--as-radius);
  box-shadow: var(--as-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  transform: translateX(28px) scale(0.98);
  pointer-events: none;
  transition: opacity 0.3s cubic-bezier(0.22, 1, 0.36, 1), transform 0.3s cubic-bezier(0.22, 1, 0.36, 1);
}
#as-chatbot-root.as-open .as-panel {
  opacity: 1;
  transform: translateX(0) scale(1);
  pointer-events: auto;
}
#as-chatbot-root.as-open .as-launcher .as-icon-chat { display: none; }
#as-chatbot-root.as-open .as-launcher .as-icon-close { display: flex; }
.as-launcher .as-icon-close { display: none; }

/* --- Header -------------------------------------------------------------- */
.as-header {
  background: linear-gradient(135deg, var(--as-primary), var(--as-blue));
  color: #fff;
  padding: 11px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.as-header .as-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: rgba(255,255,255,0.18);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.as-header .as-avatar svg { width: 17px; height: 17px; }
.as-header-text { flex: 1; min-width: 0; }
.as-header-text h4 { margin: 0; font-size: 14.5px; font-weight: 700; color: #FFFFFF; }
.as-header-text p { margin: 1px 0 0; font-size: 11.5px; opacity: 0.9; font-weight: 500; color: #FFFFFF; }
.as-header-text p::before {
  content: ''; display: inline-block; width: 7px; height: 7px;
  background: #23C55E; border-radius: 50%; margin-right: 5px;
}

/* --- Header close button --------------------------------------------- */
.as-close-btn {
  flex-shrink: 0;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: #FFFFFF;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  transition: background-color 0.25s ease, transform 0.25s ease;
}
.as-close-btn svg { width: 18px; height: 18px; }
.as-close-btn:hover { background: rgba(255,255,255,0.2); transform: scale(1.05); }
.as-close-btn:active { background: rgba(255,255,255,0.3); transform: scale(0.95); }

/* --- Messages ------------------------------------------------------------ */
.as-messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--as-bg-alt);
}
.as-msg {
  max-width: 84%;
  padding: 8px 12px;
  border-radius: 14px;
  font-size: 13.5px;
  line-height: 1.45;
  font-weight: 500;
  white-space: pre-wrap;
  word-break: break-word;
  animation: as-fade-in 0.2s ease;
}
@keyframes as-fade-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }
.as-msg.as-bot {
  align-self: flex-start;
  background: #fff;
  color: var(--as-ink);
  border: 1px solid var(--as-border);
  border-bottom-left-radius: 4px;
}
.as-msg.as-user {
  align-self: flex-end;
  background: var(--as-primary);
  color: #fff;
  border-bottom-right-radius: 4px;
}

/* --- Typing indicator ------------------------------------------------------ */
.as-typing {
  align-self: flex-start;
  display: flex;
  gap: 4px;
  padding: 12px 14px;
  background: #fff;
  border: 1px solid var(--as-border);
  border-radius: 14px;
  border-bottom-left-radius: 4px;
}
.as-typing span {
  width: 6px; height: 6px; border-radius: 50%;
  background: #b7b7b7;
  animation: as-bounce 1.2s infinite ease-in-out;
}
.as-typing span:nth-child(2) { animation-delay: 0.15s; }
.as-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes as-bounce { 0%, 60%, 100% { transform: translateY(0); opacity: 0.5; } 30% { transform: translateY(-5px); opacity: 1; } }

/* --- Quick reply buttons ------------------------------------------------ */
.as-quick-replies {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 12px 10px;
  background: var(--as-bg-alt);
}
.as-quick-btn {
  border: 1.5px solid var(--as-primary);
  color: var(--as-primary);
  background: #fff;
  border-radius: 20px;
  padding: 6px 12px;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}
.as-quick-btn:hover { background: var(--as-primary); color: #fff; }

/* --- Input row ------------------------------------------------------------ */
.as-input-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 10px;
  border-top: 1px solid var(--as-border);
  background: #fff;
}
.as-input-row input {
  flex: 1;
  border: 1.5px solid var(--as-border);
  border-radius: 22px;
  padding: 8px 14px;
  font-size: 13.5px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s ease;
}
.as-input-row input:focus { border-color: var(--as-primary); }
.as-send-btn {
  width: 34px; height: 34px;
  border-radius: 50%;
  border: none;
  background: var(--as-primary);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s ease;
}
.as-send-btn:hover { background: var(--as-primary-dark); }
.as-send-btn svg { width: 17px; height: 17px; }
.as-send-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.as-wa-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: #25D366;
  color: #fff;
  border: none;
  border-radius: 20px;
  padding: 8px 14px;
  font-size: 12.5px;
  font-weight: 700;
  cursor: pointer;
  margin-top: 4px;
}

/* --- Smart navigation action button (matches the panel's own tokens) --- */
.as-nav-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: linear-gradient(135deg, var(--as-primary), var(--as-blue));
  color: #fff;
  border: none;
  border-radius: 20px;
  padding: 8px 14px;
  font-size: 12.5px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  margin-top: 6px;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.as-nav-btn:hover { transform: translateY(-1px); box-shadow: 0 4px 12px rgba(0,0,0,0.18); }

/* --- Dark mode -------------------------------------------------------- */
@media (prefers-color-scheme: dark) {
  #as-chatbot-root.as-auto-dark .as-panel { background: #17181C; }
  #as-chatbot-root.as-auto-dark .as-messages { background: #101115; }
  #as-chatbot-root.as-auto-dark .as-msg.as-bot { background: #1F2127; color: #EDEDED; border-color: #2A2C33; }
  #as-chatbot-root.as-auto-dark .as-input-row { background: #17181C; border-color: #2A2C33; }
  #as-chatbot-root.as-auto-dark .as-input-row input { background: #1F2127; color: #fff; border-color: #2A2C33; }
  #as-chatbot-root.as-auto-dark .as-quick-replies { background: #101115; }
  #as-chatbot-root.as-auto-dark .as-quick-btn { background: #1F2127; }
  #as-chatbot-root.as-auto-dark .as-typing { background: #1F2127; border-color: #2A2C33; }
}

/* --- Tablet --------------------------------------------------------------- */
@media (max-width: 1024px) and (min-width: 481px) {
  .as-panel {
    width: 340px;
    height: min(65vh, calc(100vh - var(--as-navbar-safe) - 96px));
    max-height: min(65vh, calc(100vh - var(--as-navbar-safe) - 96px));
  }
}

/* --- Mobile ------------------------------------------------------------- */
@media (max-width: 480px) {
  .as-panel {
    right: 5vw;
    left: 5vw;
    width: auto; /* right+left at 5vw each = 90vw panel width */
    bottom: 86px;
    height: min(60vh, calc(100vh - var(--as-navbar-safe) - 86px));
    max-height: min(60vh, calc(100vh - var(--as-navbar-safe) - 86px));
  }
  #as-chatbot-root { right: 14px; bottom: 14px; }
}
