/**
 * Catalyst AI Chat Widget Styles
 * Extracted for performance optimization
 */

#catalyst-chat-widget {
  --chat-primary: #6366f1;
  --chat-primary-hover: #4f46e5;
  --chat-bg: rgba(24, 24, 27, 0.95);
  --chat-surface: rgba(39, 39, 42, 0.9);
  --chat-border: rgba(255,255,255,0.1);
  --chat-text: #ffffff;
  --chat-text-muted: #a1a1aa;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  position: fixed;
  z-index: 99999;
}

/* Backdrop blur overlay */
.catalyst-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  opacity: 0;
  visibility: hidden;
  transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 99998;
}

.catalyst-backdrop.open {
  opacity: 1;
  visibility: visible;
}

/* Bottom bar (collapsed state) */
.catalyst-bar {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  width: 420px;
  max-width: calc(100vw - 48px);
  height: 52px;
  background: var(--chat-surface);
  border: 1px solid var(--chat-border);
  border-radius: 26px;
  display: flex;
  align-items: center;
  padding: 0 8px 0 20px;
  gap: 12px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3), 0 0 0 1px rgba(255,255,255,0.05);
  cursor: text;
  transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 99999;
}

.catalyst-bar:hover {
  border-color: rgba(99, 102, 241, 0.3);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4), 0 0 0 1px rgba(99, 102, 241, 0.2);
}

.catalyst-bar.open {
  bottom: auto;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 680px;
  max-width: calc(100vw - 48px);
  height: calc(100vh - 120px);
  max-height: 700px;
  border-radius: 20px;
  flex-direction: column;
  padding: 0;
  cursor: default;
}

.catalyst-bar-placeholder {
  flex: 1;
  color: var(--chat-text-muted);
  font-size: 14px;
  pointer-events: none;
  display: flex;
  align-items: center;
  gap: 8px;
}

.catalyst-bar.open .catalyst-bar-placeholder {
  display: none;
}

.catalyst-bar-shortcut {
  display: flex;
  align-items: center;
  gap: 4px;
  color: var(--chat-text-muted);
  font-size: 12px;
  opacity: 0.6;
}

.catalyst-bar-shortcut kbd {
  background: rgba(255,255,255,0.1);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: inherit;
  font-size: 11px;
}

.catalyst-bar.open .catalyst-bar-shortcut {
  display: none;
}

.catalyst-bar-icon {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--chat-primary) 0%, #8b5cf6 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.catalyst-bar.open .catalyst-bar-icon {
  display: none;
}

.catalyst-bar-icon svg {
  width: 18px;
  height: 18px;
  color: white;
}

/* Chat container (shown when open) */
.catalyst-chat-container {
  display: none;
  flex-direction: column;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

.catalyst-bar.open .catalyst-chat-container {
  display: flex;
}

/* Header */
.catalyst-chat-header {
  padding: 20px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--chat-border);
  flex-shrink: 0;
}

.catalyst-chat-title {
  display: flex;
  align-items: center;
  gap: 12px;
}

.catalyst-chat-avatar {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--chat-primary) 0%, #8b5cf6 100%);
  display: flex;
  align-items: center;
  justify-content: center;
}

.catalyst-chat-avatar svg {
  width: 22px;
  height: 22px;
  color: white;
}

.catalyst-chat-info h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  color: var(--chat-text);
}

.catalyst-chat-info p {
  margin: 2px 0 0;
  font-size: 12px;
  color: #22c55e;
  display: flex;
  align-items: center;
  gap: 4px;
}

.catalyst-chat-info p::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #22c55e;
}

/* AI Stats Bar */
.catalyst-stats-bar {
  display: none;
  padding: 12px 24px;
  background: rgba(99, 102, 241, 0.08);
  border-bottom: 1px solid var(--chat-border);
  flex-shrink: 0;
}

.catalyst-stats-bar.visible {
  display: block;
}

.catalyst-stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 24px;
}

.catalyst-stat {
  text-align: center;
}

