/* Garde-manger — feuille de style
   Ambiance : intérieur de réfrigérateur (émail froid), dates imprimées en points comme sur les emballages. */

@font-face { font-family: "Atkinson"; src: url("/fonts/atkinson-400.woff2") format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Atkinson"; src: url("/fonts/atkinson-700.woff2") format("woff2"); font-weight: 700; font-display: swap; }
@font-face { font-family: "Dot"; src: url("/fonts/dotgothic16.woff2") format("woff2"); font-weight: 400; font-display: swap; }

:root {
  --bg: #e9f0ed;
  --surface: #ffffff;
  --surface-2: #f4f8f6;
  --ink: #13211c;
  --muted: #55665f;
  --line: #cbd8d2;
  --primary: #1d5c46;
  --primary-ink: #ffffff;
  --primary-soft: #d6e9e0;
  --focus: #1f63d6;

  --expired: #a8261d;  --expired-bg: #fbe3df;
  --soon: #7a4f00;     --soon-bg: #fbedc4;
  --ok: #24653a;       --ok-bg: #dcefe1;
  --none: #55665f;     --none-bg: #eef2f0;

  --radius-s: 8px;
  --radius-m: 12px;
  --radius-l: 18px;
  --shadow: 0 1px 0 rgba(19, 33, 28, .06), 0 6px 18px -10px rgba(19, 33, 28, .25);
  --nav-h: 68px;
  --font: "Atkinson", system-ui, -apple-system, "Segoe UI", sans-serif;
  --dot: "Dot", ui-monospace, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1a17;
    --surface: #17241f;
    --surface-2: #1d2c27;
    --ink: #e4eeea;
    --muted: #9db1a9;
    --line: #2d403a;
    --primary: #6cc59d;
    --primary-ink: #0b1a14;
    --primary-soft: #1f3a30;
    --focus: #8ab4ff;
    --expired: #ff9d92;  --expired-bg: #3a1c19;
    --soon: #f3c766;     --soon-bg: #362b12;
    --ok: #8fd6a4;       --ok-bg: #18331f;
    --none: #9db1a9;     --none-bg: #1d2c27;
    --shadow: 0 1px 0 rgba(0, 0, 0, .3), 0 8px 22px -12px rgba(0, 0, 0, .6);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: var(--font); font-size: 17px; line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { line-height: 1.2; margin: 0; }
h1 { font-size: 1.6rem; letter-spacing: -.01em; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .75em; }
a { color: var(--primary); }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }
.small { font-size: .88rem; }
.boot { padding: 2rem; color: var(--muted); }
[hidden] { display: none !important; }

/* ---------- Structure ---------- */
.shell { min-height: 100dvh; }
.main {
  max-width: 780px; margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 18px) 16px calc(var(--nav-h) + env(safe-area-inset-bottom) + 96px);
}
.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; min-height: 44px; }
.page-head h1 { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.back { margin-left: -8px; }
.section { margin-top: 26px; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 10px; }

.nav {
  position: fixed; inset: auto 0 0 0; z-index: 20;
  display: grid; grid-template-columns: repeat(5, 1fr);
  height: calc(var(--nav-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface); border-top: 1px solid var(--line);
}
.nav a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  text-decoration: none; color: var(--muted); font-size: .74rem; position: relative;
}
.nav a svg { width: 24px; height: 24px; }
.nav a[aria-current="page"] { color: var(--primary); font-weight: 700; }
.nav a[aria-current="page"]::before {
  content: ""; position: absolute; top: 0; left: 25%; right: 25%; height: 3px; border-radius: 0 0 3px 3px; background: var(--primary);
}
.nav .badge { position: absolute; top: 8px; left: calc(50% + 6px); }
.nav .brand { display: none; }

@media (min-width: 900px) {
  .shell { display: grid; grid-template-columns: 232px 1fr; }
  .nav {
    position: sticky; top: 0; height: 100dvh; inset: auto; padding: 22px 14px;
    display: flex; flex-direction: column; gap: 4px;
    border-top: 0; border-right: 1px solid var(--line);
  }
  .nav .brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.1rem; padding: 4px 10px 22px; color: var(--ink); }
  .nav .brand svg { width: 30px; height: 30px; }
  .nav a { flex-direction: row; justify-content: flex-start; gap: 12px; padding: 11px 12px; border-radius: var(--radius-m); font-size: 1rem; }
  .nav a[aria-current="page"] { background: var(--primary-soft); }
  .nav a[aria-current="page"]::before { display: none; }
  .nav .badge { position: static; margin-left: auto; }
  .main { padding: 36px 32px 120px; }
}

