/* ==========================================================================
   Interface tablette (terrain). Couleurs reprises du client de bureau (mêmes noms de
   variables que AzuLib / interface.css), tailles pensées pour le doigt : boutons de 56 px
   au moins, textes de 17 px au moins, libellés jamais plus petits que leur valeur.
   ========================================================================== */

:root {
    --color-a-a: #0d2395;
    --color-a-b: #1b6ec2;
    --couleur-succes: rgb(24 184 20);
    --couleur-succes-fonce: #0f7a0c;
    --couleur-danger: #c00101;
    --couleur-ajout: #261bbf;
    --couleur-sans-ordre: rgb(232 133 28);
    --couleur-texte-titre: #143a5a;
    --couleur-texte-secondaire: #4a5f7a;
    --couleur-fond-bleu-leger: rgb(232 242 251);
    --couleur-bordure: #b9c9e6;
    --couleur-bordure-neutre: #9aa9c2;
    --couleur-palette-attendue: #D9D9D9;
    --couleur-palette-livree: #91FC81;
    /* Plus foncé que le client de bureau (#757575) : palette manquante bien distincte */
    --couleur-palette-manquante: #5f5f5f;
    --fond-carte-livree: #e6fde2;
    --fond-carte-manquante: #dadada;
    --ombre-carte: 0 2px 8px rgba(13, 35, 149, 0.10);
    --degrade-entete: linear-gradient(110deg, var(--color-a-a) 0%, var(--color-a-b) 100%);
    /* Ligne d'en-tête du tableau de la lettre de voiture (bande du dégradé de même hauteur) */
    --hauteur-entete-tableau: 44px;
    /* Badges Livraison et Signature des cartes de dossier : fond gris en cours, vert clair terminé,
       piste blanche de la barre d'avancement */
    --fond-badge-en-cours: #ececec;
    --fond-badge-termine: #c9f5c0;
    --piste-barre-badge: #fff;
    /* Hauteur d'une carte palette : deux rangées entières sous le bandeau du destinataire (écran 1333 × 800) */
    --hauteur-carte-palette: 276px;
    /* Boutons « Palette non prévue » et « Passage à quai » : contour léger de la couleur des ajouts */
    --bordure-action-lot: rgb(38 27 191 / 22%);
    /* Lumière bleue autour de la palette dont le choix d'actions est ouvert */
    --lueur-selection: 0 0 0 1px rgba(56, 140, 222, 0.22), 0 0 15px 4px rgba(56, 140, 222, 0.28);
    /* Fonds très clairs des boutons du choix d'actions, dans la couleur de l'état visé */
    --fond-bouton-livrer: #ecfde8;
    --fond-bouton-manquante: #ececec;
    --fond-bouton-incident: #fdeaea;
    --ombre-bouton: 0 1px 4px rgba(13, 35, 149, 0.22);
    /* Batterie de la tablette : à partir de 40 %, de 20 à 40 %, sous 20 % */
    --couleur-batterie-ok: var(--couleur-palette-livree);
    --couleur-batterie-moyenne: #ffb547;
    --couleur-batterie-faible: #ff7a7a;
    /* Carré d'une palette en attente, plus clair que les barres d'avancement */
    --couleur-carre-attendue: #ececec;
    /* Fond de l'écran de connexion, sous l'en-tête */
    --fond-connexion: #fff;
    /* Ombre légère sous l'en-tête d'une carte palette (nature, expéditeur, carré) : vers le bas seulement */
    --ombre-entete-palette: rgba(76, 76, 78, 0.16);
    /* Bleu clair du destinataire choisi, repris pour le corps des cartes palette en attente */
    --fond-selection: #eef3ff;
    /* En-tête des cartes palette (nature, expéditeur, carré) : blanc quel que soit l'état */
    --fond-entete-palette: #fff;
    /* Alerte « Lettre illisible » (photo de lettre de voiture que l'API n'a pas pu lire) */
    --fond-alerte-lettre: #fff;
    --ombre-alerte-lettre: 0 8px 24px rgba(13, 35, 149, 0.25);
}

html, body {
    margin: 0;
    height: 100%;
    overflow: hidden;
    font-family: 'Inter', 'Helvetica Neue', Helvetica, Arial, sans-serif;
    color: var(--couleur-texte-titre);
    background: var(--couleur-fond-bleu-leger);
    -webkit-tap-highlight-color: transparent;
    overscroll-behavior: none;
}

button, input, textarea, select {
    font-family: inherit;
    color: inherit;
}

h1, h2, h3, p {
    margin: 0;
}

/* ---------- Écran ---------- */

.ecran {
    display: flex;
    flex-direction: column;
    /* Hauteur figée par js/ecran.js : le clavier recouvre le bas de l'écran sans le remonter */
    height: var(--hauteur-ecran, 100dvh);
    overflow: hidden;
}

.ecran-centre {
    align-items: center;
    justify-content: center;
    background: var(--degrade-entete);
}

.corps {
    flex-grow: 1;
    display: flex;
    gap: 20px;
    padding: 18px 24px;
    min-height: 0;
}

