/* ─── QP Chat — AI Assistant UI ─────────────────────────────────────────────── */

/* Chat bubble button */
.qp-chat-fab {
  position: fixed;
  bottom: 100px;
  right: 24px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--on-accent-primary1, #000);
  border: none;
  cursor: pointer;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.18);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.qp-chat-fab:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.24);
}

.qp-chat-fab:active {
  transform: scale(0.95);
}

.qp-chat-fab.open {
  transform: scale(0);
  pointer-events: none;
}

.qp-chat-fab-text {
  font-weight: var(--weight-bold);
  font-size: var(--text-md);
  letter-spacing: -0.5px;
}

.qp-chat-fab-dot {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 12px;
  height: 12px;
  background: #ff4444;
  border-radius: 50%;
  border: 2px solid var(--surface-canvas);
  animation: qp-dot-pulse 2s ease-in-out infinite;
}

.qp-chat-fab-dot.hidden { display: none; }

@keyframes qp-dot-pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.2); opacity: 0.7; }
}

/* ─── Chat panel — desktop: docked right column ───────────────────────────── */

.qp-chat-panel {
  position: fixed;
  top: 0;
  right: 0;
  width: 456px;
  height: 100vh;
  height: 100dvh;
  background: var(--surface-header);
  backdrop-filter: blur(var(--blur)) saturate(1.4);
  -webkit-backdrop-filter: blur(var(--blur)) saturate(1.4);
  border-left: 1px solid var(--outline-default);
  box-shadow: var(--shadow-glass), -4px 0 24px rgba(0, 0, 0, 0.06);
  z-index: 300;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: translateX(100%);
  pointer-events: none;
  transition: transform 0.3s ease;
}

.qp-chat-panel.open {
  transform: translateX(0);
  pointer-events: auto;
}

/* Push main content left when chat is open on desktop */
main.qp-chat-open {
  margin-right: 456px;
  transition: margin-right 0.3s ease;
}

main {
  transition: margin-right 0.3s ease;
}

/* Header */
.qp-chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-16) var(--space-20);
  border-bottom: 1px solid var(--outline-muted);
  flex-shrink: 0;
}

.qp-chat-header-left {
  display: flex;
  align-items: center;
  gap: var(--space-12);
}

.qp-chat-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--on-accent-primary1, #000);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: var(--weight-bold);
  font-size: var(--text-base);
  flex-shrink: 0;
  letter-spacing: -0.3px;
}

.qp-chat-title {
  font-weight: var(--weight-semibold);
  font-size: var(--text-lg);
  color: var(--content-primary);
}

.qp-chat-close {
  width: 44px;
  height: 44px;
  border: none;
  background: none;
  cursor: pointer;
  font-size: var(--text-2xl);
  font-weight: var(--weight-bold);
  color: var(--content-primary);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}

.qp-chat-close:hover {
  background: var(--surface-highlight);
}

/* Messages area */
.qp-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-20);
  display: flex;
  flex-direction: column;
  gap: var(--space-14);
  min-height: 0;
}

/* Scrollbar */
.qp-chat-messages::-webkit-scrollbar { width: 6px; }
.qp-chat-messages::-webkit-scrollbar-track { background: transparent; }
.qp-chat-messages::-webkit-scrollbar-thumb { background: var(--outline-muted); border-radius: var(--radius-sm); }

/* Empty state */
.qp-chat-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: var(--space-14);
  padding: 38px var(--space-20);
  color: var(--content-secondary);
  font-size: var(--text-md);
  line-height: 1.5;
}

.qp-chat-empty-avatar {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--on-accent-primary1, #000);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: var(--weight-bold);
  font-size: var(--text-xl);
  letter-spacing: -0.5px;
}

.qp-chat-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-8);
  justify-content: center;
  margin-top: var(--space-8);
}

.qp-chat-suggestion {
  padding: var(--space-8) var(--space-16);
  border: 1px solid var(--outline-default);
  border-radius: var(--radius-full);
  background: var(--surface-base);
  color: var(--content-primary);
  font-size: var(--text-md);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  font-family: inherit;
  box-shadow: var(--shadow-glass);
}

.qp-chat-suggestion:hover {
  background: var(--surface-raised);
  border-color: var(--accent-text);
}

/* Message bubbles */
.qp-chat-bubble {
  display: flex;
  gap: var(--space-8);
  max-width: 92%;
  animation: qp-bubble-in 0.2s ease;
}

@keyframes qp-bubble-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.qp-chat-bubble-assistant {
  align-self: flex-start;
}

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

.qp-chat-msg-avatar {
  width: 34px;
  height: 34px;
  min-width: 34px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--on-accent-primary1, #000);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: var(--weight-bold);
  font-size: var(--text-sm);
  letter-spacing: -0.3px;
  flex-shrink: 0;
  margin-top: var(--space-2);
}

.qp-chat-msg-content {
  padding: var(--space-12) var(--space-16);
  border-radius: var(--radius-xl);
  font-size: var(--text-md);
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  min-width: 0;
}

.qp-chat-bubble-assistant .qp-chat-msg-content {
  background: var(--surface-raised);
  color: var(--content-primary);
  border-bottom-left-radius: 4px;
  box-shadow: var(--shadow-glass);
}

.qp-chat-bubble-assistant .qp-chat-msg-content a {
  color: var(--accent-text);
  text-decoration: underline;
  cursor: pointer;
}

