/* CoverTrack — camaïeu de gris anthracite, accent rouge #e40613, blanc, noir.
   Les variables --violet* portent désormais les gris (noms conservés pour ne pas tout renommer). */
:root {
  --violet: #2f3237;
  --violet-dark: #1f2124;
  --violet-light: #5c6168;
  --violet-bg: #f4f5f6;
  --border: #e1e3e6;
  --text: #1a1a1a;
  --muted: #777;
  --red: #c0392b;
  --green: #1e8e4e;
  --blue: #2b6cb0;
  --accent: #e40613;   /* accent rouge : menu actif, champ en saisie, pastille de notifications */
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { font-family: "Segoe UI", Roboto, Arial, sans-serif; color: var(--text); background: var(--violet-bg); font-size: 15px; }
a { color: var(--violet); }
h1, h2, h3 { color: var(--violet); margin-top: 0; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }

/* ---- Layout général ---- */
.app { display: flex; min-height: 100vh; }
.sidebar { width: 230px; background: var(--violet); color: #fff; flex-shrink: 0; display: flex; flex-direction: column;
  /* Figée sur la hauteur de la fenêtre : sans cela elle s'étire avec le contenu
     et le bloc compte / déconnexion se retrouve tout en bas d'une longue page.
     align-self évite que le flex l'étire malgré la hauteur imposée. */
  position: sticky; top: 0; align-self: flex-start; height: 100vh; overflow-y: auto; }
.sidebar .brand { padding: 20px 18px; font-size: 21px; font-weight: 700; color: #fff; letter-spacing: .5px; }
/* Logo (image) : sa hauteur suit la taille de police du bloc .brand */
.brand { line-height: 1; }
.brand-logo { height: 1.15em; width: auto; max-width: 100%; vertical-align: middle; display: inline-block; }
.sidebar nav a { display: block; padding: 11px 18px; color: #dadcdf; text-decoration: none; border-left: 3px solid transparent; }
.sidebar nav a:hover { background: var(--violet-dark); color: #fff; }
.sidebar nav a.active { background: var(--violet-dark); color: #fff; border-left-color: var(--accent); }
.sidebar .spacer { flex: 1; }
.sidebar .userbox { padding: 14px 18px; border-top: 1px solid rgba(255,255,255,.15); font-size: 13px; color: #cbced2; }
.sidebar .userbox a { color: #fff; }
.main { flex: 1; min-width: 0; }
.topbar { background: #fff; border-bottom: 1px solid var(--border); padding: 12px 24px; display: flex; align-items: center; justify-content: space-between; }
.topbar h1 { font-size: 19px; margin: 0; }
.content { padding: 24px; max-width: 1200px; }

/* ---- Cartes / tableaux ---- */
.card { background: #fff; border: 1px solid var(--border); border-radius: 10px; padding: 18px 20px; margin-bottom: 18px; }
.card h2 { font-size: 16px; margin-bottom: 12px; }
table.tbl { width: 100%; border-collapse: collapse; background: #fff; }
.tbl th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); padding: 8px 10px; border-bottom: 2px solid var(--border); }
.tbl td { padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.tbl tr:hover td { background: var(--violet-bg); }

/* ---- Formulaires ---- */
label { display: block; margin-bottom: 12px; font-weight: 600; font-size: 13.5px; color: var(--violet-dark); }
input, select, textarea {
  width: 100%; padding: 9px 11px; margin-top: 5px; border: 1px solid var(--border);
  border-radius: 7px; font-size: 14.5px; font-family: inherit; background: #fff; color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); }   /* bordure inchangée : seul le contour rouge marque le champ */
input[type=checkbox], input[type=radio] { width: auto; margin-right: 6px; }
/* Les champs date/heure natifs (WebKit mobile) ont une largeur intrinsèque qui
   ignore width:100% et débordait du cadre sur smartphone : on les contraint. */
input[type=date], input[type=time], input[type=datetime-local] {
  -webkit-appearance: none; appearance: none; min-width: 0; max-width: 100%;
}
.check-inline { font-weight: 400; display: flex; align-items: center; }
.form-row { display: flex; gap: 16px; flex-wrap: wrap; }
.form-row > label { flex: 1 1 180px; min-width: 0; max-width: 100%; }
.req { color: var(--red); }

/* ---- Boutons ---- */
.btn { display: inline-block; padding: 9px 16px; border-radius: 7px; border: 1px solid transparent;
  font-family: inherit; font-size: 14px; line-height: 1.2; font-weight: 600; cursor: pointer;
  text-decoration: none; text-align: center; vertical-align: middle; }
.btn-primary { background: var(--violet); color: #fff; }
.btn-primary:hover { background: var(--violet-dark); }
.btn-outline { background: #fff; color: var(--violet); border-color: var(--violet); }
.btn-outline:hover { background: var(--violet-bg); }
.btn-danger { background: var(--red); color: #fff; }
.btn-success { background: var(--green); color: #fff; }
.btn-sm { padding: 5px 10px; font-size: 12.5px; }
.btn-block { display: block; width: 100%; }

/* ---- Agenda (planning mensuel) ---- */
.agenda-bar { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.agenda-legend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-bottom: 12px; }
.agenda-legend .lg { font-size: 12.5px; color: var(--text); display: inline-flex; align-items: center; gap: 6px; }
.agenda-legend .sw { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.agenda-wrap { overflow-x: auto; }
.agenda-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; min-width: 680px; }
.agenda-dow { text-align: center; font-weight: 600; color: var(--muted); font-size: 12px; padding: 2px 0 4px; }
.agenda-cell { background: #fff; border: 1px solid var(--border); border-radius: 6px; min-height: 92px; padding: 4px; }
.agenda-cell.other { background: #f9fafa; border-style: dashed; }
.agenda-cell .d { font-size: 12px; color: var(--muted); margin-bottom: 2px; }
.agenda-cell.today { border-color: var(--violet); box-shadow: 0 0 0 1px var(--violet) inset; }
.agenda-cell.today .d { color: var(--violet); font-weight: 700; }
.agenda-ev { display: block; font-size: 11px; line-height: 1.25; padding: 2px 5px; border-radius: 4px; margin-top: 3px; color: #fff; text-decoration: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.agenda-ev:hover { filter: brightness(1.08); }
.agenda-ev.annulee { opacity: .55; text-decoration: line-through; }

/* ---- Mini-calendrier (tableau de bord) ---- */
.mini-cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.mini-dow { text-align: center; font-weight: 600; color: var(--muted); font-size: 11px; }
.mini-cell { min-height: 38px; border: 1px solid var(--border); border-radius: 6px; padding: 2px 4px; display: flex; flex-direction: column; align-items: center; }
.mini-cell.other { border: 0; }
.mini-cell .d { font-size: 11px; color: var(--muted); align-self: flex-start; }
.mini-cell.today { border-color: var(--violet); box-shadow: 0 0 0 1px var(--violet) inset; }
.mini-cell.today .d { color: var(--violet); font-weight: 700; }
.mini-cell .cnt { margin-top: 1px; background: var(--violet); color: #fff; border-radius: 99px; font-size: 11px; font-weight: 700; line-height: 1.5; min-width: 18px; text-align: center; padding: 0 5px; text-decoration: none; }
.mini-cell .cnt:hover { filter: brightness(1.12); }

/* ---- Badges / alertes ---- */
.badge { display: inline-block; padding: 3px 10px; border-radius: 99px; font-size: 12px; font-weight: 600; color: #fff; white-space: nowrap; }
.b-grey { background: #8a8a8a; } .b-orange { background: #d98200; } .b-blue { background: var(--blue); } .b-violet { background: var(--violet-light); }
.b-red { background: var(--red); } .b-green { background: var(--green); } .b-dark { background: #333; }
.alert { padding: 11px 14px; border-radius: 8px; margin-bottom: 14px; font-size: 14px; }
.alert-success { background: #e6f6ec; color: var(--green); border: 1px solid #bfe6cd; }
.alert-danger { background: #fdecea; color: var(--red); border: 1px solid #f5c6c0; }
.alert-info { background: #ebecee; color: var(--violet); border: 1px solid #d0d3d7; }

/* ---- Notifications (cloche) ---- */
.bell { position: relative; text-decoration: none; font-size: 19px; }
.bell .dot { position: absolute; top: -6px; right: -9px; background: var(--accent); color: #fff; border-radius: 99px; font-size: 10.5px; padding: 1px 5px; font-weight: 700; }

/* ---- Auth ---- */
.auth-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: var(--violet); }
.auth-card { background: #fff; border-radius: 12px; padding: 34px 36px; width: 380px; max-width: 92vw; box-shadow: 0 18px 50px rgba(0,0,0,.35); }
.auth-card .brand { font-size: 26px; margin-bottom: 4px; }
.auth-card h2 { font-size: 16px; color: var(--muted); font-weight: 400; margin-bottom: 20px; }

/* ---- Builder de modèles ---- */
.page-block { border: 1px solid var(--border); border-radius: 10px; margin-bottom: 16px; background: #fff; }
.page-head { background: var(--violet-bg); padding: 10px 14px; display: flex; gap: 10px; align-items: center; border-radius: 10px 10px 0 0; }
.page-head .ctx { font-size: 12px; }
.champ-row { display: flex; gap: 8px; align-items: center; padding: 8px 14px; border-top: 1px solid var(--border); flex-wrap: wrap; }
.champ-row .grip { color: var(--muted); cursor: default; }
.ord-btns button { background: none; border: 1px solid var(--border); border-radius: 5px; cursor: pointer; padding: 2px 7px; }

/* ---- PWA Poseur (mobile) ---- */
.pwa-body { background: var(--violet-bg); padding-bottom: calc(70px + env(safe-area-inset-bottom, 0px)); }
/* Safe-area : réserve l'encoche (haut) et les bords (paysage) sur smartphones modernes */
.pwa-top { background: var(--violet); color: #fff;
  padding: calc(14px + env(safe-area-inset-top, 0px)) calc(16px + env(safe-area-inset-right, 0px)) 14px calc(16px + env(safe-area-inset-left, 0px));
  display: flex; justify-content: space-between; align-items: center; position: sticky; top: 0; z-index: 10; }
.pwa-top .brand { font-size: 18px; font-weight: 700; }
.pwa-user { display: inline-flex; align-items: center; gap: 8px; }
.pwa-top .user-logo { height: 28px; max-width: 96px; background: #fff; border-radius: 5px; padding: 2px 4px; }
.pwa-content { max-width: 640px; margin: auto;
  padding: 14px calc(14px + env(safe-area-inset-right, 0px)) 14px calc(14px + env(safe-area-inset-left, 0px)); }
.mission-card { background: #fff; border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; margin-bottom: 12px; display: block; text-decoration: none; color: var(--text); }
.mission-card .t { font-weight: 700; color: var(--violet); font-size: 15.5px; margin-bottom: 3px; }
.mission-card .m { font-size: 13px; color: var(--muted); }
.pwa-nav { position: fixed; bottom: 0; left: 0; right: 0; background: #fff; border-top: 1px solid var(--border); display: flex; z-index: 10;
  padding-bottom: env(safe-area-inset-bottom, 0px); }
.pwa-nav a { flex: 1; text-align: center; padding: 10px 4px 12px; text-decoration: none; color: var(--muted); font-size: 12px; }
.pwa-nav a.active { color: var(--violet); font-weight: 700; box-shadow: inset 0 3px 0 var(--accent); }   /* barre rouge, comme le menu actif */
.pwa-nav .ico { font-size: 19px; display: block; }
.notif-banner { position: fixed; top: calc(60px + env(safe-area-inset-top, 0px)); left: 12px; right: 12px; background: var(--violet); color: #fff; padding: 13px 16px; border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.3); z-index: 50; }
.notif-banner a { color: #fff; font-weight: 700; }

/* ---- Signature ---- */
.sign-pad { border: 2px dashed var(--border); border-radius: 8px; background: #fff; touch-action: none; width: 100%; height: 160px; }

/* ---- Photos ---- */
.thumb { max-width: 130px; max-height: 130px; border-radius: 8px; border: 1px solid var(--border); }
.photo-grid { display: flex; gap: 10px; flex-wrap: wrap; }
.photo-field { margin-top: 5px; }
.photo-buttons { display: flex; gap: 8px; flex-wrap: wrap; }
.photo-buttons .btn { flex: 1; min-width: 130px; }
.photo-preview { margin-top: 8px; }
.photo-preview .thumb { display: block; }

/* ---- Stat tiles ---- */
.tiles { display: flex; gap: 14px; flex-wrap: wrap; margin-bottom: 18px; }
.tile { flex: 1; min-width: 150px; background: #fff; border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px; }
.tile .n { font-size: 26px; font-weight: 700; color: var(--violet); }
.tile .l { font-size: 12.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }

/* ---- Responsive ---- */
@media (max-width: 860px) {
  .app { flex-direction: column; }
  .sidebar { width: 100%; flex-direction: row; align-items: center; overflow-x: auto;
    position: static; height: auto; align-self: auto; overflow-y: visible; }
  .sidebar .brand { padding: 12px 14px; font-size: 17px; white-space: nowrap; }
  .sidebar nav { display: flex; }
  .sidebar nav a { white-space: nowrap; border-left: none; border-bottom: 3px solid transparent; }
  .sidebar nav a.active { border-bottom-color: var(--accent); }
  .sidebar .userbox { border-top: none; white-space: nowrap; }
  .content { padding: 14px; }
  .tbl { display: block; overflow-x: auto; }
}
@media print {
  .sidebar, .topbar, .pwa-nav, .pwa-top, .no-print, .lightbox-overlay { display: none !important; }
  body { background: #fff; }
  .content { padding: 0; max-width: none; }
  .card { border: none; padding: 0; }
}

/* Visionneuse d'images (lightbox) */
.js-zoom { cursor: zoom-in; }
.lightbox-overlay {
  position: fixed; inset: 0; z-index: 1000;
  display: none; align-items: center; justify-content: center;
  padding: 20px; background: rgba(0, 0, 0, .82);
}
.lightbox-overlay.open { display: flex; }
.lightbox-img {
  max-width: 96vw; max-height: 92vh; border-radius: 6px;
  background: #fff; box-shadow: 0 6px 40px rgba(0, 0, 0, .55); cursor: zoom-out;
}
.lightbox-close {
  position: fixed; top: 10px; right: 16px;
  font-size: 38px; line-height: 1; color: #fff;
  background: none; border: none; cursor: pointer; padding: 4px 10px;
}

/* ---- Mentions légales (connexion + bas de page) ---- */
.legal-links { line-height: 1.6; }
.content > .legal-links { margin-top: 22px; padding-top: 12px; border-top: 1px solid var(--border); }

/* ---- Documents légaux (mentions, confidentialité) ---- */
.legal-doc { max-width: 860px; margin: 0 auto; padding: 24px 18px 40px; }
.legal-doc .card h2 { font-size: 16px; margin: 26px 0 10px; padding-bottom: 5px; border-bottom: 1px solid var(--border); }
.legal-doc .card h2:first-of-type { margin-top: 8px; }
.legal-doc h3 { font-size: 14.5px; margin: 18px 0 4px; color: var(--violet-dark); }
.legal-doc p, .legal-doc li { line-height: 1.65; }
.legal-doc ul { padding-left: 20px; }
.legal-doc .tbl { margin: 10px 0 4px; }
.legal-doc .tbl th { text-transform: none; font-size: 13px; color: var(--violet-dark); }
.todo { background: #fff3cd; color: #7a4b00; border: 1px dashed #e0a800; border-radius: 4px;
  padding: 0 5px; font-style: italic; font-size: 13px; }

/* ---- Éditeur de modèles d'email ---- */
.editeur-barre { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; margin-top: 5px;
  border: 1px solid var(--border); border-bottom: 0; border-radius: 7px 7px 0 0; padding: 6px; background: var(--violet-bg); }
.editeur-barre button { background: #fff; border: 1px solid var(--border); border-radius: 5px;
  padding: 4px 9px; font-size: 13px; font-family: inherit; cursor: pointer; color: var(--text); }
.editeur-barre button:hover { background: var(--violet-bg); border-color: var(--violet-light); }
.editeur-barre .sep { width: 1px; height: 20px; background: var(--border); margin: 0 3px; }
.editeur { border: 1px solid var(--border); border-radius: 0 0 7px 7px; padding: 12px 14px; min-height: 180px;
  background: #fff; font-size: 14.5px; line-height: 1.6; overflow-wrap: break-word; }
.editeur:focus { outline: 2px solid var(--violet-light); border-color: var(--violet-light); }
.editeur p { margin: 0 0 10px; }
.vars { display: flex; flex-wrap: wrap; gap: 6px; }
.var-btn { background: var(--violet-bg); border: 1px solid var(--border); border-radius: 5px; padding: 3px 8px;
  font-size: 12.5px; font-family: Consolas, monospace; color: var(--violet); cursor: pointer; }
.var-btn:hover { background: #fff; border-color: var(--violet-light); }

/* ---- Description / consignes d'une mission (mise en avant) ----
   Même teinte que l'encadré .alert-info qui les affiche ensuite sur la fiche
   mission et dans l'application mobile. */
.champ-consignes { font-size: 15px; font-weight: 700; color: var(--violet-dark); }
.champ-consignes textarea {
  background: #ebecee; border-color: #d0d3d7; font-weight: 400; color: var(--text);
}
.champ-consignes textarea:focus { border-color: var(--violet-light); }

/* ---- Sous-titres de section dans un formulaire ---- */
.form-section { font-size: 13px; text-transform: uppercase; letter-spacing: .5px; color: var(--violet);
  border-bottom: 1px solid var(--border); padding-bottom: 5px; margin: 22px 0 10px; }
.logo-apercu { display: inline-flex; align-items: center; gap: 8px; margin-top: 8px;
  border: 1px solid var(--border); border-radius: 7px; padding: 5px 9px; background: #fff; }
.logo-apercu img { height: 34px; max-width: 120px; display: block; }

/* ---- Rappel du message après enregistrement (voir scroll_restore.js) ---- */
.flash-toast { position: fixed; top: 16px; right: 16px; z-index: 1000; max-width: 420px; cursor: pointer;
  box-shadow: 0 10px 30px rgba(0,0,0,.18); border-radius: 8px; transition: opacity .4s, transform .4s; }
.flash-toast .alert { margin: 0; }
.flash-toast .alert + .alert { margin-top: 8px; }
.flash-toast-out { opacity: 0; transform: translateY(-8px); }

/* ---- Fenêtre modale ---- */
.modal-fond { position: fixed; inset: 0; z-index: 1100; background: rgba(20, 22, 25, .55);
  display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal { background: #fff; border-radius: 12px; padding: 22px 24px; width: 520px; max-width: 100%;
  box-shadow: 0 20px 60px rgba(0,0,0,.35); }
.modal h2 { font-size: 18px; margin-bottom: 10px; }

/* ---- Empreinte CO₂ d'une mission (à droite des fichiers joints) ---- */
.fichiers-co2 { display: flex; gap: 16px; align-items: flex-start; flex-wrap: wrap; margin-top: 10px; }
.co2-box { flex: 0 0 auto; min-width: 210px; max-width: 280px; border: 1px solid #cfe8d8; background: #f2faf5;
  border-radius: 8px; padding: 10px 14px; }
.co2-valeur { font-size: 22px; font-weight: 700; color: #1e8e4e; margin: 2px 0 4px; }

/* ---- Aide courte sous un champ (n'allonge pas le libellé) ---- */
.champ-aide { display: block; margin-top: 4px; font-size: 12px; font-weight: 400; color: var(--muted); }

/* ---- Bouton pictogramme (fins de ligne des listes) ----
   Libellé en infobulle, affichée dès le survol (celle du navigateur met une
   seconde à venir) et au focus clavier. Ancrée à droite : en fin de ligne, une
   infobulle centrée déborderait du tableau. aria-label porte le libellé pour
   les lecteurs d'écran. */
.btn-icon { display: inline-flex; align-items: center; justify-content: center; width: 30px; height: 30px;
  padding: 0; position: relative; vertical-align: middle; }
.btn-icon svg { width: 16px; height: 16px; }
.btn-icon[data-tip]:hover::after, .btn-icon[data-tip]:focus-visible::after {
  content: attr(data-tip); position: absolute; bottom: calc(100% + 6px); right: 0;
  background: #222; color: #fff; font-size: 12px; font-weight: 400; line-height: 1.3; white-space: nowrap;
  padding: 5px 8px; border-radius: 5px; z-index: 20; pointer-events: none; }
.actions-ligne { white-space: nowrap; text-align: right; }
.actions-ligne > * + * { margin-left: 4px; }

/* ---- Liste des poseurs : équipe repliable sous le poseur maître ---- */
.equipe-toggle { border: 0; cursor: pointer; font-family: inherit; line-height: inherit; }
.equipe-toggle:hover { filter: brightness(.95); }
.ligne-equipe td { background: #f7f8f8; }
.ligne-equipe td:nth-child(2) { padding-left: 22px; }

/* ---- Fichiers joints d'une mission : encadrés Bon de commande / Autres fichiers ---- */
.fichiers-bloc { border: 1px solid var(--border, #e2e4e6); border-radius: 8px; padding: 12px 14px; margin-top: 12px; }
.fichiers-bloc h3 { margin: 0 0 8px; font-size: 15px; }
/* ---- Moment d'intervention : créneau + heure (si « Heure définie ») ----
   Le bloc tient la place d'un champ de .form-row ; l'heure se range à côté. */
.champ-moment { display: flex; gap: 16px; flex: 1 1 180px; min-width: 0; max-width: 100%; }
.form-row > .champ-moment { flex-basis: 220px; }
.champ-moment > label { flex: 1 1 0; min-width: 0; }
.champ-moment > label[hidden] { display: none; }

/* ---- Liste avec bouton de recherche « … » (poseur d'une mission) ---- */
.select-recherche { display: flex; gap: 6px; align-items: stretch; margin-top: 5px; }   /* marge du champ portée par le bloc */
.select-recherche > select { flex: 1 1 auto; min-width: 0; margin-top: 0; }
.select-recherche > .btn { flex: 0 0 auto; margin: 0; padding: 0 14px; font-weight: 700; letter-spacing: 1px; }
.modal-fond[hidden] { display: none; }
.modal-large { width: 860px; max-height: 90vh; display: flex; flex-direction: column; }
.poseur-recherche-liste { overflow: auto; min-height: 120px; flex: 1 1 auto; }
.poseur-recherche-liste thead th { position: sticky; top: 0; background: #fff; }
.poseur-recherche-ligne { cursor: pointer; }
.poseur-recherche-ligne:hover td, .poseur-recherche-ligne:focus td { background: #f1f2f3; outline: none; }
.poseur-recherche-ligne.actif td { background: #e6e8ea; }