/* =========================================================
   Chat IA — design system
   ========================================================= */

* { box-sizing: border-box; }

/* --- Thèmes --- */
:root,
html[data-theme="dark"] {
  --bg: #0b0d11;
  --bg-gradient: radial-gradient(ellipse at top, #131722 0%, #0b0d11 60%);
  --surface: #14181f;
  --surface-2: #1b2029;
  --surface-hover: #232935;
  --border: #262c38;
  --border-soft: #1e232d;
  --text: #e9ecf1;
  --text-muted: #8b93a3;
  --text-faint: #5c6473;
  --accent: #7c9aff;
  --accent-2: #a882ff;
  --accent-soft: #7c9aff22;
  --user-bubble: #1e2536;
  --user-border: #2d3650;
  --danger: #ff7a90;
  --danger-bg: #2a1a20;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.25);
}

html[data-theme="light"] {
  --bg: #ffffff;
  --bg-gradient: radial-gradient(ellipse at top, #f4f6fb 0%, #ffffff 55%);
  --surface: #f8f9fc;
  --surface-2: #f1f3f8;
  --surface-hover: #e9ecf3;
  --border: #e2e6ee;
  --border-soft: #eceff5;
  --text: #14171c;
  --text-muted: #6b7280;
  --text-faint: #9ca3af;
  --accent: #4f6ef2;
  --accent-2: #8b5cf6;
  --accent-soft: #4f6ef21a;
  --user-bubble: #eef2ff;
  --user-border: #d5ddff;
  --danger: #e11d48;
  --danger-bg: #fef2f4;
  --shadow: 0 8px 32px rgba(20, 23, 28, 0.08);
  --shadow-sm: 0 2px 8px rgba(20, 23, 28, 0.06);
}

/* --- Base --- */
html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  background: var(--bg-gradient);
}

button { font: inherit; cursor: pointer; border: none; background: none; color: inherit; }
button:disabled { cursor: not-allowed; opacity: .5; }

.hidden { display: none !important; }

/* Scrollbar élégante */
.chat::-webkit-scrollbar,
#input::-webkit-scrollbar { width: 8px; }
.chat::-webkit-scrollbar-thumb,
#input::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}
.chat::-webkit-scrollbar-thumb:hover,
#input::-webkit-scrollbar-thumb:hover { background: var(--text-faint); }
.chat::-webkit-scrollbar-track { background: transparent; }

/* =========================================================
   TOPBAR
   ========================================================= */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 24px;
  background: color-mix(in srgb, var(--surface) 80%, transparent);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border-soft);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }

.logo {
  width: 36px; height: 36px;
  border-radius: 10px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  box-shadow: 0 4px 12px color-mix(in srgb, var(--accent) 40%, transparent);
  flex-shrink: 0;
}
.logo svg { width: 20px; height: 20px; }

.brand-text { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.brand-text h1 {
  font-size: 15px;
  font-weight: 600;
  margin: 0;
  letter-spacing: -0.01em;
}
.model-badge {
  font-size: 11.5px;
  color: var(--text-muted);
  font-family: 'JetBrains Mono', monospace;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.actions { display: flex; align-items: center; gap: 8px; }

.icon-btn {
  width: 38px; height: 38px;
  border-radius: 10px;
  display: grid; place-items: center;
  color: var(--text-muted);
  border: 1px solid transparent;
  transition: background .15s, color .15s, border-color .15s;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); border-color: var(--border); }
.icon-btn svg { width: 18px; height: 18px; }

.icon-btn.danger:hover { background: var(--danger-bg); color: var(--danger); border-color: var(--danger); }

/* Icônes de thème */
html[data-theme="dark"] .icon-sun { display: block; }
html[data-theme="dark"] .icon-moon { display: none; }
html[data-theme="light"] .icon-sun { display: none; }
html[data-theme="light"] .icon-moon { display: block; }

.btn-ghost {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 38px;
  padding: 0 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  font-size: 13.5px;
  font-weight: 500;
  transition: background .15s, color .15s, border-color .15s;
}
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-ghost svg { width: 15px; height: 15px; }

/* =========================================================
   ZONE DE CHAT
   ========================================================= */
.chat {
  flex: 1;
  overflow-y: auto;
  padding: 32px 20px 8px;
  scroll-behavior: smooth;
}

/* --- État vide --- */
.empty-state {
  max-width: 640px;
  margin: 8vh auto 0;
  text-align: center;
  animation: fadeUp .5s ease both;
}

.empty-icon {
  width: 64px; height: 64px;
  margin: 0 auto 20px;
  border-radius: 18px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent-soft), transparent);
  border: 1px solid var(--border);
  color: var(--accent);
}
.empty-icon svg { width: 30px; height: 30px; }

