:root {
  --navy: #16273b;
  --bleu: #2563eb;
  --bleu-fonce: #1d4ed8;
  --vert: #15803d;
  --rouge: #dc2626;
  --encre: #1c2430;
  --gris: #64748b;
  --bord: #e2e8f0;
  --fond: #f1f5f9;
  --carte: #ffffff;
  --rayon: 10px;
  --ombre: 0 1px 3px rgba(15, 23, 42, .08), 0 1px 2px rgba(15, 23, 42, .05);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", -apple-system, Roboto, Helvetica, Arial, sans-serif;
  color: var(--encre);
  background: var(--fond);
  font-size: 15px;
  line-height: 1.45;
}

/* ----- Barre haute ----- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  background: linear-gradient(135deg, #16273b 0%, #1e3a5f 100%);
  color: #fff; padding: 14px 28px;
  box-shadow: 0 2px 8px rgba(15, 23, 42, .25);
}
.logo {
  font-weight: 700; letter-spacing: .4px; font-size: 17px;
  display: flex; align-items: center; gap: 12px;
}
.logo-camion { width: 56px; height: 26px; flex: 0 0 auto;
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, .25)); }
.logo-camion .lc-blanc { fill: #fff; }
.logo-camion .lc-vitre { fill: #7aa5f5; }
.logo-camion .lc-chrome { fill: #aebfd4; }
.logo-camion .lc-roue { fill: var(--bleu); }
.logo-camion .lc-moyeu { fill: #fff; }
/* Logo image personnalisé (static/logo-srtp.png) si fourni : tuile carrée
   arrondie (le logo a son propre fond sombre). Fin liseré clair pour le
   détacher du bandeau navy ; sur la feuille blanche, le fond sombre suffit. */
.logo-badge { height: 46px; width: 46px; border-radius: 10px; display: block;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, .22), 0 1px 4px rgba(0, 0, 0, .3); }
.feuille-logo { height: 88px; width: 88px; border-radius: 12px; float: right;
  margin: 0 0 8px 18px; }
.topbar nav a {
  color: #b9c5d4; text-decoration: none; margin-left: 22px; font-weight: 500;
  padding: 6px 2px; border-bottom: 2px solid transparent; transition: color .15s;
}
.topbar nav a:hover { color: #fff; border-bottom-color: var(--bleu); }

main { max-width: 1140px; margin: 28px auto; padding: 0 22px; }

/* ----- Cartes ----- */
.card {
  background: var(--carte); border: 1px solid var(--bord); border-radius: var(--rayon);
  padding: 22px 24px; margin-bottom: 22px; box-shadow: var(--ombre);
}
.card-etroite { max-width: 640px; margin-left: auto; margin-right: auto; }
h1 { font-size: 22px; margin: 0 0 14px; font-weight: 700; }
h2 { font-size: 15px; margin: 0 0 14px; font-weight: 700; text-transform: uppercase;
     letter-spacing: .5px; color: var(--navy); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 22px; }
@media (max-width: 780px) { .grid2 { grid-template-columns: 1fr; } }

/* ----- Formulaires ----- */
.form { display: flex; flex-direction: column; gap: 12px; }
.form .row { display: flex; gap: 12px; align-items: flex-end; }
.form .row > * { flex: 1; }
.form .row.actions { align-items: center; justify-content: flex-start; }
.form .row.actions > * { flex: 0 0 auto; }

input, textarea, select {
  padding: 10px 12px; border: 1.5px solid var(--bord); border-radius: 8px;
  font-size: 14px; font-family: inherit; width: 100%;
  background: #fff; color: var(--encre);
  transition: border-color .15s, box-shadow .15s;
}
input:focus, textarea:focus, select:focus {
  outline: none; border-color: var(--bleu);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .12);
}
input[type=checkbox] { width: auto; margin-right: 8px; padding: 0; accent-color: var(--bleu); }
textarea { min-height: 64px; resize: vertical; }
label { font-size: 13px; color: var(--gris); display: block; font-weight: 500; }
label input, label select { margin-top: 5px; }
label.check { display: flex; align-items: center; color: var(--encre); font-size: 14px; }