.zone-defilante {
    flex-grow: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 14px;
    overflow-y: auto;
    padding: 2px 4px 24px 2px;
}

.carte {
    background: #fff;
    border-radius: 7px;
    box-shadow: var(--ombre-carte);
}

.carte-message {
    display: flex;
    flex-direction: column;
    gap: 24px;
    align-items: center;
    padding: 40px;
}

.etat-vide {
    padding: 40px;
    text-align: center;
    font-size: 19px;
    font-style: italic;
    color: var(--couleur-texte-secondaire);
}

.titre-section {
    font-size: 24px;
    font-weight: 700;
}

/* ---------- En-tête ---------- */

.entete {
    display: flex;
    align-items: center;
    gap: 20px;
    padding: 14px 24px;
    background: var(--degrade-entete);
    color: #fff;
    flex-shrink: 0;
}

/* Côtés du bandeau : gauche (retour, titres) extensible, droite (compteurs, date) à sa taille */
.entete-cote {
    display: flex;
    align-items: center;
    gap: 20px;
    flex: 1 1 auto;
    min-width: 0;
}

.entete-cote-droit {
    flex: 0 0 auto;
    justify-content: flex-end;
}

/* Avec le logo : deux côtés de même largeur, le logo reste au centre du bandeau
   (un titre trop long passe à la ligne dans sa moitié au lieu de pousser le logo) */
.entete-avec-logo .entete-cote {
    flex: 1 1 0;
}

.entete-retour {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 56px;
    height: 56px;
    flex-shrink: 0;
    border-radius: 7px;
    background: rgba(255, 255, 255, 0.18);
    color: #fff;
}

/* Logo en blanc directement sur le dégradé bleu (l'original gris et noir y est illisible), même hauteur que
   le retour. Image recadrée et pré-réduite (480 px) : l'original HD réduit par le navigateur crénelle les contours */
.entete-logo {
    display: flex;
    align-items: center;
    height: 56px;
    flex-shrink: 0;
    box-sizing: border-box;
    padding: 6px 0;
}

.entete-logo img {
    display: block;
    height: 100%;
    width: auto;
}

