/* ==========================================================================
   3Lions.ca AI Chatbot Widget
   Design · Develop · Automate

   Floating chat widget styles — self-contained, high z-index.
   Uses tokens.css custom properties with hardcoded fallbacks for
   standalone operation.
   ========================================================================== */

/* --------------------------------------------------------------------------
   TOGGLE BUTTON — Floating circle, bottom-right
   -------------------------------------------------------------------------- */
#chatbot-toggle {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  width: 56px;
  height: 56px;
  border-radius: var(--radius-full, 9999px);
  border: none;
  background-color: var(--color-navy, #012169);
  color: var(--color-white, #FFFFFF);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-lg, 0 4px 8px rgba(0,0,0,0.04), 0 8px 24px rgba(0,0,0,0.1));
  transition: transform var(--duration-normal, 250ms) var(--ease-default, cubic-bezier(0.25,0.1,0.25,1)),
              background-color var(--duration-fast, 150ms) var(--ease-default, cubic-bezier(0.25,0.1,0.25,1)),
              box-shadow var(--duration-normal, 250ms) var(--ease-default, cubic-bezier(0.25,0.1,0.25,1));
}

#chatbot-toggle:hover {
  background-color: var(--color-navy-light, #1B3A8C);
  transform: scale(1.08);
  box-shadow: var(--shadow-xl, 0 8px 16px rgba(0,0,0,0.06), 0 16px 48px rgba(0,0,0,0.12));
}

#chatbot-toggle:active {
  transform: scale(0.96);
}

#chatbot-toggle:focus-visible {
  outline: 2px solid var(--color-red, #CF081F);
  outline-offset: 3px;
}

#chatbot-toggle svg {
  width: 26px;
  height: 26px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Hide button when panel is open */
#chatbot-toggle.chatbot-hidden {
  opacity: 0;
  pointer-events: none;
  transform: scale(0.5);
}

/* --------------------------------------------------------------------------
   CHAT PANEL — Fixed bottom-right, slides up from toggle position
   -------------------------------------------------------------------------- */
