/* One stylesheet for the whole app. iPhone-first: ~358pt usable width, 44pt targets, 16px inputs. */

:root {
    --bg: #f6f5f2;
    --surface: #ffffff;
    --surface-2: #efede8;
    --text: #1d1c1a;
    --muted: #6b6862;
    --border: #dedad2;
    --accent: #2f6b4f;
    --accent-text: #ffffff;
    --accent-soft: #e2efe7;
    --danger: #b3261e;
    --warn-bg: #fff3cd;
    --warn-text: #5c4400;
    --shadow: 0 1px 2px rgb(0 0 0 / 6%), 0 2px 8px rgb(0 0 0 / 4%);
    --radius: 12px;
    --tap: 44px;
    --tab-height: 56px;
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-left: env(safe-area-inset-left, 0px);
    --safe-right: env(safe-area-inset-right, 0px);
    color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #151515;
        --surface: #1f1f1f;
        --surface-2: #2a2a2a;
        --text: #ecebe8;
        --muted: #a29f98;
        --border: #34322f;
        --accent: #6fbf95;
        --accent-text: #0d1f16;
        --accent-soft: #1e3328;
        --danger: #ff8a80;
        --warn-bg: #3d3210;
        --warn-text: #f5dc8c;
        --shadow: none;
    }
}

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

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

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
    -webkit-tap-highlight-color: transparent;
    overflow-x: hidden;
}

a { color: var(--accent); }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 1.6rem; }
h3 { font-size: 1rem; margin: 1rem 0 .5rem; }
p { margin: .25rem 0; }

.muted { color: var(--muted); }
.center { text-align: center; }
.small-text { font-size: .85rem; }
.nowrap { white-space: nowrap; }

/* ---- Shell, header, tab bar ---- */

.shell { min-height: 100dvh; }

.page {
    padding: calc(var(--safe-top) + 8px) calc(var(--safe-right) + 16px) calc(var(--tab-height) + var(--safe-bottom) + 24px) calc(var(--safe-left) + 16px);
    max-width: 640px;
    margin: 0 auto;
}

.boot { padding: 40vh 0 0; text-align: center; color: #888; font: 16px -apple-system, sans-serif; }

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-height: var(--tap);
    margin: 4px 0 12px;
}
.page-header h1 { flex: 1; }
.page-header .back + h1 { text-align: right; font-size: 1.2rem; }

.back {
    display: inline-flex;
    align-items: center;
    min-height: var(--tap);
    text-decoration: none;
    font-size: 1.05rem;
}

.tab-bar {
    position: fixed;
    inset: auto 0 0 0;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    padding: 0 var(--safe-right) var(--safe-bottom) var(--safe-left);
    background: color-mix(in srgb, var(--surface) 92%, transparent);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-top: 1px solid var(--border);
    z-index: 20;
}
.tab {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    height: var(--tab-height);
    color: var(--muted);
    text-decoration: none;
    font-size: .75rem;
}
.tab-icon { font-size: 1.3rem; line-height: 1; filter: grayscale(1); opacity: .75; }
.tab.active { color: var(--accent); font-weight: 600; }
.tab.active .tab-icon { filter: none; opacity: 1; }

.status-bar {
    position: sticky;
    top: 0;
    z-index: 30;
    padding: calc(var(--safe-top) + 6px) 16px 6px;
    text-align: center;
    font-size: .85rem;
    font-weight: 600;
}
.status-bar.offline { background: var(--warn-bg); color: var(--warn-text); }
.status-bar.syncing { background: var(--accent-soft); color: var(--accent); }
a.status-bar { display: block; text-decoration: underline; }

#update-banner {
    position: fixed;
    left: 12px;
    right: 12px;
    bottom: calc(var(--tab-height) + var(--safe-bottom) + 12px);
    z-index: 50;
    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 4px 16px rgb(0 0 0 / 25%);
}
#update-banner button {
    min-height: var(--tap);
    padding: 0 16px;
    border: 0;
    border-radius: 10px;
    background: var(--accent);
    color: var(--accent-text);
    font: inherit;
    font-weight: 600;
}