.empty-state h2 {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0 0 8px;
}
.empty-state > p {
  color: var(--text-muted);
  font-size: 14.5px;
  margin: 0 0 32px;
}

.suggestions {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  max-width: 540px;
  margin: 0 auto;
}
.suggestion {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  font-size: 13.5px;
  text-align: left;
  transition: all .15s ease;
}
.suggestion:hover {
  background: var(--surface-2);
  border-color: var(--accent);
  color: var(--text);
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}
.suggestion-emoji { font-size: 16px; flex-shrink: 0; }

/* --- Messages --- */
.msg {
  max-width: 800px;
  margin: 0 auto 24px;
  display: flex;
  gap: 14px;
  align-items: flex-start;
  animation: fadeUp .25s ease both;
}

.avatar {
  flex: 0 0 32px;
  width: 32px; height: 32px;
  border-radius: 50%;
  display: grid; place-items: center;
  font-size: 13px;
  font-weight: 600;
  user-select: none;
  flex-shrink: 0;
  margin-top: 2px;
}
.msg.user .avatar { background: var(--user-bubble); border: 1px solid var(--user-border); color: var(--text-muted); }
.msg.assistant .avatar {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  box-shadow: 0 2px 8px color-mix(in srgb, var(--accent) 35%, transparent);
}
.msg.assistant .avatar svg { width: 15px; height: 15px; }

.bubble {
  position: relative;
  padding: 12px 16px;
  border-radius: 14px;
  border: 1px solid var(--border-soft);
  background: var(--surface);
  line-height: 1.65;
  font-size: 14.5px;
  word-wrap: break-word;
  overflow-wrap: anywhere;
  min-width: 0;
  max-width: 100%;
}
.msg.user .bubble {
  background: var(--user-bubble);
  border-color: var(--user-border);
}
.msg.assistant .bubble { padding-right: 44px; } /* espace pour le bouton copier */

.bubble.error {
  background: var(--danger-bg);
  border-color: var(--danger);
  color: var(--danger);
}

/* --- Bouton copier --- */
.copy-btn {
  position: absolute;
  top: 8px; right: 8px;
  width: 28px; height: 28px;
  border-radius: 8px;
  display: grid; place-items: center;
  color: var(--text-faint);
  background: transparent;
  opacity: 0;
  transition: opacity .15s, background .15s, color .15s;
}
.msg.assistant .bubble:hover .copy-btn { opacity: 1; }
.copy-btn:hover { background: var(--surface-hover); color: var(--text); }
.copy-btn svg { width: 14px; height: 14px; }
.copy-btn.copied { color: var(--accent); opacity: 1; }

/* --- Curseur + indicateur de frappe --- */
.cursor {
  display: inline-block;
  width: 7px; height: 1em;
  background: var(--accent);
  vertical-align: -2px;
  margin-left: 2px;
  border-radius: 2px;
  animation: blink 1s steps(2, start) infinite;
}
@keyframes blink { to { visibility: hidden; } }