.qp-chat-bubble-user .qp-chat-msg-content {
  background: var(--accent);
  color: var(--on-accent-primary1, #000);
  border-bottom-right-radius: 4px;
}

/* Undo chip */
.qp-chat-undo {
  display: inline-block;
  margin-top: var(--space-10);
  padding: var(--space-6) var(--space-14);
  border: 1px solid var(--outline-default);
  border-radius: var(--radius-full);
  background: var(--surface-base);
  color: var(--accent-text);
  font-size: var(--text-base);
  font-weight: var(--weight-medium);
  cursor: pointer;
  transition: background 0.15s;
  font-family: inherit;
}

.qp-chat-undo:hover {
  background: var(--surface-raised);
}

.qp-chat-undo-done {
  color: var(--content-tertiary);
  cursor: default;
  border-color: transparent;
  background: none;
}

/* Thinking animation */
.qp-chat-thinking .qp-chat-msg-content {
  padding: var(--space-14) var(--space-18);
  display: flex;
  align-items: center;
  gap: var(--space-10);
}

.qp-chat-thinking-text {
  font-size: var(--text-base);
  color: var(--text-secondary);
  font-style: italic;
  white-space: nowrap;
}

.qp-chat-thinking {
  position: relative;
}

.qp-chat-stop {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: none;
  background: var(--surface-secondary);
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: background 0.15s, color 0.15s;
}

.qp-chat-stop:hover {
  background: var(--status-blocked-bg);
  color: var(--status-blocked-text);
}

.qp-chat-dots {
  display: flex;
  gap: var(--space-4);
  align-items: center;
}

.qp-chat-dots span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--content-tertiary);
  animation: qp-dot-bounce 1.4s ease-in-out infinite;
}

.qp-chat-dots span:nth-child(2) { animation-delay: 0.16s; }
.qp-chat-dots span:nth-child(3) { animation-delay: 0.32s; }

@keyframes qp-dot-bounce {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}

/* Input bar */
.qp-chat-input-bar {
  display: flex;
  align-items: center;
  gap: var(--space-10);
  padding: var(--space-14) var(--space-20);
  border-top: 1px solid var(--outline-muted);
  flex-shrink: 0;
}

.qp-chat-input {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--outline-muted);
  border-radius: var(--radius-full);
  padding: var(--space-12) var(--space-18);
  font-size: var(--text-md);
  font-family: inherit;
  background: var(--surface-base);
  color: var(--content-primary);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  box-shadow: var(--shadow-glass);
}

.qp-chat-input:focus {
  border-color: var(--accent-text);
  box-shadow: var(--shadow-glass), 0 0 0 2px rgba(0, 227, 255, 0.2);
}

.qp-chat-input::placeholder {
  color: var(--content-secondary);
}

.qp-chat-mic,
.qp-chat-send {
  width: 42px;
  height: 42px;
  border: none;
  background: none;
  cursor: pointer;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--content-secondary);
  transition: background 0.15s, color 0.15s;
  flex-shrink: 0;
}

.qp-chat-mic:hover,
.qp-chat-send:hover {
  background: var(--surface-highlight);
  color: var(--content-primary);
}

.qp-chat-mic-active {
  color: #ff4444 !important;
  animation: qp-mic-pulse 1s ease-in-out infinite;
}

@keyframes qp-mic-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.15); }
}

.qp-chat-send:hover {
  color: var(--accent-text);
}

/* ─── Mobile — full-screen sheet ──────────────────────────────────────────── */

@media (max-width: 768px) {
  .qp-chat-fab {
    bottom: 100px;
    right: 24px;
  }

  .qp-chat-fab-text {
    font-size: var(--text-base);
  }

  .qp-chat-panel {
    top: 0;
    right: 0;
    left: 0;
    width: 100%;
    height: 100vh;
    height: 100dvh;
    border-left: none;
    border-radius: 0;
    transform: translateY(100%);
    z-index: 1100; /* Above mobile nav (z-index: 1000) */
  }

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

  /* Don't push main on mobile — panel is full-screen overlay */
  main.qp-chat-open {
    margin-right: 0;
  }
}

/* Hide FAB when settings/trash open */
body:has(#settings-view:not(.hidden)) .qp-chat-fab,
body:has(#trash-view:not(.hidden)) .qp-chat-fab {
  display: none;
}

/* ─── Settings — Provider & API key ───────────────────────────────────────── */

.settings-ai-advanced-summary {
  cursor: pointer;
  font-size: var(--text-base);
  font-weight: var(--weight-semibold);
  color: var(--content-secondary);
  padding: var(--space-8) 0;
  user-select: none;
}
.settings-ai-advanced-summary:hover { color: var(--content-primary); }
#settings-ai-advanced { margin-top: var(--space-8); }

.settings-ai-provider-group {
  display: flex;
  gap: var(--space-16);
  margin-top: var(--space-4);
}

.settings-ai-provider-option {
  display: flex;
  align-items: center;
  gap: var(--space-6);
  cursor: pointer;
  font-size: var(--text-base);
  color: var(--content-primary);
}

.settings-ai-provider-option input[type="radio"] {
  accent-color: var(--accent-text);
  margin: 0;
  width: 16px;
  height: 16px;
}

.settings-ai-status {
  font-size: var(--text-sm);
  margin-top: var(--space-6);
  min-height: 1.2em;
}

.settings-ai-status-ok {
  color: #15803d;
}

[data-theme="dark"] .settings-ai-status-ok {
  color: #4ade80;
}

.settings-ai-status-err {
  color: #b91c1c;
}

[data-theme="dark"] .settings-ai-status-err {
  color: #f87171;
}

.settings-ai-status-info {
  color: var(--content-secondary);
}

.settings-ai-optional {
  font-size: var(--text-sm);
  color: var(--content-tertiary);
  font-weight: var(--weight-normal);
}

