/* Quality Recettes — feuille de style unique.
   Conçue pour être lisible sur un plan de travail : contrastes marqués,
   cibles tactiles généreuses, aucune dépendance externe. */

:root {
    color-scheme: light dark;

    --bg: #f6f5f2;
    --surface: #ffffff;
    --surface-2: #eceae5;
    --border: #d9d5cc;
    --text: #23201b;
    --muted: #6b655a;

    --accent: #8a5a2b;
    --accent-dark: #6d4520;
    --accent-soft: #f2e6d8;

    --ok-fg: #1c5c34;
    --ok-bg: #dcf0e2;
    --warn-fg: #7a5300;
    --warn-bg: #fbeecd;
    --error-fg: #8f2020;
    --error-bg: #fadddd;
    --info-fg: #1e4c73;
    --info-bg: #dbeaf7;

    --radius: 10px;
    --shadow: 0 1px 2px rgb(0 0 0 / .06), 0 4px 12px rgb(0 0 0 / .04);
    --tap: 44px;                       /* cible tactile minimale */
    --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #17150f;
        --surface: #211e17;
        --surface-2: #2b2720;
        --border: #3d3830;
        --text: #efece4;
        --muted: #a49d90;
        --accent: #d19a5f;
        --accent-dark: #e0ae76;
        --accent-soft: #33291d;
        --ok-fg: #8fdca9;   --ok-bg: #1a3324;
        --warn-fg: #e8c477; --warn-bg: #3a2f18;
        --error-fg: #f0a3a3; --error-bg: #3b1d1d;
        --info-fg: #9dc9ec; --info-bg: #182b3b;
        --shadow: 0 1px 2px rgb(0 0 0 / .4);
    }
}

*, *::before, *::after { box-sizing: border-box; }

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

body {
    margin: 0;
    font-family: var(--font);
    font-size: 16px;
    line-height: 1.55;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { line-height: 1.25; margin: 0 0 .5em; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 1rem; }
a { color: var(--accent-dark); text-underline-offset: .15em; }
code { font-family: ui-monospace, "SFMono-Regular", Menlo, monospace; font-size: .9em;
       background: var(--surface-2); padding: .1em .35em; border-radius: 4px; }
hr { border: 0; border-top: 1px solid var(--border); margin: 1.5rem 0; }

.muted { color: var(--muted); }
.text-ok { color: var(--ok-fg); }
.text-error { color: var(--error-fg); }
.text-right { text-align: right; }
.nowrap { white-space: nowrap; }
.visually-hidden {
    position: absolute; width: 1px; height: 1px; overflow: hidden;
    clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap;
}

/* --- Ossature ----------------------------------------------------------- */

.app { min-height: 100vh; display: flex; flex-direction: column; }

.topbar {
    position: sticky; top: 0; z-index: 20;
    display: flex; align-items: center; gap: 1rem;
    padding: .6rem 1rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

.topbar__brand {
    font-weight: 700; font-size: 1.05rem; color: var(--text);
    text-decoration: none; white-space: nowrap;
}
.topbar__brand span { color: var(--accent); }

.topbar__spacer { margin-left: auto; }

.nav { display: flex; gap: .25rem; align-items: center; }

.nav a {
    display: inline-flex; align-items: center; min-height: var(--tap);
    padding: .4rem .75rem; border-radius: var(--radius);
    color: var(--text); text-decoration: none; font-weight: 500; white-space: nowrap;
}
.nav a:hover { background: var(--surface-2); }
.nav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent-dark); font-weight: 650; }

/* Navigation repliée en barre inférieure sur téléphone. */
.nav--main { display: none; }
@media (min-width: 860px) {
    .nav--main { display: flex; }
    .tabbar { display: none !important; }
}

.tabbar {
    position: sticky; bottom: 0; z-index: 20;
    display: flex; justify-content: space-around;
    background: var(--surface); border-top: 1px solid var(--border);
    padding: .25rem max(.25rem, env(safe-area-inset-left)) max(.25rem, env(safe-area-inset-bottom));
}
.tabbar a {
    flex: 1; display: flex; flex-direction: column; align-items: center; gap: .1rem;
    min-height: var(--tap); padding: .35rem .25rem;
    font-size: .7rem; text-decoration: none; color: var(--muted); border-radius: var(--radius);
}
.tabbar a[aria-current="page"] { color: var(--accent-dark); background: var(--accent-soft); }
.tabbar svg { width: 22px; height: 22px; }

.main { flex: 1; width: min(72rem, 100%); margin: 0 auto; padding: 1.25rem 1rem 2.5rem; }
.main--wide { width: min(90rem, 100%); }

.page-head {
    display: flex; flex-wrap: wrap; gap: .75rem 1rem;
    align-items: baseline; justify-content: space-between; margin-bottom: 1.25rem;
}
.page-head h1 { margin: 0; }
.page-head .actions { display: flex; gap: .5rem; flex-wrap: wrap; }

