:root {
  --font: "Inter", system-ui, "Segoe UI", Roboto, Arial, sans-serif;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --transition: 0.2s ease;
  --params-width: 280px;
}

[data-theme="dark"] {
  --bg-base:         #0d1117;
  --bg-surface:      #161b22;
  --bg-card:         #1c2128;
  --bg-input:        #0d1117;
  --bg-hover:        #21262d;
  --border:          #30363d;
  --border-sub:      #21262d;
  --text:            #e6edf3;
  --text-muted:      #7d8590;
  --text-label:      #a0aec0;
  --accent:          #58a6ff;
  --accent-dim:      #1f3a5f;
  --badge-ok-bg:     #0d2818;
  --badge-ok-bd:     #1a4731;
  --badge-err-bg:    #2d0f0f;
  --badge-err-bd:    #5b1a1a;
  --dot:             #3fb950;
  --dot-glow:        #3fb95066;
  --user-bubble:     #1c2128;
  --ai-bubble:       #161b22;
  --btn-primary-bg:  #0b2925;
  --btn-primary-bd:  #2ea043;
  --btn-primary-tx:  #ffffff;
  --scrollbar:       #30363d;
  --range-track:     #30363d;
  --range-thumb:     #58a6ff;
  --section-title:   #8b949e;
}

[data-theme="light"] {
  --bg-base:         #f6f8fa;
  --bg-surface:      #ffffff;
  --bg-card:         #f0f2f5;
  --bg-input:        #ffffff;
  --bg-hover:        #eaeef2;
  --border:          #d0d7de;
  --border-sub:      #e8ecf0;
  --text:            #1f2328;
  --text-muted:      #636e7b;
  --text-label:      #57606a;
  --accent:          #0969da;
  --accent-dim:      #dbeafe;
  --badge-ok-bg:     #dafbe1;
  --badge-ok-bd:     #82e09a;
  --badge-err-bg:    #ffebe9;
  --badge-err-bd:    #ffcec7;
  --dot:             #1a7f37;
  --dot-glow:        #1a7f3733;
  --user-bubble:     #ffffff;
  --ai-bubble:       #f0f6ff;
  --btn-primary-bg:  #1f883d;
  --btn-primary-bd:  #1a7f37;
  --btn-primary-tx:  #ffffff;
  --scrollbar:       #d0d7de;
  --range-track:     #d0d7de;
  --range-thumb:     #0969da;
  --section-title:   #57606a;
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  font-family: var(--font);
  font-size: 13px;
  background: var(--bg-base);
  color: var(--text);
  transition: background var(--transition), color var(--transition);
}

.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-width: 100%;
  padding: 0;
  overflow: hidden;
}

/* ── Header ── */
header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  flex-wrap: wrap;
}

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

.title .dot {
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--dot);
  box-shadow: 0 0 8px var(--dot-glow);
}

h1 {
  font-size: 16px;
  font-weight: 600;
  margin: 0;
  color: var(--text);
}

.status {
  display: flex;
  gap: 7px;
  align-items: center;
  flex: 1;
  font-size: 12px;
  color: var(--text-muted);
  min-width: 0;
  overflow: hidden;
}

#init-label {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.badge {
  background: var(--bg-card);
  border: 1px solid var(--border);
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 500;
  white-space: nowrap;
  flex-shrink: 0;
}

.badge[data-ok="true"]  { background: var(--badge-ok-bg); border-color: var(--badge-ok-bd); color: var(--dot); }
.badge[data-ok="false"] { background: var(--badge-err-bg); border-color: var(--badge-err-bd); color: #e5534b; }

.model-badge {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--accent);
  max-width: 300px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.actions button {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: var(--bg-card);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 5px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
  transition: background var(--transition), border-color var(--transition);
}

.actions button:hover { background: var(--bg-hover); border-color: var(--accent); }
#btn-theme { padding: 5px 9px; font-size: 15px; }

/* ── Workspace 2 colonnes ── */
.workspace {
  display: flex;
  flex: 1;
  overflow: hidden;
  gap: 0;
}

/* ── Colonne chat ── */
.chat-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 12px;
}

.chat {
  display: flex;
  flex-direction: column;
  flex: 1;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 12px;
  overflow: hidden;
  box-shadow: 0 2px 16px rgba(0,0,0,.06);
}

.messages {
  flex: 1;
  overflow-y: auto;
  border-radius: var(--radius-md);
  padding: 10px;
  background: var(--bg-base);
  border: 1px solid var(--border-sub);
  display: flex;
  flex-direction: column;
  gap: 4px;
  scrollbar-width: thin;
  scrollbar-color: var(--scrollbar) transparent;
}

.messages::-webkit-scrollbar { width: 5px; }
.messages::-webkit-scrollbar-thumb { background: var(--scrollbar); border-radius: 99px; }

.msg { display: flex; gap: 10px; padding: 2px 0; }

.msg .who {
  width: 68px;
  flex-shrink: 0;
  font-size: 10px;
  font-weight: 700;
  text-align: right;
  color: var(--text-muted);
  padding-top: 10px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
}

