/* =====================================================================
   What Can I Cook? (index-enhanced.html #cook-with), "kitchen notepad"
   layout, in the same paper and serif style as the recipe journal cards.
   The panel holds your ingredients and filters beside the results; the
   result rows come from cwSearch in script.js. Loaded after styles.css.
   ===================================================================== */
#cook-with {
    --cw-green: var(--primary-color, #1f4836);
    --cw-green-2: #2d5a44;
    --cw-gold: #bf9b30;
    --cw-gold-soft: #f6ecc9;
    --cw-sage-soft: #e8eee0;
    --cw-paper: #fffdf7;
    --cw-ink: #24302a;
    --cw-muted: #6b7263;
    --cw-line: #e2dccb;
    --cw-buy: #a5482f;
    --cw-serif: var(--heading-font, 'Cormorant Garamond', Georgia, serif);
    --cw-sans: var(--body-font, 'Inter', -apple-system, 'Segoe UI', sans-serif);
    background: transparent;
}

#cook-with > h2 {
    max-width: 1140px;
    margin: 1.5rem auto 0.2rem;
    padding: 0 16px;
    box-sizing: border-box;
    text-align: left;
    font-family: var(--cw-serif);
    font-size: 1.9rem;
    font-weight: 600;
    color: var(--cw-green);
}
#cook-with .cw-intro { max-width: 1140px; margin: 0 auto 1rem; padding: 0 16px; box-sizing: border-box; color: var(--cw-muted); }

.cw-layout {
    display: grid;
    grid-template-columns: 300px minmax(0, 1fr);
    gap: 20px;
    align-items: start;
    max-width: 1140px;
    margin: 0 auto;
    padding: 0 16px 2rem;
    box-sizing: border-box;
}

/* ---- In my kitchen ---- */
#cook-with .cw-panel {
    position: sticky;
    top: 122px;
    max-width: none;
    margin: 0;
    display: grid;
    gap: 12px;
    padding: 18px;
    border: 0;
    border-radius: 16px;
    background: var(--cw-paper);
    box-shadow: 0 2px 12px rgba(31, 72, 54, 0.08);
    font-family: var(--cw-sans);
    text-align: left;
}
#cook-with .cw-label { margin: 0; font: 600 1.35rem var(--cw-serif); color: var(--cw-green); }
#cook-with .cw-entry { gap: 0; align-items: center; padding: 4px; border: 1px solid var(--cw-line); border-radius: 999px; background: #fff; }
#cook-with .cw-entry:focus-within { border-color: var(--cw-green); }
#cook-with .cw-entry input { padding: 0.45rem 0.6rem 0.45rem 0.8rem; border: 0; background: transparent; font-size: 0.88rem; }
#cook-with .cw-entry input:focus { box-shadow: none; }
#cook-with .cw-add-btn { padding: 0.4rem 0.95rem; border-radius: 999px; font-size: 0.8rem; }
#cook-with .cw-hint { margin: -4px 0 0; font-size: 0.74rem; color: var(--cw-muted); }
#cook-with .cw-chips { margin: 0; gap: 6px; }
#cook-with .cw-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 3px 5px 3px 11px;
    border: 0;
    border-radius: 999px;
    background: var(--cw-sage-soft);
    color: var(--cw-green);
    font-size: 0.8rem;
    font-weight: 600;
}
#cook-with .cw-chip-x {
    width: 18px;
    height: 18px;
    display: grid;
    place-items: center;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: rgba(31, 72, 54, 0.1);
    color: var(--cw-green);
    font-size: 0.85rem;
    line-height: 1;
    cursor: pointer;
}
#cook-with .cw-chips .cw-empty { padding: 0; font-size: 0.8rem; color: var(--cw-muted); }

