/* ===== DESIGN TOKENS ===== */
:root {
    --brand-brown: #5a3917;
    --brand-brown-dark: #46290c;
    --brand-gold: #F5D58C;
    --brand-gold-hover: #f0d2af;
    --sidebar-bg: #fbf4e6; /* lighter/warmer than the white article panels */
}

/* ===== RESET AND BASE STYLES ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: "Helvetica", Arial, sans-serif;
    line-height: 1.6;
    color: #333;
    background: url('/images/juanita.jpg') no-repeat center center fixed;
    background-size: cover;
}

body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.3);
    z-index: -1;
}

h1 {
    font-family: "Georgia", "Times New Roman", serif;
    text-align: center;
    margin: 1rem 0;
    color: var(--brand-brown);
}

h2 {
    color: var(--brand-brown);
}

h3 {
    color: var(--brand-brown);
}


/* ===== LINK STYLES ===== */
a {
    text-decoration: none;
    color: #965a1f;
}

a:hover {
    color: var(--brand-brown-dark);
}

/* ===== HEADER STYLES ===== */
header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: linear-gradient(to right, #f1f1ec, #ecdbc7);
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    width: 100%;
}

.header-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 0.5rem 1rem;
    max-width: 1200px;
    margin: 0 auto;
    position: relative;
}

.header-wrapper h1 {
    width: 100%;
    text-align: center;
    margin: 0;
}

/* ===== HEADER NAV BUTTONS (Home / Top) ===== */
/* These live as the first children of #search-form (inserted by JS), so on
   desktop they naturally sit just to the left of the search box, spaced by
   #search-form's own gap. On mobile they're pulled out of that flow and
   pinned to the header instead - see the mobile override below. */
.header-nav-buttons {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.header-nav-button {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--brand-brown);
    padding: 0.25rem;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.header-nav-button:hover {
    color: var(--brand-brown-dark);
}

/* Plain stroke-based icons, same minimal-line spirit as the hamburger */
.header-nav-button svg {
    display: block;
    width: 20px;
    height: 20px;
}

/* Mobile: stack Home above Top at the far left, sized/positioned to roughly
   mirror the hamburger (which sits top: 4rem; right: 1rem;) on the right */
@media (max-width: 767px) {
    .header-nav-buttons {
        position: absolute;
        top: 4rem;
        left: 1rem;
        height: 2.4rem;
        flex-direction: column;
        justify-content: space-between;
        gap: 0;
        z-index: 101; /* above header content, below sidebar/hamburger */
    }
}

/* ===== SEARCH BOX ===== */
#search-form {
    display: flex;
    justify-content: center;
    margin: 20px 0;
    gap: 0.5rem;
}

#search-input {
    width: 400px;
    padding: 10px;
    font-size: 16px;
    border: 1px solid #ccc;
    border-radius: 4px 0 0 4px;
}

#search-form button {
    padding: 10px 20px;
    font-size: 16px;
    border: 1px solid #ccc;
    border-radius: 0 4px 4px 0;
    background-color: var(--brand-gold);
    cursor: pointer;
}

#search-form button:hover {
    background-color: var(--brand-gold-hover);
}

/* ===== MAIN CONTENT STYLES ===== */
main {
    padding: 2rem;
    max-width: 1200px;
    margin: 0 auto;
}

article {
    background-color: #fff;
    border-radius: 8px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    padding: 1.5rem;
    margin-bottom: 2rem;
}

article h2 {
    color: #2c3e50;
    margin-bottom: 1rem;
}

article img {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
    margin: 1rem 0;
}



/* ===== RECIPE PRESENTATION ===== */
.recipe-wrapper {
    margin: 1rem 0;
}

.recipe-wrapper img {
    float: right;
    width: 45%;
    max-width: 45%;
    margin: 0 0 1rem 1rem;
    border-radius: 8px;
}

.recipe-wrapper::after {
    content: "";
    display: table;
    clear: both;
}

/* ===== SHARE BUTTON ===== */
.recipe-header {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.75rem;
    width: 100%;
}

/* Copy / Shop / Related: stacked full-width on mobile */
.recipe-actions {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.5rem;
    width: 100%;
}

.recipe-actions .modal-button {
    width: 100%;
    margin: 0;
}

