:root {
    --paper: #f7f4ec;
    --surface: #fffdf8;
    --surface-strong: #ffffff;
    --ink: #20241f;
    --muted: #6e726b;
    --line: #deddd5;
    --green: #355c4a;
    --green-deep: #244437;
    --green-soft: #dce8df;
    --coral: #d96f51;
    --coral-soft: #f6ded5;
    --yellow: #f1c86b;
    --danger: #a53b32;
    --shadow: 0 14px 35px rgba(36, 47, 39, 0.08);
    --radius: 18px;
    --font: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { background: var(--paper); color: var(--ink); font-family: var(--font); }
body { margin: 0; min-height: 100vh; background: var(--paper); }
button, input, select, textarea { color: inherit; font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: wait; opacity: .58; }
input, select, textarea {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--surface-strong);
    padding: 12px 13px;
    outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(53, 92, 74, .11); }
textarea { resize: vertical; line-height: 1.5; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 6px; font-family: Georgia, serif; font-size: clamp(2rem, 7vw, 3.25rem); font-weight: 500; letter-spacing: -.035em; }
h2 { margin-bottom: 6px; font-family: Georgia, serif; font-size: 1.75rem; font-weight: 500; letter-spacing: -.02em; }
h3 { margin-bottom: 5px; font-size: 1rem; }
[hidden] { display: none !important; }

