:root {
  --primaire: #1e40af;
  --primaire-fonce: #1e3a8a;
  --primaire-clair: #eff4ff;
  --accent: #f97316;
  --texte: #111827;
  --doux: #6b7280;
  --bord: #e5e7eb;
  --fond: #ffffff;
  --fond-2: #f8fafc;
  --succes: #15803d;
  --succes-clair: #dcfce7;
  --danger: #b91c1c;
  --danger-clair: #fee2e2;
  --alerte: #a16207;
  --alerte-clair: #fef9c3;
  --rayon: 12px;
  --haut-sure: env(safe-area-inset-top, 0px);
  --bas-sure: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--fond);
  color: var(--texte);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
h1, h2, h3 { margin: 0; line-height: 1.2; }
a { color: var(--primaire); }
.cache, [hidden] { display: none !important; }
.muted { color: var(--doux); }

/* ---------- Barre du haut ---------- */
.barre {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 8px;
  padding: calc(8px + var(--haut-sure)) 12px 8px;
  background: var(--fond);
  border-bottom: 1px solid var(--bord);
  min-height: 56px;
}
.barre-titre { flex: 1; min-width: 0; }
.barre h1 { font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sous-titre { font-size: 13px; color: var(--doux); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.logo {
  display: grid; place-items: center;
  min-width: 40px; height: 40px; padding: 0 8px;
  border-radius: 10px; background: var(--primaire); color: #fff;
  font-weight: 800; font-size: 13px; letter-spacing: .5px;
}
.etat-sauvegarde { font-size: 12px; }
.etat-sauvegarde.ok { color: var(--succes); }
.etat-sauvegarde.erreur { color: var(--danger); }

/* ---------- Onglets ---------- */
.onglets {
  position: sticky; top: calc(56px + var(--haut-sure)); z-index: 15;
  display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none;
  padding: 8px 12px; background: var(--fond); border-bottom: 1px solid var(--bord);
}
.onglets::-webkit-scrollbar { display: none; }
.onglets a {
  flex: none; display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px; border-radius: 999px;
  border: 1px solid var(--bord); background: var(--fond);
  color: var(--texte); text-decoration: none; font-size: 14px; font-weight: 500; white-space: nowrap;
}
.onglets a.actif { background: var(--primaire); border-color: var(--primaire); color: #fff; }
.onglets .compte {
  min-width: 20px; padding: 0 6px; border-radius: 999px;
  background: var(--primaire-clair); color: var(--primaire); font-size: 12px; font-weight: 700; text-align: center;
}
.onglets a.actif .compte { background: rgba(255,255,255,.25); color: #fff; }

/* ---------- Contenu ---------- */
.contenu {
  max-width: 760px; margin: 0 auto;
  padding: 16px 16px calc(24px + var(--bas-sure));
}
.contenu.avec-barre-bas { padding-bottom: calc(96px + var(--bas-sure)); }
.chargement { padding: 48px 0; text-align: center; color: var(--doux); }

.carte {
  background: var(--fond); border: 1px solid var(--bord); border-radius: var(--rayon);
  padding: 16px; margin-bottom: 12px;
}
.carte h3 { font-size: 15px; margin-bottom: 12px; }
.carte-tete { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.carte-tete strong { font-size: 16px; }
.section-titre { font-size: 13px; text-transform: uppercase; letter-spacing: .6px; color: var(--doux); margin: 20px 4px 8px; font-weight: 600; }
.vide { text-align: center; color: var(--doux); padding: 28px 16px; border: 1px dashed var(--bord); border-radius: var(--rayon); }
.aide { font-size: 14px; color: var(--doux); margin: 0 0 12px; }

/* ---------- Formulaires ---------- */
.champ { display: block; margin-bottom: 12px; }
.champ > span { display: block; font-size: 13px; font-weight: 600; color: var(--doux); margin-bottom: 4px; }
.champ:last-child { margin-bottom: 0; }
input, select, textarea {
  width: 100%; min-height: 46px;
  padding: 10px 12px; border: 1px solid #d1d5db; border-radius: 10px;
  background: #fff; color: var(--texte); font: inherit; font-size: 16px;
  appearance: none; -webkit-appearance: none;
}
select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%236b7280' stroke-width='2'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; padding-right: 34px;
}
input[type="time"], input[type="date"] { min-width: 0; }
textarea { min-height: 200px; resize: vertical; line-height: 1.5; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primaire); outline-offset: -1px; border-color: var(--primaire); }
input[type="checkbox"] { width: 22px; min-height: 22px; height: 22px; padding: 0; accent-color: var(--primaire); appearance: auto; -webkit-appearance: checkbox; }
.case { display: flex; align-items: center; gap: 10px; min-height: 44px; font-size: 15px; }

.grille-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grille-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
.grille-3 .champ, .grille-2 .champ { margin-bottom: 0; }
.ligne-ajout { display: flex; gap: 8px; align-items: flex-end; }
.ligne-ajout > .flex { flex: 1; min-width: 0; }
.ligne-ajout .qte { width: 84px; flex: none; }
.ligne-ajout .unite { width: 104px; flex: none; }
.compteur { text-align: right; font-size: 12px; color: var(--doux); margin-top: 4px; }

/* ---------- Boutons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 46px; padding: 10px 18px; border-radius: 10px;
  border: 1px solid transparent; font: inherit; font-weight: 600; font-size: 15px;
  cursor: pointer; text-decoration: none; text-align: center; white-space: nowrap;
}
.btn:disabled { opacity: .55; cursor: default; }
.btn-primaire { background: var(--primaire); color: #fff; }
.btn-primaire:active { background: var(--primaire-fonce); }
.btn-secondaire { background: #fff; color: var(--primaire); border-color: #c7d2fe; }
.btn-danger { background: #fff; color: var(--danger); border-color: #fecaca; }
.btn-plein { width: 100%; }
.btn-grand { min-height: 54px; font-size: 16px; }
.btn-icone {
  display: inline-grid; place-items: center; flex: none;
  width: 42px; height: 42px; border: 0; border-radius: 10px; background: transparent;
  color: var(--texte); font-size: 20px; cursor: pointer; text-decoration: none;
}
.btn-icone:active { background: var(--fond-2); }
.btn-icone.suppr { color: var(--doux); font-size: 18px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.actions .btn { flex: 1; }

/* ---------- Barre du bas (rapport) ---------- */
.barre-bas {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; gap: 10px;
  padding: 10px 16px calc(10px + var(--bas-sure));
  background: rgba(255,255,255,.97); border-top: 1px solid var(--bord);
}
.barre-bas .btn { flex: 1; }
@media (min-width: 800px) {
  .barre-bas { left: 50%; right: auto; width: 760px; transform: translateX(-50%); border-left: 1px solid var(--bord); border-right: 1px solid var(--bord); }
}

/* ---------- Listes ---------- */
.liste-rapports { display: grid; gap: 10px; }
.rapport-item {
  display: block; padding: 14px 16px; border: 1px solid var(--bord); border-radius: var(--rayon);
  color: inherit; text-decoration: none; background: #fff;
}
.rapport-item:active { background: var(--fond-2); }
.rapport-item .ligne1 { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.rapport-item .date { font-weight: 700; }
.rapport-item .chantier { margin-top: 2px; }
.rapport-item .meta { font-size: 13px; color: var(--doux); margin-top: 4px; }
.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 700; white-space: nowrap; }
.badge-brouillon { background: var(--alerte-clair); color: var(--alerte); }
.badge-envoye { background: var(--succes-clair); color: var(--succes); }
.badge-archive { background: #f3f4f6; color: var(--doux); }

.element { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--bord); }
.element:last-child { border-bottom: 0; }
.element .libelle { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.element.archive .libelle { color: var(--doux); text-decoration: line-through; }
.carte.liste { padding: 0; overflow: hidden; }
.sous-liste { margin: 12px -16px -16px; border-top: 1px solid var(--bord); }
.hist-item + .hist-item { border-top: 1px solid var(--bord); }

/* ---------- Rapport : lignes ---------- */
.ligne-saisie { padding: 12px 12px 12px 14px; }
.ligne-saisie .carte-tete { margin-bottom: 8px; }
.ligne-saisie .nom { font-weight: 700; overflow-wrap: anywhere; }
.heures { display: flex; justify-content: space-between; align-items: center; margin-top: 10px; padding: 8px 12px; background: var(--primaire-clair); border-radius: 8px; font-size: 14px; }
.heures strong { font-size: 18px; color: var(--primaire); }
.total {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 16px; border-radius: var(--rayon); background: var(--primaire); color: #fff; margin-bottom: 12px;
}
.total strong { font-size: 22px; }

.info-ligne { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--bord); font-size: 15px; }
.info-ligne:last-child { border-bottom: 0; }
.info-ligne span { color: var(--doux); }

.bandeau { padding: 12px 14px; border-radius: 10px; margin-bottom: 12px; font-size: 14px; }
.bandeau-info { background: var(--primaire-clair); color: var(--primaire-fonce); }
.bandeau-succes { background: var(--succes-clair); color: var(--succes); }
.bandeau-alerte { background: var(--alerte-clair); color: var(--alerte); }
.bandeau ul { margin: 6px 0 0; padding-left: 20px; }

/* ---------- Photos ---------- */
.boutons-photo { display: grid; gap: 8px; grid-template-columns: 1fr 1fr; }
.grille-photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.photo { position: relative; margin: 0; border: 1px solid var(--bord); border-radius: var(--rayon); overflow: hidden; background: var(--fond-2); }
.photo img { display: block; width: 100%; aspect-ratio: 4 / 3; object-fit: cover; cursor: zoom-in; }
.photo input { border: 0; border-top: 1px solid var(--bord); border-radius: 0; min-height: 42px; font-size: 14px; }
.photo-suppr {
  position: absolute; top: 6px; right: 6px; width: 34px; height: 34px; border-radius: 50%;
  border: 0; background: rgba(17,24,39,.7); color: #fff; font-size: 15px; cursor: pointer;
}
.photo.envoi { display: grid; place-items: center; aspect-ratio: 4 / 3; color: var(--doux); font-size: 14px; }

/* ---------- Destinataires ---------- */
.puces { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.puce { display: inline-flex; align-items: center; gap: 4px; padding: 4px 4px 4px 12px; border-radius: 999px; background: var(--primaire-clair); color: var(--primaire-fonce); font-size: 14px; max-width: 100%; }
.puce span { overflow: hidden; text-overflow: ellipsis; }
.puce button { width: 28px; height: 28px; border: 0; border-radius: 50%; background: transparent; color: inherit; cursor: pointer; font-size: 14px; }

/* ---------- Modales ---------- */
.modal-fond {
  position: fixed; inset: 0; z-index: 50; background: rgba(17,24,39,.45);
  display: flex; align-items: flex-end; justify-content: center;
}
.modal {
  width: 100%; max-width: 560px; max-height: 92vh; overflow-y: auto;
  background: #fff; border-radius: 16px 16px 0 0; padding: 0 16px calc(16px + var(--bas-sure));
}
.modal-tete { position: sticky; top: 0; background: #fff; display: flex; align-items: center; justify-content: space-between; padding: 14px 0 10px; z-index: 1; }
.modal-tete h2 { font-size: 18px; }
.modal .actions { margin-top: 16px; }
@media (min-width: 600px) {
  .modal-fond { align-items: center; }
  .modal { border-radius: 16px; }
}
.visionneuse { position: fixed; inset: 0; z-index: 60; background: #000; display: grid; place-items: center; }
.visionneuse img { max-width: 100%; max-height: 100%; }
.visionneuse button { position: absolute; top: calc(12px + var(--haut-sure)); right: 12px; color: #fff; background: rgba(255,255,255,.15); }

.menu-liste { display: grid; gap: 8px; }
.menu-liste .btn { justify-content: flex-start; }

/* ---------- Connexion ---------- */
.connexion { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.connexion form { width: 100%; max-width: 380px; }
.connexion .logo { width: 64px; height: 64px; font-size: 18px; border-radius: 16px; margin: 0 auto 16px; }
.connexion h1 { text-align: center; font-size: 22px; margin-bottom: 4px; }
.connexion p { text-align: center; color: var(--doux); margin: 0 0 24px; }

/* ---------- Notifications ---------- */
#toasts { position: fixed; left: 0; right: 0; bottom: calc(84px + var(--bas-sure)); z-index: 70; display: grid; justify-items: center; gap: 8px; pointer-events: none; padding: 0 16px; }
.toast { max-width: 480px; padding: 12px 16px; border-radius: 10px; background: #111827; color: #fff; font-size: 14px; box-shadow: 0 6px 20px rgba(0,0,0,.2); transition: opacity .3s, transform .3s; }
.toast-erreur { background: var(--danger); }
.toast-succes { background: var(--succes); }
.toast.sortie { opacity: 0; transform: translateY(8px); }

.recherche { margin-bottom: 12px; }
.entete-liste { display: flex; gap: 8px; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.entete-liste h2 { font-size: 20px; }

@media (max-width: 380px) {
  .grille-3 { grid-template-columns: 1fr 1fr; }
  .grille-3 .champ:last-child { grid-column: span 2; }
  .boutons-photo { grid-template-columns: 1fr; }
}