/* ---------- Boutons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 46px; padding: 0 18px; border-radius: var(--radius-m);
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  font-weight: 700; cursor: pointer; text-decoration: none; white-space: nowrap;
  touch-action: manipulation;
}
.btn svg { width: 20px; height: 20px; flex: none; }
.btn:hover { border-color: var(--muted); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn-primary:hover { filter: brightness(1.08); border-color: var(--primary); }
.btn-danger { color: var(--expired); border-color: currentColor; background: transparent; }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--surface-2); border-color: transparent; }
.btn-block { width: 100%; }
.btn-sm { min-height: 38px; padding: 0 12px; font-size: .92rem; }
.icon-btn {
  display: inline-grid; place-items: center; width: 44px; height: 44px; flex: none;
  border-radius: 50%; border: 0; background: transparent; color: var(--ink); cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn svg { width: 22px; height: 22px; }
.btn-row { display: flex; flex-wrap: wrap; gap: 10px; }
.btn-row > .btn { flex: 1 1 auto; }

.fab {
  position: fixed; z-index: 15; right: 18px; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 18px);
  display: inline-flex; align-items: center; gap: 10px; height: 58px; padding: 0 22px 0 18px;
  border-radius: 29px; border: 0; background: var(--primary); color: var(--primary-ink);
  font-weight: 700; font-size: 1.02rem; box-shadow: var(--shadow); cursor: pointer; text-decoration: none;
}
.fab svg { width: 24px; height: 24px; }
@media (min-width: 900px) { .fab { bottom: 28px; right: 32px; } }

/* ---------- Panneaux et lignes ---------- */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-l); box-shadow: var(--shadow); }
.panel-pad { padding: 18px; }
.rows { list-style: none; margin: 0; padding: 0; }
.rows > li + li { border-top: 1px solid var(--line); }
.row {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px; min-height: 64px;
  color: inherit; text-decoration: none; width: 100%; background: none; border: 0; text-align: left; cursor: pointer;
}
.row:hover { background: var(--surface-2); }
.rows > li:first-child .row { border-radius: var(--radius-l) var(--radius-l) 0 0; }
.rows > li:last-child .row { border-radius: 0 0 var(--radius-l) var(--radius-l); }
.rows > li:only-child .row { border-radius: var(--radius-l); }
.row-main { flex: 1; min-width: 0; }
.row-title { display: block; font-weight: 700; overflow-wrap: anywhere; }
.row-meta { display: block; color: var(--muted); font-size: .9rem; }
.row-thumb { width: 44px; height: 44px; border-radius: var(--radius-s); object-fit: cover; flex: none; background: var(--surface-2); }

.empty { text-align: center; padding: 34px 20px; color: var(--muted); }
.empty svg { width: 48px; height: 48px; opacity: .55; margin-bottom: 6px; }
.empty .btn { margin-top: 12px; }

