/* ==========================================================================
   WhatInTheVeg — user-facing styles
   Two layouts over one token set:
     • Phone  (<900px): single column, filter pills + bottom sheet, list results
     • Desktop (≥900px): sticky filter rail + results grid
   ========================================================================== */

/* ── Typeface ────────────────────────────────────────────────────────────── */
/* Plus Jakarta Sans — variable 200–800, self-hosted so there are no
   third-party font requests. SIL OFL 1.1; licence at /static/fonts/OFL.txt. */
@font-face {
    font-family: 'Plus Jakarta Sans';
    font-style: normal;
    font-weight: 200 800;
    font-display: swap;
    src: url('/static/fonts/plus-jakarta-sans-latin-ext.woff2') format('woff2');
    unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

@font-face {
    font-family: 'Plus Jakarta Sans';
    font-style: normal;
    font-weight: 200 800;
    font-display: swap;
    src: url('/static/fonts/plus-jakarta-sans-latin.woff2') format('woff2');
    unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
    /* Warm, appetizing palette */
    --bg: #faf8f3;
    --bg-card: #ffffff;
    --bg-subtle: #f2efe8;
    --bg-input: #ffffff;

    --text: #1e241e;
    --text-muted: #6b7268;
    --text-heading: #14180f;

    --border: #e7e4dc;
    --border-strong: #d6d2c6;

    --primary: #2e7d4f;
    --primary-600: #276b44;
    --primary-700: #1f5636;
    --primary-tint: #e7f3ea;
    --primary-tint-strong: #cfe8d7;

    --accent: #d97706;
    --accent-tint: #fbeedc;

    --danger: #b91c1c;

    --shadow-sm: 0 1px 2px rgba(20, 24, 15, 0.06);
    --shadow-md: 0 6px 18px rgba(20, 24, 15, 0.08);
    --shadow-lg: 0 18px 40px rgba(20, 24, 15, 0.16);

    --radius: 14px;
    --radius-sm: 10px;
    --radius-pill: 999px;
    --maxw: 1180px;
}

[data-theme="dark"] {
    --bg: #171a14;
    --bg-card: #1f231c;
    --bg-subtle: #23271f;
    --bg-input: #23271f;

    --text: #e6e8e1;
    --text-muted: #a0a79a;
    --text-heading: #f4f6f0;

    --border: #2e332a;
    --border-strong: #3b4236;

    --primary: #4caf7b;
    --primary-600: #43a071;
    --primary-700: #3a8c62;
    --primary-tint: #1c2e22;
    --primary-tint-strong: #24402f;

    --accent: #e8a24a;
    --accent-tint: #33270f;

    --danger: #f87171;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 6px 18px rgba(0, 0, 0, 0.45);
    --shadow-lg: 0 18px 40px rgba(0, 0, 0, 0.6);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* Several components set `display`, which would otherwise beat the UA
   `[hidden] { display: none }`. Keep the hidden attribute authoritative. */
[hidden] {
    display: none !important;
}

/* Shared inline-SVG icon set (stroke-based, currentColor). */
.icon {
    flex-shrink: 0;
    vertical-align: -0.15em;
}

/* Available to assistive tech and crawlers, not shown. */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

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

body {
    font-family: 'Plus Jakarta Sans', ui-sans-serif, system-ui, -apple-system,
        "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.55;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    transition: background 0.2s, color 0.2s;
}

button,
input {
    font-family: inherit;
}

img {
    max-width: 100%;
}

a {
    color: var(--primary-600);
}

/* ── Header ──────────────────────────────────────────────────────────────── */
.site-header {
    position: sticky;
    top: 0;
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    width: 100%;
    max-width: var(--maxw);
    margin: 0 auto;
    padding: 12px 16px;
    background: color-mix(in srgb, var(--bg) 82%, transparent);
    backdrop-filter: saturate(140%) blur(10px);
    border-bottom: 1px solid var(--border);
}

.site-logo {
    display: flex;
    align-items: center;
    gap: 12px;
    text-decoration: none;
    color: var(--text);
    min-width: 0;
}

.site-logo img {
    height: 44px;
    width: auto;
    display: block;
    flex-shrink: 0;
}

.site-logo .tagline {
    color: var(--text-muted);
    font-size: 0.78rem;
}

.site-nav {
    display: flex;
    align-items: center;
    gap: 4px;
}

.nav-link {
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.88rem;
    font-weight: 500;
    padding: 6px 10px;
    border-radius: var(--radius-sm);
    transition: background 0.15s, color 0.15s;
}

.nav-link:hover {
    color: var(--text-heading);
    background: var(--bg-subtle);
}

/* Phone: the header carries the brand only — drop the tagline (it wraps to two
   lines and shoves the nav around) and the redundant "Search" link (the logo
   already goes home), so logo + nav + theme toggle stay on one row. */
@media (max-width: 899px) {
    .site-header { gap: 8px; }
    .site-logo { gap: 9px; }
    .site-logo img { height: 36px; width: auto; }
    .site-logo .tagline { display: none; }
    .site-nav .nav-home { display: none; }
    .nav-link { padding: 6px 8px; font-size: 0.84rem; }
}

/* ── Page shell ──────────────────────────────────────────────────────────── */
.page {
    width: 100%;
    max-width: var(--maxw);
    margin: 0 auto;
    padding: 0 16px 64px;
    flex: 1;
}

/* ── Hero ────────────────────────────────────────────────────────────────── */
.hero {
    padding: 16px 0 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
}

.hero-title {
    font-size: clamp(1.3rem, 3.2vw, 1.9rem);
    font-weight: 800;
    letter-spacing: -0.02em;
    line-height: 1.2;
    color: var(--text-heading);
    max-width: 24ch;
}

/* "Searching 1,201 vegan recipes" — scope/confidence line */
.search-scope {
    margin-top: 14px;
    color: var(--text-muted);
    font-size: 0.88rem;
}

.search-scope strong {
    color: var(--text-heading);
    font-weight: 700;
}

/* ── Search panel ────────────────────────────────────────────────────────── */
.search-panel {
    width: 100%;
    max-width: 760px;
    margin-top: 24px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    padding: 14px;
    text-align: left;
}

.mode-tabs {
    display: inline-flex;
    gap: 4px;
    padding: 4px;
    background: var(--bg-subtle);
    border-radius: var(--radius-pill);
    margin-bottom: 12px;
}

.mode-tab {
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-size: 0.85rem;
    font-weight: 600;
    padding: 6px 16px;
    border-radius: var(--radius-pill);
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

.mode-tab:hover {
    color: var(--text-heading);
}

.mode-tab.active {
    background: var(--bg-card);
    color: var(--primary-700);
    box-shadow: var(--shadow-sm);
}

[data-theme="dark"] .mode-tab.active {
    color: var(--primary);
}

.search-row {
    display: flex;
    gap: 10px;
    align-items: stretch;
}

.search-input-wrap {
    position: relative;
    flex: 1;
    min-width: 0;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    min-height: 48px;
    padding: 6px 10px;
    background: var(--bg-input);
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    transition: border-color 0.15s, box-shadow 0.15s;
}

.search-input-wrap:focus-within {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 18%, transparent);
}

.chips {
    display: contents;
}

.chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: var(--primary-tint);
    color: var(--primary-700);
    padding: 5px 6px 5px 12px;
    border-radius: var(--radius-pill);
    font-size: 0.85rem;
    font-weight: 600;
    animation: chipIn 0.15s ease-out;
}

[data-theme="dark"] .chip {
    color: var(--primary);
}

.chip button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    border: none;
    border-radius: 50%;
    background: color-mix(in srgb, var(--primary) 16%, transparent);
    color: inherit;
    cursor: pointer;
    font-size: 0.9rem;
    line-height: 1;
    transition: background 0.15s;
}

