/* ─── AI Customer-Support Chat Widget (Feature #5 Phase 1) ─────────────
 *
 * Floating bottom-right widget shown on event pages only. Gated server-side
 * by system_settings.chatbot_enabled (event.php).
 *
 * Two states:
 *   - .chat-pill           — collapsed; small "Have questions?" pill
 *   - .chat-panel          — expanded; transcript + input
 *
 * Brand: festivals-v4 uses --primary-red (#dc3545) on a dark background.
 * Keep contrast high — many event pages have busy hero images.
 */

#chat-widget {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 10000;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  color: #fff;
}

/* ─── Collapsed pill ────────────────────────────────────────────── */
#chat-widget .chat-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: #dc3545;
  color: #fff;
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
  cursor: pointer;
  border: none;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

#chat-widget .chat-pill:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.45);
}

#chat-widget .chat-pill svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

/* ─── Expanded panel ────────────────────────────────────────────── */
#chat-widget .chat-panel {
  display: none;
  flex-direction: column;
  width: 360px;
  max-width: calc(100vw - 32px);
  height: 520px;
  max-height: calc(100vh - 96px);
  background: #1a1a1a;
  border: 1px solid #333;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.55);
}

#chat-widget.is-open .chat-panel { display: flex; }
#chat-widget.is-open .chat-pill  { display: none; }

#chat-widget .chat-header {
  background: linear-gradient(135deg, #dc3545, #b02a37);
  color: #fff;
  padding: 12px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 700;
  font-size: 15px;
}

#chat-widget .chat-header .chat-close {
  background: transparent;
  border: none;
  color: #fff;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
}
#chat-widget .chat-header .chat-close:hover { background: rgba(255,255,255,0.15); }

#chat-widget .chat-body {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 12px;
  background: #111;
  font-size: 14px;
  line-height: 1.45;
}

/* Bubbles */
#chat-widget .chat-msg {
  margin-bottom: 10px;
  display: flex;
}
#chat-widget .chat-msg.user { justify-content: flex-end; }
#chat-widget .chat-msg .bubble {
  max-width: 80%;
  padding: 8px 12px;
  border-radius: 14px;
  white-space: pre-wrap;
  word-wrap: break-word;
}
#chat-widget .chat-msg.user .bubble {
  background: #dc3545;
  color: #fff;
  border-bottom-right-radius: 4px;
}
#chat-widget .chat-msg.assistant .bubble {
  background: #2a2a2a;
  color: #eee;
  border-bottom-left-radius: 4px;
}
#chat-widget .chat-msg.system .bubble {
  background: #333;
  color: #ffc;
  font-style: italic;
  font-size: 13px;
  max-width: 100%;
  text-align: center;
}

#chat-widget .chat-typing {
  font-style: italic;
  color: #888;
  font-size: 13px;
  padding: 4px 0;
}

/* Footer w/ input */
#chat-widget .chat-input-row {
  display: flex;
  border-top: 1px solid #333;
  background: #1a1a1a;
}
#chat-widget .chat-input {
  flex: 1 1 auto;
  background: transparent;
  border: none;
  outline: none;
  color: #fff;
  padding: 12px;
  font-size: 14px;
  resize: none;
  font-family: inherit;
  max-height: 100px;
}
#chat-widget .chat-input::placeholder { color: #777; }
#chat-widget .chat-send {
  background: #dc3545;
  color: #fff;
  border: none;
  padding: 0 16px;
  font-weight: 700;
  cursor: pointer;
  font-size: 14px;
}
#chat-widget .chat-send:disabled {
  background: #555;
  cursor: not-allowed;
}

#chat-widget .chat-footer-note {
  padding: 6px 10px;
  font-size: 11px;
  color: #777;
  background: #1a1a1a;
  border-top: 1px solid #2a2a2a;
  text-align: center;
}

/* Small screens: full-width slide-up sheet */
@media (max-width: 480px) {
  #chat-widget .chat-panel {
    width: 100vw;
    max-width: 100vw;
    height: 70vh;
    border-radius: 12px 12px 0 0;
    position: fixed;
    right: 0;
    bottom: 0;
  }
  #chat-widget {
    right: 12px;
    bottom: 12px;
  }
}

/* ─── Header trigger (mobile) ───────────────────────────────────────
 * On mobile the floating pill collides with the bottom cart bar, so chat-
 * widget.js injects a light-grey "Have questions?" button into the event-page
 * header next to the cart and sets body.chat-in-header. Below the navbar
 * breakpoint (991.98px) we show that trigger and hide the floating pill;
 * desktop keeps the pill. The expanded panel is unchanged. */
.chat-header-trigger { display: none; }

@media (max-width: 991.98px) {
  .chat-header-trigger {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: #e5e7eb;
    color: #1f2937;
    border: 1px solid #d1d5db;
    padding: 7px 14px;
    border-radius: 999px;
    font-size: 13px;
    font-weight: 600;
    line-height: 1;
    margin-right: 8px;
    white-space: nowrap;
    cursor: pointer;
  }
  .chat-header-trigger:hover { background: #d1d5db; }
  .chat-header-trigger svg {
    width: 15px;
    height: 15px;
    fill: currentColor;
  }
  body.chat-in-header #chat-widget .chat-pill { display: none; }
}

@media (max-width: 380px) {
  /* Tight phones: keep just the icon so the header doesn't overflow. */
  .chat-header-trigger .cht-label { display: none; }
  .chat-header-trigger { padding: 7px 10px; }
}
