/* st-chat.css — Chat tokens, drawer chat, messages, bubbles, actions, typing indicator, chat input, shortcuts */
/* ===== Chat color tokens (matching editor sidebar chat) ===== */
:root {
  --chat-ai-bg: rgba(0, 0, 0, 0.03);
  --chat-ai-text: var(--color-text-primary);
  --chat-user-bg: var(--color-primary-hover, #5a5de0);
  --chat-user-text: #ffffff;
  --chat-input-bg: var(--color-card);
  --chat-input-border: var(--color-border);
  --chat-mic-active: var(--color-error, #ef4444);
}

[data-theme="dark"] {
  --chat-ai-bg: rgba(255, 255, 255, 0.04);
  --chat-ai-text: var(--color-text-primary);
  --chat-user-bg: var(--color-primary);
  --chat-user-text: #ffffff;
  --chat-input-bg: var(--color-bg);
  --chat-input-border: rgba(255, 255, 255, 0.08);
}

/* prefers-color-scheme removed — use [data-theme="dark"] only (matches site convention) */

/* ===== Drawer — full-height panel (matches editor panel) ===== */
.st-drawer-backdrop {
  position: fixed;
  inset: 0;
  background: var(--st-overlay-light);
  z-index: 40;
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--transition), visibility var(--transition);
}

.st-drawer-backdrop.open {
  opacity: 1;
  visibility: visible;
}

.st-drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 360px;
  background: var(--color-card);
  border-left: 0.5px solid var(--color-border);
  border-radius: 0;
  box-shadow: -4px 0 12px rgba(0, 0, 0, 0.1);
  z-index: 50;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 180ms ease;
  overflow: hidden;
}

.st-drawer.open {
  transform: translateX(0);
}

.st-drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 56px;
  min-height: 56px;
  padding: 0 var(--space-5);
  border-bottom: 0.5px solid var(--color-border);
  background: var(--color-card);
}

.st-drawer-title {
  font-size: var(--font-size-base);
  font-weight: 700;
  color: var(--color-text-primary);
}

.st-drawer-tabs {
  display: flex;
  align-items: center;
  gap: var(--space-1);
}

.st-drawer-tab {
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  font-size: var(--font-size-sm);
  font-weight: 500;
  color: var(--color-text-secondary);
  transition: background var(--transition), color var(--transition);
}

.st-drawer-tab:hover {
  background: var(--color-bg);
  color: var(--color-text-primary);
}

.st-drawer-tab.active {
  background: rgba(0, 0, 0, 0.08);
  color: var(--color-text-primary);
}

/* Header actions row */
.st-drawer-header-actions {
  display: flex;
  align-items: center;
  gap: 2px;
}

/* Reset / new conversation button */
.st-chat-new-conversation {
  display: none;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: none;
  background: transparent;
  border-radius: 6px;
  cursor: pointer;
  color: var(--color-text-tertiary);
  transition: all 180ms ease;
  padding: 0;
}

.st-chat-new-conversation svg {
  padding-left: 1px;
}

.st-chat-new-conversation:hover {
  background: rgba(0, 0, 0, 0.04);
  color: var(--color-text-secondary);
}

.st-drawer-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
  color: var(--color-text-secondary);
  transition: background var(--transition), color var(--transition);
}

.st-drawer-close:hover {
  background: var(--color-bg);
  color: var(--color-text-primary);
}

.st-drawer-content {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.st-drawer-panel {
  padding: var(--space-4);
}

/* ===== Dark Mode ===== */
/* prefers-color-scheme block removed — [data-theme="dark"] block below is the single source of truth */

[data-theme="dark"] {
  .st-source-panel {
    background: var(--color-card);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
  }

  .st-target-panel {
    background: var(--color-bg);
    box-shadow: none;
    border-color: rgba(255, 255, 255, 0.08);
  }

  .st-toolbar-btn:hover:not(:disabled) {
    background: var(--st-hover-dark);
  }

  .st-toolbar-btn:active:not(:disabled) {
    background: var(--st-hover-dark-active);
  }

  .st-lang-selector:hover,
  .st-lang-selector.open {
    background: var(--st-hover-dark);
  }

  .st-swap-btn:hover:not(:disabled) {
    background: var(--st-hover-dark);
  }

  .st-overflow-btn:hover {
    background: var(--st-hover-dark);
  }

  .st-tone-segment {
    background: var(--st-hover-dark);
  }

  .st-tone-segment .st-tone-preset-btn.active {
    background: var(--color-text-primary);
    color: #fff;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
  }

  .st-nav-btn:hover:not(:disabled) {
    background: var(--st-hover-dark);
  }

  .st-dropdown-item:hover,
  .st-lang-option:hover {
    background: var(--st-hover-dark);
  }

  .st-status-icon-btn:hover {
    background: var(--st-hover-dark);
  }

  .st-drawer-tab:hover {
    background: var(--st-hover-dark);
  }

  .st-drawer-close:hover {
    background: var(--st-hover-dark);
  }

  .st-drawer-backdrop {
    background: var(--st-overlay-dark);
  }
}


/* ===== WU-5: Chat Messages ===== */
.st-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: #f8f8f6;
  scrollbar-width: thin;
  scrollbar-color: rgba(0, 0, 0, 0.04) transparent;
}

