/* ===== Variables de base ===== */
:root {
  --surface:   #1e1e2e;
  --surface-2: #2a2a3e;
  --surface-3: #313145;
  --accent:    #6366f1;
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 9999px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.2); }

/* ===== Textarea auto-resize ===== */
#msg-input { field-sizing: content; }

/* ===== Bulles de message ===== */
.msg-user {
  display: flex;
  justify-content: flex-end;
}

.msg-user .bubble {
  background: var(--accent);
  color: white;
  border-radius: 1.25rem 1.25rem 0.25rem 1.25rem;
  padding: 0.75rem 1rem;
  max-width: 75%;
  font-size: 0.9rem;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}

.msg-assistant {
  display: flex;
  justify-content: flex-start;
  align-items: flex-start;
  gap: 0.625rem;
}

.msg-assistant .avatar {
  width: 1.75rem;
  height: 1.75rem;
  min-width: 1.75rem;
  border-radius: 0.5rem;
  background: rgba(99, 102, 241, 0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--accent);
  margin-top: 0.1rem;
}

.msg-assistant .bubble {
  background: var(--surface-2);
  border: 1px solid rgba(255,255,255,0.06);
  color: #e2e8f0;
  border-radius: 0.25rem 1.25rem 1.25rem 1.25rem;
  padding: 0.75rem 1rem;
  max-width: 85%;
  font-size: 0.9rem;
  line-height: 1.7;
  word-break: break-word;
}

/* ===== Markdown dans les bulles assistant ===== */
.bubble h1,.bubble h2,.bubble h3,.bubble h4 {
  font-weight: 600;
  margin-top: 1em;
  margin-bottom: 0.4em;
  line-height: 1.3;
}
.bubble h1 { font-size: 1.25em; }
.bubble h2 { font-size: 1.1em; }
.bubble h3 { font-size: 1em; }

.bubble p { margin: 0.5em 0; }
.bubble p:first-child { margin-top: 0; }
.bubble p:last-child  { margin-bottom: 0; }

.bubble ul,.bubble ol { padding-left: 1.4em; margin: 0.5em 0; }
.bubble ul { list-style: disc; }
.bubble ol { list-style: decimal; }
.bubble li { margin: 0.2em 0; }

.bubble a { color: #818cf8; text-decoration: underline; }

.bubble code {
  background: rgba(255,255,255,0.07);
  border: 1px solid rgba(255,255,255,0.08);
  padding: 0.1em 0.4em;
  border-radius: 0.3em;
  font-size: 0.85em;
  font-family: ui-monospace, monospace;
}

.bubble pre {
  background: #0d1117;
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 0.5rem;
  overflow-x: auto;
  margin: 0.75em 0;
  position: relative;
}

.bubble pre code {
  background: none;
  border: none;
  padding: 1rem;
  display: block;
  font-size: 0.82em;
  line-height: 1.6;
}

.bubble blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 0.75em;
  color: #94a3b8;
  margin: 0.5em 0;
  font-style: italic;
}

.bubble table {
  border-collapse: collapse;
  width: 100%;
  margin: 0.75em 0;
  font-size: 0.85em;
}
.bubble th,.bubble td {
  border: 1px solid rgba(255,255,255,0.1);
  padding: 0.4em 0.7em;
  text-align: left;
}
.bubble th { background: rgba(255,255,255,0.05); font-weight: 600; }

/* ===== Curseur streaming ===== */
@keyframes blink { 0%,100% { opacity: 1; } 50% { opacity: 0; } }
.streaming-cursor {
  display: inline-block;
  width: 2px;
  height: 1em;
  background: var(--accent);
  border-radius: 1px;
  margin-left: 2px;
  vertical-align: text-bottom;
  animation: blink 0.8s step-end infinite;
}

/* ===== Blocs tool_call / tool_result (mode agent) ===== */
.tool-block {
  font-size: 0.8rem;
  border-radius: 0.625rem;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,0.07);
  margin: 0.4rem 0;
}

.tool-block-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.45rem 0.75rem;
  cursor: pointer;
  user-select: none;
  font-weight: 500;
}

