:root {
  --fond: #f4f5f8;
  --carte: #ffffff;
  --texte: #1c2233;
  --doux: #5f6779;
  --bord: #dde1e8;
  --accent: #2f5bb7;
  --accent-texte: #ffffff;
  --entete: #1d2b4f;
  --alerte: #c0392b;
  --alerte-fond: #fdecea;
  --ok: #1e7d4f;
  --aujourdhui: #fff6d6;
  --vide: #eceef2;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --fond: #11151f;
    --carte: #1a2030;
    --texte: #e6e9f0;
    --doux: #9aa3b5;
    --bord: #2c3448;
    --accent: #6d95e8;
    --accent-texte: #0d1220;
    --entete: #0c1222;
    --alerte: #f07167;
    --alerte-fond: #3a1d1d;
    --ok: #5cc48f;
    --aujourdhui: #33301c;
    --vide: #151a26;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--fond);
  color: var(--texte);
}
h1, h2, h3 { line-height: 1.2; margin: 0 0 .6rem; }
h1 { font-size: 1.35rem; }
h2 { font-size: 1.1rem; }
a { color: var(--accent); }

.entete {
  background: var(--entete);
  color: #fff;
  display: flex; flex-wrap: wrap; align-items: center; gap: .5rem 1.5rem;
  padding: .6rem 16px;
  position: sticky; top: 0; z-index: 5;
}
.marque { display: flex; align-items: center; gap: .5rem; font-weight: 600; }
nav { display: flex; gap: .25rem; overflow-x: auto; max-width: 100%; }
nav a {
  color: #cfd7ea; text-decoration: none; padding: .35rem .7rem; border-radius: 999px; white-space: nowrap;
}
nav a.actif { background: rgba(255,255,255,.16); color: #fff; }

main { max-width: 1200px; margin: 0 auto; padding: 1rem 16px 3rem; }

.carte {
  background: var(--carte); border: 1px solid var(--bord); border-radius: 12px;
  padding: 1rem; margin-bottom: 1rem;
}
.grille-2 { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.grille-2 > .carte { margin-bottom: 0; }

.barre { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; margin-bottom: 1rem; }
.barre h1 { margin: 0 auto 0 0; }
.capital { text-transform: capitalize; }
.doux { color: var(--doux); }
.petit { font-size: .85rem; }

.bouton, button, select, input {
  font: inherit; color: inherit;
}
.bouton, button {
  background: var(--carte); border: 1px solid var(--bord); border-radius: 8px;
  padding: .4rem .8rem; cursor: pointer;
}
.bouton:hover, button:hover { border-color: var(--accent); }
.principal { background: var(--accent); color: var(--accent-texte); border-color: var(--accent); }
.danger { color: var(--alerte); }
button:disabled { opacity: .5; cursor: default; }

input, select {
  background: var(--fond); border: 1px solid var(--bord); border-radius: 8px; padding: .4rem .55rem;
  max-width: 100%;
}
input[type="color"] { padding: 0; width: 2.4rem; height: 2.1rem; }
label { display: block; margin-bottom: .7rem; }
label > span { display: block; font-size: .85rem; color: var(--doux); margin-bottom: .2rem; }
label > input:not([type="color"]):not([type="checkbox"]), label > select { width: 100%; }
.case { display: flex; align-items: center; gap: .5rem; }
.ligne-champs { display: flex; flex-wrap: wrap; gap: .6rem; align-items: flex-end; }
.ligne-champs label { flex: 1 1 140px; margin-bottom: 0; }

/* ---------- Calendrier mensuel ---------- */
.legende { display: flex; flex-wrap: wrap; gap: .4rem 1rem; font-size: .82rem; color: var(--doux); margin-bottom: .8rem; }
.legende span { display: inline-flex; align-items: center; gap: .3rem; }

.calendrier { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; }
.calendrier .tete { font-size: .8rem; font-weight: 600; color: var(--doux); text-align: center; padding: .2rem 0; }
.jour {
  background: var(--carte); border: 1px solid var(--bord); border-radius: 8px;
  min-height: 112px; padding: .3rem; text-align: left; cursor: pointer;
  display: flex; flex-direction: column; gap: 3px;
}
.jour.hors { background: var(--vide); border-style: dashed; cursor: default; }
.jour.auj { background: var(--aujourdhui); }
.jour.manque { border-color: var(--alerte); box-shadow: inset 0 0 0 1px var(--alerte); }
.jour .haut { display: flex; justify-content: space-between; align-items: baseline; font-size: .82rem; }
.jour .num { font-weight: 600; }
.jour .nomjour { display: none; }
.compte { font-size: .75rem; padding: 0 .4rem; border-radius: 999px; background: var(--fond); color: var(--doux); }
.manque .compte { background: var(--alerte-fond); color: var(--alerte); font-weight: 600; }
.puces { display: flex; flex-wrap: wrap; gap: 3px; }

.puce {
  display: inline-flex; align-items: center; gap: .25rem;
  font-size: .76rem; line-height: 1.2; padding: .12rem .4rem; border-radius: 6px;
  background: color-mix(in srgb, var(--c) 20%, var(--carte));
  border-left: 3px solid var(--c);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%;
}
.puce.option { background: transparent; border: 1px dashed var(--c); border-left-width: 3px; border-left-style: solid; }
.puce.reprise::before { content: "⇄"; font-size: .7rem; }
.puce.off { background: transparent; color: var(--doux); text-decoration: line-through; border-left-color: var(--bord); }

@media (max-width: 720px) {
  .calendrier { grid-template-columns: 1fr; gap: 6px; }
  .calendrier .tete, .jour.hors { display: none; }
  .jour { min-height: 0; flex-direction: row; align-items: flex-start; gap: .6rem; }
  .jour .haut { flex-direction: column; align-items: flex-start; min-width: 3.4rem; gap: 2px; }
  .jour .nomjour { display: inline; color: var(--doux); font-size: .75rem; }
  .puce { font-size: .82rem; }
}

/* ---------- Planning individuel ---------- */
.stats { display: flex; flex-wrap: wrap; gap: .8rem; margin-bottom: 1rem; }
.stat { background: var(--carte); border: 1px solid var(--bord); border-radius: 12px; padding: .7rem 1rem; min-width: 130px; flex: 1; }
.stat b { display: block; font-size: 1.5rem; }
.stat span { font-size: .82rem; color: var(--doux); }

.liste { list-style: none; margin: 0; padding: 0; }
.liste li { display: flex; flex-wrap: wrap; gap: .3rem .8rem; align-items: center; padding: .5rem 0; border-bottom: 1px solid var(--bord); }
.liste li:last-child { border-bottom: 0; }
.liste .date { min-width: 9.5rem; font-weight: 500; }
.liste .action { margin-left: auto; }
.etiquette { font-size: .76rem; padding: .1rem .45rem; border-radius: 999px; background: var(--fond); color: var(--doux); }
.etiquette.nuit { background: color-mix(in srgb, var(--accent) 18%, var(--carte)); color: var(--texte); }
.etiquette.alerte { background: var(--alerte-fond); color: var(--alerte); }

/* ---------- Tableau du cycle ---------- */
.tableau-defile { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: .85rem; }
th, td { border-bottom: 1px solid var(--bord); padding: .35rem .4rem; text-align: center; }
th:first-child, td:first-child { text-align: left; white-space: nowrap; }
tr.courante td:first-child { box-shadow: inset 4px 0 0 var(--accent); font-weight: 600; }
td.manque { color: var(--alerte); font-weight: 700; }

.equipe-ligne { display: grid; grid-template-columns: auto 1fr 7.5rem auto auto; gap: .5rem; align-items: center; padding: .45rem 0; border-bottom: 1px solid var(--bord); }
.equipe-ligne:last-child { border-bottom: 0; }
.equipe-ligne > * { min-width: 0; }
@media (max-width: 560px) {
  .equipe-ligne { grid-template-columns: auto 1fr auto auto; grid-template-areas: "c n n n" "s s e x"; }
  .equipe-ligne [type="color"] { grid-area: c; }
  .equipe-ligne [name="nom"] { grid-area: n; }
  .equipe-ligne select { grid-area: s; min-width: 8.6rem; }
  .equipe-ligne button { padding: .4rem .55rem; }
  .equipe-ligne button:not([data-suppr]) { grid-area: e; }
  .equipe-ligne [data-suppr] { grid-area: x; }
}

.lien-ics { display: flex; gap: .4rem; }
.lien-ics input { flex: 1; min-width: 0; font-size: .8rem; }

/* ---------- Mon planning : accueil, 10 semaines, année ---------- */
.accueil { max-width: 520px; margin: 4vh auto 0; }

/* Cases de calendrier personnel : n = nuit, r = reprise, o = option, x = absente/cédée, c = congé un jour de repos */
.n { background: var(--accent); color: var(--accent-texte); font-weight: 600; }
.n.r { background: color-mix(in srgb, var(--accent) 35%, var(--carte)); color: var(--texte); outline: 2px dashed var(--accent); outline-offset: -3px; }
.o { background: repeating-linear-gradient(45deg, transparent 0 4px, color-mix(in srgb, var(--accent) 30%, transparent) 4px 8px); }
.x { background: var(--alerte-fond); color: var(--alerte); text-decoration: line-through; }
.c { background: color-mix(in srgb, var(--alerte-fond) 60%, transparent); }
.auj { box-shadow: inset 0 0 0 2px var(--texte); }

table.dix td:not(:first-child) { border-radius: 6px; border: 2px solid var(--carte); }

.case-leg { display: inline-block; min-width: 1.6rem; text-align: center; border-radius: 5px; padding: 0 .2rem; font-size: .78rem; border: 1px solid var(--bord); }

.annee { display: grid; gap: 1.2rem 1rem; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.mini h3 { font-size: .95rem; margin-bottom: .3rem; display: flex; justify-content: space-between; align-items: baseline; }
.mini table { table-layout: fixed; font-size: .8rem; }
.mini th { font-weight: 500; color: var(--doux); padding: .15rem 0; border: 0; text-align: center !important; }
.mini td { padding: .25rem 0; border: 2px solid var(--carte); border-radius: 6px; text-align: center !important; }
.mini td[data-jour] { cursor: pointer; }
.mini td.sem, .mini th:first-child { width: 2.1rem; color: var(--doux); font-size: .7rem; text-align: left !important; }
.mini td.sel { box-shadow: inset 0 0 0 2px #e0a100; }
.mini td.sel:not(.n):not(.x):not(.o) { background: color-mix(in srgb, #e0a100 25%, var(--carte)); }

.barre-simu {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  background: var(--carte); border-top: 2px solid #e0a100; box-shadow: 0 -4px 18px rgba(0,0,0,.12);
  padding: .7rem 16px; display: flex; flex-wrap: wrap; gap: .5rem 1rem; align-items: center; justify-content: space-between;
}
.barre-simu .actions { display: flex; gap: .5rem; }
body.avec-simu main { padding-bottom: 9rem; }

/* ---------- Divers ---------- */
dialog {
  border: 1px solid var(--bord); border-radius: 14px; background: var(--carte); color: var(--texte);
  width: min(460px, calc(100vw - 32px)); padding: 1rem;
}
dialog::backdrop { background: rgba(10, 14, 25, .5); }
dialog form { text-align: right; margin-top: 1rem; }

#message {
  position: fixed; left: 50%; top: 4.2rem; transform: translateX(-50%); z-index: 10;
  background: var(--texte); color: var(--fond); padding: .55rem 1rem; border-radius: 10px;
  opacity: 0; pointer-events: none; transition: opacity .2s; max-width: calc(100vw - 32px);
}
#message.visible { opacity: 1; }
#message.erreur { background: var(--alerte); color: #fff; }

.connexion { max-width: 360px; margin: 12vh auto 0; }
.vide-etat { text-align: center; padding: 2rem 1rem; color: var(--doux); }

@media print {
  .entete, .barre button, .barre select, #message, .barre-simu, #f-position, #f-simu, .lien-ics, .lien-ics + p { display: none !important; }
  .n, .o, .x, .c { print-color-adjust: exact; -webkit-print-color-adjust: exact; }
  .mini { break-inside: avoid; }
  body { background: #fff; color: #000; }
  main { padding: 0; max-width: none; }
  .jour { min-height: 90px; break-inside: avoid; }
}