/* Welcome state (matches editor AI tab) */
.st-chat-welcome {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 20px;
  flex: 1;
  justify-content: center;
  animation: st-fadeInUp 0.3s ease;
}

/* Welcome state centers itself via flex:1 + justify-content on its own container */

.st-welcome-header {
  text-align: center;
  padding: 12px 0 4px;
}

.st-welcome-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--color-text-primary);
  margin: 0 0 4px;
}

.st-welcome-desc {
  font-size: 12.5px;
  color: var(--color-text-tertiary);
  margin: 0;
  font-weight: 400;
}

.st-chat-shortcuts {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 100%;
}

.st-shortcut-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  background: #ffffff;
  border: 0.5px solid rgba(0, 0, 0, 0.06);
  cursor: pointer;
  transition: all 180ms ease;
  border-radius: 10px;
  min-width: 0;
  text-align: left;
}

.st-shortcut-card:hover {
  background: rgba(0, 0, 0, 0.02);
  border-color: rgba(0, 0, 0, 0.1);
}

.st-shortcut-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  flex-shrink: 0;
  color: var(--color-text-tertiary);
}

.st-shortcut-card:hover .st-shortcut-icon svg {
  color: var(--color-text-secondary);
}

.st-shortcut-label {
  flex: 1;
  min-width: 0;
  font-size: 13px;
  font-weight: 500;
  color: var(--color-text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.st-shortcut-send {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  color: rgba(0, 0, 0, 0.15);
  border-radius: 6px;
  transition: all 180ms ease;
}

.st-shortcut-card:hover .st-shortcut-send svg {
  color: var(--color-text-tertiary);
}

/* ===== MESSAGE BUBBLES (matches grammar bot chatView.css) ===== */
.message-bubble {
  max-width: 88%;
  min-width: 140px;
  padding: 12px 16px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.6;
  animation: st-fadeInUp 0.25s ease;
  word-wrap: break-word;
}

.message-bubble.user {
  align-self: flex-end;
  background: var(--color-primary, #696cff);
  color: #ffffff;
  border-bottom-right-radius: 4px;
}

.message-bubble.ai {
  align-self: flex-start;
  background: var(--color-card, #ffffff);
  color: var(--color-text-primary);
  border-bottom-left-radius: 4px;
  border: 0.5px solid rgba(0, 0, 0, 0.06);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

.message-bubble.ai p { margin: 0; }
.message-bubble.ai p + p { margin-top: 6px; }
.message-bubble.ai p:empty { display: none; }
.message-bubble.ai ul { margin: 4px 0; padding-left: 18px; list-style-type: disc; }
.message-bubble.ai ol { margin: 4px 0; padding-left: 18px; list-style-type: decimal; }
.message-bubble.ai li { margin-bottom: 2px; }
.message-bubble.ai strong { font-weight: 600; }
.message-bubble.ai em { color: var(--color-text-secondary); }

@keyframes st-fadeInUp {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ===== MESSAGE ACTIONS (icon-only, matches grammar bot) ===== */
.message-actions {
  display: flex;
  align-items: center;
  gap: 2px;
  margin-top: 4px;
  align-self: flex-start;
  animation: st-fadeInUp 0.25s ease;
}

.message-actions .action-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: none;
  background: transparent;
  border-radius: 6px;
  color: var(--color-text-tertiary);
  cursor: pointer;
  transition: all 180ms ease;
}

.message-actions .action-icon:hover {
  background: rgba(0, 0, 0, 0.04);
  color: var(--color-text-secondary);
}

.message-actions .action-icon svg {
  width: 15px;
  height: 15px;
  flex-shrink: 0;
}

.message-actions .action-icon.copied {
  color: var(--color-success, #16a34a);
}

.message-actions .action-icon.read-btn.playing {
  background: rgba(0, 0, 0, 0.08);
  color: var(--color-text-primary);
}

.message-actions .action-icon.read-btn.playing:hover {
  background: rgba(0, 0, 0, 0.12);
}

/* Typing indicator (matches grammar bot) */
.st-typing {
  align-self: flex-start;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 12px 16px;
  background: rgba(0, 0, 0, 0.04);
  border-radius: 14px;
  border-bottom-left-radius: 4px;
  animation: st-fadeInUp 0.25s ease;
}

.st-dot {
  width: 6px;
  height: 6px;
  background: var(--color-text-tertiary);
  border-radius: 50%;
  animation: st-typingBounce 1.4s ease-in-out infinite;
}

.st-dot:nth-child(2) { animation-delay: 0.2s; }
.st-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes st-typingBounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-4px); opacity: 1; }
}

/* Chat input area (matches editor) */
.st-chat-input-area {
  border-top: 0.5px solid rgba(0, 0, 0, 0.06);
  background: #f8f8f6;
  flex-shrink: 0;
  padding: 12px 16px;
}

.st-chat-input-wrapper {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 8px 8px 16px;
  background: #ffffff;
  border: 0.5px solid rgba(0, 0, 0, 0.08);
  border-radius: 22px;
  transition: border-color 180ms ease;
}

.st-chat-input-wrapper:focus-within {
  border-color: var(--color-text-tertiary);
  box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.03);
}

.st-chat-input {
  flex: 1;
  display: block;
  border: none;
  background: transparent;
  font-size: 13px;
  color: var(--color-text-primary);
  outline: none;
  resize: none;
  overflow-y: hidden;
  line-height: 1.6;
  font-family: var(--font-family);
  padding: 4px 0;
  margin: 0;
  min-height: 1.5em;
  max-height: 120px;
}

.st-chat-input::placeholder {
  color: var(--color-text-tertiary);
}

.st-chat-mic-btn,
.st-chat-send-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  transition: all 180ms ease;
  flex-shrink: 0;
}

.st-chat-mic-btn {
  background: transparent;
  color: var(--color-text-tertiary);
}

.st-chat-mic-btn:hover {
  background: rgba(0, 0, 0, 0.04);
  color: var(--color-text-secondary);
}

.st-chat-send-btn {
  background: var(--color-primary);
  color: #ffffff;
}

.st-chat-send-btn:hover:not(:disabled) {
  background: var(--color-primary-hover);
}

.st-chat-send-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.st-chat-mic-btn.recording svg {
  color: #28a745;
  animation: st-pulse-chat-mic 1s infinite;
}

@keyframes st-pulse-chat-mic {
  0% { filter: drop-shadow(0 0 5px #28a745); }
  50% { filter: drop-shadow(0 0 15px #28a745); }
  100% { filter: drop-shadow(0 0 5px #28a745); }
}

/* ===== Dark Mode — Chat Elements ===== */
[data-theme="dark"] .st-welcome-title {
  color: var(--color-text-primary);
}

[data-theme="dark"] .st-welcome-desc {
  color: var(--color-text-secondary);
}

[data-theme="dark"] .st-shortcut-card {
  background: rgba(255, 255, 255, 0.04);
  border-color: rgba(255, 255, 255, 0.06);
}

[data-theme="dark"] .st-shortcut-card:hover {
  background: rgba(255, 255, 255, 0.07);
  border-color: rgba(255, 255, 255, 0.1);
}

[data-theme="dark"] .st-shortcut-icon {
  color: var(--color-text-secondary);
}

[data-theme="dark"] .st-shortcut-card:hover .st-shortcut-icon svg {
  color: var(--color-text-primary);
}

[data-theme="dark"] .st-shortcut-label {
  color: var(--color-text-primary);
}

[data-theme="dark"] .st-shortcut-send {
  color: rgba(255, 255, 255, 0.1);
}

[data-theme="dark"] .st-shortcut-card:hover .st-shortcut-send svg {
  color: var(--color-text-secondary);
}

[data-theme="dark"] .st-chat-input-area {
  background: var(--color-bg);
  border-top-color: rgba(255, 255, 255, 0.06);
}

[data-theme="dark"] .st-chat-input-wrapper {
  background: rgba(255, 255, 255, 0.04);
  border-color: rgba(255, 255, 255, 0.08);
}

[data-theme="dark"] .st-chat-input-wrapper:focus-within {
  border-color: rgba(255, 255, 255, 0.2);
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.03);
}

[data-theme="dark"] .st-chat-input {
  color: var(--color-text-primary);
}

[data-theme="dark"] .st-chat-input::placeholder {
  color: var(--color-text-tertiary);
}

[data-theme="dark"] .st-chat-mic-btn {
  color: var(--color-text-tertiary);
}

[data-theme="dark"] .st-chat-mic-btn:hover {
  background: rgba(255, 255, 255, 0.06);
  color: var(--color-text-secondary);
}

[data-theme="dark"] .st-typing {
  background: rgba(255, 255, 255, 0.06);
}

[data-theme="dark"] .st-dot {
  background: var(--color-text-tertiary);
}

[data-theme="dark"] .message-actions .action-icon {
  color: var(--color-text-tertiary);
}

[data-theme="dark"] .message-actions .action-icon:hover {
  background: rgba(255, 255, 255, 0.06);
  color: var(--color-text-secondary);
}

[data-theme="dark"] .message-bubble.ai {
  border-color: rgba(255, 255, 255, 0.06);
  box-shadow: none;
}

[data-theme="dark"] .message-bubble.ai em {
  color: var(--color-text-secondary);
}

[data-theme="dark"] .st-chat-new-conversation {
  color: var(--color-text-tertiary);
}

[data-theme="dark"] .st-chat-new-conversation:hover {
  background: rgba(255, 255, 255, 0.06);
  color: var(--color-text-secondary);
}