/* ---------- Tampon de date (élément signature) ---------- */
.stamp {
  flex: none; display: grid; justify-items: end; gap: 2px; min-width: 102px; text-align: right;
  padding: 6px 10px; border-radius: var(--radius-s);
  border: 1.5px dashed currentColor; color: var(--none); background: var(--none-bg);
}
.stamp-date { font-family: var(--dot); font-size: 1.12rem; letter-spacing: .06em; line-height: 1.1; }
.stamp-state { display: inline-flex; align-items: center; gap: 4px; font-size: .78rem; font-weight: 700; line-height: 1.1; }
.stamp-state svg { width: 14px; height: 14px; }
.stamp[data-state="expired"] { color: var(--expired); background: var(--expired-bg); border-style: solid; }
.stamp[data-state="soon"] { color: var(--soon); background: var(--soon-bg); border-style: solid; }
.stamp[data-state="ok"] { color: var(--ok); background: var(--ok-bg); }
/* Date estimée : pointillés serrés et mention, pour la distinguer d'une date imprimée */
.stamp[data-estimated] { border-style: dotted; border-width: 2px; }
.stamp-est { font-size: .7rem; font-weight: 400; opacity: .85; line-height: 1; }
.stamp[data-state="none"] .stamp-date { font-family: var(--font); font-size: .9rem; letter-spacing: 0; }

.badge {
  display: inline-grid; place-items: center; min-width: 20px; height: 20px; padding: 0 6px;
  border-radius: 10px; background: var(--expired); color: #fff; font-size: .72rem; font-weight: 700;
}

