/* Thème : « auto » suit le système, data-theme (posé par theme.js) force clair ou sombre.
   Chaque couleur est donnée sous la forme light-dark(clair, sombre). */
:root {
  --bg: light-dark(#f5f6f8, #11151c);
  --surface: light-dark(#ffffff, #1a1f28);
  --surface-2: light-dark(#f0f2f5, #222833);
  --text: light-dark(#1b2230, #e5e8ee);
  --muted: light-dark(#5d6779, #9aa3b3);
  --border: light-dark(#dce0e6, #2d3441);
  --accent: light-dark(#2459d6, #6b93ff);
  --accent-text: light-dark(#ffffff, #0d1320);
  --ok: light-dark(#1d8348, #4cc27e);
  --ko: light-dark(#c4352d, #f0716a);
  --on-status: light-dark(#ffffff, #0d1320);
  --run: light-dark(#2459d6, #6b93ff);
  --skip: light-dark(#7b8494, #8b94a4);
  --warn: light-dark(#9a6200, #e8b04b);
  --warn-bg: light-dark(#fff4dc, #3a2f17);
  --code-bg: light-dark(#f3f5f8, #141920);
  --radius: 8px;
  --mono: ui-monospace, "Cascadia Code", "SFMono-Regular", Consolas, monospace;
  color-scheme: light dark;
}
:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"] { color-scheme: dark; }

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

a { color: var(--accent); }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5rem; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .75rem; }

.muted { color: var(--muted); }
.small { font-size: .85rem; }
.text { white-space: pre-wrap; overflow-wrap: anywhere; }
.error { color: var(--ko); font-weight: 500; }
.hint { color: var(--muted); }
.warn {
  background: var(--warn-bg);
  color: var(--warn);
  border-radius: var(--radius);
  padding: .5rem .75rem;
}
.t-ko { color: var(--ko); font-weight: 600; }

/* --- Structure ------------------------------------------------------------ */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: .6rem 1rem;
  padding-top: calc(.6rem + env(safe-area-inset-top, 0px));
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; font-size: 1.1rem; color: var(--text); text-decoration: none; }
.brand::before { content: "✔"; color: var(--accent); margin-right: .4rem; }
.topbar .spacer { flex: 1; }
.who { display: flex; align-items: center; gap: .5rem; }
.theme-select { width: auto; font-size: .85rem; padding: .25rem .5rem; background: var(--surface-2); cursor: pointer; }

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.25rem 1rem 3rem;
}

.card, .panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1.5rem;
}
.card.narrow { max-width: 520px; margin: 3rem auto; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; flex-wrap: wrap; }
.section-title { margin-top: .5rem; }
.group-title { margin: 1.25rem 0 .5rem; font-size: .95rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.row { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.empty { color: var(--muted); padding: 2rem; text-align: center; border: 1px dashed var(--border); border-radius: var(--radius); }

/* --- Formulaires ---------------------------------------------------------- */

label { display: block; font-weight: 600; font-size: .9rem; margin: .75rem 0 .3rem; }
input, textarea, select {
  font: inherit;
  color: inherit;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .5rem .65rem;
  width: 100%;
}
.row input { flex: 1; min-width: 0; width: auto; }
textarea { resize: vertical; }
textarea[data-draft="paste"] { font-family: var(--mono); font-size: .85rem; margin: .5rem 0; }
input:focus-visible, textarea:focus-visible, select:focus-visible, button:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

button, .button {
  font: inherit;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  padding: .5rem .9rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}
button:hover, .button:hover { filter: brightness(.96); }
button:disabled { opacity: .55; cursor: progress; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
button.ok { background: var(--ok); border-color: var(--ok); color: var(--on-status); }
button.ko { background: var(--ko); border-color: var(--ko); color: var(--on-status); }
.ghost { background: transparent; }
.ghost.danger { color: var(--ko); border-color: transparent; }
button.small { font-size: .8rem; padding: .2rem .5rem; }

.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .25rem;
  padding: 2rem 1rem;
  margin: 0 0 .75rem;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  font-weight: 400;
  text-align: center;
}
.dropzone:hover, .dropzone.over { border-color: var(--accent); background: var(--surface-2); }
.dropzone input { display: none; }
details > summary { cursor: pointer; color: var(--muted); }

/* --- Badges et progression ------------------------------------------------ */

.badge {
  display: inline-block;
  font-size: .78rem;
  font-weight: 600;
  padding: .1rem .55rem;
  border-radius: 999px;
  border: 1px solid currentColor;
  white-space: nowrap;
}
.s-a_faire, .o-non_demarree { color: var(--muted); }
.s-en_cours, .o-en_cours { color: var(--run); }
.s-ok, .r-reussite, .o-terminee { color: var(--ok); }
.s-ko, .r-echec { color: var(--ko); }
.s-ignoree { color: var(--skip); }
.r-reussite_partielle, .r-retour_arriere { color: var(--warn); }

.progress {
  display: flex;
  height: 8px;
  border-radius: 999px;
  background: var(--surface-2);
  overflow: hidden;
  margin: .5rem 0 .25rem;
}
.progress .seg { display: block; height: 100%; }
.seg.s-ok { background: var(--ok); }
.seg.s-ko { background: var(--ko); }
.seg.s-ignoree { background: var(--skip); }
.seg.s-en_cours { background: var(--run); opacity: .5; }

/* --- Accueil -------------------------------------------------------------- */

.meta { display: flex; flex-wrap: wrap; gap: .25rem 1.25rem; color: var(--muted); font-size: .9rem; }
.meta strong { color: var(--text); font-weight: 500; }

.preview h3 { font-size: 1.15rem; }
.preview-tasks { margin: .5rem 0 1rem; padding-left: 1.5rem; }

.op-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 1rem; }
.op-card {
  display: block;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  color: inherit;
  text-decoration: none;
}
.op-card:hover { border-color: var(--accent); }
.op-card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: .75rem; margin-bottom: .35rem; }
.op-card .meta { font-size: .85rem; margin: 0; }
.op-card p.small { margin: 0; }

/* --- Opération ------------------------------------------------------------ */

.op-head { margin-bottom: 1rem; }
.back { display: inline-block; margin-bottom: .5rem; text-decoration: none; }
.op-title { display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; }
.op-title h1 { margin: 0; }
.op-progress { max-width: 520px; margin: .25rem 0 .75rem; }
.op-actions .button { padding: .5rem .9rem; }

.banner {
  background: var(--warn-bg);
  color: var(--warn);
  padding: .5rem .75rem;
  border-radius: var(--radius);
}

.intro {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .75rem 1rem;
  margin-bottom: 1rem;
}
.intro[open] > summary { margin-bottom: .75rem; }

.layout { display: grid; grid-template-columns: minmax(260px, 340px) 1fr; gap: 1rem; align-items: start; }
.layout .panel { margin: 0; min-width: 0; }

.task-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  position: sticky;
  top: 4rem;
  max-height: calc(100vh - 5rem);
  overflow-y: auto;
}
.task-item {
  display: grid;
  grid-template-columns: 1.4rem 1.6rem 1fr;
  grid-template-areas: "icon num title" ". . who";
  align-items: start;
  text-align: left;
  white-space: normal;
  gap: 0 .25rem;
  padding: .55rem .6rem;
  background: var(--surface);
  border: 1px solid transparent;
  border-left: 3px solid transparent;
  color: var(--text);
}
.task-item:hover { border-color: var(--border); filter: none; }
.task-item.selected { border-color: var(--accent); border-left-color: var(--accent); background: var(--surface); }
.task-item.mine .ti-num { background: var(--accent); color: var(--accent-text); }
.ti-icon { grid-area: icon; font-weight: 700; }
.task-item.s-a_faire .ti-icon { color: var(--muted); }
.task-item.s-en_cours .ti-icon { color: var(--run); }
.task-item.s-ok .ti-icon { color: var(--ok); }
.task-item.s-ko .ti-icon { color: var(--ko); }
.task-item.s-ignoree .ti-icon { color: var(--skip); }
.task-item.s-ok .ti-title, .task-item.s-ignoree .ti-title { color: var(--muted); }
.task-item.s-ignoree .ti-title { text-decoration: line-through; }
.ti-num {
  grid-area: num;
  font-size: .75rem;
  font-weight: 600;
  text-align: center;
  border-radius: 4px;
  background: var(--surface-2);
  color: var(--muted);
  margin-top: .1rem;
}
.ti-title { grid-area: title; }
.ti-who { grid-area: who; font-size: .8rem; color: var(--text); }

.detail-head { border-bottom: 1px solid var(--border); margin-bottom: 1rem; padding-bottom: .5rem; }
.detail-head h2 { font-size: 1.35rem; margin: .15rem 0 .4rem; }
.detail-head p { margin: 0; display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }

.content { margin-bottom: 1rem; }
.code { border: 1px solid var(--border); border-radius: var(--radius); margin: 0 0 .75rem; background: var(--code-bg); }
.code-bar { display: flex; justify-content: space-between; align-items: center; padding: .2rem .4rem .2rem .75rem; border-bottom: 1px solid var(--border); font-size: .75rem; color: var(--muted); }
.code pre { margin: 0; padding: .75rem; overflow-x: auto; font: .85rem/1.5 var(--mono); }

.expected, .outcome {
  border-left: 3px solid var(--accent);
  background: var(--surface-2);
  padding: .5rem .75rem;
  border-radius: 0 var(--radius) var(--radius) 0;
  margin-bottom: 1rem;
}
.expected strong, .outcome strong { font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.expected p, .outcome p { margin: .15rem 0 0; color: var(--text); }
.outcome.s-ok { border-left-color: var(--ok); }
.outcome.s-ko { border-left-color: var(--ko); }
.outcome.s-ignoree { border-left-color: var(--skip); }

.task-actions { margin-bottom: 1.25rem; }
.task-actions .row { margin-top: .75rem; }
.task-actions textarea { margin-bottom: 0; }

.notes { border-top: 1px solid var(--border); padding-top: 1rem; }
.notes ul { list-style: none; padding: 0; margin: 0 0 .75rem; }
.notes li { padding: .4rem 0; border-bottom: 1px dashed var(--border); }
.notes li p { margin: .1rem 0 0; }
.note-form { display: flex; gap: .5rem; align-items: flex-start; }

.panel select { margin-bottom: .25rem; }
.panel > .row { margin-top: 1rem; }

.journal {
  margin-top: 1.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .75rem 1rem;
}
.journal ol { list-style: none; padding: 0; margin: .75rem 0 0; max-height: 360px; overflow-y: auto; }
.journal li { padding: .3rem 0; border-bottom: 1px solid var(--border); font-size: .9rem; }
.journal time { font-family: var(--mono); color: var(--muted); margin-right: .5rem; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(1.25rem + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  max-width: min(560px, calc(100vw - 2rem));
  padding: .7rem 1rem;
  border-radius: var(--radius);
  background: var(--text);
  color: var(--bg);
  box-shadow: 0 6px 24px rgb(0 0 0 / .25);
  z-index: 20;
}
.toast.error { background: var(--ko); color: var(--on-status); }

[hidden] { display: none !important; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .task-list { position: static; max-height: none; }
  .layout .panel { order: -1; }
  .note-form { flex-direction: column; align-items: stretch; }
  .op-grid { grid-template-columns: 1fr; }
}
