/* ==========================================================================
   ChatFlow WP — Chat Widget Styles
   ========================================================================== */

/* --------------------------------------------------------------------------
   CSS Custom Properties (Theme System)
   -------------------------------------------------------------------------- */

:root {
  --chatflow-primary: #075e54;
  --chatflow-font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  --chatflow-bg: #e5ddd5;
  --chatflow-text: #303030;
  --chatflow-radius: 12px;
  --chatflow-shadow: 0 4px 24px rgba(0, 0, 0, 0.15);
  --chatflow-bot-bubble: #dcf8c6;
  --chatflow-user-bubble: #ffffff;
  --chatflow-bot-text: #303030;
  --chatflow-user-text: #303030;
  --chatflow-buttons: #075e54;
  --chatflow-buttons-text: #ffffff;
}

/* --------------------------------------------------------------------------
   Floating Button
   -------------------------------------------------------------------------- */

.chatflow-btn {
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background-color: var(--chatflow-primary);
  color: #ffffff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
  z-index: 9999;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  padding: 0;
  outline: none;
  -webkit-tap-highlight-color: transparent;
}

.chatflow-btn:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.28);
}

.chatflow-btn:active {
  transform: scale(0.96);
}

.chatflow-btn--left {
  right: auto;
  left: 20px;
}

.chatflow-btn svg {
  width: 28px;
  height: 28px;
  fill: currentColor;
}

.chatflow-btn img {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
}

/* --------------------------------------------------------------------------
   PHP-rendered Floating Button (#chatflow-floating-btn)
   -------------------------------------------------------------------------- */

#chatflow-floating-btn {
  line-height: 0;
}

#chatflow-floating-btn svg {
  width: 28px;
  height: 28px;
  fill: white;
  display: block;
  flex-shrink: 0;
}

#chatflow-floating-btn img {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
  display: block;
  flex-shrink: 0;
}

/* --------------------------------------------------------------------------
   Chat Mini-Window
   -------------------------------------------------------------------------- */