.typing {
  display: inline-flex;
  gap: 4px;
  align-items: center;
  height: 1em;
}
.typing span {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: typingPulse 1.2s ease-in-out infinite;
}
.typing span:nth-child(2) { animation-delay: .15s; }
.typing span:nth-child(3) { animation-delay: .3s; }
@keyframes typingPulse {
  0%, 60%, 100% { transform: translateY(0); opacity: .4; }
  30% { transform: translateY(-4px); opacity: 1; }
}

/* --- Markdown --- */
.bubble p { margin: 0 0 10px; }
.bubble p:last-child { margin-bottom: 0; }
.bubble h1, .bubble h2, .bubble h3, .bubble h4 {
  margin: 16px 0 8px;
  font-weight: 600;
  line-height: 1.3;
  letter-spacing: -0.01em;
}
.bubble h1:first-child, .bubble h2:first-child, .bubble h3:first-child { margin-top: 0; }
.bubble h1 { font-size: 19px; }
.bubble h2 { font-size: 17px; }
.bubble h3 { font-size: 15.5px; }
.bubble ul, .bubble ol { margin: 8px 0; padding-left: 22px; }
.bubble li { margin: 3px 0; }
.bubble li > p { margin: 0; }
.bubble a { color: var(--accent); text-decoration: none; border-bottom: 1px solid transparent; transition: border-color .15s; }
.bubble a:hover { border-bottom-color: var(--accent); }
.bubble strong { font-weight: 600; color: var(--text); }
.bubble code {
  font-family: 'JetBrains Mono', ui-monospace, 'SFMono-Regular', Menlo, monospace;
  font-size: 0.88em;
  padding: 2px 6px;
  border-radius: 5px;
  background: var(--surface-2);
  border: 1px solid var(--border-soft);
  color: var(--text);
}
.bubble pre {
  margin: 12px 0;
  padding: 14px 16px;
  border-radius: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  overflow-x: auto;
  font-size: 13px;
  line-height: 1.5;
}
.bubble pre code {
  padding: 0;
  background: transparent;
  border: none;
  font-size: inherit;
  color: inherit;
}
.bubble blockquote {
  margin: 10px 0;
  padding: 4px 0 4px 14px;
  border-left: 3px solid var(--accent);
  color: var(--text-muted);
  font-style: italic;
}
.bubble table {
  border-collapse: collapse;
  margin: 12px 0;
  font-size: 13.5px;
  width: 100%;
}
.bubble th, .bubble td {
  border: 1px solid var(--border);
  padding: 7px 12px;
  text-align: left;
}
.bubble th { background: var(--surface-2); font-weight: 600; }
.bubble hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 16px 0;
}

/* =========================================================
   COMPOSER
   ========================================================= */
.composer-wrap {
  padding: 8px 20px 22px;
  background: linear-gradient(to top, var(--bg) 60%, transparent);
  position: sticky;
  bottom: 0;
}

.composer {
  max-width: 800px;
  margin: 0 auto;
}

.composer-inner {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 8px 8px 8px 16px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  transition: border-color .15s, box-shadow .15s;
}
.composer-inner:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft), var(--shadow-sm);
}

#input {
  flex: 1;
  resize: none;
  max-height: 220px;
  padding: 8px 0;
  border: none;
  background: transparent;
  color: var(--text);
  font: inherit;
  line-height: 1.55;
  outline: none;
  min-height: 24px;
}
#input::placeholder { color: var(--text-faint); }

.composer-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.send-btn {
  width: 38px; height: 38px;
  border-radius: 10px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  transition: filter .15s, transform .05s, opacity .15s;
}
.send-btn:hover:not(:disabled) { filter: brightness(1.1); }
.send-btn:active:not(:disabled) { transform: scale(.96); }
.send-btn:disabled {
  background: var(--surface-2);
  color: var(--text-faint);
  filter: none;
}
.send-btn svg { width: 17px; height: 17px; }

.composer-hint {
  text-align: center;
  margin: 10px 0 0;
  font-size: 11.5px;
  color: var(--text-faint);
}
.composer-hint kbd {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10.5px;
  padding: 1px 5px;
  border-radius: 4px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-muted);
}

