/* chat.css — AI-Do v4.0 glassmorphic chat interface */

/* ===== Container ===== */
.chat-container {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
  position: relative;
}

/* ===== Welcome Screen ===== */
.chat-welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  padding: var(--space-xl);
  text-align: center;
  gap: var(--space-xl);
  animation: fadeIn var(--transition-slow) ease-out;
}

.chat-welcome-greeting {
  max-width: 480px;
}

.chat-welcome-greeting h2 {
  font-size: var(--font-size-2xl);
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: var(--space-sm);
}

.chat-welcome-greeting p {
  font-size: var(--font-size-base);
  color: var(--text-secondary);
  line-height: var(--line-height-relaxed);
}

.chat-quick-actions {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-md);
  max-width: 480px;
  width: 100%;
}

.chat-quick-actions .glass-card {
  cursor: pointer;
  text-align: left;
  padding: var(--space-md);
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
  user-select: none;
}

.chat-quick-actions .glass-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--glass-shadow-lg);
}

.chat-quick-actions .glass-card:active {
  transform: translateY(-1px);
}

.chat-quick-actions .glass-card .card-icon {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  background: var(--accent-gradient);
  color: #fff;
  margin-bottom: var(--space-xs);
  flex-shrink: 0;
}

.chat-quick-actions .glass-card .card-icon svg {
  width: 18px;
  height: 18px;
}

.chat-quick-actions .glass-card .card-title {
  font-size: var(--font-size-sm);
  font-weight: 600;
  color: var(--text-primary);
}

.chat-quick-actions .glass-card .card-desc {
  font-size: var(--font-size-xs);
  color: var(--text-tertiary);
  line-height: var(--line-height-normal);
}

/* ===== Messages Area ===== */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: var(--space-lg) var(--space-lg) var(--space-md);
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
  scroll-behavior: smooth;
}

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

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

.chat-messages::-webkit-scrollbar-thumb {
  background: var(--glass-border);
  border-radius: var(--radius-full);
}

.chat-messages::-webkit-scrollbar-thumb:hover {
  background: var(--glass-border-light);
}

/* ===== Message Rows ===== */
.chat-message {
  display: flex;
  flex-direction: row;
  gap: var(--space-sm);
  max-width: 85%;
  opacity: 1;
}

.chat-message.user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.chat-message.agent {
  align-self: flex-start;
}

/* ===== Avatar ===== */
.chat-message .avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--font-size-sm);
  font-weight: 700;
  overflow: hidden;
}

.chat-message.user .avatar {
  background: var(--accent-gradient);
  color: #fff;
}

.chat-message.agent .avatar {
  background: var(--glass-bg-active);
  border: 1px solid var(--glass-border);
  color: var(--accent-primary-light);
}

.chat-message.agent .avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* ===== Bubble ===== */
.chat-message .bubble {
  padding: var(--space-sm) var(--space-md);
  max-width: 100%;
  min-width: 0;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.chat-message.user .bubble {
  background: var(--accent-gradient);
  color: #fff;
  border-radius: var(--radius-lg) var(--radius-md) var(--radius-lg) var(--radius-lg);
  box-shadow: 0 4px 16px rgba(99, 102, 241, 0.25);
}

.chat-message.agent .bubble {
  background: var(--glass-bg);
  backdrop-filter: blur(var(--blur-sm));
  -webkit-backdrop-filter: blur(var(--blur-sm));
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-md) var(--radius-lg) var(--radius-lg) var(--radius-lg);
  color: var(--text-primary);
}

/* ===== Bubble Content ===== */
.chat-message .bubble .content {
  font-size: var(--font-size-base);
  line-height: var(--line-height-relaxed);
}

/* Prose styling for agent markdown */
.chat-message.agent .bubble .content p {
  margin: 0 0 var(--space-sm);
}

.chat-message.agent .bubble .content p:last-child {
  margin-bottom: 0;
}

.chat-message.agent .bubble .content ul,
.chat-message.agent .bubble .content ol {
  margin: var(--space-xs) 0 var(--space-sm);
  padding-left: var(--space-lg);
}

.chat-message.agent .bubble .content li {
  margin-bottom: var(--space-xs);
}

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

.chat-message.agent .bubble .content em {
  color: var(--text-secondary);
}

.chat-message.agent .bubble .content a {
  color: var(--accent-primary-light);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: border-color var(--transition-fast);
}

.chat-message.agent .bubble .content a:hover {
  border-bottom-color: var(--accent-primary-light);
}

