/* app.css — Styles communs gestionnaire + coursier */

:root {
  --bg: #f6f3ee;
  --surface: #ffffff;
  --surface-2: #efeae2;
  --text: #1f2421;
  --muted: #6b716c;
  --line: #e2dcd2;
  --accent: #1e5b4f;
  --accent-soft: #dcebe6;
  --on-accent: #ffffff;
  --danger: #b4432f;
  --danger-soft: #f7e3de;
  --ok: #2f7d4f;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(30, 30, 20, .06), 0 6px 20px rgba(30, 30, 20, .06);
  color-scheme: light;
}
body.coursier {
  --accent: #a3561f;
  --accent-soft: #f6e6d8;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #151816;
    --surface: #1e2220;
    --surface-2: #262b28;
    --text: #ecebe6;
    --muted: #9aa19c;
    --line: #313733;
    --accent: #6fb7a5;
    --accent-soft: #23362f;
    --on-accent: #0d1a16;
    --danger: #e8846f;
    --danger-soft: #3a2420;
    --shadow: none;
    color-scheme: dark;
  }
  :root:not([data-theme="light"]) body.coursier {
    --accent: #e3a06c;
    --accent-soft: #3a2a1d;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100dvh;
  -webkit-tap-highlight-color: transparent;
}
[lang="ar"], .ar { font-family: "Noto Sans Arabic", "Inter", system-ui, sans-serif; }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }

/* ---------- Écrans centrés (chargement, PIN) ---------- */
.center {
  min-height: 100dvh;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 24px 16px 32px;
  text-align: center;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  font-weight: 700; letter-spacing: -.01em; font-size: 1.05rem;
  margin-bottom: 28px;
}
.brand-mark {
  width: 34px; height: 34px; border-radius: 10px;
  background: var(--accent); color: var(--on-accent);
  display: grid; place-items: center; font-size: 18px;
}
.center h1 { font-size: 1.35rem; margin: 0 0 6px; letter-spacing: -.01em; }
.center .sub { color: var(--muted); margin: 0 0 22px; max-width: 320px; }
.center .sub .ar { display: block; margin-top: 2px; }

.msg {
  min-height: 1.5em; margin: 14px 0 0; font-size: .95rem; color: var(--muted);
  max-width: 320px;
}
.msg.error { color: var(--danger); }
.msg.ok { color: var(--ok); }

.spinner {
  width: 34px; height: 34px; border-radius: 50%;
  border: 3px solid var(--line); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Pavé numérique ---------- */
.pinpad { width: 100%; max-width: 300px; }
.pin-dots { display: flex; justify-content: center; gap: 14px; margin-bottom: 26px; }
.pin-dots span {
  width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid var(--muted); transition: background .12s, border-color .12s, transform .12s;
}
.pin-dots span.on { background: var(--accent); border-color: var(--accent); transform: scale(1.1); }
.pin-keys { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.pin-keys button {
  height: 64px; border-radius: 50%; border: 0;
  width: 64px; justify-self: center;
  background: var(--surface); box-shadow: var(--shadow);
  font-size: 1.5rem; font-weight: 500;
  transition: transform .08s, background .12s;
}
.pin-keys button:active { transform: scale(.94); background: var(--accent-soft); }
.pin-keys .pin-del { background: transparent; box-shadow: none; font-size: 1.3rem; color: var(--muted); }
.pinpad.busy { opacity: .55; pointer-events: none; }
.pinpad.shake { animation: shake .35s; }
@keyframes shake {
  20%, 60% { transform: translateX(-8px); }
  40%, 80% { transform: translateX(8px); }
}

/* ---------- Interface principale ---------- */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 16px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.topbar .brand { margin: 0; font-size: 1rem; }
.topbar .brand-mark { width: 30px; height: 30px; font-size: 16px; border-radius: 9px; }
.role {
  font-size: .75rem; font-weight: 600; padding: 3px 9px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent);
}
.btn-ghost {
  border: 1px solid var(--line); background: var(--surface);
  border-radius: 10px; padding: 7px 12px; font-size: .9rem;
}

main.content { padding: 18px 16px 110px; max-width: 760px; margin: 0 auto; }
main.content h2 { font-size: 1.3rem; margin: 4px 0 4px; letter-spacing: -.01em; }
main.content .lead { color: var(--muted); margin: 0 0 18px; }

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow);
}
.card + .card { margin-top: 12px; }
.placeholder { text-align: center; padding: 34px 18px; color: var(--muted); }
.placeholder .icon { font-size: 2rem; display: block; margin-bottom: 8px; }
.placeholder strong { color: var(--text); display: block; margin-bottom: 4px; }
.kv { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.kv:last-child { border-bottom: 0; }
.kv span:first-child { color: var(--muted); }

/* Barre d'onglets en bas (mobile) */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  display: flex; justify-content: center;
  background: var(--surface); border-top: 1px solid var(--line);
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
}
.tabbar-inner { display: flex; width: 100%; max-width: 560px; }
.tabbar button {
  flex: 1; border: 0; background: none;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 6px 4px; border-radius: 12px;
  font-size: .72rem; color: var(--muted); line-height: 1.2;
}
.tabbar button .ico { font-size: 1.25rem; }
.tabbar button .ar { font-size: .78rem; }
.tabbar button[aria-selected="true"] { color: var(--accent); background: var(--accent-soft); font-weight: 600; }