/* Filters: the label sits above its buttons in the narrow panel. */
#cook-with .cw-filter-row { display: flex; flex-wrap: wrap; gap: 5px; margin: 0; padding-top: 12px; border-top: 1px dashed var(--cw-line); }
#cook-with .cw-filter-label {
    flex: 1 0 100%;
    margin: 0 0 2px;
    font-size: 0.66rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--cw-muted);
}
#cook-with .cw-ex-btn,
#cook-with .cw-time-btn { padding: 3px 10px; border-color: var(--cw-line); background: var(--cw-paper); color: var(--cw-ink); font-size: 0.76rem; font-weight: 600; }
#cook-with .cw-time-btn.active { background: var(--cw-green); border-color: var(--cw-green); color: #fff; }
#cook-with .cw-ex-btn.active { background: #b45309; border-color: #b45309; color: #fff; }
#cook-with .cw-allergy-note { margin: 0; font-size: 0.78rem; }
#cook-with .cw-controls { display: grid; gap: 8px; margin: 0; padding-top: 12px; border-top: 1px dashed var(--cw-line); }
#cook-with .cw-check { align-items: flex-start; gap: 8px; font-size: 0.8rem; color: var(--cw-ink); }
#cook-with .cw-check input { margin-top: 2px; }
#cook-with .cw-clear-btn { justify-self: start; padding: 0; border: 0; background: none; color: var(--cw-green); font-size: 0.78rem; font-weight: 600; text-decoration: underline; text-underline-offset: 3px; }
#cook-with .cw-clear-btn:hover { color: #b45309; }

/* ---- Results ---- */
#cook-with .cw-results { display: grid; gap: 12px; max-width: none; margin: 0; min-width: 0; }
#cook-with .cw-count { margin: 0; font: 600 1.15rem var(--cw-serif); color: var(--cw-green); text-align: left; }
#cook-with .cw-count span { margin-left: 6px; font: 400 0.8rem var(--cw-sans); color: var(--cw-muted); }
#cook-with .cw-results > .cw-empty { margin: 0; padding: 18px; border-radius: 16px; background: var(--cw-paper); text-align: left; color: var(--cw-ink); }
.cw-start {
    display: grid;
    justify-items: center;
    gap: 8px;
    padding: 48px 24px;
    border: 1px dashed var(--cw-line);
    border-radius: 16px;
    color: var(--cw-muted);
    text-align: center;
}
.cw-start i { font-size: 1.6rem; color: var(--cw-gold); }
.cw-start p { margin: 0; max-width: 34ch; font: italic 500 1.15rem/1.4 var(--cw-serif); color: var(--cw-ink); }