.chatflow-window {
  position: fixed;
  bottom: 88px;
  right: 20px;
  width: 380px;
  max-width: calc(100vw - 40px);
  height: min(720px, calc(100vh - 120px));
  max-height: calc(100vh - 120px);
  background-color: #f0f0f0;
  border-radius: var(--chatflow-radius) var(--chatflow-radius) 0 0;
  box-shadow: var(--chatflow-shadow);
  z-index: 9998;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  font-family: var(--chatflow-font);
  color: var(--chatflow-text);
  opacity: 0;
  transform: translateY(20px);
  pointer-events: none;
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.chatflow-window--open {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.chatflow-window--left {
  right: auto;
  left: 20px;
}

/* --------------------------------------------------------------------------
   Header Bar
   -------------------------------------------------------------------------- */

.chatflow-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background-color: var(--chatflow-primary);
  color: #ffffff;
  min-height: 48px;
  flex-shrink: 0;
}

.chatflow-header__info {
  display: flex;
  align-items: center;
  gap: 10px;
}

.chatflow-header__logo {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

.chatflow-header__name-wrap {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.chatflow-header__name-row {
  display: flex;
  align-items: center;
  gap: 4px;
}

.chatflow-header__name {
  font-size: 15px;
  font-weight: 600;
  line-height: 1.2;
}

.chatflow-header__verified {
  display: inline-flex;
  align-items: center;
  line-height: 0;
}

.chatflow-header__verified svg {
  width: 18px;
  height: 18px;
}

.chatflow-header__status {
  font-size: 12px;
  font-weight: 400;
  opacity: 0.85;
  line-height: 1.2;
}

.chatflow-header__actions {
  display: flex;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
}

.chatflow-header__new-chat,
.chatflow-header__close {
  background: none;
  border: none;
  color: #ffffff;
  cursor: pointer;
  padding: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: background-color 0.15s ease;
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}

.chatflow-header__new-chat:hover,
.chatflow-header__close:hover {
  background-color: rgba(255, 255, 255, 0.2);
}

.chatflow-header__new-chat svg,
.chatflow-header__close svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

/* --------------------------------------------------------------------------
   Messages Container
   -------------------------------------------------------------------------- */

.chatflow-messages {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
  background-color: var(--chatflow-bg);
  background-image: url("data:image/svg+xml,%3Csvg width='80' height='80' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='%23000' fill-opacity='0.03'%3E%3Ccircle cx='20' cy='20' r='2'/%3E%3Ccircle cx='60' cy='60' r='2'/%3E%3C/g%3E%3C/svg%3E");
}

/* Scrollbar styling */
.chatflow-messages::-webkit-scrollbar {
  width: 4px;
}

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

.chatflow-messages::-webkit-scrollbar-thumb {
  background-color: rgba(0, 0, 0, 0.15);
  border-radius: 2px;
}

/* --------------------------------------------------------------------------
   Date Badge
   -------------------------------------------------------------------------- */

.chatflow-date-badge {
  display: flex;
  justify-content: center;
  padding: 6px 0 4px;
}

.chatflow-date-badge__text {
  display: inline-block;
  padding: 4px 12px;
  background-color: rgba(255, 255, 255, 0.85);
  border-radius: 8px;
  font-size: 12px;
  color: rgba(0, 0, 0, 0.5);
  box-shadow: 0 1px 0.5px rgba(0, 0, 0, 0.1);
}

/* --------------------------------------------------------------------------
   Privacy Footer
   -------------------------------------------------------------------------- */

.chatflow-privacy {
  flex-shrink: 0;
  padding: 6px 16px;
  font-size: 11px;
  line-height: 1.4;
  text-align: center;
  color: rgba(0, 0, 0, 0.5);
  background-color: #f0f0f0;
  border-top: 1px solid rgba(0, 0, 0, 0.08);
}

.chatflow-privacy a {
  color: var(--chatflow-primary);
  text-decoration: underline;
  font-weight: 600;
}

.chatflow-privacy a:hover {
  opacity: 0.8;
}

/* --------------------------------------------------------------------------
   Message Bubbles
   -------------------------------------------------------------------------- */

.chatflow-bubble {
  max-width: 85%;
  padding: 6px 8px 6px 9px;
  border-radius: 8px;
  font-size: 14px;
  line-height: 1.45;
  word-wrap: break-word;
  overflow-wrap: break-word;
  animation: chatflow-fade-in 0.25s ease;
  position: relative;
  box-shadow: 0 1px 0.5px rgba(0, 0, 0, 0.13);
}

.chatflow-bubble--bot {
  align-self: flex-start;
  background-color: var(--chatflow-bot-bubble);
  color: var(--chatflow-bot-text);
  border-top-left-radius: 0;
}

.chatflow-bubble--user {
  align-self: flex-end;
  background-color: var(--chatflow-user-bubble);
  color: var(--chatflow-user-text);
  border-top-right-radius: 0;
}

.chatflow-bubble__content {
  display: inline;
}

.chatflow-bubble__meta {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  float: right;
  margin-left: 8px;
  margin-top: 4px;
  font-size: 11px;
  color: rgba(0, 0, 0, 0.4);
  white-space: nowrap;
  line-height: 1;
}

.chatflow-bubble--user .chatflow-bubble__meta {
  color: rgba(0, 0, 0, 0.4);
}

.chatflow-bubble__check {
  display: inline-flex;
  align-items: center;
  line-height: 0;
}

.chatflow-bubble__check svg {
  width: 16px;
  height: 11px;
}

.chatflow-bubble-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  animation: chatflow-fade-in 0.25s ease;
}

.chatflow-bubble-row--bot {
  align-self: flex-start;
}

.chatflow-bubble-row--user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.chatflow-bubble-row .chatflow-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

/* --------------------------------------------------------------------------
   Typing Indicator
   -------------------------------------------------------------------------- */

.chatflow-typing {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 10px 14px;
  background-color: var(--chatflow-bot-bubble);
  border-radius: 8px;
  border-top-left-radius: 0;
  align-self: flex-start;
  max-width: 70px;
  box-shadow: 0 1px 0.5px rgba(0, 0, 0, 0.13);
}

.chatflow-typing__dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background-color: var(--chatflow-text);
  opacity: 0.4;
  animation: chatflow-bounce 1.2s ease-in-out infinite;
}

.chatflow-typing__dot:nth-child(2) {
  animation-delay: 0.15s;
}

.chatflow-typing__dot:nth-child(3) {
  animation-delay: 0.3s;
}

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

/* --------------------------------------------------------------------------
   Option Buttons
   -------------------------------------------------------------------------- */

.chatflow-buttons {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  padding: 4px 0;
  animation: chatflow-fade-in 0.25s ease;
}

.chatflow-buttons__btn {
  display: block;
  width: 100%;
  min-height: 44px;
  padding: 10px 16px;
  background-color: var(--chatflow-buttons);
  color: var(--chatflow-buttons-text);
  border: none;
  border-radius: 24px;
  font-family: var(--chatflow-font);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  text-align: center;
  transition: opacity 0.15s ease, transform 0.15s ease;
  -webkit-tap-highlight-color: transparent;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12);
}

.chatflow-buttons__btn:hover {
  opacity: 0.9;
}

.chatflow-buttons__btn:active {
  transform: scale(0.98);
}

.chatflow-buttons__btn:disabled {
  opacity: 0.5;
  cursor: default;
  pointer-events: none;
}

