/* Frontend styles for NS AI Search */

:root {
  --ns-ai-primary: #2563eb;
  --ns-ai-primary-dark: #1d4ed8;
  --ns-ai-bg-light: #f9fafb;
  --ns-ai-text-main: #1f2937;
  --ns-ai-text-muted: #6b7280;
  --ns-ai-border: #e5e7eb;
  --ns-ai-shadow:
    0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
}

.ns-ai-webchat-container[data-theme="ocean"] {
  --ns-ai-primary: #2563eb;
  --ns-ai-primary-dark: #1d4ed8;
}

.ns-ai-webchat-container[data-theme="emerald"] {
  --ns-ai-primary: #059669;
  --ns-ai-primary-dark: #047857;
}

.ns-ai-webchat-container[data-theme="sunset"] {
  --ns-ai-primary: #f97316;
  --ns-ai-primary-dark: #ea580c;
}

.ns-ai-webchat-container[data-theme="violet"] {
  --ns-ai-primary: #7c3aed;
  --ns-ai-primary-dark: #6d28d9;
}

.ns-ai-webchat-container[data-theme="slate"] {
  --ns-ai-primary: #0f172a;
  --ns-ai-primary-dark: #1e293b;
}

.ns-ai-search-container {
  position: relative;
  display: inline-block;
}

.ns-ai-search-toggle {
  background: none;
  border: none;
  cursor: pointer;
  padding: 8px;
  border-radius: 50%;
  transition: background-color 0.3s ease;
}

.ns-ai-search-toggle:hover {
  background-color: #f0f0f0;
}

.ns-ai-search-toggle svg {
  display: block;
}

.ns-ai-search-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(3px);
  z-index: 9999;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 20px;
}

.ns-ai-search-modal-content {
  background: #ffffff;
  border-radius: 12px;
  width: 92%;
  max-width: 760px;
  max-height: 88vh;
  overflow: hidden;
  box-shadow: 0 15px 45px rgba(0, 0, 0, 0.25);
  display: flex;
  flex-direction: column;
  animation: nsAiModalIn 140ms ease-out;
}

.ns-ai-search-modal-header {
  padding: 18px 22px;
  border-bottom: 1px solid #f0f2f5;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #fafbfc;
}

.ns-ai-search-modal-header h2 {
  margin: 0;
  font-size: 1.2rem;
  color: #1f2937;
  letter-spacing: 0.2px;
}

