/*
 * AI Site Chat — Chat Widget Styles
 * Font: Plus Jakarta Sans (loaded via Google Fonts in PHP)
 */

/* ── Reset / scope ───────────────────────────────────────────────────────── */

#aichat-widget-root,
#aichat-widget-root * {
  box-sizing: border-box;
  font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont,
               'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* ── CSS variables (set dynamically via JS on #aichat-widget-root) ───────── */

#aichat-widget-root {
  --aichat-primary:   #22c55e;
  --aichat-secondary: #4ade80;
  --aichat-gradient:  linear-gradient(135deg, var(--aichat-primary), var(--aichat-secondary));
  --aichat-radius:    16px;
  --aichat-shadow:    0 8px 40px rgba(0, 0, 0, 0.16);
}

/* ── Toggle button ───────────────────────────────────────────────────────── */

.aichat-toggle-btn {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  border: none;
  background: var(--aichat-gradient);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999998;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.22);
  transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1),
              box-shadow 0.2s ease;
  outline: none;
  padding: 0;
}

.aichat-toggle-btn:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 28px rgba(0, 0, 0, 0.28);
}

.aichat-toggle-btn:active {
  transform: scale(0.95);
}

.aichat-toggle-btn:focus-visible {
  outline: 3px solid var(--aichat-primary);
  outline-offset: 3px;
}

.aichat-toggle-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.3s ease;
}

/* ── Notification dot ────────────────────────────────────────────────────── */

.aichat-notif-dot {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 14px;
  height: 14px;
  background: #ef4444;
  border-radius: 50%;
  border: 2.5px solid #fff;
  animation: aichat-pulse 2.2s ease-in-out infinite;
}

@keyframes aichat-pulse {
  0%, 100% { transform: scale(1);    opacity: 1;    }
  50%       { transform: scale(1.2); opacity: 0.75; }
}

/* ── Chat window ─────────────────────────────────────────────────────────── */

.aichat-window {
  position: fixed;
  bottom: 98px;
  right: 24px;
  width: 370px;
  height: 580px;
  background: #ffffff;
  border-radius: var(--aichat-radius);
  box-shadow: var(--aichat-shadow);
  overflow: hidden;
  z-index: 999997;
  display: flex;
  flex-direction: column;

  /* Closed state */
  opacity: 0;
  pointer-events: none;
  transform: scale(0.9) translateY(16px);
  transform-origin: bottom right;
  transition: opacity 0.22s ease,
              transform 0.28s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.aichat-window--open {
  opacity: 1;
  pointer-events: all;
  transform: scale(1) translateY(0);
}

/* ── Header ──────────────────────────────────────────────────────────────── */

.aichat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 13px 16px;
  flex-shrink: 0;
  background: var(--aichat-gradient);
}

.aichat-header-info {
  display: flex;
  align-items: center;
  gap: 10px;
}

.aichat-header-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.25);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}

.aichat-header-name {
  font-size: 15px;
  font-weight: 700;
  color: #ffffff;
  line-height: 1.2;
}

.aichat-header-status {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.88);
  display: flex;
  align-items: center;
  gap: 5px;
  line-height: 1;
  margin-top: 2px;
}

.aichat-header-status::before {
  content: '';
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #86efac;
  flex-shrink: 0;
}

.aichat-close-btn {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.2);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  flex-shrink: 0;
  transition: background 0.15s;
}

.aichat-close-btn:hover {
  background: rgba(255, 255, 255, 0.35);
}

.aichat-close-btn:focus-visible {
  outline: 2px solid rgba(255, 255, 255, 0.8);
  outline-offset: 2px;
}

/* ── Gate screen ─────────────────────────────────────────────────────────── */

.aichat-gate {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.aichat-gate-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 30px 28px;
  background: #ffffff;
  overflow-y: auto;
}

.aichat-gate-avatar {
  font-size: 56px;
  line-height: 1;
  margin-bottom: 14px;
}

.aichat-gate-title {
  font-size: 20px;
  font-weight: 700;
  color: #0f172a;
  margin: 0 0 8px;
  text-align: center;
}

.aichat-gate-subtitle {
  font-size: 14px;
  color: #64748b;
  margin: 0 0 26px;
  text-align: center;
  line-height: 1.5;
}

.aichat-gate-form {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 11px;
}

/* ── Form inputs ─────────────────────────────────────────────────────────── */

.aichat-input {
  width: 100%;
  padding: 11px 14px;
  border: 1.5px solid #e2e8f0;
  border-radius: 10px;
  font-size: 14px;
  font-family: inherit;
  color: #0f172a;
  background: #f8fafc;
  outline: none;
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
}

.aichat-input:focus {
  border-color: var(--aichat-primary);
  background: #ffffff;
  box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.12);
}

.aichat-input::placeholder {
  color: #94a3b8;
}

.aichat-input.aichat-input--error {
  border-color: #ef4444;
  background: #fff5f5;
}

