:root {
  /* theme clair aux couleurs du blason du centre : rouge, or, argent.
     Le site reste toujours blanc/clair — pas de bascule automatique en
     sombre selon les reglages du telephone. */
  --bg: #ffffff;
  --panel: #ffffff;
  --ink: #221a10;
  --muted: #7a6f5c;
  --line: #e9e0cd;
  --accent: #c31f1f;
  --accent-soft: #fbe6e1;
  --mine: #fdf1cf;
  --weekend: #f4efe1;
  --slot-bg: #e7f0fb;
  --slot-ink: #1a4f8a;
  --gold: #f2c230;
  --gold-ink: #4a3707;

  /* couleurs par categorie de grade */
  --grade-rang-bg: #eef0f3;    --grade-rang-ink: #4b5563;    /* elve/sapeur */
  --grade-sousoff-bg: #e5f5ea; --grade-sousoff-ink: #1f7a3d; /* caporal/sergent */
  --grade-off1-bg: #e6f0fb;    --grade-off1-ink: #1a56a8;    /* adjudant/lieutenant/capitaine */
  --grade-off2-bg: #fdf0dc;    --grade-off2-ink: #96660b;    /* commandant et plus */
  --grade-medical-bg: #f5e9fb; --grade-medical-ink: #7a2ea3; /* infirmier/medecin */

  /* bandeau du cycle de garde D/A/B/C, couleurs fixes (comme le planning papier) */
  --cycle-d-bg: #f2c230; --cycle-d-ink: #3a2c02;
  --cycle-a-bg: #2f8f4e; --cycle-a-ink: #ffffff;
  --cycle-b-bg: #c0392b; --cycle-b-ink: #ffffff;
  --cycle-c-bg: #2465b0; --cycle-c-ink: #ffffff;

  /* couleur de ligne par personne : quelques responsables en couleur, les autres en gris */
  --row-gray-bg: #eef0f2;
  --row-blue-bg: #dbe9fb;
  --row-yellow-bg: #fdf0c4;
  --row-red-bg: #fbdedb;
  --row-green-bg: #ddf3e2;
}


* { box-sizing: border-box; }

/* doit primer sur les regles display: flex ci-dessous */
[hidden] { display: none !important; }

/* invisible a l'oeil mais toujours dans le DOM, pour que les gestionnaires
   de mots de passe du navigateur associent bien le nom au compte */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
  padding: 0;
  margin: -1px;
}

/* La page occupe exactement la hauteur de l'ecran et ne defile pas
   elle-meme : c'est la zone du tableau qui defile, ce qui permet de garder
   l'en-tete des dates et la colonne des noms toujours visibles. */
body {
  margin: 0;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

.topbar, .monthbar, .legend { flex: 0 0 auto; }

#admin {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.admin-intro {
  flex: 0 0 auto;
  margin: 0 16px 10px;
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.5;
}

.admin-actions {
  flex: 0 0 auto;
  padding: 0 16px 10px;
}

.admin-actions .primary { width: 100%; }

.admin-list {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 0 16px 16px;
}

/* code temporaire affiche apres la creation d'un compte */
.new-code { margin: 0 0 6px; font-size: 13.5px; }

.code {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 6px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 1px;
}

.admin-row {
  display: flex;
  align-items: stretch;
  width: 100%;
  margin-bottom: 6px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 9px;
  overflow: hidden;
}

.admin-row:hover { border-color: var(--accent); }

/* zone cliquable qui ouvre la fiche du compte */
.admin-open {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 12px;
  text-align: left;
  background: none;
  border: 0;
  color: var(--ink);
  font: inherit;
}

.admin-open .name-text { font-weight: 600; }

/* fleches pour deplacer la ligne dans le tableau */
.admin-moves {
  flex: 0 0 auto;
  display: flex;
  border-left: 1px solid var(--line);
}

.admin-moves .move {
  width: 40px;
  background: var(--bg);
  border: 0;
  border-left: 1px solid var(--line);
  color: var(--ink);
  font-size: 15px;
  line-height: 1;
}

.admin-moves .move:first-child { border-left: 0; }
.admin-moves .move:hover:not(:disabled) { background: var(--accent-soft); color: var(--accent); }
.admin-moves .move:disabled { opacity: .3; cursor: default; }

/* mise en evidence breve de la ligne qui vient d'etre deplacee */
.admin-row.just-moved { border-color: var(--accent); animation: moved 1s ease-out; }

@keyframes moved {
  from { background: var(--accent-soft); }
  to { background: var(--panel); }
}

