:root {
    --bg: #f6f5f2;
    --surface: #ffffff;
    --border: #e3e0d9;
    --text: #23201c;
    --muted: #7b746a;
    --accent: #c2410c;
    --accent-soft: #fff1e8;
    --ok: #1f7a4d;
    --ok-soft: #e7f5ee;
    --warn: #92620a;
    --warn-soft: #fdf3dd;
    --err: #a5231b;
    --err-soft: #fdeceb;
    --radius: 14px;
    --shadow: 0 1px 2px rgba(35, 32, 28, .06), 0 8px 24px rgba(35, 32, 28, .06);
}

* { box-sizing: border-box; }

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

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

/* ---------------------------------------------------------------- topbar */
.topbar {
    position: sticky;
    top: 0;
    z-index: 30;
    display: flex;
    align-items: center;
    gap: 24px;
    padding: 12px 24px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

.topbar .brand { font-weight: 700; text-decoration: none; color: var(--text); white-space: nowrap; }
.topbar nav { display: flex; gap: 18px; flex: 1; }
.topbar nav a { text-decoration: none; color: var(--muted); font-weight: 500; }
.topbar nav a:hover { color: var(--accent); }
.topbar .userbox { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 14px; }

.container { max-width: 1400px; margin: 0 auto; padding: 28px 24px 60px; }

.footer { text-align: center; color: var(--muted); font-size: 13px; padding: 24px; }

/* ---------------------------------------------------------------- titres */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; flex-wrap: wrap; margin-bottom: 22px; }
h1 { font-size: 26px; margin: 0 0 4px; }
h2 { font-size: 18px; margin: 28px 0 12px; }
.subtitle { color: var(--muted); margin: 0; }

/* ---------------------------------------------------------------- cartes */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
}

.grid-cards { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }

