/* ==========================================================================
   DH AI Chatbot — Floating Widget Styles
   digitalhipsterinc.com
   ========================================================================== */

/* --------------------------------------------------------------------------
   CSS custom properties — overridden inline by PHP with admin settings
   -------------------------------------------------------------------------- */
:root {
  --dh-primary:        #0073e6;
  --dh-primary-dark:   #005bb5;
  --dh-text:           #ffffff;
  --dh-call-color:     #22c55e;
  --dh-contact-color:  #0073e6;
  --dh-radius:         16px;
  --dh-shadow:         0 8px 32px rgba(0, 0, 0, 0.18);
  --dh-font:           -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --dh-z:              999999;
  --dh-anim:           0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

/* --------------------------------------------------------------------------
   Wrapper — positions the whole widget
   -------------------------------------------------------------------------- */
.dh-chatbot-wrapper {
  position: fixed;
  bottom: 24px;
  z-index: var(--dh-z);
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 12px;
  font-family: var(--dh-font);
  -webkit-font-smoothing: antialiased;
}

.dh-chatbot-right { right: 24px; }
.dh-chatbot-left  { left: 24px; align-items: flex-start; }

/* --------------------------------------------------------------------------
   Toggle button
   -------------------------------------------------------------------------- */
.dh-chatbot-toggle {
  position: relative;
  height: 48px;
  padding: 0 20px;
  border-radius: 28px;
  background: var(--dh-primary);
  color: var(--dh-text);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0;
  box-shadow: 0 4px 20px rgba(0, 115, 230, 0.45);
  transition: background var(--dh-anim), transform var(--dh-anim), box-shadow var(--dh-anim);
  outline-offset: 3px;
  flex-shrink: 0;
  order: 2; /* Always below the chat box */
}

.dh-chatbot-toggle:hover {
  background: var(--dh-primary-dark, color-mix(in srgb, var(--dh-primary) 80%, black));
  transform: scale(1.04);
  box-shadow: 0 6px 24px rgba(0, 115, 230, 0.55);
}

.dh-chatbot-toggle:active { transform: scale(0.97); }

.dh-chatbot-toggle-icon {
  display: flex;
  align-items: center;
  gap: 7px;
  transition: opacity var(--dh-anim), transform var(--dh-anim);
}

.dh-toggle-label {
  font-size: 15px;
  font-weight: 700;
  font-family: var(--dh-font);
  letter-spacing: 0.01em;
  line-height: 1;
}

/* Unread badge */
.dh-chatbot-badge {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #e53e3e;
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  line-height: 18px;
  text-align: center;
  border: 2px solid #fff;
}

/* --------------------------------------------------------------------------
   Chat box container
   -------------------------------------------------------------------------- */
.dh-chatbot-box {
  width: 360px;
  max-width: calc(100vw - 32px);
  background: #fff;
  border-radius: var(--dh-radius);
  box-shadow: var(--dh-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  order: 1;

  /* Entrance animation */
  transform-origin: bottom right;
  animation: dhSlideIn var(--dh-anim) both;
  max-height: 600px;
}

.dh-chatbot-left .dh-chatbot-box {
  transform-origin: bottom left;
}

.dh-chatbot-box[hidden] {
  display: none !important; /* Override flex for hidden state */
}

@keyframes dhSlideIn {
  from {
    opacity: 0;
    transform: scale(0.88) translateY(12px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

/* --------------------------------------------------------------------------
   Image avatar — toggle button & header
   -------------------------------------------------------------------------- */

/* When an image replaces the DH initials SVG in the header */
.dh-header-avatar-img {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  object-fit: contain;
  display: block;
}

/* --------------------------------------------------------------------------
   Header
   -------------------------------------------------------------------------- */
.dh-chatbot-header {
  background: var(--dh-primary);
  color: var(--dh-text);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.dh-chatbot-header-avatar {
  flex-shrink: 0;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 700;
  color: var(--dh-text);
}

.dh-chatbot-header-info {
  flex: 1;
  min-width: 0;
}

.dh-chatbot-header-name {
  display: block;
  font-size: 15px;
  font-weight: 700;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.dh-chatbot-header-status {
  font-size: 12px;
  opacity: 0.85;
  display: flex;
  align-items: center;
  gap: 5px;
  margin-top: 2px;
}

.dh-chatbot-status-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #48bb78;
  box-shadow: 0 0 0 2px rgba(72, 187, 120, 0.35);
  animation: dhPulse 2.2s ease-in-out infinite;
}

@keyframes dhPulse {
  0%, 100% { box-shadow: 0 0 0 2px rgba(72, 187, 120, 0.35); }
  50%       { box-shadow: 0 0 0 5px rgba(72, 187, 120, 0.12); }
}

.dh-chatbot-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.dh-chatbot-header-call,
.dh-chatbot-header-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.15);
  color: var(--dh-text);
  border: none;
  cursor: pointer;
  text-decoration: none;
  transition: background var(--dh-anim);
}

.dh-chatbot-header-call:hover,
.dh-chatbot-header-close:hover {
  background: rgba(255, 255, 255, 0.28);
}

/* --------------------------------------------------------------------------
   Messages area
   -------------------------------------------------------------------------- */
.dh-chatbot-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
  min-height: 200px;
  max-height: 340px;
}

.dh-chatbot-messages::-webkit-scrollbar { width: 4px; }
.dh-chatbot-messages::-webkit-scrollbar-thumb {
  background: #d0d5dd;
  border-radius: 4px;
}

/* Individual message bubbles */
.dh-msg {
  max-width: 82%;
  padding: 10px 14px;
  border-radius: 18px;
  font-size: 14px;
  line-height: 1.55;
  word-break: break-word;
  animation: dhMsgIn 0.2s ease-out both;
}

@keyframes dhMsgIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.dh-msg-bot {
  background: #f1f3f5;
  color: #1a202c;
  align-self: flex-start;
  border-bottom-left-radius: 4px;
}

.dh-msg-user {
  background: var(--dh-primary);
  color: var(--dh-text);
  align-self: flex-end;
  border-bottom-right-radius: 4px;
}

/* Message links */
.dh-msg a {
  color: inherit;
  text-decoration: underline;
  font-weight: 600;
}

/* Typing indicator */
.dh-msg-typing {
  background: #f1f3f5;
  align-self: flex-start;
  border-bottom-left-radius: 4px;
  padding: 12px 16px;
}

.dh-typing-dots {
  display: flex;
  gap: 4px;
  align-items: center;
}

.dh-typing-dots span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #a0aec0;
  animation: dhDot 1.2s ease-in-out infinite both;
}

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

@keyframes dhDot {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30%            { transform: translateY(-5px); opacity: 1; }
}

/* Timestamp */
.dh-msg-time {
  font-size: 10px;
  color: #a0aec0;
  margin-top: 3px;
  display: block;
}

.dh-msg-user .dh-msg-time {
  text-align: right;
  color: rgba(255,255,255,0.65);
}

/* --------------------------------------------------------------------------
   Quick reply chips
   -------------------------------------------------------------------------- */
.dh-chatbot-quick-replies {
  padding: 6px 14px 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  flex-shrink: 0;
}

.dh-quick-reply {
  background: #fff;
  border: 1.5px solid var(--dh-primary);
  color: var(--dh-primary);
  border-radius: 20px;
  padding: 5px 13px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--dh-anim), color var(--dh-anim);
  font-family: var(--dh-font);
  white-space: nowrap;
}

.dh-quick-reply:hover {
  background: var(--dh-primary);
  color: var(--dh-text);
}

/* --------------------------------------------------------------------------
   Input area
   -------------------------------------------------------------------------- */
.dh-chatbot-input-area {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 14px;
  border-top: 1px solid #e8ecf0;
  flex-shrink: 0;
}

.dh-chatbot-input {
  flex: 1;
  min-height: 38px;
  max-height: 100px;
  padding: 9px 12px;
  border: 1.5px solid #d0d5dd;
  border-radius: 20px;
  font-size: 14px;
  font-family: var(--dh-font);
  line-height: 1.45;
  resize: none;
  outline: none;
  color: #1a202c;
  background: #fafafa;
  transition: border-color var(--dh-anim);
  overflow-y: auto;
}

.dh-chatbot-input:focus {
  border-color: var(--dh-primary);
  background: #fff;
}

.dh-chatbot-input::placeholder { color: #a0aec0; }

.dh-chatbot-send {
  height: 38px;
  padding: 0 14px;
  border-radius: 20px;
  background: var(--dh-primary);
  color: var(--dh-text);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  flex-shrink: 0;
  font-size: 13px;
  font-weight: 600;
  font-family: var(--dh-font);
  white-space: nowrap;
  transition: background var(--dh-anim), opacity var(--dh-anim), transform var(--dh-anim);
}

.dh-chatbot-send:hover:not(:disabled) {
  background: var(--dh-primary-dark, #005bb5);
  transform: scale(1.05);
}

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

/* --------------------------------------------------------------------------
   Footer CTAs (call + contact)
   -------------------------------------------------------------------------- */
.dh-chatbot-footer {
  display: flex;
  gap: 8px;
  padding: 10px 14px 14px;
  flex-shrink: 0;
}

.dh-cta-call,
.dh-cta-contact {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 10px;
  border-radius: 10px;
  font-size: 12px;
  font-weight: 700;
  text-decoration: none;
  transition: opacity var(--dh-anim), transform var(--dh-anim);
  letter-spacing: 0.02em;
}

.dh-cta-call {
  background: var(--dh-call-color);
  color: #fff;
}

.dh-cta-contact {
  background: var(--dh-contact-color);
  color: #fff;
}

.dh-cta-call:hover,
.dh-cta-contact:hover {
  opacity: 0.88;
  transform: translateY(-1px);
}

/* --------------------------------------------------------------------------
   Error state
   -------------------------------------------------------------------------- */
.dh-msg-error {
  background: #fff5f5;
  color: #c53030;
  border: 1px solid #feb2b2;
}

/* --------------------------------------------------------------------------
   Accessibility — focus rings
   -------------------------------------------------------------------------- */
.dh-chatbot-toggle:focus-visible,
.dh-chatbot-header-close:focus-visible,
.dh-chatbot-send:focus-visible,
.dh-quick-reply:focus-visible {
  outline: 3px solid var(--dh-primary);
  outline-offset: 2px;
}

/* --------------------------------------------------------------------------
   Responsive — smaller screens
   -------------------------------------------------------------------------- */
@media (max-width: 400px) {
  .dh-chatbot-wrapper    { bottom: 12px; }
  .dh-chatbot-right      { right: 10px; }
  .dh-chatbot-left       { left: 10px; }
  .dh-chatbot-box        { width: calc(100vw - 20px); border-radius: 12px; }
  .dh-chatbot-messages   { max-height: 260px; }
}

@media (max-height: 600px) {
  .dh-chatbot-messages { max-height: 180px; }
}