/* =========================================================
   ANIMATIONS
   ========================================================= */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* =========================================================
   RESPONSIVE
   ========================================================= */
@media (max-width: 640px) {
  .topbar { padding: 12px 16px; }
  .brand-text .model-badge { display: none; }
  .btn-ghost span { display: none; }
  .btn-ghost { padding: 0 10px; }

  .chat { padding: 24px 14px 8px; }
  .msg { margin-bottom: 18px; gap: 10px; }
  .msg.assistant .bubble { padding-right: 40px; }

  .empty-state { margin-top: 4vh; }
  .empty-state h2 { font-size: 22px; }
  .suggestions { grid-template-columns: 1fr; }

  .composer-wrap { padding: 8px 12px 14px; }
  .composer-hint { display: none; }
}

/* =========================================================
   BLOCS DE CODE — wrapper + toolbar
   ========================================================= */
.code-block {
  margin: 14px 0;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  overflow: hidden;
}

.code-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px 8px 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--border-soft);
}

.code-lang {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.code-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.code-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 28px;
  padding: 0 10px;
  border-radius: 7px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 500;
  transition: background .15s, color .15s, border-color .15s;
  cursor: pointer;
}
.code-btn:hover {
  background: var(--surface-2);
  color: var(--text);
  border-color: var(--border);
}
.code-btn svg { width: 13px; height: 13px; }

.code-btn.accent {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: transparent;
}
.code-btn.accent:hover {
  background: var(--accent);
  color: #fff;
}

.code-btn.copied {
  color: var(--accent);
  border-color: var(--accent-soft);
}

/* Le <pre> à l'intérieur n'a plus besoin de ses marges/bordures */
.code-block pre {
  margin: 0;
  border: none;
  border-radius: 0;
  background: transparent;
  max-height: 400px;
  overflow: auto;
  transition: max-height .25s ease;
}
.code-block pre::-webkit-scrollbar { width: 8px; height: 8px; }
.code-block pre::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

/* Replié par défaut si trop long */
.code-block:not(.expanded) pre.collapsed {
  max-height: 220px;
  overflow: hidden;
  position: relative;
}
.code-block:not(.expanded) pre.collapsed::after {
  content: '';
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 60px;
  background: linear-gradient(to bottom, transparent, var(--surface-2));
  pointer-events: none;
}

/* =========================================================
   MODAL DE PRÉVISUALISATION
   ========================================================= */