/* Large screens: title on the left, Copy+Shop side by side on the right,
   with Related spanning the full width underneath both */
@media (min-width: 768px) {
    .recipe-header {
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
    }

    .recipe-actions {
        grid-template-columns: 1fr 1fr;
        width: auto;
        min-width: 320px;
    }

    .recipe-actions .modal-button {
        width: auto;
    }

    .recipe-actions #related-button {
        grid-column: 1 / -1;
    }
}

.share-button {
    background: var(--brand-brown);
    color: white;
    border: none;
    padding: 8px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    margin-left: 10px;
    flex-shrink: 0;
}

.share-button:hover {
    background: var(--brand-brown-dark);
}

/* ===== RECIPE LIST STYLES ===== */
#search-results ul li {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 15px;
    margin-bottom: 30px;
    align-items: start;
}

.recipe-description {
    font-size: 14px;
    color: #555;
    margin: 5px 0;
    line-height: 1.4;
}

.recipe-item {
    display: flex;
    align-items: flex-start;
    margin-bottom: 20px;
    padding: 10px;
    border-bottom: 1px solid #eee;
    width: 100%;
}

.recipe-content {
    flex: 1;
    margin-right: 15px;
}

.recipe-image {
    max-width: 30vw;
    width: 100%;
    display: flex;
    justify-content: flex-end;
    align-items: flex-start;
    margin-left: 10px;
    margin-bottom: 10px;
    height: calc(1.2em * 4);
    overflow: hidden;
}

.recipe-image img {
    max-width: 100%;
    max-height: 80%;
    width: auto;
    height: auto;
    object-fit: contain;
    border-radius: 4px;
    display: block;
}

/* Large screens: show the search/category/hub recipe list in two columns,
   matching the related-recipes grid used on index.html. Mobile layout
   (single column, text+thumbnail per row) is untouched. */
@media (min-width: 768px) {
    #recipes-list {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 0.5rem 2rem;
        padding-left: 0;
    }

    .recipe-item {
        margin-bottom: 0;
    }
}

/* ===== CATEGORY STYLES ===== */
/* #recipe-categories is the container used on an individual recipe page;
   .recipe-categories is the same thing wrapped in search/category list items.
   Both need the same flex+gap so buttons don't touch, and enough top margin
   so they don't crowd whatever sits above them (e.g. the Related button). */
#recipe-categories,
.recipe-categories {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    width: 100%;
    margin: 0.75rem 0;
}

.category-button {
    background-color: var(--brand-gold);
    border: 1px solid #ddd;
    border-radius: 3px;
    padding: 5px 10px;
    cursor: pointer;
    font-size: 14px;
    color: black;
    text-decoration: none;
    display: inline-block;
}

.category-button:hover {
    background-color: var(--brand-gold-hover);
}

/* ===== LIST STYLES ===== */
ul, ol {
    margin: 1rem 0;
    padding-left: 2rem;
}

ul li, ol li {
    margin-bottom: 0.5rem;
}

/* ===== NAVIGATION MENU STYLES ===== */

/* Shared icon+label row used by both the <h3><a> direct links (All Recipes,
   Drinks, Basics) and the accordion .nav-toggle buttons */
#nav-menu h3 a,
.nav-extra h3 a,
.nav-toggle-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.nav-icon {
    font-size: 0.95rem;
    line-height: 1;
    width: 1.1rem;
    text-align: center;
    flex-shrink: 0;
}

/* "All Recipes" / "Drinks" / "Basics" / "My cooking plans" / "Visit the
   Garden" / "Get the App" - the direct, non-collapsible links in the sidebar
   (some built by generateNavMenu() inside #nav-menu, some static in
   .nav-extra) */
#nav-menu h3,
.nav-extra h3 {
    font-size: 1rem;
    margin: 0 0 0.35rem 0;
}

#nav-menu h3 a,
.nav-extra h3 a {
    padding: 0.4rem 0.5rem;
    border-radius: 6px;
    font-weight: bold;
}

#nav-menu h3 a:hover,
.nav-extra h3 a:hover {
    background-color: rgba(90, 57, 23, 0.08);
    text-decoration: none;
}

