/* ── Chat layout ── */
.chat-layout {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

.chat-header {
  background: #fff;
  border-bottom: 1px solid #e9ecef;
  padding: 0.875rem 2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.chat-header-info { display: flex; flex-direction: column; gap: 0.1rem; }
.chat-header-actions { display: flex; gap: 0.5rem; }

.chat-title {
  font-size: 1.05rem;
  font-weight: 600;
  margin: 0;
  color: #1d1919;
}

.chat-scope {
  font-size: 0.75rem;
  color: #6c757d;
  font-family: "Fira Mono", "Consolas", monospace;
}

/* ── Messages area ── */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1.75rem 2rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  background: #f4f6fb;
}

.chat-messages::-webkit-scrollbar       { width: 5px; }
.chat-messages::-webkit-scrollbar-track  { background: transparent; }
.chat-messages::-webkit-scrollbar-thumb  { background: #dee2e6; border-radius: 3px; }

/* ── Welcome state ── */
.chat-welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  padding: 4rem 2rem;
  text-align: center;
  flex: 1;
}

.chat-welcome-icon {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: linear-gradient(135deg, #dbeafe, #ede9fe);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
}

.chat-welcome p {
  font-size: 0.975rem;
  color: #6c757d;
  margin: 0;
  max-width: 420px;
  line-height: 1.6;
}

.chat-welcome code {
  background: #e9ecef;
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
  font-size: 0.875em;
  color: #495057;
}

/* ── Message rows ── */
.chat-message {
  display: flex;
  flex-direction: column;
  max-width: 82%;
}

.chat-message--user {
  align-self: flex-end;
  align-items: flex-end;
}

.chat-message--assistant {
  align-self: flex-start;
  align-items: flex-start;
}

/* ── Bubbles ── */
.msg-bubble {
  padding: 0.75rem 1rem;
  border-radius: 1rem;
  font-size: 0.925rem;
  line-height: 1.65;
  word-break: break-word;
}

.msg-bubble--user {
  background: #0d6efd;
  color: #fff;
  border-bottom-right-radius: 0.25rem;
  white-space: pre-wrap;
}

.msg-bubble--assistant {
  background: #fff;
  color: #212529;
  border: 1px solid #e9ecef;
  border-bottom-left-radius: 0.25rem;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}

/* ── Assistant content (markdown) ── */
.msg-content { min-width: 0; }

.msg-content p { margin: 0 0 0.625rem; }
.msg-content p:last-child { margin-bottom: 0; }

.msg-content h1, .msg-content h2, .msg-content h3,
.msg-content h4, .msg-content h5, .msg-content h6 {
  margin: 0.875rem 0 0.4rem;
  font-weight: 600;
  line-height: 1.3;
}
.msg-content h1:first-child, .msg-content h2:first-child,
.msg-content h3:first-child { margin-top: 0; }

.msg-content code {
  background: #f1f3f5;
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
  font-family: "Fira Mono", "Consolas", monospace;
  font-size: 0.875em;
  color: #d63384;
}

.msg-content pre {
  background: #0f1117;
  border-radius: 0.5rem;
  padding: 0.875rem 1rem;
  margin: 0.625rem 0;
  overflow-x: auto;
}

.msg-content pre code {
  background: none;
  padding: 0;
  color: #d4d4d4;
  font-size: 0.845rem;
  line-height: 1.6;
}

.msg-content ul, .msg-content ol {
  padding-left: 1.5rem;
  margin: 0.5rem 0;
}

.msg-content li { margin-bottom: 0.25rem; }

.msg-content blockquote {
  border-left: 3px solid #dee2e6;
  padding-left: 0.875rem;
  margin: 0.5rem 0;
  color: #6c757d;
}

.msg-content hr {
  border: none;
  border-top: 1px solid #e9ecef;
  margin: 0.75rem 0;
}

.msg-content table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
  margin: 0.5rem 0;
}

.msg-content th, .msg-content td {
  border: 1px solid #dee2e6;
  padding: 0.4rem 0.65rem;
  text-align: left;
}

.msg-content th { background: #f8f9fa; font-weight: 600; }

/* ── Typing cursor ── */
.typing-cursor {
  display: inline-block;
  animation: blink 0.9s step-end infinite;
  color: #0d6efd;
  font-size: 1.05em;
  line-height: 1;
  vertical-align: middle;
  margin-left: 1px;
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0; }
}

/* ── Thinking dots ── */
.thinking-dots {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.25rem 0;
}

.thinking-dots span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #adb5bd;
  animation: thinking 1.2s ease-in-out infinite;
}

.thinking-dots span:nth-child(1) { animation-delay: 0s;    }
.thinking-dots span:nth-child(2) { animation-delay: 0.2s;  }
.thinking-dots span:nth-child(3) { animation-delay: 0.4s;  }