/* --- Cartes et grilles --------------------------------------------------- */

.card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); box-shadow: var(--shadow);
    padding: 1.15rem; margin-bottom: 1.25rem;
}
.card > :last-child { margin-bottom: 0; }
.card__head { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; margin-bottom: .75rem; }

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

.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; }
.stat__value { font-size: 1.9rem; font-weight: 700; line-height: 1.1; }
.stat__label { color: var(--muted); font-size: .875rem; }

/* --- Formulaires --------------------------------------------------------- */

.field { margin-bottom: 1rem; }
.field > label { display: block; font-weight: 600; margin-bottom: .3rem; font-size: .9rem; }
.field small { display: block; margin-top: .25rem; font-size: .8rem; }

input[type=text], input[type=email], input[type=password], input[type=number],
input[type=search], input[type=time], input[type=date], select, textarea {
    width: 100%; min-height: var(--tap);
    padding: .55rem .7rem;
    font: inherit; color: var(--text);
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius);
}
textarea { min-height: 6rem; resize: vertical; line-height: 1.5; }

input:focus-visible, select:focus-visible, textarea:focus-visible,
button:focus-visible, a:focus-visible, summary:focus-visible {
    outline: 2px solid var(--accent); outline-offset: 2px;
}

input[type=checkbox], input[type=radio] { width: 1.15rem; height: 1.15rem; accent-color: var(--accent); }

.check { display: flex; align-items: center; gap: .5rem; min-height: var(--tap); }
.check label { font-weight: 500; }

fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; margin: 0 0 1rem; }
legend { font-weight: 650; padding: 0 .4rem; }