.chip button:hover {
    background: color-mix(in srgb, var(--primary) 34%, transparent);
}

@keyframes chipIn {
    from { transform: scale(0.85); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

#ingredient-input,
#name-input {
    flex: 1;
    min-width: 140px;
    border: none;
    outline: none;
    font-size: 1rem;
    padding: 6px 2px;
    background: transparent;
    color: var(--text);
}

#ingredient-input::placeholder,
#name-input::placeholder {
    color: var(--text-muted);
    opacity: 0.75;
}

/* Autocomplete */
.ac-list {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    right: 0;
    z-index: 40;
    list-style: none;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-lg);
    padding: 6px;
    max-height: 288px;
    overflow-y: auto;
}

.ac-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 10px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.92rem;
}

.ac-item .ac-type {
    margin-left: auto;
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    background: var(--bg-subtle);
    padding: 2px 8px;
    border-radius: var(--radius-pill);
}

.ac-item[aria-selected="true"],
.ac-item:hover {
    background: var(--primary-tint);
}

.ac-empty {
    padding: 10px;
    font-size: 0.88rem;
    color: var(--text-muted);
}

.search-btn {
    flex-shrink: 0;
    align-self: stretch;
    padding: 0 26px;
    min-height: 48px;
    background: var(--primary);
    color: #fff;
    /* Transparent border so the disabled state's border doesn't shift layout. */
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    font-size: 0.95rem;
    font-weight: 700;
    cursor: pointer;
    transition: background 0.15s, transform 0.1s;
}

