/**
 * AI Search & Chatbot Styles
 *
 * Styles for the semantic search overlay and floating chatbot widget.
 * Mobile-responsive with a clean, modern aesthetic.
 *
 * @package TennisPlayer
 * @since 2.0.0
 */

/* ═══════════════════════════════════════════════════════════════════
   SEARCH OVERLAY
   ═══════════════════════════════════════════════════════════════════ */

.tp-ai-search-wrapper {
  position: relative;
  max-width: 680px;
  width: 100%;
  margin: 0 auto;
}

.tp-ai-search-form {
  position: relative;
}

.tp-ai-search-input-wrapper {
  display: flex;
  align-items: center;
  background: #fff;
  border: 2px solid #ddd;
  border-radius: 8px;
  padding: 8px 12px;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.tp-ai-search-input-wrapper:focus-within {
  border-color: #2563eb;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.tp-ai-search-icon {
  flex-shrink: 0;
  color: #9ca3af;
  margin-right: 8px;
}

.tp-ai-search-input {
  flex: 1;
  border: none;
  outline: none;
  font-size: 16px;
  line-height: 1.5;
  background: transparent;
  color: #1f2937;
  font-family: inherit;
}

.tp-ai-search-input::placeholder {
  color: #9ca3af;
}

.tp-ai-search-clear {
  flex-shrink: 0;
  background: none;
  border: none;
  color: #9ca3af;
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  display: flex;
  align-items: center;
}

.tp-ai-search-clear:hover {
  color: #4b5563;
  background: #f3f4f6;
}

/* Filters */
.tp-ai-search-filters {
  display: flex;
  gap: 8px;
  margin-top: 8px;
  flex-wrap: wrap;
}

.tp-ai-search-filters select,
.tp-ai-search-filters input {
  font-size: 13px;
  padding: 4px 8px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  background: #fff;
  color: #374151;
  min-width: 120px;
}

.tp-ai-search-filters select:focus,
.tp-ai-search-filters input:focus {
  outline: none;
  border-color: #2563eb;
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.1);
}

/* Results dropdown */
.tp-ai-search-results {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  margin-top: 4px;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1), 0 4px 10px rgba(0, 0, 0, 0.05);
  max-height: 480px;
  overflow-y: auto;
  z-index: 400;
}

/* Loading */
.tp-ai-search-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  gap: 8px;
  color: #6b7280;
}

.tp-ai-search-loading[hidden] {
  display: none;
}

.tp-ai-spinner {
  width: 20px;
  height: 20px;
  border: 2px solid #e5e7eb;
  border-top-color: #2563eb;
  border-radius: 50%;
  animation: tp-ai-spin 0.6s linear infinite;
}

@keyframes tp-ai-spin {
  to { transform: rotate(360deg); }
}

/* Section headings */
.tp-ai-results-heading {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #6b7280;
  padding: 12px 16px 4px;
  margin: 0;
}

/* Result items */
.tp-ai-result-item {
  border-bottom: 1px solid #f3f4f6;
}

.tp-ai-result-item:last-child {
  border-bottom: none;
}

.tp-ai-result-link {
  display: block;
  padding: 10px 16px;
  text-decoration: none;
  color: inherit;
  transition: background 0.1s;
}

.tp-ai-result-link:hover,
.tp-ai-result-selected .tp-ai-result-link {
  background: #f8fafc;
}

.tp-ai-result-title {
  font-size: 14px;
  font-weight: 600;
  color: #1f2937;
  margin-bottom: 2px;
}

.tp-ai-result-meta {
  display: flex;
  gap: 8px;
  font-size: 12px;
  color: #6b7280;
  flex-wrap: wrap;
}

.tp-ai-result-meta span::before {
  content: "·";
  margin-right: 8px;
}

.tp-ai-result-meta span:first-child::before {
  content: none;
}

.tp-ai-result-score {
  color: #2563eb;
}