.chat-message.agent .bubble .content h1,
.chat-message.agent .bubble .content h2,
.chat-message.agent .bubble .content h3,
.chat-message.agent .bubble .content h4 {
  margin: var(--space-md) 0 var(--space-sm);
  font-weight: 600;
  color: var(--text-primary);
}

.chat-message.agent .bubble .content h1:first-child,
.chat-message.agent .bubble .content h2:first-child,
.chat-message.agent .bubble .content h3:first-child {
  margin-top: 0;
}

.chat-message.agent .bubble .content blockquote {
  margin: var(--space-sm) 0;
  padding: var(--space-xs) var(--space-md);
  border-left: 3px solid var(--accent-primary);
  background: var(--glass-bg);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--text-secondary);
}

.chat-message.agent .bubble .content hr {
  border: none;
  height: 1px;
  background: var(--glass-border);
  margin: var(--space-md) 0;
}

/* Inline code */
.chat-message .bubble .content code:not(pre code) {
  font-family: var(--font-mono);
  font-size: 0.9em;
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  background: var(--glass-bg-active);
  border: 1px solid var(--glass-border);
  color: var(--accent-primary-light);
}

.chat-message.user .bubble .content code:not(pre code) {
  background: rgba(255, 255, 255, 0.15);
  border-color: rgba(255, 255, 255, 0.2);
  color: #fff;
}

/* Code blocks */
.chat-message .bubble .content pre {
  position: relative;
  margin: var(--space-sm) 0;
  padding: var(--space-md);
  background: var(--bg-secondary);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-md);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.chat-message .bubble .content pre code {
  font-family: var(--font-mono);
  font-size: var(--font-size-sm);
  line-height: var(--line-height-normal);
  color: var(--text-primary);
  background: none;
  border: none;
  padding: 0;
}

.chat-message .bubble .content pre::-webkit-scrollbar {
  height: 4px;
}

.chat-message .bubble .content pre::-webkit-scrollbar-track {
  background: transparent;
}

.chat-message .bubble .content pre::-webkit-scrollbar-thumb {
  background: var(--glass-border);
  border-radius: var(--radius-full);
}

/* ===== Collapsible Code Blocks ===== */
.code-collapse {
  margin: var(--space-sm) 0;
  border-radius: var(--radius-md);
  border: 1px solid var(--glass-border);
  background: var(--bg-secondary);
  overflow: hidden;
}

.code-collapse-header {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-xs) var(--space-md);
  cursor: pointer;
  user-select: none;
  list-style: none; /* remove default <details> marker */
  background: rgba(255, 255, 255, 0.02);
  border-bottom: 1px solid transparent;
  transition:
    background var(--transition-fast),
    border-color var(--transition-fast);
}

/* Remove default marker in WebKit/Blink */
.code-collapse-header::-webkit-details-marker {
  display: none;
}

.code-collapse-header::marker {
  display: none;
  content: '';
}

.code-collapse-header:hover {
  background: var(--glass-bg-hover);
}

.code-collapse[open] .code-collapse-header {
  border-bottom-color: var(--glass-border);
}

/* Language badge */
.code-collapse-lang {
  font-family: var(--font-mono);
  font-size: var(--font-size-xs);
  font-weight: 600;
  color: var(--accent-primary-light);
  background: rgba(99, 102, 241, 0.12);
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  text-transform: lowercase;
  letter-spacing: 0.02em;
}

/* Toggle label */
.code-collapse-toggle {
  font-size: var(--font-size-xs);
  color: var(--text-tertiary);
  flex: 1;
}

/* Copy button in header */
.code-collapse-copy {
  background: var(--glass-bg);
  backdrop-filter: blur(var(--blur-sm));
  -webkit-backdrop-filter: blur(var(--blur-sm));
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  padding: 2px 8px;
  font-size: var(--font-size-xs);
  color: var(--text-tertiary);
  cursor: pointer;
  transition:
    color var(--transition-fast),
    background var(--transition-fast),
    border-color var(--transition-fast);
}

.code-collapse-copy:hover {
  color: var(--text-primary);
  background: var(--glass-bg-hover);
  border-color: var(--glass-border-light);
}

.code-collapse-copy.copied {
  color: var(--success);
  border-color: rgba(74, 222, 128, 0.3);
}

/* Chevron icon */
.code-collapse-chevron {
  display: flex;
  align-items: center;
  color: var(--text-tertiary);
  transition: transform var(--transition-fast);
}

.code-collapse[open] .code-collapse-chevron {
  transform: rotate(180deg);
}

/* Code body (the pre block inside) */
.code-collapse-body {
  overflow: hidden;
}