@keyframes thinking {
  0%, 80%, 100% { transform: scale(0.8); opacity: 0.4; }
  40%           { transform: scale(1.1); opacity: 1;   }
}

/* ── Tool use pills ── */
.tool-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.35rem;
  margin-bottom: 0.5rem;
}

.msg-bubble--assistant > .msg-content + .tool-pills { margin-top: 0.5rem; }

.tool-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.775rem;
  font-family: "Fira Mono", "Consolas", monospace;
  background: #f1f3f5;
  border: 1px solid #dee2e6;
  border-radius: 20px;
  padding: 0.2rem 0.6rem;
  color: #495057;
  white-space: nowrap;
  overflow: hidden;
  max-width: 100%;
  text-overflow: ellipsis;
}

.tool-pill--read   { background: #e8f5e9; border-color: #a5d6a7; color: #2e7d32; }
.tool-pill--image  { background: #f3e8ff; border-color: #d8b4fe; color: #7e22ce; }
.tool-pill--write  { background: #fff3e0; border-color: #ffcc80; color: #c75a00; }
.tool-pill--edit   { background: #fff3e0; border-color: #ffcc80; color: #c75a00; }
.tool-pill--bash   { background: #e8eaf6; border-color: #9fa8da; color: #3949ab; }
.tool-pill--search { background: #e1f5fe; border-color: #81d4fa; color: #01579b; }
.tool-pill--web    { background: #ecfdf5; border-color: #6ee7b7; color: #065f46; }

/* ── Input area ── */
.chat-input-area {
  background: #fff;
  border-top: 1px solid #e9ecef;
  padding: 1rem 2rem 1.25rem;
  flex-shrink: 0;
}

.chat-input-wrap {
  display: flex;
  align-items: flex-end;
  gap: 0.625rem;
  background: #f8f9fa;
  border: 1px solid #dee2e6;
  border-radius: 0.75rem;
  padding: 0.625rem 0.75rem;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.chat-input-wrap:focus-within {
  border-color: #86b7fe;
  background: #fff;
  box-shadow: 0 0 0 3px rgba(13, 110, 253, 0.1);
}

.chat-input {
  flex: 1;
  border: none;
  background: transparent;
  resize: none;
  font-family: inherit;
  font-size: 0.935rem;
  line-height: 1.55;
  color: #212529;
  outline: none;
  min-height: 24px;
  max-height: 200px;
  overflow-y: auto;
}

.chat-input::placeholder { color: #adb5bd; }

.chat-send-btn {
  flex-shrink: 0;
  width: 34px;
  height: 34px;
  border-radius: 0.5rem;
  border: none;
  background: #0d6efd;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, opacity 0.15s;
}

.chat-send-btn:hover:not(:disabled) { background: #0b5ed7; }
.chat-send-btn:disabled { background: #c8d8fd; cursor: default; }

.chat-stop-btn { background: #dc3545; pointer-events: auto; }
.chat-stop-btn:hover { background: #bb2d3b; }

.chat-hint {
  font-size: 0.75rem;
  color: #adb5bd;
  margin: 0.5rem 0 0;
  text-align: center;
}

/* ── Streaming disabled state ── */
.chat-input-wrap.is-streaming {
  opacity: 0.7;
  pointer-events: none;
}

/* ── Attach button ── */
.chat-attach-btn {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border-radius: 0.4rem;
  border: none;
  background: none;
  color: #adb5bd;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: color 0.15s;
}

.chat-attach-btn:hover { color: #6366f1; }

/* ── Pending image previews strip ── */
.image-previews {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 0 0 0.6rem;
}

.image-preview-item {
  position: relative;
  width: 60px;
  height: 60px;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid #dee2e6;
  flex-shrink: 0;
}

.image-preview-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.image-preview-remove {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 17px;
  height: 17px;
  border-radius: 50%;
  background: rgba(0,0,0,0.6);
  color: #fff;
  border: none;
  cursor: pointer;
  font-size: 11px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.image-preview-remove:hover { background: rgba(0,0,0,0.85); }

/* ── Images in user messages ── */
.msg-images {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 0.5rem;
}

.msg-image {
  max-width: 220px;
  max-height: 180px;
  border-radius: 8px;
  object-fit: cover;
  cursor: zoom-in;
  display: block;
}

/* ── Drag-over highlight ── */
.chat-input-wrap.drag-over {
  border-color: #6366f1;
  background: #f0f0ff;
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

/* ── Instructions globales ── */
.chat-instructions-bar {
  border-top: 1px solid #e9ecef;
  background: #f8f9fa;
  flex-shrink: 0;
}

.instructions-toggle {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  width: 100%;
  padding: 0.45rem 1.5rem;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0.75rem;
  font-weight: 500;
  color: #6c757d;
  text-align: left;
}

.instructions-toggle:hover { color: #495057; }

#instructions-chevron {
  transition: transform 0.2s;
  flex-shrink: 0;
}

.instructions-badge {
  background: #6366f1;
  color: #fff;
  border-radius: 20px;
  padding: 0 0.45rem;
  font-size: 0.65rem;
  font-weight: 600;
  line-height: 1.6;
}

.instructions-body {
  padding: 0 1.5rem 0.75rem;
}

.instructions-textarea {
  width: 100%;
  border: 1px solid #dee2e6;
  border-radius: 6px;
  padding: 0.5rem 0.75rem;
  font-size: 0.8rem;
  font-family: inherit;
  color: #212529;
  background: #fff;
  resize: vertical;
  outline: none;
}

.instructions-textarea:focus { border-color: #6366f1; box-shadow: 0 0 0 3px rgba(99,102,241,.12); }

.instructions-hint {
  font-size: 0.7rem;
  color: #adb5bd;
  margin: 0.3rem 0 0;
}

/* ── Modale sauvegarde ── */
.save-modal-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.35);
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  transition: opacity 0.18s;
}

.save-modal-backdrop.is-open { opacity: 1; }

.save-modal {
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0,0,0,.18);
  width: 100%;
  max-width: 420px;
  margin: 1rem;
  transform: translateY(12px);
  transition: transform 0.18s;
}

.save-modal-backdrop.is-open .save-modal { transform: translateY(0); }

.save-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem 0.75rem;
  border-bottom: 1px solid #e9ecef;
}

.save-modal-title {
  font-weight: 600;
  font-size: 0.95rem;
  color: #1d1919;
}

.save-modal-close {
  background: none;
  border: none;
  font-size: 1.25rem;
  line-height: 1;
  color: #6c757d;
  cursor: pointer;
  padding: 0 0.25rem;
}

.save-modal-close:hover { color: #212529; }

.save-modal-body {
  padding: 1rem 1.25rem;
}

.save-modal-label {
  display: block;
  font-size: 0.8rem;
  font-weight: 500;
  color: #495057;
  margin-bottom: 0.4rem;
}

.save-filename-wrap {
  display: flex;
  align-items: center;
  border: 1px solid #dee2e6;
  border-radius: 6px;
  overflow: hidden;
}

.save-filename-input {
  flex: 1;
  border: none;
  outline: none;
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  font-family: inherit;
  color: #212529;
}

.save-filename-wrap:focus-within {
  border-color: #6366f1;
  box-shadow: 0 0 0 3px rgba(99,102,241,.12);
}

.save-filename-ext {
  padding: 0.5rem 0.75rem;
  font-size: 0.8rem;
  color: #6c757d;
  background: #f8f9fa;
  border-left: 1px solid #dee2e6;
  user-select: none;
}

.save-modal-error {
  margin: 0.5rem 0 0;
  font-size: 0.8rem;
  color: #dc3545;
}

.save-modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  padding: 0.75rem 1.25rem 1rem;
  border-top: 1px solid #e9ecef;
}

/* ── Pending card ── */
.pending-card {
  flex-shrink: 0;
  margin: 0.75rem 0;
  border: 1px solid #f59e0b;
  border-radius: 10px;
  background: #fffbeb;
  overflow: hidden;
}

.pending-card--done {
  border-color: #e2e8f0;
  background: #f8fafc;
}

.pending-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.65rem 1rem;
  font-size: 0.82rem;
  font-weight: 500;
  color: #92400e;
}

.pending-card--done .pending-header {
  color: #64748b;
}

.pending-title { flex: 1; }

.pending-file {
  font-size: 0.75rem;
  background: rgba(0,0,0,0.06);
  padding: 0.1em 0.45em;
  border-radius: 4px;
}

.pending-actions {
  display: flex;
  gap: 0.5rem;
  padding: 0.6rem 1rem 0.75rem;
  border-top: 1px solid #fde68a;
}

.pending-btn {
  padding: 0.3em 0.85em;
  font-size: 0.78rem;
  font-weight: 500;
  border-radius: 6px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: opacity 0.15s;
}
.pending-btn:hover { opacity: 0.8; }

.pending-btn--run    { background: #3b82f6; color: #fff; }
.pending-btn--confirm { background: #10b981; color: #fff; }
.pending-btn--discard { background: #fff; color: #6b7280; border-color: #d1d5db; }

.pending-output {
  margin: 0;
  padding: 0.65rem 1rem;
  font-size: 0.72rem;
  font-family: monospace;
  line-height: 1.5;
  background: #0f172a;
  color: #e2e8f0;
  max-height: 220px;
  overflow-y: auto;
  white-space: pre-wrap;
}