.search-btn:hover:not(:disabled) { background: var(--primary-600); }
.search-btn:active:not(:disabled) { transform: scale(0.98); }

/* Disabled = clearly inert: neutral surface + muted text, not a recoloured
   "active-looking" button. (White text on a light fill read as a third
   button colour rather than a disabled state.) */
.search-btn:disabled {
    background: var(--bg-subtle);
    color: var(--text-muted);
    border: 1px solid var(--border);
    cursor: not-allowed;
}

/* Active filter chips (both layouts) */
.active-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    margin-top: 12px;
}

/* Active-filter chips. Same object as .chip — a criterion you have applied,
   with an × to remove it — so it uses the same green treatment rather than the
   accent. Amber was the only thing distinguishing them and nothing else in the
   UI said "these are a different kind of thing", so it read as arbitrary; it
   also made the sparing accent colour the default for a routine state. The
   label measured 2.79:1 in light mode, under the 4.5:1 AA threshold for text
   this size; the green is 7.54:1.

   Kept separate from .chip rather than merged: different padding and size, no
   enter animation (these re-render wholesale on every filter change, so one
   would re-trigger constantly), and no border — the ingredient chip has none. */
.filter-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: var(--primary-tint);
    color: var(--primary-700);
    padding: 4px 6px 4px 12px;
    border-radius: var(--radius-pill);
    font-size: 0.8rem;
    font-weight: 600;
}

[data-theme="dark"] .filter-chip {
    color: var(--primary);
}

.filter-chip button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    border: none;
    border-radius: 50%;
    background: color-mix(in srgb, var(--primary) 16%, transparent);
    color: inherit;
    cursor: pointer;
    font-size: 0.8rem;
    line-height: 1;
    transition: background 0.15s;
}

.filter-chip button:hover {
    background: color-mix(in srgb, var(--primary) 34%, transparent);
}

.clear-link {
    margin-left: auto;
    border: none;
    background: none;
    color: var(--text-muted);
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: underline;
}

.clear-link:hover { color: var(--text-heading); }

/* ── Hero examples ───────────────────────────────────────────────────────── */
.hero-examples {
    display: flex;
    flex-direction: column;
    gap: 9px;
    align-items: center;
    margin-top: 18px;
    /* No width cap: lets the ingredient row fit on one line on desktop. */
    max-width: none;
}

.example-group {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    justify-content: center;
    align-items: center;
}

