/* Thème Theodo. Palette : marine #16243F pour la structure, orange #EF5A2A pour
   le seul chiffre qui compte (temps dans l'étape), gris pour le reste.
   Échelle d'espacement : 4 / 8 / 16 / 24 px. */
:root {
  --navy: #16243F;
  --navy-2: #294F73;
  --orange: #EF5A2A;
  --red: #D92D20;
  --red-light: #FEF3F2;   /* fond des cartes en retard */
  --red-line: #FECDCA;
  --pine: #1E7A4A;   /* vert sapin, texte du bloc QCP */
  --text: #16243F;
  --muted: #667085;
  --line: #D5DCE5;
  --bg: #F5F7FA;
  --subtle: #F0F3F7;
  --surface: #FFFFFF;
  --green: #1F8A5B;
  --s1: 4px; --s2: 8px; --s3: 16px; --s4: 24px;
  --radius: 8px;
  --head-h: 112px;   /* minimum stage header height */
  --gate-h: 144px;   /* minimum checks block height */
}
* { box-sizing: border-box; }
html { height: 100%; }
body {
  margin: 0; min-height: 100%; display: flex; flex-direction: column;
  font-family: "Poppins", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 13px; line-height: 1.4; color: var(--text); background: var(--bg);
}

/* ---- barre de titre ---- */
.topbar {
  display: flex; align-items: baseline; justify-content: space-between;
  padding: var(--s3) var(--s4); background: var(--surface); border-bottom: 1px solid var(--line);
}
.topbar h1 { margin: 0; font-size: 18px; font-weight: 600; display: flex; align-items: center; gap: var(--s2); }
.topbar h1::before { content: ""; width: 10px; height: 10px; border-radius: 2px; background: var(--orange); }
.topbar .titles { display: flex; flex-direction: column; gap: 2px; }
.intent { margin: 0; color: var(--muted); font-size: 13px; padding-left: calc(10px + var(--s2)); }
.topbar .meta { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; }
.owner { color: var(--muted); font-size: 12px; }
.owner b { color: var(--ink, inherit); font-weight: 600; }
.asof { color: var(--muted); font-size: 12px; }

/* ---- grille des étapes ---- */
.board {
  flex: 1; display: grid; align-items: stretch;
  grid-template-columns: repeat(var(--stages), minmax(240px, 1fr));
  /* 4 rows shared by every stage: header / doing / checks / ready. Each row takes the height
     of its tallest content, so long check lists or big teams stay fully visible and aligned. */
  grid-template-rows: auto minmax(160px, 1fr) auto auto;
  gap: var(--s3); padding: var(--s4); overflow-x: auto;
}
.stage {
  display: grid; grid-template-rows: subgrid; grid-row: 1 / span 4;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
}
.stage-head { grid-row: 1; }
.lane.doing { grid-row: 2; }
.gate { grid-row: 3; }
.lane.ready { grid-row: 4; }
/* browsers without subgrid: back to a column, blocks simply grow */
@supports not (grid-template-rows: subgrid) {
  .stage { display: flex; flex-direction: column; }
  .gate { margin-top: auto; }
}

/* en-tête : hauteur fixe pour que toutes les colonnes s'alignent */
.stage-head { min-height: var(--head-h); padding: var(--s3); border-bottom: 1px solid var(--line); }
.stage-head h2 { margin: 0 0 var(--s2); font-size: 15px; font-weight: 600; display: flex; align-items: center; gap: var(--s2); }
.count { font-size: 11px; font-weight: 500; color: var(--muted); background: var(--subtle); border-radius: 999px; padding: 0 var(--s2); }
.team { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: var(--s1); }
.member {
  border-radius: 999px; padding: 2px 10px; font-size: 11px; font-weight: 500;
  line-height: 1.4; background: var(--subtle); color: var(--text);
}
.note { margin: var(--s2) 0 0; font-size: 11px; color: var(--muted); min-height: 15px; }