@media (min-width: 900px) {
  .tabbar { top: 61px; bottom: auto; border-top: 0; border-bottom: 1px solid var(--line); background: var(--bg); padding: 6px 16px; }
  .tabbar button { flex-direction: row; gap: 8px; font-size: .9rem; padding: 8px 12px; }
  main.content { padding-top: 76px; padding-bottom: 40px; }
}

/* Barre du haut compacte sur téléphone */
.topbar .brand, .btn-ghost { white-space: nowrap; }
@media (max-width: 440px) {
  .topbar .brand-name { display: none; }
}

/* =================================================================
   Étape 2 — Tâches
   ================================================================= */

/* Filtres */
.seg {
  display: flex; gap: 6px; padding: 4px; margin: 0 0 14px;
  background: var(--surface-2); border-radius: 12px; overflow-x: auto;
}
.seg button {
  flex: 1; border: 0; background: none; border-radius: 9px;
  padding: 8px 10px; font-size: .88rem; color: var(--muted); white-space: nowrap;
}
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: var(--shadow); }
.seg .count {
  display: inline-block; min-width: 20px; padding: 0 6px; margin-left: 4px;
  border-radius: 999px; background: var(--line); font-size: .75rem; line-height: 20px; text-align: center;
}
.seg .count.hot { background: var(--accent); color: var(--on-accent); }

/* Liste des tâches */
.task-list { display: flex; flex-direction: column; gap: 10px; }
.task {
  display: flex; gap: 12px; align-items: flex-start; width: 100%; text-align: left;
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
  padding: 14px; box-shadow: var(--shadow);
}
.task.urgent { border-left: 4px solid var(--danger); }
.task .t-ico {
  width: 40px; height: 40px; flex: none; border-radius: 11px;
  background: var(--surface-2); display: grid; place-items: center; font-size: 1.25rem;
}
.task .t-body { flex: 1; min-width: 0; }
.task .t-title { font-weight: 600; margin: 0 0 4px; overflow-wrap: anywhere; }
.task .t-meta { display: flex; flex-wrap: wrap; gap: 6px; font-size: .8rem; color: var(--muted); }
.task.done .t-title { color: var(--muted); }

