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

/* Chat bubble button */
.qp-chat-fab {
  position: fixed;
  bottom: 28px;
  right: 24px;
  width: 52px;
  height: 52px;
  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;
  font-family: 'DM Sans', sans-serif;
}

.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: 700;
  font-size: 16px;
  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: 380px;
  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: 380px;
  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: 14px 16px;
  border-bottom: 1px solid var(--outline-muted);
  flex-shrink: 0;
}

.qp-chat-header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

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

.qp-chat-title {
  font-weight: 600;
  font-size: 15px;
  color: var(--content-primary);
}

.qp-chat-close {
  width: 32px;
  height: 32px;
  border: none;
  background: none;
  cursor: pointer;
  font-size: 20px;
  color: var(--content-tertiary);
  border-radius: 8px;
  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: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  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: 3px; }

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

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

.qp-chat-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin-top: 8px;
}

.qp-chat-suggestion {
  padding: 6px 14px;
  border: 1px solid var(--outline-default);
  border-radius: 100px;
  background: var(--surface-base);
  color: var(--content-primary);
  font-size: 13px;
  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);
}

/* Message bubbles */
.qp-chat-bubble {
  display: flex;
  gap: 8px;
  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: 28px;
  height: 28px;
  min-width: 28px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--on-accent-primary1, #000);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 10px;
  letter-spacing: -0.3px;
  flex-shrink: 0;
  margin-top: 2px;
}

.qp-chat-msg-content {
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 14px;
  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-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: 8px;
  padding: 4px 12px;
  border: 1px solid var(--outline-default);
  border-radius: 100px;
  background: var(--surface-base);
  color: var(--accent-text);
  font-size: 12px;
  font-weight: 500;
  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: 14px 18px;
}

.qp-chat-dots {
  display: flex;
  gap: 5px;
  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: 8px;
  padding: 12px 16px;
  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: 100px;
  padding: 10px 16px;
  font-size: 14px;
  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);
  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: 36px;
  height: 36px;
  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);
}

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

@media (max-width: 768px) {
  .qp-chat-fab {
    bottom: 88px;
    right: 16px;
    width: 48px;
    height: 48px;
  }

  .qp-chat-fab-text {
    font-size: 14px;
  }

  .qp-chat-panel {
    top: 0;
    right: 0;
    left: 0;
    width: 100%;
    height: 100vh;
    height: 100dvh;
    border-left: none;
    border-radius: 0;
    transform: translateY(100%);
  }

  .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 — API key field ─────────────────────────────────────────────── */

.settings-password-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.settings-ai-key-input {
  width: 100%;
  padding-right: 40px;
}

.settings-password-toggle {
  position: absolute;
  right: 8px;
  width: 28px;
  height: 28px;
  border: none;
  background: none;
  cursor: pointer;
  color: var(--content-tertiary);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
}

.settings-password-toggle:hover {
  color: var(--content-primary);
}