.catalyst-stat-value {
  font-size: 18px;
  font-weight: 700;
  color: var(--chat-text);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.catalyst-stat-value .faster {
  font-size: 11px;
  font-weight: 600;
  color: #22c55e;
  background: rgba(34, 197, 94, 0.15);
  padding: 2px 6px;
  border-radius: 4px;
}

.catalyst-stat-label {
  font-size: 10px;
  color: var(--chat-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-top: 2px;
}

.catalyst-stat-compare {
  font-size: 10px;
  color: var(--chat-text-muted);
  margin-top: 4px;
}

.catalyst-stat-compare span {
  color: #ef4444;
  text-decoration: line-through;
  opacity: 0.7;
}

.catalyst-close-btn {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--chat-border);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
  color: var(--chat-text-muted);
}

.catalyst-close-btn:hover {
  background: rgba(255,255,255,0.1);
  color: var(--chat-text);
}

.catalyst-close-btn svg {
  width: 18px;
  height: 18px;
}

/* Messages */
.catalyst-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.catalyst-chat-messages::-webkit-scrollbar {
  width: 6px;
}

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

.catalyst-chat-messages::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.1);
  border-radius: 3px;
}

.catalyst-chat-messages::-webkit-scrollbar-thumb:hover {
  background: rgba(255,255,255,0.2);
}

/* Welcome state */
.catalyst-welcome {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 40px;
}

.catalyst-welcome-icon {
  width: 72px;
  height: 72px;
  border-radius: 20px;
  background: linear-gradient(135deg, var(--chat-primary) 0%, #8b5cf6 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 24px;
  box-shadow: 0 8px 24px rgba(99, 102, 241, 0.3);
}

.catalyst-welcome-icon svg {
  width: 36px;
  height: 36px;
  color: white;
}

.catalyst-welcome h2 {
  margin: 0 0 8px;
  font-size: 22px;
  font-weight: 600;
  color: var(--chat-text);
}

.catalyst-welcome p {
  margin: 0 0 32px;
  font-size: 14px;
  color: var(--chat-text-muted);
  max-width: 300px;
  line-height: 1.6;
}

.catalyst-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  max-width: 400px;
}

.catalyst-suggestion {
  padding: 10px 16px;
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--chat-border);
  border-radius: 20px;
  font-size: 13px;
  color: var(--chat-text);
  cursor: pointer;
  transition: all 0.2s ease;
}

.catalyst-suggestion:hover {
  background: var(--chat-primary);
  border-color: var(--chat-primary);
}

/* Message bubbles */
.catalyst-message {
  display: flex;
  gap: 12px;
  max-width: 100%;
  animation: messageIn 0.3s ease;
}

@keyframes messageIn {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.catalyst-message.user {
  flex-direction: row-reverse;
}

.catalyst-message-avatar {
  width: 32px;
  height: 32px;
  border-radius: 10px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.catalyst-message.assistant .catalyst-message-avatar {
  background: linear-gradient(135deg, var(--chat-primary) 0%, #8b5cf6 100%);
}

.catalyst-message.user .catalyst-message-avatar {
  background: rgba(255,255,255,0.1);
}

.catalyst-message-avatar svg {
  width: 16px;
  height: 16px;
  color: white;
}

.catalyst-message-content {
  flex: 1;
  min-width: 0;
}

.catalyst-message-bubble {
  padding: 14px 18px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.6;
  word-wrap: break-word;
}

.catalyst-message.user .catalyst-message-bubble {
  background: linear-gradient(135deg, var(--chat-primary) 0%, #8b5cf6 100%);
  color: white;
  border-bottom-right-radius: 4px;
}

.catalyst-message.assistant .catalyst-message-bubble {
  background: rgba(255,255,255,0.05);
  color: var(--chat-text);
  border: 1px solid var(--chat-border);
  border-bottom-left-radius: 4px;
}

.catalyst-message-bubble strong {
  font-weight: 600;
  color: var(--chat-primary);
}

.catalyst-message.user .catalyst-message-bubble strong {
  color: white;
}

.catalyst-message-bubble code {
  background: rgba(0,0,0,0.3);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: 'SF Mono', Monaco, monospace;
  font-size: 12px;
}

.catalyst-message-bubble .chat-table {
  width: 100%;
  border-collapse: collapse;
  margin: 12px 0;
  font-size: 13px;
}

.catalyst-message-bubble .chat-table th,
.catalyst-message-bubble .chat-table td {
  padding: 8px 12px;
  border: 1px solid var(--chat-border);
  text-align: left;
}

.catalyst-message-bubble .chat-table th {
  background: rgba(255,255,255,0.05);
  font-weight: 600;
}

.catalyst-message-bubble ul {
  margin: 8px 0;
  padding-left: 20px;
}

.catalyst-message-bubble li {
  margin: 4px 0;
}

.catalyst-message-sources {
  margin-top: 10px;
  padding: 10px 14px;
  background: rgba(99, 102, 241, 0.1);
  border: 1px solid rgba(99, 102, 241, 0.2);
  border-radius: 10px;
  font-size: 12px;
  color: var(--chat-text-muted);
}

.catalyst-message-sources strong {
  color: var(--chat-primary);
  margin-right: 4px;
}

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

.catalyst-typing span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--chat-text-muted);
  animation: typing 1.4s infinite ease-in-out;
}

.catalyst-typing span:nth-child(2) { animation-delay: 0.2s; }
.catalyst-typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-4px); opacity: 1; }
}