.badge {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: .75rem; font-weight: 600; padding: 2px 8px; border-radius: 999px;
  background: var(--surface-2); color: var(--muted); white-space: nowrap;
}
.badge.urgent, .badge.late { background: var(--danger-soft); color: var(--danger); }
.st-afaire    { background: var(--surface-2); color: var(--text); }
.st-terminee  { background: #fbecc7; color: #7a5300; }
.st-reprendre { background: var(--danger-soft); color: var(--danger); }
.st-validee   { background: #dcefe2; color: #2f6b45; }
.st-annulee   { background: var(--surface-2); color: var(--muted); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .st-terminee { background: #3b3018; color: #f1cf7c; }
  :root:not([data-theme="light"]) .st-validee  { background: #1f3a2a; color: #8fd3a8; }
}

.empty { text-align: center; color: var(--muted); padding: 36px 12px; }
.empty .icon { font-size: 2rem; display: block; margin-bottom: 6px; }

/* Bouton flottant « + » */
.fab {
  position: fixed; right: 16px; bottom: calc(84px + env(safe-area-inset-bottom)); z-index: 6;
  border: 0; border-radius: 16px; padding: 14px 18px;
  background: var(--accent); color: var(--on-accent); font-weight: 600;
  box-shadow: 0 6px 20px rgba(0,0,0,.18);
}
@media (min-width: 900px) { .fab { bottom: 28px; right: 28px; } }

/* Boutons */
.btn {
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  border-radius: 12px; padding: 11px 16px; font-weight: 600; font-size: .95rem;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.danger  { color: var(--danger); border-color: var(--danger-soft); background: var(--danger-soft); }
.btn.ok      { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn:disabled { opacity: .5; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 18px; }
.actions .btn { flex: 1 1 140px; }

/* Panneau (fenêtre du bas sur mobile, centrée sur ordinateur) */
.sheet-back {
  position: fixed; inset: 0; z-index: 20; background: rgba(15, 18, 16, .45);
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet {
  width: 100%; max-width: 560px; max-height: 92dvh; overflow-y: auto;
  background: var(--bg); border-radius: 20px 20px 0 0;
  padding: 18px 16px calc(20px + env(safe-area-inset-bottom));
  animation: up .2s ease-out;
}
@media (min-width: 700px) {
  .sheet-back { align-items: center; }
  .sheet { border-radius: 20px; padding: 22px; }
}
@keyframes up { from { transform: translateY(30px); opacity: 0; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; }
.sheet-head h3 { margin: 0; font-size: 1.15rem; }
.x { border: 0; background: var(--surface-2); width: 34px; height: 34px; border-radius: 50%; font-size: 1.1rem; }

/* Formulaire */
.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: .85rem; font-weight: 600; margin-bottom: 6px; }
.field small { color: var(--muted); font-weight: 400; }
.field input, .field textarea, .field select {
  width: 100%; font: inherit; color: var(--text);
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 11px 12px;
}
.field textarea { min-height: 80px; resize: vertical; }
.field input:focus, .field textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.cats { display: grid; grid-template-columns: repeat(auto-fill, minmax(98px, 1fr)); gap: 8px; }
.cats button {
  border: 1px solid var(--line); background: var(--surface); border-radius: 12px;
  padding: 8px 4px; font-size: .74rem; line-height: 1.2; display: flex; flex-direction: column; align-items: center; gap: 3px;
}
.cats button .e { font-size: 1.3rem; }
.cats button[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); font-weight: 600; }

.toggle { display: flex; gap: 8px; }
.toggle button { flex: 1; border: 1px solid var(--line); background: var(--surface); border-radius: 12px; padding: 10px; font-weight: 600; }
.toggle button[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.toggle button.urg[aria-pressed="true"] { border-color: var(--danger); background: var(--danger-soft); color: var(--danger); }

.form-error { color: var(--danger); font-size: .9rem; min-height: 1.2em; margin: 4px 0 0; }

/* Détail d'une tâche */
.detail-title { font-size: 1.2rem; font-weight: 700; margin: 0 0 8px; overflow-wrap: anywhere; }
.detail-desc { white-space: pre-wrap; margin: 12px 0; overflow-wrap: anywhere; }
.note {
  border-radius: 12px; padding: 10px 12px; margin-top: 12px; font-size: .92rem;
  background: var(--surface-2);
}
.note.warn { background: var(--danger-soft); color: var(--danger); }
.note strong { display: block; font-size: .8rem; margin-bottom: 2px; }
.detail-photo { width: 100%; border-radius: 12px; margin-top: 10px; }

/* Message bref en bas de l'écran */
.toast {
  position: fixed; left: 50%; top: calc(70px + env(safe-area-inset-top)); z-index: 30;
  transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: .92rem;
  box-shadow: 0 6px 20px rgba(0,0,0,.2); max-width: calc(100% - 32px);
}

/* =================================================================
   Étape 2.1 — Priorités, produits et catalogue
   ================================================================= */

:root { --warn: #9a6400; --warn-soft: #fbecc7; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --warn: #f1cf7c; --warn-soft: #3b3018; }
}

/* Priorité moyenne */
.badge.moyenne { background: var(--warn-soft); color: var(--warn); }
.task.moyenne { border-left: 4px solid #d79a1d; }
.toggle button.moyenne[aria-pressed="true"] { border-color: #d79a1d; background: var(--warn-soft); color: var(--warn); }

.sheet.wide { max-width: 760px; }
.link { border: 0; background: none; padding: 0; color: var(--accent); font-weight: 600; text-decoration: underline; text-underline-offset: 3px; }
.hint { color: var(--muted); font-size: .82rem; margin: 6px 0 0; }
.spinner.small { width: 22px; height: 22px; border-width: 2px; }

/* Lien « Mes produits » dans Paramètres */
.setting-link { display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; margin-bottom: 12px; }
.setting-link .t-ico { width: 42px; height: 42px; border-radius: 11px; background: var(--accent-soft); display: grid; place-items: center; font-size: 1.3rem; flex: none; }
.setting-link strong { display: block; }
.setting-link small { color: var(--muted); }
.setting-link > span:nth-child(2) { flex: 1; }
.setting-link .chev { font-size: 1.6rem; color: var(--muted); }

/* Vignettes sur les cartes de tâche */
.thumbs { display: flex; gap: 4px; margin-top: 8px; }
.mini {
  width: 30px; height: 30px; border-radius: 7px; object-fit: cover; flex: none;
  background: var(--surface-2); display: grid; place-items: center; font-size: .9rem;
}
.mini.more { font-size: .72rem; font-weight: 700; color: var(--muted); }

/* Lignes de produits (formulaire et détail) */
.lines { display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; }
.lines:empty { display: none; }
.lines.view { margin: 14px 0 0; }
.line {
  display: flex; align-items: center; gap: 10px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 8px;
}
.lthumb {
  width: 48px; height: 48px; border-radius: 9px; object-fit: cover; flex: none;
  background: var(--surface-2); display: grid; place-items: center; font-size: 1.4rem;
}
.lname { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.lname strong { font-size: .92rem; overflow-wrap: anywhere; }
.lname span { font-size: .82rem; color: var(--muted); font-family: "Noto Sans Arabic", "Inter", sans-serif; }
.lqte { font-weight: 700; white-space: nowrap; }
.lunit { font-size: .8rem; color: var(--muted); min-width: 44px; }
.lrm { border: 0; background: none; color: var(--muted); font-size: 1rem; padding: 6px; }
.stepper { display: flex; align-items: center; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; flex: none; }
.stepper button { border: 0; background: var(--surface-2); width: 30px; height: 34px; font-size: 1.1rem; font-weight: 600; }
.stepper input {
  width: 48px; height: 34px; border: 0; text-align: center; font: inherit; font-weight: 600;
  background: var(--surface); color: var(--text); -moz-appearance: textfield;
}
.stepper input::-webkit-outer-spin-button, .stepper input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.add-prod { width: 100%; border-style: dashed; }
@media (max-width: 400px) {
  .line { flex-wrap: wrap; }
  .lname { flex-basis: calc(100% - 100px); }
  .stepper { margin-left: 58px; }
}

/* Barre recherche + filtres du catalogue */
.cat-toolbar { display: flex; gap: 8px; margin-bottom: 10px; }
.search {
  flex: 1; min-width: 0; font: inherit; color: var(--text);
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px;
}
.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 6px; margin-bottom: 8px; scrollbar-width: thin; }
.chips button {
  flex: none; border: 1px solid var(--line); background: var(--surface); border-radius: 999px;
  padding: 6px 12px; font-size: .85rem; white-space: nowrap;
}
.chips button[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.chips .count { color: var(--muted); font-size: .75rem; margin-left: 2px; }
.check { display: flex; align-items: center; gap: 8px; font-size: .85rem; color: var(--muted); margin: 0 0 12px; }

/* Grille de produits */
.pgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(108px, 1fr)); gap: 10px; }
.pcard {
  position: relative; display: flex; flex-direction: column; align-items: stretch; gap: 3px; text-align: center;
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 6px 6px 8px;
}
.pthumb {
  width: 100%; aspect-ratio: 1; border-radius: 10px; object-fit: cover;
  background: var(--surface-2); display: grid; place-items: center; font-size: 2rem;
}
.pname { font-size: .82rem; font-weight: 600; line-height: 1.2; overflow-wrap: anywhere; }
.pname-ar { font-size: .78rem; color: var(--muted); font-family: "Noto Sans Arabic", "Inter", sans-serif; }
.punit { font-size: .72rem; color: var(--muted); }
.pcard.on { border: 2px solid var(--accent); background: var(--accent-soft); padding: 5px 5px 7px; }
.pcard.there:not(.on) { opacity: .55; }
.pcard.archived { opacity: .5; }
.pcard.new .pthumb { color: var(--accent); font-size: 2.2rem; border: 2px dashed var(--line); background: transparent; }
.pcard .tick {
  position: absolute; top: 10px; right: 10px; width: 26px; height: 26px; border-radius: 50%;
  background: var(--accent); color: var(--on-accent); display: grid; place-items: center; font-weight: 700;
}
.pick-bar {
  position: sticky; bottom: calc(-20px - env(safe-area-inset-bottom)); margin: 14px -16px calc(-20px - env(safe-area-inset-bottom));
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: var(--bg); border-top: 1px solid var(--line);
}
@media (min-width: 700px) { .pick-bar { bottom: -22px; margin: 14px -22px -22px; padding: 12px 22px; } }
.pick-count { color: var(--muted); font-size: .9rem; }

/* Fiche produit : photo */
.photo-pick { display: flex; gap: 14px; align-items: center; margin-bottom: 16px; }
.photo-box {
  width: 104px; height: 104px; flex: none; border-radius: 14px; overflow: hidden;
  background: var(--surface-2); display: grid; place-items: center; font-size: 2rem; border: 1px dashed var(--line);
}
.photo-box img { width: 100%; height: 100%; object-fit: cover; }
.photo-pick label.btn { display: inline-block; cursor: pointer; }
.photo-pick .link { display: block; margin-top: 8px; font-size: .85rem; }
.field select { appearance: auto; }
.detail-desc { white-space: pre-wrap; overflow-wrap: anywhere; }
.lname span { text-align: left; }
.lines.view .line { flex-wrap: nowrap; }
.lines.view .lname { flex-basis: auto; }

/* Étape 2.2 — multi-catégories et import fruits/légumes */
.chips.wrap { flex-wrap: wrap; overflow: visible; }
.import-btn { width: 100%; margin-bottom: 12px; border-style: dashed; }
.imp-group { margin: 18px 0 8px; font-size: .95rem; }
.imp-tools { display: flex; gap: 16px; margin: 4px 0 4px; font-size: .9rem; }
.pcard:disabled { cursor: default; }

/* Étape 4.3 — Rangées de boutons en BLOCS (téléphone) :
   plus de défilement de gauche à droite, tout est visible d'un coup. */
.chips, .chips.wrap {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(105px, 1fr));
  gap: 8px; overflow: visible; padding-bottom: 0; margin-bottom: 12px;
}
.chips button {
  flex: initial; white-space: normal; border-radius: 12px;
  min-height: 46px; padding: 8px 6px; line-height: 1.2; text-align: center;
  display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 4px;
}
.chips .count { margin-left: 0; }
