/* RLinf Sphinx AI assistant styles. */

:root {
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 12px;
  --space-lg: 16px;
  --space-xl: 20px;
  --space-2xl: 24px;
  --space-3xl: 32px;

  --text-xs: 0.75rem;
  --text-sm: 0.875rem;
  --text-base: 1rem;
  --text-lg: 1.125rem;

  --leading-tight: 1.25;
  --leading-normal: 1.5;
  --leading-relaxed: 1.65;

  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 8px;
  --radius-pill: 999px;

  --sphinx-primary: var(--pst-color-primary, #673ab7);
  --sphinx-primary-hover: var(--pst-color-secondary, #512da8);
  --sphinx-primary-soft: color-mix(in srgb, var(--sphinx-primary) 10%, transparent);
  --sphinx-background: var(--pst-color-background, #fff);
  --sphinx-surface: var(--pst-color-surface, var(--pst-color-background, #fff));
  --sphinx-subtle-surface: var(--pst-color-on-background, #f8f9fb);
  --sphinx-border: var(--pst-color-border, #d9d9d9);
  --sphinx-text-primary: var(--pst-color-text-base, #1f1f1f);
  --sphinx-text-secondary: var(--pst-color-text-muted, #5f6570);
  --sphinx-text-tertiary: var(--pst-color-text-muted, #6b7280);
  --sphinx-error: var(--pst-color-danger, #b3261e);
  --sphinx-error-surface: color-mix(in srgb, var(--sphinx-error) 10%, var(--sphinx-background));
  --sphinx-focus-ring: color-mix(in srgb, var(--sphinx-primary) 16%, transparent);
  --sphinx-shadow: 0 18px 48px rgba(15, 23, 42, 0.18);
  --sphinx-shadow-subtle: 0 6px 18px rgba(15, 23, 42, 0.08);
  --sphinx-font-sans: var(--pst-font-family-base-system, var(--pst-font-family-base, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif));
  --assistant-control-height: 40px;
  --assistant-control-radius: var(--radius-md);
}

html[data-theme="dark"] {
  --sphinx-shadow: 0 22px 52px rgba(0, 0, 0, 0.42);
  --sphinx-shadow-subtle: 0 8px 20px rgba(0, 0, 0, 0.28);
}

.sphinx-modal,
.sphinx-modal *,
.sphinx-modal *::before,
.sphinx-modal *::after {
  box-sizing: border-box;
}

.sphinx-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.42);
  z-index: 1001;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.18s ease, visibility 0.18s ease;
}

.sphinx-modal-overlay.show {
  opacity: 1;
  visibility: visible;
}

.sphinx-modal {
  position: fixed;
  top: 50%;
  left: 50%;
  display: flex;
  flex-direction: column;
  width: min(820px, calc(100vw - 32px));
  max-height: min(760px, calc(100vh - 40px));
  overflow: hidden;
  background: var(--sphinx-background);
  border: 1px solid var(--sphinx-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--sphinx-shadow);
  color: var(--sphinx-text-primary);
  font-family: var(--sphinx-font-sans);
  opacity: 0;
  transform: translate(-50%, -48%) scale(0.985);
  transition: opacity 0.18s ease, transform 0.18s ease, visibility 0.18s ease;
  visibility: hidden;
  z-index: 1002;
}

.sphinx-modal.show {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
  visibility: visible;
}

.sphinx-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-md);
  padding: var(--space-md) var(--space-xl);
  background: var(--sphinx-surface);
  border-bottom: 1px solid var(--sphinx-border);
}

.sphinx-modal-header-content {
  min-width: 0;
}

.sphinx-modal-title {
  margin: 0;
  color: var(--sphinx-text-primary);
  font-size: var(--text-base);
  font-weight: 650;
  line-height: var(--leading-tight);
}

.sphinx-modal-actions {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.sphinx-modal-reset,
.sphinx-modal-close {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 32px;
  border: 1px solid var(--sphinx-border);
  border-radius: var(--radius-md);
  background: var(--sphinx-background);
  color: var(--sphinx-text-secondary);
  cursor: pointer;
  font-family: inherit;
  font-size: var(--text-xs);
  font-weight: 600;
  line-height: 1;
  transition: background 0.16s ease, border-color 0.16s ease, color 0.16s ease;
}

.sphinx-modal-reset {
  padding: 0 var(--space-md);
}

.sphinx-modal-close {
  width: 32px;
  padding: 0;
  font-size: var(--text-lg);
}

.sphinx-modal-reset:hover:not(:disabled),
.sphinx-modal-close:hover {
  background: var(--sphinx-primary-soft);
  border-color: var(--sphinx-primary);
  color: var(--sphinx-primary);
}

.sphinx-modal-reset:focus-visible,
.sphinx-modal-close:focus-visible,
.sphinx-submit-btn:focus-visible,
.sphinx-suggested-prompt:focus-visible,
.sphinx-input-container textarea:focus-visible {
  outline: 2px solid var(--sphinx-primary);
  outline-offset: 2px;
}

.sphinx-modal-body {
  display: flex;
  min-height: 0;
  flex: 1;
  background: var(--sphinx-background);
  overflow: hidden;
}

.sphinx-modal-footer {
  padding: 0 var(--space-xl) 10px;
  background: var(--sphinx-surface);
  border-top: 0;
  color: var(--sphinx-text-secondary);
  font-size: 0.72rem;
  line-height: var(--leading-normal);
  text-align: center;
}

.sphinx-ai-chat {
  display: flex;
  flex: 1;
  flex-direction: column;
  height: min(560px, calc(100vh - 190px));
  min-height: 320px;
  min-width: 0;
}

.sphinx-chat-messages {
  flex: 1;
  overflow-x: hidden;
  overflow-y: auto;
  padding: var(--space-xl);
  background: var(--sphinx-background);
}

.sphinx-chat-messages:has(.sphinx-chat-empty) {
  display: grid;
  align-items: center;
}

.sphinx-message {
  display: flex;
  margin-bottom: var(--space-lg);
}

.sphinx-message.user-message {
  justify-content: flex-end;
}

.sphinx-message-content {
  width: 100%;
  color: var(--sphinx-text-primary);
  font-size: var(--text-sm);
  line-height: var(--leading-relaxed);
}

.ai-message .sphinx-message-content {
  padding: var(--space-lg) var(--space-xl);
  background: var(--sphinx-background);
  border: 1px solid var(--sphinx-border);
  border-radius: var(--radius-lg);
}

.user-message .sphinx-message-content {
  width: auto;
  max-width: min(72%, 620px);
  padding: 9px var(--space-md);
  background: var(--sphinx-surface);
  border: 1px solid var(--sphinx-border);
  border-radius: var(--radius-lg);
}

.sphinx-message-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-sm);
  margin-bottom: var(--space-sm);
}

.sphinx-message-label {
  color: var(--sphinx-text-secondary);
  font-size: var(--text-xs);
  font-weight: 650;
  line-height: var(--leading-tight);
}

.sphinx-query-plan {
  display: inline-flex;
  max-width: 100%;
  padding: 1px 6px;
  overflow: hidden;
  background: var(--sphinx-surface);
  border: 1px solid var(--sphinx-border);
  border-radius: var(--radius-sm);
  color: var(--sphinx-text-secondary);
  font-size: 0.68rem;
  line-height: var(--leading-normal);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sphinx-message-text {
  margin: 0;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.ai-message .sphinx-message-text {
  white-space: normal;
}

.sphinx-message-text h1,
.sphinx-message-text h2,
.sphinx-message-text h3 {
  margin: var(--space-lg) 0 var(--space-sm);
  color: var(--sphinx-text-primary);
  font-weight: 650;
  line-height: var(--leading-tight);
}

.sphinx-message-text h1 {
  font-size: var(--text-lg);
}

.sphinx-message-text h2,
.sphinx-message-text h3 {
  font-size: var(--text-base);
}

.sphinx-message-text p {
  margin: 0 0 var(--space-md);
}

.sphinx-message-text p:last-child,
.sphinx-message-text ul:last-child,
.sphinx-message-text ol:last-child,
.sphinx-message-text pre:last-child {
  margin-bottom: 0;
}

.sphinx-message-text strong {
  color: var(--sphinx-text-primary);
  font-weight: 650;
}

.sphinx-message-text code {
  padding: 1px 5px;
  background: var(--sphinx-subtle-surface);
  border: 1px solid var(--sphinx-border);
  border-radius: var(--radius-sm);
  color: var(--sphinx-text-primary);
  font-family: var(--pst-font-family-monospace-system, var(--pst-font-family-monospace, "SFMono-Regular", Consolas, monospace));
  font-size: 0.9em;
}

.sphinx-message-text pre {
  margin: var(--space-md) 0;
  padding: var(--space-md);
  overflow-x: auto;
  background: var(--sphinx-subtle-surface);
  border: 1px solid var(--sphinx-border);
  border-radius: var(--radius-md);
}

.sphinx-message-text pre code {
  padding: 0;
  background: transparent;
  border: 0;
  border-radius: 0;
  font-size: 0.85em;
}

.sphinx-message-text ul,
.sphinx-message-text ol {
  margin: var(--space-sm) 0 var(--space-md);
  padding-left: var(--space-xl);
}

.sphinx-message-text li {
  margin: 2px 0;
}

.sphinx-message-text a,
.sphinx-source a {
  color: var(--sphinx-primary);
  text-decoration: none;
}

.sphinx-message-text a:hover {
  color: var(--sphinx-primary-hover);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.sphinx-source:hover a {
  color: var(--sphinx-primary-hover);
  text-decoration: none;
}

.sphinx-chat-input {
  flex-shrink: 0;
  padding: var(--space-md) var(--space-xl) 8px;
  background: var(--sphinx-surface);
  border-top: 1px solid var(--sphinx-border);
}

.sphinx-input-container {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: var(--space-sm);
  align-items: end;
}

.sphinx-input-left-controls {
  display: flex;
  align-items: center;
  min-height: var(--assistant-control-height);
}

.sphinx-mode-selector-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.sphinx-input-container textarea {
  appearance: none;
  width: 100%;
  height: var(--assistant-control-height);
  min-height: var(--assistant-control-height);
  max-height: 120px;
  padding: 8px var(--space-md);
  resize: none;
  background: var(--sphinx-background);
  border: 1px solid var(--sphinx-border);
  border-radius: var(--assistant-control-radius);
  color: var(--sphinx-text-primary);
  font-family: inherit;
  font-size: var(--text-sm);
  line-height: var(--leading-normal);
  transition: border-color 0.16s ease, box-shadow 0.16s ease;
}

.sphinx-input-container textarea:focus {
  border-color: var(--sphinx-primary);
  box-shadow: 0 0 0 2px var(--sphinx-focus-ring);
  outline: none;
}

.sphinx-input-container textarea::placeholder {
  color: var(--sphinx-text-tertiary);
}

.sphinx-submit-btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 80px;
  height: var(--assistant-control-height);
  min-width: 80px;
  padding: 0 var(--space-md);
  background: var(--sphinx-primary);
  border: 1px solid var(--sphinx-primary);
  border-radius: var(--assistant-control-radius);
  color: #fff;
  cursor: pointer;
  font-family: inherit;
  font-size: var(--text-sm);
  font-weight: 650;
  line-height: 1;
  transition: background 0.16s ease, border-color 0.16s ease, opacity 0.16s ease;
}

.sphinx-submit-btn:hover:not(:disabled) {
  background: var(--sphinx-primary-hover);
  border-color: var(--sphinx-primary-hover);
}

.sphinx-submit-btn:disabled {
  cursor: not-allowed;
  opacity: 0.58;
}

.sphinx-sources {
  margin-top: var(--space-lg);
  padding-top: var(--space-sm);
  border-top: 1px solid var(--sphinx-border);
  counter-reset: sphinx-source;
}

.sphinx-sources h4 {
  margin: 0 0 var(--space-sm);
  color: var(--sphinx-text-secondary);
  font-size: var(--text-xs);
  font-weight: 650;
  line-height: var(--leading-tight);
}

.sphinx-source {
  margin-bottom: 2px;
}

.sphinx-source a {
  display: grid;
  grid-template-columns: 20px minmax(0, 1fr);
  column-gap: var(--space-sm);
  padding: 5px 0;
  background: transparent;
  border: 0;
  border-radius: 0;
}

.sphinx-source a::before {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  background: var(--sphinx-surface);
  border: 1px solid var(--sphinx-border);
  border-radius: var(--radius-sm);
  color: var(--sphinx-text-secondary);
  content: counter(sphinx-source);
  counter-increment: sphinx-source;
  font-size: 0.68rem;
  font-weight: 650;
  line-height: 1;
}

.sphinx-source:hover a::before {
  color: var(--sphinx-primary-hover);
  text-decoration: none;
}

.sphinx-source:hover .sphinx-source-title,
.sphinx-source:hover .sphinx-source-excerpt {
  text-decoration: underline;
  text-underline-offset: 2px;
}

.sphinx-source-title {
  display: block;
  font-size: var(--text-sm);
  font-weight: 650;
  line-height: var(--leading-tight);
  min-width: 0;
}

.sphinx-source-excerpt {
  display: block;
  grid-column: 2;
  margin-top: 3px;
  color: var(--sphinx-text-secondary);
  font-size: var(--text-xs);
  line-height: var(--leading-normal);
}

.sphinx-message.loading .sphinx-message-text {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  color: var(--sphinx-text-secondary);
}

.sphinx-message.loading .sphinx-message-text::before {
  width: 14px;
  height: 14px;
  border: 2px solid var(--sphinx-border);
  border-top-color: var(--sphinx-primary);
  border-radius: 50%;
  animation: sphinx-spin 0.9s linear infinite;
  content: "";
}

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

.sphinx-streaming-indicator {
  display: inline-block;
  width: 6px;
  height: 6px;
  background: var(--sphinx-primary);
  border-radius: 50%;
  animation: sphinx-pulse 1.4s ease-in-out infinite;
}

@keyframes sphinx-pulse {
  0%,
  100% {
    opacity: 0.35;
  }

  50% {
    opacity: 1;
  }
}

.sphinx-chat-empty {
  max-width: 520px;
  margin: 0 auto;
  padding: var(--space-xl) var(--space-md) var(--space-2xl);
  color: var(--sphinx-text-secondary);
  text-align: center;
}

.sphinx-chat-empty h3 {
  margin: 0 0 var(--space-xs);
  color: var(--sphinx-text-primary);
  font-size: var(--text-lg);
  font-weight: 650;
  line-height: var(--leading-tight);
}

.sphinx-chat-empty p {
  margin: 0 0 var(--space-lg);
  color: var(--sphinx-text-secondary);
  font-size: var(--text-sm);
}

.sphinx-suggested-prompts {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-sm);
}

.sphinx-suggested-prompt {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 7px var(--space-md);
  background: var(--sphinx-background);
  border: 1px solid var(--sphinx-border);
  border-radius: var(--radius-md);
  color: var(--sphinx-text-primary);
  cursor: pointer;
  font-family: inherit;
  font-size: var(--text-xs);
  font-weight: 550;
  line-height: var(--leading-normal);
  text-align: center;
  transition: background 0.16s ease, border-color 0.16s ease, color 0.16s ease;
}

.sphinx-suggested-prompt:hover {
  background: var(--sphinx-primary-soft);
  border-color: var(--sphinx-primary);
  color: var(--sphinx-primary);
}

.sphinx-message.error .sphinx-message-content {
  background: var(--sphinx-error-surface);
  border-color: color-mix(in srgb, var(--sphinx-error) 28%, var(--sphinx-border));
  color: var(--sphinx-error);
}

.sphinx-error-icon {
  color: var(--sphinx-error);
  margin-right: var(--space-xs);
}

.sphinx-chat-messages::-webkit-scrollbar {
  width: 8px;
}

.sphinx-chat-messages::-webkit-scrollbar-track {
  background: transparent;
}

.sphinx-chat-messages::-webkit-scrollbar-thumb {
  background: var(--sphinx-border);
  border: 2px solid var(--sphinx-background);
  border-radius: var(--radius-pill);
}

@media (prefers-reduced-motion: reduce) {
  .sphinx-modal-overlay,
  .sphinx-modal,
  .sphinx-modal-reset,
  .sphinx-modal-close,
  .sphinx-submit-btn,
  .sphinx-suggested-prompt,
  .sphinx-input-container textarea,
  .sphinx-streaming-indicator,
  .sphinx-message.loading .sphinx-message-text::before {
    animation: none;
    transition: none;
  }
}

@media (max-height: 560px) {
  .sphinx-modal {
    max-height: calc(100vh - 20px);
  }

  .sphinx-ai-chat {
    height: calc(100vh - 150px);
    min-height: 220px;
  }
}

@media (max-width: 768px) {
  .sphinx-modal {
    width: calc(100vw - 20px);
    max-height: calc(100vh - 20px);
  }

  .sphinx-modal-header,
  .sphinx-chat-messages,
  .sphinx-chat-input,
  .sphinx-modal-footer {
    padding-left: var(--space-md);
    padding-right: var(--space-md);
  }

  .sphinx-chat-messages:has(.sphinx-chat-empty) {
    display: block;
  }

  .sphinx-ai-chat {
    height: min(520px, calc(100vh - 160px));
    min-height: 280px;
  }

  .sphinx-input-container {
    grid-template-columns: auto minmax(0, 1fr) auto;
  }

  .user-message .sphinx-message-content {
    max-width: 86%;
  }

  .sphinx-suggested-prompts {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 520px) {
  .sphinx-modal-title {
    font-size: var(--text-sm);
  }

  .sphinx-modal-reset {
    padding: 0 var(--space-sm);
  }

  .sphinx-ai-chat {
    height: min(460px, calc(100vh - 142px));
  }

  .sphinx-input-container {
    grid-template-columns: 1fr auto;
  }

  .sphinx-input-left-controls {
    grid-column: 1 / -1;
    min-height: 32px;
  }

  .sphinx-submit-btn {
    min-width: 72px;
    width: 72px;
  }
}