/* mur de qualité : hauteur fixe, même gris que le reste */
.gate { min-height: var(--gate-h); padding: var(--s3); background: var(--subtle); border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.gate h3, .lane-title {
  margin: 0 0 var(--s2); font-size: 11px; font-weight: 500; color: var(--muted);
  text-transform: uppercase; letter-spacing: .06em;
}
.gate ul { margin: 0; padding: 0; list-style: none; }
.gate li { font-size: 12px; padding-left: var(--s3); position: relative; line-height: 1.6; color: var(--pine); }
.gate li::before { content: "✓"; position: absolute; left: 0; color: var(--pine); font-weight: 600; }
.gate h3 { color: var(--pine); }

/* couloirs */
.lane { padding: var(--s3); }
.lane.doing { flex: 1; }
.lane.ready { min-height: 136px; background: var(--surface); border-radius: 0 0 var(--radius) var(--radius); }

/* cartes */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: var(--s2) 12px; margin-bottom: var(--s2);
}
.card:last-of-type { margin-bottom: 0; }
.card.late { background: var(--red-light); border-color: var(--red-line); }
.card h4 { margin: 0; font-size: 13px; font-weight: 600; }
.client { margin: 0; font-size: 12px; color: var(--muted); }
.tag {
  display: inline-block; margin-top: var(--s1); font-size: 11px; border-radius: 999px;
  padding: 0 var(--s2); background: var(--subtle); color: var(--muted);
}
.meta { margin: var(--s2) 0 0; display: flex; gap: 12px; flex-wrap: wrap; font-size: 12px; color: var(--muted); }
.meta b { font-weight: 600; color: var(--text); }
.meta .col b { color: var(--orange); }
.meta .late b { color: var(--red); }
.card.done .closed { color: var(--green); font-weight: 500; }

.more { margin: var(--s2) 0 0; text-align: center; font-size: 12px; color: var(--muted); }
.legend { padding: var(--s2) var(--s4) var(--s3); font-size: 11px; color: var(--muted); }
.legend b { font-weight: 500; color: var(--text); }

/* ---- page interactive : boutons, glisser-déposer, éditeur ---- */
[hidden] { display: none !important; }   /* wins over display:flex below */
.btn {
  font: inherit; font-size: 12px; font-weight: 500; line-height: 1.4; cursor: pointer;
  padding: 4px 10px; border-radius: 6px; border: 1px solid var(--line); background: var(--surface); color: var(--text);
}
.btn:hover { background: var(--subtle); }
.btn.primary { background: var(--navy); border-color: var(--navy); color: #fff; }
.btn.primary:hover { background: var(--navy-2); }
.btn.danger { color: var(--red); border-color: var(--red-line); }
.btn.danger:hover { background: var(--red-light); }
.toolbar { display: flex; align-items: center; gap: var(--s2); margin-top: var(--s1); }
.dirty { font-size: 11px; color: var(--orange); }
.banner {
  display: flex; align-items: center; gap: var(--s2); flex-wrap: wrap;
  padding: var(--s2) var(--s4); font-size: 12px; background: #FFF7E6; border-bottom: 1px solid #FFE1A6; color: var(--text);
}

.lane-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: var(--s2); }
.lane-head .lane-title { margin: 0; }
.add {
  font: inherit; font-size: 14px; line-height: 1; cursor: pointer; width: 22px; height: 22px;
  border-radius: 6px; border: 1px solid var(--line); background: var(--surface); color: var(--muted);
}
.add:hover { color: var(--navy); border-color: var(--navy-2); }
.cards { min-height: 48px; }
.lane.over .cards { outline: 2px dashed var(--navy-2); outline-offset: 4px; border-radius: var(--radius); }
.card[draggable="true"] { cursor: grab; }
.card.dragging { opacity: .5; }
.more[title] { cursor: pointer; }
.legend #hint b { font-weight: 600; }

dialog#editor { border: 1px solid var(--line); border-radius: var(--radius); padding: var(--s4); width: min(420px, 92vw); font: inherit; color: var(--text); }
dialog#editor::backdrop { background: rgba(22, 36, 63, .35); }
#editor h3 { margin: 0 0 var(--s3); font-size: 15px; font-weight: 600; }
#editor label { display: flex; flex-direction: column; gap: var(--s1); font-size: 12px; color: var(--muted); margin-bottom: var(--s3); }
#editor input { font: inherit; font-size: 13px; color: var(--text); padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; }
#editor input:disabled { background: var(--subtle); color: var(--muted); }
#editor small { font-size: 11px; }
#editor .row { display: flex; gap: var(--s3); }
#editor .row label { flex: 1; }
#editor .actions { display: flex; align-items: center; gap: var(--s2); margin-top: var(--s2); }
#editor .spacer { flex: 1; }