.tp-ai-result-snippet {
  font-size: 13px;
  color: #4b5563;
  margin-top: 4px;
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Video results grid */
.tp-ai-results-video-grid .tp-ai-result-video .tp-ai-result-link {
  display: flex;
  align-items: center;
  gap: 12px;
}

.tp-ai-result-video-icon {
  flex-shrink: 0;
  width: 48px;
  height: 48px;
  background: #1e293b;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
}

.tp-ai-result-video-thumb {
  flex-shrink: 0;
  width: 80px;
  height: 60px;
  border-radius: 6px;
  overflow: hidden;
  background: #1e293b;
}

.tp-ai-result-video-thumb video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.tp-ai-result-video-info {
  flex: 1;
  min-width: 0;
}

/* Footer */
.tp-ai-search-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  border-top: 1px solid #f3f4f6;
  font-size: 12px;
  color: #9ca3af;
}

.tp-ai-search-show-more {
  background: none;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  padding: 4px 12px;
  font-size: 12px;
  color: #2563eb;
  cursor: pointer;
}

.tp-ai-search-show-more:hover {
  background: #f8fafc;
}

/* No results */
.tp-ai-search-no-results {
  padding: 24px;
  text-align: center;
  color: #6b7280;
  font-size: 14px;
}

/* ═══════════════════════════════════════════════════════════════════
   CHATBOT WIDGET
   ═══════════════════════════════════════════════════════════════════ */

.tp-ai-chatbot {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 9999;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, sans-serif;
}

/* Trigger button */
.tp-ai-chatbot-trigger {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #1e293b;
  color: #fff;
  border: none;
  border-radius: 24px;
  padding: 12px 20px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  transition: transform 0.2s, box-shadow 0.2s;
}

.tp-ai-chatbot-trigger:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
}

.tp-ai-chatbot[data-state="expanded"] .tp-ai-chatbot-trigger {
  display: none;
}

/* Chat panel */
.tp-ai-chatbot-panel {
  width: 380px;
  max-height: 560px;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.12), 0 2px 8px rgba(0, 0, 0, 0.06);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.tp-ai-chatbot-panel[hidden] {
  display: none;
}

/* Header */
.tp-ai-chatbot-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: #1e293b;
  color: #fff;
}

.tp-ai-chatbot-header-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
  font-weight: 600;
}

.tp-ai-chatbot-logo {
  font-size: 18px;
}

.tp-ai-chatbot-header-actions {
  display: flex;
  gap: 4px;
}

.tp-ai-chatbot-header-actions svg[hidden] {
  display: none;
}

.tp-ai-chatbot-header-actions button {
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.7);
  cursor: pointer;
  padding: 6px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 28px;
  min-height: 28px;
}

.tp-ai-chatbot-header-actions button:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.1);
}

/* Messages */
.tp-ai-chatbot-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  min-height: 300px;
  max-height: 380px;
}

.tp-ai-chatbot-message {
  margin-bottom: 12px;
  max-width: 90%;
}

.tp-ai-chatbot-message-user {
  margin-left: auto;
}

.tp-ai-chatbot-message-content {
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 13px !important;
  line-height: 1.55;
}

.tp-ai-chatbot-message-content *:not(.tp-ai-source-tag):not(.tp-ai-chatbot-sources-label) {
  font-size: inherit;
  line-height: inherit;
}

.tp-ai-chatbot-message-user .tp-ai-chatbot-message-content {
  background: #2563eb;
  color: #fff;
  border-bottom-right-radius: 4px;
  font-size: 14px;
}

.tp-ai-chatbot-message-assistant .tp-ai-chatbot-message-content {
  background: #f3f4f6;
  color: #1f2937;
  border-bottom-left-radius: 4px;
}

.tp-ai-chatbot-message-content p {
  margin: 0 0 8px;
}

.tp-ai-chatbot-message-content p:last-child {
  margin-bottom: 0;
}

.tp-ai-chatbot-message-content ul {
  margin: 4px 0;
  padding-left: 20px;
}

.tp-ai-chatbot-message-content li {
  margin-bottom: 1px;
}

/* Sources */
.tp-ai-chatbot-sources {
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid #e5e7eb;
  font-size: 13px;
}

.tp-ai-chatbot-sources-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #6b7280;
  margin-bottom: 4px;
}

