/* ============================================================
   Atelier Truby · système de design "régie de l'histoire"
   Palette : salle de montage nuit + papier chaud + lampe ambre
   ============================================================ */

:root {
  /* fond & surfaces */
  --bg: #14161A;
  --panel: #1D212A;
  --panel-2: #252B36;
  --line: #333A47;
  --line-soft: #2A303C;

  /* texte */
  --text: #EAE5DA;
  --muted: #98A0AC;

  /* accents */
  --amber: #E0A33E;
  --amber-soft: rgba(224, 163, 62, 0.13);
  --green: #79B07F;
  --red: #C25550;

  /* typographie */
  --font-display: Georgia, 'Times New Roman', serif;
  --font-body: 'Segoe UI', system-ui, -apple-system, sans-serif;
  --font-mono: Consolas, 'Cascadia Mono', 'Roboto Mono', monospace;

  --radius: 6px;
  --sidebar-w: 302px;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 14.5px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* ---------- Barre du haut ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  height: 58px;
  padding: 0 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}

.brand { display: flex; align-items: baseline; gap: 10px; min-width: 0; }

.brand-mark {
  font-family: var(--font-display);
  font-size: 20px;
  line-height: 1;
  color: var(--amber);
  border: 1px solid var(--amber);
  border-radius: 4px;
  padding: 3px 6px;
  letter-spacing: 1px;
}

.brand-name {
  font-family: var(--font-display);
  font-size: 17px;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.brand-sub {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.topbar-tools { display: flex; align-items: center; gap: 8px; min-width: 0; }

.title-input {
  width: 240px;
  background: transparent;
  border: 1px solid transparent;
  border-bottom-color: var(--line);
  color: var(--text);
  font-family: var(--font-display);
  font-size: 15px;
  padding: 6px 8px;
  outline: none;
}
.title-input:focus { border-bottom-color: var(--amber); }
.title-input::placeholder { color: var(--muted); font-style: italic; }

.project-select {
  width: 190px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 13px;
  padding: 6px 8px;
  outline: none;
  cursor: pointer;
}
.project-select:focus { border-color: var(--amber); }

.save-status { font-family: var(--font-mono); font-size: 11px; color: var(--muted); white-space: nowrap; }
.save-status[data-state="saving"] { color: var(--amber); }
.save-status[data-state="saved"]  { color: var(--green); }
.save-status[data-state="offline"]{ color: var(--red); }
.save-status[data-state="idle"]   { color: var(--muted); }
.save-status[data-state="error"]  { color: var(--red); }

/* ---------- Boutons ---------- */
.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 13px;
  line-height: 1;
  padding: 8px 14px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color .15s, background .15s, color .15s;
  white-space: nowrap;
}
.btn:hover { border-color: var(--amber); color: var(--amber); }
.btn:disabled { opacity: .45; cursor: default; }

.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { color: var(--amber); border-color: transparent; background: var(--panel-2); }

.btn-primary {
  background: var(--amber);
  border-color: var(--amber);
  color: #1B160C;
  font-weight: 600;
}
.btn-primary:hover { background: #EDB45C; border-color: #EDB45C; color: #1B160C; }

.btn-danger { color: var(--red); background: transparent; border-color: transparent; }
.btn-danger:hover { border-color: var(--red); color: var(--red); background: rgba(194,85,80,.08); }

.btn-small { padding: 5px 10px; font-size: 12px; }

.btn-menu { display: none; font-size: 16px; line-height: 1; padding: 6px 9px; }

/* Actions d'export, épinglées en bas du tiroir latéral (tous écrans) */
.sidebar-actions {
  margin-top: auto;
  padding: 14px 12px;
  border-top: 1px solid var(--line);
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.sidebar-actions .btn { flex: 1 1 0; padding: 7px 6px; font-size: 12.5px; }

/* ---------- Structure ---------- */
.shell {
  display: flex;
  flex: 1 1 auto;
  min-height: 0;
}

.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: var(--panel);
  border-right: 1px solid var(--line);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  padding-bottom: 40px;
}

.main {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 28px 40px 80px;
  max-width: 980px;
  outline: none;
}

/* ---------- Navigation des étapes ---------- */
.stage-nav { padding: 14px 12px 6px; border-bottom: 1px solid var(--line); }

.stage-nav-label {
  font-family: var(--font-mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--muted);
  margin: 0 8px 8px;
}

.stage-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 10px;
  margin: 2px 0;
  border: none;
  border-radius: var(--radius);
  background: transparent;
  color: var(--muted);
  font-family: var(--font-body);
  font-size: 13.5px;
  text-align: left;
  cursor: pointer;
  transition: background .12s, color .12s;
}
.stage-item:hover { background: var(--panel-2); color: var(--text); }
.stage-item.active { background: var(--amber-soft); color: var(--amber); }

.stage-num {
  font-family: var(--font-mono);
  font-size: 11px;
  width: 18px;
  text-align: right;
  opacity: .7;
}
.stage-item.active .stage-num { opacity: 1; }

.stage-name { flex: 1 1 auto; }

.stage-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  border: 1px solid var(--line);
  flex: 0 0 auto;
}
.stage-item.done .stage-dot { border-color: var(--green); background: var(--green); }

