/* ALIQ V14 - PWA chauffeur (MVP). Mobile-first. */

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: rgba(56, 189, 248, 0.15);
}

html, body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  background: #f1f5f9;
  color: #0f172a;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  font-size: 16px;
  line-height: 1.45;
}

body {
  /* Safe areas iOS (notch + home indicator) */
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

a {
  color: #0284c7;
  text-decoration: none;
}

/* ============================================================
   Header sticky
   ============================================================ */
.app-header {
  background: #0f172a;
  color: #f8fafc;
  padding: 16px 16px 12px;
  position: sticky;
  top: 0;
  z-index: 10;
  border-bottom: 1px solid #1e293b;
}

.app-header h1 {
  font-size: 18px;
  margin: 0;
  font-weight: 700;
  letter-spacing: 0.3px;
}

.app-header .subtitle {
  font-size: 13px;
  margin-top: 2px;
  color: #94a3b8;
}

.app-header .date-jour {
  font-size: 14px;
  font-weight: 600;
  color: #38bdf8;
  text-transform: capitalize;
}

.header-actions {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 8px;
  margin-top: 8px;
}

.btn-logout {
  background: transparent;
  border: 1px solid #334155;
  color: #cbd5e1;
  font-size: 12px;
  padding: 6px 10px;
  border-radius: 6px;
  cursor: pointer;
}
.btn-logout:active { background: #1e293b; }

/* ============================================================
   Login page
   ============================================================ */
.login-wrap {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 24px 20px;
  background: linear-gradient(180deg, #0f172a 0%, #1e293b 100%);
  color: #f8fafc;
}

.login-card {
  background: #f8fafc;
  color: #0f172a;
  border-radius: 16px;
  padding: 24px 20px;
  box-shadow: 0 18px 40px -16px rgba(0, 0, 0, 0.5);
}

.login-card h1 {
  margin: 0 0 4px;
  font-size: 22px;
  text-align: center;
  color: #0f172a;
}
.login-card .tagline {
  text-align: center;
  font-size: 13px;
  color: #64748b;
  margin: 0 0 18px;
}

.field {
  display: block;
  margin-bottom: 14px;
}
.field label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 6px;
  color: #334155;
}
.field input {
  display: block;
  width: 100%;
  padding: 12px 12px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  font-size: 16px;   /* >= 16px = pas de zoom iOS */
  background: #ffffff;
  color: #0f172a;
  -webkit-appearance: none;
}
.field input:focus {
  outline: none;
  border-color: #38bdf8;
  box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.18);
}

.btn-primary {
  display: block;
  width: 100%;
  padding: 14px;
  background: #0f172a;
  color: #f8fafc;
  border: none;
  border-radius: 10px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 4px;
}
.btn-primary:disabled {
  background: #94a3b8;
  cursor: not-allowed;
}
.btn-primary:active:not(:disabled) {
  background: #1e293b;
}

.error-banner {
  background: #fee2e2;
  color: #991b1b;
  border: 1px solid #fca5a5;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 14px;
  margin-bottom: 12px;
  display: none;
}
.error-banner.show { display: block; }

.info-banner {
  background: #e0f2fe;
  color: #075985;
  border: 1px solid #bae6fd;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 13px;
  margin-top: 14px;
}

/* ============================================================
   Tournee page : liste livraisons
   ============================================================ */
.tournee-summary {
  background: #ffffff;
  padding: 14px 16px;
  border-bottom: 1px solid #e2e8f0;
  font-size: 13px;
  color: #475569;
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
}
.tournee-summary strong {
  color: #0f172a;
  font-weight: 700;
}

.livraisons-list {
  list-style: none;
  margin: 0;
  padding: 8px 12px 24px;
}

.livraison-item {
  background: #ffffff;
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 10px;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.06);
  border-left: 4px solid #94a3b8;
  display: flex;
  flex-direction: column;
  gap: 6px;
  cursor: pointer;
}