/* ── Error message ───────────────────────────────────────────────────────── */

.aichat-error-msg {
  font-size: 12.5px;
  color: #dc2626;
  min-height: 18px;
  text-align: center;
  font-weight: 500;
}

/* ── Primary button ──────────────────────────────────────────────────────── */

.aichat-btn-primary {
  width: 100%;
  padding: 12px 20px;
  border: none;
  border-radius: 10px;
  background: var(--aichat-gradient);
  color: #ffffff;
  font-size: 15px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.15s;
  margin-top: 4px;
}

.aichat-btn-primary:hover   { opacity: 0.9; transform: translateY(-1px); }
.aichat-btn-primary:active  { opacity: 1;   transform: translateY(0);    }
.aichat-btn-primary:focus-visible {
  outline: 3px solid var(--aichat-primary);
  outline-offset: 2px;
}

/* ── Chat screen ─────────────────────────────────────────────────────────── */

.aichat-chat {
  display: flex;
  flex-direction: column;
  height: 100%;
}

/* ── Messages area ───────────────────────────────────────────────────────── */

.aichat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  background: #f8fafc;
  scroll-behavior: smooth;
  overscroll-behavior: contain;
}

.aichat-messages::-webkit-scrollbar       { width: 4px; }
.aichat-messages::-webkit-scrollbar-track { background: transparent; }
.aichat-messages::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 2px; }

/* ── Message bubbles ─────────────────────────────────────────────────────── */

.aichat-message {
  display: flex;
  flex-direction: column;
  max-width: 84%;
  animation: aichat-fade-in 0.2s ease;
}

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

.aichat-message--user {
  align-self: flex-end;
  align-items: flex-end;
}

.aichat-message--bot {
  align-self: flex-start;
  align-items: flex-start;
  max-width: 90%;
}

.aichat-bot-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.aichat-bot-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: #e2e8f0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
}

.aichat-bubble {
  padding: 10px 14px;
  font-size: 14px;
  line-height: 1.6;
  word-break: break-word;
}

.aichat-bubble--user {
  background: var(--aichat-gradient);
  color: #ffffff;
  border-radius: 18px 18px 4px 18px;
}

.aichat-bubble--bot {
  background: #ffffff;
  color: #1e293b;
  border-radius: 18px 18px 18px 4px;
  border: 1px solid #e2e8f0;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.05);
}