/* ---------- Cases Truby (panneau couverture) ---------- */
.coverage { padding: 14px 12px 0; }

.coverage-title {
  font-family: var(--font-display);
  font-size: 14px;
  margin: 0 8px 10px;
  color: var(--text);
  display: flex;
  align-items: baseline;
  justify-content: space-between;
}
.coverage-title .cov-count { font-family: var(--font-mono); font-size: 12px; color: var(--amber); }

.cov-groups { display: flex; flex-direction: column; gap: 8px; }

.cov-group { padding: 0 8px; }

.cov-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
}
.cov-row .cov-label { flex: 1 1 auto; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cov-row .cov-num { font-family: var(--font-mono); font-size: 11px; color: var(--muted); }
.cov-row.ok .cov-label { color: var(--green); }

.cov-bar {
  height: 3px;
  border-radius: 2px;
  background: var(--line-soft);
  overflow: hidden;
  margin-top: 3px;
}
.cov-bar > i {
  display: block;
  height: 100%;
  background: var(--amber);
  transition: width .25s ease;
}
.cov-bar.ok > i { background: var(--green); }

/* grille des 22 steps */
.cov-steps {
  margin-top: 12px;
  border-top: 1px solid var(--line);
  padding-top: 10px;
}
.cov-steps-label {
  font-family: var(--font-mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--muted);
  margin: 0 8px 8px;
}
.cov-step-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 12px;
  color: var(--muted);
}
.cov-step-row.is-on { color: var(--text); }
.cov-step-row .n { font-family: var(--font-mono); font-size: 10px; color: var(--muted); width: 18px; text-align: right; }
.cov-step-row .tick { color: var(--green); width: 12px; text-align: center; font-size: 11px; }

.cov-anchored { margin-top: 10px; }
.cov-anchored .anchored-dots { display: flex; flex-wrap: wrap; gap: 3px; padding: 0 8px; }
.cov-anchored .adot {
  width: 8px; height: 8px; border-radius: 2px;
  background: var(--line-soft);
  cursor: help;
}
.cov-anchored .adot.is-on { background: var(--green); }

/* ---------- Zone centrale ---------- */
.stage-head { margin-bottom: 22px; }
.stage-head h2 {
  font-family: var(--font-display);
  font-size: 24px;
  font-weight: 500;
  margin: 0 0 6px;
  letter-spacing: 0.01em;
}
.stage-head p { margin: 0; color: var(--muted); max-width: 60ch; }
.stage-head .progress-line {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--amber);
  margin-top: 10px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px 22px;
  margin-bottom: 18px;
}
.panel h3 {
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 500;
  margin: 0 0 4px;
}
.panel .panel-sub { color: var(--muted); font-size: 13px; margin: 0 0 14px; }

