:root {
    --bg: #f6f7f5;
    --surface: #ffffff;
    --text: #1d211e;
    --muted: #66706a;
    --border: #dfe3df;
    --primary: #2f7d4a;
    --primary-text: #ffffff;
    --primary-soft: #dcefe1;
    --primary-soft-text: #1b4d2c;
    --warn: #b26a00;
    --danger-bg: #fbe4e4;
    --danger-text: #8a1c1c;
    --success-bg: #e2f3e7;
    --success-text: #1b4d2c;
    --radius: 10px;
    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #161816;
        --surface: #212421;
        --text: #e8ebe8;
        --muted: #a1aaa4;
        --border: #363b37;
        --primary: #8fd19e;
        --primary-text: #10251a;
        --primary-soft: #2b3a30;
        --primary-soft-text: #b9e6c4;
        --warn: #f0b456;
        --danger-bg: #4a2020;
        --danger-text: #ffd0d0;
        --success-bg: #213a2a;
        --success-text: #c9f0d4;
        color-scheme: dark;
    }
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
    font-size: 16px;
    line-height: 1.45;
}

a { color: var(--primary); text-decoration: none; }
h1 { font-size: 1.7rem; margin: 0.2rem 0 0.4rem; }
h2 { font-size: 1.15rem; margin: 1.4rem 0 0.5rem; }

/* ---------- Header / navigation ---------- */
.topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.6rem 1rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 0.5rem; font-weight: 700; color: var(--text); white-space: nowrap; }
.brand img { width: 26px; height: 26px; border-radius: 6px; }
h1:focus { outline: none; }
.tabs { display: flex; gap: 0.25rem; flex: 1; }
.tabs a {
    padding: 0.4rem 0.75rem;
    border-radius: 999px;
    color: var(--muted);
    white-space: nowrap;
}
.tabs a.active { background: var(--primary-soft); color: var(--primary-soft-text); font-weight: 600; }
.signout { margin-left: auto; }

.content { max-width: 860px; margin: 0 auto; padding: 1rem 1rem 6rem; }

/* Phones: tabs become a bottom bar */
@media (max-width: 700px) {
    .tabs {
        position: fixed;
        left: 0; right: 0; bottom: 0;
        justify-content: space-around;
        padding: 0.4rem 0.25rem calc(0.4rem + env(safe-area-inset-bottom));
        background: var(--surface);
        border-top: 1px solid var(--border);
    }
    .tabs a { padding: 0.45rem 0.5rem; font-size: 0.85rem; }
    h1 { font-size: 1.45rem; }
}

/* ---------- Building blocks ---------- */
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 0.5rem; }
.actions { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.empty { color: var(--muted); text-align: center; padding: 2rem 1rem; }
.back { display: inline-block; margin-bottom: 0.5rem; }
.top-gap { margin-top: 1rem; }
.grow { flex: 1; min-width: 0; }

.cards { display: flex; flex-direction: column; gap: 0.5rem; }
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.75rem 1rem;
}
.card.card-link { display: block; color: var(--text); }
.card.card-link:hover { border-color: var(--primary); }
.card.row { display: flex; align-items: center; gap: 0.6rem; }
.card.edit { background: var(--primary-soft); border-color: transparent; display: flex; flex-direction: column; gap: 0.5rem; }
.card.done { opacity: 0.6; }
.card-title { font-weight: 600; color: var(--text); }
section.card { display: flex; flex-direction: column; gap: 0.6rem; margin: 0.8rem 0; }
.count { min-width: 2.5rem; text-align: center; }

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.3rem;
    padding: 0.55rem 1rem;
    border: none;
    border-radius: 8px;
    background: var(--primary);
    color: var(--primary-text);
    font: inherit;
    font-weight: 600;
    cursor: pointer;
}
.btn.secondary { background: var(--primary-soft); color: var(--primary-soft-text); }
.btn.small { padding: 0.35rem 0.7rem; font-size: 0.875rem; }
.btn.wide { width: 100%; padding: 0.8rem; }
.btn:disabled { opacity: 0.55; cursor: default; }
.icon {
    width: 2.2rem; height: 2.2rem;
    border: none; border-radius: 8px;
    background: var(--primary-soft); color: var(--primary-soft-text);
    font: inherit; font-weight: 700; cursor: pointer;
}
.link { background: none; border: none; color: var(--primary); font: inherit; cursor: pointer; padding: 0.3rem; }

input, select, textarea {
    font: inherit;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.55rem 0.7rem;
    width: 100%;
    min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; }
input[type=checkbox] { width: 1.25rem; height: 1.25rem; accent-color: var(--primary); flex: none; }
input.narrow { width: 6rem; }
input.medium { width: 10rem; }
.search { margin: 0.5rem 0 0.8rem; }
select.wide { margin-bottom: 0.4rem; }

