/* ==========================================================================
   Chat: messages, citations, suggested questions, composer, voice button
   ========================================================================== */

/* ---------- Sidebar chat list items ---------- */
.chat-list { display: flex; flex-direction: column; gap: 2px; }
.chat-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: var(--space-3);
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background var(--duration-fast) var(--ease-out);
  text-align: left;
  position: relative;
}
.chat-item:hover { background: var(--bg-surface-2); }
.chat-item.active {
  background: var(--color-primary-50);
  border-color: var(--color-primary-200);
  color: var(--color-primary-700);
}
[data-theme="dark"] .chat-item.active,
:root:not([data-theme="light"]) .chat-item.active {
  background: rgba(99, 102, 241, 0.16);
  border-color: rgba(99, 102, 241, 0.3);
  color: var(--color-primary-200);
}
.chat-item .title {
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: inherit;
}
.chat-item .meta {
  font-size: 11px;
  color: var(--fg-tertiary);
  display: flex; gap: var(--space-2); align-items: center;
}
.chat-item .author-badge {
  background: var(--bg-surface-3);
  padding: 1px 6px;
  border-radius: var(--radius-pill);
  font-size: 10px;
}

/* ---------- Suggested questions ---------- */
.suggested-questions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-bottom: var(--space-4);
}
.suggested-questions .chip {
  font-size: var(--fs-sm);
  padding: 8px var(--space-3);
}

/* ---------- Welcome screen (chat empty) ---------- */
.welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: var(--space-10) var(--space-5);
  gap: var(--space-4);
  flex: 1;
}
.welcome .greeting {
  font-size: var(--fs-3xl);
  font-weight: var(--fw-semibold);
  background: linear-gradient(135deg, var(--color-primary-500), var(--color-primary-700));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  letter-spacing: -0.02em;
}
.welcome .subtitle {
  color: var(--fg-secondary);
  font-size: var(--fs-base);
  max-width: 540px;
}

/* ---------- Message bubbles ---------- */
.msg {
  display: flex;
  gap: var(--space-3);
  animation: fade-up var(--duration-base) var(--ease-out);
}
.msg .avatar { width: 32px; height: 32px; font-size: 12px; }
.msg-content {
  flex: 1;
  min-width: 0;
}
.msg .author {
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
  color: var(--fg-secondary);
  margin-bottom: var(--space-1);
}
.msg .bubble {
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-lg);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  color: var(--fg-primary);
  line-height: var(--lh-loose);
  word-wrap: break-word;
}
.msg .bubble p:last-child { margin-bottom: 0; }
.msg .bubble pre {
  background: var(--bg-surface-2);
  padding: var(--space-3);
  border-radius: var(--radius-md);
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: var(--fs-sm);
}
.msg .bubble code {
  font-family: var(--font-mono);
  font-size: 0.9em;
  background: var(--bg-surface-2);
  padding: 2px 5px;
  border-radius: var(--radius-sm);
}
.msg .bubble pre code { padding: 0; background: transparent; }

.msg-user .bubble {
  background: linear-gradient(135deg, var(--color-primary-600), var(--color-primary-700));
  border-color: transparent;
  color: var(--fg-on-primary);
}
.msg-user .bubble code,
.msg-user .bubble pre {
  background: rgba(255, 255, 255, 0.15);
  color: inherit;
}

.msg-actions {
  display: flex;
  gap: var(--space-1);
  margin-top: var(--space-2);
  opacity: 0;
  transition: opacity var(--duration-fast) var(--ease-out);
}
.msg:hover .msg-actions { opacity: 1; }
.msg-actions .btn-icon { width: 28px; height: 28px; border-radius: var(--radius-sm); }
.msg-actions .btn-icon .icon { width: 14px; height: 14px; }
.msg-actions .reaction-active { color: var(--color-primary-600); }
.msg-actions .reaction-active.dislike { color: var(--color-danger-500); }