.msg .bubble {
  flex: 1;
  background: var(--user-bubble);
  border: 1px solid var(--border);
  padding: 9px 13px;
  border-radius: var(--radius-md);
  border-top-left-radius: 4px;
  white-space: pre-wrap;
  word-wrap: break-word;
  line-height: 1.6;
  font-size: 13.5px;
}

.msg.assistant .bubble {
  background: var(--ai-bubble);
  border-color: var(--border-sub);
  border-top-right-radius: 4px;
  border-top-left-radius: var(--radius-md);
}

.msg.user { flex-direction: row-reverse; }
.msg.user .who { text-align: left; }
.msg.user .bubble {
  background: var(--accent-dim);
  border-color: var(--accent);
  border-top-left-radius: var(--radius-md);
  border-top-right-radius: 4px;
}

.msg-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 8px;
  border-top: 1px solid var(--border-sub);
  padding-top: 4px;
}

.msg-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px 8px;
  font-size: 14px;
  border-radius: var(--radius-sm);
  transition: all var(--transition);
}

.msg-btn:hover {
  background: var(--bg-hover);
  color: var(--text);
}

/* On cache les actions pendant que l'IA écrit (le texte est "...") */
.msg.assistant .content:empty + .msg-actions,
.msg.assistant .content:contains('...') + .msg-actions {
  display: none;
}



/* ── Input ── */
.input-row {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  align-items: flex-end;
}

.input-row textarea {
  flex: 1;
  padding: 9px 13px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text);
  font-size: 13.5px;
  font-family: var(--font);
  resize: none;
  line-height: 1.5;
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
}

.input-row textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent);
}

.input-row textarea::placeholder { color: var(--text-muted); }

.input-row button {
  padding: 9px 16px;
  border-radius: 10px;
  border: 1px solid var(--btn-primary-bd);
  background: var(--btn-primary-bg);
  color: var(--btn-primary-tx);
  cursor: pointer;
  /*font-size: 13px;*/
  font-weight: 600;
  font-family: var(--font);
  white-space: nowrap;
  transition: opacity var(--transition), transform var(--transition);
  align-self: flex-end;
}

.input-row button:hover { 
  background: var(--bg-card);
  border-color: var(--border);
  color: var(--text);
}
.input-row button:active { transform: scale(0.97); }

/* ── Panneau paramètres ── */
.params-col {
  width: var(--params-width);
  flex-shrink: 0;
  border-left: 1px solid var(--border);
  background: var(--bg-surface);
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--scrollbar) transparent;
}

.params-panel {
  padding: 14px 14px 20px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.params-title {
  font-size: 13px;
  font-weight: 600;
  margin: 0 0 10px 0;
  color: var(--text);
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.param-section {
  margin-bottom: 14px;
}

.param-section h3 {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--section-title);
  margin: 0 0 10px 0;
  padding-top: 10px;
}

.param-section label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-bottom: 10px;
  font-size: 12px;
  color: var(--text-label);
  font-weight: 500;
}

.param-section label span {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.param-section label em {
  font-style: normal;
  font-weight: 600;
  color: var(--accent);
  font-size: 12px;
}

/* Range slider */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  border-radius: 99px;
  background: var(--range-track);
  outline: none;
  cursor: pointer;
  accent-color: var(--range-thumb);
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--range-thumb);
  cursor: pointer;
  border: 2px solid var(--bg-surface);
  box-shadow: 0 1px 4px rgba(0,0,0,.3);
  transition: transform 0.1s;
}

input[type="range"]::-webkit-slider-thumb:hover { transform: scale(1.2); }
input[type="range"]::-moz-range-thumb {
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--range-thumb);
  border: 2px solid var(--bg-surface);
  cursor: pointer;
}

.param-section input[type="number"],
.param-section select {
  width: 100%;
  padding: 6px 9px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text);
  font-family: var(--font);
  font-size: 12px;
  outline: none;
  transition: border-color var(--transition);
}

.param-section input[type="number"]:focus,
.param-section select:focus { border-color: var(--accent); }

.param-section textarea {
  width: 100%;
  padding: 7px 9px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text);
  font-family: var(--font);
  font-size: 12px;
  resize: vertical;
  outline: none;
  line-height: 1.5;
  transition: border-color var(--transition);
}

.param-section textarea:focus { border-color: var(--accent); }

.btn-accent {
  width: 100%;
  margin-top: 6px;
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--btn-primary-bd);
  background: var(--btn-primary-bg);
  color: var(--btn-primary-tx);
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  font-family: var(--font);
  transition: opacity var(--transition);
}

.btn-accent:hover { 
  background: var(--bg-card);
  border-color: var(--border);
  color: var(--text); 
}

/* ── Responsive ── */
@media (max-width: 640px) {
  .workspace { flex-direction: column; }
  .params-col {
    width: 100%;
    border-left: none;
    border-top: 1px solid var(--border);
    max-height: 40vh;
  }
}

/* ── Bubble wrapper & copy button ── */
.bubble-wrapper {
  flex: 1;
  display: flex;
  align-items: flex-start;
  gap: 6px;
  min-width: 0;
}

.bubble-wrapper .bubble {
  flex: 1;
}

