:root {
    --bg-color: #f4f7f6;
    --card-bg: #ffffff;
    --text-main: #2d3436;
    --text-light: #636e72;
    --primary: #00b894; /* Soothing Green */
    --secondary: #0984e3;
    --accent: #fdcb6e;
    --danger: #d63031;
    --radius: 16px;
    --shadow: 0 10px 20px rgba(0,0,0,0.05);
    --font-main: 'Inter', -apple-system, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
body {
    margin: 0;
    padding: 0;
    font-family: var(--font-main);
    /* Image de fond globale (Style Cuisine/Marbre) */
    background: url('https://images.unsplash.com/photo-1495195134817-aeb325a55b65?q=80&w=1920&auto=format&fit=crop') fixed;
    background-size: cover;
    background-position: center;
    color: var(--text-main);
    height: 100vh;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* --- UTILS --- */
.hidden { display: none !important; }
.btn {
    border: none;
    padding: 15px 24px; /* Increased padding */
    margin-top: 25px;   /* Increased margin top */
    border-radius: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.1s;
    font-size: 1rem;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    justify-content: center;
}
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--primary); color: white; }
.btn-secondary { background: #dfe6e9; color: var(--text-main); }
.btn-danger { background: var(--danger); color: white; }
.btn-ghost { background: transparent; color: var(--text-light); padding: 12px 24px; } /* Removed margin-top: 0 override */
.btn-lg { padding: 16px 32px; font-size: 1.2rem; width: 100%; }

/* --- VIEWS --- */
.view {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: none;
    flex-direction: column;
    /* Effet "Verre" pour lire le texte sur le fond */
    background: rgba(244, 247, 246, 0.85);
    backdrop-filter: blur(8px);
}
.view.active { display: flex; }

/* --- AUTH VIEW --- */
#auth-view {
    justify-content: center;
    align-items: center;
    text-align: center;
    width: 100%;
    height: 100vh;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    /* Image de fond temporaire (à remplacer par votre génération IA) */
    background: linear-gradient(rgba(0, 0, 0, 0.4), rgba(0, 0, 0, 0.4)), url('https://images.unsplash.com/photo-1495521821757-a1efb6729352?q=80&w=1920&auto=format&fit=crop');
    background-size: cover;
    background-position: center;
    z-index: 9999;
    padding: 20px;
    backdrop-filter: none; /* Pas de flou sur le fond Auth */
}

#auth-view.hidden {
    display: none !important;
}

#auth-forms {
    max-width: 400px;
    margin: 0 auto;
    background: rgba(255, 255, 255, 0.95); /* Légère transparence */
    padding: 30px;
    border-radius: 24px;
    box-shadow: 0 20px 40px rgba(0,0,0,0.2);
    width: 100%;
    backdrop-filter: blur(10px);
}

#auth-forms h1 {
    margin-bottom: 10px;
    color: var(--primary);
}

#auth-forms p {
    color: var(--text-light);
    margin-bottom: 30px;
}

/* --- SETUP WIZARD --- */
#setup-view {
    display: none; /* Hidden by default */
    justify-content: center;
    align-items: center;
    text-align: center;
    max-width: 100%; /* Full width for background */
    margin: 0;
    
    /* Fond spécifique pour le Setup (Style Dark Food) */
    background: linear-gradient(rgba(0, 0, 0, 0.7), rgba(0, 0, 0, 0.7)), url('https://images.unsplash.com/photo-1506368249639-73a05d6f6488?q=80&w=1920&auto=format&fit=crop');
    background-size: cover;
    background-position: center;
    color: white;
    backdrop-filter: none;
}
#setup-view h1, #setup-view h2, #setup-view p {
    color: white;
    text-shadow: 0 2px 10px rgba(0,0,0,0.5);
}
#setup-view .day-label {
    background: rgba(255, 255, 255, 0.2);
    color: white;
    backdrop-filter: blur(4px);
    border: 1px solid rgba(255,255,255,0.3);
}
#setup-view .day-checkbox:checked + .day-label {
    background: var(--primary);
    border-color: var(--primary);
}

#setup-view.active {
    display: flex;
}
.setup-step { display: none; animation: fadeIn 0.3s; width: 100%; max-width: 600px; margin: 0 auto; }
.setup-step.active { display: block; }
.day-selector {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: center;
    margin: 20px 0;
}
.day-checkbox {
    display: none;
}
.day-label {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: #dfe6e9;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s;
}
.day-checkbox:checked + .day-label {
    background: var(--primary);
    color: white;
    transform: scale(1.1);
}

/* --- PLANNER (HOME) --- */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}
.week-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 20px;
    padding-bottom: 80px;
}
@media (min-width: 600px) {
    .week-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (min-width: 1000px) {
    .week-grid { grid-template-columns: repeat(3, 1fr); }
}
@media (min-width: 1400px) {
    .week-grid { grid-template-columns: repeat(4, 1fr); }
}

.day-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
    position: relative;
    display: flex;
    flex-direction: column;
    height: 100%;
}