.hero-examples-label {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 700;
    color: var(--text-muted);
    white-space: nowrap;
}

.example-btn {
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 6px 11px;
    border-radius: var(--radius-pill);
    font-size: 0.8rem;
    font-weight: 500;
    white-space: nowrap;
    cursor: pointer;
    transition: border-color 0.15s, color 0.15s, background 0.15s;
}

.example-btn:hover {
    border-color: var(--primary);
    color: var(--primary-700);
    background: var(--primary-tint);
}

[data-theme="dark"] .example-btn:hover { color: var(--primary); }

/* ── Homepage recipe sample ──────────────────────────────────────────────── */
.featured {
    margin-top: 40px;
}

.featured-title {
    font-size: 1.15rem;
    font-weight: 800;
    color: var(--text-heading);
}

.featured-sub {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin: 4px 0 16px;
}

/* ── Mobile filter bar (pills) ───────────────────────────────────────────── */
.filter-bar {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding: 16px 0 4px;
    margin: 0 -16px;
    padding-left: 16px;
    padding-right: 16px;
    scrollbar-width: none;
}

.filter-bar::-webkit-scrollbar { display: none; }

.filter-pill {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 8px 14px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-pill);
    color: var(--text);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: border-color 0.15s, background 0.15s, color 0.15s;
}

.filter-pill.has-selection {
    border-color: var(--accent);
    background: var(--accent-tint);
    color: var(--accent);
}

.pill-badge {
    min-width: 18px;
    height: 18px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 5px;
    border-radius: var(--radius-pill);
    background: var(--accent);
    color: #fff;
    font-size: 0.7rem;
    font-weight: 700;
}

/* ── Layout: rail + results ──────────────────────────────────────────────── */
.layout {
    display: grid;
    grid-template-columns: 1fr;
    gap: 24px;
    margin-top: 12px;
}

.rail {
    display: none;
}

.results-col {
    min-width: 0;
}

/* ── Filter groups (shared by rail + sheet) ──────────────────────────────── */
.filter-group {
    padding: 14px 0;
    border-bottom: 1px solid var(--border);
}

.filter-group:first-child { padding-top: 0; }
.filter-group:last-child { border-bottom: none; }

.filter-group-title {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    font-weight: 800;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.filter-hint {
    font-size: 0.78rem;
    color: var(--text-muted);
    padding: 2px 0 10px;
}

.filter-opt.is-empty {
    opacity: 0.42;
    cursor: not-allowed;
}

.filter-opt.is-empty:hover {
    background: transparent;
}

.filter-opt {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 6px 4px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: background 0.12s;
}

.filter-opt:hover { background: var(--bg-subtle); }

.filter-opt input {
    width: 16px;
    height: 16px;
    accent-color: var(--primary);
    flex-shrink: 0;
    cursor: pointer;
}

.filter-opt-label {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.filter-opt-count {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
}

.filter-more > summary {
    display: flex;
    align-items: center;
    gap: 6px;
    list-style: none;
    cursor: pointer;
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--primary-600);
    padding: 8px 0;
}

.filter-more > summary::-webkit-details-marker { display: none; }
.filter-more > summary .icon { transition: transform 0.15s; }
.filter-more[open] > summary .icon { transform: rotate(180deg); }

.rail-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    margin-bottom: 4px;
}

.rail-head h2 {
    font-size: 1.05rem;
    font-weight: 800;
    color: var(--text-heading);
}

/* ── Toolbar + results ───────────────────────────────────────────────────── */
.toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 4px 0 14px;
}

.results-count {
    font-size: 0.9rem;
    color: var(--text-muted);
}

.results-count strong {
    color: var(--text-heading);
    font-weight: 700;
}

/* ── Pagination ──────────────────────────────────────────────────────────── */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 22px 0 6px;
}

.pagination .page-info {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.pagination button {
    font-family: inherit;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--primary-700);
    background: var(--bg-card);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-pill);
    padding: 7px 16px;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
}