.tool-call .tool-block-header  { background: rgba(99,102,241,0.12); color: #a5b4fc; }
.tool-result .tool-block-header { background: rgba(34,197,94,0.10);  color: #86efac; }
.tool-error  .tool-block-header { background: rgba(239,68,68,0.10);  color: #fca5a5; }

.tool-block-body {
  background: rgba(0,0,0,0.2);
  padding: 0.6rem 0.75rem;
  max-height: 200px;
  overflow-y: auto;
  font-family: ui-monospace, monospace;
  font-size: 0.78rem;
  line-height: 1.5;
  color: #cbd5e1;
  white-space: pre-wrap;
  word-break: break-all;
}

.tool-block-body.collapsed { display: none; }

.tool-chevron {
  margin-left: auto;
  transition: transform 0.2s;
}
.tool-chevron.open { transform: rotate(180deg); }

/* ===== Bouton de téléchargement de fichier Office ===== */
a.download-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  margin-top: 0.5rem;
  padding: 0.45rem 0.9rem;
  background: rgba(99,102,241,0.15);
  border: 1px solid rgba(99,102,241,0.4);
  border-radius: 0.5rem;
  color: #a5b4fc;
  font-size: 0.82rem;
  font-weight: 500;
  text-decoration: none;
  transition: background 0.15s, border-color 0.15s;
}
a.download-btn::before {
  content: "⬇️";
  font-size: 0.9em;
}
a.download-btn:hover {
  background: rgba(99,102,241,0.28);
  border-color: rgba(99,102,241,0.7);
  color: #c7d2fe;
  text-decoration: none;
}

/* Badge mode agent sur le bouton toggle */
#btn-mode-toggle.agent-mode {
  border-color: rgba(99,102,241,0.5);
  background: rgba(99,102,241,0.08);
  color: #a5b4fc;
}

/* ===== Modal de prévisualisation de fichier ===== */
#preview-modal {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

#preview-modal.hidden { display: none; }

#preview-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.65);
  backdrop-filter: blur(3px);
}

#preview-panel {
  position: relative;
  background: var(--surface-2);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 1rem;
  width: 100%;
  max-width: 900px;
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 24px 60px rgba(0,0,0,0.5);
  overflow: hidden;
}

#preview-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid rgba(255,255,255,0.07);
  flex-shrink: 0;
}

#preview-icon { font-size: 1.1rem; }
#preview-filename {
  flex: 1;
  font-size: 0.85rem;
  font-weight: 500;
  color: #e2e8f0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#preview-download-btn {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.35rem 0.75rem;
  background: rgba(99,102,241,0.15);
  border: 1px solid rgba(99,102,241,0.4);
  border-radius: 0.5rem;
  color: #a5b4fc;
  font-size: 0.78rem;
  font-weight: 500;
  text-decoration: none;
  transition: background 0.15s;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
}
#preview-download-btn:hover {
  background: rgba(99,102,241,0.28);
  border-color: rgba(99,102,241,0.7);
  color: #c7d2fe;
}

#preview-close {
  flex-shrink: 0;
  padding: 0.25rem;
  color: #64748b;
  cursor: pointer;
  background: none;
  border: none;
  line-height: 1;
  transition: color 0.15s;
}
#preview-close:hover { color: #f87171; }

#preview-body {
  flex: 1;
  overflow: hidden;
  position: relative;
}

#preview-body.loading::after {
  content: "Chargement…";
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #64748b;
  font-size: 0.9rem;
}

#preview-iframe {
  width: 100%;
  height: 100%;
  border: none;
  display: block;
  background: #f8fafc;
}