.tp-ai-chatbot-sources ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

.tp-ai-chatbot-sources li {
  padding: 1px 0;
}

.tp-ai-chatbot-sources a {
  color: #2563eb;
  text-decoration: none;
}

.tp-ai-chatbot-sources a:hover {
  text-decoration: underline;
}

.tp-ai-source-tag {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  padding: 2px 5px;
  border-radius: 3px;
  vertical-align: baseline;
}
.tp-ai-source-tag--article { background: #dbeafe; color: #1e40af; }
.tp-ai-source-tag--forum { background: #fef3c7; color: #92400e; }
.tp-ai-source-tag--player { background: #d1fae5; color: #065f46; }

.tp-ai-source-video-icon {
  font-size: 13px;
}

.tp-ai-source-video-card {
  list-style: none;
}

.tp-ai-source-video-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 0;
  border: none;
  border-radius: 6px;
  text-decoration: none !important;
  color: inherit;
  transition: background 0.15s;
}

.tp-ai-source-video-link:hover {
  background: rgba(255, 255, 255, 0.05);
}

.tp-ai-source-thumb {
  flex-shrink: 0;
  width: 80px;
  height: 60px;
  border-radius: 4px;
  object-fit: cover;
  background: #0f172a;
}

.tp-ai-source-video-text {
  flex: 1;
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  word-break: break-word;
}

/* Inline article links in chat messages */
.tp-ai-inline-link {
  color: #2563eb;
  text-decoration: underline;
  text-decoration-color: rgba(37, 99, 235, 0.3);
  text-underline-offset: 2px;
}

.tp-ai-inline-link:hover {
  text-decoration-color: #2563eb;
}

/* Typing indicator */
.tp-ai-chatbot-typing {
  display: flex;
  gap: 4px;
  padding: 4px 0;
}

.tp-ai-chatbot-typing span {
  width: 8px;
  height: 8px;
  background: #9ca3af;
  border-radius: 50%;
  animation: tp-ai-typing 1.4s infinite ease-in-out;
}

.tp-ai-chatbot-typing span:nth-child(2) {
  animation-delay: 0.2s;
}

.tp-ai-chatbot-typing span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes tp-ai-typing {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}

/* Rate limit info */
.tp-ai-chatbot-limit-info {
  padding: 4px 16px;
  font-size: 11px;
  color: #6b7280;
  text-align: center;
  background: #fafafa;
}

.tp-ai-chatbot-limit-low {
  color: #d97706;
}

.tp-ai-chatbot-limit-exhausted {
  color: #dc2626;
  font-weight: 500;
}

/* Input area */
.tp-ai-chatbot-input-area {
  padding: 12px 16px;
  border-top: 1px solid #e5e7eb;
}

.tp-ai-chatbot-input-wrapper {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #f9fafb;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  padding: 8px 12px;
}

.tp-ai-chatbot-input-wrapper:focus-within {
  border-color: #2563eb;
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.1);
}

.tp-ai-chatbot-input {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  font-size: 14px;
  line-height: 1.4;
  resize: none;
  font-family: inherit;
  color: #1f2937;
  max-height: 120px;
}

.tp-ai-chatbot-input::placeholder {
  color: #9ca3af;
}

.tp-ai-chatbot-send {
  flex-shrink: 0;
  background: #2563eb;
  color: #fff;
  border: none;
  border-radius: 6px;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.2s;
}

.tp-ai-chatbot-send:hover:not(:disabled) {
  background: #1d4ed8;
}

.tp-ai-chatbot-send:disabled {
  background: #d1d5db;
  cursor: not-allowed;
}

/* Fullscreen mode */
.tp-ai-chatbot-fullscreen-mode {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 99999;
}

.tp-ai-chatbot-fullscreen-mode .tp-ai-chatbot-panel {
  width: 100%;
  max-height: none;
  height: 100%;
  border-radius: 0;
  box-shadow: none;
}

.tp-ai-chatbot-fullscreen-mode .tp-ai-chatbot-messages {
  max-height: none;
  flex: 1;
}

/* ═══════════════════════════════════════════════════════════════════
   MOBILE RESPONSIVE
   ═══════════════════════════════════════════════════════════════════ */

@media (max-width: 480px) {
  /* Search: full width */
  .tp-ai-search-results {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    max-height: none;
    border-radius: 0;
    margin-top: 0;
    z-index: 10000;
  }

  .tp-ai-search-filters {
    flex-direction: column;
  }

  /* Chatbot: full screen on mobile */
  .tp-ai-chatbot[data-state="expanded"] {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
  }

  .tp-ai-chatbot-panel {
    width: 100%;
    max-height: none;
    height: 100%;
    border-radius: 0;
  }

  .tp-ai-chatbot-messages {
    max-height: none;
    flex: 1;
  }

  .tp-ai-chatbot-trigger {
    bottom: 16px;
    right: 16px;
    padding: 10px 16px;
    font-size: 13px;
  }
}

/* ═══════════════════════════════════════════════════════════════════
   PROFILE BUTTONS (progressive profiling in chatbot)
   ═══════════════════════════════════════════════════════════════════ */

.tp-ai-chatbot-profile-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.tp-ai-chatbot-profile-btn {
  background: #f0f4ff;
  border: 1px solid #c7d2fe;
  border-radius: 20px;
  padding: 6px 16px;
  font-size: 13px;
  color: #3730a3;
  cursor: pointer;
  transition: all 0.15s ease;
}

.tp-ai-chatbot-profile-btn:hover:not(:disabled) {
  background: #e0e7ff;
  border-color: #818cf8;
}

.tp-ai-chatbot-profile-btn:disabled {
  opacity: 0.5;
  cursor: default;
}

.tp-ai-chatbot-profile-btn-selected {
  background: #4f46e5;
  border-color: #4f46e5;
  color: #fff;
  opacity: 1 !important;
}

.tp-ai-chatbot-profile-link {
  display: inline-block;
  margin-top: 8px;
  font-size: 12px;
  color: #6366f1;
  text-decoration: underline;
  cursor: pointer;
}

/* ═══════════════════════════════════════════════════════════════════
   ADMIN STYLES
   ═══════════════════════════════════════════════════════════════════ */

.tp-ai-section {
  background: #fff;
  border: 1px solid #c3c4c7;
  border-radius: 4px;
  padding: 20px;
  margin: 20px 0;
}

.tp-ai-section h2 {
  margin-top: 0;
  padding-bottom: 10px;
  border-bottom: 1px solid #f0f0f1;
}

/* Profile prompt link in search overlay */
.tp-ai-profile-prompt {
  margin: 6px 0 0;
  font-size: 13px;
  color: #64748b;
  text-align: center;
}

.tp-ai-profile-prompt a {
  color: #2563eb;
  text-decoration: none;
}

.tp-ai-profile-prompt a:hover {
  text-decoration: underline;
}

/* ─── Video Modal: Ask Coach AI button ──────────────────────── */

.tp-video-modal-ask-ai {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 10px 16px;
  background: rgba(37, 99, 235, 0.9);
  color: #fff;
  border: none;
  border-radius: 0 0 8px 8px;
  font-size: 13px;
  font-weight: 500;
  font-family: Inter, system-ui, sans-serif;
  cursor: pointer;
  transition: background 0.15s;
}

.tp-video-modal-ask-ai:hover {
  background: rgba(29, 78, 216, 1);
}

.tp-video-modal-ask-ai svg {
  flex-shrink: 0;
}

/* ─── Chatbot: Video context badge ──────────────────────────── */

.tp-ai-chatbot-video-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  background: #f1f5f9;
  border-bottom: 1px solid #e2e8f0;
  font-size: 12px;
  color: #475569;
  line-height: 1.3;
}

.tp-ai-video-badge-icon {
  flex-shrink: 0;
}

.tp-ai-video-badge-text {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tp-ai-video-badge-clear {
  flex-shrink: 0;
  background: none;
  border: none;
  color: #94a3b8;
  font-size: 16px;
  cursor: pointer;
  padding: 0 2px;
  line-height: 1;
}

.tp-ai-video-badge-clear:hover {
  color: #475569;
}
