/* ============================================================
   FoodScore.fr — CSS Principal
   ============================================================ */

/* --- CSS Custom Properties --- */
:root {
    /* Nutri-Score (couleurs officielles) */
    --ns-a: #038141;
    --ns-b: #85BB2F;
    --ns-c: #FECB02;
    --ns-d: #EE8100;
    --ns-e: #E63E11;

    /* NOVA */
    --nova-1: #038141;
    --nova-2: #85BB2F;
    --nova-3: #EE8100;
    --nova-4: #E63E11;

    /* Éco-Score */
    --eco-a: #1E8F4E;
    --eco-b: #60AC0E;
    --eco-c: #FECB02;
    --eco-d: #EF7F1A;
    --eco-e: #E63E11;

    /* Risque additifs */
    --risk-safe: #038141;
    --risk-limited: #85BB2F;
    --risk-caution: #EE8100;
    --risk-avoid: #E63E11;

    /* Identité */
    --primary: #01696F;
    --primary-light: #028A92;
    --primary-dark: #014E53;
    --accent: #2ECC71;

    /* Surfaces */
    --bg: #FFFFFF;
    --bg-alt: #F8F9FA;
    --bg-card: #FFFFFF;
    --surface: #FFFFFF;
    --border: rgba(0,0,0,0.08);
    --shadow: 0 1px 3px rgba(0,0,0,0.08);
    --shadow-lg: 0 4px 12px rgba(0,0,0,0.1);

    /* Texte */
    --text: #1A1A2E;
    --text-secondary: #4A5568;
    --text-muted: #6B7280;
    --text-inverse: #FFFFFF;

    /* Typographie */
    --font-heading: 'Instrument Serif', Georgia, serif;
    --font-body: 'Satoshi', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', monospace;

    /* Spacing */
    --space-xs: 0.25rem;
    --space-sm: 0.5rem;
    --space-md: 1rem;
    --space-lg: 1.5rem;
    --space-xl: 2rem;
    --space-2xl: 3rem;
    --space-3xl: 4rem;

    /* Layout */
    --container-max: 1200px;
    --radius: 8px;
    --radius-sm: 4px;
    --radius-lg: 12px;
    --radius-full: 9999px;
}

/* --- Dark Mode --- */
[data-theme="dark"] {
    --bg: #0F172A;
    --bg-alt: #1E293B;
    --bg-card: #1E293B;
    --surface: #1E293B;
    --border: rgba(255,255,255,0.08);
    --shadow: 0 1px 3px rgba(0,0,0,0.3);
    --shadow-lg: 0 4px 12px rgba(0,0,0,0.4);
    --text: #E2E8F0;
    --text-secondary: #CBD5E1;
    --text-muted: #94A3B8;
    --text-inverse: #0F172A;
}

/* --- Reset & Base --- */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: var(--font-body);
    color: var(--text);
    background: var(--bg);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

img {
    max-width: 100%;
    height: auto;
    display: block;
}

a {
    color: var(--primary);
    text-decoration: none;
}
a:hover {
    text-decoration: underline;
}

table {
    border-collapse: collapse;
    width: 100%;
}

/* --- Typographie --- */
h1, h2, h3, h4 {
    font-family: var(--font-heading);
    color: var(--text);
    line-height: 1.2;
}

h1 { font-size: 2rem; margin-bottom: var(--space-lg); }
h2 { font-size: 1.5rem; margin-bottom: var(--space-md); margin-top: var(--space-2xl); }
h3 { font-size: 1.25rem; margin-bottom: var(--space-sm); margin-top: var(--space-xl); }
h4 { font-size: 1.1rem; margin-bottom: var(--space-sm); margin-top: var(--space-lg); }

p { margin-bottom: var(--space-md); }

/* --- Layout --- */
.container {
    max-width: var(--container-max);
    margin: 0 auto;
    padding: 0 var(--space-lg);
}

.grid-2 {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-lg);
}

.grid-3 {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: var(--space-lg);
}

.grid-4 {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: var(--space-lg);
}