/* --- Boutons ------------------------------------------------------------- */

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
    min-height: var(--tap); padding: .5rem 1rem;
    font: inherit; font-weight: 600; text-decoration: none; white-space: nowrap;
    color: var(--text); background: var(--surface);
    border: 1px solid var(--border); border-radius: var(--radius);
    cursor: pointer;
}
.btn:hover { background: var(--surface-2); }
.btn--primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn--primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); }
.btn--danger { color: var(--error-fg); border-color: var(--error-fg); background: transparent; }
.btn--danger:hover { background: var(--error-bg); }
.btn--small { min-height: 34px; padding: .25rem .6rem; font-size: .85rem; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

.btn-row { display: flex; flex-wrap: wrap; gap: .5rem; }

/* --- Alertes et étiquettes ---------------------------------------------- */

.alert {
    padding: .75rem 1rem; border-radius: var(--radius);
    margin-bottom: 1rem; border: 1px solid transparent;
}
.alert--success { background: var(--ok-bg); color: var(--ok-fg); border-color: currentColor; }
.alert--error   { background: var(--error-bg); color: var(--error-fg); border-color: currentColor; }
.alert--warning { background: var(--warn-bg); color: var(--warn-fg); border-color: currentColor; }
.alert--info    { background: var(--info-bg); color: var(--info-fg); border-color: currentColor; }

.tag {
    display: inline-block; padding: .1rem .5rem; border-radius: 999px;
    font-size: .75rem; font-weight: 650; background: var(--surface-2); color: var(--muted);
}
.tag--allergen { background: var(--warn-bg); color: var(--warn-fg); }
.tag--trace { background: var(--surface-2); color: var(--muted); font-weight: 500; }
.tag--draft { background: var(--surface-2); color: var(--muted); }
.tag--published { background: var(--ok-bg); color: var(--ok-fg); }
.tag--archived { background: var(--error-bg); color: var(--error-fg); }
.tag--preparation { background: var(--info-bg); color: var(--info-fg); }

/* --- Tableaux ------------------------------------------------------------ */

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

table { width: 100%; border-collapse: collapse; }
th, td { padding: .6rem .5rem; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 650; }
tbody tr:hover { background: var(--surface-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* Sur téléphone, chaque ligne devient une fiche empilée. */
@media (max-width: 640px) {
    table.stacked thead { display: none; }
    table.stacked tr {
        display: block; margin-bottom: .75rem; padding: .75rem;
        background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    }
    table.stacked td { display: flex; justify-content: space-between; gap: 1rem; border: 0; padding: .3rem 0; }
    table.stacked td::before {
        content: attr(data-label); font-weight: 650; color: var(--muted);
        font-size: .8rem; text-transform: uppercase;
    }
    table.stacked td.num { text-align: right; }
}

/* --- Liste d'ingrédients ------------------------------------------------- */

.ingredients { list-style: none; margin: 0; padding: 0; }
.ingredients li {
    display: flex; gap: .75rem; align-items: baseline;
    padding: .5rem 0; border-bottom: 1px dashed var(--border);
}
.ingredients li:last-child { border-bottom: 0; }
.ingredients .qty {
    flex: 0 0 7.5rem; font-weight: 700; font-variant-numeric: tabular-nums;
    text-align: right; font-size: 1.05rem;
}
.ingredients .name { flex: 1; }
.ingredients .note { color: var(--muted); font-size: .9rem; }
.ingredients--nested { margin-left: 1rem; padding-left: 1rem; border-left: 3px solid var(--accent-soft); }
.ingredients li.is-optional .name::after {
    content: " (facultatif)"; color: var(--muted); font-size: .85rem; font-weight: 400;
}

.section-title {
    margin: 1.25rem 0 .35rem; font-size: .8rem; font-weight: 700;
    text-transform: uppercase; letter-spacing: .06em; color: var(--accent-dark);
}
.section-title:first-child { margin-top: 0; }

/* --- Étapes -------------------------------------------------------------- */

.steps-list { counter-reset: step; list-style: none; margin: 0; padding: 0; }
.steps-list li { position: relative; padding: 0 0 1rem 2.75rem; counter-increment: step; }
.steps-list li::before {
    content: counter(step);
    position: absolute; left: 0; top: 0;
    width: 1.9rem; height: 1.9rem; border-radius: 50%;
    display: grid; place-items: center;
    background: var(--accent); color: #fff; font-weight: 700; font-size: .9rem;
}
.steps-list h4 { margin-bottom: .2rem; }
.steps-list p { margin-bottom: 0; white-space: pre-line; }

/* --- Barre de mise à l'échelle ------------------------------------------ */

.scaler {
    position: sticky; top: 3.6rem; z-index: 10;
    background: var(--accent-soft); border: 1px solid var(--border);
    border-radius: var(--radius); padding: .85rem; margin-bottom: 1.25rem;
}
.scaler__row { display: flex; flex-wrap: wrap; gap: .6rem; align-items: flex-end; }
.scaler__row .field { margin: 0; flex: 1 1 8rem; }
.scaler__presets { display: flex; gap: .35rem; flex-wrap: wrap; margin-top: .6rem; }
.scaler__presets .btn { flex: 1 1 auto; }
.scaler__result { margin-top: .6rem; font-weight: 650; }

/* --- Recherche ----------------------------------------------------------- */

.filters { display: flex; flex-wrap: wrap; gap: .6rem; align-items: flex-end; margin-bottom: 1.25rem; }
.filters .field { margin: 0; flex: 1 1 12rem; }

.recipe-card {
    display: block; padding: 1rem; text-decoration: none; color: inherit;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); box-shadow: var(--shadow); height: 100%;
}
.recipe-card:hover { border-color: var(--accent); }
.recipe-card h3 { margin-bottom: .25rem; }
.recipe-card__meta { display: flex; flex-wrap: wrap; gap: .35rem; margin-top: .5rem; }

.empty { text-align: center; padding: 3rem 1rem; color: var(--muted); }

/* --- Pagination ---------------------------------------------------------- */

.pagination { display: flex; gap: .35rem; flex-wrap: wrap; justify-content: center; margin-top: 1.5rem; }
.pagination a, .pagination span {
    min-width: var(--tap); min-height: var(--tap);
    display: inline-flex; align-items: center; justify-content: center;
    padding: 0 .6rem; border: 1px solid var(--border); border-radius: var(--radius);
    text-decoration: none; color: var(--text); background: var(--surface);
}
.pagination [aria-current="page"] { background: var(--accent); color: #fff; border-color: var(--accent); }

/* --- Impression ---------------------------------------------------------- */

@page {
    size: A4 portrait;
    margin: 2cm;
}

@media print {
    :root { --bg: #fff; --surface: #fff; --surface-2: #fff; --border: #999; --text: #000; --muted: #444; }
    .topbar, .tabbar, .scaler, .page-head .actions, .no-print { display: none !important; }
    body { background: #fff; font-size: 11pt; }

    /* Filet de sécurité horizontal.
       Si l'utilisateur a laissé « Marges : aucune » dans la boîte d'impression,
       le navigateur ignore le @page ci-dessus et la zone imprimable fait 21 cm.
       Brider le contenu à 17 cm recrée alors les 2 cm de blanc à gauche et à
       droite ; quand les marges du @page s'appliquent, la zone fait déjà 17 cm
       et cette règle ne change rien. */
    .main { width: 100%; max-width: 17cm; margin-left: auto; margin-right: auto; padding: 0; }
    .card { border: 0; box-shadow: none; padding: 0; margin-bottom: 1rem; page-break-inside: avoid; }
    .steps-list li, .ingredients li { page-break-inside: avoid; }
    h1, h2, h3 { page-break-after: avoid; }
    a { color: #000; text-decoration: none; }
    .print-only { display: block !important; }
}
.print-only { display: none; }