.chatbot-panel {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  width: 380px;
  height: 520px;
  max-height: calc(100vh - 48px);
  display: flex;
  flex-direction: column;
  border-radius: var(--radius-lg, 12px);
  overflow: hidden;
  background-color: var(--color-white, #FFFFFF);
  box-shadow: var(--shadow-xl, 0 8px 16px rgba(0,0,0,0.06), 0 16px 48px rgba(0,0,0,0.12));

  /* Slide-up animation */
  transform: translateY(20px) scale(0.95);
  opacity: 0;
  visibility: hidden;
  transition: transform var(--duration-slow, 400ms) var(--ease-out, cubic-bezier(0,0,0.2,1)),
              opacity var(--duration-slow, 400ms) var(--ease-out, cubic-bezier(0,0,0.2,1)),
              visibility 0ms linear var(--duration-slow, 400ms);
}

.chatbot-panel.chatbot-open {
  transform: translateY(0) scale(1);
  opacity: 1;
  visibility: visible;
  transition: transform var(--duration-slow, 400ms) var(--ease-out, cubic-bezier(0,0,0.2,1)),
              opacity var(--duration-slow, 400ms) var(--ease-out, cubic-bezier(0,0,0.2,1)),
              visibility 0ms linear 0ms;
}

/* --------------------------------------------------------------------------
   HEADER — Navy bar with title and close button
   -------------------------------------------------------------------------- */
.chatbot-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  background-color: var(--color-navy, #012169);
  color: var(--color-white, #FFFFFF);
  flex-shrink: 0;
}

.chatbot-title {
  font-family: var(--font-primary, 'Roboto', sans-serif);
  font-weight: var(--fw-bold, 700);
  font-size: var(--fs-body, 1rem);
  line-height: var(--lh-tight, 1.1);
  letter-spacing: var(--ls-normal, 0);
  white-space: nowrap;
}

.chatbot-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: var(--radius-sm, 4px);
  background: transparent;
  color: var(--color-white, #FFFFFF);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  transition: background-color var(--duration-fast, 150ms) var(--ease-default, ease);
}

.chatbot-close:hover {
  background-color: rgba(255, 255, 255, 0.15);
}

.chatbot-close:focus-visible {
  outline: 2px solid var(--color-white, #FFFFFF);
  outline-offset: -2px;
}

/* --------------------------------------------------------------------------
   MESSAGE AREA — Scrollable conversation history
   -------------------------------------------------------------------------- */
.chatbot-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background-color: var(--color-white, #FFFFFF);
  scroll-behavior: smooth;
}

/* Scrollbar styling */
.chatbot-messages::-webkit-scrollbar {
  width: 6px;
}

.chatbot-messages::-webkit-scrollbar-track {
  background: transparent;
}

.chatbot-messages::-webkit-scrollbar-thumb {
  background-color: var(--color-gray-300, #C8C8D4);
  border-radius: var(--radius-full, 9999px);
}

.chatbot-messages::-webkit-scrollbar-thumb:hover {
  background-color: var(--color-gray-400, #9898AC);
}

/* --------------------------------------------------------------------------
   MESSAGE BUBBLES
   -------------------------------------------------------------------------- */
.chatbot-msg {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: var(--radius-md, 8px);
  font-family: var(--font-primary, 'Roboto', sans-serif);
  font-size: var(--fs-small, 0.875rem);
  font-weight: var(--fw-regular, 400);
  line-height: var(--lh-body, 1.6);
  word-wrap: break-word;
  overflow-wrap: break-word;

  /* Entrance animation */
  animation: chatbot-msg-in var(--duration-normal, 250ms) var(--ease-out, cubic-bezier(0,0,0.2,1)) both;
}

/* Assistant messages — left-aligned, off-white bg */
.chatbot-msg--assistant {
  align-self: flex-start;
  background-color: var(--color-off-white, #F5F5F7);
  color: var(--color-text, #1A1A2E);
  border-bottom-left-radius: 2px;
}

/* User messages — right-aligned, light navy bg */
.chatbot-msg--user {
  align-self: flex-end;
  background-color: rgba(1, 33, 105, 0.08);
  color: var(--color-text, #1A1A2E);
  border-bottom-right-radius: 2px;
}

/* Links inside messages */
.chatbot-msg a {
  color: var(--color-navy, #012169);
  font-weight: var(--fw-medium, 500);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.chatbot-msg a:hover {
  color: var(--color-red, #CF081F);
}

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

/* --------------------------------------------------------------------------
   TYPING INDICATOR — Three bouncing dots
   -------------------------------------------------------------------------- */
.chatbot-typing {
  align-self: flex-start;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 12px 16px;
  background-color: var(--color-off-white, #F5F5F7);
  border-radius: var(--radius-md, 8px);
  border-bottom-left-radius: 2px;
}

.chatbot-typing-dot {
  width: 7px;
  height: 7px;
  border-radius: var(--radius-full, 9999px);
  background-color: var(--color-gray-400, #9898AC);
  animation: chatbot-bounce 1.2s ease-in-out infinite;
}

.chatbot-typing-dot:nth-child(2) {
  animation-delay: 0.15s;
}

.chatbot-typing-dot:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes chatbot-bounce {
  0%, 60%, 100% {
    transform: translateY(0);
    opacity: 0.4;
  }
  30% {
    transform: translateY(-6px);
    opacity: 1;
  }
}

/* --------------------------------------------------------------------------
   INPUT AREA — Text input + send button
   -------------------------------------------------------------------------- */
.chatbot-input-area {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--color-border, #E0E0E8);
  background-color: var(--color-white, #FFFFFF);
  flex-shrink: 0;
}

.chatbot-input-area input[type="text"] {
  flex: 1;
  height: 40px;
  padding: 0 12px;
  border: 1px solid var(--color-border, #E0E0E8);
  border-radius: var(--radius-md, 8px);
  background-color: var(--color-white, #FFFFFF);
  color: var(--color-text, #1A1A2E);
  font-family: var(--font-primary, 'Roboto', sans-serif);
  font-size: var(--fs-small, 0.875rem);
  font-weight: var(--fw-regular, 400);
  outline: none;
  transition: border-color var(--duration-fast, 150ms) var(--ease-default, ease);
}

.chatbot-input-area input[type="text"]::placeholder {
  color: var(--color-gray-400, #9898AC);
}

.chatbot-input-area input[type="text"]:focus {
  border-color: var(--color-navy, #012169);
  box-shadow: 0 0 0 2px rgba(1, 33, 105, 0.1);
}

.chatbot-send {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: var(--radius-md, 8px);
  background-color: var(--color-red, #CF081F);
  color: var(--color-white, #FFFFFF);
  cursor: pointer;
  flex-shrink: 0;
  transition: background-color var(--duration-fast, 150ms) var(--ease-default, ease),
              transform var(--duration-fast, 150ms) var(--ease-default, ease);
}

.chatbot-send:hover {
  background-color: var(--color-red-hover, #A8061A);
}

.chatbot-send:active {
  transform: scale(0.93);
}

.chatbot-send:focus-visible {
  outline: 2px solid var(--color-navy, #012169);
  outline-offset: 2px;
}

.chatbot-send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.chatbot-send svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* --------------------------------------------------------------------------
   MOBILE — Full-width, full-height panel
   -------------------------------------------------------------------------- */
@media (max-width: 768px) {
  .chatbot-panel {
    bottom: 0;
    right: 0;
    width: 100%;
    height: 100%;
    max-height: 100vh;
    max-height: 100dvh;
    border-radius: 0;
  }

  .chatbot-panel.chatbot-open {
    border-radius: 0;
  }

  .chatbot-messages {
    padding: 12px;
  }

  .chatbot-msg {
    max-width: 90%;
  }
}

/* --------------------------------------------------------------------------
   REDUCED MOTION — Respect prefers-reduced-motion
   -------------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  .chatbot-panel {
    transition: opacity var(--duration-fast, 150ms) linear,
                visibility 0ms linear var(--duration-fast, 150ms);
    transform: none !important;
  }

  .chatbot-panel.chatbot-open {
    transition: opacity var(--duration-fast, 150ms) linear,
                visibility 0ms linear 0ms;
  }

  #chatbot-toggle {
    transition: background-color var(--duration-fast, 150ms) linear;
  }

  #chatbot-toggle:hover {
    transform: none;
  }

  .chatbot-msg {
    animation: none;
  }

  .chatbot-typing-dot {
    animation: none;
    opacity: 0.6;
  }
}