/* Thin divider #1: between the filter accordions (Cuisine, Cooking Method...)
   and the direct links (Drinks, Basics) that follow them. Matches only the
   first <h3> right after the last .nav-group. */
.nav-group + h3 {
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid #e6ddcf;
}

/* Thin divider #2: above whatever comes after the nav-menu block itself
   (e.g. "My cooking plans", "Visit the Garden", "Get the App"). Add this
   class to that wrapping element in index.html - see chat for details. */
.nav-extra {
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid #e6ddcf;
}

.nav-group {
    margin-bottom: 0.35rem; /* match the h3 links' spacing so all top-level rows feel evenly spaced */
}

.nav-list {
    list-style: none;
    padding-left: 0.5rem;
    margin: 0.15rem 0 0.5rem 0;
    display: none;
}

.nav-toggle {
    cursor: pointer;
    background: none;
    border: none;
    font-size: 0.95rem;
    font-weight: bold;
    padding: 0.4rem 0.5rem;
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    text-align: left;
    color: var(--brand-brown);
    border-radius: 6px;
    outline: none;
}

.nav-toggle:hover {
    background-color: rgba(90, 57, 23, 0.08);
    text-decoration: none;
    color: var(--brand-brown-dark);
}

.nav-toggle::after {
    content: "▼";
    font-size: 0.7rem;
    color: #9c8567;
    transition: transform 0.2s;
    margin-left: 5px;
}

.nav-toggle.active::after {
    content: "▲";
}

.nav-list li {
    margin-bottom: 0; /* override the site-wide ul/ol li spacing meant for recipe lists */
}

.nav-list a {
    color: var(--brand-brown);
    display: block;
    padding: 0.15rem 0.5rem;
    border-radius: 6px;
    font-size: 0.9rem;
}

.nav-list a:hover {
    background-color: rgba(90, 57, 23, 0.08);
    color: var(--brand-brown-dark);
    text-decoration: none;
}

/* ===== FOOTER STYLES ===== */
footer {
    text-align: center;
    padding: 1rem;
    background-color: #2c3e50;
    color: #fff;
    margin-top: 2rem;
}

/* ===== MOBILE STYLES ===== */
@media (max-width: 767px) {
    .hamburger {
        display: block;
        cursor: pointer;
        padding: 10px;
        background: transparent;
        border-radius: 5px;
        position: absolute;
        top: 4rem;
        right: 1rem;
        z-index: 1001;
    }

    .hamburger div {
        width: 25px;
        height: 3px;
        background-color: #007BFF;
        margin: 5px 0;
    }

    .sidebar {
        display: none;
        position: fixed;
        top: var(--header-height, 4rem); /* starts right where the header ends; JS keeps this in sync with its real height */
        right: 0;
        width: min(78%, 280px);
        height: auto; /* only as tall as its content, not a forced full-screen panel */
        max-height: calc(100vh - var(--header-height, 4rem));
        background-color: var(--sidebar-bg);
        border-radius: 12px 0 0 12px; /* rounded corner now faces left, since the panel is right-aligned */
        z-index: 1000;
        box-shadow: -2px 0 5px rgba(0, 0, 0, 0.1); /* shadow now falls to the left of the panel */
        overflow-y: auto;
        padding: 1rem 0.85rem;
        font-size: 0.95rem;
        transform: translateX(100%); /* slides in from the right instead of the left */
        transition: transform 0.3s ease-in-out;
    }

    .sidebar.active {
        display: block;
        transform: translateX(0);
    }

    main {
        padding: 1rem;
    }

    .header-wrapper {
        flex-direction: column;
        align-items: center;
        padding: 0.5rem 1rem;
        position: relative;
        margin: 0 auto;
    }

    .header-wrapper h1 {
        margin: 0.5rem 0;
    }

    #search-form {
        flex-direction: row;
        justify-content: center;
        align-items: center;
        max-width: 300px;
        margin: 0 auto;
        gap: 0.5rem;
    }

    #search-input {
        height: 2.2rem;
        width: 10rem;
        padding: 0.5rem;
    }

    #search-form button {
        height: 2.2rem;
        background-color: var(--brand-gold);
        width: auto;
        padding: 0 1rem;
        margin-top: 0;
    }

    .recipe-wrapper img {
        float: none;
        width: 100%;
        max-width: 100%;
        margin: 0 0 1rem 0;
    }
}