.pagination button:hover:not(:disabled) {
    background: var(--primary-tint);
    border-color: var(--primary);
}

.pagination button:disabled {
    opacity: 0.45;
    cursor: default;
}

.layout-toggle {
    display: none;
    gap: 4px;
    padding: 3px;
    background: var(--bg-subtle);
    border-radius: var(--radius-sm);
}

.toggle-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 28px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

.toggle-btn:hover { color: var(--text-heading); }
.toggle-btn.active {
    background: var(--bg-card);
    color: var(--primary-700);
    box-shadow: var(--shadow-sm);
}

[data-theme="dark"] .toggle-btn.active { color: var(--primary); }

.results {
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
}

/* ── Result card ─────────────────────────────────────────────────────────── */
.card {
    display: flex;
    gap: 14px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px;
    transition: box-shadow 0.15s, border-color 0.15s, transform 0.15s;
}

.card:hover {
    box-shadow: var(--shadow-md);
    border-color: var(--primary-tint-strong);
}

.card-thumb {
    display: block;
    width: 104px;
    height: 104px;
    flex-shrink: 0;
    border-radius: var(--radius-sm);
    overflow: hidden;
    background: linear-gradient(135deg, var(--primary-tint), var(--primary-tint-strong));
}

.card-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.card-thumb-placeholder {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--primary-700);
    opacity: 0.7;
}

.card-body {
    min-width: 0;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.card-title {
    font-size: 1rem;
    font-weight: 700;
    line-height: 1.3;
    color: var(--text-heading);
}

.card-title a {
    color: inherit;
    text-decoration: none;
}

.card-title a:hover { color: var(--primary-600); }

.card-desc {
    font-size: 0.86rem;
    color: var(--text-muted);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.card-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 12px;
    align-items: center;
    font-size: 0.78rem;
    color: var(--text-muted);
}

.card-meta .dot { opacity: 0.5; }

.card-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
}

.card-tag {
    background: var(--bg-subtle);
    color: var(--text-muted);
    padding: 1px 8px;
    border-radius: var(--radius-pill);
    font-size: 0.7rem;
}

/* "Also uses" ingredient line — desktop only (see the 900px media query). */
.card-also {
    display: none;
    font-size: 0.78rem;
    line-height: 1.45;
    color: var(--text-muted);
}

.card-also-label {
    font-weight: 600;
    color: var(--text);
}

.card-source {
    margin-top: auto;
    font-size: 0.76rem;
    color: var(--text-muted);
}

.card-source a {
    color: var(--text-muted);
    text-decoration: none;
    font-weight: 600;
}

.card-source a:hover { color: var(--primary-600); }

.card-source a .icon {
    margin-left: 3px;
    vertical-align: -0.12em;
    opacity: 0.75;
}

/* Grid layout (desktop) */
.results.grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
}

.results.grid .card {
    flex-direction: column;
    padding: 0;
    gap: 0;
    overflow: hidden;
}

.results.grid .card-thumb {
    width: 100%;
    height: auto;
    aspect-ratio: 16 / 10;
    border-radius: 0;
}

.results.grid .card-body {
    padding: 12px 14px 14px;
    gap: 7px;
}

/* ── Empty / status states ───────────────────────────────────────────────── */
.empty-state {
    text-align: center;
    padding: 56px 24px;
}

.empty-state h2 {
    font-size: 1.25rem;
    color: var(--text-heading);
    margin-bottom: 6px;
}

.empty-state p {
    color: var(--text-muted);
    max-width: 42ch;
    margin: 0 auto;
}

.loading {
    text-align: center;
    padding: 40px;
    color: var(--text-muted);
}

