/* DA ProCalc : blanc, "Pro" noir + "Calc" bleu eau, épuré, tactile (foire). */
:root {
  --bleu: #1289c7;
  --bleu-fonce: #0d6ea3;
  --bleu-clair: #e8f4fb;
  --noir: #17202a;
  --gris: #5b6b78;
  --gris-clair: #eef2f5;
  --bord: #d8e0e6;
  --ok: #22a06b;
  --alerte: #e07b2c;
  --rouge: #d64545;
  --radius: 14px;
  --ombre: 0 1px 3px rgba(20, 40, 60, 0.08), 0 6px 20px rgba(20, 40, 60, 0.06);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; touch-action: manipulation; } /* coupe le double-tap zoom */
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--noir);
  background: #f4f7f9;
  font-size: 17px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
}

/* --- En-tête / logo --- */
.topbar {
  /* fixed (pas sticky) : reste TOUJOURS à l'écran, même Safari mobile / PWA en momentum
     scroll → le logo (déclencheur du mode commercial) est cliquable à n'importe quel scroll. */
  position: fixed; top: 0; left: 0; right: 0; z-index: 30; height: 56px;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px; background: #fff; border-bottom: 1px solid var(--bord);
  padding-top: env(safe-area-inset-top);
}
/* Compense la hauteur du header fixe sur les pages qui en ont un. */
body:has(.topbar) { padding-top: calc(56px + env(safe-area-inset-top)); }
.logo { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 22px; letter-spacing: -0.5px; user-select: none; -webkit-user-select: none; cursor: default; }
.logo .drop { width: 22px; height: 22px; }
.logo .pro { color: var(--noir); }
.logo .calc { color: var(--bleu); }

.sync-chip {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 13px; font-weight: 600; color: var(--gris);
  background: var(--gris-clair); border-radius: 999px; padding: 6px 12px; border: none; cursor: pointer;
}
.sync-chip.pending { color: #fff; background: var(--alerte); }
.sync-chip.ok { color: var(--ok); background: #e6f6ee; }
.sync-chip .dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }

/* Bandeau mode commercial */
body.mode-commercial { background: #eef5fa; }
.commercial-banner { display: none; }
body.mode-commercial .commercial-banner {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: var(--bleu); color: #fff; padding: 8px 16px; font-weight: 700; font-size: 14px;
}
.commercial-banner button {
  background: rgba(255,255,255,.2); color: #fff; border: 0; border-radius: 8px; padding: 6px 12px; font-weight: 700; cursor: pointer;
}

/* --- Layout --- */
main { max-width: 640px; margin: 0 auto; padding: 16px 16px 120px; }
.card {
  background: #fff; border: 1px solid var(--bord); border-radius: var(--radius);
  box-shadow: var(--ombre); padding: 18px; margin-bottom: 16px;
}
.card > h2 {
  margin: 0 0 14px; font-size: 15px; text-transform: uppercase; letter-spacing: 0.6px;
  color: var(--bleu); font-weight: 800;
}
.field { margin-bottom: 14px; }
.field:last-child { margin-bottom: 0; }
label.q { display: block; font-weight: 600; margin-bottom: 7px; }
label.q .req { color: var(--rouge); }
.hint { font-size: 13px; color: var(--gris); margin-top: 4px; }

/* Inputs */
input[type="text"], input[type="email"], input[type="tel"], input[type="number"],
input[type="date"], input[type="datetime-local"], input[type="time"], select, textarea {
  width: 100%; padding: 13px 14px; font-size: 17px; color: var(--noir);
  background: #fff; border: 1.5px solid var(--bord); border-radius: 11px; outline: none;
  appearance: none; -webkit-appearance: none;
}
select {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%235b6b78' stroke-width='2.4' stroke-linecap='round'><path d='M6 9l6 6 6-6'/></svg>");
  background-repeat: no-repeat; background-position: right 12px center; padding-right: 40px;
}
input:focus, select:focus, textarea:focus { border-color: var(--bleu); box-shadow: 0 0 0 3px rgba(18,137,199,.15); }
textarea { min-height: 84px; resize: vertical; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 460px) { .row2 { grid-template-columns: 1fr; } }

/* Choix segmentés (bulles) */
.choices { display: flex; flex-wrap: wrap; gap: 10px; }
.choices label {
  flex: 1 1 auto; min-width: 44%; text-align: center; padding: 13px 14px; border-radius: 11px;
  border: 1.5px solid var(--bord); background: #fff; font-weight: 600; cursor: pointer; user-select: none;
}
.choices input { position: absolute; opacity: 0; pointer-events: none; }
.choices label:has(input:checked) { border-color: var(--bleu); background: var(--bleu-clair); color: var(--bleu-fonce); }
.choices.compact label { min-width: 0; flex: 1 1 0; padding: 13px 6px; font-size: 14px; letter-spacing: -0.2px; }

/* Interrupteur (checkbox) */
.switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; cursor: pointer; }
.switch input { position: absolute; opacity: 0; }
.switch .track { width: 52px; height: 31px; border-radius: 999px; background: #cdd7de; position: relative; transition: background .15s; flex: none; }
.switch .track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 25px; height: 25px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.2); transition: transform .15s; }
.switch input:checked + .track { background: var(--bleu); }
.switch input:checked + .track::after { transform: translateX(21px); }

