/* Traçabilité - Les Frères Toastés
   Vert pâle (sage), gros boutons, pensé pour un téléphone tenu d'une main en cuisine. */
:root {
  --bg: #E8F5E9;          /* vert très pâle */
  --bg-soft: #F4FAF4;
  --accent: #A5D6A7;      /* vert pâle */
  --primary: #2E7D32;     /* texte et boutons */
  --primary-dark: #1B5E20;
  --ink: #1B3A1F;
  --muted: #5F7A63;
  --card: #FFFFFF;
  --danger: #C62828;
  --radius: 18px;
  --tab-h: 70px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 17px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  padding-bottom: calc(var(--tab-h) + env(safe-area-inset-bottom) + 14px);
  -webkit-tap-highlight-color: transparent;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; opacity: 0; overflow: hidden; pointer-events: none; }

/* ---------- logo ---------- */
.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; justify-content: center;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: linear-gradient(#FFFFFF, var(--bg-soft));
  border-bottom: 3px solid var(--accent);
}
.logo { height: 46px; width: auto; max-width: 100%; display: block; }

main { max-width: 640px; margin: 0 auto; padding: 16px; }
.view { display: none; }
.view.is-active { display: block; animation: rise .25s ease-out; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

h1 { margin: 4px 0 14px; font-size: 1.55rem; color: var(--primary-dark); }
.step { margin-bottom: 8px; }
.step h2 { display: flex; align-items: center; gap: 10px; margin: 22px 0 10px; font-size: 1.08rem; color: var(--primary-dark); }
.step h2 small { font-weight: 500; color: var(--muted); }
.num { display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; background: var(--primary); color: #fff; font-size: .9rem; font-weight: 800; }

/* ---------- catégories ---------- */
.cats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.cat {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  min-height: 88px; padding: 10px;
  background: var(--card); border: 3px solid transparent; border-radius: var(--radius);
  box-shadow: 0 2px 0 rgba(46, 125, 50, .18), 0 6px 14px rgba(46, 125, 50, .08);
  font-weight: 800; font-size: 1.05rem; color: var(--ink);
  transition: transform .12s, background .15s, border-color .15s;
}
.cat:last-child:nth-child(odd) { grid-column: 1 / -1; min-height: 72px; flex-direction: row; gap: 12px; }
.cat .ic { font-size: 2rem; line-height: 1; }
.people .cat { min-height: 76px; }
.cat:active { transform: scale(.97); }
.cat { position: relative; }
.cat[aria-checked="true"] { background: var(--primary); border-color: var(--primary-dark); color: #fff; }
.cat[aria-checked="true"]::after { content: "✓"; position: absolute; top: 8px; right: 12px; font-size: 1.1rem; }

/* ---------- photo ---------- */
.photo {
  position: relative; display: grid; place-items: center; overflow: hidden;
  min-height: 190px; border: 3px dashed var(--primary); border-radius: var(--radius);
  background: var(--card); text-align: center; cursor: pointer;
}
.photo:active { background: var(--bg-soft); }
.photo-empty { display: grid; gap: 2px; padding: 18px; }
.photo-ic { font-size: 3.2rem; line-height: 1.1; }
.photo-t { font-size: 1.3rem; font-weight: 800; color: var(--primary); }
.photo-s { color: var(--muted); font-size: .95rem; }
.photo.has-photo { border-style: solid; border-color: var(--primary); }
.photo-preview { display: block; width: 100%; max-height: 360px; object-fit: contain; background: #0f1a10; }
.photo-again {
  position: absolute; right: 10px; bottom: 10px; padding: 8px 14px; border-radius: 999px;
  background: rgba(27, 94, 32, .92); color: #fff; font-weight: 700; font-size: .95rem;
}
.link { display: block; margin: 10px 2px 0; padding: 8px 0; color: var(--primary); font-weight: 700; text-decoration: underline; cursor: pointer; }

/* ---------- champs ---------- */
.field { display: block; margin: 0 0 12px; }
.field > span { display: block; margin: 0 2px 6px; font-weight: 700; color: var(--primary-dark); font-size: .98rem; }
.field input, .field textarea {
  display: block; width: 100%; min-height: 54px; padding: 12px 14px;
  background: var(--card); border: 2px solid var(--accent); border-radius: 14px; outline: none;
}
.field textarea { resize: vertical; min-height: 84px; }
.field input:focus, .field textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 4px rgba(46, 125, 50, .18); }

/* ---------- boutons ---------- */
.btn {
  display: block; width: 100%; min-height: 62px; padding: 14px 18px;
  border: 0; border-radius: var(--radius); font-weight: 800; font-size: 1.2rem; letter-spacing: .2px;
  transition: transform .12s, filter .15s, opacity .15s;
}
.btn:active { transform: scale(.98); }
.btn-primary { background: var(--primary); color: #fff; box-shadow: 0 6px 16px rgba(46, 125, 50, .35); margin-top: 8px; }
.btn-secondary { background: var(--accent); color: var(--primary-dark); margin: 4px 0 18px; }
.btn[aria-disabled="true"] { opacity: .45; box-shadow: none; }
.btn.is-busy { opacity: .75; pointer-events: none; }
.hint { margin: 10px 4px 0; text-align: center; color: var(--muted); font-size: .95rem; }
.hint.is-error { color: var(--danger); font-weight: 700; }
.shake { animation: shake .35s; }
@keyframes shake { 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }

/* ---------- onglets ---------- */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; display: grid; grid-template-columns: 1fr 1fr;
  padding-bottom: env(safe-area-inset-bottom);
  background: #fff; border-top: 3px solid var(--accent); box-shadow: 0 -6px 18px rgba(0, 0, 0, .06);
}
.tab {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  height: var(--tab-h); border: 0; background: transparent; color: var(--muted); font-weight: 800; font-size: .95rem;
}
.tab span { font-size: 1.5rem; line-height: 1; }
.tab.is-active { color: var(--primary); background: var(--bg-soft); box-shadow: inset 0 4px 0 var(--primary); }

/* ---------- historique ---------- */
.monthnav { display: grid; grid-template-columns: 60px 1fr 60px; gap: 8px; align-items: center; margin-bottom: 12px; }
.mbtn { height: 56px; border: 0; border-radius: 14px; background: var(--card); color: var(--primary); font-size: 2rem; font-weight: 800; box-shadow: 0 2px 0 rgba(46, 125, 50, .18); }
.mbtn:disabled { opacity: .3; }
.mlabel { text-align: center; font-size: 1.3rem; font-weight: 800; color: var(--primary-dark); }
.summary { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 12px; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 5px 12px; border-radius: 999px; background: var(--cat, var(--primary)); color: #fff; font-weight: 800; font-size: .9rem; }
.pill.total { background: var(--primary-dark); }
.day { margin: 20px 2px 8px; font-weight: 800; font-size: .95rem; text-transform: capitalize; color: var(--muted); letter-spacing: .3px; }
.rec { display: grid; grid-template-columns: 96px 1fr; gap: 12px; margin-bottom: 10px; padding: 10px; background: var(--card); border-radius: var(--radius); box-shadow: 0 2px 0 rgba(46, 125, 50, .15); }
.thumb { padding: 0; border: 0; border-radius: 12px; overflow: hidden; background: var(--bg); width: 96px; height: 96px; }
.thumb img { display: block; width: 100%; height: 100%; object-fit: cover; }
.info { min-width: 0; display: flex; flex-direction: column; gap: 4px; justify-content: center; }
.line1 { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.chip { padding: 3px 12px; border-radius: 999px; background: var(--cat, var(--primary)); color: #fff; font-weight: 800; font-size: .88rem; }
.when { font-weight: 800; font-variant-numeric: tabular-nums; }
.dlc { font-weight: 700; color: var(--primary-dark); font-size: .95rem; }
.who { font-weight: 800; color: var(--ink); font-size: .95rem; }
.note { margin: 0; color: var(--ink); font-size: .95rem; overflow-wrap: anywhere; }
.empty { padding: 28px 8px; text-align: center; color: var(--muted); }

/* ---------- supprimer un produit ---------- */
.rec-del { align-self: flex-start; margin-top: 4px; padding: 6px 12px; border: 2px solid #E57373; border-radius: 12px; background: #fff; color: var(--danger); font-weight: 800; font-size: .88rem; }
.rec-del:active { background: #FFEBEE; }
.del-note { margin: -4px 2px 12px; color: var(--muted); font-size: .9rem; }
.sheet { align-items: end; overflow-y: auto; background: rgba(8, 20, 9, .6); }
.del-card { width: 100%; max-width: 560px; max-height: 100%; overflow-y: auto; margin: auto; padding: 20px 18px calc(18px + env(safe-area-inset-bottom)); background: var(--bg); border-radius: 22px; box-shadow: 0 20px 50px rgba(0, 0, 0, .4); }
.del-card h2 { margin: 0 0 6px; color: var(--danger); }
.del-card h3 { margin: 14px 0 8px; font-size: 1.02rem; color: var(--primary-dark); }
.del-sum { margin: 0 0 6px; font-weight: 800; }
.del-help { margin: 0; color: var(--muted); font-size: .92rem; }
.btn-danger { background: var(--danger); color: #fff; box-shadow: 0 6px 16px rgba(198, 40, 40, .3); margin-top: 6px; }
.btn-ghost { background: transparent; color: var(--primary-dark); border: 2px solid var(--accent); margin-top: 10px; min-height: 54px; }
.field small { font-weight: 500; color: var(--muted); }

/* ---------- PDF enregistrés ---------- */
.archives-wrap { margin-top: 30px; padding-top: 6px; border-top: 3px solid var(--accent); }
.archives-wrap h2 { margin: 16px 0 4px; font-size: 1.2rem; color: var(--primary-dark); }
.arch-help { margin: 0 0 12px; color: var(--muted); font-size: .92rem; }
.arch { display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: center; margin-bottom: 10px; padding: 12px 14px; background: var(--card); border-radius: var(--radius); box-shadow: 0 2px 0 rgba(46, 125, 50, .15); }
.arch-txt { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.arch-txt strong { font-size: 1.08rem; color: var(--primary-dark); }
.arch-txt span { color: var(--muted); font-size: .88rem; }
.arch-badge { display: inline-block; margin-right: 6px; padding: 1px 9px; border-radius: 999px; background: var(--primary); color: #fff; font-weight: 800; font-size: .78rem; }
.arch-badge.live { background: var(--accent); color: var(--primary-dark); }
.arch-btn { min-height: 50px; padding: 0 16px; border: 0; border-radius: 14px; background: var(--primary); color: #fff; font-weight: 800; }
.arch-btn:disabled { opacity: .6; }

/* ---------- code d'accès / photo en grand / message ---------- */
.overlay { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: 20px; background: var(--bg); }
.login-card { width: 100%; max-width: 380px; display: grid; gap: 14px; justify-items: center; text-align: center; }
.login-card .logo { height: 64px; }
.login-card h2 { margin: 6px 0 0; color: var(--primary-dark); }
.login-card input { width: 100%; min-height: 64px; padding: 12px; text-align: center; font-size: 1.8rem; letter-spacing: 6px; background: #fff; border: 3px solid var(--accent); border-radius: 16px; outline: none; }
.login-card input:focus { border-color: var(--primary); }
.login-card .btn { margin-top: 0; }
.login-err { min-height: 1.4em; margin: 0; color: var(--danger); font-weight: 700; }

.viewer { position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; background: rgba(8, 20, 9, .94); }
.viewer img { max-width: 100vw; max-height: 100vh; object-fit: contain; }
.viewer-x { position: absolute; top: calc(12px + env(safe-area-inset-top)); right: 12px; width: 52px; height: 52px; border: 0; border-radius: 50%; background: rgba(255, 255, 255, .95); color: var(--primary-dark); font-size: 1.4rem; font-weight: 800; }

#toast {
  position: fixed; left: 12px; right: 12px; bottom: calc(var(--tab-h) + env(safe-area-inset-bottom) + 14px); z-index: 40;
  max-width: 560px; margin: 0 auto; padding: 14px 18px; border-radius: 16px;
  background: var(--primary-dark); color: #fff; font-weight: 700; text-align: center;
  box-shadow: 0 10px 28px rgba(0, 0, 0, .28); opacity: 0; transform: translateY(12px); pointer-events: none; transition: opacity .2s, transform .2s;
}
#toast.show { opacity: 1; transform: none; }
#toast.error { background: var(--danger); }

@media (min-width: 560px) {
  .cats { grid-template-columns: repeat(3, 1fr); }
  .cat:last-child:nth-child(odd) { grid-column: auto; min-height: 88px; flex-direction: column; gap: 4px; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
