:root {
  --bg: #f4f6f8; --card: #ffffff; --ink: #1c2630; --muted: #5d6b79; --line: #dde3e9;
  --primary: #0b5d8a; --primary-ink: #ffffff; --accent: #0f9d8a;
  --red: #c62828; --red-bg: #fdecea; --orange: #b45309; --orange-bg: #fff4e0;
  --green: #2e7d32; --green-bg: #e8f5e9; --blue-bg: #e3f1fa; --grey-bg: #eceff1;
  --radius: 12px; --shadow: 0 1px 3px rgba(0,0,0,.12);
  --nav-h: 60px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11181f; --card: #1a232c; --ink: #e8edf1; --muted: #9fb0bf; --line: #2c3a46;
    --primary: #4aa8dc; --primary-ink: #06131c; --accent: #3ccbb8;
    --red: #ff8a80; --red-bg: #3a1d1b; --orange: #ffb74d; --orange-bg: #3a2b12;
    --green: #81c784; --green-bg: #17301a; --blue-bg: #14293a; --grey-bg: #25313c;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif; background: var(--bg); color: var(--ink); }
h1 { font-size: 1.35rem; margin: 0 0 .75rem; } h2 { font-size: 1.1rem; margin: 0 0 .6rem; } h3 { font-size: 1rem; margin: .8rem 0 .4rem; }
a { color: var(--primary); }
.boot { text-align: center; padding: 3rem 1rem; color: var(--muted); }
.muted { color: var(--muted); } .small { font-size: .85rem; } .right { text-align: right; }
.hidden, [hidden] { display: none !important; }

/* ---- Structure ---- */
.top { position: sticky; top: 0; z-index: 20; background: var(--primary); color: var(--primary-ink); display: flex; align-items: center; gap: .75rem; padding: .55rem .9rem; padding-top: calc(.55rem + env(safe-area-inset-top)); }
.top .brand { font-weight: 700; flex: 1; line-height: 1.15; }
.top .brand small { display: block; font-weight: 400; opacity: .85; font-size: .72rem; }
.top .who { font-size: .8rem; text-align: right; opacity: .95; }
.top button.link { color: inherit; }
main { max-width: 1100px; margin: 0 auto; padding: .9rem .9rem calc(var(--nav-h) + 1.5rem + env(safe-area-inset-bottom)); }
.nav { position: fixed; bottom: 0; left: 0; right: 0; z-index: 20; display: flex; background: var(--card); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
.nav a { flex: 1; min-height: var(--nav-h); display: flex; flex-direction: column; align-items: center; justify-content: center; text-decoration: none; color: var(--muted); font-size: .72rem; gap: 2px; }
.nav a .ico { font-size: 1.35rem; line-height: 1; }
.nav a.active { color: var(--primary); font-weight: 700; }
.nav a.plus { color: var(--primary-ink); background: var(--accent); margin: 6px; border-radius: 14px; font-weight: 700; }
@media (min-width: 800px) {
  main { padding-bottom: 2rem; }
  .nav { position: static; border: 0; background: transparent; padding: 0; gap: .25rem; }
  .top { flex-wrap: wrap; }
  .nav a { flex-direction: row; min-height: 40px; padding: 0 .9rem; color: var(--primary-ink); opacity: .85; border-radius: 8px; font-size: .95rem; flex: none; }
  .nav a.active { opacity: 1; background: rgba(255,255,255,.18); color: var(--primary-ink); }
  .nav a.plus { margin: 0; background: var(--accent); opacity: 1; }
  .nav a .ico { font-size: 1.05rem; }
  .top .navwrap { order: 3; flex-basis: 100%; }
}
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: .9rem; margin-bottom: .9rem; }
.card > h2:first-child { margin-top: 0; }
.row { display: flex; gap: .6rem; flex-wrap: wrap; align-items: center; }
.row.between { justify-content: space-between; }
.grid2 { display: grid; gap: .6rem; grid-template-columns: 1fr; }
@media (min-width: 640px) { .grid2 { grid-template-columns: 1fr 1fr; } }
.grid3 { display: grid; gap: .6rem; grid-template-columns: 1fr; }
@media (min-width: 800px) { .grid3 { grid-template-columns: 1fr 1fr 1fr; } }

/* ---- Formulaires ---- */
label { display: block; font-weight: 600; font-size: .88rem; margin: .55rem 0 .2rem; }
label .opt { font-weight: 400; color: var(--muted); }
input, select, textarea { width: 100%; min-height: 46px; font: inherit; color: var(--ink); background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: .55rem .7rem; }
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus, button:focus-visible, a:focus-visible { outline: 3px solid color-mix(in srgb, var(--primary) 45%, transparent); outline-offset: 1px; }
input[type=checkbox] { width: 22px; min-height: 22px; height: 22px; accent-color: var(--primary); }
.check { display: flex; align-items: center; gap: .55rem; font-weight: 500; margin: .6rem 0; }
.check input { flex: none; }
button, .btn { font: inherit; font-weight: 600; min-height: 46px; padding: .5rem 1rem; border-radius: 10px; border: 1px solid var(--primary); background: var(--primary); color: var(--primary-ink); cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: .4rem; }
button.secondary, .btn.secondary { background: transparent; color: var(--primary); }
button.danger { background: var(--red); border-color: var(--red); color: #fff; }
button.big { min-height: 56px; font-size: 1.05rem; flex: 1; }
button.small, .btn.small { min-height: 36px; padding: .2rem .65rem; font-size: .85rem; }
button.link { background: none; border: 0; color: var(--primary); min-height: 0; padding: .2rem; text-decoration: underline; font-weight: 500; }
button[disabled] { opacity: .5; cursor: not-allowed; }
.hint { font-size: .82rem; color: var(--muted); margin: .25rem 0; }
.err { color: var(--red); background: var(--red-bg); padding: .5rem .7rem; border-radius: 8px; margin: .5rem 0; }
details > summary { cursor: pointer; font-weight: 600; padding: .4rem 0; min-height: 36px; }

/* ---- Badges / tuiles ---- */
.badge { display: inline-block; padding: .12rem .55rem; border-radius: 999px; font-size: .76rem; font-weight: 700; white-space: nowrap; }
.st-recu { background: var(--grey-bg); color: var(--muted); }
.st-affecte, .st-en_cours { background: var(--blue-bg); color: var(--primary); }
.st-reponse_en_preparation, .st-reponse_validee { background: var(--orange-bg); color: var(--orange); }
.st-reponse_envoyee, .st-cloture { background: var(--green-bg); color: var(--green); }
.st-sans_reponse_requise { background: var(--grey-bg); color: var(--muted); }
.late { background: var(--red-bg); color: var(--red); } .soon { background: var(--orange-bg); color: var(--orange); }
.ok { background: var(--green-bg); color: var(--green); }
.tiles { display: grid; gap: .6rem; grid-template-columns: repeat(2, 1fr); margin-bottom: .9rem; }
@media (max-width: 799px) { .tiles { grid-template-columns: repeat(3, 1fr); gap: .45rem; } .tile { min-height: 74px; padding: .55rem; } .tile .n { font-size: 1.55rem; } .tile .l { font-size: .74rem; } }
@media (min-width: 800px) { .tiles { grid-template-columns: repeat(5, 1fr); } }
.tile { display: block; text-align: left; background: var(--card); color: var(--ink); border: 1px solid var(--line); border-radius: var(--radius); padding: .8rem; min-height: 92px; box-shadow: var(--shadow); text-decoration: none; }
.tile .n { font-size: 2rem; font-weight: 800; line-height: 1.1; display: block; }
.tile .l { font-size: .85rem; color: var(--muted); }
.tile.red { border-color: var(--red); } .tile.red .n { color: var(--red); }
.tile.blue .n { color: var(--primary); } .tile.green .n { color: var(--green); } .tile.orange .n { color: var(--orange); }
.bar { height: 10px; border-radius: 6px; background: var(--grey-bg); overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--primary); }

/* ---- Liste ---- */
.item { display: block; text-decoration: none; color: inherit; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: .75rem .85rem; margin-bottom: .55rem; box-shadow: var(--shadow); }
.item:hover { border-color: var(--primary); }
.item .ref { font-weight: 800; }
.item .obj { margin: .2rem 0; overflow-wrap: anywhere; }
.item .meta { display: flex; gap: .4rem .8rem; flex-wrap: wrap; font-size: .84rem; color: var(--muted); align-items: center; }
table.t { width: 100%; border-collapse: collapse; font-size: .9rem; }
table.t th, table.t td { text-align: left; padding: .45rem .4rem; border-bottom: 1px solid var(--line); vertical-align: top; }
.scroll { overflow-x: auto; }

/* ---- Détail ---- */
dl.kv { display: grid; grid-template-columns: 9.5rem 1fr; gap: .35rem .75rem; margin: 0; }
dl.kv dt { color: var(--muted); font-size: .88rem; } dl.kv dd { margin: 0; overflow-wrap: anywhere; }
@media (max-width: 520px) { dl.kv { grid-template-columns: 1fr; gap: 0; } dl.kv dt { margin-top: .5rem; } }
.docgroup { border-left: 4px solid var(--primary); padding-left: .7rem; margin: .8rem 0; }
.doc { display: flex; gap: .5rem; align-items: center; padding: .45rem 0; border-bottom: 1px dashed var(--line); flex-wrap: wrap; }
.doc .v { font-weight: 800; min-width: 2.2rem; } .doc .info { flex: 1; min-width: 12rem; }
.doc.arch { opacity: .55; text-decoration: line-through; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { padding: .5rem 0 .5rem .9rem; border-left: 3px solid var(--line); margin-left: .3rem; }
.timeline li b { font-size: .88rem; }

/* ---- Capture de pages ---- */
.capture { border: 2px dashed var(--line); border-radius: var(--radius); padding: .8rem; background: color-mix(in srgb, var(--card) 80%, var(--bg)); }
.pages { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: .6rem; margin: .7rem 0; }
.page { border: 1px solid var(--line); border-radius: 10px; background: var(--card); padding: .35rem; text-align: center; }
.page .thumb { width: 100%; aspect-ratio: 3/4; object-fit: cover; border-radius: 6px; background: var(--grey-bg); display: flex; align-items: center; justify-content: center; font-size: 2rem; cursor: zoom-in; overflow: hidden; border: 0; padding: 0; }
.page .thumb img { width: 100%; height: 100%; object-fit: cover; }
.page .nm { font-size: .72rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin: .2rem 0; }
.page .ctl { display: flex; justify-content: space-between; gap: 2px; }
.page .ctl button { min-height: 34px; padding: 0; flex: 1; font-size: 1rem; }

/* ---- Fenêtre modale / toasts / attente ---- */
.modal { position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.6); display: flex; align-items: flex-end; justify-content: center; }
@media (min-width: 800px) { .modal { align-items: center; } }
.modal .box { background: var(--card); width: 100%; max-width: 900px; max-height: 94vh; border-radius: 16px 16px 0 0; display: flex; flex-direction: column; overflow: hidden; }
@media (min-width: 800px) { .modal .box { border-radius: 16px; } }
.modal .bar-top { display: flex; align-items: center; gap: .5rem; padding: .6rem .8rem; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.modal .bar-top b { flex: 1; overflow-wrap: anywhere; }
.modal .body { overflow: auto; padding: .8rem; flex: 1; text-align: center; }
.modal .body img { max-width: 100%; height: auto; }
.modal .body iframe { width: 100%; height: 70vh; border: 0; background: #fff; }
#toasts { position: fixed; left: 0; right: 0; bottom: calc(var(--nav-h) + 12px + env(safe-area-inset-bottom)); z-index: 70; display: flex; flex-direction: column; align-items: center; gap: .4rem; pointer-events: none; padding: 0 .8rem; }
@media (min-width: 800px) { #toasts { bottom: 20px; } }
.toast { background: #25313c; color: #fff; padding: .65rem 1rem; border-radius: 10px; max-width: 560px; box-shadow: 0 4px 14px rgba(0,0,0,.3); pointer-events: auto; }
.toast.error { background: #b71c1c; } .toast.success { background: #1b5e20; }
#busy { position: fixed; inset: 0; z-index: 90; background: rgba(0,0,0,.5); display: flex; flex-direction: column; align-items: center; justify-content: center; color: #fff; gap: .8rem; }
.spinner { width: 44px; height: 44px; border: 5px solid rgba(255,255,255,.35); border-top-color: #fff; border-radius: 50%; animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.login { max-width: 420px; margin: 2rem auto; }
.tabs { display: flex; gap: .3rem; flex-wrap: wrap; margin-bottom: .8rem; }
.tabs button { background: transparent; color: var(--primary); } .tabs button.on { background: var(--primary); color: var(--primary-ink); }

/* ---- Pilotage : alertes, circuit, colonnes ---- */
:root { --c-recu:#78909c; --c-affecte:#1e88e5; --c-en_cours:#0b5d8a; --c-reponse_en_preparation:#f59e0b; --c-reponse_validee:#fb8c00; --c-reponse_envoyee:#43a047; --c-cloture:#2e7d32; --c-sans_reponse_requise:#9e9e9e; }
.chips { display: flex; gap: .45rem; flex-wrap: wrap; margin: .2rem 0 .8rem; }
.chip { display: inline-flex; align-items: center; gap: .35rem; min-height: 38px; padding: .15rem .8rem; border-radius: 999px; border: 1px solid var(--line); background: var(--card); color: var(--ink); text-decoration: none; font-size: .88rem; white-space: nowrap; }
.chip b { font-size: 1rem; } .chip:hover { border-color: var(--primary); }
.chip.on { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
.chip.late { background: var(--red-bg); color: var(--red); border-color: var(--red); } .chip.soon { background: var(--orange-bg); color: var(--orange); border-color: var(--orange); }
.chip.info { background: var(--blue-bg); color: var(--primary); } .chip.zero { color: var(--muted); }
.funnel { list-style: none; margin: .2rem 0 .8rem; padding: 0; display: flex; gap: 2px; flex-wrap: wrap; }
.fstep { flex: 1 1 120px; min-width: 110px; }
.fstep a { display: flex; flex-direction: column; gap: 2px; align-items: flex-start; text-decoration: none; color: var(--ink); background: var(--grey-bg); border-top: 5px solid var(--primary); padding: .5rem .6rem .5rem .7rem; min-height: 86px; clip-path: polygon(0 0, calc(100% - 12px) 0, 100% 50%, calc(100% - 12px) 100%, 0 100%); }
.fstep a:hover { filter: brightness(.96); }
.fl { font-size: .74rem; color: var(--muted); line-height: 1.15; } .fn { font-size: 1.6rem; font-weight: 800; line-height: 1.1; } .fsp { min-height: 1.2rem; }
.fs-recu a { border-color: var(--c-recu); } .fs-affecte a { border-color: var(--c-affecte); } .fs-en_cours a { border-color: var(--c-en_cours); }
.fs-reponse_en_preparation a { border-color: var(--c-reponse_en_preparation); } .fs-reponse_validee a { border-color: var(--c-reponse_validee); }
.fs-reponse_envoyee a { border-color: var(--c-reponse_envoyee); } .fs-cloture a { border-color: var(--c-cloture); }
.board { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(250px, 1fr); gap: .7rem; overflow-x: auto; padding-bottom: .6rem; scroll-snap-type: x proximity; }
.col { background: color-mix(in srgb, var(--bg) 70%, var(--card)); border: 1px solid var(--line); border-top: 5px solid var(--primary); border-radius: 10px; padding: .5rem; scroll-snap-align: start; min-width: 250px; }
.col-recu { border-top-color: var(--c-recu); } .col-affecte { border-top-color: var(--c-affecte); } .col-en_cours { border-top-color: var(--c-en_cours); }
.col-reponse_en_preparation { border-top-color: var(--c-reponse_en_preparation); } .col-reponse_validee { border-top-color: var(--c-reponse_validee); }
.col-reponse_envoyee { border-top-color: var(--c-reponse_envoyee); } .col-cloture { border-top-color: var(--c-cloture); } .col-sans_reponse_requise { border-top-color: var(--c-sans_reponse_requise); }
.col header { margin-bottom: .5rem; } .col .ct { font-weight: 700; font-size: .92rem; } .col .cn { font-size: 1.8rem; font-weight: 800; line-height: 1.1; }
.col .cb { display: flex; gap: .3rem; flex-wrap: wrap; align-items: center; margin-top: .35rem; min-height: 1.4rem; }
.bar.red > i { background: var(--red); } .bar.orange > i { background: var(--orange); }
.mc { display: block; text-decoration: none; color: inherit; background: var(--card); border: 1px solid var(--line); border-left: 4px solid var(--line); border-radius: 8px; padding: .5rem .6rem; margin-bottom: .45rem; font-size: .85rem; }
.mc:hover { border-color: var(--primary); } .mc-late { border-left-color: var(--red); }
.mc .mo { margin: .2rem 0; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow-wrap: anywhere; }
.mc .meta { display: flex; gap: .2rem .6rem; flex-wrap: wrap; font-size: .76rem; color: var(--muted); }
.col .more { display: block; text-align: center; padding: .45rem; font-weight: 600; font-size: .85rem; } .col .empty { text-align: center; padding: 1rem 0; }
table.matrix th.num, table.matrix td.num { text-align: center; } table.matrix thead th { font-size: .78rem; vertical-align: bottom; }
table.matrix tbody th { font-weight: 600; text-align: left; white-space: nowrap; }
a.cell { display: inline-block; min-width: 2rem; padding: .15rem .35rem; border-radius: 6px; background: var(--blue-bg); color: var(--primary); text-decoration: none; font-weight: 700; }
a.badge { text-decoration: none; }
.hb { display: grid; grid-template-columns: 8.5rem 1fr 2.2rem; gap: .5rem; align-items: center; margin: .4rem 0; font-size: .88rem; } .hb .hv { text-align: right; }
.kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: .5rem; } .kpis .kn { display: block; font-size: 1.5rem; font-weight: 800; color: var(--primary); } .kpis .l { font-size: .78rem; color: var(--muted); }
.flux { display: grid; grid-template-columns: repeat(6, 1fr); gap: .4rem; align-items: end; } .fm { text-align: center; font-size: .72rem; }
.fb { height: 90px; display: flex; gap: 3px; align-items: flex-end; justify-content: center; } .fb i { display: block; width: 40%; max-width: 22px; min-height: 2px; border-radius: 3px 3px 0 0; }
.in { background: var(--primary); } .out { background: var(--accent); } .dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; vertical-align: middle; } .fm .fv { display: block; color: var(--muted); }

/* ---- Liste dense ---- */
.item.head { display: none; }
.item { display: grid; grid-template-columns: 1fr auto; grid-template-areas: "ref stage" "obj obj" "due resp" "doc doc"; gap: .25rem .6rem; align-items: center; }
.item.is-late { border-left: 4px solid var(--red); }
.c-ref { grid-area: ref; display: flex; flex-direction: column; } .c-obj { grid-area: obj; overflow-wrap: anywhere; } .c-resp { grid-area: resp; text-align: right; font-size: .84rem; color: var(--muted); }
.c-stage { grid-area: stage; display: flex; gap: .4rem; align-items: center; justify-content: flex-end; } .c-due { grid-area: due; } .c-doc { grid-area: doc; font-size: .8rem; color: var(--muted); }
.pager { display: flex; gap: .6rem; align-items: center; justify-content: space-between; flex-wrap: wrap; margin: .5rem 0; }
@media (min-width: 900px) {
  .item, .item.head { display: grid; grid-template-columns: 9.5rem minmax(0, 1fr) 10rem 12rem 11.5rem 3.5rem; grid-template-areas: "ref obj resp stage due doc"; gap: .6rem; padding: .55rem .8rem; border-radius: 8px; margin-bottom: .3rem; }
  .item.head { background: transparent; border: 0; box-shadow: none; font-size: .76rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 700; margin-bottom: 0; padding-bottom: 0; }
  .item.head span:nth-child(n) { grid-area: auto; }
  .c-resp { text-align: left; } .c-stage { justify-content: flex-start; } .c-obj { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; } .c-doc { text-align: right; }
}

/* ---- Fiche : tracé du circuit ---- */
.stepper { list-style: none; margin: .4rem 0; padding: 0; display: grid; gap: 0; grid-template-columns: 1fr; }
.step { display: grid; grid-template-columns: 1.7rem 1fr auto auto; gap: .1rem .5rem; align-items: center; padding: .35rem 0; border-left: 3px solid var(--line); padding-left: .5rem; margin-left: .6rem; position: relative; }
.step .dotc { width: 1.5rem; height: 1.5rem; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; font-size: .8rem; background: var(--grey-bg); color: var(--muted); margin-left: -1.65rem; border: 2px solid var(--card); }
.step.done { border-left-color: var(--green); } .step.done .dotc { background: var(--green); color: #fff; }
.step.now { border-left-color: var(--primary); font-weight: 700; } .step.now .dotc { background: var(--primary); color: var(--primary-ink); box-shadow: 0 0 0 4px color-mix(in srgb, var(--primary) 25%, transparent); }
.step.now.late { border-left-color: var(--red); } .step.now.late .dotc { background: var(--red); }
.step.todo { color: var(--muted); } .step .sd, .step .sj { font-size: .78rem; color: var(--muted); font-weight: 400; }
@media (min-width: 800px) {
  .stepper { grid-template-columns: repeat(7, 1fr); gap: .3rem; margin-top: 1rem; }
  .step { grid-template-columns: 1fr; border-left: 0; border-top: 4px solid var(--line); margin: 0; padding: .45rem .3rem 0; text-align: center; justify-items: center; }
  .step .dotc { margin: -1.4rem 0 .15rem; } .step.done { border-top-color: var(--green); } .step.now { border-top-color: var(--primary); } .step.now.late { border-top-color: var(--red); }
}
@media print { .top, .nav, #toasts { display: none !important; } main { padding: 0; } }
