:root {
  --vert: #0f766e; --vert-f: #115e59; --vert-c: #e6f4f1; --sable: #fbf7ef; --or: #b45309; --or-c: #fef3e2;
  --rouge: #b91c1c; --rouge-c: #fdecec; --texte: #1f2937; --gris: #6b7280; --bord: #e5e1d8; --blanc: #fff;
  --rayon: 12px;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body { font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--texte); background: var(--sable); font-size: 16px; line-height: 1.45; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
.wrap { max-width: 1180px; margin: 0 auto; padding: 16px; }
.muted { color: var(--gris); }
.small { font-size: 13px; }
.ar { font-family: "Amiri", "Traditional Arabic", serif; direction: rtl; }

/* En-tête */
.top { background: var(--vert); color: #fff; }
.top .wrap { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding-top: 14px; padding-bottom: 14px; }
.top h1 { font-size: 20px; }
.top .sub { opacity: .85; font-size: 14px; }
.top .grow { flex: 1; }
.top .other-app { color: #fff; font-weight: 600; text-decoration: none; border: 1px solid rgba(255,255,255,.35); border-radius: 8px; padding: 6px 12px; }
.top .other-app:hover { background: rgba(255,255,255,.14); }
.top button { background: rgba(255,255,255,.14); border: 1px solid rgba(255,255,255,.35); color: #fff; border-radius: 8px; padding: 6px 12px; }
.demo-banner { background: var(--or-c); color: var(--or); text-align: center; font-size: 13px; padding: 6px 10px; border-bottom: 1px solid #f5d9b0; }

/* Boutons et champs */
.btn { border: 1px solid var(--bord); background: var(--blanc); border-radius: 8px; padding: 8px 14px; }
.btn:hover { border-color: var(--vert); }
.btn.primary { background: var(--vert); border-color: var(--vert); color: #fff; font-weight: 600; }
.btn.primary:hover { background: var(--vert-f); }
.btn.danger { color: var(--rouge); }
.btn.sm { padding: 4px 10px; font-size: 14px; }
.btn:disabled { opacity: .5; cursor: default; }
input[type=text], input[type=tel], input[type=number], input[type=date], input[type=email], input[type=password], select, textarea {
  border: 1px solid var(--bord); border-radius: 8px; padding: 8px 10px; background: #fff; width: 100%;
}
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--vert); outline-offset: 1px; }
label.f { display: block; font-size: 14px; color: var(--gris); margin: 10px 0 4px; }
.check { display: flex; align-items: center; gap: 10px; padding: 12px; border: 1px solid var(--bord); border-radius: 10px; background: #fff; margin-top: 8px; cursor: pointer; }
.check input { width: 22px; height: 22px; accent-color: var(--vert); }
.check.off { opacity: .45; cursor: not-allowed; }

/* Badges */
.badge { display: inline-flex; align-items: center; gap: 4px; border-radius: 999px; padding: 2px 10px; font-size: 13px; font-weight: 600; white-space: nowrap; }
.b-ok { background: var(--vert-c); color: var(--vert-f); }
.b-manque { background: var(--or-c); color: var(--or); }
.b-rouge { background: var(--rouge-c); color: var(--rouge); }
.b-gris { background: #f1f0ec; color: var(--gris); }

/* Cartes */
.card { background: #fff; border: 1px solid var(--bord); border-radius: var(--rayon); padding: 14px; }
.grid { display: grid; gap: 10px; }

/* Public : liste des jours */
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin: 14px 0; }
.chip { border: 1px solid var(--bord); background: #fff; border-radius: 999px; padding: 6px 14px; font-size: 14px; }
.chip.on { background: var(--vert); color: #fff; border-color: var(--vert); }
.day { display: flex; align-items: center; gap: 12px; padding: 12px 14px; }
.day .d { width: 56px; text-align: center; flex: none; }
.day .d b { display: block; font-size: 24px; line-height: 1; }
.day .d span { font-size: 12px; color: var(--gris); text-transform: uppercase; }
.day .mid { flex: 1; min-width: 0; }
.day .badges { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 4px; }
.day.full { opacity: .55; }
.day button { flex: none; }
.sheet-bg { position: fixed; inset: 0; background: rgba(17,24,39,.45); display: flex; align-items: flex-end; justify-content: center; z-index: 20; }
.sheet { background: #fff; width: 100%; max-width: 520px; border-radius: 16px 16px 0 0; padding: 18px; max-height: 92vh; overflow: auto; }
@media (min-width: 640px) { .sheet-bg { align-items: center; } .sheet { border-radius: 16px; } }
.msg { border-radius: 10px; padding: 10px 12px; margin-top: 10px; font-size: 14px; }
.msg.err { background: var(--rouge-c); color: var(--rouge); }
.msg.ok { background: var(--vert-c); color: var(--vert-f); }

/* Admin */
.tabs { display: flex; gap: 4px; overflow-x: auto; border-bottom: 1px solid var(--bord); background: #fff; }
.tabs button { border: 0; background: none; padding: 12px 14px; border-bottom: 3px solid transparent; white-space: nowrap; color: var(--gris); font-weight: 600; }
.tabs button.on { color: var(--vert); border-bottom-color: var(--vert); }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin: 14px 0; }
.toolbar .grow { flex: 1; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin: 14px 0; }
.kpi { background: #fff; border: 1px solid var(--bord); border-radius: var(--rayon); padding: 12px 14px; }
.kpi b { display: block; font-size: 22px; font-variant-numeric: tabular-nums; }
.kpi span { font-size: 13px; color: var(--gris); }
.tbl-wrap { overflow-x: auto; background: #fff; border: 1px solid var(--bord); border-radius: var(--rayon); }
table.t { border-collapse: collapse; width: 100%; font-size: 14px; }
table.t th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--gris); background: #faf8f3; padding: 8px 10px; border-bottom: 1px solid var(--bord); white-space: nowrap; }
table.t td { padding: 6px 10px; border-bottom: 1px solid #f0ede6; vertical-align: middle; }
table.t td.num, table.t th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.t tr:last-child td { border-bottom: 0; }
table.t tfoot td { font-weight: 700; background: #faf8f3; border-top: 1px solid var(--bord); }
table.t input, table.t select { padding: 5px 7px; min-width: 60px; }
table.t input[type=number] { width: 86px; text-align: right; }
.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 8px; }
.cal .head { font-size: 12px; font-weight: 700; color: var(--gris); text-transform: uppercase; text-align: center; }
.cal .cell { background: #fff; border: 1px solid var(--bord); border-radius: 10px; padding: 8px; min-height: 118px; cursor: pointer; display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
.cal .cell:hover { border-color: var(--vert); }
.cal .cell.vide { background: transparent; border: 0; cursor: default; }
.cal .cell .n { display: flex; justify-content: space-between; font-weight: 700; }
.cal .cell .who { font-size: 12px; color: var(--gris); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 760px) { .cal { grid-template-columns: 1fr; } .cal .head, .cal .cell.vide { display: none; } .cal .cell { min-height: 0; } }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 560px) { .row2 { grid-template-columns: 1fr; } }
.section-title { display: flex; align-items: baseline; gap: 10px; margin: 22px 0 8px; }
.section-title h2 { font-size: 18px; }
.qr { display: flex; gap: 20px; align-items: center; flex-wrap: wrap; }
.qr canvas, .qr img { border: 1px solid var(--bord); border-radius: 8px; padding: 8px; background: #fff; }
.empty { text-align: center; padding: 30px; color: var(--gris); }
@media print {
  .top button, .tabs, .toolbar, .no-print { display: none !important; }
  body { background: #fff; }
  .cal .cell { min-height: 90px; break-inside: avoid; }
}

/* Factures : une carte par ticket, lisible sur téléphone */
.dep { display: flex; gap: 12px; align-items: center; padding: 10px 12px; }
.dep-pj { flex: none; width: 58px; height: 58px; border-radius: 10px; border: 1px solid var(--bord); background: var(--vert-c); color: var(--vert-f); font-size: 24px; font-weight: 700; }
.dep-pj.manque { background: var(--or-c); color: var(--or); border-style: dashed; font-size: 12px; }
.dep-mid { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; align-items: flex-start; }
.dep-right { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.dep-mt { font-size: 19px; font-variant-numeric: tabular-nums; white-space: nowrap; }
@media (max-width: 520px) { .dep { flex-wrap: wrap; } .dep-right { flex-direction: row; align-items: center; width: 100%; justify-content: space-between; } }

/* Chèques viande : barre de progression, impression des chèques et du bordereau */
.prog { height: 14px; background: #ece8df; border-radius: 999px; overflow: hidden; margin: 8px 0 6px; }
.prog > div { height: 100%; background: var(--vert); border-radius: 999px; transition: width .4s; }
#print-zone { display: none; }
.chq-grid { display: grid; grid-template-columns: 1fr 1fr; }
.chq { display: flex; gap: 3mm; height: 54mm; padding: 4mm 5mm; border: 1px dashed #9ca3af; break-inside: avoid; color: #111; background: #fff; }
.chq-g { flex: 1; display: flex; flex-direction: column; gap: 1.2mm; min-width: 0; }
.chq-h { color: var(--vert-f); font-size: 10pt; border-bottom: 2px solid var(--vert); padding-bottom: 1mm; }
.chq-v { font-size: 28pt; font-weight: 800; line-height: 1; margin-top: 1mm; }
.chq-n { font-family: ui-monospace, Consolas, monospace; font-size: 12pt; font-weight: 700; }
.chq-i { font-size: 7pt; color: #374151; line-height: 1.25; }
.chq-d { width: 31mm; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1mm; font-size: 6.5pt; text-align: center; color: #374151; line-height: 1.2; }
.chq-d img { width: 29mm; height: 29mm; }
table.bord { width: 100%; font-size: 10pt; }
table.bord td { height: 11mm; border: 1px solid #bbb; }
table.bord th { border: 1px solid #bbb; }
@media print {
  @page { size: A4; margin: 10mm; }
  body.printing > *:not(#print-zone) { display: none !important; }
  body.printing #print-zone { display: block; }
  .chq-grid, .chq { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

/* Téléphone : une ligne = un bouton, la fiche s'ouvre au toucher */
.lignes { display: flex; flex-direction: column; gap: 8px; }
.ligne { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; background: #fff; border: 1px solid var(--bord); border-radius: var(--rayon); padding: 12px 10px 12px 14px; min-height: 58px; }
.ligne:hover { border-color: var(--vert); }
.ligne:active { background: var(--vert-c); }
.l-mid { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.l-t { font-weight: 700; font-size: 16px; overflow-wrap: anywhere; }
.l-s { font-size: 13px; color: var(--gris); overflow-wrap: anywhere; }
.l-b { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 2px; }
.l-d { flex: none; display: flex; flex-direction: column; align-items: flex-end; gap: 2px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.l-chev { flex: none; color: #c4bfb3; font-size: 24px; line-height: 1; }
.sheet .row2 { grid-template-columns: 1fr 1fr; }
.fiche-pied { display: flex; gap: 8px; align-items: center; margin-top: 16px; position: sticky; bottom: -18px; background: #fff; padding: 10px 0 6px; border-top: 1px solid var(--bord); }
.fiche-pied .grow { flex: 1; }
.fiche-pied .btn { padding: 10px 18px; }
.choix { display: flex; flex-wrap: wrap; gap: 6px; }
.choix button { border: 1px solid var(--bord); background: #fff; border-radius: 999px; padding: 9px 14px; font-weight: 600; }
.choix button.on { background: var(--vert); color: #fff; border-color: var(--vert); }
.gros-boutons { display: grid; gap: 8px; margin-top: 12px; }
.gros-boutons .btn { padding: 13px; font-weight: 600; }

/* Tableau de bord (accueil Colis) */
.tuiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 10px; margin: 14px 0; }
.tuile { background: #fff; border: 1px solid var(--bord); border-radius: 16px; padding: 14px 16px; box-shadow: 0 1px 2px rgba(0,0,0,.04); text-align: left; width: 100%; }
button.tuile:hover { border-color: var(--vert); }
.tu-l { font-size: 13px; font-weight: 600; color: var(--gris); }
.tu-v { font-size: 26px; font-weight: 800; font-variant-numeric: tabular-nums; margin-top: 2px; }
.tu-h { font-size: 12.5px; color: var(--gris); margin-top: 2px; }
.tuile .prog { height: 10px; margin: 10px 0 4px; }
.empile { display: flex; height: 14px; border-radius: 999px; overflow: hidden; background: #ece8df; margin: 4px 0 4px; }
.pt { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; vertical-align: 0; }
.src-modes { margin-top: 8px; display: flex; flex-wrap: wrap; gap: 4px; }

@media (max-width: 760px) {
  .top .wrap { padding-top: 10px; padding-bottom: 10px; gap: 8px; }
  .top h1 { font-size: 17px; }
  .top .sub { display: none; }
  .top button, .top .other-app { padding: 6px 10px; font-size: 14px; }
  .wrap { padding: 12px; }
  .tabs button { padding: 11px 12px; }
  .kpi b { font-size: 19px; }
  .toolbar { gap: 6px; }
  .toolbar .btn.sm { padding: 7px 12px; }
  .toolbar input[type=text], .toolbar input[type=search] { max-width: none !important; flex: 1 1 100%; }
  input, select, textarea { font-size: 16px !important; } /* pas de zoom automatique sur iPhone */
  .tu-v { font-size: 23px; }
  .sheet { padding: 16px; }
  /* Petits tableaux restants : une carte par ligne, « libellé : valeur » */
  table.t.pile thead { display: none; }
  table.t.pile, table.t.pile tbody, table.t.pile tr, table.t.pile td { display: block; width: 100%; }
  table.t.pile tr { border-bottom: 1px solid var(--bord); padding: 6px 0; }
  table.t.pile td { display: flex; justify-content: space-between; align-items: center; gap: 10px; border: 0; padding: 4px 12px; text-align: right; }
  table.t.pile td::before { content: attr(data-label); color: var(--gris); font-size: 13px; text-align: left; }
  table.t.pile td input, table.t.pile td select { max-width: 60%; }
}