.cwj {
    display: grid;
    grid-template-columns: 120px minmax(0, 1fr) minmax(0, 0.9fr);
    gap: 16px;
    padding: 14px;
    border-radius: 16px;
    background: var(--cw-paper);
    box-shadow: 0 2px 12px rgba(31, 72, 54, 0.08);
    font-family: var(--cw-sans);
    color: var(--cw-ink);
    text-align: left;
}
.cwj-photo { position: relative; display: block; aspect-ratio: 1; max-width: 100%; align-self: start; border-radius: 12px; overflow: hidden; background: #e9e4d6; }
.cwj-photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cwj-photo b { display: none; }
.cwj-photo-none { background: repeating-linear-gradient(135deg, #f6ecc9 0 10px, #f1e3b6 10px 20px); }
.cwj-photo-none b { position: absolute; inset: 0; display: grid; place-items: center; font: 600 1.8rem var(--cw-serif); color: var(--cw-gold); }

.cwj-mid { display: grid; gap: 6px; align-content: start; min-width: 0; }
.cwj-title { margin: 0; font: 600 1.35rem/1.15 var(--cw-serif); }
.cwj-title a { color: var(--cw-green); text-decoration: none; }
.cwj-title a:hover { text-decoration: underline; text-underline-offset: 4px; }
.cwj-by { font-size: 0.78rem; color: var(--cw-muted); }
.cwj-by a { color: var(--cw-ink); font-weight: 700; text-decoration: none; }
.cwj-by a:hover { color: var(--cw-green); text-decoration: underline; }
.cwj-facts { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 12px; font-size: 0.76rem; color: var(--cw-muted); }
.cwj-country { color: var(--cw-green); font-weight: 700; }
.cwj .cw-time-chip { margin: 0; padding: 0; background: none; font-size: 0.76rem; color: var(--cw-muted); }
.cwj-meter { display: grid; gap: 4px; }
.cwj-bar { height: 7px; border-radius: 999px; background: var(--cw-line); overflow: hidden; }
.cwj-bar i { display: block; height: 100%; border-radius: 999px; background: var(--cw-gold); }
.cwj-meter small { font-size: 0.74rem; color: var(--cw-muted); font-variant-numeric: tabular-nums; }
.cwj-meter small b { color: var(--cw-ink); }
.cwj-full {
    justify-self: start;
    display: inline-flex;
    align-items: center;
    gap: 7px;
    margin-top: 2px;
    padding: 7px 14px;
    border-radius: 999px;
    background: var(--cw-green);
    color: #fff !important;
    font-size: 0.8rem;
    font-weight: 600;
    text-decoration: none;
}
.cwj-full:hover { background: var(--cw-green-2); }

.cwj-side { display: grid; gap: 7px; align-content: start; min-width: 0; padding-left: 14px; border-left: 1px dashed var(--cw-line); }
.cwj-lab { font-size: 0.66rem; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; color: var(--cw-muted); }
.cwj-have { display: flex; flex-wrap: wrap; gap: 4px; }
.cwj-have span { padding: 2px 9px; border-radius: 999px; background: var(--cw-sage-soft); color: var(--cw-green); font-size: 0.74rem; font-weight: 600; }
.cwj-have span::before { content: "\2713\00a0"; }
.cwj-buy { margin: 0; padding: 0; list-style: none; display: grid; gap: 2px; font-size: 0.8rem; }
.cwj-buy li { display: flex; gap: 7px; align-items: baseline; min-width: 0; overflow-wrap: anywhere; }
.cwj-buy li::before { content: ""; flex: 0 0 auto; width: 9px; height: 9px; border: 1.5px solid var(--cw-buy); border-radius: 2px; transform: translateY(1px); }
.cwj-buy .cwj-more::before { display: none; }
.cwj-more a { color: var(--cw-muted); font-size: 0.76rem; }
.cwj .cw-have-all { margin: 0; padding: 0; background: none; border: 0; color: var(--cw-green); font-size: 0.8rem; font-weight: 600; }

.cwj a:focus-visible,
#cook-with button:focus-visible { outline: 2px solid var(--cw-gold); outline-offset: 2px; }

/* ---- Narrower screens ---- */
@media (max-width: 900px) {
    .cw-layout { grid-template-columns: minmax(0, 1fr); }
    #cook-with .cw-panel { position: static; }
}
@media (max-width: 768px) {
    .cw-layout,
    #cook-with > h2,
    #cook-with .cw-intro { padding-left: 0; padding-right: 0; }
}
@media (max-width: 620px) {
    .cwj { grid-template-columns: 90px minmax(0, 1fr); gap: 12px; padding: 12px; }
    .cwj-title { font-size: 1.2rem; }
    .cwj-side { grid-column: 1 / -1; padding: 10px 0 0; border-left: 0; border-top: 1px dashed var(--cw-line); }
}

/* The one-line shopping list and the filter sheet are phone-only. */
.cwj-buyline,
.cw-filters-btn,
.cw-sheet,
.cw-sheet-dim { display: none; }

/* =====================================================================
   Phones: search bar + filter sheet (scripts/cook-phone.js).
   The panel is a slim bar that stays under the site header: the
   ingredient box, a Filters button with a count, and your ingredients as
   a row that scrolls sideways. The filters live in a sheet that slides up
   from the bottom. Results are compact cards.
   ===================================================================== */
@media (max-width: 600px) {
    #cook-with > h2 { margin-top: 0.75rem; font-size: 1.6rem; }
    #cook-with .cw-intro { margin-bottom: 0.5rem; font-size: 0.8rem; }

    /* styles.css gives body overflow-x: hidden, which quietly makes body a
       scroll container and turns every position: sticky inside it off.
       clip blocks sideways scrolling the same way without doing that. */
    body:has(#cook-with) { overflow-x: clip !important; }

    #cook-with .cw-panel {
        position: sticky;
        top: var(--header-h, 56px);
        z-index: 20;
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        gap: 8px;
        margin: 0 -16px;
        padding: 10px 16px;
        border-radius: 0;
        background: var(--cream-bg, #f5efe1);
        border-bottom: 1px solid var(--cw-line);
        box-shadow: none;
    }
    #cook-with .cw-label,
    #cook-with .cw-hint { display: none; }
    /* styles.css stacks the input over a full-width Add button on phones;
       here they share one pill. */
    #cook-with .cw-entry { grid-column: 1; min-width: 0; flex-wrap: nowrap; }
    #cook-with .cw-entry input { width: auto; min-width: 0; font-size: 16px; }   /* 16px stops iOS zooming in */
    #cook-with .cw-add-btn { width: auto; flex: 0 0 auto; }
    .cw-filters-btn { align-self: center; height: 40px; }
    .cw-filters-btn {
        grid-column: 2;
        display: inline-flex;
        align-items: center;
        gap: 6px;
        padding: 0 12px;
        border: 1px solid var(--cw-line);
        border-radius: 999px;
        background: var(--cw-paper);
        color: var(--cw-green);
        font: 700 0.78rem var(--cw-sans);
        cursor: pointer;
    }
    .cw-filters-n {
        display: inline-grid;
        place-items: center;
        min-width: 18px;
        height: 18px;
        padding: 0 5px;
        border-radius: 999px;
        background: var(--cw-green);
        color: #fff;
        font: 700 0.62rem var(--cw-sans);
        font-style: normal;
    }
    .cw-filters-n[hidden] { display: none; }
    #cook-with .cw-chips {
        grid-column: 1 / -1;
        flex-wrap: nowrap;
        overflow-x: auto;
        scrollbar-width: none;
    }
    #cook-with .cw-chips::-webkit-scrollbar { display: none; }
    #cook-with .cw-chip { flex: 0 0 auto; }
    #cook-with .cw-chips:has(.cw-empty) { display: none; }

    /* ---- The sheet ---- */
    .cw-sheet-dim:not([hidden]) {
        display: block;
        position: fixed;
        inset: 0;
        z-index: 2000;
        background: rgba(20, 36, 28, 0.4);
    }
    .cw-sheet:not([hidden]) {
        display: grid;
        gap: 12px;
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 2001;
        max-height: 85vh;
        overflow-y: auto;
        padding: 8px 16px calc(16px + env(safe-area-inset-bottom, 0px));
        border-radius: 18px 18px 0 0;
        background: var(--cw-paper, #fffdf7);
        box-shadow: 0 -10px 30px rgba(31, 72, 54, 0.25);
        font-family: var(--cw-sans, sans-serif);
        transform: translateY(100%);
        transition: transform 0.22s ease;
        --cw-green: var(--primary-color, #1f4836);
        --cw-line: #e2dccb;
        --cw-ink: #24302a;
        --cw-muted: #6b7263;
        --cw-paper: #fffdf7;
    }
    .cw-sheet.in { transform: none; }
    html.cw-sheet-open { overflow: hidden; }
    .cw-sheet-grab { justify-self: center; width: 40px; height: 4px; border-radius: 999px; background: var(--cw-line); }
    .cw-sheet-head { display: flex; justify-content: space-between; align-items: baseline; }
    .cw-sheet-head h3 { margin: 0; font: 600 1.25rem var(--heading-font, Georgia, serif); color: var(--cw-green); }
    .cw-sheet-reset { padding: 0; border: 0; background: none; color: var(--cw-green); font: 600 0.78rem var(--cw-sans, sans-serif); text-decoration: underline; cursor: pointer; }
    .cw-sheet-body { display: grid; gap: 12px; }
    .cw-sheet .cw-filter-row { display: flex; flex-wrap: wrap; gap: 6px; margin: 0; padding: 0; border: 0; }
    .cw-sheet .cw-filter-label {
        flex: 1 0 100%;
        font-size: 0.64rem;
        font-weight: 700;
        letter-spacing: 0.1em;
        text-transform: uppercase;
        color: var(--cw-muted);
    }
    .cw-sheet .cw-ex-btn,
    .cw-sheet .cw-time-btn { padding: 6px 12px; border: 1px solid var(--cw-line); border-radius: 999px; background: var(--cw-paper); color: var(--cw-ink); font-size: 0.8rem; font-weight: 600; }
    .cw-sheet .cw-time-btn.active { background: var(--cw-green); border-color: var(--cw-green); color: #fff; }
    .cw-sheet .cw-ex-btn.active { background: #b45309; border-color: #b45309; color: #fff; }
    .cw-sheet .cw-allergy-note { margin: 0; font-size: 0.76rem; }
    .cw-sheet .cw-controls { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin: 0; padding-top: 10px; border-top: 1px dashed var(--cw-line); }
    .cw-sheet .cw-check { display: flex; gap: 8px; align-items: flex-start; font-size: 0.8rem; color: var(--cw-ink); }
    .cw-sheet .cw-clear-btn { flex: 0 0 auto; padding: 0; border: 0; background: none; color: var(--cw-muted); font-size: 0.76rem; text-decoration: underline; }
    .cw-sheet-show {
        padding: 12px;
        border: 0;
        border-radius: 999px;
        background: var(--cw-green);
        color: #fff;
        font: 700 0.86rem var(--cw-sans, sans-serif);
        cursor: pointer;
    }

    /* ---- Compact result cards ---- */
    #cook-with .cw-results { gap: 10px; margin-top: 10px; }
    #cook-with .cw-count { font-size: 1.05rem; }
    .cw-start { padding: 28px 18px; }
    .cwj {
        grid-template-columns: 72px minmax(0, 1fr);
        grid-template-areas:
            "photo title"
            "photo by"
            "photo facts"
            "photo meter"
            "have  have"
            "buy   buy"
            "full  full";
        grid-template-rows: auto auto auto 1fr;
        gap: 0 10px;
        padding: 11px;
        border-radius: 14px;
    }
    .cwj-mid,
    .cwj-side { display: contents; }
    .cwj-photo { grid-area: photo; align-self: start; border-radius: 10px; }
    .cwj-title { grid-area: title; font-size: 1.08rem; }
    .cwj-by { grid-area: by; margin-top: 2px; font-size: 0.7rem; }
    .cwj-facts { grid-area: facts; margin-top: 2px; font-size: 0.68rem; }
    .cwj-meter { grid-area: meter; align-self: start; margin-top: 5px; }
    .cwj-meter small { font-size: 0.7rem; }
    .cwj-side .cwj-lab { display: none; }
    .cwj-have { grid-area: have; margin-top: 8px; }
    .cwj-have span { font-size: 0.68rem; }
    .cwj-buy { display: none; }
    .cwj-buyline { grid-area: buy; display: block; margin: 6px 0 0; font-size: 0.74rem; color: var(--cw-ink); }
    .cwj-buyline b { color: var(--cw-buy); }
    .cwj .cw-have-all { grid-area: buy; margin-top: 6px; font-size: 0.74rem; }
    .cwj-full {
        grid-area: full;
        justify-self: end;
        margin-top: 6px;
        padding: 0;
        background: none;
        color: var(--cw-green) !important;
        font-size: 0.74rem;
        font-weight: 700;
    }
    .cwj-full:hover { background: none; text-decoration: underline; }
}
