/* Fiches de garde — feuille de style */
:root {
  --bg: #eef1f5;
  --card: #ffffff;
  --ink: #1f2937;
  --muted: #6b7280;
  --line: #d9dee6;
  --line-soft: #e8ecf1;
  --red: #c62828;
  --red-dark: #9b1c1c;
  --red-soft: #fdecea;
  --navy: #1b2a41;
  --navy-soft: #e3e8f0;
  --yellow: #ffd600;
  --yellow-soft: #fff8cc;
  --green: #2e7d32;
  --green-soft: #e6f4ea;
  --orange: #ef6c00;
  --orange-soft: #fff1e0;
  --blue: #1565c0;
  --blue-soft: #e3effb;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { font-family: var(--font); color: var(--ink); background: var(--bg); font-size: 15px; line-height: 1.4; -webkit-text-size-adjust: 100%; }
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.45rem; margin: 0 0 .5rem; }
h2 { font-size: 1.1rem; margin: 0 0 .75rem; color: var(--navy); }
h3 { font-size: .95rem; margin: 0 0 .5rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
small, .muted { color: var(--muted); }
code { font-family: ui-monospace, Consolas, monospace; font-size: .9em; background: var(--line-soft); padding: 1px 4px; border-radius: 4px; }
hr { border: 0; border-top: 1px solid var(--line); margin: 1rem 0; }

/* ---- barre du haut ---- */
.topbar { display: flex; align-items: center; gap: 1rem; padding: 0 16px; height: 56px; background: var(--navy); color: #fff; position: sticky; top: 0; z-index: 20; }
.brand { display: flex; align-items: center; gap: 10px; color: #fff; text-decoration: none !important; min-width: 0; }
.brand-badge { background: var(--red); color: #fff; font-weight: 800; font-size: .8rem; letter-spacing: .06em; padding: 6px 8px; border-radius: 8px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.1; min-width: 0; }
.brand-text strong { font-size: .95rem; white-space: nowrap; }
.brand-text small { color: #b8c2d3; font-size: .72rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nav { display: flex; gap: 2px; margin-left: .5rem; overflow-x: auto; flex: 1; scrollbar-width: none; }
.nav::-webkit-scrollbar { display: none; }
.nav a { color: #d6dde8; padding: 8px 10px; border-radius: 8px; font-size: .9rem; white-space: nowrap; }
.nav a:hover { background: rgba(255,255,255,.08); text-decoration: none; color: #fff; }
.nav a.active { background: rgba(255,255,255,.14); color: #fff; font-weight: 600; }
.userbox { display: flex; align-items: center; gap: 8px; font-size: .85rem; color: #d6dde8; white-space: nowrap; }
.userbox .role { background: rgba(255,255,255,.12); padding: 2px 7px; border-radius: 999px; font-size: .72rem; }
.userbox button { color: #fff; }

/* ---- structure ---- */
.main { max-width: 1240px; margin: 0 auto; padding: 18px 16px 90px; }
.loading { color: var(--muted); padding: 2rem; text-align: center; }
.page-head { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; margin-bottom: 14px; }
.page-head h1 { margin: 0; }
.page-head .grow { flex: 1; }
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 14px; }
.card.tight { padding: 12px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.cards-auto { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 14px; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.row.between { justify-content: space-between; }
.right { text-align: right; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.empty { color: var(--muted); font-style: italic; padding: 8px 0; }

/* ---- boutons ---- */
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: #fff; color: var(--ink); font: inherit; font-size: .9rem; font-weight: 600; padding: 8px 14px; border-radius: 8px; cursor: pointer; line-height: 1.2; white-space: nowrap; }
.btn:hover { background: #f7f8fa; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--red); border-color: var(--red); color: #fff; }
.btn-primary:hover { background: var(--red-dark); }
.btn-success { background: var(--green); border-color: var(--green); color: #fff; }
.btn-success:hover { background: #256628; }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: rgba(0,0,0,.05); }
.btn-danger { color: var(--red); border-color: #f1b8b8; }
.btn-danger:hover { background: var(--red-soft); }
.btn-sm { padding: 5px 9px; font-size: .82rem; border-radius: 6px; }
.btn-icon { padding: 6px 8px; }

/* ---- formulaires ---- */
label { font-size: .85rem; color: var(--muted); font-weight: 600; display: block; margin-bottom: 4px; }
input[type=text], input[type=password], input[type=date], input[type=number], input[type=search], select, textarea {
  width: 100%; font: inherit; font-size: .95rem; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--ink);
}
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(21, 101, 192, .35); outline-offset: 1px; border-color: var(--blue); }
textarea { min-height: 90px; resize: vertical; }
.agendis { margin: 8px 0 10px; padding: 10px 12px; border: 1px dashed var(--line-soft); border-radius: 8px; }
.agendis textarea { width: 100%; font-family: ui-monospace, Consolas, monospace; font-size: .85rem; min-height: 120px; }
select.warn { border-color: var(--orange); background: var(--orange-soft); }
select.bad { border-color: var(--red); background: var(--red-soft); }
select.ok { background: #fff; }
.field { margin-bottom: 10px; }
.fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 10px; }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: .9rem; font-weight: 500; color: var(--ink); margin: 0; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--red); margin: 0; }
.checks { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 6px 14px; }
.form-error { color: var(--red); background: var(--red-soft); padding: 8px 10px; border-radius: 8px; font-size: .9rem; margin: 8px 0; }
.help { font-size: .82rem; color: var(--muted); margin-top: 4px; }

/* ---- tableaux ---- */
.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table th, .table td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
.table th { font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); background: #f8f9fb; position: sticky; top: 56px; }
.table tr:hover td { background: #fafbfd; }
.table td.actions { white-space: nowrap; text-align: right; }
.table-wrap { overflow-x: visible; } /* un conteneur à défilement casserait l'en-tête collant ; défilement horizontal seulement sur mobile */

/* ---- badges ---- */
.badge { display: inline-block; font-size: .72rem; font-weight: 700; padding: 2px 7px; border-radius: 999px; background: var(--line-soft); color: var(--ink); line-height: 1.5; white-space: nowrap; }
.badge-j { background: var(--yellow); color: #3a2f00; }
.badge-n { background: var(--navy); color: #fff; }
.badge-red { background: var(--red-soft); color: var(--red-dark); }
.badge-green { background: var(--green-soft); color: var(--green); }
.badge-orange { background: var(--orange-soft); color: var(--orange); }
.badge-blue { background: var(--blue-soft); color: var(--blue); }
.badge-grey { background: var(--line-soft); color: var(--muted); }
.st-brouillon { background: var(--orange-soft); color: var(--orange); }
.st-validee { background: var(--green-soft); color: var(--green); }
.st-historique { background: var(--line-soft); color: var(--muted); }
.st-nouvelle { background: var(--blue-soft); color: var(--blue); }

/* ---- connexion ---- */
.auth { max-width: 420px; margin: 6vh auto; }
.auth .brand-big { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.auth .brand-big .brand-badge { font-size: 1.1rem; padding: 10px 12px; }

/* ---- calendrier ---- */
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.cal-dow { font-size: .75rem; text-transform: uppercase; color: var(--muted); text-align: center; padding: 4px 0; letter-spacing: .04em; }
.cal-day { background: #fff; border: 1px solid var(--line); border-radius: 8px; min-height: 92px; padding: 6px 8px; display: flex; flex-direction: column; gap: 4px; color: inherit; text-decoration: none !important; transition: box-shadow .12s; }
.cal-day:hover { box-shadow: 0 0 0 2px rgba(21,101,192,.25); }
.cal-day.other { opacity: .45; background: #f6f7f9; }
.cal-day.today { border-color: var(--red); box-shadow: inset 0 0 0 1px var(--red); }
.cal-day .num { font-weight: 700; font-size: .95rem; display: flex; justify-content: space-between; align-items: center; }
.cal-day .eff { font-size: .78rem; color: var(--muted); }
.cal-day .eq { font-size: .75rem; }
.cal-day .st { margin-top: auto; }
.cal-legend { display: flex; flex-wrap: wrap; gap: 10px; font-size: .8rem; color: var(--muted); margin-top: 10px; }

/* ---- fiche ---- */
.fiche-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }
.fiche-bar .date-nav { display: flex; align-items: center; gap: 4px; }
.fiche-bar .date-title { font-size: 1.2rem; font-weight: 700; margin: 0 4px; }
.fiche-bar input[type=date] { width: auto; }
.eff { display: inline-flex; gap: 6px; align-items: center; font-weight: 600; }
.eff .n { font-size: 1.05rem; }
.actions-bar { position: sticky; bottom: 0; z-index: 10; background: rgba(255,255,255,.96); backdrop-filter: blur(6px); border-top: 1px solid var(--line); padding: 10px 16px; margin: 0 -16px -90px; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: flex-end; }
.actions-bar .msg { margin-right: auto; font-size: .85rem; color: var(--muted); }
.dirty { color: var(--orange); font-weight: 600; }

.pres-groups { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 10px; }
.pres-group h3 { display: flex; justify-content: space-between; align-items: baseline; }
.pres-row { display: grid; grid-template-columns: 1fr 34px 34px 26px; align-items: center; gap: 4px; padding: 4px 0; border-bottom: 1px solid var(--line-soft); font-size: .9rem; }
.pres-row:last-child { border-bottom: 0; }
.pres-row .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pres-row .nm small { display: block; font-size: .72rem; color: var(--muted); }
.pres-row input[type=checkbox] { width: 20px; height: 20px; accent-color: var(--red); margin: 0 auto; display: block; }
.pres-row .rm { border: 0; background: none; color: var(--muted); cursor: pointer; font-size: 1rem; padding: 0; line-height: 1; }
.pres-row .rm:hover { color: var(--red); }
.pres-head { display: grid; grid-template-columns: 1fr 34px 34px 26px; font-size: .7rem; color: var(--muted); text-align: center; padding-bottom: 2px; }
.pres-head span:first-child { text-align: left; }
.add-agent { position: relative; }
.add-agent .sugg { position: absolute; z-index: 15; left: 0; right: 0; top: 100%; background: #fff; border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 6px 20px rgba(0,0,0,.12); max-height: 260px; overflow: auto; }
.add-agent .sugg button { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 7px 10px; font: inherit; cursor: pointer; }
.add-agent .sugg button:hover, .add-agent .sugg button.hl { background: var(--blue-soft); }
.add-agent .sugg small { color: var(--muted); margin-left: 6px; }

.engin { break-inside: avoid; }
.engin h3 { color: var(--navy); display: flex; justify-content: space-between; }
.poste { display: grid; grid-template-columns: 110px 1fr 1fr; gap: 6px; align-items: center; margin-bottom: 6px; }
.poste .lbl { font-size: .85rem; font-weight: 600; }
.poste-head { display: grid; grid-template-columns: 110px 1fr 1fr; gap: 6px; font-size: .72rem; color: var(--muted); text-align: center; margin-bottom: 4px; }
.poste-head span:first-child { text-align: left; }
.poste select { padding: 6px 8px; font-size: .9rem; }
.jn-head .j { background: var(--yellow-soft); border-radius: 4px; padding: 1px 6px; }
.jn-head .n { background: var(--navy-soft); border-radius: 4px; padding: 1px 6px; }

.alerts { display: flex; flex-direction: column; gap: 4px; }
.alert { padding: 7px 10px; border-radius: 8px; font-size: .88rem; }
.alert-warn { background: var(--orange-soft); color: #7a3b00; }
.alert-bad { background: var(--red-soft); color: var(--red-dark); }
.alert-info { background: var(--blue-soft); color: #0b3d7a; }
.alert-ok { background: var(--green-soft); color: var(--green); }

.consignes { white-space: pre-wrap; font-size: .88rem; background: var(--yellow-soft); padding: 10px 12px; border-radius: 8px; border: 1px solid #f1e3a0; }

/* ---- agents ---- */
.comp-chips { display: flex; flex-wrap: wrap; gap: 3px; }
.comp-chips .badge { font-weight: 600; }
.filters { display: grid; grid-template-columns: 2fr 1fr 1fr 1fr auto; gap: 8px; align-items: end; }

/* ---- toast ---- */
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--navy); color: #fff; padding: 10px 16px; border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.25); z-index: 50; font-size: .92rem; max-width: 90vw; }
.toast.err { background: var(--red-dark); }
.toast.ok { background: var(--green); }

/* ---- mobile ---- */
@media (max-width: 1000px) {
  .brand-text small { display: none; }
  .nav { gap: 0; margin-left: .25rem; }
  .nav a { padding: 8px 7px; font-size: .84rem; }
  .userbox .role { display: none; }
}

@media (max-width: 760px) {
  .topbar { height: auto; flex-wrap: wrap; padding: 8px 12px; gap: 6px; }
  .brand { order: 1; }
  .userbox { order: 2; margin-left: auto; }
  .userbox .role { display: none; }
  .nav { order: 3; width: 100%; margin: 0; }
  .fiche-bar .date-nav { flex-wrap: wrap; }
  .fiche-bar .date-title { white-space: nowrap; }
  .table-wrap { overflow-x: auto; }
  .table th { position: static; }
  .main { padding: 12px 12px 90px; }
  .grid-2, .grid-3, .filters { grid-template-columns: 1fr; }
  .poste { grid-template-columns: 1fr 1fr; }
  .poste .lbl { grid-column: 1 / -1; margin-bottom: -2px; }
  .poste-head { grid-template-columns: 1fr 1fr; }
  .poste-head span:first-child { display: none; }
  .actions-bar { margin: 0 -12px -90px; padding: 10px 12px; }
  .fiche-bar .date-title { font-size: 1rem; }
}

/* ======================= IMPRESSION DE LA FICHE ======================= */
/* Feuille imprimée — deux niveaux visuels : titres de bloc (noir / blanc, capitales) et libellés (gris clair, 8.5 pt).
   Noms centrés partout, lignes de 14 px, blocs espacés de 2 mm, bordures 1 px noires. */
.sheet { background: #fff; color: #000; font-family: Arial, Helvetica, sans-serif; font-size: 9.5pt; width: 277mm; margin: 0 auto; padding: 4mm;
  --sheet-head: #000; --sheet-head-ink: #fff; --sheet-lbl: #e4e4e4; --sheet-row: 14px; }
.sheet table { border-collapse: collapse; width: 100%; }
.sheet th, .sheet td { border: 1px solid #000; padding: 1px 3px; vertical-align: middle; text-align: center; height: var(--sheet-row); }
.sheet th { font-weight: 700; }
/* niveau 1 : titres de bloc */
.sheet .engin-t th.name, .sheet .presences th.grp, .sheet .fonctions .lbl, .sheet .verif th, .sheet .foot .box b {
  background: var(--sheet-head); color: var(--sheet-head-ink); font-weight: 700; text-transform: uppercase; letter-spacing: .04em; font-size: 9.5pt; }
/* niveau 2 : libellés */
.sheet .presences th.jn, .sheet .engin-t td.lbl, .sheet .verif td.lbl, .sheet .title .equipe, .sheet .title .effectif {
  background: var(--sheet-lbl); font-weight: 700; font-size: 8.5pt; }
.sheet .title { display: grid; grid-template-columns: 1fr 2fr 1fr; align-items: center; gap: 4mm; margin-bottom: 2mm; }
.sheet .title .equipe, .sheet .title .effectif { border: 1px solid #000; padding: 3px 6px; text-align: center; font-size: 9.5pt; }
.sheet .title .garde { text-align: center; font-size: 13pt; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; }
.sheet .title .effectif { display: flex; justify-content: space-around; }
.sheet .fonctions td { width: 25%; }
.sheet .fonctions .jn { display: grid; grid-template-columns: 1fr 1fr; padding: 0; }
.sheet .fonctions .jn span { padding: 1px 3px; display: flex; align-items: center; justify-content: center; }
.sheet .fonctions .jn span + span { border-left: 1px solid #000; }
.sheet .presences { margin-top: 2mm; }
.sheet .presences th.jn, .sheet .presences td.jn { width: 16px; font-weight: 700; }
.sheet .engins { display: grid; grid-template-columns: repeat(4, 1fr); gap: 2mm; margin-top: 2mm; }
.sheet .engin-t td.lbl { width: 14%; text-align: left; white-space: nowrap; text-transform: uppercase; }
.sheet .engin-t td.v { width: 43%; white-space: nowrap; } /* un nom long élargit sa colonne plutôt que de passer sur deux lignes */
.sheet .presences td.nm { white-space: nowrap; }
.sheet .verif { margin-top: 2mm; }
.sheet .verif td.lbl { width: 9%; }
.sheet .foot { display: grid; grid-template-columns: 1fr 1.3fr; gap: 2mm; margin-top: 2mm; }
.sheet .foot .box { border: 1px solid #000; padding: 2px 5px; min-height: 16mm; white-space: pre-wrap; font-size: 9pt; }
.sheet .foot .box b { display: block; margin: -2px -5px 2px; padding: 2px 5px; text-align: center; }
.sheet .foot .remarques { font-size: 9.5pt; }
.print-tools { display: flex; gap: 8px; justify-content: center; margin: 12px 0; }

@media print {
  @page { size: A4 landscape; margin: 6mm; }
  html, body { background: #fff !important; }
  .no-print, .topbar, .toast, .actions-bar, .print-tools { display: none !important; }
  .main { max-width: none; padding: 0; margin: 0; }
  .sheet { width: 100%; padding: 0; margin: 0; box-shadow: none; }
  .sheet th, .sheet td, .sheet .title .equipe, .sheet .title .effectif, .sheet .foot .box b { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
