/* ── ILPA Chatbot Widget ── */

#ilpa-chatbot {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 99999;
  font-family: 'Open Sans', sans-serif;
}

/* Overlay */
#ilpa-chat-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.4);
  z-index: 99998;
  cursor: pointer;
  transition: opacity 0.3s;
  opacity: 0;
}

#ilpa-chat-overlay.active {
  display: block;
  opacity: 1;
}

/* Toggle button */
#ilpa-chat-toggle {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: linear-gradient(145deg, #ffb820, #e89500);
  border: none;
  cursor: pointer;
  box-shadow:
    0 4px 15px rgba(249, 168, 0, 0.4),
    0 8px 25px rgba(0, 0, 0, 0.12),
    inset 0 1px 1px rgba(255, 255, 255, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  position: absolute;
  bottom: 0;
  right: 0;
}

#ilpa-chat-toggle:hover {
  transform: scale(1.08);
  box-shadow:
    0 6px 22px rgba(249, 168, 0, 0.55),
    0 10px 35px rgba(0, 0, 0, 0.18),
    inset 0 1px 1px rgba(255, 255, 255, 0.25);
}

/* Nudge bubble */
#ilpa-chat-nudge {
  position: absolute;
  bottom: 68px;
  right: 5px;
  background: #fff;
  color: #333;
  font-size: 13.5px;
  font-weight: 600;
  padding: 8px 14px;
  border-radius: 16px 16px 4px 16px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
  white-space: nowrap;
  pointer-events: auto;
  cursor: pointer;
  opacity: 0;
  transform: translateY(8px) scale(0.9);
  transition: opacity 0.35s ease, transform 0.35s ease;
  visibility: hidden;
}

#ilpa-chat-nudge.visible {
  opacity: 1;
  transform: translateY(0) scale(1);
  visibility: visible;
}

/* small triangle pointing down-right to the button */
#ilpa-chat-nudge::after {
  content: '';
  position: absolute;
  bottom: -6px;
  right: 18px;
  width: 0;
  height: 0;
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  border-top: 6px solid #fff;
}

/* Bounce animation for the toggle */
#ilpa-chat-toggle.ilpa-bounce {
  animation: ilpa-wiggle 0.8s ease;
}

@keyframes ilpa-wiggle {
  0%   { transform: scale(1); }
  15%  { transform: scale(1.15); }
  30%  { transform: scale(0.95); }
  45%  { transform: scale(1.08); }
  60%  { transform: scale(0.98); }
  75%  { transform: scale(1.03); }
  100% { transform: scale(1); }
}

/* Chat window */
#ilpa-chat-window {
  position: absolute;
  bottom: 70px;
  right: 0;
  width: 370px;
  max-width: calc(100vw - 30px);
  height: 500px;
  max-height: calc(100vh - 120px);
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.18);
  flex-direction: column;
  overflow: hidden;
}

/* Header */
#ilpa-chat-header {
  background: #f9a800;
  color: #fff;
  padding: 14px 16px;
  font-size: 15px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: space-between;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

#ilpa-chat-close {
  background: none;
  border: none;
  color: #fff;
  font-size: 22px;
  cursor: pointer;
  line-height: 1;
  padding: 0 2px;
}

/* Messages area */
#ilpa-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px;
  background: #f7f7f7;
}

/* Message row */
.ilpa-chat-msg {
  display: flex;
  margin-bottom: 12px;
}

.ilpa-chat-user {
  justify-content: flex-end;
}

.ilpa-chat-assistant {
  justify-content: flex-start;
}

/* Bubble */
.ilpa-chat-bubble {
  max-width: 82%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 13.5px;
  line-height: 1.5;
  word-wrap: break-word;
}

.ilpa-chat-user .ilpa-chat-bubble {
  background: #f9a800;
  color: #fff;
  border-bottom-right-radius: 4px;
}

.ilpa-chat-assistant .ilpa-chat-bubble {
  background: #fff;
  color: #333;
  border: 1px solid #e5e5e5;
  border-bottom-left-radius: 4px;
}

.ilpa-chat-bubble a.ilpa-chat-link {
  color: #f9a800;
  text-decoration: underline;
  font-weight: 600;
}

.ilpa-chat-bubble strong {
  font-weight: 700;
}

/* Typing indicator */
.ilpa-typing {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 12px 18px !important;
}

.ilpa-typing span {
  width: 7px;
  height: 7px;
  background: #ccc;
  border-radius: 50%;
  display: inline-block;
  animation: ilpa-bounce 1.2s infinite;
}

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

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

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

/* Form */
#ilpa-chat-form {
  display: flex;
  border-top: 1px solid #e5e5e5;
  background: #fff;
  padding: 8px;
}

#ilpa-chat-input {
  flex: 1;
  border: 1px solid #ddd;
  border-radius: 20px;
  padding: 8px 14px;
  font-size: 13.5px;
  outline: none;
  font-family: 'Open Sans', sans-serif;
}

#ilpa-chat-input:focus {
  border-color: #f9a800;
}

#ilpa-chat-send {
  background: #f9a800;
  border: none;
  border-radius: 50%;
  width: 36px;
  height: 36px;
  margin-left: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  transition: background 0.2s;
  flex-shrink: 0;
}

#ilpa-chat-send:hover {
  background: #e09700;
}

/* Scrollbar */
#ilpa-chat-messages::-webkit-scrollbar {
  width: 5px;
}

#ilpa-chat-messages::-webkit-scrollbar-thumb {
  background: #ccc;
  border-radius: 3px;
}

/* Tablet responsive */
@media (max-width: 768px) {
  #ilpa-chat-window {
    width: 340px;
  }
}

/* Mobile responsive */
@media (max-width: 480px) {
  #ilpa-chatbot {
    bottom: 10px;
    right: 10px;
  }

  #ilpa-chat-toggle {
    width: 52px;
    height: 52px;
  }

  #ilpa-chat-toggle svg {
    width: 24px;
    height: 24px;
  }

  #ilpa-chat-nudge {
    bottom: 58px;
    font-size: 12.5px;
    padding: 7px 12px;
  }

  #ilpa-chat-window {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    max-width: 100vw;
    max-height: none;
    border-radius: 0;
    z-index: 99999;
  }

  /* Safe area for notched devices */
  #ilpa-chat-header {
    padding-top: calc(10px + env(safe-area-inset-top, 0px));
    padding-left: calc(16px + env(safe-area-inset-left, 0px));
    padding-right: calc(16px + env(safe-area-inset-right, 0px));
  }

  #ilpa-chat-form {
    padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px));
    padding-left: calc(8px + env(safe-area-inset-left, 0px));
    padding-right: calc(8px + env(safe-area-inset-right, 0px));
  }

  #ilpa-chat-input {
    font-size: 16px;  /* prevents iOS zoom on focus */
    padding: 10px 14px;
  }

  #ilpa-chat-send {
    width: 40px;
    height: 40px;
  }

  .ilpa-chat-bubble {
    max-width: 88%;
    font-size: 14px;
  }

  #ilpa-chat-close {
    font-size: 28px;
    padding: 0 6px;
  }
}