.admin-tag {
  flex: 0 0 auto;
  padding: 1px 6px;
  border-radius: 5px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .3px;
  background: var(--grade-rang-bg);
  color: var(--grade-rang-ink);
}

.admin-tag.is-admin { background: var(--accent-soft); color: var(--accent); }

.check {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  font-size: 13px;
  color: var(--muted);
}

.check input { width: 16px; height: 16px; margin: 0; }

.big.danger { color: var(--accent); border-color: var(--accent-soft); }

#planning {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

/* ------------------------------------------------------------- en-tête */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  box-shadow: inset 0 -3px 0 var(--gold);
}

.brand { display: flex; align-items: center; gap: 10px; }
.brand-logo { height: 34px; width: auto; display: block; }
.topbar h1 { font-size: 17px; margin: 0; letter-spacing: .2px; }
.me {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  font-size: 14px;
  color: var(--muted);
}

/* le nom peut etre long : il se tronque plutot que de faire grandir
   l'en-tete, qui prendrait de la hauteur au tableau */
#me-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.me .link { flex: 0 0 auto; white-space: nowrap; }

button { font: inherit; cursor: pointer; }

.link {
  background: none;
  border: 0;
  color: var(--accent);
  padding: 4px 2px;
  text-decoration: underline;
}

.primary {
  background: var(--accent);
  color: #fff;
  border: 0;
  border-radius: 8px;
  padding: 9px 16px;
  font-weight: 600;
}

/* ---------------------------------------------------------- connexion */

.auth {
  flex: 1 1 auto;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  overflow-y: auto;
  padding: 40px 16px;
}

.card {
  width: 100%;
  max-width: 360px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 20px;
}

.tabs { display: flex; gap: 6px; margin-bottom: 18px; }

.tab {
  flex: 1;
  background: none;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  color: var(--muted);
}

.tab.is-active { border-color: var(--accent); color: var(--accent); font-weight: 600; }

.card label, .field { display: block; margin-bottom: 14px; font-size: 13px; color: var(--muted); }

.card input,
.card select,
select#grade-select,
.field input,
.field select {
  display: block;
  width: 100%;
  margin-top: 5px;
  padding: 10px;
  font: inherit;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.card .primary { width: 100%; }
.primary.full { width: 100%; }
.error { color: var(--accent); font-size: 13px; margin: 0 0 12px; }
.success { color: var(--grade-sousoff-ink); font-size: 13px; margin: 0 0 12px; }
.hint { color: var(--muted); font-size: 12.5px; margin: 16px 0 0; }

.force-title { margin: 0 0 8px; font-size: 17px; }
.force-hint { margin: 0 0 18px; line-height: 1.5; }
.force-logout { display: block; margin: 14px auto 0; text-align: center; }

/* ------------------------------------------------------------ barre mois */

.monthbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 16px 10px;
}

