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

#catalyst-chat-widget {
  --chat-primary: #ffffff;
  --chat-primary-hover: #d4d4d8;
  --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(255, 255, 255, 0.2);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4), 0 0 0 1px rgba(255, 255, 255, 0.1);
}

.catalyst-bar.open {
  bottom: auto;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 500px;
  max-width: calc(100vw - 48px);
  height: calc(100vh - 160px);
  max-height: 520px;
  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: rgba(255, 255, 255, 0.12);
  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: rgba(255, 255, 255, 0.12);
  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: #a1a1aa;
  display: flex;
  align-items: center;
  gap: 4px;
}

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

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

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

.catalyst-stats-grid {
  display: flex;
  justify-content: center;
  gap: 24px;
}

.catalyst-stat {
  display: flex;
  align-items: center;
  gap: 6px;
}

.catalyst-stat-value {
  font-size: 13px;
  font-weight: 600;
  color: var(--chat-text);
  display: flex;
  align-items: center;
  gap: 4px;
}

.catalyst-stat-value .faster {
  font-size: 10px;
  font-weight: 600;
  color: #a1a1aa;
  background: rgba(255, 255, 255, 0.08);
  padding: 1px 5px;
  border-radius: 4px;
}

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

.catalyst-stat-compare {
  display: none;
}

.catalyst-stat-compare span {
  color: #71717a;
  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: rgba(255, 255, 255, 0.12);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 24px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 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: rgba(255, 255, 255, 0.15);
  border-color: rgba(255, 255, 255, 0.2);
}

/* 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: rgba(255, 255, 255, 0.12);
}

.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: rgba(255, 255, 255, 0.12);
  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;
}

/* Navigation links in chat */
.chat-nav-link {
  display: inline-block;
  margin-top: 8px;
  padding: 8px 16px;
  background: rgba(255, 255, 255, 0.12);
  color: white;
  text-decoration: none;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 500;
  transition: all 0.2s ease;
  cursor: pointer;
}

.chat-nav-link:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.catalyst-message-sources {
  margin-top: 10px;
  padding: 10px 14px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  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: rgba(255, 255, 255, 0.3);
  background: rgba(255, 255, 255, 0.08);
}

.catalyst-chat-input button {
  width: 48px;
  height: 48px;
  background: rgba(255, 255, 255, 0.12);
  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(0, 0, 0, 0.3);
}

.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;
  display: flex;
  justify-content: space-between;
  align-items: 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;
}

.catalyst-session-id {
  font-family: monospace;
  font-size: 10px;
  color: var(--chat-text-muted);
  opacity: 0.6;
  transition: opacity 0.2s;
}

.catalyst-session-id:hover {
  opacity: 1;
}

/* Combo popup — hidden by default, shown only on mobile */
.catalyst-combo-popup,
.catalyst-combo-backdrop,
.catalyst-combo-btn {
  display: none !important;
}

/* Mobile responsiveness */
@media (max-width: 720px) {
  .catalyst-bar {
    width: 56px;
    height: 56px;
    bottom: 16px;
    right: 16px;
    left: auto;
    padding: 0;
    border-radius: 50%;
    z-index: 999999;
  }

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

  .catalyst-bar-icon {
    width: 56px;
    height: 56px;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    margin: 0;
    border-radius: 50%;
  }

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

  .catalyst-bar.open {
    top: auto;
    left: auto;
    right: 8px;
    bottom: 8px;
    width: calc(100vw - 16px);
    height: calc(100dvh - 16px);
    max-width: calc(100vw - 16px);
    max-height: calc(100dvh - 16px);
    padding: 0;
    transform: none;
    border-radius: 16px;
    background: var(--chat-bg);
  }

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

  .catalyst-chat-messages {
    padding: 16px;
    -webkit-overflow-scrolling: touch;
    overflow-y: auto;
    overscroll-behavior: contain;
  }

  .catalyst-chat-header {
    padding: 12px 16px;
    padding-top: calc(12px + env(safe-area-inset-top, 0px));
    padding-left: calc(16px + env(safe-area-inset-left, 0px));
    padding-right: calc(16px + env(safe-area-inset-right, 0px));
    background: transparent;
    border-bottom: 1px solid var(--chat-border);
  }

  .catalyst-chat-input {
    padding-left: calc(16px + env(safe-area-inset-left, 0px));
    padding-right: calc(16px + env(safe-area-inset-right, 0px));
  }

  .catalyst-chat-footer {
    padding: 10px 16px;
    padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
    padding-left: calc(16px + env(safe-area-inset-left, 0px));
    padding-right: calc(16px + env(safe-area-inset-right, 0px));
    background: transparent;
    border-top: 1px solid var(--chat-border);
  }

  /* Hide top nav glass pill on mobile — combo bubble replaces it */
  nav.fixed .glass {
    display: none;
  }

  /* Combo popup above the bubble */
  .catalyst-combo-popup {
    position: fixed;
    bottom: 80px;
    right: 16px;
    display: flex !important;
    flex-direction: column;
    gap: 8px;
    z-index: 999998;
    opacity: 0;
    transform: scale(0.8) translateY(10px);
    transform-origin: bottom right;
    pointer-events: none;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  }

  .catalyst-combo-btn {
    display: flex !important;
  }

  .catalyst-combo-popup.visible {
    opacity: 1;
    transform: scale(1) translateY(0);
    pointer-events: auto;
  }

  .catalyst-combo-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 20px;
    background: rgba(39, 39, 42, 0.95);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 16px;
    color: #fff;
    font-size: 14px;
    font-weight: 500;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    cursor: pointer;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    transition: all 0.2s ease;
    white-space: nowrap;
  }

  .catalyst-combo-btn:active {
    transform: scale(0.95);
    background: rgba(255, 255, 255, 0.15);
  }

  .catalyst-combo-btn svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
  }

  .catalyst-combo-backdrop {
    position: fixed;
    inset: 0;
    z-index: 999997;
    display: none;
  }

  .catalyst-combo-backdrop.visible {
    display: block;
  }
}
