/* Matlista – mobile first. Colours live in the variables below. */
:root {
    --green: #2f6b4f;
    --green-dark: #24543e;
    --green-light: #e6f0ea;
    --bg: #f7f5f1;
    --card: #ffffff;
    --text: #1f2421;
    --muted: #6b716d;
    --border: #ddd8cf;
    --danger: #b3412e;
    --radius: 12px;
    --tabbar-h: 62px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    font-size: 16px;
    line-height: 1.45;
    background: var(--bg);
    color: var(--text);
}
body.has-tabbar { padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); }

a { color: var(--green); }
h1 { font-size: 1.6rem; margin: .4rem 0 1rem; line-height: 1.2; }
h2 { font-size: 1.2rem; margin: 0 0 .6rem; }
h3 { font-size: 1.05rem; margin: 1.4rem 0 .6rem; }

/* ---- Top bar and bottom tabs ---- */
.topbar {
    position: sticky; top: 0; z-index: 10;
    display: flex; align-items: center; justify-content: space-between;
    padding: .7rem 1rem; padding-top: calc(.7rem + env(safe-area-inset-top));
    background: var(--green); color: #fff;
}
.topbar .brand { color: #fff; text-decoration: none; font-weight: 700; font-size: 1.15rem; }
.topbar .who { font-size: .9rem; opacity: .85; }

.container { max-width: 760px; margin: 0 auto; padding: 1rem; }
body.wide .container { max-width: 1200px; }

.tabbar {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
    display: flex; height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    background: var(--card); border-top: 1px solid var(--border);
}
.tabbar a {
    flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
    font-size: .75rem; color: var(--muted); text-decoration: none;
}
.tabbar a .ico { font-size: 1.35rem; line-height: 1.2; }
.tabbar a.active { color: var(--green); font-weight: 600; }

/* ---- Buttons ---- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: .35rem;
    min-height: 44px; padding: .55rem 1rem;
    border: 1px solid var(--border); border-radius: 10px;
    background: var(--card); color: var(--text);
    font: inherit; font-weight: 500; text-decoration: none; cursor: pointer;
}
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--green); border-color: var(--green); color: #fff; }
.btn.primary:hover { background: var(--green-dark); }
.btn.danger { color: var(--danger); border-color: #e7c4bd; }
.btn.small { min-height: 34px; padding: .3rem .7rem; font-size: .9rem; }
.btn.on { background: #fff6d6; border-color: #e6cf7a; }
.icon-btn {
    width: 36px; height: 36px; border: none; border-radius: 8px;
    background: transparent; color: var(--muted); font-size: 1.05rem; cursor: pointer;
}
.icon-btn:hover { background: var(--green-light); color: var(--text); }

/* ---- Forms ---- */
.form { display: flex; flex-direction: column; gap: .9rem; }
.form label, .recipe-form label { display: flex; flex-direction: column; gap: .3rem; font-weight: 500; }
.form label.check { flex-direction: row; align-items: center; gap: .5rem; font-weight: 400; }
input, select, textarea {
    font: inherit; color: inherit;
    width: 100%; min-height: 44px; padding: .55rem .7rem;
    border: 1px solid var(--border); border-radius: 10px; background: #fff;
}
input[type=checkbox] { width: 20px; height: 20px; min-height: 0; accent-color: var(--green); }
input[type=file] { padding: .4rem; }
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--green); outline-offset: -1px; border-color: var(--green); }
small, .hint { color: var(--muted); font-size: .88rem; font-weight: 400; }
fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: .8rem; margin: 0; background: var(--card); }
legend { font-weight: 700; padding: 0 .4rem; }
.row2, .row3 { display: grid; gap: .7rem; grid-template-columns: 1fr 1fr; }
.row3 { grid-template-columns: repeat(3, 1fr); }
.row3 label { font-size: .88rem; }
.form-actions { display: flex; gap: .6rem; position: sticky; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); padding: .6rem 0; background: var(--bg); }
.form-actions .btn { flex: 1; }
.inline-form { display: inline-flex; gap: .4rem; align-items: center; flex-wrap: wrap; margin: 0; }
.inline-form input, .inline-form select { width: auto; min-width: 8rem; }
.narrow { max-width: 420px; margin: 1rem auto; }