/* --- PRINT STYLES --- */
@media print {
    @page { margin: 0.5cm; size: landscape; }
    body { background: white; height: auto; overflow: visible; }
    .view { display: block !important; overflow: visible; padding: 0; }
    .bottom-nav, .header button, .card-actions, .modal-overlay, #setup-view, #shopping-view, #import-view, #cooking-view { display: none !important; }
    .week-grid {
        display: grid !important;
        grid-template-columns: repeat(4, 1fr) !important;
        gap: 10px;
        padding-bottom: 0;
    }
    .day-card {
        box-shadow: none;
        border: 1px solid #eee;
        break-inside: avoid;
        page-break-inside: avoid;
    }
    .card-image { height: 100px; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
    .card-content { padding: 10px; }
    .card-title { font-size: 1.1rem; margin-bottom: 5px; }
    .card-meta { margin-bottom: 5px; font-size: 0.8rem; }
}
.card-image {
    height: 200px;
    background-size: cover;
    background-position: center;
    background-color: #eee;
    position: relative;
}
.card-image:hover .edit-overlay {
    opacity: 1;
}
.edit-overlay {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.2s;
    cursor: pointer;
    z-index: 5;
}
.card-tag {
    position: absolute;
    top: 10px;
    right: 10px;
    background: rgba(0,0,0,0.7);
    color: white;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.8rem;
    backdrop-filter: blur(4px);
    z-index: 6;
}

.recipe-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 10px;
}

.recipe-tag {
    background: #f1f2f6;
    color: var(--text-light);
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
    border: 1px solid #e1e1e1;
}
.card-content {
    padding: 20px;
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}
.card-title {
    font-size: 1.5rem;
    margin: 0 0 10px 0;
    font-weight: 700;
}
.card-meta {
    display: flex;
    gap: 15px;
    color: var(--text-light);
    font-size: 0.9rem;
    margin-bottom: 15px;
}
.card-actions {
    display: flex;
    gap: 10px;
}

/* --- MODALS (Centered) --- */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.6);
    z-index: 10000;
    display: none;
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(4px);
}
.modal-overlay.active { display: flex; }
.modal-sheet {
    background: var(--bg-color);
    width: 90%;
    max-width: 500px;
    border-radius: 24px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    animation: popIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    overflow: hidden;
}
@keyframes popIn { 
    from { opacity: 0; transform: scale(0.95) translateY(10px); } 
    to { opacity: 1; transform: scale(1) translateY(0); } 
}
.sheet-header {
    padding: 20px;
    border-bottom: 1px solid #eee;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.sheet-tabs {
    display: flex;
    padding: 10px 20px;
    gap: 10px;
}
.sheet-tab {
    flex: 1;
    padding: 10px;
    text-align: center;
    border-radius: 8px;
    background: #eee;
    cursor: pointer;
    font-weight: 600;
}
.sheet-tab.active {
    background: var(--text-main);
    color: white;
}
.sheet-content {
    overflow-y: auto;
    padding: 20px;
}
.replacement-item {
    display: flex;
    gap: 15px;
    padding: 15px;
    background: white;
    border-radius: 12px;
    margin-bottom: 10px;
    cursor: pointer;
    transition: background 0.2s;
}
.replacement-item:hover { background: #f9f9f9; }
.replacement-img {
    width: 60px;
    height: 60px;
    border-radius: 8px;
    background-color: #ddd;
    background-size: cover;
}

/* --- SHOPPING LIST --- */
.aisle-section { margin-bottom: 20px; }
.aisle-title {
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-light);
    margin-bottom: 10px;
    font-weight: 700;
}
.shop-item {
    display: flex;
    align-items: center;
    padding: 12px;
    background: white;
    border-bottom: 1px solid #f0f0f0;
    cursor: pointer;
}
.shop-item:first-child { border-radius: 12px 12px 0 0; }
.shop-item:last-child { border-radius: 0 0 12px 12px; border-bottom: none; }
.shop-checkbox {
    width: 24px;
    height: 24px;
    border: 2px solid var(--primary);
    border-radius: 50%;
    margin-right: 15px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}
.shop-item.checked .shop-checkbox {
    background: var(--primary);
}
.shop-item.checked .shop-checkbox::after {
    content: '✓';
    color: white;
    font-size: 14px;
}
.shop-item.checked span {
    text-decoration: line-through;
    color: var(--text-light);
}

/* --- COOKING MODE --- */
#cooking-view {
    background: #1a1a1a;
    color: white;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    z-index: 200;
    padding: 0;
}
.cooking-header {
    padding: 20px;
    padding-top: max(20px, env(safe-area-inset-top)); /* Safe area for mobile */
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(255,255,255,0.1);
}
.cooking-content {
    padding: 20px;
    overflow-y: auto;
    height: calc(100vh - 80px);
}
.step-card {
    background: #333;
    padding: 25px;
    border-radius: 16px;
    margin-bottom: 20px;
    font-size: 1.4rem;
    line-height: 1.5;
    cursor: pointer;
    transition: opacity 0.3s;
}
.step-card.done {
    opacity: 0.4;
    text-decoration: line-through;
}
.ingredients-panel {
    background: #2d3436;
    padding: 15px;
    border-radius: 12px;
    margin-bottom: 20px;
}

