/* ── AI Chat Panel ── */

:root {
  --border-strong: var(--outline-variant);
  --bg-sidebar: rgba(14, 14, 14, 0.75);
  --bg-header: transparent;
  --border: var(--border-ghost);
  --bg-input: var(--surface-container-lowest);
  --bg-card: var(--surface-container-low);
  --text-primary: var(--text-bright);
  --bg-card-hover: var(--surface-container-high);
}

/* Toggle button (FAB) */
.chat-toggle-btn {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 900;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: 1px solid var(--border-strong);
  background: var(--accent-blue);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 20px rgba(59, 130, 246, 0.3);
  transition: transform 0.2s, box-shadow 0.2s, background 0.2s;
}

.chat-toggle-btn:hover {
  background: var(--accent-blue-hover);
  transform: scale(1.05);
  box-shadow: 0 6px 24px rgba(59, 130, 246, 0.4);
}

.chat-toggle-btn svg {
  width: 22px;
  height: 22px;
}

/* Mascot canvas in toggle button */
#mascot-toggle-canvas {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  pointer-events: none;
  display: block;
}

/* Mascot welcome container */
.mascot-welcome-container {
  width: 180px;
  height: 180px;
  margin: 0 auto;
  border-radius: 16px;
  overflow: hidden;
  pointer-events: auto;
}

.mascot-welcome-container canvas {
  border-radius: 16px;
  display: block;
}

/* Inline welcome (in messages area when no messages) */
.chat-welcome-inline {
  padding: 24px 16px;
  border-bottom: none;
  flex: none;
}

/* Panel overlay (mobile backdrop) */
.chat-overlay {
  position: fixed;
  inset: 0;
  z-index: 999;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
}

.chat-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

/* Panel */
.chat-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 1000;
  width: 420px;
  max-width: 100vw;
  background: var(--bg-sidebar);
  border-left: 1px solid var(--border-strong);
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: -8px 0 40px rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
}

.chat-panel.open {
  transform: translateX(0);
}

/* Header */
.chat-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--bg-header);
}

.chat-header-title {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-bright);
}

.chat-header-title svg {
  width: 18px;
  height: 18px;
  color: var(--accent-blue);
}

.chat-header-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 6px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s, background 0.15s;
}

.chat-header-btn:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.06);
}

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

/* Quick actions */
.chat-quick-actions {
  display: flex;
  gap: 8px;
  padding: 10px 16px;
  overflow-x: auto;
  flex-shrink: 0;
  border-bottom: 1px solid var(--border);
  -ms-overflow-style: none;
  scrollbar-width: none;
}

.chat-quick-actions::-webkit-scrollbar {
  display: none;
}

.chat-chip {
  flex-shrink: 0;
  padding: 6px 12px;
  border-radius: 16px;
  border: 1px solid var(--border-strong);
  background: var(--bg-card);
  color: var(--text-secondary);
  font-size: 12px;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
  white-space: nowrap;
}

.chat-chip:hover {
  border-color: var(--accent-blue);
  color: var(--accent-blue);
  background: rgba(59, 130, 246, 0.08);
}

/* Messages area */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

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

.chat-messages::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 2px;
}

/* Message bubbles */
.chat-msg {
  max-width: 88%;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 13px;
  line-height: 1.55;
  word-break: break-word;
}