.form { display: flex; flex-direction: column; gap: 0.6rem; }
.form label { display: flex; flex-direction: column; gap: 0.25rem; font-weight: 600; }
.form label input, .form label textarea { font-weight: 400; }
label.inline { display: flex; flex-direction: row; align-items: center; gap: 0.6rem; font-weight: 600; }
.row-form { display: flex; gap: 0.5rem; margin: 0.5rem 0; }
.row-form .btn { flex: none; }
.stack { display: flex; flex-direction: column; gap: 0.6rem; }

.ing-grid { display: grid; grid-template-columns: 4.5rem 6rem 1fr 2.2rem; gap: 0.4rem; align-items: center; }
.ing-grid.head { margin-bottom: -0.3rem; }

.check { display: flex; align-items: center; gap: 0.6rem; cursor: pointer; flex-wrap: wrap; }
.strike { text-decoration: line-through; }

.ingredients { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 0.35rem; }
.ingredients li { display: flex; justify-content: space-between; gap: 1rem; padding: 0.35rem 0; border-bottom: 1px dashed var(--border); }
.status { font-size: 0.85rem; white-space: nowrap; }
.status.good { color: var(--primary); }
.status.warn { color: var(--warn); }
.status.none { color: var(--muted); }
.instructions { white-space: pre-wrap; }

.banner { padding: 0.7rem 1rem; border-radius: var(--radius); margin: 0.6rem 0; }
.banner.error { background: var(--danger-bg); color: var(--danger-text); }
.banner.success { background: var(--success-bg); color: var(--success-text); }

.login { max-width: 380px; margin: 12vh auto 0; text-align: center; }
.login .btn { width: 100%; }

/* ---------- Blazor framework bits ---------- */
#blazor-error-ui {
    background: #fff4d6;
    color: #3a2c00;
    bottom: 0;
    box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
    display: none;
    left: 0;
    padding: 0.6rem 1.25rem 0.7rem 1.25rem;
    position: fixed;
    width: 100%;
    z-index: 1000;
}
#blazor-error-ui .dismiss { cursor: pointer; position: absolute; right: 0.75rem; top: 0.5rem; }

.loading-progress { position: relative; display: block; width: 6rem; height: 6rem; margin: 25vh auto 1rem auto; }
.loading-progress circle { fill: none; stroke: var(--border); stroke-width: 0.5rem; transform-origin: 50% 50%; transform: rotate(-90deg); }
.loading-progress circle:last-child {
    stroke: var(--primary);
    stroke-dasharray: calc(3.141 * var(--blazor-load-percentage, 0%) * 0.8), 500%;
    transition: stroke-dasharray 0.05s ease-in-out;
}
.loading-progress-text { position: absolute; text-align: center; font-weight: 600; inset: calc(25vh + 2.4rem) 0 auto 0.2rem; color: var(--muted); }
.loading-progress-text:after { content: var(--blazor-load-percentage-text, "Loading"); }

.row-between { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }

.site-footer { margin-top: 3rem; padding-top: 1rem; border-top: 1px solid var(--border); text-align: center; font-size: 0.9rem; }

.item-text { display: flex; flex-direction: column; min-width: 0; }
.warn { color: var(--warn); }
.center { text-align: center; }
.divider { border-top: 1px solid var(--border); margin: 0.3rem 0; }
.btn.walmart { background: #0071dc; color: #fff; margin: 0.3rem 0; text-align: center; }
a.btn { text-decoration: none; }

/* ---------- Categories, prices, budget planner ---------- */
.field { display: flex; flex-direction: column; gap: 0.3rem; }
.field-label { font-weight: 600; }
.chips { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.chips.filter { margin: -0.2rem 0 0.8rem; }
.chip {
    display: inline-flex; align-items: center; gap: 0.3rem;
    padding: 0.35rem 0.8rem; border-radius: 999px;
    border: 1px solid var(--border); background: var(--surface); color: var(--text);
    font: inherit; font-size: 0.9rem; cursor: pointer; font-weight: 400;
}
.chip.on { background: var(--primary-soft); color: var(--primary-soft-text); border-color: transparent; font-weight: 600; }
.chip input { display: none; }
.row-form.wrap { flex-wrap: wrap; align-items: center; }
select.auto { width: auto; }
.suggestion { border-top: 1px solid var(--border); padding-top: 0.6rem; display: flex; flex-direction: column; gap: 0.4rem; }
ul.plain { margin: 0.2rem 0; padding-left: 1.1rem; }
ul.plain li { margin: 0.15rem 0; }
.estimate { margin: 0.6rem 0; }
.product-editor { display: flex; flex-direction: column; gap: 0.5rem; }

/* ---------- Receipt import ---------- */
.receipt-row { display: flex; flex-direction: column; gap: 0.4rem; }
.receipt-row.off { opacity: 0.55; }
.receipt-text { font-family: ui-monospace, Consolas, monospace; font-size: 0.9rem; }