.ns-ai-search-close {
  background: none;
  border: none;
  font-size: 1.8rem;
  cursor: pointer;
  color: #6b7280;
  padding: 0;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.ns-ai-search-close:hover {
  color: #333;
}

.ns-ai-search-modal-body {
  padding: 18px 22px 22px 22px;
  flex: 1;
  overflow-y: auto;
}

.ns-ai-search-form {
  margin-bottom: 20px;
}

.ns-ai-search-input-container {
  display: flex;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
}

.ns-ai-search-input {
  flex: 1;
  padding: 12px 16px;
  border: none;
  font-size: 1rem;
  outline: none;
}

.ns-ai-search-submit {
  background: #2563eb;
  border: none;
  color: white;
  padding: 0 18px;
  cursor: pointer;
  transition: background-color 0.3s ease;
}

.ns-ai-search-submit:hover {
  background: #1d4ed8;
}

.ns-ai-search-results {
  margin-top: 20px;
}

.ns-ai-search-result-item {
  padding: 14px 16px;
  border: 1px solid #eef2f7;
  border-radius: 10px;
  background: #ffffff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
  margin-bottom: 12px;
}

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

.ns-ai-search-result-title {
  margin: 0 0 8px 0;
  font-size: 1.2rem;
}

.ns-ai-search-result-title a {
  text-decoration: none;
  color: #2563eb;
}

.ns-ai-search-result-title a:hover {
  text-decoration: underline;
}

.ns-ai-search-result-excerpt {
  margin: 0 0 10px 0;
  color: #4b5563;
  font-size: 0.95rem;
  line-height: 1.5;
}

.ns-ai-search-result-link {
  color: #2563eb;
  text-decoration: none;
  font-size: 0.9rem;
}

.ns-ai-search-result-link:hover {
  text-decoration: underline;
}

.ns-ai-search-loading {
  text-align: center;
  padding: 30px 0;
}

.ns-ai-search-spinner {
  border: 4px solid #f3f3f3;
  border-top: 4px solid #2563eb;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  animation: spin 1s linear infinite;
  margin: 0 auto 15px;
}

@keyframes spin {
  0% {
    transform: rotate(0deg);
  }

  100% {
    transform: rotate(360deg);
  }
}

.ns-ai-search-error {
  color: #d63638;
  padding: 15px;
  background-color: #fcf0f1;
  border-left: 4px solid #d63638;
  margin: 20px 0;
  border-radius: 2px;
}

.ns-ai-search-pagination {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: center;
  margin-top: 16px;
}

.ns-ai-pagination a {
  display: inline-block;
  padding: 6px 10px;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  text-decoration: none;
  color: #374151;
}

.ns-ai-pagination a:hover {
  background: #f3f4f6;
}

@keyframes nsAiModalIn {
  0% {
    transform: translateY(8px);
    opacity: 0;
  }

  100% {
    transform: translateY(0);
    opacity: 1;
  }
}

/* Web Chat Widget */
html.ns-ai-webchat-open,
body.ns-ai-webchat-open {
  overflow: hidden;
  height: 100%;
  overscroll-behavior: none;
  position: fixed;
  width: 100%;
  left: 0;
  right: 0;
}

.ns-ai-webchat-container,
.ns-ai-webchat-container * {
  box-sizing: border-box;
}

.ns-ai-webchat-container {
  --ns-ai-webchat-offset-x: 24px;
  --ns-ai-webchat-offset-y: 24px;
  --ns-ai-webchat-window-gap: 76px;
  position: fixed;
  bottom: var(--ns-ai-webchat-offset-y);
  right: var(--ns-ai-webchat-offset-x);
  z-index: 999998;
  font-family:
    -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial,
    sans-serif;
  font-size: 16px;
  line-height: 1.4;
  color: var(--ns-ai-text-main);
}

.ns-ai-webchat-container[data-position="left"] {
  right: auto;
  left: var(--ns-ai-webchat-offset-x);
}

.ns-ai-webchat-container[data-position="right"] {
  right: var(--ns-ai-webchat-offset-x);
  left: auto;
}

.ns-ai-webchat-container p,
.ns-ai-webchat-container h1,
.ns-ai-webchat-container h2,
.ns-ai-webchat-container h3,
.ns-ai-webchat-container h4,
.ns-ai-webchat-container h5,
.ns-ai-webchat-container h6 {
  margin: 0;
}

.ns-ai-webchat-container button,
.ns-ai-webchat-container input,
.ns-ai-webchat-container textarea {
  font: inherit;
}

.ns-ai-webchat-toggle {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: var(--ns-ai-primary);
  border: none;
  color: white;
  cursor: pointer;
  box-shadow: 0 4px 15px rgba(37, 99, 235, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.ns-ai-webchat-toggle:hover {
  transform: scale(1.05);
  background: var(--ns-ai-primary-dark);
  box-shadow: 0 6px 20px rgba(37, 99, 235, 0.45);
}

.ns-ai-webchat-toggle svg,
.ns-ai-webchat-header svg,
.ns-ai-webchat-welcome-icon svg,
.ns-ai-webchat-send svg {
  display: block !important;
  width: 24px !important;
  height: 24px !important;
  min-width: 24px !important;
  min-height: 24px !important;
  flex-shrink: 0;
}

.ns-ai-webchat-header .ns-ai-webchat-btn-icon svg,
.ns-ai-webchat-send svg {
  width: 18px !important;
  height: 18px !important;
  min-width: 18px !important;
  min-height: 18px !important;
}

.ns-ai-webchat-avatar svg {
  width: 20px !important;
  height: 20px !important;
  min-width: 20px !important;
  min-height: 20px !important;
}

.ns-ai-webchat-welcome-icon svg {
  width: 40px !important;
  height: 40px !important;
  min-width: 40px !important;
  min-height: 40px !important;
}

.ns-ai-webchat-window {
  position: fixed;
  bottom: calc(var(--ns-ai-webchat-offset-y) + var(--ns-ai-webchat-window-gap));
  right: var(--ns-ai-webchat-offset-x);
  width: 380px;
  height: 600px;
  max-height: calc(100vh - 120px);
  background: #ffffff;
  border-radius: 16px;
  box-shadow: var(--ns-ai-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: nsAiWebchatSlideIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  z-index: 999999;
  border: 1px solid rgba(0, 0, 0, 0.05);
}

.ns-ai-webchat-container[data-position="left"] .ns-ai-webchat-window {
  right: auto;
  left: var(--ns-ai-webchat-offset-x);
}

.ns-ai-webchat-window.minimized {
  display: none !important;
}

.ns-ai-webchat-window.is-maximized {
  top: 16px;
  bottom: 16px;
  left: 16px;
  right: 16px;
  width: auto;
  height: auto;
  max-height: none;
  border-radius: 18px;
}

@keyframes nsAiWebchatSlideIn {
  0% {
    transform: translateY(30px) scale(0.95);
    opacity: 0;
  }

  100% {
    transform: translateY(0) scale(1);
    opacity: 1;
  }
}

.ns-ai-webchat-header {
  padding: 20px;
  background: var(--ns-ai-primary);
  color: white;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
  position: relative;
}

.ns-ai-webchat-header-info {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-right: 120px;
}

.ns-ai-webchat-avatar {
  width: 40px;
  height: 40px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.ns-ai-webchat-header-text h3 {
  margin: 0;
  font-size: 1em;
  font-weight: 600;
  line-height: 1.2;
  color: #ffffff;
}

.ns-ai-webchat-status {
  font-size: 0.75em;
  opacity: 0.9;
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 2px;
  color: #ffffff;
}

.ns-ai-webchat-status::before {
  content: "";
  width: 8px;
  height: 8px;
  background: #4ade80;
  border-radius: 50%;
  display: inline-block;
  box-shadow: 0 0 0 2px rgba(74, 222, 128, 0.2);
}

.ns-ai-webchat-actions {
  position: absolute;
  top: 26px;
  right: 14px;
  display: flex;
  align-items: center;
  gap: 20px;
}

.ns-ai-webchat-btn-icon {
  background: transparent;
  border: none;
  color: white;
  width: 14px;
  height: 14px;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  padding: 0 !important;
}

.ns-ai-webchat-btn-icon:hover {
  background: rgba(255, 255, 255, 0);
  transform: scale(1.05);
}

.ns-ai-webchat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  background: #ffffff;
  display: flex;
  flex-direction: column;
  gap: 16px;
  scroll-behavior: smooth;
  min-height: 0;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.ns-ai-webchat-sync-panel {
  position: absolute;
  inset: 0;
  background: rgba(17, 24, 39, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 4;
  backdrop-filter: blur(2px);
}

.ns-ai-webchat-sync-card {
  background: #ffffff;
  border-radius: 16px;
  padding: 18px;
  width: min(360px, 90%);
  box-shadow: var(--ns-ai-shadow);
  border: 1px solid rgba(0, 0, 0, 0.08);
}

.ns-ai-webchat-sync-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.ns-ai-webchat-sync-header h4 {
  margin: 0;
  font-size: 1em;
  color: var(--ns-ai-text-main);
}

.ns-ai-webchat-sync-text {
  margin: 0 0 12px 0;
  font-size: 0.85em;
  color: var(--ns-ai-text-muted);
}

.ns-ai-webchat-sync-qr {
  display: flex;
  justify-content: center;
  margin-bottom: 12px;
}

.ns-ai-webchat-sync-qr img {
  width: 180px;
  height: 180px;
  border-radius: 12px;
  border: 1px solid rgba(0, 0, 0, 0.08);
  background: #f9fafb;
}

.ns-ai-webchat-sync-link {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.ns-ai-webchat-sync-link input {
  flex: 1;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--ns-ai-border);
  font-size: 0.8em;
  color: var(--ns-ai-text-main);
  background: #f9fafb;
}

.ns-ai-webchat-sync-copy {
  border: none;
  background: var(--ns-ai-primary);
  color: #ffffff;
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 0.8em;
  cursor: pointer;
}

.ns-ai-webchat-sync-copy:hover {
  background: var(--ns-ai-primary-dark);
}

.ns-ai-webchat-sync-note {
  margin: 0;
  font-size: 0.75em;
  color: var(--ns-ai-text-muted);
}

.ns-ai-webchat-welcome {
  text-align: center;
  padding: 30px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.ns-ai-webchat-welcome-icon {
  color: var(--ns-ai-primary);
  opacity: 0.5;
  margin-bottom: 8px;
}

.ns-ai-webchat-welcome p {
  margin: 0;
  color: var(--ns-ai-text-muted);
  font-size: 0.9em;
  line-height: 1.5;
}

.ns-ai-webchat-message {
  display: flex;
  flex-direction: column;
  max-width: 85%;
}

.ns-ai-webchat-message.user {
  align-self: flex-end;
  align-items: flex-end;
}

.ns-ai-webchat-message.bot {
  align-self: flex-start;
  align-items: flex-start;
}

.ns-ai-webchat-message-bubble {
  padding: 12px 16px;
  border-radius: 18px;
  font-size: 0.92em;
  line-height: 1.5;
  word-wrap: break-word;
  position: relative;
}

.ns-ai-webchat-message.user .ns-ai-webchat-message-bubble {
  background: var(--ns-ai-primary);
  color: white;
  border-bottom-right-radius: 4px;
}

.ns-ai-webchat-message.bot .ns-ai-webchat-message-bubble {
  background: #f3f4f6;
  color: var(--ns-ai-text-main);
  border-bottom-left-radius: 4px;
}

.ns-ai-webchat-message-time {
  font-size: 0.7em;
  color: var(--ns-ai-text-muted);
  margin-top: 4px;
  padding: 0 4px;
}

/* Message formatting */
.ns-ai-webchat-message-bubble strong {
  font-weight: 600;
}

.ns-ai-webchat-message-bubble em {
  font-style: italic;
}

.ns-ai-webchat-message-bubble code {
  background: rgba(0, 0, 0, 0.05);
  padding: 2px 4px;
  border-radius: 3px;
  font-family: monospace;
  font-size: 0.9em;
}

.ns-ai-webchat-message-bubble a {
  color: inherit;
  text-decoration: underline;
  word-break: break-all;
}

.ns-ai-webchat-message.user .ns-ai-webchat-message-bubble a {
  color: rgba(255, 255, 255, 0.9);
}

.ns-ai-webchat-message.bot .ns-ai-webchat-message-bubble a {
  color: var(--ns-ai-primary);
}

/* Source links */
.ns-ai-webchat-sources {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid rgba(0, 0, 0, 0.08);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.ns-ai-webchat-source-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.8em;
  color: var(--ns-ai-primary) !important;
  text-decoration: none !important;
  padding: 4px 0;
  transition: opacity 0.2s ease;
}

.ns-ai-webchat-source-link:hover {
  opacity: 0.7;
  text-decoration: underline !important;
}

.ns-ai-webchat-source-link svg {
  flex-shrink: 0;
}

.ns-ai-webchat-typing {
  display: flex;
  gap: 4px;
  padding: 12px 16px;
  background: #f3f4f6;
  border-radius: 18px;
  border-bottom-left-radius: 4px;
  width: fit-content;
}

.ns-ai-webchat-typing-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #9ca3af;
  animation: nsAiTyping 1.4s infinite;
}

.ns-ai-webchat-typing-dot:nth-child(2) {
  animation-delay: 0.2s;
}

.ns-ai-webchat-typing-dot:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes nsAiTyping {
  0%,
  60%,
  100% {
    transform: translateY(0);
    opacity: 0.5;
  }

  30% {
    transform: translateY(-4px);
    opacity: 1;
  }
}

.ns-ai-webchat-input-container {
  padding: 16px;
  background: white;
  border-top: 1px solid var(--ns-ai-border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.ns-ai-webchat-input-wrapper {
  display: flex;
  align-items: center;
  background: #f9fafb;
  border: 1px solid var(--ns-ai-border);
  border-radius: 24px;
  padding: 4px 4px 4px 16px;
  transition: all 0.2s ease;
}

.ns-ai-webchat-input-wrapper:focus-within {
  border-color: var(--ns-ai-primary);
  background: white;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.ns-ai-webchat-input {
  flex: 1;
  border: none;
  background: transparent;
  padding: 8px 0;
  font-size: 0.92em;
  outline: none;
  color: var(--ns-ai-text-main);
}

.ns-ai-webchat-send {
  background: var(--ns-ai-primary);
  border: none;
  color: white;
  width: 36px !important;
  height: 36px !important;
  min-width: 36px !important;
  min-height: 36px !important;
  border-radius: 50% !important;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  flex-shrink: 0;
  padding: 0 !important;
  margin: 0 !important;
}

.ns-ai-webchat-send:hover {
  background: var(--ns-ai-primary-dark);
  transform: scale(1.05);
}

.ns-ai-webchat-send:disabled {
  background: #d1d5db;
  cursor: not-allowed;
}

.ns-ai-webchat-footer-brand {
  font-size: 0.65em;
  color: var(--ns-ai-text-muted);
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* History Loading Indicator */
.ns-ai-webchat-history-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  gap: 16px;
}

.ns-ai-webchat-spinner {
  width: 40px;
  height: 40px;
  border: 4px solid #f3f4f6;
  border-top-color: var(--ns-ai-primary);
  border-radius: 50%;
  animation: ns-ai-spin 0.8s linear infinite;
}

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

.ns-ai-webchat-loading-text {
  font-size: 0.875em;
  color: var(--ns-ai-text-muted);
  font-weight: 500;
}

/* Mobile Responsive */
@media (max-width: 640px) {
  .ns-ai-webchat-window {
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    height: calc(var(--ns-ai-vh, 1vh) * 100);
    max-height: none;
    border-radius: 0;
    box-shadow: none;
  }

  .ns-ai-webchat-window.is-maximized {
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    height: calc(var(--ns-ai-vh, 1vh) * 100);
    border-radius: 0;
  }

  .ns-ai-webchat-header {
    padding-top: calc(20px + env(safe-area-inset-top));
  }

  .ns-ai-webchat-input-container {
    padding-bottom: calc(16px + env(safe-area-inset-bottom));
  }

  .ns-ai-webchat-messages {
    padding-bottom: calc(20px + env(safe-area-inset-bottom));
  }

  .ns-ai-webchat-container {
    --ns-ai-webchat-offset-x: 16px;
    --ns-ai-webchat-offset-y: 16px;
  }
}

/* Admin bar action state */
#wpadminbar #wp-admin-bar-ns-ai-searchable-action .ab-item.ns-ai-disabled {
  opacity: 0.6;
  pointer-events: none;
  cursor: default;
}

/* Admin bar status indicator */
#wpadminbar #wp-admin-bar-ns-ai-searchable > .ab-item {
  display: flex;
  align-items: center;
  gap: 6px;
}

#wpadminbar #wp-admin-bar-ns-ai-searchable > .ab-item.ns-ai-disabled {
  opacity: 0.6;
  pointer-events: none;
  cursor: default;
}

#wpadminbar #wp-admin-bar-ns-ai-searchable .ns-ai-toolbar-dot {
  display: inline-block;
  width: 8px !important;
  height: 8px !important;
  border-radius: 999px;
  background: #9ca3af;
  flex: 0 0 8px;
  padding: 0;
  line-height: 8px;
}

#wpadminbar #wp-admin-bar-ns-ai-searchable.ns-ai-status-not-embedded .ns-ai-toolbar-dot,
#wpadminbar #wp-admin-bar-ns-ai-searchable.ns-ai-status-failed .ns-ai-toolbar-dot {
  background: #dc2626;
}

#wpadminbar #wp-admin-bar-ns-ai-searchable.ns-ai-status-indexing .ns-ai-toolbar-dot {
  background: #f59e0b;
}

#wpadminbar #wp-admin-bar-ns-ai-searchable.ns-ai-status-embedded .ns-ai-toolbar-dot {
  background: #16a34a;
}
