:root {
  --bg: #0c0d12;
  --panel: #15171f;
  --panel-2: #1c1f2a;
  --border: #2a2e3c;
  --text: #e7e9ee;
  --muted: #8b90a0;
  --accent: #6c5ce7;
  --accent-2: #00d2a8;
  --danger: #ff5c7a;
  --radius: 14px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: radial-gradient(1200px 600px at 80% -10%, #1a1c2b 0%, var(--bg) 55%);
  color: var(--text);
  min-height: 100vh;
}

/* Header */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; flex-wrap: wrap;
  padding: 16px 32px;
  background: rgba(12, 13, 18, .82);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.brand { font-size: 19px; font-weight: 700; letter-spacing: -.3px; }
.brand .badge {
  font-size: 12px; font-weight: 600;
  color: var(--accent-2);
  background: rgba(0, 210, 168, .1);
  border: 1px solid rgba(0, 210, 168, .25);
  padding: 3px 9px; border-radius: 999px; margin-left: 8px;
  vertical-align: middle;
}
.topbar-right { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.project-picker { display: flex; align-items: center; gap: 8px; }
.project-picker select {
  background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
  border-radius: 9px; padding: 8px 11px; font-size: 13px; max-width: 220px;
}
.balance {
  font-size: 13px; color: var(--muted);
  background: var(--panel); border: 1px solid var(--border);
  padding: 8px 14px; border-radius: 999px;
}
.balance strong { color: var(--accent-2); }
.balance-load { opacity: .6; }

/* Onglet Projet */
.project-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 24px 32px 0; flex-wrap: wrap;
}
.project-name-input {
  background: none; border: none; color: var(--text);
  font-size: 22px; font-weight: 700; padding: 4px 0;
  border-bottom: 1px solid transparent; min-width: 240px; flex: 1;
}
.project-name-input:focus { outline: none; border-bottom-color: var(--accent); }
.project-head-actions { display: flex; gap: 8px; }
.ghost-btn.danger { color: var(--danger); }
.ghost-btn.danger:hover { border-color: var(--danger); }
.project-card { margin: 18px 32px 0; }
.project-card textarea {
  width: 100%; background: var(--panel-2); border: 1px solid var(--border);
  color: var(--text); border-radius: 10px; padding: 12px 14px; font-size: 14px;
  font-family: inherit; resize: vertical; line-height: 1.5;
}
.project-card textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(108,92,231,.18); }
.hint { color: var(--muted); font-size: 12px; margin: 10px 0 0; line-height: 1.5; }

/* Onglets */
.tabs {
  display: flex; gap: 4px;
  padding: 14px 32px 0;
  border-bottom: 1px solid var(--border);
}
.tab-btn {
  background: none; border: none;
  color: var(--muted); font-size: 14px; font-weight: 500;
  padding: 10px 18px; cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color .15s, border-color .15s;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--text); border-bottom-color: var(--accent); }

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* Bandeau de mode */
.mode-banner {
  margin: 20px 32px 0; padding: 12px 16px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 11px;
  font-size: 13px; color: var(--muted); line-height: 1.5;
}
.mode-banner strong { color: var(--text); }
.link-btn {
  background: none; border: none; color: var(--accent-2); cursor: pointer;
  font: inherit; padding: 0; text-decoration: underline;
}

/* Onglet Script — flux guidé */
.script-flow {
  max-width: 920px; margin: 0 auto;
  padding: 24px 32px 48px;
  display: flex; flex-direction: column; gap: 18px;
}
.step-card { }
.step-title { margin: 0 0 14px; font-size: 16px; }
.step-title .autosave { font-size: 11px; color: var(--muted); font-weight: 400; margin-left: 8px; }
.step-card > textarea {
  width: 100%; background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
  border-radius: 10px; padding: 12px 14px; font-size: 14px; font-family: inherit; resize: vertical;
  line-height: 1.5; margin-bottom: 14px;
}
.step-card > textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(108,92,231,.18); }
.step-card .primary { width: auto; padding: 12px 20px; }