.copy-btn {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  margin-top: 7px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  opacity: 0;
  transition: opacity var(--transition), background var(--transition), color var(--transition), border-color var(--transition);
}

.msg:hover .copy-btn {
  opacity: 1;
}

.copy-btn:hover {
  background: var(--bg-hover);
  border-color: var(--border);
  color: var(--text);
}

.copy-btn.copied {
  color: var(--dot);
  border-color: var(--badge-ok-bd);
  background: var(--badge-ok-bg);
  opacity: 1;
}

/* ── Import / Export row ── */
.import-export-row {
  display: flex;
  gap: 7px;
}

.btn-half {
  flex: 1;
  margin-top: 0;
}

/* ── Sauvegardes ── */
.saves-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 8px;
}

.saves-empty {
  font-size: 11px;
  color: var(--text-muted);
  margin: 4px 0 0;
  font-style: italic;
}

.save-item {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 5px 7px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-card);
  transition: background var(--transition), border-color var(--transition);
  cursor: default;
}

.save-item:hover {
  background: var(--bg-hover);
  border-color: var(--accent);
}

.save-item.save-flash {
  border-color: var(--dot);
  background: var(--badge-ok-bg);
}

.save-name {
  flex: 1;
  font-size: 12px;
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.save-name:hover {
  color: var(--accent);
}

.save-actions {
  display: flex;
  gap: 2px;
  flex-shrink: 0;
}

.save-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 5px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
  padding: 0;
}

.save-btn:hover {
  background: var(--bg-surface);
  border-color: var(--border);
  color: var(--text);
}

.save-btn-del:hover {
  background: var(--badge-err-bg);
  border-color: var(--badge-err-bd);
  color: #e5534b;
}

.save-rename-input {
  flex: 1;
  font-size: 12px;
  font-family: var(--font);
  padding: 1px 5px;
  border-radius: 4px;
  border: 1px solid var(--accent);
  background: var(--bg-input);
  color: var(--text);
  outline: none;
  min-width: 0;
}

/* ── Attachment ── */
.input-stack {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.input-row-inner {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

.attach-btn {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-hover);
  color: var(--text-muted);
  cursor: pointer;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  align-self: flex-end;
  transition: background var(--transition), border-color var(--transition), color var(--transition);
}

.attach-btn:hover {
  background: var(--bg-card);
  border-color: var(--border);
  color: var(--text);
}

.attach-btn.has-file {
  border-color: var(--dot);
  background: var(--badge-ok-bg);
  color: var(--dot);
}

.attach-btn:active {
  transform: scale(0.95);
}

.file-preview {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--badge-ok-bd);
  background: var(--badge-ok-bg);
  font-size: 12px;
}

.file-preview-name {
  font-weight: 600;
  color: var(--dot);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 200px;
}

.file-preview-size {
  color: var(--text-muted);
  flex-shrink: 0;
  font-size: 11px;
}

.file-preview-warn {
  color: #e3b341;
  font-size: 11px;
  flex-shrink: 0;
}

.file-remove-btn {
  margin-left: auto;
  flex-shrink: 0;
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 13px;
  padding: 0 2px;
  line-height: 1;
  transition: color var(--transition);
}

.file-remove-btn:hover { color: #e5534b; }

/* ── Optimisation des performances de rendu ── */
.msg {
  display: flex; gap: 10px; padding: 2px 0;
  content-visibility: auto; /* Le navigateur ne calcule pas le rendu hors écran */
  contain-intrinsic-size: auto 60px; /* Taille estimée par défaut */
}

/* ── Auto-resize du Textarea ── */
.input-row textarea {
  /* ... tes styles existants ... */
  max-height: 200px; /* Limite la hauteur maximale */
  overflow-y: auto;  /* Scroll interne si le texte est très long */
}

/* ── Styles Markdown pour les bulles ── */
.bubble p { margin: 0 0 10px 0; }
.bubble p:last-child { margin-bottom: 0; }

.bubble pre {
  background: var(--bg-card);
  padding: 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  overflow-x: auto;
  font-size: 12px;
  margin: 10px 0;
}

.bubble code {
  font-family: monospace;
  background: color-mix(in srgb, var(--text) 15%, transparent);
  padding: 2px 5px;
  border-radius: 4px;
  font-size: 0.9em;
}

.bubble pre code {
  background: transparent;
  padding: 0;
  border-radius: 0;
}

.bubble ul, .bubble ol { margin: 5px 0 10px 20px; padding: 0; }

.msg-content code {
    background: var(--bg-color);
    padding: 0.2rem 0.4rem;
    border-radius: 4px;
    font-family: monospace;
}

.msg-content pre {
    background: #1e1e1e;
    color: #fff;
    padding: 1rem;
    border-radius: 8px;
    overflow-x: auto;
    margin: 0.5rem 0;
}

.send-btn:disabled {
  background-color: var(--bg-hover);
  color: var(--text-muted);
  cursor: not-allowed;
  opacity: 0.6;
  filter: grayscale(1);
}

/* Optionnel : ajouter une petite animation de pulsation sur le label de chargement */
#init-label {
    font-size: 12px;
    transition: all 0.3s ease;
}