/* Chat-specific styles for WebLLM integration */

/* CSS variables */
:root {
  --ai-name: "AI"; /* Default AI name, overridden by config */
}

/* Chat message containers */
.chat-message {
  margin: 1em 0;
  padding: 0.75em 1em;
  border-radius: 4px;
  animation: fadeIn 0.3s ease-in;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* User messages */
.chat-message.user {
  background: rgba(100, 200, 255, 0.1);
  border-left: 3px solid #64c8ff;
}

.chat-message.user::before {
  content: "💬 You: ";
  font-weight: 600;
  color: #64c8ff;
}

/* AI messages */
.chat-message.assistant {
  background: rgba(100, 255, 150, 0.1);
  border-left: 3px solid #64ff96;
}

.chat-message.assistant::before {
  content: "🤖 " var(--ai-name) ": ";
  font-weight: 600;
  color: #64ff96;
}

/* System/error messages */
.chat-message.system {
  background: rgba(255, 200, 100, 0.1);
  border-left: 3px solid #ffc864;
  font-style: italic;
}

.chat-message.error {
  background: rgba(255, 100, 100, 0.1);
  border-left: 3px solid #ff6464;
}

.chat-message.error::before {
  content: "⚠️ Error: ";
  font-weight: 600;
  color: #ff6464;
}

/* Loading indicator for AI thinking */
.chat-loading {
  display: inline-block;
  margin: 1em 0;
  padding: 0.75em 1em;
  background: rgba(100, 255, 150, 0.1);
  border-left: 3px solid #64ff96;
  border-radius: 4px;
  animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {

  0%,
  100% {
    opacity: 0.6;
  }

  50% {
    opacity: 1;
  }
}

.chat-loading::before {
  content: "🤖 AI is thinking";
}

.chat-loading .dots {
  display: inline-block;
  width: 20px;
}

.chat-loading .dots::after {
  content: "...";
  animation: ellipsis 1.5s infinite;
}

@keyframes ellipsis {
  0% {
    content: ".";
  }

  33% {
    content: "..";
  }

  66% {
    content: "...";
  }
}

/* Model loading progress bar - thin bar above input */
.model-progress-bar {
  position: fixed;
  bottom: 3.2em;
  /* Right above the input bar */
  left: 0;
  right: 0;
  width: 100%;
  height: 3px;
  background: rgba(100, 255, 150, 0.1);
  z-index: 1000;
  transition: opacity 0.3s ease;
}

.model-progress-text {
  position: fixed;
  bottom: 5em;
  /* Just above the progress bar */
  left: 50%;
  transform: translateX(-50%);
  color: #64c8ff;
  font-size: 0.75em;
  font-weight: bold;
  text-align: center;
  z-index: 1001;
  pointer-events: none;
  text-shadow: 0 0 5px rgba(100, 200, 255, 0.5);
  white-space: nowrap;
  transition: opacity 0.3s ease;
}

.model-progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #64c8ff, #64ff96);
  transition: width 0.3s ease, background 0.5s ease;
  position: relative;
  overflow: hidden;
}

.model-progress-fill::after {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(90deg,
      transparent,
      rgba(255, 255, 255, 0.4),
      transparent);
  animation: shimmer 1.5s infinite;
}

/* Model loading progress overlay (for important messages) */
.model-loading {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(0, 0, 0, 0.95);
  border: 2px solid #64ff96;
  border-radius: 8px;
  padding: 2em;
  min-width: 300px;
  max-width: 500px;
  z-index: 9999;
  box-shadow: 0 0 20px rgba(100, 255, 150, 0.3);
}

.model-loading h3 {
  margin: 0 0 1em 0;
  color: #64ff96;
  font-size: 1.2em;
}

.model-loading .progress-bar {
  width: 100%;
  height: 20px;
  background: rgba(100, 255, 150, 0.1);
  border: 1px solid #64ff96;
  border-radius: 4px;
  overflow: hidden;
  position: relative;
}

.model-loading .progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #64ff96, #32cd5c);
  transition: width 0.3s ease;
  position: relative;
  overflow: hidden;
}

.model-loading .progress-fill::after {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(90deg,
      transparent,
      rgba(255, 255, 255, 0.3),
      transparent);
  animation: shimmer 1.5s infinite;
}

@keyframes shimmer {
  0% {
    transform: translateX(-100%);
  }

  100% {
    transform: translateX(100%);
  }
}

.model-loading .progress-text {
  margin-top: 0.5em;
  font-size: 0.9em;
  color: #64ff96;
  text-align: center;
}

.model-loading .progress-details {
  margin-top: 0.5em;
  font-size: 0.8em;
  color: #aaa;
  text-align: center;
}

/* ASCII art styling */
.ascii-art {
  font-family: 'IBM Plex Mono', 'Courier New', monospace;
  white-space: pre;
  line-height: 1.2;
  color: #64ff96;
  font-size: 0.8em;
  margin: 1em 0;
  overflow-x: auto;
}

/* Command suggestions in chat */
.chat-suggestion {
  display: inline-block;
  padding: 0.2em 0.5em;
  background: rgba(100, 200, 255, 0.2);
  border: 1px solid #64c8ff;
  border-radius: 3px;
  color: #64c8ff;
  cursor: pointer;
  margin: 0.2em;
  transition: all 0.2s ease;
}