.flex { display: flex; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-sm { gap: var(--space-sm); }
.gap-md { gap: var(--space-md); }
.gap-lg { gap: var(--space-lg); }

/* --- Header / Navigation --- */
.site-header {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: var(--space-md) 0;
    position: sticky;
    top: 0;
    z-index: 100;
}

.site-header .container {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.site-logo {
    font-family: var(--font-heading);
    font-size: 1.5rem;
    color: var(--primary);
    font-weight: 700;
    text-decoration: none;
}
.site-logo:hover {
    text-decoration: none;
    color: var(--primary-light);
}

.site-nav {
    display: flex;
    align-items: center;
    gap: var(--space-lg);
}

.site-nav a {
    color: var(--text-secondary);
    font-size: 0.9rem;
    font-weight: 500;
    transition: color 0.15s;
}
.site-nav a:hover {
    color: var(--primary);
    text-decoration: none;
}

.nav-search {
    position: relative;
}

.nav-search input {
    border: 1px solid var(--border);
    border-radius: var(--radius-full);
    padding: 0.5rem 1rem 0.5rem 2.5rem;
    font-size: 0.875rem;
    background: var(--bg-alt);
    color: var(--text);
    width: 240px;
    transition: border-color 0.15s, width 0.2s;
}
.nav-search input:focus {
    outline: none;
    border-color: var(--primary);
    width: 320px;
}

.nav-search::before {
    content: '🔍';
    position: absolute;
    left: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.8rem;
    pointer-events: none;
}

/* Dark mode toggle */
.theme-toggle {
    background: none;
    border: 1px solid var(--border);
    border-radius: var(--radius-full);
    padding: 0.4rem 0.6rem;
    cursor: pointer;
    font-size: 1rem;
    color: var(--text-muted);
    transition: background 0.15s;
}
.theme-toggle:hover {
    background: var(--bg-alt);
}

/* --- Main content --- */
main {
    min-height: calc(100vh - 160px);
    padding: var(--space-xl) 0 var(--space-3xl);
}

/* --- Breadcrumb --- */
.breadcrumb {
    display: flex;
    align-items: center;
    gap: var(--space-xs);
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: var(--space-xl);
    flex-wrap: wrap;
}

.breadcrumb a {
    color: var(--text-muted);
}
.breadcrumb a:hover {
    color: var(--primary);
}

.breadcrumb .separator {
    margin: 0 0.25rem;
}

/* --- Cards --- */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: var(--space-lg);
    box-shadow: var(--shadow);
    transition: box-shadow 0.2s;
}

.card:hover {
    box-shadow: var(--shadow-lg);
}

/* --- Nutri-Score Badge --- */
.nutriscore {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    font-weight: 700;
    font-size: 0.75rem;
}

.nutriscore .ns-letter {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: var(--radius-sm);
    color: white;
    font-size: 0.85rem;
    opacity: 0.35;
    transition: transform 0.15s, opacity 0.15s;
}

.nutriscore .ns-letter.active {
    opacity: 1;
    transform: scale(1.25);
    border-radius: var(--radius);
    box-shadow: 0 2px 6px rgba(0,0,0,0.2);
}

.nutriscore .ns-a { background: var(--ns-a); }
.nutriscore .ns-b { background: var(--ns-b); }
.nutriscore .ns-c { background: var(--ns-c); color: #333; }
.nutriscore .ns-d { background: var(--ns-d); }
.nutriscore .ns-e { background: var(--ns-e); }

/* --- Nutri-Score Badge Large (pour fiches produit) --- */
.nutriscore-lg .ns-letter {
    width: 40px;
    height: 40px;
    font-size: 1.1rem;
}

/* --- NOVA Badge --- */
.nova-badge {
    display: inline-flex;
    align-items: center;
    gap: var(--space-xs);
    padding: 0.25rem 0.75rem;
    border-radius: var(--radius-full);
    font-size: 0.8rem;
    font-weight: 600;
    color: white;
}

.nova-1 { background: var(--nova-1); }
.nova-2 { background: var(--nova-2); }
.nova-3 { background: var(--nova-3); }
.nova-4 { background: var(--nova-4); }

/* --- Scores rapides (above the fold) --- */
.scores-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: var(--space-md);
    margin-bottom: var(--space-2xl);
}

.score-card {
    background: var(--bg-alt);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: var(--space-md);
    text-align: center;
}

.score-card .score-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: var(--space-xs);
}