.preview-dialog {
  width: min(1100px, 94vw);
  max-width: 94vw;
  height: min(780px, 90vh);
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.5);
  overflow: hidden;
}
.preview-dialog::backdrop {
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.preview-shell {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.preview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px 12px 18px;
  border-bottom: 1px solid var(--border-soft);
  background: var(--surface-2);
}

.preview-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  font-weight: 600;
}
.preview-dot {
  display: inline-flex;
  gap: 5px;
}
.preview-dot::before,
.preview-dot::after,
.preview-dot { /* astuce : trois points via pseudo */ }
.preview-dot {
  width: 44px; height: 12px;
  position: relative;
}
.preview-dot::before,
.preview-dot::after,
.preview-dot {
  background:
    radial-gradient(circle at 6px 6px, #ff5f57 6px, transparent 7px),
    radial-gradient(circle at 22px 6px, #febc2e 6px, transparent 7px),
    radial-gradient(circle at 38px 6px, #28c840 6px, transparent 7px);
  background-repeat: no-repeat;
}

.preview-lang {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  color: var(--text-muted);
  padding: 2px 8px;
  border-radius: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.preview-actions { display: flex; align-items: center; gap: 4px; }

.preview-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: #fff;
}

#preview-frame {
  flex: 1;
  width: 100%;
  border: none;
  background: #fff;
}

/* Console */
.preview-console {
  height: 180px;
  min-height: 180px;
  display: flex;
  flex-direction: column;
  border-top: 1px solid var(--border);
  background: #0d1117;
  color: #e6edf3;
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 12.5px;
}

.console-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 12px;
  background: #161b22;
  border-bottom: 1px solid #21262d;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #8b949e;
}

.console-btn {
  font-size: 11px;
  color: #8b949e;
  padding: 2px 8px;
  border-radius: 5px;
}
.console-btn:hover { color: #e6edf3; background: #21262d; }

.console-body {
  flex: 1;
  overflow-y: auto;
  padding: 8px 12px;
}

.console-line {
  padding: 2px 0;
  white-space: pre-wrap;
  word-break: break-word;
  border-left: 2px solid transparent;
  padding-left: 8px;
  margin: 2px 0;
}
.console-line.log     { color: #e6edf3; border-color: #30363d; }
.console-line.info    { color: #79c0ff; border-color: #1f6feb; }
.console-line.warn    { color: #e3b341; border-color: #9e6a03; }
.console-line.error   { color: #ff7b72; border-color: #da3633; }
.console-line .ts     { color: #6e7681; margin-right: 8px; }

/* Responsive */
@media (max-width: 700px) {
  .code-btn span { display: none; }
  .code-btn { padding: 0 8px; }
  .preview-dialog {
    width: 100vw;
    max-width: 100vw;
    height: 100dvh;
    max-height: 100dvh;
    border-radius: 0;
    border: none;
  }
  .preview-console { height: 140px; min-height: 140px; }
}

/* =========================================================
   MODE SWITCH (Chat / Générer / Retoucher)
   ========================================================= */
.mode-switch {
  display: flex;
  gap: 4px;
  padding: 4px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: fit-content;
  margin: 0 auto 12px;
}

.mode-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 14px;
  border-radius: 9px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s, color .15s, box-shadow .15s;
}
.mode-btn svg { width: 15px; height: 15px; flex-shrink: 0; }
.mode-btn:hover { color: var(--text); }
.mode-btn.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

/* =========================================================
   UPLOAD PANEL (mode Retoucher)
   ========================================================= */
.upload-panel {
  max-width: 800px;
  margin: 0 auto 12px;
  padding: 0 4px;
}

.upload-drop {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 14px 18px;
  border: 1.5px dashed var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text-muted);
  font-size: 13.5px;
  cursor: pointer;
  transition: border-color .15s, background .15s, color .15s;
}
.upload-drop:hover,
.upload-drop.dragover {
  border-color: var(--accent);
  background: var(--surface-2);
  color: var(--text);
}
.upload-drop svg { width: 18px; height: 18px; flex-shrink: 0; }

.image-preview {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px;
  margin-top: 10px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  animation: fadeUp .2s ease both;
}
.image-preview img {
  width: 64px;
  height: 64px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--border);
  flex-shrink: 0;
}
.image-preview-info {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex: 1;
  gap: 10px;
  min-width: 0;
}
.preview-filename {
  font-size: 13px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.image-remove {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  color: var(--text-muted);
  background: transparent;
  border: 1px solid transparent;
  transition: background .15s, color .15s, border-color .15s;
  flex-shrink: 0;
}
.image-remove:hover {
  background: var(--danger-bg);
  color: var(--danger);
  border-color: var(--danger);
}
.image-remove svg { width: 14px; height: 14px; }

/* =========================================================
   IMAGE RÉSULTAT (dans les bulles du chat)
   ========================================================= */
.generated-image {
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: flex-start;
}
.generated-image img {
  max-width: 100%;
  max-height: 520px;
  border-radius: 10px;
  border: 1px solid var(--border);
  display: block;
  box-shadow: var(--shadow-sm);
}
.generated-image .image-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* Responsive */
@media (max-width: 640px) {
  .mode-btn span { display: none; }
  .mode-btn { padding: 7px 10px; }
  .upload-text { font-size: 12.5px; }
}

.svg-host {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  margin: 12px 0;
  text-align: center;
}

/* 🔧 FIX : wrapper pour que le title s'affiche même sur bouton disabled */
.mode-wrapper {
  display: inline-flex;
  position: relative;
}
.mode-wrapper[title]:hover::after {
  content: attr(title);
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 12px;
  white-space: nowrap;
  box-shadow: var(--shadow-sm);
  pointer-events: none;
  z-index: 100;
  animation: fadeUp .15s ease both;
}

.mode-btn .mode-badge { margin-left: 2px; }
.mode-btn[disabled] .mode-badge { display: none; }

/* =========================================================
   APP SHELL — layout avec sidebar
   ========================================================= */
body {
  display: block;           /* on remplace flex-column */
  height: 100dvh;
  overflow: hidden;
}

.app-shell {
  display: flex;
  height: 100dvh;
  width: 100%;
}

.app-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  height: 100dvh;
}

/* =========================================================
   SIDEBAR
   ========================================================= */
.sidebar {
  width: 280px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  height: 100dvh;
  background: var(--surface);
  border-right: 1px solid var(--border-soft);
  overflow: hidden;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 16px 12px;
  border-bottom: 1px solid var(--border-soft);
}
.sidebar-brand .logo {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  flex-shrink: 0;
}
.sidebar-brand .logo svg { width: 18px; height: 18px; }
.sidebar-brand h1 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.sidebar-new {
  margin: 12px 12px 8px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  transition: all .15s;
  text-align: left;
}
.sidebar-new:hover {
  background: var(--surface-hover);
  border-color: var(--accent);
}
.sidebar-new svg { width: 15px; height: 15px; flex-shrink: 0; }

.sidebar-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 8px;
  min-height: 0;
}
.sidebar-list::-webkit-scrollbar { width: 6px; }
.sidebar-list::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

.sidebar-item {
  display: flex;
  align-items: stretch;
  gap: 2px;
  margin-bottom: 2px;
  border-radius: 8px;
  transition: background .15s;
}
.sidebar-item:hover {
  background: var(--surface-2);
}
.sidebar-item.active {
  background: var(--accent-soft);
}

.sidebar-item-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 9px 10px;
  text-align: left;
  background: transparent;
  border: none;
  color: var(--text);
  cursor: pointer;
  border-radius: 8px;
}

.sidebar-item-title {
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text);
}
.sidebar-item.active .sidebar-item-title { color: var(--accent); }

.sidebar-item-meta {
  font-size: 11px;
  color: var(--text-faint);
}

.sidebar-item-delete {
  flex-shrink: 0;
  width: 28px;
  background: transparent;
  border: none;
  color: var(--text-faint);
  cursor: pointer;
  border-radius: 8px;
  opacity: 0;
  transition: opacity .15s, color .15s, background .15s;
  display: grid;
  place-items: center;
}
.sidebar-item:hover .sidebar-item-delete { opacity: 1; }
.sidebar-item-delete:hover {
  color: var(--danger);
  background: var(--danger-bg);
}
.sidebar-item-delete svg { width: 13px; height: 13px; }

.sidebar-empty {
  padding: 24px 12px;
  text-align: center;
  font-size: 12.5px;
  color: var(--text-faint);
  line-height: 1.5;
}

.sidebar-footer {
  border-top: 1px solid var(--border-soft);
  padding: 8px;
}

.sidebar-clear {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 8px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 12.5px;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.sidebar-clear:hover {
  background: var(--danger-bg);
  color: var(--danger);
}
.sidebar-clear svg { width: 14px; height: 14px; flex-shrink: 0; }

/* Backdrop mobile */
.sidebar-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(2px);
  z-index: 99;
}
.sidebar-backdrop[hidden] { display: none; }

/* Bouton hamburger (visible uniquement sur mobile) */
.sidebar-toggle { display: none; }

/* =========================================================
   RESPONSIVE — sidebar en drawer sur mobile
   ========================================================= */
@media (max-width: 900px) {
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 100;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.4);
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .sidebar-toggle { display: grid; }
  .topbar { padding-left: 8px; }
}