/* Diffusion effect - text refines in place */

.catalyst-message-bubble.catalyst-final {
  font-family: inherit;
  letter-spacing: normal;
  animation: textClear 0.3s ease-out;
}

@keyframes textClear {
  from { opacity: 0.8; }
  to { opacity: 1; }
}

/* Input area */
.catalyst-chat-input {
  padding: 20px 24px;
  border-top: 1px solid var(--chat-border);
  flex-shrink: 0;
}

.catalyst-chat-input form {
  display: flex;
  gap: 12px;
  align-items: center;
}

.catalyst-chat-input input {
  flex: 1;
  height: 48px;
  padding: 0 18px;
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--chat-border);
  border-radius: 14px;
  color: var(--chat-text);
  font-size: 14px;
  outline: none;
  transition: all 0.2s ease;
}

.catalyst-chat-input input::placeholder {
  color: var(--chat-text-muted);
}

.catalyst-chat-input input:focus {
  border-color: var(--chat-primary);
  background: rgba(99, 102, 241, 0.05);
}

.catalyst-chat-input button {
  width: 48px;
  height: 48px;
  background: linear-gradient(135deg, var(--chat-primary) 0%, #8b5cf6 100%);
  border: none;
  border-radius: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.catalyst-chat-input button:hover:not(:disabled) {
  transform: scale(1.05);
  box-shadow: 0 4px 16px rgba(99, 102, 241, 0.4);
}

.catalyst-chat-input button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.catalyst-chat-input button svg {
  width: 20px;
  height: 20px;
  color: white;
}

/* Footer */
.catalyst-chat-footer {
  padding: 12px 24px;
  text-align: center;
  font-size: 11px;
  color: var(--chat-text-muted);
  border-top: 1px solid var(--chat-border);
  flex-shrink: 0;
}

.catalyst-chat-footer a {
  color: var(--chat-primary);
  text-decoration: none;
}

.catalyst-chat-footer a:hover {
  text-decoration: underline;
}

/* Mobile responsiveness */
@media (max-width: 720px) {
  .catalyst-bar {
    width: calc(100vw - 32px);
    bottom: 16px;
  }

  .catalyst-bar.open {
    width: 100vw;
    max-width: 100vw;
    height: 100vh;
    max-height: 100vh;
    top: 0;
    left: 0;
    transform: none;
    border-radius: 0;
  }

  .catalyst-bar-shortcut {
    display: none;
  }

  .catalyst-chat-messages {
    padding: 16px;
  }

  .catalyst-chat-header,
  .catalyst-chat-input,
  .catalyst-chat-footer {
    padding-left: 16px;
    padding-right: 16px;
  }
}
