/* ==========================================================================
   CSS Layer 3: Layout (Container, Navbar, Footer, Responsive Shell)
   โครงสร้างเลย์เอาต์หลัก แถบเมนูนำทาง และส่วนท้ายหน้า
   ========================================================================== */

.container {
    max-width: 960px;
    margin: 0 auto;
    padding: 1rem;
    border: 2px solid var(--primary-color);
    border-radius: var(--radius-lg);
    box-shadow: 0 6px 14px rgba(0, 0, 0, 0.12);
    background-color: rgba(250, 248, 240, 0.85);
    background-size: cover;
    background-position: center;
}

body.view-table .container {
    max-width: 1400px;
}

/* เลเยอร์ป้องกันและ Readability Layer สำหรับ View หลัก */
#home-view,
#detail-view {
    position: relative;
    overflow: hidden;
    border: 1px solid var(--secondary-color);
    border-radius: 8px;
    padding: 1rem;
    margin-top: 0.5rem;
}

#home-view::before,
#detail-view::before {
    content: "";
    position: absolute;
    inset: 0;
    background-color: rgba(255, 255, 255, 0.80);
    backdrop-filter: blur(3px);
    z-index: 0;
    pointer-events: none;
    border-radius: inherit;
}

#home-view > *,
#detail-view > * {
    position: relative;
    z-index: 1;
}

/* ===== Navbar ===== */
.navbar {
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--primary-color);
    color: #fff;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    border-radius: 8px;
    margin-bottom: 0.5rem;
}

.nav-inner {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    min-height: 3.5rem;
}

.nav-brand {
    color: #fff;
    text-decoration: none;
    font-weight: 700;
    font-size: 1.1rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
}

.nav-links {
    display: flex;
    gap: 0.25rem;
    align-items: stretch;
    flex: 1 1 auto;
    min-width: 0;
    flex-wrap: wrap;
    justify-content: flex-end;
    padding: 0.15rem 0;
}

.nav-link {
    color: rgba(255, 255, 255, 0.9);
    text-decoration: none;
    padding: 0.5rem 0.9rem;
    border-radius: 8px;
    font-size: 1rem;
    white-space: nowrap;
    border-bottom: 3px solid transparent;
    flex-shrink: 0;
}

.nav-link:hover {
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
}

.nav-link.active {
    background: rgba(255, 255, 255, 0.2);
    color: #fff;
    font-weight: 700;
    border-bottom-color: var(--accent-gold);
}

.nav-link:focus-visible,
.nav-brand:focus-visible {
    outline: 3px solid var(--accent-gold);
    outline-offset: 2px;
}

.nav-toggle,
.nav-current {
    display: none;
}

#view-toggle,
#stats-area,
#taste-list-anchor {
    scroll-margin-top: 4.5rem;
}

/* Footer */
footer {
    background: #eceae1;
    padding: 1.2rem;
    text-align: center;
    font-size: 0.85rem;
    margin-top: 3rem;
    border-top: 1px solid var(--border-color);
    border-radius: 0 0 8px 8px;
}

/* ===== Responsive Navbar & Safe Areas ===== */
@media (max-width: 820px) {
    .navbar {
        padding-top: env(safe-area-inset-top);
    }

    .nav-inner {
        flex-wrap: nowrap;
        padding: 0 0.75rem;
        position: relative;
        gap: 0.5rem;
        min-height: 3.25rem;
        justify-content: flex-start;
    }

    .nav-brand {
        flex: 0 1 auto;
        min-width: 0;
    }

    .nav-brand-text {
        display: inline !important;
    }

    .nav-current {
        display: block;
        flex: 1 1 auto;
        min-width: 0;
        text-align: right;
        font-size: 0.9rem;
        color: var(--accent-gold);
        font-weight: 600;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .nav-toggle {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        flex: 0 0 auto;
        width: 44px;
        height: 44px;
        margin-right: -0.4rem;
        background: transparent;
        border: 0;
        border-radius: 10px;
        cursor: pointer;
        -webkit-tap-highlight-color: transparent;
    }

    .nav-toggle:hover,
    .navbar.open .nav-toggle {
        background: rgba(255, 255, 255, 0.15);
    }

    .nav-toggle:focus-visible {
        outline: 3px solid var(--accent-gold);
        outline-offset: 1px;
    }

    .nav-bars {
        position: relative;
        width: 22px;
        height: 16px;
        display: block;
    }

    .nav-bars i {
        position: absolute;
        left: 0;
        width: 22px;
        height: 2.5px;
        background: #fff;
        border-radius: 2px;
        transition: transform 0.2s, opacity 0.2s, top 0.2s;
    }

    .nav-bars i:nth-child(1) { top: 0; }
    .nav-bars i:nth-child(2) { top: 6.7px; }
    .nav-bars i:nth-child(3) { top: 13.5px; }

    .navbar.open .nav-bars i:nth-child(1) { top: 6.7px; transform: rotate(45deg); }
    .navbar.open .nav-bars i:nth-child(2) { opacity: 0; }
    .navbar.open .nav-bars i:nth-child(3) { top: 6.7px; transform: rotate(-45deg); }

    .nav-links {
        display: none;
        position: absolute;
        top: 100%;
        left: 0;
        right: 0;
        flex-direction: column;
        flex-wrap: nowrap;
        gap: 0;
        padding: 0.4rem 0.6rem 0.7rem;
        background: var(--primary-color);
        border-radius: 0 0 14px 14px;
        box-shadow: 0 10px 24px rgba(0, 0, 0, 0.28);
        max-height: calc(100vh - 4rem);
        overflow-y: auto;
    }

    .navbar.open .nav-links {
        display: flex;
    }

    .nav-link {
        display: flex;
        align-items: center;
        min-height: 46px;
        padding: 0.5rem 0.9rem;
        font-size: 1.05rem;
        border-bottom: 0;
        border-left: 4px solid transparent;
        border-radius: 10px;
    }

    .nav-link.active {
        border-left-color: var(--accent-gold);
        border-bottom-color: transparent;
    }

    .container {
        padding-left: max(0.75rem, env(safe-area-inset-left));
        padding-right: max(0.75rem, env(safe-area-inset-right));
        padding-bottom: calc(1rem + env(safe-area-inset-bottom));
    }

    .pg-pill,
    .si-clear {
        min-height: 36px;
    }

    .pg-input,
    .search-input,
    .lp-search-input {
        font-size: 16px;
    }
}

@media (max-width: 380px) {
    .nav-brand-text {
        font-size: 1rem;
    }
}

@media screen and (max-width: 375px) {
    body {
        font-size: 16px;
    }

    .container {
        padding: 0.8rem;
    }
}