/* =========================================================
   PARTAGE D'ÉCRAN
   ========================================================= */
.screen-btn.active {
  background: var(--danger-bg);
  color: var(--danger);
  border-color: var(--danger);
  animation: screenPulse 1.5s ease-in-out infinite;
}

@keyframes screenPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 122, 144, 0.5); }
  50%      { box-shadow: 0 0 0 6px rgba(255, 122, 144, 0); }
}

.screen-preview {
  max-width: 800px;
  margin: 0 auto 10px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-2);
  display: flex;
  align-items: center;
  gap: 12px;
  animation: fadeUp .2s ease both;
}

.screen-preview img {
  max-height: 72px;
  max-width: 128px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: #000;
  flex-shrink: 0;
}

.screen-preview-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
  min-width: 0;
  font-size: 13px;
}

.screen-live-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--danger);
  margin-right: 6px;
  animation: screenPulse 1.5s ease-in-out infinite;
}

.screen-preview-info strong {
  color: var(--text);
  font-weight: 600;
}

.screen-live-hint {
  color: var(--text-muted);
  font-size: 12px;
}

.screen-stop {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  color: var(--text-muted);
  flex-shrink: 0;
  transition: background .15s, color .15s;
}

.screen-stop:hover {
  background: var(--danger-bg);
  color: var(--danger);
}