/* ===== Navigation sidebar commune ===== */
.nav-link {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  border-radius: 0.5rem;
  font-size: 0.8rem;
  font-weight: 500;
  color: #94a3b8;
  transition: background 0.15s, color 0.15s;
  text-decoration: none;
}
.nav-link:hover { background: rgba(255,255,255,0.05); color: #e2e8f0; }
.nav-active { background: rgba(99,102,241,0.15) !important; color: #a5b4fc !important; }

/* ===== Formulaires modaux ===== */
.form-label {
  display: block;
  font-size: 0.75rem;
  color: #94a3b8;
  margin-bottom: 0.25rem;
  font-weight: 500;
}
.form-input {
  width: 100%;
  background: var(--surface-3);
  border: 1px solid rgba(255,255,255,0.10);
  border-radius: 0.5rem;
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  color: #e2e8f0;
  transition: ring 0.15s;
}
.form-input:focus { outline: none; box-shadow: 0 0 0 2px rgba(99,102,241,0.5); }
.form-input::placeholder { color: #475569; }

/* ===== Sélecteur backend hardware ===== */
.backend-option { cursor: pointer; }
.backend-option input:checked + .backend-btn {
  background: rgba(99,102,241,0.15);
  border-color: rgba(99,102,241,0.5);
  color: #c7d2fe;
}
.backend-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.15rem;
  padding: 0.6rem 0.5rem;
  border-radius: 0.625rem;
  border: 1px solid rgba(255,255,255,0.08);
  background: var(--surface-3);
  font-size: 0.78rem;
  text-align: center;
  transition: background 0.15s, border-color 0.15s;
  width: 100%;
}
.backend-btn:hover { background: rgba(255,255,255,0.05); }

/* ===== Badge modèle hardware ===== */
.hw-model-badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 0.375rem;
  font-size: 0.68rem;
  font-weight: 500;
  background: rgba(255,255,255,0.05);
  color: #94a3b8;
  border: 1px solid rgba(255,255,255,0.08);
  font-family: ui-monospace, monospace;
}

/* ===== Cartes projet ===== */
.project-card {
  background: var(--surface-2);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 0.875rem;
  padding: 1rem 1.125rem;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.project-card:hover {
  border-color: rgba(99,102,241,0.25);
  box-shadow: 0 4px 16px rgba(0,0,0,0.25);
}

.project-action-btn {
  padding: 0.25rem;
  border-radius: 0.375rem;
  transition: color 0.15s, background 0.15s;
  line-height: 1;
}
.project-action-btn:hover { background: rgba(255,255,255,0.06); }

.project-tag {
  display: inline-block;
  padding: 0.15rem 0.55rem;
  border-radius: 9999px;
  font-size: 0.7rem;
  font-weight: 500;
  background: rgba(99,102,241,0.12);
  color: #a5b4fc;
  border: 1px solid rgba(99,102,241,0.2);
}

.line-clamp-2 {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ===== Journal de projet ===== */
.journal-entry {
  border-radius: 0.625rem;
  padding: 0.75rem;
  border: 1px solid rgba(255,255,255,0.06);
  background: rgba(0,0,0,0.15);
}
.journal-pending     { border-color: rgba(251,191,36,0.25); background: rgba(251,191,36,0.04); }
.journal-validated   { border-color: rgba(52,211,153,0.2);  background: rgba(52,211,153,0.04); }
.journal-invalidated { border-color: rgba(239,68,68,0.2);   background: rgba(239,68,68,0.04);  }

.journal-status-badge {
  font-size: 0.65rem;
  font-weight: 600;
  padding: 0.15rem 0.5rem;
  border-radius: 9999px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.journal-status-badge.journal-pending     { background: rgba(251,191,36,0.15); color: #fbbf24; }
.journal-status-badge.journal-validated   { background: rgba(52,211,153,0.15); color: #34d399; }
.journal-status-badge.journal-invalidated { background: rgba(239,68,68,0.15);  color: #f87171; }

.journal-action-btn {
  font-size: 0.72rem;
  font-weight: 500;
  padding: 0.2rem 0.6rem;
  border-radius: 0.375rem;
  border: 1px solid currentColor;
  opacity: 0.8;
  transition: opacity 0.15s;
}
.journal-action-btn:hover { opacity: 1; }

/* ===== Item conversation dans sidebar ===== */
.conv-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  border-radius: 0.5rem;
  cursor: pointer;
  transition: background 0.15s;
  font-size: 0.8rem;
  color: #94a3b8;
  position: relative;
}
.conv-item:hover { background: rgba(255,255,255,0.05); color: #e2e8f0; }
.conv-item.active { background: rgba(99,102,241,0.15); color: #c7d2fe; }
.conv-item .conv-title { flex: 1; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.conv-item .conv-delete {
  opacity: 0;
  transition: opacity 0.15s;
  color: #64748b;
}
.conv-item:hover .conv-delete { opacity: 1; }
.conv-item .conv-delete:hover { color: #f87171; }

/* ===== Gestion de fichiers ===== */
.file-action-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 1.75rem;
  height: 1.75rem;
  border-radius: 0.375rem;
  transition: color 0.15s, background 0.15s;
}
.file-action-btn:hover { background: rgba(255,255,255,0.06); }

.filter-btn {
  padding: 0.25rem 0.75rem;
  border-radius: 9999px;
  font-size: 0.75rem;
  border: 1px solid rgba(255,255,255,0.08);
  color: #94a3b8;
  transition: all 0.15s;
}
.filter-btn:hover { border-color: rgba(255,255,255,0.2); color: #e2e8f0; }
.filter-btn.filter-active {
  background: rgba(99,102,241,0.2);
  border-color: rgba(99,102,241,0.4);
  color: #a5b4fc;
}