/* ---- mode édition : structure modifiable sur place ---- */
.toolbar { flex-wrap: wrap; justify-content: flex-end; }
.noscript { padding: var(--s4); color: var(--muted); }
.placeholder { color: var(--muted); font-style: italic; font-weight: 400; }
.editing .editable { cursor: text; border-radius: 4px; outline: 1px dashed transparent; outline-offset: 2px; transition: outline-color .15s; }
.editing .editable:hover { outline-color: var(--navy-2); background: var(--subtle); }
input.inline {
  font: inherit; color: inherit; background: var(--surface); border: 1px solid var(--navy-2); border-radius: 4px;
  padding: 1px 6px; min-width: 8ch; width: 100%; max-width: 100%; box-sizing: border-box;
}
.count.editable, .member .editable { display: inline-block; }
.count input.inline { min-width: 5ch; width: 6ch; }
.count.over { background: var(--red-light); color: var(--red); font-weight: 600; }
.x {
  font: inherit; font-size: 12px; line-height: 1; cursor: pointer; margin-left: 4px; padding: 0 3px;
  border: none; background: transparent; color: var(--muted); border-radius: 4px;
}
.x:hover { color: var(--red); background: var(--red-light); }
.member .x { margin-left: 2px; margin-right: -4px; }
.add-item { color: var(--muted); border: 1px dashed var(--line); background: transparent; cursor: text; }
.gate li.add-item { padding-left: var(--s3); }
.gate li.add-item::before { content: "+"; color: var(--muted); }
.gate li .x { vertical-align: middle; }
.stage-tools { margin-top: var(--s2); }
.tool {
  font: inherit; font-size: 11px; cursor: pointer; padding: 2px 8px; border-radius: 6px;
  border: 1px solid var(--red-line); background: transparent; color: var(--red);
}
.tool:hover { background: var(--red-light); }
.handle { cursor: grab; color: var(--muted); font-size: 14px; letter-spacing: -2px; user-select: none; margin-right: 2px; }
.handle:active { cursor: grabbing; }
.stage.dragging { opacity: .5; }
.stage.drop-target { outline: 2px dashed var(--navy-2); outline-offset: 2px; }
.stage.add-stage {
  grid-row: 1 / span 4; display: flex; align-items: center; justify-content: center;
  border-style: dashed; background: transparent; min-height: 200px;
}
.stage-head h2 .name { flex: 1; min-width: 0; }

/* ---- panneaux repliés sous le tableau : journal, texte ---- */
.panel { margin: 0 var(--s4) var(--s3); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.panel .panel-head { display: flex; align-items: center; gap: var(--s3); padding: var(--s2) var(--s3); border-bottom: 1px solid var(--line); }
.panel h3 { margin: 0; font-size: 13px; font-weight: 600; }
.panel .panel-head .muted { flex: 1; }
.panel .panel-body { padding: var(--s2) var(--s3); max-height: 260px; overflow: auto; }
.text-panel .panel-body { max-height: none; display: grid; grid-template-columns: 3fr 2fr; gap: var(--s3); padding: var(--s3); }
.text-body label { display: flex; flex-direction: column; gap: var(--s1); font-size: 11px; font-weight: 500; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; min-width: 0; }
.text-body textarea {
  font: 12px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; color: var(--text); background: var(--bg);
  border: 1px solid var(--line); border-radius: 6px; padding: var(--s2) 10px; min-height: 320px; resize: vertical; white-space: pre; overflow: auto;
}
.text-body textarea:focus { outline: 2px solid var(--navy-2); outline-offset: -1px; background: var(--surface); }
.text-body textarea[readonly] { color: var(--muted); }
.text-error { margin: 0; font-size: 12px; color: var(--red); text-transform: none; letter-spacing: 0; font-weight: 500; }
@media (max-width: 900px) { .text-panel .panel-body { grid-template-columns: 1fr; } }
.status { font-size: 11px; color: var(--muted); }
.status.dirty { color: var(--orange); }
.status.saving { color: var(--muted); }
.status.saved { color: var(--green); }
.status.error { color: var(--red); font-weight: 600; }
.status.readonly { color: var(--muted); border: 1px solid var(--line); border-radius: 999px; padding: 1px 8px; }
.readonly .card[draggable="false"] { cursor: default; }
.history table { width: 100%; border-collapse: collapse; font-size: 12px; }
.history th { text-align: left; font-weight: 500; color: var(--muted); padding: 4px 8px 4px 0; border-bottom: 1px solid var(--line); }
.history td { padding: 4px 8px 4px 0; border-bottom: 1px solid var(--subtle); vertical-align: top; }
.history td.strong { font-weight: 600; }
.muted { color: var(--muted); font-size: 12px; margin: 0; }

/* ---- impression / PDF ---- */
@media print {
  @page { size: landscape; margin: 10mm; }
  body { background: #fff; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .toolbar, .banner, .add, .x, .tool, .handle, .stage-tools, .add-item, .add-stage, .panel, .legend span, dialog { display: none !important; }
  .topbar { border-bottom: 1px solid var(--line); padding: 0 0 var(--s2); }
  .board { padding: var(--s3) 0; gap: var(--s2); overflow: visible; grid-template-columns: repeat(var(--stages), minmax(0, 1fr)); }
  .stage, .card { break-inside: avoid; }
  .card[draggable="true"] { cursor: default; }
  .legend { padding: var(--s2) 0; }
}