.errors { background: #fbeae6; color: var(--danger); border-radius: var(--radius); padding: .7rem 1rem .7rem 2rem; }
.notice { background: var(--green-light); color: var(--green-dark); border-radius: var(--radius); padding: .7rem 1rem; }
.empty { color: var(--muted); text-align: center; padding: 2rem 1rem; }

/* ---- Recipe list ---- */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.page-head h1 { margin: 0; }
.search { margin: 1rem 0; }
.recipe-grid { display: grid; gap: .8rem; grid-template-columns: 1fr; }
@media (min-width: 560px) { .recipe-grid { grid-template-columns: 1fr 1fr; } }
.recipe-card {
    display: flex; gap: .8rem; align-items: center;
    background: var(--card); border-radius: var(--radius); overflow: hidden;
    color: inherit; text-decoration: none; box-shadow: 0 1px 2px rgba(0,0,0,.06);
}
.recipe-card img, .recipe-card .noimg { width: 92px; height: 92px; object-fit: cover; flex-shrink: 0; }
.recipe-card .noimg { display: flex; align-items: center; justify-content: center; background: var(--green-light); font-size: 2rem; }
.recipe-card .info { display: flex; flex-direction: column; gap: .25rem; padding-right: .6rem; min-width: 0; }
.recipe-card .info strong { overflow: hidden; text-overflow: ellipsis; }
.recipe-card .meta { display: flex; gap: .7rem; color: var(--muted); font-size: .85rem; }

/* ---- Recipe page ---- */
.recipe .hero { width: calc(100% + 2rem); margin: -1rem -1rem 1rem; max-height: 46vh; object-fit: cover; display: block; }
.recipe .desc, .steps p { white-space: pre-line; }
.recipe section { background: var(--card); border-radius: var(--radius); padding: 1rem; margin: 1rem 0; }
.facts { display: flex; gap: .6rem; flex-wrap: wrap; }
.facts div { flex: 1; min-width: 6rem; background: var(--card); border-radius: var(--radius); padding: .6rem .8rem; display: flex; flex-direction: column; }
.facts span { color: var(--muted); font-size: .8rem; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: .5rem; flex-wrap: wrap; margin-bottom: .4rem; }
.section-head h2 { margin: 0; }
.stepper { display: inline-flex; align-items: center; gap: .5rem; background: var(--green-light); border-radius: 999px; padding: .2rem; }
.stepper button { width: 38px; height: 38px; border-radius: 50%; border: none; background: #fff; font-size: 1.3rem; cursor: pointer; color: var(--green); }
.ingredients { list-style: none; padding: 0; margin: 0; }
.ingredients li { display: flex; gap: .8rem; padding: .55rem 0; border-bottom: 1px solid #efebe4; }
.ingredients li:last-child { border-bottom: none; }
.ingredients .amount { min-width: 5.5rem; font-weight: 600; text-align: right; white-space: nowrap; }
.ingredients .note { color: var(--muted); }
.steps { padding-left: 1.4rem; margin: 0; }
.steps li { padding: .4rem 0 .8rem; }
.steps li::marker { font-weight: 700; color: var(--green); }
.steps p { margin: 0 0 .3rem; }
.badge { display: inline-block; background: var(--green-light); color: var(--green-dark); border-radius: 999px; padding: .1rem .6rem; font-size: .85rem; }
.byline, .source { color: var(--muted); font-size: .9rem; }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; margin: 1rem 0 2rem; }
.actions form { margin: 0; }

/* ---- Recipe editor ---- */
.recipe-form fieldset { display: flex; flex-direction: column; gap: .6rem; }
.preview { max-width: 100%; max-height: 240px; border-radius: var(--radius); object-fit: cover; }
.rows { display: flex; flex-direction: column; gap: .6rem; }
.ing-row {
    display: grid; gap: .4rem;
    grid-template-columns: 4.5rem 5.2rem 1fr;
    grid-template-areas: "qty unit name" "note note note" "noscale noscale tools";
    padding: .6rem; border: 1px solid var(--border); border-radius: 10px; background: #fcfbf9;
}
.ing-row .qty { grid-area: qty; }
.ing-row .unit { grid-area: unit; padding-left: .4rem; padding-right: .2rem; }
.ing-row .name { grid-area: name; }
.ing-row .note { grid-area: note; }
.ing-row .noscale { grid-area: noscale; flex-direction: row !important; align-items: center; gap: .4rem; font-weight: 400 !important; font-size: .85rem; color: var(--muted); }
.ing-row .row-tools { grid-area: tools; justify-self: end; }
@media (min-width: 700px) {
    .ing-row { grid-template-columns: 4.5rem 5.5rem 1fr 1fr auto auto; grid-template-areas: "qty unit name note noscale tools"; align-items: center; }
}
.step-row { display: grid; grid-template-columns: 1.8rem 1fr; gap: .4rem; padding: .6rem; border: 1px solid var(--border); border-radius: 10px; background: #fcfbf9; }
.step-row .num { font-weight: 700; color: var(--green); padding-top: .6rem; text-align: center; }
.step-row .step-tools { grid-column: 2; display: flex; justify-content: space-between; align-items: center; }
.step-row .minutes { flex-direction: row !important; align-items: center; gap: .3rem; font-weight: 400 !important; }
.step-row .minutes input { width: 5.5rem; }

/* ---- Cards, settings, admin ---- */
.card { background: var(--card); border-radius: var(--radius); padding: 1rem; margin-bottom: 1rem; }
.household { padding: .7rem 0; border-bottom: 1px solid #efebe4; display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.household:last-of-type { border-bottom: none; }
.household .hint { width: 100%; }
.tag { background: var(--green-light); color: var(--green-dark); border-radius: 999px; padding: .1rem .6rem; font-size: .8rem; }
.members { width: 100%; list-style: none; padding: 0; margin: 0; }
.members li { display: flex; align-items: center; justify-content: space-between; padding: .2rem 0; }
.logout { margin: 1.5rem 0 2rem; }
.admin-grid { display: grid; gap: 1rem; }
@media (min-width: 1000px) { .admin-grid { grid-template-columns: 2fr 1fr; align-items: start; } }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { text-align: left; padding: .5rem; border-bottom: 1px solid #efebe4; vertical-align: middle; }
th { color: var(--muted); font-weight: 600; white-space: nowrap; }
td .inline-form input { min-width: 9rem; min-height: 34px; padding: .3rem .5rem; }

/* ---- Shopping list (v3) ---- */
.add-to-list { margin-top: .8rem; width: 100%; }
.lead { color: var(--muted); margin-top: -.5rem; }
.add-item { display: flex; gap: .5rem; position: sticky; top: calc(56px + env(safe-area-inset-top)); z-index: 5; background: var(--bg); padding: .4rem 0; }
.add-item .btn { min-width: 52px; font-size: 1.4rem; }
.offline { background: #fff6d6; color: #7a5b00; border-radius: var(--radius); padding: .5rem .8rem; font-size: .9rem; }
.shop-items { list-style: none; padding: 0; margin: .6rem 0; background: var(--card); border-radius: var(--radius); overflow: hidden; }
.shop-items li {
    display: flex; align-items: center; gap: .8rem;
    padding: .7rem .6rem .7rem .9rem; min-height: 56px;
    border-bottom: 1px solid #efebe4; cursor: pointer;
    -webkit-tap-highlight-color: transparent; user-select: none;
}
.shop-items li:last-child { border-bottom: none; }
.shop-items .box { width: 24px; height: 24px; border: 2px solid var(--green); border-radius: 7px; flex-shrink: 0; position: relative; }
.shop-items li.checked .box { background: var(--green); }
.shop-items li.checked .box::after { content: "✓"; color: #fff; position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: .9rem; }
.shop-items .text { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.shop-items .line strong { margin-right: .25rem; }
.shop-items small { color: var(--muted); font-size: .8rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.shop-items li.checked .line { text-decoration: line-through; color: var(--muted); }
.shop-items.done { opacity: .75; }
.done-head { color: var(--muted); font-size: .95rem; margin: 1.2rem 0 .2rem; }
.list-actions { display: flex; gap: .5rem; flex-wrap: wrap; margin: 1rem 0 2rem; }
.list-actions .btn { flex: 1; }

.review-tools { display: flex; gap: .5rem; margin-bottom: .5rem; }
.review-list { list-style: none; padding: 0; margin: 0 0 1rem; background: var(--card); border-radius: var(--radius); overflow: hidden; }
.review-list li { border-bottom: 1px solid #efebe4; }
.review-list li:last-child { border-bottom: none; }
.review-list label { display: flex; align-items: center; gap: .8rem; padding: .75rem .9rem; cursor: pointer; }
.review-list input[type=checkbox] { width: 24px; height: 24px; flex-shrink: 0; }
.review-list .amount { min-width: 4.8rem; font-weight: 600; text-align: right; white-space: nowrap; }
.review-list .name { display: flex; flex-wrap: wrap; align-items: center; gap: .35rem; }
.review-list .note { color: var(--muted); }
.review-list .on-list { width: 100%; color: #8a6d00; }

.staples { list-style: none; padding: 0; margin: 0 0 .8rem; }
.staples li { display: flex; align-items: center; justify-content: space-between; padding: .2rem 0; border-bottom: 1px solid #efebe4; }