.code-collapse-body pre {
  margin: 0 !important;
  border: none !important;
  border-radius: 0 !important;
}

/* Legacy copy button (hidden since we now use header copy) */
.code-copy-btn {
  position: absolute;
  top: var(--space-xs);
  right: var(--space-xs);
  background: var(--glass-bg);
  backdrop-filter: blur(var(--blur-sm));
  -webkit-backdrop-filter: blur(var(--blur-sm));
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  padding: 4px 8px;
  font-size: var(--font-size-xs);
  color: var(--text-tertiary);
  cursor: pointer;
  opacity: 0;
  transition:
    opacity var(--transition-fast),
    color var(--transition-fast),
    background var(--transition-fast);
  z-index: 1;
}

.chat-message .bubble .content pre:hover .code-copy-btn {
  opacity: 1;
}

.code-copy-btn:hover {
  color: var(--text-primary);
  background: var(--glass-bg-hover);
}

.code-copy-btn.copied {
  color: var(--success);
  border-color: rgba(74, 222, 128, 0.3);
}

/* ===== Timestamp ===== */
.chat-message .bubble .timestamp {
  font-size: var(--font-size-xs);
  color: var(--text-tertiary);
  text-align: right;
  margin-top: var(--space-xs);
  user-select: none;
}

.chat-message.user .bubble .timestamp {
  color: rgba(255, 255, 255, 0.6);
}

/* ===== Message Animation ===== */
.chat-message.animate-in {
  animation: slideInUp 300ms ease-out forwards;
}

/* ===== Streaming Shimmer Bar ===== */
.chat-streaming {
  height: 3px;
  margin: 0 var(--space-lg);
  border-radius: var(--radius-full);
  background: linear-gradient(
    90deg,
    var(--glass-bg) 0%,
    var(--accent-primary) 50%,
    var(--glass-bg) 100%
  );
  background-size: 200% 100%;
  animation: shimmer 1.5s ease-in-out infinite;
}

/* ===== Typing Indicator ===== */
.chat-typing-indicator {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: var(--space-sm) var(--space-md);
}

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

.chat-typing-indicator span:nth-child(1) { animation-delay: 0ms; }
.chat-typing-indicator span:nth-child(2) { animation-delay: 200ms; }
.chat-typing-indicator span:nth-child(3) { animation-delay: 400ms; }

/* ===== Input Area ===== */
.chat-input-area {
  display: flex;
  flex-direction: row;
  align-items: flex-end;
  gap: var(--space-sm);
  padding: var(--space-md) var(--space-lg);
  background: var(--glass-bg);
  backdrop-filter: blur(var(--blur-md));
  -webkit-backdrop-filter: blur(var(--blur-md));
  border-top: 1px solid var(--glass-border);
  flex-shrink: 0;
}

.chat-input-area textarea {
  flex: 1;
  min-height: 40px;
  max-height: 160px;
  resize: none;
  font-family: var(--font-family);
  font-size: var(--font-size-base);
  line-height: var(--line-height-normal);
  padding: var(--space-sm) var(--space-md);
  background: rgba(0, 0, 0, 0.3);
  backdrop-filter: blur(var(--blur-sm));
  -webkit-backdrop-filter: blur(var(--blur-sm));
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  outline: none;
  transition:
    border-color var(--transition-fast),
    box-shadow var(--transition-fast);
}

.chat-input-area textarea::placeholder {
  color: var(--text-tertiary);
}

.chat-input-area textarea:focus {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
}

/* Send button */
.chat-input-area .btn-send {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: var(--accent-gradient);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition:
    opacity var(--transition-fast),
    transform var(--transition-fast),
    box-shadow var(--transition-fast);
  box-shadow: 0 4px 16px rgba(99, 102, 241, 0.3);
}

.chat-input-area .btn-send:hover {
  box-shadow: 0 6px 20px rgba(99, 102, 241, 0.4);
  transform: scale(1.05);
}

.chat-input-area .btn-send:active {
  transform: scale(0.95);
}

.chat-input-area .btn-send:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  box-shadow: none;
  transform: none;
}

.chat-input-area .btn-send svg {
  width: 18px;
  height: 18px;
}

/* Stop button (replaces send during streaming) */
.chat-input-area .btn-stop {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: var(--error);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition:
    transform var(--transition-fast),
    box-shadow var(--transition-fast);
  box-shadow: 0 4px 16px rgba(248, 113, 113, 0.3);
  animation: pulse 2s ease-in-out infinite;
}