.screen-stop svg { width: 14px; height: 14px; }

@media (max-width: 640px) {
  .screen-preview { padding: 8px; gap: 8px; }
  .screen-preview img { max-height: 56px; max-width: 96px; }
  .screen-live-hint { display: none; }
}

/* =========================================================
   MODALE DE CONSENTEMENT PARTAGE D'ÉCRAN
   ========================================================= */
.consent-dialog {
  width: min(480px, 92vw);
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.5);
}

.consent-dialog::backdrop {
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.consent-shell {
  padding: 24px 24px 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  animation: fadeUp .2s ease both;
}

.consent-icon {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, var(--accent-soft), transparent);
  border: 1px solid var(--border);
  color: var(--accent);
  margin-bottom: 2px;
}
.consent-icon svg { width: 24px; height: 24px; }

.consent-shell h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.consent-intro {
  margin: 0;
  color: var(--text-muted);
  font-size: 14px;
  line-height: 1.55;
}

.consent-list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 10px;
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.5;
}
.consent-list li {
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border-soft);
}
.consent-list li strong { color: var(--text); font-weight: 600; }
.consent-list code {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11.5px;
  padding: 1px 6px;
  border-radius: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--accent);
}
.consent-list .consent-warn {
  background: color-mix(in srgb, var(--danger-bg) 60%, var(--surface-2));
  border-color: color-mix(in srgb, var(--danger) 30%, var(--border-soft));
}
.consent-list .consent-warn strong { color: var(--danger); }

.consent-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 4px;
}

.btn-primary {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 18px;
  border-radius: 9px;
  border: none;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  transition: filter .15s, transform .05s;
}
.btn-primary:hover { filter: brightness(1.1); }
.btn-primary:active { transform: scale(.98); }

@media (max-width: 480px) {
  .consent-shell { padding: 20px 18px 16px; gap: 12px; }
  .consent-actions { flex-direction: column-reverse; }
  .consent-actions button { width: 100%; justify-content: center; }
}
/* Le panneau d'aperçu affiche un titre variable selon le mode (écran / photo) */
.screen-preview-info strong {
  transition: color .15s;
}

/* =========================================================
   PARTAGE D'ÉCRAN / PHOTO
   ========================================================= */
.screen-btn.active {
  background: var(--danger-bg);
  color: var(--danger);
  border-color: var(--danger);
  animation: screenPulse 1.5s ease-in-out infinite;
}
@keyframes screenPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 122, 144, 0.5); }
  50%      { box-shadow: 0 0 0 6px rgba(255, 122, 144, 0); }
}