/* ---------- Champs ---------- */
.field { margin-bottom: 14px; }
.field label {
  display: block;
  font-family: var(--font-mono);
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
  margin-bottom: 5px;
}
.field .hint { font-family: var(--font-body); text-transform: none; letter-spacing: 0; font-size: 12px; color: var(--muted); font-style: italic; }

input[type="text"], input[type="number"], textarea, select {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 14px;
  padding: 8px 10px;
  outline: none;
  transition: border-color .12s;
}
input:focus, textarea:focus, select:focus { border-color: var(--amber); }
textarea { resize: vertical; min-height: 54px; line-height: 1.5; }
select { cursor: pointer; }

.row { display: flex; gap: 14px; }
.row > * { flex: 1 1 auto; }

.grow { flex: 1 1 auto; }

.actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 6px; }

/* ---------- Variantes de prémisse ---------- */
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 14px 0 4px; }
.chip {
  font-family: var(--font-mono);
  font-size: 11px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  border-radius: 999px;
  padding: 4px 10px;
  cursor: pointer;
}
.chip:hover { border-color: var(--amber); color: var(--amber); }
.chip.is-on { border-color: var(--amber); color: var(--amber); background: var(--amber-soft); }

.variant {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 10px;
  transition: border-color .12s;
}
.variant:hover { border-color: var(--line); }
.variant.is-fav { border-color: var(--amber); }
.variant.is-retained { border-left: 3px solid var(--green); }

.variant-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 8px; }

.tag {
  font-family: var(--font-mono);
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--amber);
  border: 1px solid var(--amber-soft);
  background: var(--amber-soft);
  padding: 2px 8px;
  border-radius: 3px;
}

.variant-actions { display: flex; align-items: center; gap: 6px; }
.fav-btn {
  border: none; background: none; cursor: pointer;
  font-size: 15px; color: var(--muted); line-height: 1; padding: 4px 6px;
}
.fav-btn.is-fav { color: var(--amber); }
.fav-btn:hover { color: var(--amber); }

.variant-logline { margin: 0 0 6px; font-family: var(--font-display); font-size: 14.5px; line-height: 1.45; }
.variant-why { margin: 0; font-size: 12.5px; color: var(--muted); }

/* check high concept */
.hc-check { display: flex; gap: 12px; margin-top: 4px; flex-wrap: wrap; }
.hc-check span { font-family: var(--font-mono); font-size: 11px; color: var(--muted); }
.hc-check span.ok { color: var(--green); }
.hc-check span.no { color: var(--muted); text-decoration: line-through; opacity: .7; }

/* ---------- Personnages ---------- */
.char-block { border-top: 1px solid var(--line-soft); padding-top: 14px; margin-top: 4px; }
.char-block h3 { font-family: var(--font-display); font-size: 14px; margin: 0 0 12px; }
.char-block h3 small { color: var(--muted); font-family: var(--font-body); font-size: 12px; font-weight: 400; display: block; margin-top: 2px; }

.web-row { display: flex; gap: 10px; margin-bottom: 8px; align-items: center; }

/* ---------- Steps ---------- */
.step {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 10px;
}
.step.is-answered { border-left: 3px solid var(--green); }

.step-head { display: flex; gap: 12px; align-items: flex-start; margin-bottom: 10px; }
.step-num {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--amber);
  padding-top: 3px;
}
.step-body { flex: 1 1 auto; }
.step-body h3 { font-family: var(--font-display); font-size: 14.5px; margin: 0 0 2px; font-weight: 500; }
.step-q { margin: 0; font-size: 12.5px; color: var(--muted); }
.step-time { font-family: var(--font-mono); font-size: 10.5px; color: var(--muted); margin-top: 4px; }
.step-check { color: var(--green); font-size: 13px; padding-top: 2px; }

/* ---------- Scènes ---------- */
.scene {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
  margin-bottom: 14px;
}
.scene.is-ok { border-left: 3px solid var(--green); }