.chat-suggestion:hover {
  background: rgba(100, 200, 255, 0.3);
  border-color: #32a0ff;
  transform: translateY(-2px);
}

/* AI Consent Buttons */
.ai-consent-btn {
  display: inline-block;
  padding: 0.6em 1.2em;
  margin: 0.3em;
  background: rgba(100, 255, 150, 0.2);
  border: 2px solid #64ff96;
  border-radius: 6px;
  color: #64ff96;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.95em;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
}

.ai-consent-btn:hover {
  background: rgba(100, 255, 150, 0.3);
  border-color: #32cd5c;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(100, 255, 150, 0.3);
}

.ai-consent-btn:active {
  transform: translateY(0);
}

.ai-consent-btn[data-consent="no"] {
  background: rgba(255, 200, 100, 0.2);
  border-color: #ffc864;
  color: #ffc864;
}

.ai-consent-btn[data-consent="no"]:hover {
  background: rgba(255, 200, 100, 0.3);
  border-color: #ff9632;
  box-shadow: 0 4px 12px rgba(255, 200, 100, 0.3);
}

/* Keyboard shortcut hint */
.kbd {
  display: inline-block;
  padding: 0.2em 0.4em;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 3px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.9em;
}

/* Typing indicator */
.typing-indicator {
  display: inline-block;
}

.typing-indicator span {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #64ff96;
  margin: 0 2px;
  animation: typing 1.4s infinite;
}

.typing-indicator span:nth-child(1) {
  animation-delay: 0s;
}

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

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

@keyframes typing {

  0%,
  60%,
  100% {
    transform: translateY(0);
    opacity: 0.7;
  }

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

/* Mobile responsiveness */
@media (max-width: 768px) {
  .model-loading {
    min-width: 250px;
    padding: 1.5em;
  }

  .chat-message {
    padding: 0.6em 0.8em;
    font-size: 0.95em;
  }
}

/* Thinking blocks for models that output thoughts */

/* Inline thinking toggle that appears after role label */
.think-toggle-inline {
  display: inline-flex;
  margin-left: 0.5em;
  vertical-align: middle;
}

.think-toggle-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.3em;
  background: rgba(150, 100, 255, 0.15);
  border: 1px solid rgba(150, 100, 255, 0.4);
  border-radius: 3px;
  padding: 0.2em 0.5em;
  color: #b896ff;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.75em;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.think-toggle-btn:hover {
  background: rgba(150, 100, 255, 0.25);
  border-color: rgba(150, 100, 255, 0.6);
}

.think-toggle-btn .think-icon {
  font-size: 0.9em;
}

.think-toggle-btn .think-label {
  font-weight: 500;
  opacity: 0.9;
}

.think-toggle-btn .think-arrow {
  font-size: 0.7em;
  transition: transform 0.2s ease;
}

.think-toggle-btn.expanded .think-arrow {
  transform: rotate(180deg);
}

/* Thinking block container */
.think-block {
  margin: 0.5em 0;
}

.think-toggle {
  display: flex;
  align-items: center;
  gap: 0.5em;
  background: rgba(150, 100, 255, 0.1);
  border: 1px solid rgba(150, 100, 255, 0.3);
  border-radius: 4px;
  padding: 0.4em 0.8em;
  color: #b896ff;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.85em;
  cursor: pointer;
  transition: all 0.2s ease;
  width: auto;
  margin-bottom: 0.3em;
}

.think-toggle:hover {
  background: rgba(150, 100, 255, 0.2);
  border-color: rgba(150, 100, 255, 0.5);
}

.think-icon {
  font-size: 1.1em;
}

.think-label {
  flex: 1;
  text-align: left;
  font-weight: 500;
  opacity: 0.9;
}

.think-arrow {
  font-size: 0.8em;
  transition: transform 0.2s ease;
}

.think-content {
  background: rgba(150, 100, 255, 0.05);
  border-left: 2px solid rgba(150, 100, 255, 0.3);
  border-radius: 3px;
  padding: 0.8em;
  margin-top: 0.3em;
  max-height: 500px;
  overflow-y: auto;
  transition: all 0.3s ease;
}

.think-content.collapsed {
  max-height: 0;
  padding: 0;
  margin: 0;
  overflow: hidden;
  opacity: 0;
}

.think-content:not(.collapsed)+.think-toggle .think-arrow,
.think-toggle:has(+ .think-content:not(.collapsed)) .think-arrow {
  transform: rotate(180deg);
}

.think-content pre {
  margin: 0;
  white-space: pre-wrap;
  word-wrap: break-word;
  font-family: 'IBM Plex Mono', 'Courier New', monospace;
  font-size: 0.85em;
  line-height: 1.5;
  color: #b896ff;
  opacity: 0.85;
}

/* Scrollbar styling for think content */
.think-content::-webkit-scrollbar {
  width: 6px;
}

.think-content::-webkit-scrollbar-track {
  background: rgba(150, 100, 255, 0.05);
}

.think-content::-webkit-scrollbar-thumb {
  background: rgba(150, 100, 255, 0.3);
  border-radius: 3px;
}

.think-content::-webkit-scrollbar-thumb:hover {
  background: rgba(150, 100, 255, 0.5);
}