/* Markdown content inside bot bubble */
.aichat-bubble--bot p            { margin: 0 0 8px; }
.aichat-bubble--bot p:last-child { margin-bottom: 0; }
.aichat-bubble--bot ul,
.aichat-bubble--bot ol           { margin: 4px 0 8px; padding-left: 18px; }
.aichat-bubble--bot li           { margin-bottom: 3px; }
.aichat-bubble--bot strong       { font-weight: 700; }
.aichat-bubble--bot em           { font-style: italic; }
.aichat-bubble--bot a            { color: var(--aichat-primary); text-decoration: underline; }
.aichat-bubble--bot code         { background: #f1f5f9; padding: 1px 5px; border-radius: 4px; font-size: 12.5px; font-family: monospace; }
.aichat-bubble--bot pre          { background: #f1f5f9; padding: 10px 12px; border-radius: 8px; overflow-x: auto; margin: 6px 0; }
.aichat-bubble--bot pre code     { background: transparent; padding: 0; }
.aichat-bubble--bot h1,
.aichat-bubble--bot h2,
.aichat-bubble--bot h3           { font-size: 14px; font-weight: 700; margin: 10px 0 4px; }
.aichat-bubble--bot blockquote   { border-left: 3px solid #e2e8f0; margin: 6px 0; padding: 4px 12px; color: #64748b; }
.aichat-bubble--bot hr           { border: none; border-top: 1px solid #e2e8f0; margin: 8px 0; }

/* ── Typing indicator ────────────────────────────────────────────────────── */

.aichat-typing {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 12px 16px;
  min-width: 56px;
}

.aichat-dot {
  width: 7px;
  height: 7px;
  background: #94a3b8;
  border-radius: 50%;
  display: inline-block;
  animation: aichat-bounce 1.2s ease-in-out infinite;
}

.aichat-dot:nth-child(1) { animation-delay: 0s;    }
.aichat-dot:nth-child(2) { animation-delay: 0.18s; }
.aichat-dot:nth-child(3) { animation-delay: 0.36s; }

@keyframes aichat-bounce {
  0%, 80%, 100% { transform: translateY(0);   opacity: 0.45; }
  40%           { transform: translateY(-7px); opacity: 1;    }
}

/* ── Quick reply chips ───────────────────────────────────────────────────── */

.aichat-quick-replies {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px 12px;
  background: #f8fafc;
  border-top: 1px solid #f1f5f9;
  min-height: 0;
  transition: min-height 0.2s;
}

.aichat-chip {
  padding: 6px 13px;
  border-radius: 20px;
  border: 1.5px solid var(--aichat-primary);
  background: #ffffff;
  color: var(--aichat-primary);
  font-size: 12.5px;
  font-family: inherit;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, transform 0.1s;
  white-space: nowrap;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.4;
}

.aichat-chip:hover {
  background: var(--aichat-primary);
  color: #ffffff;
  transform: translateY(-1px);
}

.aichat-chip:active {
  transform: translateY(0);
}

/* ── Input bar ───────────────────────────────────────────────────────────── */

.aichat-input-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 11px 12px;
  background: #ffffff;
  border-top: 1px solid #e2e8f0;
  flex-shrink: 0;
}

.aichat-msg-input {
  flex: 1;
  padding: 10px 14px;
  border: 1.5px solid #e2e8f0;
  border-radius: 22px;
  font-size: 14px;
  font-family: inherit;
  color: #0f172a;
  background: #f8fafc;
  outline: none;
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
  min-width: 0;
}

.aichat-msg-input:focus {
  border-color: var(--aichat-primary);
  background: #ffffff;
  box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.1);
}

.aichat-msg-input::placeholder { color: #94a3b8; }

.aichat-msg-input:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.aichat-send-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: var(--aichat-gradient);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  padding: 0;
  transition: opacity 0.15s, transform 0.15s;
}

.aichat-send-btn:hover   { opacity: 0.88; transform: scale(1.06); }
.aichat-send-btn:active  { transform: scale(0.94); }
.aichat-send-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  transform: none;
}

.aichat-send-btn:focus-visible {
  outline: 3px solid var(--aichat-primary);
  outline-offset: 2px;
}

/* ── Quick reply chips — right-aligned stack ─────────────────────────────── */

.aichat-quick-replies {
  flex-direction: column;
  align-items: flex-end;
}

/* ── Mobile responsive — full-screen takeover ────────────────────────────── */

@media (max-width: 600px) {
  /* Full-screen window */
  .aichat-window {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100% !important;
    height: 100% !important;
    max-height: 100dvh;
    border-radius: 0 !important;
    transform: translateY(100%) !important;
    transition: transform 0.32s cubic-bezier(0.32, 0.72, 0, 1) !important;
  }

  .aichat-window--open {
    transform: translateY(0) !important;
    opacity: 1 !important;
  }

  /* Toggle button stays in corner */
  .aichat-toggle-btn {
    right: 16px;
    bottom: 20px;
    width: 56px;
    height: 56px;
  }

  /* Taller header on mobile */
  .aichat-header {
    padding: 16px 18px;
    min-height: 66px;
  }

  .aichat-header-avatar {
    width: 42px;
    height: 42px;
    font-size: 22px;
  }

  .aichat-header-name   { font-size: 16px; }
  .aichat-header-status { font-size: 13px; }

  /* Close button bigger touch target */
  .aichat-close-btn {
    width: 36px;
    height: 36px;
  }

  /* White messages background like reference */
  .aichat-messages {
    background: #ffffff;
    padding: 20px 16px;
    gap: 16px;
  }

  /* Bigger bubbles on mobile */
  .aichat-bubble {
    font-size: 15px;
    padding: 12px 16px;
  }

  .aichat-message   { max-width: 88%; }
  .aichat-message--bot { max-width: 92%; }

  /* Quick replies — right-side stacked chips */
  .aichat-quick-replies {
    padding: 10px 14px;
    gap: 8px;
    background: #ffffff;
  }

  .aichat-chip {
    font-size: 13.5px;
    padding: 8px 16px;
    max-width: 280px;
  }

  /* Input bar */
  .aichat-input-bar {
    padding: 12px 14px;
    padding-bottom: max(12px, env(safe-area-inset-bottom));
    background: #ffffff;
    border-top: 1px solid #e2e8f0;
  }

  .aichat-msg-input {
    font-size: 15px;
    padding: 11px 16px;
  }

  .aichat-send-btn {
    width: 44px;
    height: 44px;
  }
}

/* ── Reduced motion ──────────────────────────────────────────────────────── */

@media (prefers-reduced-motion: reduce) {
  .aichat-window,
  .aichat-toggle-btn,
  .aichat-notif-dot,
  .aichat-message,
  .aichat-dot { animation: none; transition: none; }
}

/* ── Inline embed (shortcode) ────────────────────────────────────────────── */

.aichat-inline-embed {
  display: block;
  width: 100%;
  max-width: 500px;
  margin: 0 auto;
}

.aichat-inline-embed .aichat-window--inline {
  position: relative !important;
  bottom: auto !important;
  right: auto !important;
  width: 100% !important;
  height: 580px;
  opacity: 1 !important;
  pointer-events: all !important;
  transform: none !important;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.12);
}

/* Hide the floating toggle when inline root is present */
#aichat-inline-root ~ #aichat-widget-root .aichat-toggle-btn,
.aichat-inline-embed ~ #aichat-widget-root .aichat-toggle-btn {
  display: none;
}