/* ---- Buttons and inputs ---- */

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: var(--tap);
    padding: 0 16px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
}
.button.small { min-height: 36px; padding: 0 12px; font-size: .9rem; }
/* Keep small buttons at a 44pt hit area. */
.button.small { position: relative; }
.button.small::after { content: ""; position: absolute; inset: -4px 0; }
.button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.button.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, var(--border)); }
.button.ghost { background: transparent; }
.button:disabled, .card:disabled { opacity: .5; cursor: default; }

.icon-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: var(--tap);
    min-height: var(--tap);
    border: 0;
    background: transparent;
    color: var(--muted);
    font: inherit;
    font-size: 1.1rem;
    cursor: pointer;
}
.icon-button:disabled { opacity: .3; }

input[type=text], input[type=url], input[type=search], select, textarea {
    width: 100%;
    min-height: var(--tap);
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-size: 16px; /* 16px or more stops iOS Safari zooming on focus */
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.search { margin-bottom: 12px; }

.form { display: grid; gap: 12px; }
.field { display: grid; gap: 4px; min-width: 0; }
.field > span:first-child { font-size: .85rem; font-weight: 600; color: var(--muted); }
.field-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.sheet-body .field + .field, .sheet-body .field-pair, .sheet-body .field-pair + .field { margin-top: 10px; }
.sheet-body .field-pair .field { margin-top: 0; }
.toggle-row, .radio-row {
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: var(--tap);
    cursor: pointer;
}
.toggle-row input, .radio-row input { width: 22px; height: 22px; margin: 0; accent-color: var(--accent); flex: none; }
.row-buttons { display: flex; flex-wrap: wrap; gap: 8px; }
.file-button input { display: none; }

/* ---- Cards ---- */

.cards { list-style: none; margin: 0 0 12px; padding: 0; display: grid; gap: 8px; }
.card {
    display: block;
    width: 100%;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    box-shadow: var(--shadow);
    font: inherit;
    text-align: left;
    text-decoration: none;
}
.cards.compact { gap: 6px; }
.title { font-weight: 600; display: block; overflow-wrap: anywhere; }
.badge {
    display: inline-block;
    padding: 1px 8px;
    border-radius: 999px;
    background: var(--accent-soft);
    color: var(--accent);
    font-size: .75rem;
    font-weight: 600;
    white-space: nowrap;
    vertical-align: middle;
}
.muted-badge { background: var(--surface-2); color: var(--muted); }

.line-card { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; min-height: var(--tap); cursor: pointer; overflow-wrap: anywhere; }
.line-card > :first-child { flex: 1 1 auto; min-width: 0; }
.line-card .small-text { flex-basis: 100%; }

.line-edit-row { display: flex; align-items: center; gap: 4px; }
.line-edit-row .card { flex: 1; min-width: 0; }
.move { display: flex; flex: none; }

.nav-card { display: grid; gap: 2px; }

.thumb.large { width: 88px; height: 88px; border-radius: 10px; }
.thumb.large.placeholder { font-size: 2rem; }
.thumb-link { flex: none; display: block; }
.recipe-link { display: grid; gap: 2px; color: var(--text); text-decoration: none; }
.plan-toggle { align-self: flex-end; min-width: 104px; }
.plan-toggle.planned { background: var(--accent-soft); border-color: var(--accent-soft); color: var(--accent); }
.recipe-card { display: flex; align-items: flex-start; gap: 12px; }
.staple-row { display: flex; align-items: center; gap: 8px; min-height: 52px; border-bottom: 1px solid var(--border); }
.staple-name { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.recipe-card-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 8px; }
.thumb { width: 52px; height: 52px; border-radius: 8px; object-fit: cover; flex: none; background: var(--surface-2); }
.thumb.placeholder { display: inline-flex; align-items: center; justify-content: center; font-size: 1.4rem; }

.hero { width: 100%; max-height: 40dvh; object-fit: cover; border-radius: var(--radius); margin-bottom: 12px; }
.hero.small { max-height: 160px; }
.recipe-title { margin-bottom: 4px; overflow-wrap: anywhere; }
.notes { white-space: pre-wrap; margin: 12px 0; }
.section-title { font-size: 1.1rem; margin: 20px 0 8px; }
.steps { padding-left: 1.5rem; margin: 0; }
.steps li { margin-bottom: 10px; padding-left: 4px; }
.plain-list { padding-left: 1.2rem; margin: 0 0 12px; }

.plan-box { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 12px 0; }

.plan-card { display: grid; gap: 10px; }
.plan-name { display: flex; align-items: center; gap: 12px; color: var(--text); text-decoration: none; min-height: var(--tap); }
.plan-name > span { min-width: 0; }
.plan-controls { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.stepper { display: inline-flex; align-items: center; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.stepper button {
    width: var(--tap);
    height: var(--tap);
    border: 0;
    background: var(--surface-2);
    color: var(--text);
    font-size: 1.3rem;
    cursor: pointer;
}
.stepper button:disabled { opacity: .4; }
.stepper-value { min-width: 84px; text-align: center; font-weight: 600; }

.pick-list { list-style: none; padding: 0; margin: 0; }
.pick {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    width: 100%;
    min-height: 52px;
    padding: 8px 4px;
    border: 0;
    border-bottom: 1px solid var(--border);
    background: transparent;
    color: var(--text);
    font: inherit;
    text-align: left;
    cursor: pointer;
}
.pick > span:first-child { overflow-wrap: anywhere; }

.empty { text-align: center; padding: 48px 0; display: grid; gap: 16px; justify-items: center; }
.actions { margin: 24px 0; display: grid; gap: 6px; justify-items: start; }

.step-edit { padding-left: 1.5rem; margin: 0 0 12px; display: grid; gap: 8px; }
.step-edit li { display: flex; gap: 4px; align-items: flex-start; }
.step-edit textarea { flex: 1; }
.step-edit .move { flex-direction: column; }

.sub-edit { margin-bottom: 10px; box-shadow: none; background: var(--surface-2); }
.sub-edit-header { display: flex; align-items: center; justify-content: space-between; }

.fields { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; margin: 0 0 12px; }
.fields dt { color: var(--muted); }
.fields dd { margin: 0; overflow-wrap: anywhere; }

/* ---- Banners ---- */

.error-banner, .install-hint {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 12px;
    padding: 8px 4px 8px 14px;
    border-radius: var(--radius);
}
.error-banner { background: color-mix(in srgb, var(--danger) 14%, var(--surface)); color: var(--danger); align-items: center; }
.install-hint { background: var(--accent-soft); }
.install-hint p { font-size: .9rem; }

/* ---- Grocery list ---- */

.area { margin-bottom: 8px; }
.area-header {
    position: sticky;
    top: 0;
    z-index: 5;
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0 -16px;
    padding: 10px 16px 6px;
    background: color-mix(in srgb, var(--bg) 94%, transparent);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    font-size: .85rem;
    font-weight: 700;
    letter-spacing: .04em;
    text-transform: uppercase;
    color: var(--muted);
}
.area-header .count {
    min-width: 22px;
    padding: 0 6px;
    border-radius: 999px;
    background: var(--surface-2);
    text-align: center;
    font-size: .75rem;
    letter-spacing: 0;
}
details.have > summary { cursor: pointer; list-style: none; min-height: var(--tap); }
details.have > summary::-webkit-details-marker { display: none; }
details.have > summary::after { content: "▸"; margin-left: auto; }
details.have[open] > summary::after { content: "▾"; }

.rows {
    list-style: none;
    margin: 0;
    padding: 0;
    border-radius: var(--radius);
    background: var(--surface);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    overflow: hidden;
}
.row { display: flex; align-items: flex-start; border-bottom: 1px solid var(--border); }
.row:last-child { border-bottom: 0; }
.row.pending { opacity: .55; }
.row.static .row-main { padding-left: 14px; cursor: default; }

.check {
    display: flex;
    align-items: center;
    justify-content: center;
    flex: none;
    width: 48px;
    min-height: 52px;
    cursor: pointer;
}
.check input { width: 24px; height: 24px; margin: 0; accent-color: var(--accent); cursor: pointer; }

.row-main { flex: 1; min-width: 0; padding: 10px 14px 10px 0; cursor: pointer; }
.row-top { display: flex; align-items: baseline; gap: 10px; }
.name { flex: 1; min-width: 0; font-weight: 600; overflow-wrap: anywhere; }
.amount-inline { flex: none; white-space: nowrap; text-align: right; font-variant-numeric: tabular-nums; }
.amounts { font-variant-numeric: tabular-nums; }
.recipes { font-size: .8rem; margin-top: 2px; overflow-wrap: anywhere; }
.checked .name { text-decoration: line-through; color: var(--muted); font-weight: 500; }
.checked .amounts, .checked .amount-inline { color: var(--muted); }

.asterisk {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 32px;
    min-height: 32px;
    margin: -6px -4px -6px 0;
    padding: 0;
    border: 0;
    background: transparent;
    color: var(--accent);
    font: inherit;
    font-size: 1.2rem;
    font-weight: 800;
    vertical-align: middle;
    cursor: pointer;
    position: relative;
}
.asterisk::after { content: ""; position: absolute; inset: -6px; }

.details { list-style: none; margin: 8px 0 0; padding: 8px 0 0; border-top: 1px dashed var(--border); font-size: .9rem; cursor: default; }
.details > li + li { margin-top: 6px; }
.details ul { list-style: none; margin: 2px 0 0; padding: 0 0 0 10px; }
.details ul li { padding: 2px 0; overflow-wrap: anywhere; }
.detail-total { font-weight: 600; }

.sub-menu { display: grid; gap: 8px; }
.sub-option {
    margin: 0;
    padding: 8px 14px 6px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    min-width: 0;
}
.sub-option legend { padding: 0 4px; font-weight: 600; font-size: .9rem; }
.sub-option .radio-row span { overflow-wrap: anywhere; }

/* ---- Bottom sheet ---- */

.sheet-backdrop { position: fixed; inset: 0; background: rgb(0 0 0 / 40%); z-index: 40; animation: fade .15s ease-out; }
.sheet {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 41;
    display: flex;
    flex-direction: column;
    max-height: 88dvh;
    max-width: 640px;
    margin: 0 auto;
    border-radius: 16px 16px 0 0;
    background: var(--bg);
    box-shadow: 0 -4px 24px rgb(0 0 0 / 20%);
    animation: slide-up .2s ease-out;
}
.sheet-header { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 4px 4px 16px; border-bottom: 1px solid var(--border); }
.sheet-header h2 { font-size: 1.1rem; overflow-wrap: anywhere; }
.sheet-body { overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 12px 16px 16px; overscroll-behavior: contain; }
.sheet-footer {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    padding: 10px 16px calc(10px + var(--safe-bottom));
    border-top: 1px solid var(--border);
}
.sheet-footer .button { flex: 1; }

@keyframes slide-up { from { transform: translateY(100%); } to { transform: none; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

/* ---- Blazor error UI ---- */

#blazor-error-ui {
    display: none;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1000;
    padding: 12px 16px calc(12px + var(--safe-bottom));
    background: var(--warn-bg);
    color: var(--warn-text);
}
#blazor-error-ui .dismiss { float: right; cursor: pointer; }