/* Questions / formulaires */
.qblock { padding: 14px 0; border-top: 1px solid var(--border); }
.qblock:first-child { border-top: none; }
.qtext { font-size: 14px; font-weight: 500; margin-bottom: 10px; }
.qopts { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.opt {
  display: inline-flex; align-items: center; gap: 7px;
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 9px;
  padding: 8px 12px; font-size: 13px; cursor: pointer;
}
.opt input { accent-color: var(--accent); }
.opt:hover { border-color: var(--accent); }
.qcustom {
  width: 100%; background: var(--panel-2); border: 1px dashed var(--border); color: var(--text);
  border-radius: 8px; padding: 8px 11px; font-size: 13px;
}
.qcustom:focus { outline: none; border-color: var(--accent); }

/* Éléments récurrents */
.entity { border: 1px solid var(--border); border-radius: 11px; padding: 12px; margin-bottom: 10px; background: var(--panel-2); }
.entity-row { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.entity-row .ent-type { width: 130px; }
.entity-row .ent-name { flex: 1; }
.entity .ent-field { background: var(--panel); border: 1px solid var(--border); color: var(--text); border-radius: 8px; padding: 8px 10px; font-size: 13px; font-family: inherit; }
.entity textarea.ent-desc { width: 100%; resize: vertical; line-height: 1.45; }
.ent-del { width: 30px; height: 30px; border-radius: 8px; border: 1px solid var(--border); background: var(--panel); color: var(--danger); cursor: pointer; font-size: 18px; }
.ent-del:hover { border-color: var(--danger); }
.entity-ref { display: flex; align-items: center; gap: 10px; margin-top: 8px; }
.entity-ref img { width: 44px; height: 44px; object-fit: cover; border-radius: 7px; border: 1px solid var(--border); }
.entity-ref .noref { font-size: 11px; color: var(--muted); width: 44px; text-align: center; }
.entity-ref .ent-ref { flex: 1; }

.scene-ents { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.ent-tag { font-size: 11px; background: rgba(108,92,231,.15); color: #b9acff; border: 1px solid rgba(108,92,231,.3); border-radius: 999px; padding: 2px 9px; }

.scenes-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; gap: 10px; flex-wrap: wrap; }
.scenes-head .primary { width: auto; padding: 10px 16px; }
.scenes-head-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.primary.alt { background: linear-gradient(135deg, #d2691e, #e8954a); }
.scenes-head h3 { margin: 0; font-size: 16px; }
.scenes-head .primary { width: auto; padding: 10px 16px; }
.scene-item {
  border: 1px solid var(--border); border-radius: 11px; padding: 14px; margin-bottom: 12px;
  background: var(--panel-2);
}
.scene-item .scene-top { display: flex; justify-content: space-between; gap: 10px; align-items: center; margin-bottom: 8px; }
.scene-item .scene-title { font-weight: 600; font-size: 14px; }
.scene-item .scene-dur { font-size: 12px; color: var(--accent-2); white-space: nowrap; }
.scene-item .scene-desc { font-size: 13px; color: var(--text); margin-bottom: 10px; line-height: 1.5; }
.scene-field { margin-top: 8px; }
.scene-field .slbl { font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); display: block; margin-bottom: 4px; }
.scene-field textarea {
  width: 100%; background: var(--panel); border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; padding: 8px 10px; font-size: 12.5px; font-family: inherit; resize: vertical; line-height: 1.45;
}
.scene-field textarea:focus { outline: none; border-color: var(--accent); }

/* Références de cohérence */
.refs-block { margin-bottom: 16px; }
.refs-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.ref-chip {
  position: relative; width: 52px; height: 52px; padding: 0;
  border: 2px solid var(--border); border-radius: 9px; overflow: hidden;
  cursor: pointer; background: var(--panel-2);
}
.ref-chip img { width: 100%; height: 100%; object-fit: cover; opacity: .45; }
.ref-chip.on { border-color: var(--accent-2); }
.ref-chip.on img { opacity: 1; }
.ref-check {
  position: absolute; top: 2px; right: 3px; font-size: 12px; color: var(--accent-2);
  text-shadow: 0 0 3px #000; font-weight: 700;
}

/* Visuel de scène */
.scene-visual { margin-top: 12px; }
.scene-img { width: 100%; border-radius: 9px; margin-bottom: 10px; display: block; }
.scene-visual-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.scene-size {
  background: var(--panel); border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; padding: 7px 9px; font-size: 12px;
}
.scene-visual-actions .gen-img,
.scene-visual-actions .gen-vid { font-size: 12px; padding: 7px 12px; }
.img-state, .vid-state { font-size: 12px; color: var(--muted); }
.scene-video { margin-top: 14px; padding-top: 12px; border-top: 1px dashed var(--border); }
.scene-vid { width: 100%; border-radius: 9px; margin-bottom: 10px; display: block; background: #000; }
.scene-vmodel {
  background: var(--panel); border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; padding: 7px 9px; font-size: 12px;
}

/* Historique */
.history-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 24px 32px 0;
}
.history-head h2 { margin: 0; font-size: 20px; }
.ghost-btn {
  background: var(--panel); border: 1px solid var(--border);
  color: var(--text); border-radius: 9px; padding: 8px 14px;
  font-size: 13px; cursor: pointer;
}
.ghost-btn:hover { border-color: var(--accent); }

.history-section { padding: 24px 32px 8px; }
.history-section h3 {
  font-size: 14px; color: var(--muted); font-weight: 500;
  margin: 0 0 14px;
}
.history-section h3 .count {
  color: var(--text); background: var(--panel-2);
  border-radius: 999px; padding: 1px 9px; font-size: 12px; margin-left: 6px;
}
.empty { color: var(--muted); font-size: 14px; padding: 8px 0 24px; }

.media-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
}
.media-card {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 12px; overflow: hidden;
  display: flex; flex-direction: column;
}
.media-card video, .media-card .asset-img {
  width: 100%; aspect-ratio: 16/10; object-fit: cover;
  background: #000; display: block;
}
.media-card .asset-img { object-fit: contain; background: var(--panel-2); }
.media-meta { padding: 11px 13px; font-size: 12px; }
.media-meta .mtitle {
  color: var(--text); font-size: 13px; margin-bottom: 4px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.media-meta .msub { color: var(--muted); display: flex; justify-content: space-between; gap: 8px; }
.media-meta .mtag {
  color: var(--accent-2); font-size: 11px;
}
.media-card .card-actions {
  display: flex; gap: 6px; padding: 0 13px 12px; flex-wrap: wrap;
}
.media-card .card-actions a, .media-card .card-actions button {
  font-size: 12px; text-decoration: none; color: var(--text);
  background: var(--panel-2); border: 1px solid var(--border);
  border-radius: 8px; padding: 6px 10px; cursor: pointer;
}
.media-card .card-actions a:hover, .media-card .card-actions button:hover { border-color: var(--accent); }

.layout {
  display: grid;
  grid-template-columns: minmax(360px, 460px) 1fr;
  gap: 24px;
  padding: 20px 32px 48px;
  align-items: start;
}
@media (max-width: 900px) { .layout { grid-template-columns: 1fr; } }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
}

label.field { display: block; margin-bottom: 16px; }
label.field > span.lbl {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 7px;
  font-weight: 500;
}

input[type=text], textarea, select {
  width: 100%;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 11px 13px;
  font-size: 14px;
  font-family: inherit;
  transition: border-color .15s, box-shadow .15s;
}
input[type=text]:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(108, 92, 231, .18);
}
textarea { resize: vertical; min-height: 92px; }
input[type=number] {
  width: 100%;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 11px 13px;
  font-size: 14px;
}

.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

.check {
  display: flex; align-items: center; gap: 10px;
  font-size: 14px; cursor: pointer;
}
.check input { width: 18px; height: 18px; accent-color: var(--accent); }

.group-title {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .6px;
  color: var(--muted);
  margin: 18px 0 12px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.model-desc {
  font-size: 13px; color: var(--muted);
  margin: -6px 0 18px; line-height: 1.5;
}

/* Dropzone images de référence */
.dropzone {
  border: 1.5px dashed var(--border);
  border-radius: 11px;
  padding: 18px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.dropzone:hover, .dropzone.over { border-color: var(--accent); background: rgba(108, 92, 231, .06); }

.thumb-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
  gap: 8px;
  margin-top: 10px;
}
.thumb {
  position: relative;
  aspect-ratio: 1;
  border-radius: 9px;
  overflow: hidden;
  border: 1px solid var(--border);
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb.loading img { opacity: .4; }
.thumb.err { border-color: var(--danger); }
.thumb-state {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
}
.thumb-del {
  position: absolute; top: 3px; right: 3px;
  width: 20px; height: 20px; line-height: 1;
  border: none; border-radius: 50%;
  background: rgba(0,0,0,.65); color: #fff;
  cursor: pointer; font-size: 14px;
}

/* Estimation de coût */
.cost-box:not(:empty) {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 11px;
  padding: 14px 16px;
  margin: 4px 0 18px;
}
.cost-main { font-size: 22px; font-weight: 700; color: var(--accent-2); }
.cost-sub { font-size: 13px; color: var(--text); margin-top: 2px; }
.cost-note { font-size: 11px; color: var(--muted); margin-top: 6px; line-height: 1.4; }

button.primary {
  width: 100%;
  background: linear-gradient(135deg, var(--accent), #8d7bff);
  color: #fff;
  border: none;
  border-radius: 11px;
  padding: 14px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: transform .1s, opacity .15s;
}
button.primary:hover { transform: translateY(-1px); }
button.primary:disabled { opacity: .5; cursor: not-allowed; transform: none; }

/* Résultat */
.result { min-height: 320px; display: flex; flex-direction: column; }
.result .placeholder {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  color: var(--muted); text-align: center; gap: 12px;
}
.result .placeholder svg { opacity: .35; }

.status-line {
  display: flex; align-items: center; gap: 12px;
  font-size: 14px; margin-bottom: 16px;
}
.dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--accent-2);
}
.dot.working { background: #f9c846; animation: pulse 1.1s infinite; }
.dot.fail { background: var(--danger); }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .3; } }

.progress-bar {
  height: 6px; background: var(--panel-2); border-radius: 999px;
  overflow: hidden; margin-bottom: 18px;
}
.progress-bar > div {
  height: 100%; width: 0;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width .4s ease;
}

video { width: 100%; border-radius: 12px; background: #000; display: block; }

.actions { display: flex; gap: 10px; margin-top: 14px; flex-wrap: wrap; }
.actions a, .actions button {
  font-size: 13px; text-decoration: none;
  color: var(--text); background: var(--panel-2);
  border: 1px solid var(--border); border-radius: 9px;
  padding: 9px 14px; cursor: pointer;
}
.actions a:hover, .actions button:hover { border-color: var(--accent); }

.error-box {
  background: rgba(255, 92, 122, .08);
  border: 1px solid rgba(255, 92, 122, .3);
  color: #ffb3c2;
  border-radius: 10px; padding: 13px 15px; font-size: 13px;
  line-height: 1.5; word-break: break-word;
}

.meta { font-size: 12px; color: var(--muted); margin-top: 12px; }

.history { margin-top: 20px; }
.history h3 { font-size: 13px; color: var(--muted); margin: 0 0 10px; font-weight: 500; }
.history-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 0; border-top: 1px solid var(--border);
  font-size: 13px;
}
.history-item a { color: var(--accent-2); text-decoration: none; }
.history-item .tag { color: var(--muted); font-size: 11px; }