.score-card .score-value {
    font-size: 1.5rem;
    font-weight: 700;
    font-family: var(--font-heading);
}

/* --- Tableau nutritionnel --- */
.nutrition-table {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    margin-bottom: var(--space-xl);
}

.nutrition-table thead {
    background: var(--bg-alt);
}

.nutrition-table th,
.nutrition-table td {
    padding: 0.6rem 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
    font-size: 0.9rem;
}

.nutrition-table th {
    font-weight: 600;
    font-size: 0.8rem;
    text-transform: uppercase;
    color: var(--text-muted);
}

.nutrition-table tr:last-child td {
    border-bottom: none;
}

.nutrition-table .indent {
    padding-left: 2rem;
    color: var(--text-secondary);
}

/* --- Barre nutriment (avec seuil OMS) --- */
.nutrient-bar {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    margin-bottom: var(--space-sm);
}

.nutrient-bar .bar-label {
    width: 100px;
    font-size: 0.8rem;
    color: var(--text-secondary);
    flex-shrink: 0;
}

.nutrient-bar .bar-track {
    flex: 1;
    height: 8px;
    background: var(--bg-alt);
    border-radius: var(--radius-full);
    position: relative;
    overflow: hidden;
}

.nutrient-bar .bar-fill {
    height: 100%;
    border-radius: var(--radius-full);
    transition: width 0.5s ease;
}

.nutrient-bar .bar-value {
    width: 60px;
    text-align: right;
    font-size: 0.85rem;
    font-weight: 600;
    flex-shrink: 0;
}

/* --- Pastille additif --- */
.additive-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.2rem 0.6rem;
    border-radius: var(--radius-full);
    font-size: 0.75rem;
    font-weight: 600;
    cursor: help;
    transition: transform 0.1s;
    border: 1px solid transparent;
}
.additive-pill:hover {
    transform: scale(1.05);
}