.livraison-item.statut-a_livrer    { border-left-color: #f59e0b; }
.livraison-item.statut-livree      { border-left-color: #16a34a; opacity: 0.85; }
.livraison-item.statut-refusee     { border-left-color: #dc2626; }
.livraison-item.statut-refusee_partielle { border-left-color: #dc2626; }
.livraison-item.statut-reportee    { border-left-color: #6366f1; }

.livraison-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
}

.livraison-ordre {
  background: #0f172a;
  color: #f8fafc;
  border-radius: 6px;
  padding: 2px 8px;
  font-size: 13px;
  font-weight: 700;
  flex-shrink: 0;
}

.livraison-nom {
  font-size: 15px;
  font-weight: 600;
  color: #0f172a;
  flex: 1;
}

.livraison-adresse {
  font-size: 13px;
  color: #475569;
  line-height: 1.35;
}

.livraison-meta {
  display: flex;
  gap: 12px;
  font-size: 12px;
  color: #64748b;
  flex-wrap: wrap;
}

.statut-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}
.statut-badge.statut-a_livrer    { background: #fef3c7; color: #92400e; }
.statut-badge.statut-livree      { background: #dcfce7; color: #166534; }
.statut-badge.statut-refusee     { background: #fee2e2; color: #991b1b; }
.statut-badge.statut-refusee_partielle { background: #fee2e2; color: #991b1b; }
.statut-badge.statut-reportee    { background: #e0e7ff; color: #3730a3; }

/* ============================================================
   Modal detail livraison
   ============================================================ */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 100;
  padding: 0;
}
.modal-backdrop[hidden] { display: none; }

.modal {
  background: #ffffff;
  width: 100%;
  max-width: 480px;
  border-radius: 18px 18px 0 0;
  padding: 18px 18px 28px;
  max-height: 88vh;
  overflow-y: auto;
  box-shadow: 0 -10px 30px -10px rgba(0, 0, 0, 0.3);
  animation: slideUp 0.18s ease-out;
}
@keyframes slideUp {
  from { transform: translateY(100%); }
  to   { transform: translateY(0); }
}

.modal h2 {
  margin: 0 0 4px;
  font-size: 18px;
}

.modal .modal-close {
  position: absolute;
  top: 12px;
  right: 14px;
  background: transparent;
  border: 0;
  font-size: 22px;
  color: #64748b;
  cursor: pointer;
  line-height: 1;
  padding: 4px 8px;
}

.modal dl {
  margin: 10px 0 0;
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 6px 12px;
  font-size: 14px;
}
.modal dt {
  font-weight: 600;
  color: #475569;
}
.modal dd {
  margin: 0;
  color: #0f172a;
}

.modal .instructions {
  margin-top: 14px;
  background: #fffbeb;
  border-left: 3px solid #f59e0b;
  padding: 10px 12px;
  font-size: 13px;
  border-radius: 6px;
  white-space: pre-wrap;
}

.modal .actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 18px;
}
.modal .actions a.btn-call,
.modal .actions a.btn-nav {
  display: block;
  padding: 12px;
  border-radius: 10px;
  font-weight: 600;
  text-align: center;
  font-size: 15px;
}
.modal .actions a.btn-call { background: #0f172a; color: #f8fafc; }
.modal .actions a.btn-nav  { background: #0284c7; color: #f8fafc; }

/* ============================================================
   Etats vide / chargement / erreur
   ============================================================ */
.state-empty,
.state-loading,
.state-error {
  text-align: center;
  padding: 60px 24px 40px;
  color: #64748b;
  font-size: 15px;
}
.state-error {
  color: #991b1b;
}

.spinner {
  width: 28px;
  height: 28px;
  border: 3px solid #cbd5e1;
  border-top-color: #0f172a;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin: 0 auto 14px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ============================================================
   iPhone SE compat (375x667) : pas de scroll horizontal
   ============================================================ */
@media (max-width: 380px) {
  .app-header h1 { font-size: 16px; }
  .livraison-nom { font-size: 14px; }
}
/* ============================================================
   V14b - POD / Signature / Non-livre / Offline badge
   ============================================================ */

/* Badge offline en haut */
.offline-badge {
  margin-top: 8px;
  background: #fbbf24;
  color: #78350f;
  padding: 6px 10px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.offline-badge[hidden] { display: none; }
.btn-replay {
  background: #78350f;
  color: #fef3c7;
  border: 0;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 700;
  border-radius: 6px;
  cursor: pointer;
}
.btn-replay:active { background: #92400e; }

/* Actions POD dans la modal */
.pod-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 18px;
}
.pod-actions[hidden] { display: none; }
.pod-actions .btn-pod,
.pod-actions .btn-signature,
.pod-actions .btn-non-livre {
  padding: 14px 10px;
  border-radius: 10px;
  font-weight: 600;
  font-size: 14px;
  border: 0;
  cursor: pointer;
  text-align: center;
}
.pod-actions .btn-pod {
  background: #16a34a;
  color: #f0fdf4;
  grid-column: 1 / span 2; /* full width sur la premiere ligne */
}
.pod-actions .btn-pod:active { background: #15803d; }
.pod-actions .btn-signature {
  background: #0284c7;
  color: #f0f9ff;
}
.pod-actions .btn-signature:active { background: #0369a1; }
.pod-actions .btn-non-livre {
  background: #dc2626;
  color: #fef2f2;
}
.pod-actions .btn-non-livre:active { background: #b91c1c; }

/* Signature block */
.signature-block,
.non-livre-block {
  margin-top: 18px;
  padding: 14px;
  background: #f8fafc;
  border-radius: 12px;
  border: 1px solid #e2e8f0;
}
.signature-block[hidden],
.non-livre-block[hidden] { display: none; }

.signature-block h3,
.non-livre-block h3 {
  margin: 0 0 10px;
  font-size: 15px;
  font-weight: 700;
  color: #0f172a;
}

#signature-canvas {
  display: block;
  width: 100%;
  max-width: 100%;
  height: auto;
  aspect-ratio: 320 / 180;
  background: #ffffff;
  border: 1px dashed #94a3b8;
  border-radius: 8px;
  touch-action: none;     /* IMPORTANT : evite le scroll pendant le trace */
  -webkit-user-select: none;
  user-select: none;
}

#signataire-nom {
  display: block;
  width: 100%;
  margin-top: 10px;
  padding: 10px 12px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  font-size: 16px;     /* >= 16px = pas de zoom iOS */
  background: #ffffff;
  color: #0f172a;
  -webkit-appearance: none;
}

.signature-actions,
.non-livre-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 10px;
}
.signature-actions .btn-primary,
.non-livre-actions .btn-primary,
.signature-actions .btn-secondary,
.non-livre-actions .btn-secondary {
  width: 100%;
  padding: 12px 10px;
  font-size: 14px;
  font-weight: 600;
  border-radius: 8px;
  border: 0;
  cursor: pointer;
}
.signature-actions .btn-primary,
.non-livre-actions .btn-primary {
  background: #0f172a;
  color: #f8fafc;
  grid-column: 1 / span 2;
}
.signature-actions .btn-secondary,
.non-livre-actions .btn-secondary {
  background: #e2e8f0;
  color: #0f172a;
}

/* Non-livre block */
.motif-select {
  display: block;
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  font-size: 16px;
  background: #ffffff;
  color: #0f172a;
  -webkit-appearance: none;
}
#motif-libre {
  display: block;
  width: 100%;
  margin-top: 8px;
  padding: 10px 12px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  font-size: 16px;
  font-family: inherit;
  background: #ffffff;
  color: #0f172a;
  resize: vertical;
}
#motif-libre[hidden] { display: none; }

/* Toast confirmation/erreur */
.pod-toast {
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  text-align: center;
}
.pod-toast[hidden] { display: none; }
.pod-toast.info { background: #e0f2fe; color: #075985; }
.pod-toast.ok   { background: #dcfce7; color: #166534; }
.pod-toast.warn { background: #fef3c7; color: #92400e; }
.pod-toast.err  { background: #fee2e2; color: #991b1b; }

/* ============================================================
 * V14d - Geoloc tracking chauffeur (bouton + indicateur GPS)
 * ============================================================ */
.gps-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 6px;
  flex-wrap: wrap;
}
.btn-gps-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border: 0;
  border-radius: 999px;
  background: #1e293b;
  color: #f8fafc;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  -webkit-appearance: none;
}
.btn-gps-toggle.active {
  background: #16a34a;
  color: #ffffff;
}
.btn-gps-toggle:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.gps-indicator {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  background: #dcfce7;
  color: #166534;
  font-size: 12px;
  font-weight: 700;
  border: 1px solid #86efac;
}
.gps-indicator[hidden] { display: none; }
.gps-dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #16a34a;
  box-shadow: 0 0 0 0 rgba(22, 163, 74, 0.6);
  animation: gpsPulse 1.6s infinite;
}
@keyframes gpsPulse {
  0%   { box-shadow: 0 0 0 0 rgba(22, 163, 74, 0.55); }
  70%  { box-shadow: 0 0 0 8px rgba(22, 163, 74, 0); }
  100% { box-shadow: 0 0 0 0 rgba(22, 163, 74, 0); }
}
/* Chantier 1 (2026-06-01) — bouton BL PDF dans l en-tete tournee */
.btn-bl-pdf {
  display: inline-flex;
  align-items: center;
  gap: 0.4em;
  margin: 6px 0 0;
  padding: 8px 14px;
  font-size: 14px;
  font-weight: 600;
  color: #fff;
  background: #0a3d62;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(0,0,0,.25);
  -webkit-tap-highlight-color: transparent;
}
.btn-bl-pdf:active { transform: translateY(1px); }
.btn-bl-pdf:disabled { opacity: 0.6; cursor: progress; }