.screen-preview {
  max-width: 800px;
  margin: 0 auto 10px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-2);
  display: flex;
  align-items: center;
  gap: 12px;
  animation: fadeUp .2s ease both;
}
.screen-preview img {
  max-height: 72px; max-width: 128px;
  border-radius: 6px; border: 1px solid var(--border);
  background: #000; flex-shrink: 0;
}
.screen-preview-info {
  display: flex; flex-direction: column; gap: 2px;
  flex: 1; min-width: 0; font-size: 13px;
}
.screen-live-dot {
  display: inline-block; width: 8px; height: 8px;
  border-radius: 50%; background: var(--danger);
  margin-right: 6px; animation: screenPulse 1.5s ease-in-out infinite;
}
.screen-preview-info strong { color: var(--text); font-weight: 600; }
.screen-live-hint { color: var(--text-muted); font-size: 12px; }
.screen-stop {
  width: 32px; height: 32px; border-radius: 8px;
  display: grid; place-items: center;
  color: var(--text-muted); flex-shrink: 0;
  transition: background .15s, color .15s;
}
.screen-stop:hover { background: var(--danger-bg); color: var(--danger); }
.screen-stop svg { width: 14px; height: 14px; }

/* Modale de consentement */
.consent-dialog {
  width: min(480px, 92vw); padding: 0;
  border: 1px solid var(--border); border-radius: 16px;
  background: var(--surface); color: var(--text);
  box-shadow: 0 24px 80px rgba(0,0,0,0.5);
}
.consent-dialog::backdrop {
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.consent-shell {
  padding: 24px 24px 20px;
  display: flex; flex-direction: column; gap: 14px;
  animation: fadeUp .2s ease both;
}
.consent-icon {
  width: 48px; height: 48px; border-radius: 12px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent-soft), transparent);
  border: 1px solid var(--border); color: var(--accent);
  margin-bottom: 2px;
}
.consent-icon svg { width: 24px; height: 24px; }
.consent-shell h2 { margin: 0; font-size: 18px; font-weight: 700; letter-spacing: -0.01em; }
.consent-intro { margin: 0; color: var(--text-muted); font-size: 14px; line-height: 1.55; }
.consent-list {
  margin: 0; padding: 0; list-style: none;
  display: flex; flex-direction: column; gap: 10px;
  font-size: 13px; color: var(--text-muted); line-height: 1.5;
}
.consent-list li {
  padding: 10px 12px; border-radius: 8px;
  background: var(--surface-2); border: 1px solid var(--border-soft);
}
.consent-list li strong { color: var(--text); font-weight: 600; }
.consent-list code {
  font-family: 'JetBrains Mono', monospace; font-size: 11.5px;
  padding: 1px 6px; border-radius: 4px;
  background: var(--surface); border: 1px solid var(--border); color: var(--accent);
}
.consent-list .consent-warn {
  background: color-mix(in srgb, var(--danger-bg) 60%, var(--surface-2));
  border-color: color-mix(in srgb, var(--danger) 30%, var(--border-soft));
}
.consent-list .consent-warn strong { color: var(--danger); }
.consent-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 4px; }
.btn-primary {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 9px 18px; border-radius: 9px; border: none;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff; font-size: 13.5px; font-weight: 600;
  cursor: pointer; transition: filter .15s, transform .05s;
}
.btn-primary:hover { filter: brightness(1.1); }
.btn-primary:active { transform: scale(.98); }

@media (max-width: 640px) {
  .screen-preview { padding: 8px; gap: 8px; }
  .screen-preview img { max-height: 56px; max-width: 96px; }
  .screen-live-hint { display: none; }
  .consent-shell { padding: 20px 18px 16px; gap: 12px; }
  .consent-actions { flex-direction: column-reverse; }
  .consent-actions button { width: 100%; justify-content: center; }
}