:root {
    --waitrose-green: #154733;
    --waitrose-lime: #c4d600;
    --background: #f4f5f1;
    --surface: #ffffff;
    --text: #17221d;
    --secondary-text: #66716b;
    --border: rgba(21, 71, 51, 0.12);
    --safe-top: env(safe-area-inset-top);
    --safe-bottom: env(safe-area-inset-bottom);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; min-height: 100%; background: var(--background); color: var(--text); font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
body { overscroll-behavior-y: none; }
button, input { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

.setup-screen { position: fixed; inset: 0; z-index: 1000; display: flex; align-items: center; justify-content: center; padding: calc(30px + var(--safe-top)) 28px calc(30px + var(--safe-bottom)); background: var(--waitrose-green); }
.setup-content { width: 100%; max-width: 420px; text-align: center; }
.setup-logo { width: 120px; height: 120px; object-fit: cover; border-radius: 26px; margin-bottom: 30px; box-shadow: 0 15px 40px rgba(0,0,0,.22); }
.setup-content h1, #greeting, .hero-content h2, .subpage-header h1, .settings-header h2, .home-barcode-card h2, .section-toolbar h2, .empty-state h2, .julian-result strong { font-family: "League Gothic", sans-serif; font-weight: 400; }
.setup-content h1 { margin: 0; color: var(--waitrose-lime); font-size: 64px; line-height: .95; }
.setup-content > p { margin: 14px auto 36px; max-width: 300px; color: rgba(255,255,255,.82); line-height: 1.5; }
.setup-content form { text-align: left; }
.setup-content label { color: white; }
label { display: block; margin-bottom: 8px; font-size: 14px; font-weight: 600; }
input { width: 100%; padding: 17px 16px; border: 1px solid var(--border); border-radius: 14px; background: white; font-size: 17px; outline: 0; }
input:focus { box-shadow: 0 0 0 3px rgba(196,214,0,.35); }

.primary-button, .secondary-button { width: 100%; padding: 16px 18px; border: 0; border-radius: 14px; font-weight: 700; }
.primary-button { background: var(--waitrose-lime); color: var(--waitrose-green); }
.secondary-button { background: var(--waitrose-green); color: white; }

.app { min-height: 100vh; padding-bottom: calc(25px + var(--safe-bottom)); }
.page { display: none; min-height: 100vh; }
.page.active-page { display: block; }
.top-header { padding: calc(22px + var(--safe-top)) 22px 22px; background: var(--waitrose-green); }
.header-content { max-width: 800px; margin: 0 auto; display: flex; align-items: center; justify-content: space-between; gap: 20px; }
#greeting { margin: 0; color: var(--waitrose-lime); font-size: clamp(44px, 12vw, 66px); line-height: .95; }
.current-date { margin: 8px 0 0; color: rgba(255,255,255,.78); font-size: 15px; }
.icon-button { width: 46px; height: 46px; flex: 0 0 auto; display: grid; place-items: center; padding: 11px; border: 0; border-radius: 50%; background: rgba(255,255,255,.1); color: white; }
.icon-button svg { width: 100%; height: 100%; fill: currentColor; }

.hero-banner { position: relative; height: 230px; overflow: hidden; background: var(--waitrose-green); }
.hero-banner img { width: 100%; height: 100%; display: block; object-fit: cover; }
.hero-overlay { position: absolute; inset: 0; background: linear-gradient(90deg, rgba(10,50,35,.48) 0%, rgba(10,50,35,.18) 58%, rgba(10,50,35,.01) 100%); }
.hero-content { position: absolute; left: 24px; right: 24px; bottom: 25px; color: white; }
.hero-content h2 { margin: 0; max-width: 640px; font-size: clamp(44px, 12vw, 60px); line-height: .94; text-wrap: balance; }

.main-content, .subpage-content { max-width: 800px; margin: 0 auto; padding: 30px 20px; }
.narrow-content { max-width: 620px; }
.menu-grid, .category-grid, .product-grid { display: grid; gap: 12px; }
.menu-card, .category-card { width: 100%; display: grid; grid-template-columns: 58px minmax(0,1fr) 30px; align-items: center; gap: 15px; padding: 18px; text-align: left; border: 1px solid var(--border); border-radius: 18px; background: white; color: var(--text); box-shadow: 0 4px 15px rgba(21,71,51,.04); }
.menu-card:active, .category-card:active { transform: scale(.985); }
.menu-card-icon, .category-code { width: 58px; height: 58px; display: grid; place-items: center; border-radius: 15px; background: var(--waitrose-green); color: var(--waitrose-lime); font-family: "League Gothic", sans-serif; font-size: 26px; }
.menu-card h3, .category-card h3 { margin: 0 0 4px; font-size: 17px; }
.menu-card p, .category-card p { margin: 0; color: var(--secondary-text); font-size: 13px; }
.menu-arrow { justify-self: end; color: var(--waitrose-green); font-size: 23px; }

.home-barcode-card, .tool-card, .empty-state { padding: 20px; border: 1px solid var(--border); border-radius: 18px; background: white; }
.home-barcode-card { margin-bottom: 18px; }
.home-barcode-card h2 { margin: 0 0 14px; color: var(--waitrose-green); font-size: 34px; }
.barcode-frame { width: 100%; overflow-x: auto; padding: 12px 8px; border-radius: 12px; background: white; text-align: center; }
.barcode-frame svg, .product-barcode svg { max-width: 100%; height: auto; }
footer { padding: 5px 20px 15px; text-align: center; color: #84908a; font-size: 12px; }

.subpage-header { display: flex; align-items: flex-start; gap: 16px; padding: calc(20px + var(--safe-top)) 20px 22px; background: var(--waitrose-green); color: white; }
.subpage-header h1 { margin: 0; color: var(--waitrose-lime); font-size: 48px; line-height: .95; }
.subpage-header p { margin: 8px 0 0; color: rgba(255,255,255,.78); font-size: 14px; }
.back-button { width: 42px; height: 42px; flex: 0 0 auto; border: 0; border-radius: 50%; background: rgba(255,255,255,.1); color: white; font-size: 24px; }
.section-toolbar { margin-bottom: 18px; }
.section-toolbar h2 { margin: 10px 0 3px; color: var(--waitrose-green); font-size: 38px; }
.section-toolbar p { margin: 0; color: var(--secondary-text); font-size: 13px; }
.text-button, .text-link-button { padding: 0; border: 0; background: transparent; color: var(--waitrose-green); font-weight: 700; }

.product-card { overflow: hidden; border: 1px solid var(--border); border-radius: 18px; background: white; }
.product-image-wrap { position: relative; aspect-ratio: 16 / 10; overflow: hidden; background: #eef0eb; }
.product-image-wrap img { width: 100%; height: 100%; object-fit: contain; display: block; }
.product-image-fallback { position: absolute; inset: 0; display: grid; place-items: center; padding: 20px; color: var(--secondary-text); font-size: 13px; text-align: center; }
.product-details { padding: 18px; }
.product-details h3 { margin: 0 0 7px; font-size: 18px; line-height: 1.25; }
.product-meta { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.meta-pill { padding: 6px 9px; border-radius: 999px; background: var(--background); color: var(--waitrose-green); font-size: 11px; font-weight: 700; }
.product-barcode { padding: 9px 4px 2px; overflow-x: auto; text-align: center; }

.tool-card input { margin-bottom: 18px; background: var(--background); }
.julian-result { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 20px; border-radius: 16px; background: var(--waitrose-green); color: white; }
.julian-result strong { color: var(--waitrose-lime); font-size: 52px; line-height: 1; }
.tool-note { margin: 14px 0 0; color: var(--secondary-text); font-size: 13px; line-height: 1.45; }
.sco-full-frame { min-height: 180px; display: grid; place-items: center; }
.open-settings-link { margin-top: 18px; }
.empty-state { text-align: center; }
.empty-state h2 { margin-top: 0; color: var(--waitrose-green); font-size: 38px; }
.empty-state p { color: var(--secondary-text); line-height: 1.5; }

.overlay { position: fixed; inset: 0; z-index: 100; background: rgba(0,0,0,.38); backdrop-filter: blur(2px); -webkit-backdrop-filter: blur(2px); }
.settings-panel { position: fixed; z-index: 101; left: 0; right: 0; bottom: 0; max-height: 88vh; padding-bottom: var(--safe-bottom); border-radius: 24px 24px 0 0; background: var(--background); transform: translateY(110%); transition: transform .32s cubic-bezier(.32,.72,0,1); box-shadow: 0 -20px 60px rgba(0,0,0,.2); overflow: hidden; }
.settings-panel.open { transform: translateY(0); }
.settings-header { display: flex; align-items: center; justify-content: space-between; padding: 22px 22px 18px; border-bottom: 1px solid var(--border); }
.settings-header h2 { margin: 0; color: var(--waitrose-green); font-size: 38px; }
.close-button { width: 40px; height: 40px; display: grid; place-items: center; padding: 0; border: 0; border-radius: 50%; background: rgba(21,71,51,.08); color: var(--waitrose-green); font-size: 28px; }
.settings-content { max-height: calc(88vh - 80px); padding: 20px; overflow-y: auto; }
.setting-section { margin-bottom: 24px; padding: 20px; border: 1px solid var(--border); border-radius: 18px; background: white; }
.setting-section h3 { margin: 0 0 6px; }
.setting-section > p { margin: 0 0 16px; color: var(--secondary-text); font-size: 14px; line-height: 1.45; }
.setting-section input[type="text"] { margin-bottom: 12px; background: var(--background); }
.checkbox-row { display: flex !important; align-items: flex-start; gap: 12px; margin: 4px 0 16px !important; padding: 13px; border-radius: 13px; background: var(--background); }
.checkbox-row input { width: 22px; height: 22px; margin: 1px 0 0; accent-color: var(--waitrose-green); box-shadow: none; }
.checkbox-row span { display: flex; flex-direction: column; gap: 3px; }
.checkbox-row small { color: var(--secondary-text); font-weight: 400; line-height: 1.35; }
.disabled-row { opacity: .48; }
.app-info { text-align: center; background: transparent; border: 0; }
.app-info p { margin: 0; color: var(--waitrose-green); font-weight: 700; }
.app-info span { display: block; margin-top: 4px; color: var(--secondary-text); font-size: 12px; }

@media (min-width: 700px) {
    .hero-banner { max-width: 800px; height: 300px; margin: 25px auto 0; border-radius: 24px; }
    .settings-panel { left: 50%; max-width: 500px; transform: translate(-50%,110%); }
    .settings-panel.open { transform: translate(-50%,0); }
    .category-grid, .product-grid { grid-template-columns: repeat(2,minmax(0,1fr)); }
}


/* Compact rescan product cards */
.product-card {
    overflow: hidden;
}

.product-summary {
    width: 100%;
    display: grid;
    grid-template-columns: 76px minmax(0, 1fr) 28px;
    align-items: center;
    gap: 14px;
    padding: 12px 14px;
    border: 0;
    background: white;
    color: var(--text);
    text-align: left;
}

.product-summary:active {
    background: var(--background);
}

.product-summary .product-image-wrap {
    width: 76px;
    height: 76px;
    aspect-ratio: 1;
    border-radius: 13px;
    background: #eef0eb;
}

.product-summary .product-image-wrap img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.product-summary .product-image-fallback {
    padding: 8px;
    font-size: 10px;
}

.product-summary-text {
    min-width: 0;
}

.product-summary-text h3 {
    margin: 0 0 7px;
    font-size: 16px;
    line-height: 1.25;
}

.product-summary .product-meta {
    margin: 0;
}

.product-expand-arrow {
    justify-self: end;
    color: var(--waitrose-green);
    font-size: 24px;
    line-height: 1;
}

.product-expanded {
    padding: 4px 18px 18px;
    border-top: 1px solid var(--border);
    background: white;
}

.product-expanded .product-barcode {
    padding-top: 16px;
}

@media (min-width: 700px) {
    .product-summary {
        grid-template-columns: 88px minmax(0, 1fr) 32px;
        padding: 14px 18px;
    }

    .product-summary .product-image-wrap {
        width: 88px;
        height: 88px;
    }

    .product-summary-text h3 {
        font-size: 18px;
    }
}
