.chat {
  display: flex;
  flex-direction: column;
  gap: 12px;
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

/* --- Drag & drop overlay --- */
.chat-drop-overlay {
  display: none;
  position: absolute;
  inset: 0;
  z-index: 10;
  background: color-mix(in srgb, var(--accent) 12%, var(--bg));
  border: 2px dashed var(--accent);
  border-radius: 14px;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 15px;
  font-weight: 600;
  color: var(--accent);
  pointer-events: none;
}

.chat-drop-overlay.visible {
  display: flex;
}

.chat-drop-icon {
  font-size: 36px;
}

.chat-log {
  display: flex;
  flex-direction: column;
  gap: 12px;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-right: 8px;
  padding-bottom: 16px;
}

.bubble {
  padding: 12px 16px;
  border-radius: 14px;
  line-height: 1.4;
  width: fit-content;
  max-width: 85%;
  white-space: pre-wrap;
}

.bubble.user {
  align-self: flex-end;
  background: var(--accent);
  color: var(--accent-on-dark);
}

.bubble.assistant {
  background: var(--surface-hover);
  color: var(--ink);
  border: 1px solid var(--border);
  white-space: normal;
}

.bubble.assistant h1,
.bubble.assistant h2,
.bubble.assistant h3 {
  margin: 8px 0 4px;
  font-weight: 600;
}

.bubble.assistant h1 {
  font-size: 20px;
}

.bubble.assistant h2 {
  font-size: 18px;
}

.bubble.assistant h3 {
  font-size: 16px;
}

.bubble.assistant p {
  margin: 6px 0;
}

.bubble.assistant ul {
  margin: 6px 0 6px 18px;
  padding: 0;
}

.bubble.assistant li {
  margin: 4px 0;
}

/* --- Markdown code blocks inside bubbles --- */
.bubble.assistant pre {
  margin: 8px 0;
  padding: 12px 14px;
  background: var(--surface-deep);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow-x: auto;
  font-size: 13px;
  line-height: 1.5;
}

.bubble.assistant pre code {
  background: none;
  padding: 0;
  border-radius: 0;
  font-size: inherit;
  color: inherit;
}

.bubble.assistant code {
  background: var(--surface-deep);
  padding: 2px 6px;
  border-radius: 5px;
  font-size: 0.9em;
  color: var(--accent);
}

.bubble.assistant table {
  width: 100%;
  border-collapse: collapse;
  margin: 8px 0;
  font-size: 13px;
}

.bubble.assistant th,
.bubble.assistant td {
  padding: 6px 10px;
  border: 1px solid var(--border);
  text-align: left;
}

.bubble.assistant th {
  background: var(--surface-deep);
  font-weight: 600;
}

.bubble.assistant blockquote {
  margin: 8px 0;
  padding: 8px 14px;
  border-left: 3px solid var(--accent);
  color: var(--muted);
  background: var(--surface-deep);
  border-radius: 0 8px 8px 0;
}

.bubble.assistant a {
  color: var(--accent);
  text-decoration: underline;
}

.bubble.streaming {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.bubble.streaming .stream-text {
  display: inline;
}

.spinner {
  display: inline-block;
  width: 12px;
  height: 12px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex-shrink: 0;
  vertical-align: middle;
}

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

/* --- Typing indicator (bouncing dots) --- */
.typing-indicator {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.typing-indicator span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  opacity: 0.4;
  animation: typing-bounce 1.2s ease-in-out infinite;
}

.typing-indicator span:nth-child(2) {
  animation-delay: 0.2s;
}

.typing-indicator span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes typing-bounce {
  0%, 60%, 100% {
    transform: translateY(0);
    opacity: 0.4;
  }
  30% {
    transform: translateY(-6px);
    opacity: 1;
  }
}

.meta {
  display: block;
  font-size: 11px;
  margin-top: 8px;
  padding-top: 6px;
  border-top: 1px solid var(--border);
  color: var(--muted);
  white-space: normal;
}

.chat-form {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  flex-shrink: 0;
}

.chat-form input {
  flex: 1;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--ink);
  font-size: 15px;
}

.chat-form button[type="submit"] {
  padding: 10px 16px;
  border-radius: 10px;
  background: var(--accent);
  color: var(--accent-on-dark);
  border: none;
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
}

.chat-form button[type="submit"]:hover {
  opacity: 0.9;
}

/* --- Export button --- */
.btn-export {
  padding: 6px;
  border-radius: 8px;
  background: none;
  color: var(--muted);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.2s;
}

.btn-export:hover {
  color: var(--accent);
  opacity: 1;
}

/* --- Mic / Voice input button --- */
.btn-mic {
  padding: 6px;
  border-radius: 8px;
  background: none;
  color: var(--muted);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.2s, box-shadow 0.2s;
  position: relative;
}

.btn-mic:hover {
  color: var(--accent);
}

.btn-mic.recording {
  color: #ef4444;
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.25);
  animation: mic-pulse 1.5s ease-in-out infinite;
}