/* ---------------------------------------------------------------- boutons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 9px 16px;
    border-radius: 10px;
    border: 1px solid transparent;
    background: var(--accent);
    color: #fff;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: filter .15s;
}
.btn:hover { filter: brightness(1.08); }
.btn-sm { padding: 5px 11px; font-size: 13px; }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--text); }
.btn-ghost:hover { background: var(--bg); filter: none; }
.btn-danger { background: var(--err); }
.btn-ok { background: var(--ok); }
button.btn, a.btn { line-height: 1.2; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---------------------------------------------------------------- flash */
.flash { padding: 12px 16px; border-radius: 10px; margin-bottom: 12px; border: 1px solid; }
.flash-success { background: var(--ok-soft); border-color: #bfe3d0; color: var(--ok); }
.flash-warning { background: var(--warn-soft); border-color: #f0dcae; color: var(--warn); }
.flash-error   { background: var(--err-soft); border-color: #f3c9c6; color: var(--err); }

/* ---------------------------------------------------------------- formulaires */
label { display: block; font-weight: 600; margin-bottom: 4px; font-size: 14px; }
input[type=text], input[type=email], input[type=password], input[type=number], select, textarea {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: #fff;
    font: inherit;
    color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.help { color: var(--muted); font-size: 13px; margin-top: 4px; }
.field { margin-bottom: 18px; }
.form-row { display: grid; gap: 18px; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }

/* lignes de regles d'ingredients */
.rules-list { display: flex; flex-direction: column; gap: 10px; margin-bottom: 12px; }
.rule-row { display: grid; grid-template-columns: 1fr 140px 90px 40px; gap: 10px; align-items: center; }
.rule-row .count-input { text-align: center; }
.rule-row .remove-rule {
    background: transparent; border: 1px solid var(--border); border-radius: 8px;
    cursor: pointer; padding: 8px; color: var(--err); font-weight: 700;
}

/* autocompletion des ingredients */
.food-cell { position: relative; }
.food-suggestions {
    position: absolute;
    top: calc(100% + 3px);
    left: 0;
    right: 0;
    z-index: 50;
    max-height: 260px;
    overflow-y: auto;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: 0 12px 28px rgba(0, 0, 0, .13);
    padding: 4px;
}
.food-suggestion { padding: 7px 10px; border-radius: 7px; cursor: pointer; font-size: 14px; }
.food-suggestion:hover,
.food-suggestion.actif { background: var(--accent-soft, #fdece0); }
.hidden { display: none !important; }

/* ---------------------------------------------------------------- grille semaine */
.week-grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }

.day-col { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; display: flex; flex-direction: column; }
.day-head { display: flex; align-items: center; justify-content: space-between; padding: 10px 14px; background: var(--accent-soft); border-bottom: 1px solid var(--border); }
.day-head h3 { margin: 0; font-size: 15px; color: var(--accent); }
.day-head label { margin: 0; font-weight: 500; font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.day-head input[type=checkbox] { width: auto; }
.day-body { padding: 12px; display: flex; flex-direction: column; gap: 12px; flex: 1; }
.day-empty { color: var(--muted); font-size: 13px; font-style: italic; padding: 18px 0; text-align: center; }

.recipe-card { border: 1px solid var(--border); border-radius: 12px; overflow: hidden; background: #fff; cursor: pointer; transition: transform .12s, box-shadow .12s; }
.recipe-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.recipe-card img { width: 100%; height: 140px; object-fit: cover; display: block; background: var(--bg); }
.recipe-card .noimg { width: 100%; height: 140px; display: flex; align-items: center; justify-content: center; background: var(--bg); color: var(--muted); font-size: 32px; }
.recipe-card .body { padding: 10px 12px; }
.recipe-card .name { font-weight: 600; font-size: 14px; line-height: 1.3; }
.recipe-card .meta { color: var(--muted); font-size: 12px; margin-top: 4px; }

/* ---------------------------------------------------------------- tableau */
table { width: 100%; border-collapse: collapse; background: var(--surface); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
th, td { padding: 11px 14px; text-align: left; border-bottom: 1px solid var(--border); }
th { background: #faf9f6; font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
tr:last-child td { border-bottom: none; }
.badge { display: inline-block; padding: 2px 9px; border-radius: 20px; font-size: 12px; font-weight: 600; }
.badge-draft { background: var(--warn-soft); color: var(--warn); }
.badge-saved { background: var(--ok-soft); color: var(--ok); }
.badge-admin { background: var(--accent-soft); color: var(--accent); }
.badge-reader { background: #eef0f3; color: #4b5563; }
.actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* ---------------------------------------------------------------- modal */
.modal-backdrop {
    position: fixed; inset: 0; background: rgba(35, 32, 28, .55);
    display: flex; align-items: center; justify-content: center; padding: 24px; z-index: 100;
}
.modal-backdrop.hidden { display: none; }
.modal {
    background: var(--surface); border-radius: var(--radius); max-width: 820px; width: 100%;
    max-height: 88vh; overflow: auto; box-shadow: 0 24px 60px rgba(0,0,0,.3);
}
.modal img.hero { width: 100%; height: 260px; object-fit: cover; display: block; }
.modal .modal-body { padding: 22px 26px 30px; }
.modal h2 { margin-top: 0; }
.modal .close-x { position: absolute; top: 14px; right: 18px; background: rgba(255,255,255,.92); border: none; border-radius: 50%; width: 34px; height: 34px; font-size: 18px; cursor: pointer; }
.modal-wrap { position: relative; }
.modal ul { padding-left: 20px; }
.modal ol { padding-left: 22px; }
.modal li { margin-bottom: 6px; }
.tag { display: inline-block; background: var(--accent-soft); color: var(--accent); padding: 3px 10px; border-radius: 20px; font-size: 12px; font-weight: 600; margin-right: 6px; }

/* liste d'ingredients du mail / apercu */
.ing-list { columns: 2; column-gap: 32px; list-style: none; padding-left: 0; margin: 0; }
.ing-list li {
    break-inside: avoid;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 3px 0;
}
.ing-list li span { flex: 1; }
.btn-ignorer {
    flex: none;
    opacity: .55;
    font: inherit;
    font-size: 12px;
    padding: 2px 10px;
    border-radius: 20px;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    white-space: nowrap;
    transition: opacity .15s, background .15s, color .15s;
}
.ing-list li:hover .btn-ignorer,
.btn-ignorer:focus { opacity: 1; }
.btn-ignorer:hover { background: var(--err-soft); color: var(--err); border-color: #f3c9c6; }
.btn-ignorer:disabled { opacity: .6; cursor: wait; }

/* cases de selection dans la liste de courses */
.ing-list li input.choix-ingredient {
    flex: none;
    width: auto;
    margin: 0 8px 0 0;
    cursor: pointer;
}

/* barre flottante des alternatives */
.barre-flottante {
    position: fixed;
    left: 50%;
    bottom: 24px;
    transform: translateX(-50%);
    z-index: 90;
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 12px 18px;
    background: var(--text);
    color: #fff;
    border-radius: 999px;
    box-shadow: 0 12px 34px rgba(0, 0, 0, .28);
}
.barre-flottante span { font-size: 14px; color: #e8e5df; }
.barre-flottante .btn { background: var(--accent); }
.barre-flottante .btn-ghost { background: transparent; border-color: rgba(255,255,255,.35); color: #fff; }
.barre-flottante .btn-ghost:hover { background: rgba(255,255,255,.12); }
.barre-flottante .btn:disabled { opacity: .45; cursor: not-allowed; }
@media (max-width: 640px) {
    .barre-flottante { flex-wrap: wrap; justify-content: center; border-radius: 18px; width: calc(100% - 24px); }
}

@media (max-width: 700px) { .ing-list { columns: 1; } .rule-row { grid-template-columns: 1fr 1fr; } .btn-ignorer { opacity: 1; } }

.loading { text-align: center; padding: 40px; color: var(--muted); }
