/*
 * Styles de l'application. Mobile d'abord (NF-01), zones tactiles de 48 px
 * minimum (NF-02), contrastes AA en clair comme en sombre (NF-07).
 * Toutes les couleurs passent par les variables ci-dessous.
 */
:root {
  --bg: #fbf7f2;
  --surface: #ffffff;
  --surface-2: #f3ece3;
  --text: #1c1917;
  --muted: #5c534b;
  --border: #ddd3c7;
  --primary: #a3461f;
  --primary-text: #ffffff;
  --success: #1f6b3a;
  --danger: #a3261f;
  --focus: #1d4ed8;
  --timer-bg: #1c1917;
  --timer-text: #fbf7f2;
  --timer-done: #c2410c;
  --radius: 12px;
  --tap: 48px;
  --gutter: 16px;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.06), 0 4px 12px rgb(0 0 0 / 0.05);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171412;
    --surface: #221e1b;
    --surface-2: #2c2723;
    --text: #f5efe8;
    --muted: #b8ada2;
    --border: #3d3631;
    --primary: #e0875c;
    --primary-text: #1c1917;
    --success: #6bc48b;
    --danger: #f08a80;
    --focus: #93b4ff;
    --timer-bg: #2c2723;
    --timer-text: #f5efe8;
    --timer-done: #ea7a45;
    --shadow: none;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

body.has-timers { padding-bottom: calc(var(--banner-h, 0px) + 16px); }

a { color: var(--primary); }

h1 { font-size: 1.6rem; line-height: 1.2; margin: 0 0 12px; }
h2 { font-size: 1.2rem; margin: 24px 0 8px; }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

.skip-link { position: absolute; left: -999px; top: 8px; }
.skip-link:focus { left: 8px; z-index: 100; background: var(--surface); padding: 8px 12px; }

.muted { color: var(--muted); }
.center { text-align: center; }

/* ---- En-tête ---- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 8px var(--gutter); background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.brand { font-weight: 700; font-size: 1.15rem; color: var(--text); text-decoration: none; min-height: var(--tap); display: flex; align-items: center; gap: 6px; }
#nav { display: flex; gap: 4px; }
#nav a { min-height: var(--tap); display: flex; align-items: center; padding: 0 12px; border-radius: var(--radius); color: var(--text); text-decoration: none; }
#nav a:hover { background: var(--surface-2); }

main { max-width: 960px; margin: 0 auto; padding: 16px var(--gutter) 32px; }
main:focus, main:focus-visible { outline: none; }

/* ---- Boutons ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: var(--tap); min-width: var(--tap); padding: 0 16px;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 600;
  text-decoration: none; cursor: pointer;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.btn-primary:hover { background: var(--primary); filter: brightness(1.08); }
.btn-danger { color: var(--danger); }
.btn-check { background: var(--success); border-color: var(--success); color: var(--primary-text); }
.btn-check:hover { background: var(--success); filter: brightness(1.08); }
.btn-small { padding: 0 10px; font-size: 0.95rem; }
.btn-large { font-size: 1.1rem; padding: 0 20px; min-height: 56px; }
.btn-block { width: 100%; }

.actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 16px 0; }
.row-actions { display: flex; gap: 4px; flex-wrap: wrap; }

/* ---- Formulaires ---- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.auth-card { max-width: 420px; margin: 24px auto; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; min-width: 0; }
.field label, fieldset legend { font-weight: 600; font-size: 0.95rem; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; min-height: var(--tap); width: 100%;
}
textarea { resize: vertical; }
input[type="checkbox"] { width: 24px; height: 24px; min-height: 0; accent-color: var(--primary); flex: none; }
.check { display: inline-flex; align-items: center; gap: 10px; min-height: var(--tap); cursor: pointer; }
.form-error { color: var(--danger); font-weight: 600; min-height: 1.5em; margin: 8px 0; }
.form-error:empty { min-height: 0; margin: 0; }

.grid-2, .grid-3 { display: grid; gap: 0 12px; grid-template-columns: 1fr; }
@media (min-width: 600px) {
  .grid-2 { grid-template-columns: 1fr 1fr; }
  .grid-3 { grid-template-columns: repeat(3, 1fr); }
}

.edit-list { list-style: none; padding: 0; margin: 0 0 12px; display: grid; gap: 12px; }
.edit-row { display: flex; flex-wrap: wrap; gap: 0 8px; align-items: flex-end; padding: 12px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.edit-row .row-actions { margin-bottom: 12px; }
.field-qty { flex: 0 0 90px; }
.field-unit { flex: 0 0 110px; }
.field-grow { flex: 1 1 160px; }
.field-full { flex: 1 1 100%; }
.duration { display: flex; flex-wrap: wrap; gap: 0 8px; flex: 1 1 100%; border: 0; padding: 0; margin: 0; }
.duration legend { margin-bottom: 4px; }
.sticky-actions { position: sticky; bottom: 0; background: var(--bg); padding: 8px 0; margin-bottom: 0; }

.danger-zone { margin-top: 24px; padding: 20px; border: 1px solid var(--danger); border-radius: var(--radius); }
.danger-zone h2 { margin-top: 0; color: var(--danger); }

/* ---- Liste ---- */
.page-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.page-head h1 { margin: 0; }
.filters { display: flex; flex-wrap: wrap; gap: 0 12px; align-items: flex-end; }
.filters .field { flex: 1 1 180px; }
.filters .field-grow { flex: 3 1 220px; }
.filters .check { margin-bottom: 12px; }
.active-tag { display: flex; align-items: center; gap: 8px; }
.recipe-grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); margin-top: 8px; }
.recipe-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); display: flex; flex-direction: column; }
.recipe-card img, .recipe-card-placeholder { width: 100%; aspect-ratio: 16 / 9; object-fit: cover; }
.recipe-card-placeholder { display: flex; align-items: center; justify-content: center; font-size: 2.5rem; background: var(--surface-2); }
.recipe-card-body { padding: 12px 16px 16px; }
.recipe-card h2 { margin: 0 0 4px; font-size: 1.15rem; }
.recipe-card h2 a { color: var(--text); text-decoration: none; }
.recipe-card h2 a:hover { text-decoration: underline; }
.recipe-card p { margin: 0 0 6px; }
.fav { color: var(--primary); }
.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; min-height: 32px; padding: 0 10px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text); font: inherit; font-size: 0.9rem; cursor: pointer; }
button.chip { min-height: 40px; }
.chip-active { background: var(--primary); color: var(--primary-text); border-color: var(--primary); }
.empty { text-align: center; padding: 40px 16px; grid-column: 1 / -1; }