.loading::after {
    content: '';
    display: inline-block;
    width: 18px;
    height: 18px;
    border: 2px solid var(--border-strong);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-left: 8px;
    vertical-align: middle;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Mobile filter sheet ─────────────────────────────────────────────────── */
.sheet-backdrop {
    position: fixed;
    inset: 0;
    z-index: 90;
    background: rgba(20, 24, 15, 0.45);
    animation: fadeIn 0.15s ease-out;
}

.sheet {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 100;
    max-height: 82vh;
    display: flex;
    flex-direction: column;
    background: var(--bg-card);
    border-radius: 20px 20px 0 0;
    box-shadow: var(--shadow-lg);
    animation: sheetUp 0.22s cubic-bezier(0.2, 0.8, 0.2, 1);
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes sheetUp { from { transform: translateY(100%); } to { transform: translateY(0); } }

.sheet-handle {
    width: 40px;
    height: 4px;
    border-radius: var(--radius-pill);
    background: var(--border-strong);
    margin: 10px auto 0;
    flex-shrink: 0;
}

.sheet-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 20px;
    border-bottom: 1px solid var(--border);
}

.sheet-head h2 {
    font-size: 1.05rem;
    font-weight: 800;
    color: var(--text-heading);
}

.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--text-muted);
    border-radius: 50%;
    cursor: pointer;
    font-size: 1.1rem;
    line-height: 1;
}

.icon-btn:hover { color: var(--text-heading); }

#filter-groups-sheet {
    overflow-y: auto;
    padding: 4px 20px 8px;
}

.sheet-apply {
    margin: 12px 20px 20px;
    padding: 14px;
    border: none;
    border-radius: var(--radius-sm);
    background: var(--primary);
    color: #fff;
    font-size: 0.95rem;
    font-weight: 700;
    cursor: pointer;
}

.sheet-apply:hover { background: var(--primary-600); }

/* ── PWA install guide (static/js/install.js) ─────────────────────────────── */
.install-backdrop {
    position: fixed;
    inset: 0;
    z-index: 120;
    background: rgba(20, 24, 15, 0.45);
    display: grid;
    place-items: center;
    padding: 20px;
    animation: fadeIn 0.15s ease-out;
}

.install-modal {
    width: 100%;
    max-width: 380px;
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: 22px;
}

.install-modal h2 {
    font-size: 1.1rem;
    color: var(--text-heading);
    margin-bottom: 6px;
}

.install-modal p {
    font-size: 0.88rem;
    color: var(--text-muted);
    margin-bottom: 12px;
}

.install-modal ol {
    padding-left: 20px;
    margin-bottom: 18px;
    font-size: 0.9rem;
}

.install-modal li { margin-bottom: 6px; }