button {
  cursor: pointer; border: none; border-radius: 8px; padding: 10px 18px;
  font-size: 14px; background: var(--vert); color: #fff; font-weight: 600;
  font-family: inherit; transition: filter .15s, transform .05s;
}
button:hover { filter: brightness(1.08); }
button:active { transform: translateY(1px); }
.btn-primary { background: var(--bleu); }
.btn-primary:hover { background: var(--bleu-fonce); filter: none; }
.btn-light {
  background: #eef2f7; color: var(--navy); text-decoration: none;
  padding: 9px 16px; border-radius: 8px; font-size: 14px; font-weight: 600;
  display: inline-block; border: 1px solid var(--bord);
}
.btn-light:hover { background: #e2e9f1; }
.btn-small { padding: 5px 12px; font-size: 13px; }
.btn-del { background: transparent; color: var(--rouge); padding: 2px 8px;
  font-size: 17px; line-height: 1; border: 1px solid transparent; border-radius: 6px; }
.btn-del:hover { background: #fee2e2; filter: none; }

.datebar { display: flex; align-items: flex-end; justify-content: space-between;
  gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.datebar .inline { display: inline; }
.inline input[type=date] { width: auto; }

/* ----- Calendrier (vue principale) ----- */
.calendrier { padding: 16px 18px; }
.cal-head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.cal-titre { font-weight: 700; color: var(--navy); font-size: 16px;
  min-width: 160px; text-align: center; }
.cal-nav { text-decoration: none; color: var(--navy); background: #eef2f7;
  border: 1px solid var(--bord); border-radius: 8px; width: 34px; height: 34px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 19px; font-weight: 700; line-height: 1; }
.cal-nav:hover { background: #e2e9f1; }
.cal-aujourdhui { margin-left: auto; }
.cal-grille { table-layout: fixed; }
.cal-grille th { text-align: center; font-size: 11px; padding: 6px 0; border-bottom: none; }
.cal-grille td { padding: 0; border: 1px solid var(--bord); height: 58px; vertical-align: top; }
.cal-grille tbody tr:hover { background: transparent; }
.cal-grille td.cal-vide { background: #f8fafc; border-color: #eef2f7; }
.cal-grille td a { display: flex; flex-direction: column; height: 100%;
  padding: 6px 8px; text-decoration: none; color: var(--encre); }
.cal-grille td a:hover { background: #f1f5f9; }
.cal-num { font-size: 13px; font-weight: 600; color: var(--gris); }
.cal-charge { background: #eff6ff; }
.cal-charge .cal-num { color: var(--bleu-fonce); }
.cal-compte { margin-top: auto; align-self: flex-start; background: var(--bleu);
  color: #fff; font-size: 12px; font-weight: 700; padding: 1px 8px; border-radius: 10px; }
.cal-grue { margin-left: 5px; background: var(--rouge); color: #fff;
  font-size: 10px; font-weight: 800; padding: 0 4px; border-radius: 4px; }
.cal-grille td.cal-sel { outline: 2px solid var(--navy); outline-offset: -2px; }
.cal-grille td.cal-sel a { background: #e8eef6; }
.cal-grille td.cal-sel .cal-num { color: var(--navy); font-weight: 800; }

/* ----- Tableaux ----- */
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--bord); }
th { color: var(--gris); font-weight: 600; font-size: 11.5px; text-transform: uppercase;
     letter-spacing: .6px; }
tbody tr:hover { background: #f8fafc; }
td form { margin: 0; display: inline; }
.cell-actions { white-space: nowrap; }
.cell-actions .btn-light { margin-right: 6px; }

/* ----- Tournées ----- */
.tournee { border: 1px solid var(--bord); border-radius: var(--rayon);
  margin-bottom: 18px; overflow: hidden; background: #fff; }
.tournee-head { display: flex; align-items: center; gap: 14px;
  background: #f1f5f9; padding: 12px 16px; border-bottom: 1px solid var(--bord); }
.tournee-head strong { font-size: 15px; color: var(--navy); }
.tournee-head a { margin-left: auto; }
.tournee-warn .tournee-head { background: #fef2f2; border-bottom-color: #fecaca; }
.tournee-warn .tournee-head strong { color: var(--rouge); }

/* ----- Badges / états ----- */
.muted { color: var(--gris); font-size: 13px; }
.warn-tag {
  display: inline-block; background: #fee2e2; color: var(--rouge);
  font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 5px;
  text-transform: uppercase; letter-spacing: .4px; vertical-align: middle;
}
/* ----- Ecran de chargement (anti double-clic) ----- */
.overlay-chargement {
  display: none; position: fixed; inset: 0; z-index: 9999;
  background: rgba(15, 23, 42, .6); backdrop-filter: blur(2px);
  flex-direction: column; align-items: center; justify-content: center; gap: 18px;
}
.overlay-chargement p { color: #fff; font-weight: 600; font-size: 16px; margin: 0; }
.spinner {
  width: 48px; height: 48px; border: 5px solid rgba(255, 255, 255, .3);
  border-top-color: #fff; border-radius: 50%; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.flash { padding: 12px 16px; border-radius: 8px; margin-bottom: 18px; font-size: 14px;
  border: 1px solid transparent; }
.flash-info { background: #eff6ff; color: #1e40af; border-color: #bfdbfe; }
.flash-warn { background: #fef2f2; color: #991b1b; border-color: #fecaca; }

/* ----- Vérification import PDF ----- */
.bloc-verif {
  border: 1.5px solid var(--bord); border-radius: var(--rayon);
  padding: 16px 18px 18px; margin: 0; display: flex; flex-direction: column; gap: 12px;
  background: #fbfcfe;
}
.bloc-verif legend {
  font-weight: 700; color: var(--navy); padding: 0 8px; font-size: 14px;
}
.bloc-verif legend .warn-tag { margin-left: 8px; }

/* ----- Bons incomplets (à compléter) : ambre, distinct du rouge GRUE ----- */
.warn-manque { background: #fef3c7; color: #92400e; }
a.warn-manque { text-decoration: none; cursor: pointer; }
a.warn-manque:hover { background: #fde68a; }
.bloc-incomplet { border-color: #f59e0b; background: #fffbeb; }
.bloc-incomplet legend { color: #92400e; }
.champ-manque { border-color: #f59e0b; background: #fffbeb; }
.champ-manque::placeholder { color: #b45309; }

/* ----- Feuille de route ----- */
.feuille { background: #fff; border: 1px solid var(--bord); border-radius: var(--rayon);
  padding: 30px; box-shadow: var(--ombre); }
.feuille-head { border-bottom: 3px solid var(--navy); padding-bottom: 16px; margin-bottom: 20px; }
.feuille-meta { display: flex; flex-direction: column; gap: 4px; font-size: 14px; color: #3a4452; }
.feuille-table th { background: var(--navy); color: #fff; }
.feuille-table td { border-bottom: 1px solid var(--bord); vertical-align: top; }
.feuille-table .num { font-weight: 700; }

@media print {
  @page { size: A4; margin: 13mm; }
  body { background: #fff; font-size: 12.5px; }
  .topbar, .noprint, .flash { display: none; }
  main { margin: 0; max-width: 100%; padding: 0; }
  .feuille { border: none; padding: 0; box-shadow: none; }
  tbody tr:hover { background: transparent; }
}

/* ============================================================
   MOBILE / TÉLÉPHONE  (écrans ≤ 640px)
   Adaptation pour l'usage terrain sur smartphone.
   N'affecte ni l'affichage bureau ni l'impression.
   ============================================================ */
@media screen and (max-width: 640px) {

  /* place pour la barre d'onglets + zone tactile bas (home indicator) */
  body { padding-bottom: calc(64px + var(--safe-bottom, env(safe-area-inset-bottom, 0px))); }

  /* ---- Barre haute : logo compact ; on réserve l'espace de la caméra / encoche ----
     viewport-fit=cover (dans base.html) rend env(safe-area-inset-*) non nul.
     --safe-top/left/right ne servent qu'à simuler l'encoche dans l'aperçu. */
  .topbar {
    padding: calc(10px + var(--safe-top, env(safe-area-inset-top, 0px)))
             calc(14px + var(--safe-right, env(safe-area-inset-right, 0px)))
             10px
             calc(14px + var(--safe-left, env(safe-area-inset-left, 0px)));
  }
  .logo { font-size: 13px; gap: 8px; letter-spacing: .2px; }
  .logo-badge { height: 32px; width: 32px; }
  .logo-camion { width: 38px; height: 18px; }

  .topbar nav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 60;
    display: flex; margin: 0;
    background: #16273b;
    border-top: 1px solid rgba(255, 255, 255, .14);
    box-shadow: 0 -3px 12px rgba(15, 23, 42, .3);
    padding-bottom: var(--safe-bottom, env(safe-area-inset-bottom, 0px));
    padding-left: env(safe-area-inset-left, 0px);
    padding-right: env(safe-area-inset-right, 0px);
  }
  .topbar nav a {
    flex: 1; margin: 0; text-align: center;
    padding: 9px 2px 9px; font-size: 10.5px; font-weight: 600;
    color: #aebcce; border-bottom: none; border-top: 3px solid transparent;
  }
  .topbar nav a:hover { color: #fff; border-bottom-color: transparent; }

  /* ---- Contenu ---- */
  main { margin: 14px auto; padding: 0 12px; }
  .card { padding: 16px 14px; border-radius: 12px; margin-bottom: 14px; }
  .card-etroite { max-width: 100%; }
  h1 { font-size: 19px; }
  .grid2 { gap: 14px; }

  /* ---- Formulaires : on empile, 16px pour éviter le zoom auto iOS ---- */
  input, textarea, select { font-size: 16px; padding: 12px; }
  .form { gap: 14px; }
  .form .row { flex-direction: column; align-items: stretch; gap: 14px; }
  .form .row.actions { flex-direction: row; flex-wrap: wrap; }
  .form > button,
  .form .row.actions > button { width: 100%; padding: 14px 18px; font-size: 15px; }
  .form .row.actions > .btn-light { flex: 1; text-align: center; }
  textarea { min-height: 80px; }

  /* ---- Barre de date ---- */
  .datebar { gap: 12px; }
  .datebar > * { flex: 1 1 auto; }

  /* ---- Calendrier : compact mais lisible ---- */
  .calendrier { padding: 12px 8px; }
  .cal-head { gap: 8px; flex-wrap: wrap; }
  .cal-titre { min-width: 0; flex: 1; font-size: 15px; }
  .cal-aujourdhui { font-size: 12px; padding: 7px 11px; }
  .cal-nav { width: 38px; height: 38px; } /* cible tactile */
  .cal-grille th { font-size: 9.5px; padding: 4px 0; }
  .cal-grille td { height: 50px; }
  .cal-grille td a { padding: 4px; }
  .cal-num { font-size: 12px; }
  .cal-compte { font-size: 10.5px; padding: 1px 6px; }
  .cal-grue { font-size: 9px; margin-left: 3px; }

  /* ---- Tableaux d'admin (chauffeurs, stock…) : défilement horizontal ---- */
  .card > table:not(.cal-grille) {
    display: block; width: 100%; overflow-x: auto;
    -webkit-overflow-scrolling: touch; white-space: nowrap;
  }

  /* ---- Tournées du jour & feuille de route : chaque ligne devient une carte ---- */
  .tournee { border: none; background: transparent; overflow: visible; margin-bottom: 18px; }
  .tournee-head {
    flex-wrap: wrap; gap: 8px 12px; border-radius: 10px;
    border: 1px solid var(--bord);
  }
  .tournee-head .muted { flex: 0 0 auto; }
  .tournee-head a { margin-left: 0; }
  .tournee-head a.btn-light,
  .tournee-head a.btn-primary { flex: 1 1 100%; text-align: center; }

  .tournee table, .feuille-table { display: block; }
  .tournee thead, .feuille-table thead { display: none; }
  .tournee tbody, .feuille-table tbody { display: block; }
  .tournee tr, .feuille-table tr {
    display: block; background: #fff;
    border: 1px solid var(--bord); border-radius: 10px;
    padding: 8px 2px; margin-bottom: 10px; box-shadow: var(--ombre);
  }
  .tournee tbody tr:hover, .feuille-table tbody tr:hover { background: #fff; }
  .tournee td, .feuille-table td {
    display: flex; gap: 12px; align-items: baseline;
    border: none; padding: 5px 14px; white-space: normal; font-size: 14px;
  }
  .tournee td::before, .feuille-table td::before {
    content: attr(data-label);
    flex: 0 0 86px; color: var(--gris);
    font-size: 10.5px; font-weight: 700; text-transform: uppercase;
    letter-spacing: .4px; line-height: 1.5;
  }
  /* cellule d'actions : pas de libellé, boutons sur toute la largeur */
  .tournee td.cell-actions { padding-top: 10px; gap: 8px; }
  .tournee td.cell-actions::before { content: none; }
  .tournee td.cell-actions .btn-light { flex: 1; text-align: center; margin: 0; }

  .feuille { padding: 18px 14px; }
  .feuille-logo { height: 56px; width: 56px; margin: 0 0 6px 12px; }
  .feuille-head h1 { font-size: 20px; }

  /* ---- Vérification import ---- */
  .bloc-verif { padding: 14px 14px 16px; }

  .flash { font-size: 13.5px; }
}