.additive-pill.safe { background: #e8f5e9; color: #2e7d32; border-color: #c8e6c9; }
.additive-pill.limited { background: #fff3e0; color: #ef6c00; border-color: #ffe0b2; }
.additive-pill.caution { background: #fff3e0; color: #e65100; border-color: #ffcc80; }
.additive-pill.avoid { background: #ffebee; color: #c62828; border-color: #ffcdd2; }

[data-theme="dark"] .additive-pill.safe { background: #1b5e20; color: #a5d6a7; border-color: #2e7d32; }
[data-theme="dark"] .additive-pill.limited { background: #e65100; color: #ffe0b2; border-color: #ef6c00; }
[data-theme="dark"] .additive-pill.caution { background: #bf360c; color: #ffcc80; border-color: #e65100; }
[data-theme="dark"] .additive-pill.avoid { background: #b71c1c; color: #ffcdd2; border-color: #c62828; }

/* --- Labels (badges) --- */
.label-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.25rem 0.65rem;
    border-radius: var(--radius-full);
    font-size: 0.75rem;
    font-weight: 500;
    background: var(--bg-alt);
    border: 1px solid var(--border);
    color: var(--text-secondary);
}

.label-badge.bio { border-color: #4caf50; color: #2e7d32; }
.label-badge.vegan { border-color: #66bb6a; color: #388e3c; }

/* --- Product Card (réutilisable) --- */
.product-card {
    display: flex;
    gap: var(--space-md);
    padding: var(--space-md);
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    transition: box-shadow 0.2s;
    text-decoration: none;
    color: inherit;
}

.product-card:hover {
    box-shadow: var(--shadow-lg);
    text-decoration: none;
}

.product-card img {
    width: 80px;
    height: 80px;
    object-fit: contain;
    border-radius: var(--radius-sm);
    flex-shrink: 0;
}

.product-card .pc-info {
    flex: 1;
    min-width: 0;
}

.product-card .pc-name {
    font-weight: 600;
    font-size: 0.9rem;
    margin-bottom: 0.2rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.product-card .pc-brand {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: var(--space-xs);
}

.product-card .pc-meta {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    font-size: 0.8rem;
}

/* --- Pagination --- */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-xs);
    margin-top: var(--space-2xl);
}

.pagination a, .pagination span {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 36px;
    height: 36px;
    padding: 0 0.5rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.85rem;
    color: var(--text-secondary);
    transition: all 0.15s;
}

.pagination a:hover {
    border-color: var(--primary);
    color: var(--primary);
    text-decoration: none;
}

.pagination .current {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

/* --- FAQ Section --- */
.faq-section {
    margin-top: var(--space-2xl);
}

.faq-item {
    border-bottom: 1px solid var(--border);
    padding: var(--space-md) 0;
}

.faq-item summary {
    font-weight: 600;
    font-size: 0.95rem;
    cursor: pointer;
    list-style: none;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.faq-item summary::after {
    content: '+';
    font-size: 1.2rem;
    color: var(--text-muted);
    transition: transform 0.2s;
}

.faq-item[open] summary::after {
    transform: rotate(45deg);
}

.faq-item .faq-answer {
    padding-top: var(--space-sm);
    font-size: 0.9rem;
    color: var(--text-secondary);
    line-height: 1.7;
}

/* --- Footer --- */
.site-footer {
    background: var(--bg-alt);
    border-top: 1px solid var(--border);
    padding: var(--space-2xl) 0 var(--space-xl);
    font-size: 0.85rem;
    color: var(--text-muted);
}

.footer-grid {
    display: grid;
    grid-template-columns: 2fr 1fr 1fr 1fr;
    gap: var(--space-2xl);
    margin-bottom: var(--space-2xl);
}

.footer-col h4 {
    font-family: var(--font-body);
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text);
    margin-bottom: var(--space-md);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.footer-col a {
    display: block;
    color: var(--text-muted);
    margin-bottom: var(--space-sm);
    font-size: 0.85rem;
}
.footer-col a:hover {
    color: var(--primary);
}

.footer-bottom {
    border-top: 1px solid var(--border);
    padding-top: var(--space-lg);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.footer-bottom .attribution {
    font-size: 0.75rem;
}

/* --- KPI Cards (pages marque/catégorie) --- */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: var(--space-md);
    margin-bottom: var(--space-2xl);
}

.kpi-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: var(--space-lg);
    text-align: center;
}

.kpi-card .kpi-value {
    font-size: 2rem;
    font-weight: 700;
    font-family: var(--font-heading);
    color: var(--primary);
}

.kpi-card .kpi-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-top: var(--space-xs);
}

/* --- Comparison Table --- */
.comparison-table {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.comparison-table th,
.comparison-table td {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border);
}

.comparison-table th {
    background: var(--bg-alt);
    font-weight: 600;
    text-align: center;
}

.comparison-table th:first-child {
    text-align: left;
}

.comparison-table .winner,
.winner {
    background: rgba(3, 129, 65, 0.08);
    font-weight: 600;
}

.loser {
    color: var(--text-muted);
}

/* --- Search Dropdown (autocomplete) --- */
.search-dropdown a:hover,
.search-result-item:hover {
    background: var(--bg-alt) !important;
}

.search-dropdown a:last-child {
    border-bottom: none !important;
}

/* --- Responsive --- */
@media (max-width: 768px) {
    h1 { font-size: 1.5rem; }
    h2 { font-size: 1.25rem; }

    .container { padding: 0 var(--space-md); }

    .grid-2, .grid-3, .grid-4 {
        grid-template-columns: 1fr;
    }

    .footer-grid {
        grid-template-columns: 1fr 1fr;
    }

    .site-nav {
        display: none; /* Menu hamburger en Phase 6 */
    }

    .nav-search input {
        width: 160px;
    }
    .nav-search input:focus {
        width: 200px;
    }

    .scores-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .kpi-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .comparison-table {
        font-size: 0.8rem;
    }

    .footer-bottom {
        flex-direction: column;
        gap: var(--space-sm);
        text-align: center;
    }
}

@media (max-width: 480px) {
    .scores-grid {
        grid-template-columns: 1fr 1fr;
    }

    .footer-grid {
        grid-template-columns: 1fr;
    }
}