/* --------------------------------------------------------------------------
   CTA Button (Redirect)
   -------------------------------------------------------------------------- */

.chatflow-cta {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  min-height: 48px;
  padding: 12px 20px;
  background-color: var(--chatflow-buttons);
  color: var(--chatflow-buttons-text);
  border: none;
  border-radius: 24px;
  font-family: var(--chatflow-font);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  text-align: center;
  transition: opacity 0.15s ease, transform 0.15s ease;
  animation: chatflow-fade-in 0.25s ease;
  -webkit-tap-highlight-color: transparent;
}

.chatflow-cta:hover {
  opacity: 0.9;
}

.chatflow-cta:active {
  transform: scale(0.98);
}

.chatflow-cta__arrow {
  width: 16px;
  height: 16px;
  fill: currentColor;
  flex-shrink: 0;
}

.chatflow-cta-hint {
  text-align: center;
  font-size: 12px;
  color: #888;
  margin-top: 6px;
  margin-bottom: 4px;
  font-style: italic;
  animation: chatflow-fade-in 0.3s ease;
}

/* --------------------------------------------------------------------------
   Input Field
   -------------------------------------------------------------------------- */

.chatflow-input-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
  width: 100%;
  animation: chatflow-fade-in 0.25s ease;
}

.chatflow-input-wrap__field {
  flex: 1 1 auto;
  min-height: 44px;
  padding: 10px 14px;
  border: 1px solid #ddd;
  border-radius: 24px;
  font-family: var(--chatflow-font);
  font-size: 14px;
  color: var(--chatflow-text);
  background-color: #ffffff;
  outline: none;
  transition: border-color 0.15s ease;
}

.chatflow-input-wrap__field:focus {
  border-color: var(--chatflow-primary);
}

.chatflow-input-wrap__field::placeholder {
  color: var(--chatflow-text);
  opacity: 0.5;
}

.chatflow-input-wrap__send {
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 50%;
  background-color: var(--chatflow-buttons);
  color: #ffffff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: opacity 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}

.chatflow-input-wrap__send:hover {
  opacity: 0.9;
}

.chatflow-input-wrap__send svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

/* --------------------------------------------------------------------------
   HTML / Ad Node Container
   -------------------------------------------------------------------------- */

.chatflow-html-container {
  width: 100%;
  border-radius: 8px;
  background-color: var(--chatflow-bot-bubble);
  animation: chatflow-fade-in 0.25s ease;
  box-shadow: 0 1px 0.5px rgba(0, 0, 0, 0.13);
}

/* --------------------------------------------------------------------------
   Fallback / Dead-End
   -------------------------------------------------------------------------- */

.chatflow-fallback {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 12px 0;
  animation: chatflow-fade-in 0.25s ease;
}

.chatflow-fallback__msg {
  font-size: 14px;
  color: var(--chatflow-text);
  opacity: 0.7;
  text-align: center;
}

.chatflow-fallback__restart {
  min-height: 44px;
  padding: 10px 24px;
  background-color: var(--chatflow-buttons);
  color: var(--chatflow-buttons-text);
  border: none;
  border-radius: 24px;
  font-family: var(--chatflow-font);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: opacity 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}

.chatflow-fallback__restart:hover {
  opacity: 0.9;
}

/* --------------------------------------------------------------------------
   Animations
   -------------------------------------------------------------------------- */

@keyframes chatflow-fade-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* --------------------------------------------------------------------------
   Responsive — Mobile
   -------------------------------------------------------------------------- */

@media (max-width: 400px) {
  .chatflow-window {
    bottom: 0;
    right: 0;
    left: 0;
    width: 100%;
    max-width: 100%;
    height: calc(100% - env(safe-area-inset-top, 0px));
    max-height: 100%;
    border-radius: 0;
  }

  .chatflow-window--left {
    left: 0;
    right: 0;
  }

  .chatflow-btn {
    bottom: 16px;
    right: 16px;
  }

  .chatflow-btn--left {
    right: auto;
    left: 16px;
  }

  .chatflow-messages {
    padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  }
}

/* Safe area for iOS */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  .chatflow-window {
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
}

/* Floating button shake animation (triggered when notification badge visible) */
@keyframes chatflow-shake {
  0%   { transform: rotate(0deg); }
  15%  { transform: rotate(-15deg); }
  30%  { transform: rotate(12deg); }
  45%  { transform: rotate(-10deg); }
  60%  { transform: rotate(8deg); }
  75%  { transform: rotate(-5deg); }
  100% { transform: rotate(0deg); }
}
#chatflow-floating-btn.chatflow-shake {
  animation: chatflow-shake 0.7s ease-in-out;
}
