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

[hidden] {
    display: none !important;
}

:root {
    --brand: #1a1a1a;
    --bg: #ffffff;
    --text: #1a1a1a;
    --text-muted: #6b7280;
    --border: #e5e7eb;
    --surface: #f9fafb;
    --radius: 12px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    color: var(--text);
    background: var(--bg);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

/* Page container - boxed on tablet/desktop */
#product {
    max-width: 100%;
    margin: 0 auto;
}

#app {
    max-width: 100%;
    margin: 0 auto;
}

/* Loading */
.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 60vh;
}

.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--border);
    border-top-color: var(--brand);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

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

/* Error */
.error-page {
    text-align: center;
    padding: 80px 24px;
}

.error-page h1 {
    font-size: 20px;
    margin-bottom: 8px;
}

.error-page p {
    color: var(--text-muted);
    font-size: 15px;
}

/* Brand bar */
.brand-bar {
    height: 6px;
    background: var(--brand);
}

/* Hero image */
.hero {
    display: none;
    position: relative;
    overflow: hidden;
    aspect-ratio: 4 / 3;
    background: var(--surface);
}

.hero.has-image {
    display: block;
}

.hero-img {
    position: absolute;
    top: -10%;
    left: 50%;
    width: 100%;
    height: 120%;
    object-fit: cover;
    object-position: center center;
    display: block;
    will-change: transform;
    transform: translate(-50%, 0);
    transition: none;
}

/* Content */
.content {
    padding: 24px 20px 40px;
    max-width: 640px;
    margin: 0 auto;
}

.product-title {
    font-size: 24px;
    font-weight: 700;
    line-height: 1.3;
    margin-bottom: 8px;
}

.product-description {
    color: var(--text-muted);
    font-size: 15px;
    margin-bottom: 16px;
    white-space: pre-line;
}

/* Meta badges */
.meta {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 28px;
}

.meta-badge {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 500;
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text-muted);
}

.meta-badge.nutriscore {
    font-weight: 700;
    text-transform: uppercase;
}

/* Sections */
.section {
    margin-bottom: 32px;
}

.section-title {
    font-size: 16px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 2px solid var(--border);
}

/* Ingredients */
.ingredients-list {
    list-style: none;
}

.ingredients-list li {
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    font-size: 15px;
}

.ingredients-list li:last-child {
    border-bottom: none;
}

.ingredient-name {
    flex: 1;
    margin-right: 12px;
}

.ingredient-amount {
    color: var(--text-muted);
    white-space: nowrap;
    font-size: 14px;
}

/* Nutrition tabs */
.nutrition-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
    overflow-x: auto;
}

.nutrition-tab {
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 500;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text-muted);
    cursor: pointer;
    white-space: nowrap;
}

.nutrition-tab.active {
    background: var(--brand);
    color: #fff;
    border-color: var(--brand);
}

/* Nutrition table */
.nutrition-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.nutrition-table th {
    text-align: left;
    font-weight: 600;
    padding: 10px 8px;
    background: var(--surface);
    border-bottom: 2px solid var(--border);
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.02em;
    color: var(--text-muted);
}

.nutrition-table th:not(:first-child) {
    text-align: right;
}

.nutrition-table td {
    padding: 8px;
    border-bottom: 1px solid var(--border);
}

.nutrition-table td:not(:first-child) {
    text-align: right;
    white-space: nowrap;
    color: var(--text-muted);
}

.nutrition-table tr.energy-row td {
    font-weight: 600;
}

/* Gallery */
.gallery {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
}

.gallery img {
    width: 100%;
    aspect-ratio: 1;
    object-fit: cover;
    border-radius: var(--radius);
    border: 1px solid var(--border);
}

/* Footer */
.footer {
    text-align: center;
    padding: 24px 20px;
    color: var(--text-muted);
    font-size: 13px;
    border-top: 1px solid var(--border);
}

/* Lightbox */
.lightbox-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    padding: 20px;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.25s ease, visibility 0.25s ease;
}

.lightbox-overlay.is-open {
    opacity: 1;
    visibility: visible;
}

.lightbox-img {
    max-width: min(90vw, 1200px);
    max-height: 85vh;
    object-fit: contain;
    border-radius: 8px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
    transform: scale(0.95);
    transition: transform 0.25s ease;
}

.lightbox-overlay.is-open .lightbox-img {
    transform: scale(1);
}

.lightbox-close {
    position: absolute;
    top: 16px;
    right: 16px;
    width: 40px;
    height: 40px;
    border: 0;
    background: rgba(255, 255, 255, 0.9);
    color: #111;
    border-radius: 50%;
    font-size: 22px;
    line-height: 40px;
    text-align: center;
    cursor: pointer;
}

/* Tablet */
@media (min-width: 768px) {
    body {
        background: #f0f1f3;
        padding: 32px 20px;
    }

    #product {
        max-width: 720px;
        background: var(--bg);
        border-radius: var(--radius);
        box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 8px 24px rgba(0, 0, 0, 0.06);
        overflow: hidden;
    }

    .brand-bar {
        border-radius: var(--radius) var(--radius) 0 0;
    }

    .hero {
        aspect-ratio: 4 / 3;
    }

    .content {
        padding: 32px 36px 48px;
        max-width: none;
    }

    .product-title {
        font-size: 28px;
    }

    .footer {
        border-radius: 0 0 var(--radius) var(--radius);
    }

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

/* Desktop */
@media (min-width: 1024px) {
    body {
        padding: 48px 20px;
    }

    #product {
        max-width: 800px;
    }

    .hero {
        aspect-ratio: 16 / 9;
        max-height: 450px;
    }

    .content {
        padding: 40px 48px 60px;
    }

    .product-title {
        font-size: 32px;
    }
}