/* ---------- Tableau de bord ---------- */
.tally { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.tally a {
  display: grid; gap: 2px; padding: 12px 10px; border-radius: var(--radius-m); text-decoration: none;
  background: var(--surface); border: 1px solid var(--line); color: var(--ink);
}
.tally strong { font-size: 1.5rem; line-height: 1; display: flex; align-items: center; gap: 6px; }
.tally strong svg { width: 18px; height: 18px; }
.tally span { font-size: .82rem; color: var(--muted); }
.tally a[data-state="expired"] strong { color: var(--expired); }
.tally a[data-state="soon"] strong { color: var(--soon); }
.tally a[data-state="ok"] strong { color: var(--ok); }
@media (max-width: 420px) { .tally { grid-template-columns: repeat(2, 1fr); } }

.greet { margin-bottom: 18px; }
.greet p { color: var(--muted); margin: 4px 0 0; }

.list-cards { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.list-card { display: block; padding: 14px 16px; border-radius: var(--radius-m); background: var(--surface); border: 1px solid var(--line); text-decoration: none; color: inherit; }
.list-card:hover { border-color: var(--muted); }
.progress { height: 6px; border-radius: 3px; background: var(--surface-2); margin-top: 10px; overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--primary); }

/* ---------- Formulaires ---------- */
.form { display: grid; gap: 14px; }
.field { display: grid; gap: 6px; }
.field > span, .field-label { font-weight: 700; font-size: .95rem; }
.field small { color: var(--muted); font-size: .85rem; }
.input, select.input, textarea.input {
  width: 100%; min-height: 48px; padding: 10px 12px; font-size: 16px;
  border: 1.5px solid var(--line); border-radius: var(--radius-m); background: var(--surface); color: var(--ink);
}
textarea.input { min-height: 84px; resize: vertical; }
.input:focus { border-color: var(--primary); outline: none; box-shadow: 0 0 0 3px var(--primary-soft); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
@media (max-width: 480px) { .grid-3 { grid-template-columns: 1fr 1fr; } }
.quick-dates { display: flex; flex-wrap: wrap; gap: 6px; }
.estimate-hint {
  display: flex; gap: 10px; padding: 10px 12px; border-radius: var(--radius-m);
  background: var(--surface-2); border: 1px dashed var(--line); font-size: .92rem;
}
.estimate-hint svg { width: 20px; height: 20px; flex: none; color: var(--primary); margin-top: 1px; }
.estimate-hint strong { display: block; }
.linkish {
  display: inline; padding: 0; margin: 0; border: 0; background: none; color: var(--primary);
  font-weight: 700; text-decoration: underline; cursor: pointer; min-height: 32px;
}
.notice .linkish { color: inherit; }
.check { display: flex; align-items: center; gap: 10px; min-height: 44px; cursor: pointer; }
.check input { width: 22px; height: 22px; accent-color: var(--primary); flex: none; }
.err { color: var(--expired); font-weight: 700; }
fieldset { border: 0; padding: 0; margin: 0; }

/* ---------- Puces / filtres ---------- */
.toolbar { display: grid; gap: 10px; margin-bottom: 14px; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.chip {
  flex: none; display: inline-flex; align-items: center; gap: 6px; min-height: 38px; padding: 0 14px;
  border-radius: 19px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; font-size: .92rem;
}
.chip svg { width: 16px; height: 16px; }
.chip[aria-pressed="true"] { background: var(--ink); color: var(--surface); border-color: var(--ink); }
.search { position: relative; }
.search svg { position: absolute; left: 12px; top: 50%; width: 20px; height: 20px; transform: translateY(-50%); color: var(--muted); }
.search .input { padding-left: 40px; }
.toolbar-row { display: flex; gap: 8px; }
.toolbar-row .input { flex: 1; }

/* ---------- Liste de courses ---------- */
.shop-item { display: flex; align-items: center; gap: 4px; padding: 4px 6px 4px 4px; min-height: 58px; }
.shop-item label { display: flex; align-items: center; gap: 12px; flex: 1; min-width: 0; padding: 8px 10px; cursor: pointer; }
.shop-item input[type="checkbox"] { width: 26px; height: 26px; accent-color: var(--primary); flex: none; }
.shop-item.is-checked .row-title { text-decoration: line-through; color: var(--muted); font-weight: 400; }
.cat-head { padding: 14px 14px 4px; font-size: .85rem; font-weight: 700; color: var(--muted); }
.add-bar { display: flex; gap: 8px; margin-bottom: 14px; }
.add-bar .input:first-child { flex: 1; }
.add-bar .qty { width: 74px; }

/* ---------- Feuille modale ---------- */
dialog.sheet {
  border: 0; padding: 0; width: 100%; max-width: 560px; max-height: 92dvh; margin: auto auto 0;
  border-radius: var(--radius-l) var(--radius-l) 0 0; background: var(--surface); color: var(--ink);
}
dialog.sheet::backdrop { background: rgba(10, 20, 16, .5); }
@media (min-width: 640px) { dialog.sheet { margin: auto; border-radius: var(--radius-l); } }
.sheet-head { position: sticky; top: 0; z-index: 1; display: flex; align-items: center; gap: 8px; padding: 14px 10px 10px 20px; background: var(--surface); border-bottom: 1px solid var(--line); }
.sheet-head h2 { flex: 1; }
.sheet-body { padding: 18px 20px calc(20px + env(safe-area-inset-bottom)); }
dialog.sheet[open] { animation: rise .2s ease-out; }
@keyframes rise { from { transform: translateY(24px); opacity: .6; } to { transform: none; opacity: 1; } }

/* ---------- Ajout par photo ---------- */
.capture { display: grid; gap: 10px; grid-template-columns: 1fr 1fr; }
.capture .big {
  grid-column: 1 / -1; display: grid; place-items: center; gap: 8px; min-height: 150px; padding: 18px;
  border-radius: var(--radius-l); border: 2px dashed var(--primary); background: var(--primary-soft); color: var(--primary);
  font-weight: 700; font-size: 1.1rem; cursor: pointer; text-align: center;
}
.capture .big svg { width: 44px; height: 44px; }
.capture label.btn { cursor: pointer; }
.notice {
  display: flex; gap: 10px; padding: 12px 14px; border-radius: var(--radius-m);
  background: var(--soon-bg); color: var(--ink); font-size: .93rem;
}
.notice svg { width: 20px; height: 20px; flex: none; color: var(--soon); margin-top: 1px; }
.notice.info { background: var(--surface-2); }
.notice.info svg { color: var(--primary); }
.notice ul { margin: 4px 0 0; padding-left: 18px; }
.preview { width: 100%; max-height: 260px; object-fit: contain; border-radius: var(--radius-m); background: var(--surface-2); }
.analyzing { display: grid; place-items: center; gap: 12px; padding: 30px 10px; text-align: center; }
.spinner { width: 40px; height: 40px; border-radius: 50%; border: 4px solid var(--primary-soft); border-top-color: var(--primary); animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.candidates { display: grid; gap: 8px; }
.candidate {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px; min-height: 52px;
  border: 1.5px solid var(--line); border-radius: var(--radius-m); cursor: pointer;
}
.candidate:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); }
.candidate input { width: 20px; height: 20px; accent-color: var(--primary); flex: none; }
.candidate .stamp-date { font-family: var(--dot); font-size: 1.15rem; letter-spacing: .06em; }
.candidate .conf { margin-left: auto; font-size: .82rem; color: var(--muted); text-align: right; }
.meter { display: inline-block; width: 46px; height: 6px; border-radius: 3px; background: var(--line); vertical-align: middle; overflow: hidden; }
.meter > i { display: block; height: 100%; background: var(--muted); }
details.ocr { font-size: .88rem; }
details.ocr pre { white-space: pre-wrap; max-height: 200px; overflow: auto; background: var(--surface-2); padding: 10px; border-radius: var(--radius-s); }

/* ---------- Fiche produit ---------- */
.detail-stamp { display: flex; align-items: center; gap: 16px; padding: 18px; }
.detail-stamp .stamp { min-width: 0; padding: 10px 16px; }
.detail-stamp .stamp-date { font-size: 1.7rem; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 8px 16px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.photo { width: 100%; max-height: 320px; object-fit: contain; border-radius: var(--radius-m); background: var(--surface-2); }

/* ---------- Réglages ---------- */
.settings-group { margin-top: 22px; }
.settings-group > h2 { margin-bottom: 4px; }
.settings-group > p { color: var(--muted); font-size: .93rem; }
.status-line { font-size: .9rem; margin-top: 4px; }
.status-line.ok { color: var(--ok); }
.status-line.ko { color: var(--expired); }
.caps { display: flex; flex-wrap: wrap; gap: 6px; }
.cap { display: inline-flex; align-items: center; gap: 4px; padding: 4px 10px; border-radius: 14px; background: var(--surface-2); font-size: .85rem; }
.cap svg { width: 14px; height: 14px; }

/* ---------- Connexion ---------- */
.auth { min-height: 100dvh; display: grid; place-items: center; padding: 20px; }
.auth .panel { width: 100%; max-width: 400px; padding: 28px 24px; }
.auth .logo { display: block; width: 56px; height: 56px; margin-bottom: 12px; color: var(--primary); }
.auth .logo svg { width: 100%; height: 100%; }
.auth h1 { margin-bottom: 6px; }
.auth p { color: var(--muted); }
.or { display: flex; align-items: center; gap: 10px; margin: 16px 0; color: var(--muted); font-size: .88rem; }
.or::before, .or::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.btn-google { background: #fff; color: #1f1f1f; border-color: #c7c7c7; }
.btn-google:hover { border-color: #8e8e8e; }
.btn-google svg { width: 20px; height: 20px; }

/* ---------- Toast ---------- */
#toast {
  position: fixed; z-index: 50; left: 50%; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 90px);
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
  display: flex; align-items: center; gap: 12px; max-width: calc(100vw - 32px);
  padding: 12px 12px 12px 18px; border-radius: var(--radius-m); background: var(--ink); color: var(--surface); box-shadow: var(--shadow);
}
#toast.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
#toast.error { background: var(--expired); color: #fff; }
#toast button { background: none; border: 0; color: inherit; font-weight: 700; text-decoration: underline; cursor: pointer; min-height: 36px; }
@media (min-width: 900px) { #toast { bottom: 32px; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* Messages d'erreur de connexion et longues adresses (URI de redirection) */
.auth .err { color: var(--expired); }
code { overflow-wrap: anywhere; word-break: break-word; }
.settings-group details ol li { margin-bottom: 4px; }
.grid-2 > *, .grid-3 > * { min-width: 0; }
.btn-row > .btn { white-space: normal; text-align: center; min-width: 0; }