/* ---------- Source chips (sotto bubble AI) ---------- */
.msg-sources {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  margin-top: var(--space-3);
  padding-top: var(--space-3);
  border-top: 1px dashed var(--border-subtle);
}
.msg-sources-label {
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
  color: var(--fg-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.msg-source-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: 4px 10px 4px 8px;
  font-size: var(--fs-xs);
  background: var(--bg-surface-2);
  color: var(--fg-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  cursor: pointer;
  max-width: 220px;
  transition: all var(--duration-fast) var(--ease-out);
}
.msg-source-chip:hover {
  background: var(--color-primary-50);
  color: var(--color-primary-700);
  border-color: var(--color-primary-200);
  transform: translateY(-1px);
}
[data-theme="dark"] .msg-source-chip:hover,
:root:not([data-theme="light"]) .msg-source-chip:hover {
  background: rgba(99, 102, 241, 0.18);
  color: var(--color-primary-200);
  border-color: rgba(99, 102, 241, 0.35);
}
.msg-source-chip i { font-size: 13px; opacity: 0.7; }
.msg-source-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  font-size: 10px;
  font-weight: var(--fw-semibold);
  background: var(--color-primary-600);
  color: #fff;
  border-radius: var(--radius-sm);
}
.msg-source-title {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 160px;
}

/* ---------- Citation marker (inline) ---------- */
.citation {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  margin: 0 2px;
  font-size: 11px;
  font-weight: var(--fw-semibold);
  background: var(--color-primary-100);
  color: var(--color-primary-700);
  border-radius: var(--radius-sm);
  cursor: pointer;
  vertical-align: middle;
  transition: all var(--duration-fast) var(--ease-out);
  text-decoration: none;
}
.citation:hover {
  background: var(--color-primary-600);
  color: #fff;
  transform: translateY(-1px);
}
[data-theme="dark"] .citation,
:root:not([data-theme="light"]) .citation {
  background: rgba(99, 102, 241, 0.2);
  color: var(--color-primary-200);
}

/* ---------- Composer ---------- */
.composer-row {
  display: flex;
  align-items: flex-end;
  gap: var(--space-2);
  background: var(--bg-app);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-xl);
  padding: var(--space-2) var(--space-3);
  transition:
    border-color var(--duration-fast) var(--ease-out),
    box-shadow var(--duration-fast) var(--ease-out);
}
.composer-row:focus-within {
  border-color: var(--color-primary-500);
  box-shadow: var(--shadow-ring);
}
.composer-input {
  flex: 1;
  border: 0;
  background: transparent;
  resize: none;
  font: inherit;
  font-size: var(--fs-base);
  color: var(--fg-primary);
  min-height: 28px;
  max-height: 200px;
  padding: var(--space-2) var(--space-1);
  line-height: var(--lh-normal);
}
.composer-input:focus { outline: none; }
.composer-input::placeholder { color: var(--fg-tertiary); }

.composer-tools {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-shrink: 0;
}

/* Mic button — pill ghost, pulse rosso quando ascolta */
.mic-btn {
  width: 38px; height: 38px;
  border: 0;
  border-radius: var(--radius-pill);
  color: var(--fg-secondary);
  background: transparent;
  font-size: 18px;
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: all var(--duration-fast) var(--ease-out);
}
.mic-btn:hover {
  background: var(--bg-surface-2);
  color: var(--fg-primary);
}
.mic-btn.listening {
  background: var(--color-danger-500);
  color: #fff;
  animation: pulse-ring 1.4s ease-out infinite;
}
.mic-btn.transcribing {
  opacity: 0.6;
  pointer-events: none;
  background: var(--bg-surface-2);
}

/* Send button — primary filled, modern arrow up */
.send-btn {
  width: 40px; height: 40px;
  background: var(--color-primary-600);
  color: #fff;
  border-radius: var(--radius-pill);
  border: 0;
  cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 20px;
  transition:
    transform var(--duration-fast) var(--ease-out),
    background var(--duration-fast) var(--ease-out),
    box-shadow var(--duration-fast) var(--ease-out),
    opacity var(--duration-fast) var(--ease-out);
  box-shadow: 0 4px 10px -2px rgba(99, 102, 241, 0.4);
}
.send-btn:hover {
  background: var(--color-primary-700);
  transform: translateY(-1px);
  box-shadow: 0 6px 14px -2px rgba(99, 102, 241, 0.5);
}
.send-btn:active { transform: translateY(0); }
.send-btn:disabled {
  background: var(--bg-surface-3);
  color: var(--fg-tertiary);
  box-shadow: none;
  cursor: not-allowed;
  transform: none;
  opacity: 0.7;
}

.composer-hint {
  margin-top: var(--space-2);
  font-size: var(--fs-xs);
  color: var(--fg-tertiary);
  text-align: center;
}

/* ---------- Toolbar (sopra al composer) ---------- */
.composer-toolbar {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding-bottom: var(--space-2);
}
.composer-toolbar .chip { background: transparent; border-color: var(--border-subtle); }