/* ===== LARGE SCREEN LAYOUT ===== */
@media (min-width: 768px) {
    main {
        display: flex;
        align-items: flex-start; /* stop .sidebar from stretching to match the (often taller) .main-article */
        gap: 2rem;
    }

    .main-article {
        flex: 0 0 70%;
    }

    .sidebar {
        flex: 0 0 30%;
        font-family: "Helvetica", Arial, sans-serif;
        background-color: var(--sidebar-bg);
        border-radius: 8px;
        padding: 1.5rem;
        box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
        position: sticky;
        top: 6rem; /* adjust to match your actual sticky header height */
        max-height: calc(100vh - 8rem);
        overflow-y: auto;
    }
}

/* ===== CATEGORY DESCRIPTION STYLES ===== */

/* Container that holds the collapsible description panel + optional image */
.category-description-container {
    display: flex;
    width: 100%;
    max-width: 100%; /* Ensures it respects the 70% width of .main-article */
    gap: 1rem;
    margin-bottom: 1rem;
    align-items: flex-start;
    box-sizing: border-box; /* Includes padding/border in width calculations */
}

/*
 * The panel is the actual element the JS creates (createCollapsiblePanel()),
 * so its sizing lives here rather than on an unused wrapper class. flex: 1
 * makes it always claim 100% of whatever width the (optional) image doesn't
 * use, so the collapsed preview text no longer determines the panel's width.
 */
.category-description-container .collapsible-panel {
    flex: 1 1 auto;
    min-width: 0; /* allows text to wrap instead of overflowing */
    margin-bottom: 0; /* the container already has margin-bottom */
}

/* Image container - fixed max width on desktop, hidden on mobile */
.category-description-image {
    display: none; /* Hidden on mobile */
    flex: 0 0 auto;
    max-width: 35%;
    height: auto;
    object-fit: contain; /* Ensures the image scales proportionally */
    border-radius: 8px;
    align-self: flex-start;
    box-sizing: border-box;
}

/* Desktop layout (≥768px) */
@media (min-width: 768px) {
    .category-description-container {
        flex-wrap: nowrap; /* Force text and image to stay on the same line */
    }

    .category-description-image {
        display: block; /* Show image on desktop */
    }
}

/* Download button style */
.download-button {
    display: block;
    margin: 0 auto;
    padding: 15px 30px;
    font-size: 24px;
    background-color: var(--brand-brown);
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
}

.download-button:hover {
    background-color: var(--brand-brown-dark);
}


/* ===== SHOPPING MODAL STYLES ===== */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000; /* Higher than header (100) and sidebar (1000) */
}

.modal-content {
    background-color: #fff;
    padding: 1.5rem;
    border-radius: 8px;
    max-width: 500px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    border: 1px solid #eee;
}

.modal-content h2 {
    color: var(--brand-brown);
    margin-top: 0;
    font-family: "Georgia", "Times New Roman", serif;
}

#shopping-list {
    list-style: none;
    padding: 0;
    margin: 1rem 0;
}

#shopping-list li {
    margin: 0.5rem 0;
    padding: 0.5rem;
    border-bottom: 1px solid #eee;
}

#shopping-list li:last-child {
    border-bottom: none;
}

#shopping-list input[type="checkbox"] {
    margin-right: 10px;
}

.modal-buttons {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 1.5rem;
}

/* Modal buttons match your share-button style */
.modal-button {
    background: var(--brand-brown);
    color: white;
    border: none;
    padding: 8px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    flex-shrink: 0;
}

.modal-button:hover {
    background: var(--brand-brown-dark);
}

/* Responsive adjustments */
@media (max-width: 767px) {
    .modal-content {
        width: 95%;
        padding: 1rem;
    }
}


/* Shopping modal - same cream color as the Copy confirmation popup */
#shopping-modal .modal-content {
    background-color: #fff8f0;
    border-top: 4px solid var(--brand-brown);
}

/* Custom alert specific styles */
#custom-alert-modal .modal-content {
    background-color: #fff8f0;
    border-top: 4px solid var(--brand-brown);
    text-align: center;
}

#custom-alert-message {
    color: var(--brand-brown);
    font-size: 16px;
    margin-bottom: 1rem;
}