/* ── Responsive: desktop layout ──────────────────────────────────────────── */
@media (min-width: 900px) {
    .hero {
        padding: 24px 0 12px;
    }

    /* "Also uses" line is desktop-only. */
    .card-also {
        display: block;
    }

    .layout {
        grid-template-columns: 232px minmax(0, 1fr);
        gap: 32px;
        margin-top: 28px;
        align-items: start;
    }

    .rail {
        display: block;
        position: sticky;
        top: 84px;
        max-height: calc(100vh - 104px);
        overflow-y: auto;
        /* No visible scrollbar, but still scrollable. A sticky rail taller than
           the viewport would otherwise strand its bottom filters off-screen, so
           the scroll stays and a bottom fade (toggled in JS when it overflows)
           is the affordance instead of a scrollbar. */
        scrollbar-width: none;
        -ms-overflow-style: none;
    }

    .rail::-webkit-scrollbar { display: none; }

    .rail.is-scrollable:not(.at-bottom) {
        -webkit-mask-image: linear-gradient(to bottom, #000 calc(100% - 28px), transparent);
        mask-image: linear-gradient(to bottom, #000 calc(100% - 28px), transparent);
    }

    .filter-bar {
        display: none;
    }

    .layout-toggle {
        display: inline-flex;
    }

    .results.grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .hero-examples { margin-top: 20px; }
}

@media (min-width: 900px) and (max-width: 1099px) {
    .results.grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

/* Phone: collapse the hero once a search is active */
@media (max-width: 899px) {
    /* Grid is a desktop layout — always collapse to a list on phones. */
    .results.grid {
        grid-template-columns: 1fr;
    }

    /* The longer "Try ingredients or food groups" label fits one line on a
       normal phone, but allow it to wrap rather than ever force a horizontal
       scroll on a narrow one. */
    .hero-examples-label {
        white-space: normal;
        text-align: center;
    }

    body.searching .hero {
        padding: 16px 0 4px;
    }

    body.searching .hero-title,
    body.searching .search-scope,
    body.searching .hero-examples {
        display: none;
    }

    .search-row {
        flex-direction: column;
    }

    .search-btn {
        width: 100%;
        padding: 14px;
    }

    .active-filters { margin-top: 10px; }

    .clear-link { margin-left: 0; width: 100%; text-align: left; }
}

/* ── Footer ──────────────────────────────────────────────────────────────── */
.site-footer {
    margin-top: auto;
    padding: 28px 16px 32px;
    border-top: 1px solid var(--border);
    text-align: center;
    color: var(--text-muted);
    font-size: 0.78rem;
    max-width: var(--maxw);
    margin-left: auto;
    margin-right: auto;
    width: 100%;
}

.site-footer a { color: var(--text-muted); text-decoration: none; }
.site-footer a:hover { color: var(--primary-600); }

/* ── Form pages (contact, dmca) ──────────────────────────────────────────── */
.form-page { max-width: 600px; margin: 40px auto; padding: 0 20px; flex: 1; }
.form-page h1 { font-size: 1.5rem; color: var(--text-heading); margin-bottom: 8px; }
.form-page p { color: var(--text-muted); margin-bottom: 16px; }
.form-page p small { font-size: 0.82rem; }
.form-page a { color: var(--primary-600); text-decoration: underline; }
.form-page a:hover { color: var(--primary-700); }
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 0.88rem; font-weight: 500; color: var(--text); margin-bottom: 6px; }
.form-group input, .form-group textarea {
    width: 100%; padding: 10px 12px; font-size: 0.95rem;
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    background: var(--bg-input); color: var(--text);
}
.form-group textarea { min-height: 120px; resize: vertical; }
.form-group input:focus, .form-group textarea:focus {
    outline: none; border-color: var(--primary);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 18%, transparent);
}
.submit-btn {
    display: inline-flex; align-items: center; gap: 8px;
    padding: 10px 24px; font-size: 0.95rem; font-weight: 600;
    border: none; border-radius: var(--radius-sm); cursor: pointer;
    background: var(--primary); color: white;
    transition: background 0.15s;
}
.submit-btn:hover { background: var(--primary-600); }
.submit-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.status { margin-top: 16px; padding: 12px; border-radius: var(--radius-sm); font-size: 0.9rem; }
.status.success { background: var(--primary-tint); color: var(--primary-700); }
.status.error { background: #fef2f2; color: var(--danger); }
[data-theme="dark"] .status.error { background: #3a1414; color: var(--danger); }
.back-link { display: inline-block; margin-top: 24px; color: var(--primary-600); text-decoration: none; font-size: 0.88rem; }
.back-link:hover { text-decoration: underline; }

/* ── Content pages (privacy, terms) ──────────────────────────────────────── */
.form-page h2 { font-size: 1.1rem; color: var(--text-heading); margin-top: 24px; margin-bottom: 8px; }
.form-page ul { padding-left: 20px; margin-bottom: 12px; color: var(--text); }

/* Legal pages share the home page's container width so the layout doesn't
   visibly narrow between pages. Contact/DMCA keep the narrower form width. */
.form-page.doc-page {
    max-width: var(--maxw);
    padding: 0 16px;
}

.form-page.doc-page h1 { font-size: 1.75rem; }
.form-page.doc-page h2 { font-size: 1.2rem; margin-top: 30px; }

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.001ms !important;
        transition-duration: 0.001ms !important;
    }
}