/* --- MAIN NAV (TOP) --- */
#app-container {
    display: flex;
    flex-direction: column;
    height: 100%;
}
.main-nav {
    background: white;
    box-shadow: 0 4px 15px rgba(0,0,0,0.05);
    display: flex;
    justify-content: center;
    gap: 15px;
    padding: 20px;
    padding-top: env(safe-area-inset-top, 20px);
    z-index: 1000;
    flex-shrink: 0;
}
.nav-item {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 10px;
    color: var(--text-light);
    font-size: 1.1rem;
    font-weight: 700;
    cursor: pointer;
    padding: 15px 25px;
    margin-top: 25px; /* Increased margin top */
    border-radius: 40px;
    transition: all 0.2s;
    background: #f8f9fa;
}
.nav-item.active { 
    color: white; 
    background: var(--primary); 
    box-shadow: 0 6px 15px rgba(0, 184, 148, 0.3);
    transform: scale(1.05);
}
.nav-item i { font-size: 1.3rem; }

@media print { .main-nav { display: none; } }

/* --- IMPORT --- */
.import-box {
    background: white;
    padding: 20px;
    border-radius: 16px;
    box-shadow: var(--shadow);
}
.url-input {
    width: 100%;
    padding: 15px;
    border: 2px solid #eee;
    border-radius: 12px;
    font-size: 1rem;
    margin-bottom: 15px;
    font-family: inherit;
}
.url-input:focus { outline: none; border-color: var(--primary); }

/* --- ANIMATIONS --- */
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* --- MOBILE & TABLET OPTIMIZATION (Touch Devices) --- */
@media (max-width: 1024px) {
    body {
        padding-bottom: 0;
    }

    /* Fixed Bottom Nav for Tablets & Mobile */
    .main-nav {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        top: auto;
        background: white;
        border-top: 1px solid #eee;
        box-shadow: 0 -5px 20px rgba(0,0,0,0.05);
        justify-content: space-around;
        padding: 10px 5px;
        padding-bottom: env(safe-area-inset-bottom, 10px); /* Safe area for iPhone X+ */
        z-index: 9000;
        overflow-x: visible;
        gap: 0;
        height: auto;
    }

    .nav-item {
        flex-direction: column;
        padding: 8px;
        margin-top: 0;
        font-size: 0.75rem; /* Smaller font for labels */
        border-radius: 12px;
        background: transparent;
        color: var(--text-light);
        gap: 4px;
        flex: 1;
        justify-content: center;
        height: auto;
    }

    .nav-item.active {
        background: transparent;
        color: var(--primary);
        box-shadow: none;
        transform: none;
    }
    
    .nav-item.active i {
        background: var(--primary);
        color: white;
        padding: 8px;
        border-radius: 50%;
        margin-bottom: 2px;
        box-shadow: 0 4px 8px rgba(0, 184, 148, 0.3);
    }

    .nav-item i {
        font-size: 1.3rem;
    }

    #app-container {
        padding-bottom: 90px; /* Space for bottom nav + safe area */
    }

    .view {
        padding-bottom: 110px;
    }

    /* Hide hover overlay on touch devices */
    .edit-overlay {
        display: none !important;
    }
    
    /* Better touch targets for cards */
    .card-actions .btn {
        padding: 12px; /* Larger touch target */
        margin-top: 0;
    }
    
    /* Modals full screen on mobile */
    .modal-sheet {
        width: 100%;
        height: 100%;
        max-height: 100%;
        border-radius: 0;
        max-width: none;
    }
    
    .sheet-content {
        padding-bottom: 100px; /* Ensure content isn't hidden by bottom nav if z-index issue, though modal is on top */
    }
}

/* --- PHONE SPECIFIC (Small Screens) --- */
@media (max-width: 600px) {
    .header {
        flex-direction: row;
        align-items: center;
        margin-bottom: 15px;
    }

    .header h2 {
        font-size: 1.4rem;
    }

    .btn {
        padding: 14px 20px; /* Comfortable touch size */
        margin-top: 15px;
        font-size: 1rem;
    }

    .week-grid {
        gap: 15px;
    }

    .day-card {
        border-radius: 16px; /* Softer corners */
    }

    .card-image {
        height: 180px; /* Slightly taller image */
    }

    .card-content {
        padding: 15px;
    }

    .card-title {
        font-size: 1.3rem;
    }
    
    /* Adjust cooking mode for small screens */
    .cooking-header {
        padding: 15px;
        padding-top: max(15px, env(safe-area-inset-top));
    }
    
    .step-card {
        font-size: 1.2rem;
        padding: 20px;
    }
}