.chat-input-area .btn-stop:hover {
  box-shadow: 0 6px 20px rgba(248, 113, 113, 0.4);
  transform: scale(1.05);
}

.chat-input-area .btn-stop:active {
  transform: scale(0.95);
}

.chat-input-area .btn-stop svg {
  width: 16px;
  height: 16px;
}

/* Mic button */
.chat-input-area .btn-mic {
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: var(--radius-md);
  background: var(--glass-bg);
  backdrop-filter: blur(var(--blur-sm));
  -webkit-backdrop-filter: blur(var(--blur-sm));
  border: 1px solid var(--glass-border);
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition:
    background var(--transition-fast),
    color var(--transition-fast),
    border-color var(--transition-fast);
}

.chat-input-area .btn-mic:hover {
  background: var(--glass-bg-hover);
  color: var(--text-primary);
  border-color: var(--glass-border-light);
}

.chat-input-area .btn-mic svg {
  width: 18px;
  height: 18px;
}

/* Upload button */
.chat-input-area .btn-upload {
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: var(--radius-md);
  background: var(--glass-bg);
  backdrop-filter: blur(var(--blur-sm));
  -webkit-backdrop-filter: blur(var(--blur-sm));
  border: 1px solid var(--glass-border);
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition:
    background var(--transition-fast),
    color var(--transition-fast),
    border-color var(--transition-fast);
}

.chat-input-area .btn-upload:hover {
  background: var(--glass-bg-hover);
  color: var(--text-primary);
  border-color: var(--glass-border-light);
}

.chat-input-area .btn-upload svg {
  width: 18px;
  height: 18px;
}

/* Hidden file input for upload */
.chat-input-area .file-input-hidden {
  display: none;
}

/* ===== Light Theme Overrides ===== */
[data-theme="light"] .chat-input-area {
  background: var(--glass-bg);
}

[data-theme="light"] .chat-input-area textarea {
  background: rgba(255, 255, 255, 0.6);
}

[data-theme="light"] .chat-message.user .bubble {
  box-shadow: 0 4px 16px rgba(99, 102, 241, 0.15);
}

[data-theme="light"] .chat-message.agent .bubble {
  background: var(--glass-bg);
}

[data-theme="light"] .chat-message .bubble .content pre {
  background: var(--bg-surface);
}

[data-theme="light"] .code-collapse {
  background: var(--bg-surface);
}

[data-theme="light"] .code-collapse-header {
  background: rgba(0, 0, 0, 0.02);
}

[data-theme="light"] .code-collapse-header:hover {
  background: rgba(0, 0, 0, 0.04);
}

[data-theme="light"] .code-collapse-lang {
  background: rgba(99, 102, 241, 0.08);
}

[data-theme="light"] .code-collapse-copy {
  background: var(--glass-bg);
}

[data-theme="light"] .code-copy-btn {
  background: var(--glass-bg);
}

[data-theme="light"] .chat-message.user .bubble .content code:not(pre code) {
  background: rgba(255, 255, 255, 0.2);
  border-color: rgba(255, 255, 255, 0.25);
}

/* ===== Chat Header ===== */
.chat-header {
  display: flex;
  align-items: center;
  padding: var(--space-sm) var(--space-lg);
  flex-shrink: 0;
}

.chat-back-btn {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  padding: var(--space-xs) var(--space-sm);
  font-size: var(--font-size-sm);
  color: var(--text-secondary);
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.chat-back-btn:hover {
  background: var(--glass-bg-hover);
  color: var(--text-primary);
}

.chat-back-btn svg {
  width: 18px;
  height: 18px;
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .chat-messages {
    padding: var(--space-md) var(--space-sm) var(--space-sm);
  }

  .chat-message {
    max-width: 92%;
  }

  .chat-input-area {
    padding: var(--space-sm);
    gap: var(--space-xs);
  }

  .chat-welcome {
    padding: var(--space-lg) var(--space-md);
  }

  .chat-quick-actions {
    grid-template-columns: 1fr;
  }

  .chat-input-area .btn-mic,
  .chat-input-area .btn-upload {
    width: 36px;
    height: 36px;
  }

  .chat-input-area .btn-send,
  .chat-input-area .btn-stop {
    width: 36px;
    height: 36px;
  }
}

/* Connection banner */
.chat-connection-banner {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space-md);
  background: var(--warning-bg);
  color: var(--warning);
  font-size: var(--font-size-sm);
  border-radius: var(--radius-sm);
  margin: 0 var(--space-md);
  animation: fadeIn 300ms ease;
}