/* ---- Fiche recette ---- */
.recipe-photo { width: 100%; max-height: 360px; object-fit: cover; border-radius: var(--radius); margin-bottom: 16px; }
.description { white-space: pre-line; }
.section-head { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 8px; }
.stepper { display: inline-flex; align-items: center; gap: 8px; }
.stepper output { min-width: 5ch; text-align: center; font-weight: 600; }
.ingredients { padding-left: 20px; }
.ingredients li { margin: 6px 0; }
.steps li { margin: 0 0 12px; padding-left: 4px; }
.steps li p { margin: 0; white-space: pre-line; }

/* ---- Mode cuisine (F-10 à F-12, NF-02) ---- */
.cook-mode main { max-width: 760px; }
.cook-mode .topbar { position: static; }
.cook-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin-bottom: 8px; }
.cook-head h1 { flex: 1 1 200px; margin: 0; font-size: 1.3rem; }
.progress { margin: 0; color: var(--muted); font-weight: 600; }

.cook-ingredients {
  position: sticky; top: 0; z-index: 5;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 4px 12px; max-height: 32vh; overflow-y: auto; box-shadow: var(--shadow);
}
.cook-ingredient-list { list-style: none; margin: 0; padding: 0; columns: 2 220px; column-gap: 16px; }
.cook-ingredient-list li { break-inside: avoid; font-size: 1.05rem; }
.cook-ingredient-list .is-checked span { text-decoration: line-through; color: var(--muted); }

.cook-steps { margin-top: 12px; }
.cook-current { background: var(--surface); border: 2px solid var(--primary); border-radius: var(--radius); padding: 16px; }
.cook-current .actions { margin-bottom: 0; }
.step-number { margin: 0; font-weight: 700; color: var(--primary); }
.step-text { font-size: 1.35rem; line-height: 1.45; margin: 6px 0 0; white-space: pre-line; }
.timer-status { margin: 0; display: flex; align-items: center; font-weight: 600; }

.cook-upcoming { list-style: none; padding: 0; margin: 16px 0; display: grid; gap: 8px; }
.cook-upcoming li { display: flex; gap: 8px; align-items: center; padding: 8px 12px; border: 1px solid var(--border); border-radius: var(--radius); font-size: 1.125rem; }
.cook-upcoming li > span:nth-child(2) { flex: 1; white-space: pre-line; }
.cook-upcoming .step-number { color: var(--muted); }

.cook-done { margin-top: 16px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-2); }
.cook-done summary { min-height: var(--tap); display: flex; align-items: center; padding: 0 12px; cursor: pointer; font-weight: 600; }
.cook-done ul { list-style: none; margin: 0; padding: 0 12px 8px; }
.cook-done .done-text { text-decoration: line-through; color: var(--muted); font-size: 1.125rem; }
.cook-finished { text-align: center; padding: 24px; }
.big { font-size: 1.5rem; font-weight: 700; }

/* ---- Bandeau des minuteurs (F-24) ---- */
.timer-banner {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  background: var(--timer-bg); color: var(--timer-text);
  max-height: 45vh; overflow-y: auto;
  padding: 0 var(--gutter) env(safe-area-inset-bottom);
}
.timer-banner:empty { display: none; }
.timer-list { list-style: none; margin: 0 auto; padding: 6px 0; max-width: 960px; }
.timer { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; padding: 6px 0; border-bottom: 1px solid rgb(255 255 255 / 0.12); }
.timer:last-child { border-bottom: 0; }
.timer-label { flex: 1 1 140px; color: inherit; text-decoration: none; display: flex; flex-direction: column; min-width: 0; }
.timer-label strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.timer-label small { opacity: 0.8; }
.timer-time { font-size: 1.6rem; font-weight: 700; font-variant-numeric: tabular-nums; min-width: 4.5ch; text-align: right; }
.timer-actions { display: flex; gap: 4px; flex-wrap: wrap; }
.timer .btn { background: transparent; color: inherit; border-color: rgb(255 255 255 / 0.3); }
.timer-paused .timer-time { opacity: 0.6; }
.timer-done { background: var(--timer-done); margin: 0 calc(-1 * var(--gutter)); padding: 8px var(--gutter); animation: pulse 1s ease-in-out infinite alternate; }
.timer-done .timer-time { font-size: 1.2rem; }
@keyframes pulse { from { filter: brightness(1); } to { filter: brightness(1.2); } }
@media (prefers-reduced-motion: reduce) { .timer-done { animation: none; } }

/* ---- Messages ---- */
.toasts { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(16px + var(--banner-h, 0px)); z-index: 30; display: grid; gap: 8px; width: min(480px, calc(100% - 32px)); }
.toast { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 8px 8px 16px; border-radius: var(--radius); background: var(--text); color: var(--bg); box-shadow: 0 6px 20px rgb(0 0 0 / 0.25); }
.toast .btn { background: transparent; color: inherit; border-color: currentColor; }