/* le nom du mois est un bouton : il ouvre le choix direct mois/annee */
.month-label {
  font-size: 17px;
  font-weight: 700;
  margin: 0;
  min-width: 165px;
  height: 40px;
  padding: 0 10px;
  text-align: center;
  text-transform: capitalize;
  background: var(--panel);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.month-label:hover { border-color: var(--accent); }

/* cibles tactiles confortables : 40px de cote minimum */
.monthbar button:not(.link):not(.month-label) {
  width: 40px;
  height: 40px;
  font-size: 21px;
  line-height: 1;
  background: var(--panel);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.year-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 12px;
}

.year-row strong { font-size: 16px; }

.year-row button {
  width: 40px;
  height: 36px;
  font-size: 20px;
  line-height: 1;
  background: var(--panel);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.month-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.month-grid button {
  padding: 10px 4px;
  font-size: 13px;
  text-transform: capitalize;
  background: var(--bg);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.month-grid button:hover { border-color: var(--accent); }

.month-grid button.is-current {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 700;
}

/* --------------------------------------------------------------- tableau */
/*
 * Le nom (a gauche) et les jours (a droite) sont deux <table> distincts
 * places cote a cote, plutot qu'un seul tableau avec une colonne "collante".
 * Sur certains navigateurs mobiles, `position: sticky` a l'interieur d'un
 * <table> qui defile horizontalement ne fonctionne pas de façon fiable — la
 * colonne des noms se met alors a defiler avec le reste. En la sortant
 * completement de la zone qui defile, elle ne peut plus jamais bouger,
 * quel que soit le navigateur.
 */

.grid-frozen {
  flex: 1 1 auto;
  min-height: 0;      /* indispensable pour que la zone puisse retrecir et defiler */
  display: flex;
  align-items: stretch;
  margin: 0 16px 8px;
}

/* Les deux colonnes defilent verticalement chacune de leur cote, mais
   app.js synchronise leur scrollTop : elles descendent donc toujours
   ensemble, ligne par ligne. Chacune garde ainsi son propre en-tete
   colle en haut (sticky), y compris celui des dates. */
.grid-names {
  flex: 0 0 auto;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: none;          /* la barre utile est celle de droite */
  -webkit-overflow-scrolling: touch;
}

.grid-names::-webkit-scrollbar { display: none; }

.grid-scroll {
  flex: 1 1 auto;
  min-width: 0;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

.grid-names table, .grid-scroll table {
  border-collapse: separate;
  border-spacing: 0;
  background: var(--panel);
  border: 1px solid var(--line);
}

.grid-names table {
  border-right: 2px solid var(--line);
  border-top-left-radius: 10px;
  border-bottom-left-radius: 10px;
}

.grid-scroll table {
  border-left: 0;
  border-top-right-radius: 10px;
  border-bottom-right-radius: 10px;
}

th, td {
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  padding: 0;
}

.name-col { border-right: 0; }

/* les deux tetes de tableau restent visibles pendant qu'on descend dans la
   liste — sticky ici ne sert qu'a l'axe vertical, le cas le plus simple et
   le mieux supporte partout. */
thead th { position: -webkit-sticky; position: sticky; top: 0; z-index: 2; background: var(--panel); }

/* bandeau du cycle de garde (D/A/B/C), une ligne au-dessus des jours */
.cycle {
  top: 0;
  height: 20px;
  padding: 0;
  text-align: center;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .5px;
}

.cycle-D { background: var(--cycle-d-bg); color: var(--cycle-d-ink); }
.cycle-A { background: var(--cycle-a-bg); color: var(--cycle-a-ink); }
.cycle-B { background: var(--cycle-b-bg); color: var(--cycle-b-ink); }
.cycle-C { background: var(--cycle-c-bg); color: var(--cycle-c-ink); }

/* les 2 lignes d'en-tete vides de la table des noms, alignees en hauteur
   sur le bandeau de cycle (ligne 1) et la ligne des jours (ligne 2) */
.grid-names thead tr:first-child .corner { height: 20px; top: 0; }
.grid-names thead tr:last-child .corner { height: 38px; top: 20px; }

.day-head { top: 20px; height: 38px; }

.name-col {
  min-width: 175px;
  max-width: 270px;
  width: 1px; /* laisse le contenu (nom + grade) dicter la largeur reelle */
  height: 38px;
  text-align: left;
  padding: 7px 10px;
  font-size: 13.5px;
  font-weight: 600;
  background: var(--panel);
}

.name-row {
  display: flex;
  align-items: baseline;
  gap: 4px;
  min-width: 0;
}

.name-text {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.you {
  flex: 0 0 auto;
  font-size: 10px;
  font-weight: 700;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: .3px;
}

.grade {
  display: inline-block;
  margin-right: 6px;
  padding: 1px 5px;
  border-radius: 5px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .3px;
  vertical-align: 1px;
}

button.grade { border: 0; margin: 0 6px 0 0; padding: 1px 5px; }

.grade.tier-rang     { background: var(--grade-rang-bg);    color: var(--grade-rang-ink); }
.grade.tier-sousoff  { background: var(--grade-sousoff-bg); color: var(--grade-sousoff-ink); }
.grade.tier-off1     { background: var(--grade-off1-bg);    color: var(--grade-off1-ink); }
.grade.tier-off2     { background: var(--grade-off2-bg);    color: var(--grade-off2-ink); }
.grade.tier-medical  { background: var(--grade-medical-bg); color: var(--grade-medical-ink); }

.grade-missing {
  display: inline-block;
  margin-right: 6px;
  padding: 1px 6px;
  border-radius: 5px;
  font-size: 10px;
  font-weight: 600;
  background: none;
  border: 1px dashed var(--muted);
  color: var(--muted);
  cursor: pointer;
}

.day-head {
  min-width: 46px;
  padding: 5px 2px;
  font-weight: 500;
  color: var(--muted);
}

.dnum { display: block; font-size: 13px; font-weight: 600; color: var(--ink); }
.dwd { display: block; font-size: 10.5px; text-transform: uppercase; }

.cell { height: 38px; min-width: 46px; text-align: center; }
.weekend { background: var(--weekend); }
.today { box-shadow: inset 0 0 0 2px var(--accent); }
/* couleur de ligne par personne : quelques responsables en couleur, les autres en gris */
tr.role-gray .name-col, tr.role-gray .cell { background: var(--row-gray-bg); }
tr.role-blue .name-col, tr.role-blue .cell { background: var(--row-blue-bg); }
tr.role-yellow .name-col, tr.role-yellow .cell { background: var(--row-yellow-bg); }
tr.role-red .name-col, tr.role-red .cell { background: var(--row-red-bg); }
tr.role-green .name-col, tr.role-green .cell { background: var(--row-green-bg); }

tr.role-gray .cell.weekend { background: color-mix(in srgb, var(--row-gray-bg) 70%, var(--weekend)); }
tr.role-blue .cell.weekend { background: color-mix(in srgb, var(--row-blue-bg) 70%, var(--weekend)); }
tr.role-yellow .cell.weekend { background: color-mix(in srgb, var(--row-yellow-bg) 70%, var(--weekend)); }
tr.role-red .cell.weekend { background: color-mix(in srgb, var(--row-red-bg) 70%, var(--weekend)); }
tr.role-green .cell.weekend { background: color-mix(in srgb, var(--row-green-bg) 70%, var(--weekend)); }

/* votre propre ligne : un lisere plutot qu'une couleur de fond, pour ne pas
   entrer en conflit avec la couleur de role ci-dessus */
tr.mine .name-col { box-shadow: inset 3px 0 0 var(--accent); }

.editable { cursor: pointer; }
.editable:hover, .editable:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

/* case d'une autre personne : consultable, pas modifiable */
.readable { cursor: help; }
.readable:hover, .readable:focus-visible { outline: 2px dashed var(--muted); outline-offset: -2px; }

.chip {
  display: inline-block;
  min-width: 22px;
  padding: 2px 5px;
  border-radius: 5px;
  font-size: 11.5px;
  font-weight: 600;
  white-space: nowrap;
}

.chip.cross { background: var(--accent-soft); color: var(--accent); font-size: 13px; }
.chip.slot { background: var(--slot-bg); color: var(--slot-ink); }

.legend { padding: 4px 16px 32px; color: var(--muted); font-size: 12.5px; }

/* --------------------------------------------------------------- éditeur */

.backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, .35); z-index: 9; }

.editor {
  position: fixed;
  z-index: 10;
  width: 292px;
  padding: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, .22);
}

.editor-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  font-size: 13.5px;
}

.editor-head button {
  background: none;
  border: 0;
  color: var(--muted);
  font-size: 21px;
  line-height: 1;
  padding: 0 4px;
}

.big {
  display: block;
  width: 100%;
  padding: 10px;
  margin-bottom: 10px;
  font-weight: 600;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
}

.big.cross { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.big.ghost { color: var(--muted); font-weight: 500; margin-bottom: 0; }

.viewer-line { margin: 0 0 10px; display: flex; align-items: center; gap: 8px; font-size: 14px; }
.viewer-note { margin: 0; font-size: 12.5px; line-height: 1.4; color: var(--muted); }

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

.slot-row input {
  flex: 1;
  min-width: 0;
  padding: 8px 4px;
  font: inherit;
  font-size: 13.5px;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.slot-row .primary { padding: 9px 12px; }
.slot-row span { color: var(--muted); }

.presets { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }

.preset {
  flex: 1 1 calc(50% - 3px);
  padding: 7px 4px;
  font-size: 12.5px;
  color: var(--slot-ink);
  background: var(--slot-bg);
  border: 0;
  border-radius: 7px;
}

@media (max-width: 639px) {
  .editor {
    left: 8px;
    right: 8px;
    bottom: 8px;
    top: auto !important;
    width: auto;
  }
  .name-col { min-width: 145px; max-width: 210px; font-size: 12px; padding: 6px 8px; }

  /* en-tete compact : chaque pixel gagne ici est un pixel de tableau visible */
  .topbar { padding: 8px 12px; gap: 8px; }
  .brand-logo { height: 26px; }
  .topbar h1 { font-size: 15px; }
  .me { gap: 8px; font-size: 12.5px; }
  .monthbar { padding: 10px 12px 8px; gap: 6px; }
  .month-label { font-size: 15px; min-width: 0; flex: 1 1 auto; }
  .grid-frozen { margin: 0 12px 6px; }
  .legend { padding: 4px 12px 10px; font-size: 11.5px; }
}

/* presence dans l'ecran de gestion : qui est connecte, et depuis quand */
.presence {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 1px 7px 1px 5px;
  border-radius: 5px;
  font-size: 10.5px;
  font-weight: 600;
  white-space: nowrap;
}

.presence::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
}

.presence.en-ligne {
  background: var(--grade-sousoff-bg);
  color: var(--grade-sousoff-ink);
}

.presence.hors-ligne {
  background: var(--grade-rang-bg);
  color: var(--muted);
}