.btn-mic.recording .mic-icon {
  stroke: #ef4444;
}

@keyframes mic-pulse {
  0%, 100% { box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.25); }
  50% { box-shadow: 0 0 0 8px rgba(239, 68, 68, 0.1); }
}

/* --- Attach image button --- */
.btn-attach {
  padding: 6px;
  border-radius: 8px;
  background: none;
  color: var(--muted);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.2s;
}

.btn-attach:hover {
  color: var(--accent);
}

/* --- Image preview chip --- */
.image-preview-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px 4px 4px;
  background: var(--surface-hover);
  border: 1px solid var(--border);
  border-radius: 20px;
  max-width: 220px;
}

.image-preview-thumb {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1;
  min-width: 0;
}

.image-preview-thumb img {
  width: 28px;
  height: 28px;
  object-fit: cover;
  border-radius: 50%;
  border: 1px solid var(--border);
}

.image-preview-name {
  font-size: 12px;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.image-preview-remove {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 14px;
  cursor: pointer;
  padding: 0 2px;
  border-radius: 50%;
  line-height: 1;
  transition: color 0.2s;
}

.image-preview-remove:hover {
  color: #ef4444;
}

/* --- Image thumbnail in user bubble --- */
.bubble-image-thumb {
  display: block;
  max-width: 200px;
  max-height: 150px;
  border-radius: 8px;
  margin-top: 6px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  cursor: pointer;
  transition: opacity 0.2s;
}

.bubble-image-thumb:hover {
  opacity: 0.8;
}

/* --- Image lightbox --- */
.image-lightbox {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(0, 0, 0, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: zoom-out;
  animation: lightbox-in 0.15s ease;
}

.image-lightbox img {
  max-width: 90vw;
  max-height: 90vh;
  border-radius: 10px;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.5);
}

@keyframes lightbox-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.hints {
  flex-shrink: 0;
  margin-top: 8px;
  color: var(--muted);
  font-size: 13px;
}

.hints ul {
  margin: 8px 0 0;
  padding-left: 18px;
}

/* --- In-bubble tool details --- */
.bubble-tool-details {
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--muted);
}

.bubble-tool-details summary {
  cursor: pointer;
  color: var(--accent);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.bubble-tool-details pre {
  margin: 8px 0 0;
  padding: 10px 12px;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 8px;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 12px;
  color: var(--ink);
  max-height: 200px;
  overflow-y: auto;
}

/* --- Copy button --- */
.copy-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 3px 6px;
  font-size: 13px;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.2s;
  color: var(--muted);
  line-height: 1;
}

.bubble.assistant {
  position: relative;
}

.bubble.assistant:hover .copy-btn {
  opacity: 1;
}

.copy-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

@media (max-width: 640px) {
  .chat-form {
    flex-direction: row;
    flex-wrap: nowrap;
    gap: 4px;
  }

  .chat-form input {
    font-size: 14px;
    padding: 10px 10px;
    min-width: 0;
  }

  .chat-form button[type="submit"] {
    padding: 10px 10px;
    font-size: 0;
    min-width: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .chat-form button[type="submit"]::after {
    content: "\279C";
    font-size: 16px;
  }

  .btn-mic,
  .btn-attach {
    padding: 4px;
    flex-shrink: 0;
  }

  .bubble {
    max-width: 92%;
    font-size: 14px;
    padding: 10px 12px;
  }

  .hints {
    font-size: 12px;
  }

  .hints ul {
    padding-left: 14px;
  }
}