.eyebrow { margin-bottom: 7px; color: var(--green); font-size: .7rem; font-weight: 800; letter-spacing: .14em; }
.muted { color: var(--muted); }
.spacer { flex: 1; }
.button {
    min-height: 44px;
    border: 1px solid transparent;
    border-radius: 12px;
    padding: 10px 16px;
    font-weight: 750;
    transition: transform .12s ease, background .12s ease;
}
.button:active { transform: translateY(1px); }
.button-primary { background: var(--coral); color: #fff; box-shadow: 0 5px 14px rgba(217, 111, 81, .22); }
.button-primary:hover { background: #cb6044; }
.button-dark { background: var(--green-deep); color: #fff; }
.button-light { border-color: var(--line); background: var(--surface); color: var(--ink); }
.button-full { width: 100%; }
.button-danger-text { background: transparent; color: var(--danger); }
.text-button { border: 0; background: transparent; color: var(--green); font-weight: 750; padding: 5px 0; }
.icon-button, .close-button {
    display: inline-grid;
    width: 42px;
    height: 42px;
    place-items: center;
    border: 1px solid var(--line);
    border-radius: 50%;
    background: var(--surface);
}
.close-button { border: 0; font-size: 1.8rem; font-weight: 300; }

.offline-banner { position: fixed; z-index: 100; top: 0; left: 0; right: 0; background: var(--yellow); padding: 8px 16px; text-align: center; font-size: .82rem; font-weight: 700; }
.auth-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: radial-gradient(circle at 15% 10%, #e6eee8 0, transparent 37%), radial-gradient(circle at 85% 90%, #f6dfd6 0, transparent 35%), var(--paper); }
.auth-card { width: min(100%, 430px); border: 1px solid rgba(53, 92, 74, .13); border-radius: 28px; background: rgba(255, 253, 248, .94); padding: 34px 28px; box-shadow: var(--shadow); }
.auth-card h1 { font-size: 2.55rem; }
.brand-mark { display: inline-grid; flex: 0 0 auto; width: 40px; height: 40px; place-items: center; border-radius: 13px; background: var(--green); color: #fff; font-family: Georgia, serif; font-size: .82rem; }
.brand-mark-large { width: 58px; height: 58px; margin-bottom: 24px; border-radius: 18px; font-size: 1rem; }
.stack-form { display: grid; gap: 15px; margin-top: 24px; }
.stack-form label, .field-label, .form-grid label { display: grid; gap: 7px; color: #434942; font-size: .82rem; font-weight: 750; }
.form-error { margin: 14px 0 0; border-radius: 10px; background: #fbe6e2; color: var(--danger); padding: 10px 12px; font-size: .85rem; }

.app-shell { min-height: 100vh; }
.app-main { width: 100%; padding: 78px 16px 96px; }
.mobile-header { position: fixed; z-index: 20; top: 0; left: 0; right: 0; display: flex; height: 64px; align-items: center; justify-content: space-between; border-bottom: 1px solid rgba(222, 221, 213, .8); background: rgba(247, 244, 236, .92); padding: 9px 16px; backdrop-filter: blur(12px); }
.brand { display: flex; align-items: center; gap: 10px; color: inherit; text-decoration: none; }
.brand > span:last-child, .profile-button > span:last-child { display: grid; gap: 2px; }
.brand small, .profile-button small { color: var(--muted); font-size: .72rem; font-weight: 500; }
.avatar { display: inline-grid; flex: 0 0 auto; width: 38px; height: 38px; place-items: center; border-radius: 50%; background: var(--coral-soft); color: #9f4f39; font-size: .82rem; font-weight: 850; }
.avatar-button { border: 0; }
.avatar-large { width: 48px; height: 48px; }
.desktop-sidebar { display: none; }
.desktop-nav { display: grid; gap: 6px; }
.nav-link { border: 0; background: transparent; color: var(--muted); font-weight: 750; }
.desktop-nav .nav-link { display: flex; align-items: center; gap: 13px; border-radius: 12px; padding: 12px; text-align: left; }
.desktop-nav .nav-link span { width: 22px; text-align: center; font-size: 1.1rem; }
.desktop-nav .nav-link.is-active { background: var(--green-soft); color: var(--green-deep); }
.mobile-nav { position: fixed; z-index: 20; right: 0; bottom: 0; left: 0; display: grid; grid-template-columns: repeat(3, 1fr); border-top: 1px solid var(--line); background: rgba(255, 253, 248, .96); padding: 7px 10px calc(7px + env(safe-area-inset-bottom)); backdrop-filter: blur(12px); }
.mobile-nav .nav-link { display: grid; justify-items: center; gap: 3px; padding: 5px; }
.mobile-nav .nav-link span { font-size: 1.18rem; }
.mobile-nav .nav-link small { font-size: .68rem; }
.mobile-nav .nav-link.is-active { color: var(--green); }
.view-panel { display: none; width: min(100%, 1020px); margin: 0 auto; animation: fade-in .18s ease; }
.view-panel.is-active { display: block; }
@keyframes fade-in { from { opacity: .25; transform: translateY(3px); } }

.next-meal-card { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 30px; border: 1px solid #d4e1d8; border-radius: var(--radius); background: var(--green-soft); padding: 15px 16px; }
.next-meal-card div { display: grid; gap: 2px; }
.next-meal-card .eyebrow { margin: 0; font-size: .62rem; }
.next-meal-card strong { font-family: Georgia, serif; font-size: 1.05rem; font-weight: 600; }
.page-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 24px; }
.page-heading .muted { margin-bottom: 0; font-size: .9rem; }
.shop-heading { align-items: flex-end; }
.shop-heading .button { flex: 0 0 auto; }
.quick-add { display: grid; grid-template-columns: 36px minmax(0, 1fr) 64px auto; align-items: center; gap: 7px; margin-bottom: 14px; border: 1px solid var(--line); border-radius: 16px; background: var(--surface); padding: 7px; box-shadow: 0 5px 18px rgba(36, 47, 39, .04); }
.quick-add input { border: 0; background: transparent; padding: 9px 4px; box-shadow: none; }
.quick-add-plus { display: grid; place-items: center; color: var(--green); font-size: 1.65rem; font-weight: 300; }
.trip-strip { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; border-radius: 15px; background: var(--green-deep); color: #fff; padding: 12px 13px; }
.trip-strip > div { display: grid; grid-template-columns: auto 1fr; align-items: center; column-gap: 8px; }
.trip-strip small { grid-column: 2; color: #dce8df; }
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: #7fdda7; box-shadow: 0 0 0 4px rgba(127, 221, 167, .14); }
.list-toolbar { display: flex; justify-content: space-between; margin: 12px 0 15px; }
.chip-button { border: 1px solid var(--line); border-radius: 999px; background: transparent; padding: 9px 13px; font-size: .8rem; font-weight: 750; }
.chip-button-dark { border-color: var(--green); color: var(--green); }
.shopping-list { display: grid; gap: 8px; margin: 0; padding: 0; list-style: none; }
.shopping-item { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 12px; border: 1px solid var(--line); border-radius: 15px; background: var(--surface); padding: 11px 10px; }
.shopping-item-check { display: grid; width: 27px; height: 27px; place-items: center; border: 1.5px solid #a9afa7; border-radius: 50%; background: #fff; color: transparent; }
.shopping-item-main { min-width: 0; }
.shopping-item-main strong { display: block; overflow: hidden; font-size: .95rem; text-overflow: ellipsis; white-space: nowrap; }
.shopping-item-main small { display: block; margin-top: 3px; color: var(--muted); font-size: .72rem; }
.shopping-item-meta { display: flex; align-items: center; gap: 7px; }
.quantity-badge { border-radius: 8px; background: #ebe9e1; padding: 5px 7px; color: #535850; font-size: .72rem; font-weight: 750; }
.item-menu-button { border: 0; background: transparent; color: var(--muted); padding: 8px; font-size: 1.1rem; }
.shopping-list-bought .shopping-item { background: rgba(255, 253, 248, .55); }
.shopping-list-bought .shopping-item-check { border-color: var(--green); background: var(--green); color: #fff; }
.shopping-list-bought .shopping-item-main strong { color: var(--muted); text-decoration: line-through; }
.bought-section { margin-top: 25px; }
.list-section-label { margin: 0 0 9px; color: var(--muted); font-size: .65rem; font-weight: 850; letter-spacing: .13em; }
.empty-state { margin: 30px auto; max-width: 400px; padding: 34px 20px; text-align: center; }
.empty-state h2 { font-size: 1.45rem; }
.empty-state p { color: var(--muted); line-height: 1.5; }
.empty-illustration { display: grid; width: 58px; height: 58px; margin: 0 auto 15px; place-items: center; border-radius: 20px; background: var(--green-soft); color: var(--green); font-size: 1.6rem; }

.plan-controls { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.meal-calendar { display: grid; gap: 9px; }
.meal-day { display: grid; grid-template-columns: 58px minmax(0, 1fr); gap: 12px; min-height: 90px; border: 1px solid var(--line); border-radius: 16px; background: var(--surface); padding: 13px; }
.meal-date { display: grid; align-content: center; justify-items: center; border-right: 1px solid var(--line); padding-right: 10px; }
.meal-date small { color: var(--muted); font-size: .65rem; font-weight: 800; text-transform: uppercase; }
.meal-date strong { font-family: Georgia, serif; font-size: 1.6rem; font-weight: 500; }
.meal-day.is-today { border-color: #a9c1b0; box-shadow: inset 3px 0 var(--green); }
.meal-content { display: flex; min-width: 0; align-items: center; justify-content: space-between; gap: 10px; }
.meal-content > div { min-width: 0; }
.meal-content strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.meal-content small { display: block; margin-top: 4px; color: var(--muted); }
.meal-add { border: 1px dashed #b8bbb3; border-radius: 12px; background: transparent; color: var(--green); padding: 10px 13px; font-weight: 750; }

.search-bar { display: flex; align-items: center; gap: 8px; margin: -6px 0 20px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); padding: 4px 12px; }
.search-bar input { border: 0; background: transparent; box-shadow: none; }
.recipe-grid { display: grid; gap: 12px; }
.recipe-card { display: grid; grid-template-columns: 62px minmax(0, 1fr) auto; align-items: center; gap: 13px; border: 1px solid var(--line); border-radius: 17px; background: var(--surface); padding: 12px; text-align: left; }
.recipe-card:hover { border-color: #b9c8bd; }
.recipe-card-art { display: grid; width: 62px; height: 62px; place-items: center; overflow: hidden; border-radius: 14px; background: var(--coral-soft); color: #a4543c; font-family: Georgia, serif; font-size: 1.35rem; }
.recipe-card-art img { width: 100%; height: 100%; object-fit: cover; }
.recipe-card-main { min-width: 0; }
.recipe-card-main strong { display: block; overflow: hidden; font-size: .98rem; text-overflow: ellipsis; white-space: nowrap; }
.recipe-card-main small { display: block; margin-top: 5px; color: var(--muted); }
.recipe-card-arrow { color: var(--green); font-size: 1.25rem; }

.modal { width: min(calc(100% - 22px), 580px); max-height: min(90vh, 820px); border: 0; border-radius: 22px; background: var(--surface); padding: 0; box-shadow: 0 25px 70px rgba(18, 31, 23, .24); }
.modal-wide { width: min(calc(100% - 22px), 740px); }
.modal-regulars { width: min(calc(100% - 22px), 720px); }
.modal::backdrop { background: rgba(25, 33, 28, .55); backdrop-filter: blur(3px); }
.modal-shell { display: flex; max-height: min(90vh, 820px); flex-direction: column; margin: 0; }
.modal-header { display: flex; flex: 0 0 auto; align-items: flex-start; justify-content: space-between; gap: 15px; border-bottom: 1px solid var(--line); padding: 20px 20px 15px; }
.modal-header h2 { margin: 0; }
.modal-body { overflow-y: auto; padding: 19px 20px 22px; }
.modal-body > section + section { margin-top: 27px; }
.modal-footer { display: flex; flex: 0 0 auto; align-items: center; gap: 9px; border-top: 1px solid var(--line); background: #faf8f2; padding: 12px 20px calc(12px + env(safe-area-inset-bottom)); }
.section-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.section-heading p { margin-bottom: 0; font-size: .82rem; }
.check-list { display: grid; gap: 7px; }
.check-row { display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: center; gap: 11px; border: 1px solid var(--line); border-radius: 13px; padding: 10px 12px; }
.check-row input { width: 20px; height: 20px; accent-color: var(--green); }
.check-row strong, .check-row small { display: block; }
.check-row small { margin-top: 3px; color: var(--muted); font-size: .72rem; }
.inline-empty { border-radius: 12px; background: var(--green-soft); color: var(--green-deep); padding: 12px; text-align: center; }
.regular-form { display: grid; grid-template-columns: minmax(0, 1fr) 68px; gap: 7px; margin-bottom: 16px; }
.regular-form input, .regular-form select { min-width: 0; font-size: .88rem; }
.regular-form select { grid-column: 1; }
.regular-form input[name="interval_days"] { grid-column: 2; grid-row: 2; }
.regular-form .button { grid-column: 2; grid-row: 2; }
.regular-form input[name="interval_days"]:not([hidden]) + .button { grid-column: 1 / -1; grid-row: 3; }
.manage-list { display: grid; gap: 8px; }
.manage-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 10px; border-bottom: 1px solid var(--line); padding: 10px 3px; }
.manage-row strong, .manage-row small { display: block; }
.manage-row small { margin-top: 3px; color: var(--muted); }
.manage-row button { border: 0; background: transparent; color: var(--danger); padding: 8px; }
.import-box { margin-bottom: 20px; border-radius: 14px; background: var(--green-soft); padding: 14px; }
.import-box > label { display: block; margin-bottom: 7px; font-size: .8rem; font-weight: 750; }
.import-box small { display: block; margin-top: 7px; color: var(--muted); }
.import-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 7px; }
.form-grid { display: grid; gap: 14px; }
.form-grid label small { color: var(--muted); font-weight: 500; }
.or-divider { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: .7rem; text-transform: uppercase; }
.or-divider::before, .or-divider::after { height: 1px; flex: 1; background: var(--line); content: ""; }
.settings-profile { display: flex; align-items: center; gap: 12px; margin-bottom: 25px; }
.settings-profile strong, .settings-profile small { display: block; }
.settings-profile small { margin-top: 3px; color: var(--muted); }
.copy-box { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 6px; margin-top: 10px; }
.copy-box button { border: 0; border-radius: 10px; background: var(--green-deep); color: #fff; padding: 0 13px; font-weight: 750; }
.toast-region { position: fixed; z-index: 80; top: 72px; right: 14px; left: 14px; display: grid; justify-items: center; gap: 8px; pointer-events: none; }
.toast { max-width: 420px; border-radius: 12px; background: var(--ink); color: #fff; padding: 10px 14px; box-shadow: var(--shadow); font-size: .82rem; font-weight: 650; animation: toast-in .2s ease; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-7px); } }

@media (max-width: 520px) {
    .shop-heading { display: block; }
    .shop-heading .button { width: 100%; margin-top: 16px; }
    .quick-add { grid-template-columns: 28px minmax(0, 1fr) 50px auto; }
    .quick-add .button { padding-right: 12px; padding-left: 12px; }
    .page-heading:not(.shop-heading) { align-items: center; }
    .page-heading:not(.shop-heading) h1 { font-size: 2.25rem; }
    .page-heading:not(.shop-heading) .muted { display: none; }
}

@media (min-width: 700px) {
    .app-main { padding: 88px 30px 105px; }
    .recipe-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .field-span-2 { grid-column: 1 / -1; }
    .meal-calendar { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .regular-form { grid-template-columns: minmax(0, 1fr) 82px 150px 82px auto; }
    .regular-form select, .regular-form input[name="interval_days"], .regular-form .button,
    .regular-form input[name="interval_days"]:not([hidden]) + .button { grid-column: auto; grid-row: auto; }
}

@media (min-width: 1000px) {
    .app-shell { display: grid; grid-template-columns: 245px minmax(0, 1fr); }
    .desktop-sidebar { position: sticky; top: 0; display: flex; height: 100vh; flex-direction: column; border-right: 1px solid var(--line); background: #f2efe6; padding: 24px 18px; }
    .desktop-sidebar .brand { margin: 0 7px 42px; }
    .desktop-nav { flex: 1; }
    .profile-button { display: flex; width: 100%; align-items: center; gap: 10px; border: 0; border-radius: 13px; background: transparent; padding: 10px; text-align: left; }
    .profile-button:hover { background: var(--surface); }
    .mobile-header, .mobile-nav { display: none; }
    .app-main { padding: 58px 48px 80px; }
    .next-meal-card { margin-bottom: 38px; }
    .meal-calendar { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .toast-region { left: 260px; }
}