.hidden { display: none !important; }

/* Produits */
.produit {
  border: 1.5px solid var(--bord); border-radius: 12px; padding: 14px; margin-bottom: 12px; background: #fdfefe;
}
.produit-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.produit-head .t { font-weight: 800; color: var(--bleu-fonce); }
.produit-head .del { background: none; border: 0; color: var(--rouge); font-weight: 700; cursor: pointer; font-size: 14px; }
.prix-bloc { display: none; margin-top: 10px; padding-top: 12px; border-top: 1px dashed var(--bord); }
body.mode-commercial .prix-bloc { display: block; }
.prix-ligne { display: flex; align-items: center; justify-content: space-between; font-weight: 600; }
.prix-ligne .val { font-variant-numeric: tabular-nums; }
.add-produit {
  width: 100%; padding: 13px; border: 1.5px dashed var(--bleu); color: var(--bleu-fonce);
  background: var(--bleu-clair); border-radius: 11px; font-weight: 700; cursor: pointer;
}

/* Total commercial */
.total-bloc { display: none; }
body.mode-commercial .total-bloc {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--noir); color: #fff; padding: 16px 18px; border-radius: 12px; margin-bottom: 16px;
}
.total-bloc .lbl { font-weight: 700; font-size: 15px; }
.total-bloc .amount { font-weight: 800; font-size: 24px; font-variant-numeric: tabular-nums; }

/* Barre d'action bas de page */
.actionbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  background: #fff; border-top: 1px solid var(--bord); padding: 12px 16px;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
}
.actionbar .inner { max-width: 640px; margin: 0 auto; display: flex; gap: 12px; align-items: center; }
button.primary {
  flex: 1; padding: 16px; border: 0; border-radius: 12px; background: var(--bleu); color: #fff;
  font-size: 18px; font-weight: 800; cursor: pointer;
}
button.primary:active { background: var(--bleu-fonce); }
button.ghost { padding: 16px; border: 1.5px solid var(--bord); border-radius: 12px; background: #fff; font-weight: 700; cursor: pointer; }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: 92px; transform: translateX(-50%) translateY(20px);
  background: var(--noir); color: #fff; padding: 13px 18px; border-radius: 12px; font-weight: 600;
  opacity: 0; transition: all .25s; z-index: 40; max-width: 90%; text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { background: var(--rouge); }
.toast.ok { background: var(--ok); }

/* Login */
.login-wrap { max-width: 380px; margin: 12vh auto; padding: 0 20px; }
.login-wrap .card { padding: 26px; }
.login-wrap .logo { justify-content: center; font-size: 30px; margin-bottom: 4px; }
.login-wrap p.sub { text-align: center; color: var(--gris); margin: 0 0 22px; }
.err-msg { color: var(--rouge); font-weight: 600; margin-top: 10px; min-height: 20px; font-size: 14px; }

/* Admin */
.admin-toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 16px; }
.admin-toolbar input, .admin-toolbar select { width: auto; flex: 1 1 160px; }
table { width: 100%; border-collapse: collapse; background: #fff; font-size: 14px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--bord); white-space: nowrap; }
th { background: var(--gris-clair); font-size: 12px; text-transform: uppercase; letter-spacing: .4px; color: var(--gris); position: sticky; top: 0; }
.table-wrap { overflow-x: auto; border: 1px solid var(--bord); border-radius: 12px; }
td.money { font-variant-numeric: tabular-nums; font-weight: 700; }