#custom-alert-ok {
    background: var(--brand-brown);
    color: white;
    margin: 0 auto; /* Center the button */
}


/* PIN Modal specific styles */
#pin-modal .modal-content {
    background-color: #fff8f0;
    border-top: 4px solid var(--brand-brown);
    text-align: center;
    max-width: 400px;
}

#pin-modal h2 {
    color: var(--brand-brown);
    margin-bottom: 0.5rem;
}

#pin-modal p {
    color: var(--brand-brown);
    font-size: 14px;
    margin-bottom: 1rem;
    font-style: italic;
}

#pin-input {
    width: 100%;
    padding: 8px;
    margin: 10px 0;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 14px;
}

#pin-modal .modal-buttons {
    justify-content: center;
    gap: 20px;
}

/* Related Recipes Section */
.related-recipes {
    margin-top: 2rem;
    text-align: center;
}

.related-recipes-list {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 1rem;
    margin-top: 1rem;
}

.related-recipe {
    display: flex;
    flex-direction: column;
    align-items: center;
    max-width: 250px;
    margin: 0.5rem;
}

.related-recipe img {
    width: 250px;
    height: 250px;
    object-fit: cover;
    border-radius: 8px;
    display: block;
}

.related-recipe p {
    margin-top: 0.5rem;
    text-align: center;
    word-break: break-word;
}

/* Large screens: 2 columns */
@media (min-width: 768px) {
    .related-recipes-list {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 1rem;
        justify-content: center;
    }

    .related-recipe {
        margin: 0;
        text-align: center;
        max-width: 384px; /* Larger container for large screens */
    }

    .related-recipe img {
        width: 346px; /* Larger image width for large screens */
        height: 346px; /* Larger image height for large screens */
    }
}

/* ===== BASICS HUB ===== */
.basics-hub {
    margin-bottom: 1.5rem;
}

.basics-hub-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
}

.basics-hub-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    min-width: 0;
}

.basics-hub-item img {
    width: 100%;
    aspect-ratio: 1 / 1;
    object-fit: cover;
    border-radius: 8px;
    display: block;
    cursor: pointer;
}

/* Only the width differs from the base .category-button rule */
.basics-hub-item .category-button {
    width: 100%;
}

#basics-recipes {
    margin-top: 1rem;
}

/* Mobile: 2x2 grid */
@media (max-width: 767px) {
    .basics-hub-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    /* Once a sub-category is selected, only its picture/button remains,
       shown as a single full-width item */
    .basics-hub.hub-focused .basics-hub-grid {
        grid-template-columns: 1fr;
    }

    .basics-hub-item.hub-item-hidden {
        display: none;
    }
}

/* ===== DRINKS HUB ===== */
.drinks-hub {
    margin-bottom: 1.5rem;
}

.drinks-hub-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
}

.drinks-hub-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    min-width: 0;
}

.drinks-hub-item img {
    width: 100%;
    aspect-ratio: 1 / 1;
    object-fit: cover;
    border-radius: 8px;
    display: block;
    cursor: pointer;
}

.drinks-hub-item .category-button {
    width: 100%;
}

#drinks-recipes {
    margin-top: 1rem;
}

/* Mobile: stack to a single column so 3 items stay readable */
@media (max-width: 767px) {
    .drinks-hub-grid {
        grid-template-columns: 1fr;
    }

    /* Once a sub-category is selected, only its picture/button remains */
    .drinks-hub-item.hub-item-hidden {
        display: none;
    }
}

/* ===== COLLAPSIBLE PANELS ===== */
.collapsible-panel {
    margin-bottom: 1rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    overflow: hidden;
}

.collapsible-header {
    padding: 0.5rem;
    background-color: #eee6da;
    cursor: pointer;
    transition: all 0.3s ease;
}

.collapsible-header:hover {
    background-color: #e0e0e0;
}

.collapsible-content {
    padding: 0.5rem;
    background-color: #eee6da;
    border-top: 1px solid #ddd;
    transition: all 0.3s ease;
}

.collapsible-header a {
    color: inherit;
    text-decoration: underline;
    cursor: pointer;
}

.collapsible-header br {
    display: inline; /* Ensure <br> tags work in the preview */
}