.scene-head { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.tc {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--amber);
  background: var(--amber-soft);
  padding: 3px 8px;
  border-radius: 3px;
  white-space: nowrap;
}

/* repères jo-ha-kyū (mode manga) */
.jh {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 2px 7px;
  white-space: nowrap;
}
.jh.is-kyu { color: var(--amber); border-color: var(--amber-soft); }
.scene-title {
  font-family: var(--font-display);
  font-size: 15px;
  background: transparent;
  border: none;
  border-bottom: 1px solid transparent;
  color: var(--text);
  flex: 1 1 auto;
  padding: 2px 4px;
  outline: none;
}
.scene-title:focus { border-bottom-color: var(--amber); }

.scene-steps { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-top: 10px; }
.scene-steps .label { font-family: var(--font-mono); font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin-right: 4px; }
.step-chip {
  font-family: var(--font-mono);
  font-size: 11px;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: var(--panel-2);
  color: var(--text);
  padding: 2px 7px;
  cursor: pointer;
}
.step-chip:hover { border-color: var(--red); color: var(--red); text-decoration: line-through; }
.step-chip-add { border-style: dashed; color: var(--muted); width: auto; }

.total-line { font-family: var(--font-mono); font-size: 12px; color: var(--muted); margin: 4px 2px 14px; }
.total-line .t { color: var(--amber); }
.total-line.warn { color: var(--red); }
.total-line.warn .t { color: var(--red); }

/* ---------- Dialogues ---------- */
.dialogue {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 10px;
}
.dialogue-meta { display: flex; gap: 8px; margin-bottom: 8px; }
.dialogue-meta input { flex: 1 1 auto; }
.dialogue-meta input:first-child { flex: 0 0 160px; font-weight: 600; }
.dialogue-meta input:nth-child(2) { flex: 0 0 200px; font-style: italic; color: var(--muted); }
.dialogue textarea { min-height: 42px; }

.scene-mini { margin-bottom: 18px; }
.scene-mini .mini-head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.scene-mini .mini-action {
  font-size: 12.5px; color: var(--muted); font-style: italic;
  margin: 0 0 10px; padding-left: 4px; white-space: pre-wrap;
}

.tips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 16px; }
.tip {
  font-size: 12px; color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: 999px; padding: 4px 10px;
}

/* ---------- Divers ---------- */
.empty-cta {
  text-align: center;
  padding: 46px 20px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  background: var(--panel);
}
.empty-cta .big { font-family: var(--font-display); font-size: 19px; margin: 0 0 8px; }
.empty-cta p { color: var(--muted); margin: 0 0 18px; max-width: 48ch; margin-left: auto; margin-right: auto; }

.toast {
  position: fixed;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-left: 3px solid var(--amber);
  color: var(--text);
  font-size: 13px;
  padding: 10px 16px;
  border-radius: var(--radius);
  box-shadow: 0 6px 24px rgba(0,0,0,.45);
  z-index: 50;
  max-width: 480px;
}
.toast[data-kind="error"] { border-left-color: var(--red); }
.toast[data-kind="ok"] { border-left-color: var(--green); }

.main > section { animation: rise .22s ease both; }
@keyframes rise {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: none; }
}

:focus-visible { outline: 2px solid var(--amber); outline-offset: 2px; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--line); border-radius: 5px; }
::-webkit-scrollbar-track { background: transparent; }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

@media (max-width: 900px) {
  .sidebar { position: fixed; inset: 58px auto 0 0; z-index: 20; transform: translateX(-100%); transition: transform .2s ease; }
  .app.sidebar-open .sidebar { transform: none; box-shadow: 8px 0 28px rgba(0,0,0,.5); }
  .btn-menu { display: inline-block; }
  .main { padding: 20px 18px 80px; }
  /* le titre prend tout l'espace disponible : plus jamais écrasé */
  .title-input { flex: 1 1 auto; min-width: 0; width: auto; }
  .project-select { width: auto; max-width: 150px; }
  .brand-name, .brand-sub { display: none; }
}