.entete-titres {
    flex-grow: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.entete-ligne {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.entete-titre {
    font-size: 24px;
    font-weight: 600;
    letter-spacing: -0.03em;
}

.entete-badge {
    background: rgba(255, 255, 255, 0.22);
    border-radius: 7px;
    padding: 4px 14px;
    font-size: 17px;
    font-weight: 500;
}

.entete-sous-titre {
    font-size: 16px;
    opacity: 0.9;
}

.entete-droite {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

.compteur {
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 88px;
    padding: 6px 10px;
    border-radius: 7px;
    background: rgba(255, 255, 255, 0.16);
}

.compteur-valeur {
    font-size: 26px;
    font-weight: 700;
}

.compteur-libelle {
    font-size: 15px;
    opacity: 0.9;
}

/* ---------- File d'envoi (en-tête, à gauche de la date) ---------- */

.etat-envois {
    position: relative;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.etat-envois-pastille {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 40px;
    padding: 0 12px;
    box-sizing: border-box;
    border: none;
    border-radius: 7px;
    background: rgba(255, 255, 255, 0.18);
    color: #fff;
    font-family: inherit;
    font-size: 17px;
    font-weight: 600;
    white-space: nowrap;
}

/* Envoi refusé : pastille blanche, texte rouge, touchable (liste des échecs) */
.etat-envois-echec {
    min-height: 48px;
    background: #fff;
    color: var(--couleur-danger);
    cursor: pointer;
}

.etat-envois-echec .icone-incident { margin-top: 0; }

.etat-envois-liste {
    position: absolute;
    top: calc(100% + 10px);
    right: 0;
    z-index: 20;
    width: 460px;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 14px;
    border-radius: 7px;
    background: #fff;
    color: var(--couleur-texte-titre);
    box-shadow: 0 8px 24px rgba(13, 35, 149, 0.25);
}

.etat-envois-ligne {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

/* ---------- Date, heure et batterie (coin supérieur droit) ---------- */

.etat-appareil {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
    flex-shrink: 0;
    color: #fff;
    line-height: 1.15;
}

.etat-appareil-date { font-size: 17px; opacity: 0.9; }
.etat-appareil-heure { font-size: 24px; font-weight: 700; }

/* Pile à gauche du pourcentage, sans fond ni marge : alignée sur la date et l'heure */
.batterie {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 17px;
    font-weight: 700;
    white-space: nowrap;
}

.batterie-pourcent { font-size: 13px; margin-left: 1px; }

.batterie-ok { color: var(--couleur-batterie-ok); }
.batterie-moyenne { color: var(--couleur-batterie-moyenne); }
.batterie-faible { color: var(--couleur-batterie-faible); }

/* ---------- Boutons ---------- */

.bouton {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    min-height: 56px;
    padding: 0 20px;
    border-radius: 7px;
    border: 2px solid transparent;
    box-sizing: border-box;
    font-size: 18px;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    user-select: none;
    background: #fff;
}

/* bouton-inactif : lien ou étiquette sans attribut disabled (Photo, Numérique sans palette livrée à signer) */
.bouton:disabled,
.bouton-inactif {
    opacity: 0.35;
    cursor: not-allowed;
}

.bouton-principal { background: var(--color-a-a); border-color: var(--color-a-a); color: #fff; }
.bouton-secondaire { background: #fff; border-color: var(--color-a-a); color: var(--color-a-a); }
.bouton-neutre { background: #fff; border-color: var(--couleur-bordure-neutre); color: var(--couleur-texte-titre); }
.bouton-incident { background: var(--couleur-danger); border-color: var(--couleur-danger); color: #fff; }
.bouton-danger-contour { background: #fff; border-color: var(--couleur-danger); color: var(--couleur-danger); }
.bouton-lien { background: transparent; color: var(--color-a-a); padding: 0 12px; }
.bouton-pointille { background: transparent; border: 2px dashed var(--color-a-b); color: var(--color-a-a); }
.bouton-entete { background: transparent; border-color: rgba(255, 255, 255, 0.7); color: #fff; }

.bouton-grand { min-height: 72px; font-size: 20px; }

.bouton-carre {
    width: 56px;
    min-width: 56px;
    padding: 0;
}

/* ---------- Champs ---------- */

.libelle {
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: 17px;
    font-weight: 700;
}

.champ {
    box-sizing: border-box;
    width: 100%;
    height: 56px;
    padding: 0 14px;
    border-radius: 7px;
    border: 1px solid var(--couleur-bordure);
    background: #fff;
    font-size: 18px;
    font-weight: 400;
}

textarea.champ {
    height: auto;
    padding: 12px 14px;
    resize: none;
}

.champ:focus {
    outline: 3px solid rgba(27, 110, 194, 0.35);
    border-color: var(--color-a-b);
}

/* ---------- Champ avec liste de propositions (ChampSuggestions) ---------- */

.champ-suggestions {
    position: relative;
}

/* Champ au-dessus de la liste : son contour de sélection reste visible */
.champ-suggestions .champ {
    position: relative;
    z-index: 2;
}

.champ-suggestions-ouvert {
    z-index: 5;
}

/* Cadre de la liste, sous le champ, commencé un peu avant son bas (caché par les coins arrondis du champ).
   Marge transparente en bas : comptée dans le défilement de la zone (la liste n'est plus rognée en bas de
   page, son ombre comprise) ; elle laisse passer les touchers. */
.suggestions-cadre {
    position: absolute;
    left: 0;
    right: 0;
    top: calc(100% - 12px);
    z-index: 1;
    padding-bottom: 16px;
    pointer-events: none;
}

.suggestions {
    pointer-events: auto;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    max-height: 300px;
    overflow-y: auto;
    padding-top: 12px;
    border: 1px solid var(--couleur-bordure);
    border-top: none;
    border-radius: 0 0 7px 7px;
    background: #fff;
    box-shadow: 0 8px 18px rgba(13, 35, 149, 0.18);
}

.suggestion {
    flex-shrink: 0;
    min-height: 52px;
    padding: 0 14px;
    border: none;
    border-top: 1px solid #eef2f8;
    background: #fff;
    color: var(--couleur-texte-titre);
    font-size: 18px;
    font-weight: 400;
    text-align: left;
    cursor: pointer;
}

.suggestion:first-child { border-top: none; }

.suggestion-manuelle {
    font-style: italic;
    font-weight: 600;
    color: var(--color-a-a);
}

.message-erreur {
    padding: 12px 16px;
    border-radius: 7px;
    background: #fde8e8;
    color: #8a0000;
    font-size: 17px;
}

/* ---------- Connexion ---------- */

/* Sous l'en-tête commun : fond blanc, cadre centré (les marges automatiques de la saisie l'emportent) */
.connexion-corps {
    flex-grow: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: var(--fond-connexion);
}

.connexion {
    width: 620px;
    max-width: calc(100% - 32px);
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    gap: 26px;
    padding: 36px 40px 40px;
    border-radius: 7px;
    background: #fff;
    box-shadow: 0 12px 40px rgba(6, 0, 88, 0.35);
}

.connexion .libelle { font-size: 22px; }
.connexion .champ { height: 64px; font-size: 22px; }

/* Saisie en cours (champ ou bouton touché) : le clavier recouvre le bas de l'écran sans rien remonter
   (voir js/ecran.js). Le cadre remonte sous l'en-tête (la marge automatique l'emporte sur le centrage) et se
   resserre : en-tête (84 px), champ et bouton tiennent dans les 330 px du haut. */
.connexion:focus-within {
    margin-top: 16px;
    margin-bottom: auto;
    gap: 16px;
    padding: 20px 32px 24px;
}

/* ---------- Liste des dossiers ---------- */

.barre-outils {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 16px;
    padding: 18px 24px 8px;
    flex-shrink: 0;
}

.recherche .champ { width: 380px; }

.grille-dossiers {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(460px, 1fr));
    gap: 18px;
    align-content: start;
    padding: 8px 24px 28px;
    overflow-y: auto;
    flex-grow: 1;
}

.carte-dossier {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: 16px;
    padding: 18px 20px;
    text-decoration: none;
    color: inherit;
}

/* Bas de carte : badge d'avancement (livraison puis signature) à gauche, sur 50 % de la carte ;
   badge Incident en bas à droite */
.cd-bas {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 12px;
}

/* Badge d'avancement : deux parties (Livraison, Signature), chacune avec libellé et valeur aux deux bouts
   et sa barre sur toute la largeur dessous */
.badge-avancement {
    width: 50%;
    min-width: 0;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 10px 14px;
    border-radius: 7px;
    font-size: 17px;
    font-weight: 600;
}

.badge-avancement-partie {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.badge-avancement-ligne {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    white-space: nowrap;
}

.badge-avancement-valeur {
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.badge-avancement .barre-avancement {
    flex-grow: 0;
    height: 10px;
    background: var(--piste-barre-badge);
}

/* Fond gris tant que livraison et signature ne sont pas toutes deux terminées, vert ensuite ;
   barres vertes (manquantes en gris foncé) */
.badge-avancement-en-cours { background: var(--fond-badge-en-cours); }
.badge-avancement-termine { background: var(--fond-badge-termine); }

.badge-signature {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 3px;
    padding: 8px 14px;
    border-radius: 7px;
    background: var(--color-a-b);
    color: #fff;
    font-size: 17px;
    font-weight: 600;
    white-space: nowrap;
}

.badge-signature-recue {
    background: var(--couleur-succes-fonce);
}

.cd-ligne {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
}

.cd-agence {
    font-size: 21px;
    font-weight: 700;
}

.cd-detail {
    font-size: 17px;
    color: var(--couleur-texte-secondaire);
}

/* Haut à droite de la carte : mentions puis état du dossier dessous, alignés à droite */
.cd-droite {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 8px;
    flex-shrink: 0;
}

/* « Sans ordre » et code mission, en texte gras (sans badge) */
.cd-mentions {
    display: flex;
    gap: 14px;
    flex-shrink: 0;
}

.cd-mention {
    font-size: 17px;
    font-weight: 700;
    color: var(--couleur-texte-titre);
    white-space: nowrap;
}

.pastille {
    padding: 6px 12px;
    border-radius: 7px;
    font-size: 16px;
    font-weight: 600;
    white-space: nowrap;
}

/* État d'un dossier (carte de la liste) : en attente (gris), en cours (bleu), terminé (vert clair) */
.pastille-etat-attente { background: var(--fond-badge-en-cours); color: var(--couleur-texte-titre); }
.pastille-etat-en-cours { background: var(--color-a-b); color: #fff; }
.pastille-etat-termine { background: var(--fond-badge-termine); color: var(--couleur-texte-titre); }

.pastille-sans-ordre { background: var(--couleur-sans-ordre); color: #fff; }
/* Libellé et nombre d'incidents, séparés */
.pastille-incident { display: inline-flex; gap: 10px; background: var(--couleur-danger); color: #fff; }


/* ---------- Barre d'avancement ---------- */

.barre-avancement {
    flex-grow: 1;
    display: flex;
    width: 100%;
    height: 12px;
    border-radius: 7px;
    overflow: hidden;
    background: var(--couleur-palette-attendue);
}

.barre-livree { background: var(--couleur-succes); }
.barre-manquante { background: var(--couleur-palette-manquante); }

/* ---------- Colonne des destinataires (lots) ---------- */

.colonne-lots {
    width: 250px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 12px;
    overflow-y: auto;
    /* Marges qui laissent la place à la lumière du destinataire choisi, compensées : rien ne bouge */
    padding: 18px;
    margin: -16px;
}

.bouton-lot {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
    width: 100%;
    padding: 14px 16px;
    border-radius: 7px;
    border: 2px solid transparent;
    background: #fff;
    box-shadow: var(--ombre-carte);
    text-align: left;
    cursor: pointer;
    transition: box-shadow 0.4s ease;
}

.bouton-lot-actif {
    background: var(--fond-selection);
    box-shadow: var(--lueur-selection);
}

/* Sous les destinataires */
/* « + Palette non prévue » et « + Passage à quai » : même forme, fond et texte que les cases destinataire au-dessus ;
   contour et carré « + » de la couleur des ajouts pour se lire comme un bouton ; texte aligné à gauche : les « + »
   sont alignés d'un bouton à l'autre */
.bouton-action-lot {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    min-height: 64px;
    padding: 12px 14px;
    box-sizing: border-box;
    border-radius: 7px;
    border: 1px solid var(--bordure-action-lot);
    background: #fff;
    box-shadow: var(--ombre-carte);
    color: var(--couleur-texte-titre);
    font-family: inherit;
    /* 16 px (sous le minimum de 17 px, à la demande) : « Palette non prévue » tient sur une ligne */
    font-size: 16px;
    font-weight: 700;
    text-align: left;
    cursor: pointer;
    transition: box-shadow 0.15s ease, transform 0.15s ease;
}

/* « Commencer » en tête de la colonne des destinataires, tant que le dossier n'est pas commencé */
.bouton-commencer {
    flex-shrink: 0;
    width: 100%;
}

.bouton-action-lot:active {
    box-shadow: none;
    transform: translateY(1px);
}

.action-lot-signe {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 7px;
    background: var(--couleur-ajout);
    color: #fff;
    font-size: 24px;
    font-weight: 600;
    line-height: 1;
}

.lot-nom { font-size: 19px; font-weight: 700; }

/* Nom et panneau d'incident d'un passage à quai */
.lot-ligne {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 8px;
    width: 100%;
}

.lot-ligne .icone-incident { margin-top: 0; }
.lot-compte { font-size: 16px; color: var(--couleur-texte-secondaire); }
.lot-lettre { font-size: 16px; font-weight: 600; color: var(--color-a-a); }
.lot-lettre-signee { color: var(--couleur-succes-fonce); }

.titre-lot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.titre-lot-texte {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

/* Photo ou Numérique, à la place du bouton « Signature » */
.choix-signature {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

/* Photo de la lettre de voiture avant l'envoi : entière, dans la hauteur de la fenêtre */
.apercu-lettre {
    display: block;
    width: 100%;
    max-height: 520px;
    object-fit: contain;
    border-radius: 7px;
    background: var(--couleur-fond-bleu-leger);
}

/* « Signature » suivi de ses deux façons de signer */
.choix-signature-libelle {
    font-size: 19px;
    font-weight: 700;
}

.choix-signature-titre {
    display: flex;
    flex-direction: column;
    line-height: 1.2;
}

.choix-signature-detail {
    font-size: 17px;
    color: var(--couleur-texte-secondaire);
    white-space: nowrap;
}

.resume {
    font-size: 17px;
    color: var(--couleur-texte-secondaire);
}

/* ---------- Cartes palette (livraison) ---------- */

/* Marges qui laissent la place à la lumière de la palette ouverte (sinon coupée par le défilement) */
/* Les cartes défilent sous le bandeau du destinataire (fixe) et s'effacent en fondu sous lui et en bas de la zone */
.zone-palettes {
    padding: 0 18px 24px 18px;
    -webkit-mask-image: linear-gradient(to bottom, #000 calc(100% - 28px), transparent);
    mask-image: linear-gradient(to bottom, #000 calc(100% - 28px), transparent);
}

/* Bandeau du destinataire (infos et boutons de signature) : fixe en haut, sur toute la largeur de la zone */
.zone-palettes > .titre-lot {
    position: sticky;
    top: 0;
    z-index: 3;
    margin: 0 -18px;
    padding: 4px 18px 6px;
    background: var(--couleur-fond-bleu-leger);
}

/* Fondu sous le bandeau : les cartes disparaissent progressivement en passant dessous */
.zone-palettes > .titre-lot::after {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    top: 100%;
    height: 14px;
    background: linear-gradient(var(--couleur-fond-bleu-leger), transparent);
    pointer-events: none;
}

.grille-palettes {
    /* Repère des positions relevées par js/grille.js */
    position: relative;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 14px;
}

/* Hauteur minimale : le menu qui recouvre la carte garde des boutons de 56 px
   (Livrer 1,5 fois plus haut + 3 boutons, 3 écarts de 8 px, marges de 10 px) */
.carte-palette {
    position: relative;
    min-height: var(--hauteur-carte-palette);
    cursor: pointer;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 14px;
    border-radius: 7px;
    box-shadow: var(--ombre-carte);
    background: var(--fond-selection);
    transition: box-shadow 0.4s ease;
}

.carte-palette-active { box-shadow: var(--lueur-selection); }

.carte-palette-livree { background: var(--fond-carte-livree); }
.carte-palette-manquante { background: var(--fond-carte-manquante); }

/* En-tête de la carte (nature, expéditeur, carré) : blanc quel que soit l'état (le corps porte la couleur de l'état), bord à bord, sans arrondi en bas,
   ombre légère sous sa limite (::after, sur toute la largeur de la carte : une box-shadow à étalement négatif
   s'arrêtait avant les bords). Coins du haut arrondis comme la carte (sinon ils dépassent de la carte). */
.cp-tete {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin: -14px -14px 4px;
    padding: 14px 14px 10px;
    border-radius: 7px 7px 0 0;
    background: var(--fond-entete-palette);
}

.cp-tete::after {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    top: 100%;
    height: 6px;
    background: linear-gradient(var(--ombre-entete-palette), transparent);
    pointer-events: none;
}

.cp-entete {
    display: flex;
    align-items: flex-start;
    gap: 10px;
}

.cp-nature {
    flex-grow: 1;
    min-width: 0;
    font-size: 24px;
    font-weight: 800;
    line-height: 1.2;
    color: var(--couleur-texte-titre);
    /* Nature et compléments (« Raisin + Fenouil ») : deux lignes au plus, « … » au-delà */
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    overflow: hidden;
    overflow-wrap: anywhere;
}

.cp-expediteur {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    /* Une ligne en général ; deux au plus (les cartes ne sont alors plus alignées, accepté) */
    line-height: 1.25em;
    /* Majuscule en début de chaque mot, le reste en minuscules : fait par la page (MotsCapitalises) */
    font-size: 18px;
    font-weight: 700;
}

.cp-ligne-taille {
    display: flex;
    align-items: end;
    justify-content: space-between;
    gap: 8px;
    min-height: 40px;
}

.cp-taille { font-size: 19px; font-weight: 700; }

/* Bas de carte : type et nombre de palettes, puis l'état (et sa date) */
.cp-bas {
    margin-top: auto;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.cp-etat {
    font-size: 18px;
    font-weight: 700;
    color: var(--couleur-texte-secondaire);
}

/* Panneau d'incident : ouvre la liste des incidents, sans ouvrir le choix des actions */
.cp-voir-incidents {
    flex-shrink: 0;
    display: flex;
    margin: -6px;
    padding: 6px;
    border: none;
    background: transparent;
    cursor: pointer;
}

/* Choix des actions : colonne qui recouvre toute la carte, Livrer 1,5 fois plus haut */
.cp-menu {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 10px;
    border-radius: 7px;
    background: #fff;
    cursor: default;
    z-index: 2;
}

/* Bouton blanc ombré, carré de l'état visé à gauche (comme le menu palette du client de bureau),
   libellé centré : marges égales des deux côtés */
.cp-bouton {
    position: relative;
    flex: 1 1 0;
    min-height: 56px;
    padding: 0 52px;
    border: none;
    background: #fff;
    box-shadow: var(--ombre-bouton);
    color: var(--couleur-texte-titre);
}

.cp-bouton-carre {
    position: absolute;
    left: 16px;
    top: 50%;
    transform: translateY(-50%);
    width: 22px;
    height: 22px;
    box-sizing: border-box;
    border-radius: 7px;
    border: 1px solid rgba(0, 0, 0, 0.12);
}

.cp-bouton-carre-incident { background: var(--couleur-danger); }

.cp-bouton-livrer { background: var(--fond-bouton-livrer); }
.cp-bouton-manquante { background: var(--fond-bouton-manquante); }
.cp-bouton-incident { background: var(--fond-bouton-incident); }

.cp-menu .cp-menu-livrer { flex-grow: 1.5; }


/* Carré d'état d'une palette */
.carre-palette {
    position: relative;
    flex-shrink: 0;
    width: 48px;
    height: 48px;
    border-radius: 7px;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    font-weight: 700;
    color: var(--couleur-ajout);
}

.carre-attendue { background: var(--couleur-carre-attendue); }
.carre-livree { background: var(--couleur-palette-livree); }
.carre-manquante { background: var(--couleur-palette-manquante); }

.icone-incident {
    flex-shrink: 0;
    margin-top: 7px;
}

/* ---------- Fenêtre superposée ---------- */

.voile {
    position: fixed;
    inset: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(6, 0, 88, 0.45);
}

.fenetre {
    width: 640px;
    max-width: calc(100% - 32px);
    max-height: calc(100% - 64px);
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    gap: 14px;
    padding: 22px 24px;
    border-radius: 7px;
    background: #fff;
    box-shadow: 0 12px 40px rgba(6, 0, 88, 0.35);
    overflow-y: auto;
}

/* Fenêtre courte à champs à propositions (palette non prévue, nouveau passage à quai) : sans défilement, la
   liste des propositions dépasse de la fenêtre au lieu d'y être coupée */
.fenetre-debordante {
    overflow: visible;
}

/* Deux fenêtres côte à côte (palette non prévue, palettes manquantes) */
.fenetres-cote {
    display: flex;
    gap: 20px;
    width: calc(100% - 32px);
    max-width: 1280px;
    max-height: calc(100% - 64px);
}

.fenetres-cote .fenetre {
    flex: 1 1 0;
    width: auto;
    max-width: none;
    max-height: none;
    min-width: 0;
    min-height: 0;
}

.liste-manquantes {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.ligne-manquante {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
    padding: 12px 16px;
    border-radius: 7px;
    border: none;
    background: #fff;
    box-shadow: var(--ombre-bouton);
    font-size: 17px;
    text-align: left;
    cursor: pointer;
}

.ligne-manquante:disabled { opacity: 0.35; }
.ligne-manquante-titre { font-size: 19px; font-weight: 700; color: var(--color-a-a); }
.ligne-manquante-dossier { color: var(--couleur-texte-secondaire); }

.resume-incident {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.fenetre-choix {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.fenetre-choix .bouton {
    justify-content: flex-start;
    text-align: left;
}

/* ---------- Incident ---------- */

.entete-incident { background: var(--couleur-danger); }

.colonnes {
    display: flex;
    gap: 24px;
    flex-grow: 1;
    min-height: 0;
    padding: 22px 24px;
}

.colonne {
    flex: 1 1 0;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 14px;
    overflow-y: auto;
}

.grille-photos {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
}

.vignette {
    position: relative;
    height: 140px;
    border-radius: 7px;
    overflow: hidden;
    background: #c7d3e6;
}

/* Roue de chargement derrière la photo : visible tant que l'image n'est pas affichée (ou case d'attente) */
.vignette::before {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    width: 34px;
    height: 34px;
    margin: -17px 0 0 -17px;
    box-sizing: border-box;
    border-radius: 50%;
    border: 4px solid rgba(255, 255, 255, 0.6);
    border-top-color: var(--color-a-a);
    animation: rotation 0.8s linear infinite;
}

.vignette img {
    position: relative;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Roue de chargement (écran d'attente de la photo, envoi) */
.roue {
    display: inline-block;
    flex-shrink: 0;
    width: 56px;
    height: 56px;
    box-sizing: border-box;
    border-radius: 50%;
    border: 6px solid var(--couleur-fond-bleu-leger);
    border-top-color: var(--color-a-a);
    animation: rotation 0.8s linear infinite;
}

@keyframes rotation {
    to { transform: rotate(360deg); }
}

.fenetre-chargement {
    width: 480px;
    align-items: center;
    gap: 20px;
    padding: 32px 24px 24px;
    text-align: center;
}

.vignette-retirer {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: none;
    background: rgba(6, 0, 88, 0.7);
    color: #fff;
    font-size: 22px;
    cursor: pointer;
}

/* Champ fichier caché, déclenché par son libellé (bouton) */
.fichier-cache {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
    overflow: hidden;
}

.puces {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.puce {
    min-height: 52px;
    padding: 0 18px;
    border-radius: 7px;
    border: 2px solid var(--color-a-b);
    background: #fff;
    color: var(--color-a-a);
    font-size: 17px;
    font-weight: 600;
    cursor: pointer;
}

.puce-active {
    background: var(--color-a-a);
    border-color: var(--color-a-a);
    color: #fff;
}

.encart {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 14px 16px;
    border-radius: 7px;
    background: var(--couleur-fond-bleu-leger);
    font-size: 17px;
}

.pied {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 14px;
    padding: 14px 24px;
    background: #fff;
    box-shadow: 0 -2px 12px rgba(13, 35, 149, 0.12);
    flex-shrink: 0;
}

.pied-message {
    flex-grow: 1;
}

/* ---------- Nouveau dossier ---------- */

.colonne-dossier {
    width: 340px;
    flex-shrink: 0;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding: 20px;
    overflow-y: auto;
}

.bloc-total {
    margin-top: auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 16px 18px;
    border-radius: 7px;
    background: var(--color-a-a);
    color: #fff;
}

.bloc-total-titre { font-size: 22px; font-weight: 700; }

.bloc-total-ligne {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    font-size: 19px;
}

.bloc-total-valeur { font-size: 30px; font-weight: 700; }

/* « Ajouter un destinataire » aligné sur « Ajouter une livraison » (marge intérieure des cartes) */
.bouton-ajout-lot {
    align-self: flex-start;
    margin-left: 20px;
}

/* Signalement, Fermer, Enregistrer */
.grille-trois-boutons {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
}

.carte-lot-saisie {
    display: flex;
    flex-direction: column;
    gap: 14px;
    padding: 18px 20px;
}

.ligne-destinataire {
    display: flex;
    align-items: flex-end;
    gap: 14px;
}

.grille-livraison {
    display: grid;
    grid-template-columns: minmax(0, 2fr) minmax(0, 1.3fr) 196px 216px 56px;
    gap: 12px;
    align-items: center;
}

.grille-livraison-entete {
    font-size: 17px;
    font-weight: 700;
}

.compteur-saisie {
    display: flex;
    align-items: center;
    gap: 8px;
}

.compteur-saisie-valeur {
    width: 62px;
    text-align: center;
    font-size: 21px;
    font-weight: 700;
}

.bouton-rond {
    width: 48px;
    height: 48px;
    border-radius: 7px;
    border: 2px solid var(--color-a-b);
    background: #fff;
    color: var(--color-a-a);
    font-size: 24px;
    font-weight: 700;
    cursor: pointer;
}

.bascule {
    display: flex;
}

.bascule button {
    flex: 1 1 0;
    height: 52px;
    border: 2px solid var(--color-a-b);
    background: #fff;
    color: var(--color-a-a);
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
}

.bascule button:first-child { border-radius: 7px 0 0 7px; }
.bascule button:last-child { border-radius: 0 7px 7px 0; border-left: none; }

.bascule .bascule-active {
    background: var(--color-a-a);
    border-color: var(--color-a-a);
    color: #fff;
}

.bouton-retirer-ligne {
    width: 56px;
    height: 56px;
    border-radius: 7px;
    border: none;
    background: var(--couleur-fond-bleu-leger);
    color: var(--couleur-danger);
    font-size: 26px;
    cursor: pointer;
}

/* ---------- Lettre de voiture ---------- */

.colonne-signature {
    width: 440px;
    flex-shrink: 0;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 16px 18px;
    overflow-y: auto;
}

.titre-bloc {
    font-size: 18px;
    font-weight: 700;
    color: var(--color-a-a);
}

.valeur-forte { font-size: 18px; font-weight: 700; }
.valeur { font-size: 17px; }

.grille-deux {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
}

.grille-quatre {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 10px;
}

.bloc {
    padding: 14px 16px;
}

.pile {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.pile-centree {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}

.tableau {
    width: 100%;
    border-collapse: collapse;
    font-size: 17px;
}

/* En-tête : cellules transparentes, hauteur fixe. Le dégradé est peint d'un seul tenant derrière elles
   (.tableau-defilant::before) : peint par la ligne ou par chaque cellule, il laissait un fin trait blanc
   à chaque changement de colonne (bords de cellule entre deux pixels à l'échelle 1,5 de la tablette). */
.tableau th {
    box-sizing: border-box;
    height: var(--hauteur-entete-tableau);
    padding: 0 12px;
    background: transparent;
    color: #fff;
    text-align: left;
    vertical-align: middle;
    font-size: 17px;
}

.tableau td {
    padding: 6px 12px;
}

.tableau tbody tr:nth-child(odd) { background: #fff; }
.tableau tbody tr:nth-child(even) { background: #efefef; }

/* Ligne décochée : grisée, hors du total (la case reste nette pour la recocher) */
.tableau tbody tr.ligne-decochee { background: #dcdcdc; }
.tableau tbody tr.ligne-decochee td:not(.colonne-case) { opacity: 0.4; }

.colonne-case {
    width: 56px;
    text-align: center;
}

.case {
    width: 32px;
    height: 32px;
    margin: 0;
    accent-color: var(--color-a-a);
    cursor: pointer;
}

/* Colonne qui ne défile pas : le tableau prend la place restante et fait défiler ses lignes */
.colonne-fixe {
    flex-grow: 1;
    min-width: 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.carte-tableau {
    flex: 1 1 0;
    min-height: 160px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.tableau-defilant {
    flex: 1 1 0;
    min-height: 0;
    overflow-y: auto;
}

/* Bande du dégradé de l'en-tête, fixe en haut de la zone qui défile, sous les intitulés et au-dessus
   des lignes qui passent dessous (marge négative : elle ne décale pas le tableau) */
.tableau-defilant::before {
    content: "";
    display: block;
    position: sticky;
    top: 0;
    z-index: 1;
    height: var(--hauteur-entete-tableau);
    margin-bottom: calc(-1 * var(--hauteur-entete-tableau));
    background: var(--degrade-entete);
}

/* En-tête fixe pendant le défilement des lignes */
.tableau-defilant thead {
    position: sticky;
    top: 0;
    z-index: 2;
}

/* Panneau d'incident de la ligne (vide sans incident) */
.colonne-incident {
    width: 54px;
    text-align: center;
}

.colonne-incident .icone-incident {
    display: inline-block;
    margin-top: 0;
    vertical-align: middle;
}

.grille-trois {
    display: grid;
    grid-template-columns: minmax(0, 1.3fr) minmax(0, 1.3fr) minmax(0, 1fr);
    gap: 12px 18px;
    align-items: end;
}

.grille-trois .pile {
    align-self: start;
}

.pile-espacee {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.tableau .nombre { text-align: right; }

.tableau-pied {
    display: flex;
    justify-content: flex-end;
    padding: 10px 12px;
    border-top: 1px solid #e3eefd;
    font-size: 17px;
    font-weight: 700;
}

.bouton-info-ligne {
    width: 48px;
    height: 48px;
    border-radius: 7px;
    border: 2px solid var(--color-a-b);
    background: #fff;
    color: var(--color-a-a);
    font-size: 22px;
    font-weight: 700;
    cursor: pointer;
}

/* Bloc de la signature : prend la hauteur laissée libre par le nom du réceptionnaire, les réserves,
   les mentions et le bouton, pour que la colonne ne déborde pas (canvas dimensionné à l'ouverture) */
.pile-signature {
    flex: 1 1 auto;
    min-height: 0;
}

.zone-signature {
    position: relative;
    flex: 1 1 auto;
    min-height: 150px;
    max-height: 220px;
    border-radius: 7px;
    border: 2px dashed var(--color-a-b);
    background: #f6f9ff;
    overflow: hidden;
}

.zone-signature canvas {
    width: 100%;
    height: 100%;
    touch-action: none;
    display: block;
}

.zone-signature-invite {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 19px;
    color: var(--couleur-texte-secondaire);
    pointer-events: none;
}

.mentions {
    font-size: 13px;
    line-height: 1.4;
    color: var(--couleur-texte-secondaire);
}

/* ---- Alerte « Lettre illisible » (AlerteLettres), en haut à droite sous l'en-tête ---- */
.alertes-lettres {
    position: fixed;
    top: 96px;
    right: 24px;
    z-index: 40;
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: 420px;
}

.alerte-lettre {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 12px 12px 12px 16px;
    border-left: 6px solid var(--couleur-danger);
    border-radius: 7px;
    background: var(--fond-alerte-lettre);
    color: var(--couleur-texte-titre);
    box-shadow: var(--ombre-alerte-lettre);
}

.alerte-lettre .pile { flex-grow: 1; min-width: 0; }
.alerte-lettre .valeur-forte { color: var(--couleur-danger); }

.alerte-lettre-fermer {
    flex-shrink: 0;
    width: 56px;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: 7px;
    background: transparent;
    color: var(--couleur-texte-titre);
    cursor: pointer;
}