.chat-msg-user {
  align-self: flex-end;
  background: var(--accent-blue);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.chat-msg-assistant {
  align-self: flex-start;
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.chat-msg-assistant p { margin: 0 0 8px 0; }
.chat-msg-assistant p:last-child { margin-bottom: 0; }
.chat-msg-assistant strong { color: var(--text-bright); }
.chat-msg-assistant code {
  background: rgba(255, 255, 255, 0.06);
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 12px;
}
.chat-msg-assistant ul,
.chat-msg-assistant ol {
  margin: 4px 0 8px 18px;
  padding: 0;
}
.chat-msg-assistant li { margin-bottom: 2px; }

/* Tool execution indicator */
.chat-tool-indicator {
  align-self: flex-start;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: 8px;
  background: rgba(59, 130, 246, 0.08);
  border: 1px solid rgba(59, 130, 246, 0.15);
  color: var(--accent-blue);
  font-size: 12px;
}

.chat-tool-indicator .spinner {
  width: 14px;
  height: 14px;
  border: 2px solid rgba(59, 130, 246, 0.2);
  border-top-color: var(--accent-blue);
  border-radius: 50%;
  animation: chat-spin 0.8s linear infinite;
}

@keyframes chat-spin {
  to { transform: rotate(360deg); }
}

/* Typing cursor */
.chat-cursor {
  display: inline-block;
  width: 2px;
  height: 14px;
  background: var(--accent-blue);
  margin-left: 2px;
  vertical-align: text-bottom;
  animation: chat-blink 1s step-end infinite;
}

@keyframes chat-blink {
  50% { opacity: 0; }
}

/* Welcome / no-key state */
.chat-welcome {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px;
  text-align: center;
  gap: 12px;
}

.chat-welcome svg {
  width: 40px;
  height: 40px;
  color: var(--accent-blue);
  opacity: 0.6;
}

.chat-welcome h3 {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0;
}

.chat-welcome p {
  font-size: 13px;
  color: var(--text-secondary);
  margin: 0;
  max-width: 280px;
}

.chat-welcome-btn {
  margin-top: 8px;
  padding: 8px 20px;
  border-radius: var(--radius);
  border: 1px solid var(--accent-blue);
  background: transparent;
  color: var(--accent-blue);
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s;
}

.chat-welcome-btn:hover {
  background: rgba(59, 130, 246, 0.1);
}

/* Input area */
.chat-input-area {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--bg-header);
}

.chat-input-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.chat-input {
  flex: 1;
  resize: none;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--bg-input);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 13px;
  padding: 10px 12px;
  max-height: 120px;
  line-height: 1.4;
  outline: none;
  transition: border-color 0.15s;
}

.chat-input::placeholder { color: var(--text-muted); }
.chat-input:focus { border-color: var(--accent-blue); }
.chat-input:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.chat-send-btn {
  flex-shrink: 0;
  width: 38px;
  height: 38px;
  border-radius: var(--radius);
  border: none;
  background: var(--accent-blue);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, opacity 0.15s;
}

.chat-send-btn:hover { background: var(--accent-blue-hover); }
.chat-send-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

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

/* Settings panel (within chat) */
.chat-settings {
  flex: 1;
  overflow-y: auto;
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.chat-settings-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.chat-settings-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  font-weight: 600;
}

.chat-provider-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border-strong);
  background: var(--bg-card);
}

.chat-provider-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.chat-provider-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
}

.chat-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.chat-status-dot.configured { background: var(--accent-green); }
.chat-status-dot.missing { background: var(--accent-red); }

.chat-key-input {
  width: 100%;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--bg-input);
  color: var(--text-primary);
  font-family: monospace;
  font-size: 12px;
  outline: none;
  transition: border-color 0.15s;
}

.chat-key-input:focus { border-color: var(--accent-blue); }
.chat-key-input::placeholder { color: var(--text-muted); }

.chat-provider-actions {
  display: flex;
  gap: 8px;
}

.chat-btn-save,
.chat-btn-delete {
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  border: none;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: opacity 0.15s;
}

.chat-btn-save {
  background: var(--accent-blue);
  color: #fff;
}

.chat-btn-save:hover { opacity: 0.9; }

.chat-btn-delete {
  background: rgba(239, 68, 68, 0.15);
  color: var(--accent-red);
}

.chat-btn-delete:hover { opacity: 0.8; }

/* Provider selector */
.chat-provider-toggle {
  display: flex;
  border-radius: var(--radius);
  border: 1px solid var(--border-strong);
  overflow: hidden;
}

.chat-provider-toggle button {
  flex: 1;
  padding: 8px;
  border: none;
  background: var(--bg-card);
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.chat-provider-toggle button.active {
  background: var(--accent-blue);
  color: #fff;
}

.chat-provider-toggle button:not(.active):hover {
  background: var(--bg-card-hover);
  color: var(--text-primary);
}

/* Mobile full width */
@media (max-width: 640px) {
  .chat-panel {
    width: 100vw;
  }

  .chat-toggle-btn {
    bottom: 16px;
    right: 16px;
    width: 48px;
    height: 48px;
  }
}
