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

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

:root {
  --chatflow-primary: #2563eb;
  --chatflow-secondary: #f0f4f8;
  --chatflow-font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  --chatflow-bg: #ffffff;
  --chatflow-text: #1a1a2e;
  --chatflow-radius: 12px;
  --chatflow-shadow: 0 4px 24px rgba(0, 0, 0, 0.15);
  --chatflow-bot-bubble: var(--chatflow-secondary);
  --chatflow-user-bubble: var(--chatflow-primary);
}

/* --------------------------------------------------------------------------
   Theme Presets
   -------------------------------------------------------------------------- */

[data-chatflow-theme="light"] {
  --chatflow-primary: #2563eb;
  --chatflow-secondary: #f0f4f8;
  --chatflow-bg: #ffffff;
  --chatflow-text: #1a1a2e;
  --chatflow-bot-bubble: #f0f4f8;
}

[data-chatflow-theme="dark"] {
  --chatflow-primary: #00d4ff;
  --chatflow-secondary: #2a2a4a;
  --chatflow-bg: #1a1a2e;
  --chatflow-text: #e8e8f0;
  --chatflow-bot-bubble: #2a2a4a;
}

[data-chatflow-theme="brand"] {
  /* Uses primary/secondary from settings — no overrides needed */
}

/* --------------------------------------------------------------------------
   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: var(--chatflow-bg);
  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: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

.chatflow-header__name {
  font-size: 15px;
  font-weight: 600;
  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;
  display: flex;
  flex-direction: column;
  gap: 8px;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}

/* 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;
}

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

.chatflow-bubble {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.5;
  word-wrap: break-word;
  overflow-wrap: break-word;
  animation: chatflow-fade-in 0.25s ease;
}

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

.chatflow-bubble--user {
  align-self: flex-end;
  background-color: var(--chatflow-user-bubble);
  color: #ffffff;
  border-bottom-right-radius: 4px;
}

.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: 12px 16px;
  background-color: var(--chatflow-bot-bubble);
  border-radius: 16px;
  border-bottom-left-radius: 4px;
  align-self: flex-start;
  max-width: 70px;
}

.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-bg);
  color: var(--chatflow-primary);
  border: 2px solid var(--chatflow-primary);
  border-radius: 8px;
  font-family: var(--chatflow-font);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  text-align: center;
  transition: background-color 0.15s ease, color 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}

.chatflow-buttons__btn:hover {
  background-color: var(--chatflow-primary);
  color: #ffffff;
}

.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-primary);
  color: #ffffff;
  border: none;
  border-radius: 8px;
  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: 2px solid var(--chatflow-secondary);
  border-radius: 8px;
  font-family: var(--chatflow-font);
  font-size: 14px;
  color: var(--chatflow-text);
  background-color: var(--chatflow-bg);
  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: 8px;
  background-color: var(--chatflow-primary);
  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-secondary);
  animation: chatflow-fade-in 0.25s ease;
}

/* --------------------------------------------------------------------------
   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-primary);
  color: #ffffff;
  border: none;
  border-radius: 8px;
  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;
}
