﻿/* /MainPage/Modules/HealthAndWellBeing/Food/Settings/Settings.css */

.SettingsContentArea {
    display: grid;
    grid-template-columns: minmax(0, 1.2fr) minmax(320px, 0.8fr);
    gap: 16px;
    color: var(--textColor);
    min-width: 0;

    .SettingsPanel {
        min-width: 0;
        padding: 16px;
        border: 1px solid var(--mainPageBorderColor);
        border-radius: 8px;
        background-color: var(--mainPageCardBgColor);

        h4, h5, p {
            margin-top: 0;
        }
    }

    .SettingsPanelHeader {
        display: flex;
        justify-content: space-between;
        gap: 12px;
        align-items: flex-start;
        margin-bottom: 14px;

        span, p {
            color: var(--textColor);
            opacity: 0.75;
        }

        h4{
            font-size: 20px;
        }
    }

    .SettingsFormGrid {
        display: grid;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 12px 10px;

        label {
            display: flex;
            flex-direction: column;
            gap: 6px;
            font-size: 0.85rem;
            color: var(--textColor);
            opacity: 0.9;
        }
    }

    .SettingsFormGridSmall {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }

    .FoodContentBodyMicroNutrients input,
    .FoodContentCalculateMicroNutrients input {
        width: 80px;
        box-sizing: border-box;
    }

    .FoodContentBodyMicroNutrients {
        grid-template-columns: repeat(auto-fit, 80px);
        justify-content: start;
    }

    .SettingsFormGridCompact {
        grid-template-columns: repeat(3, minmax(0, 1fr));

    }

    input, select, button {
        min-height: 38px;
        border: 1px solid var(--mainPageBorderColor);
        border-radius: 8px;
        color: var(--textColor);
        background-color: var(--mainPageButtonBgColor);
    }

    input, select {
        padding: 0 10px;
        box-sizing: border-box;
        max-width: 100%;
        min-width: 0;
    }

    button {
        padding: 0 12px;
        cursor: pointer;

    }

    .PrimaryButton {
        border-color: var(--activeElementBgColor);
        background-color: var(--activeElementBgColor);
    }

    .SettingsActions {
        display: flex;
        flex-wrap: wrap;
        gap: 8px;
        margin-top: 14px;
    }

    .FoodAdvancedSettingsHeader {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 12px;
        margin-top: 18px;
    }

    .FoodAdvancedSettingsHeader > h5 {
        margin: 0 !important;
    }

    .FoodAdvancedSettingsButton[aria-expanded="true"] {
        border-color: var(--activeElementBgColor);
        background-color: var(--activeElementHoverColor);
    }

    #FoodManualAdvancedSettings[hidden],
    #FoodCalculateAdvancedSettings[hidden] {
        display: none;
    }

    .FoodCyclicDietaryPattern {
        grid-column: 1 / -1;
    }

    .FoodCycleConfiguration {
        grid-template-columns: repeat(5, minmax(150px, 1fr));
    }

    .FoodCycleEnabled {
        align-items: flex-start;
    }

    .FoodCycleEnabled input {
        width: 22px;
        min-height: 22px;
    }

    .FoodCycleSummary {
        margin: 14px 0;
        padding: 10px 12px;
        border-left: 3px solid var(--activeElementBgColor);
        background: var(--mainPageBodyBgColor);
    }

    .FoodCycleDays {
        display: grid;
        gap: 12px;
    }

    .FoodCycleDay {
        border: 1px solid var(--mainPageBorderColor);
        border-radius: 10px;
        overflow: hidden;
    }

    .FoodCycleDayHeader {
        display: grid;
        grid-template-columns: 80px minmax(180px, 360px);
        align-items: center;
        gap: 10px;
        padding: 10px;
        background: var(--mainPageBodyBgColor);
    }

    .FoodCycleMeals {
        display: grid;
        grid-template-columns: repeat(5, minmax(150px, 1fr));
    }

    .FoodCycleMeal {
        display: grid;
        align-content: start;
        gap: 8px;
        min-width: 0;
        padding: 10px;
        border-right: 1px solid var(--mainPageBorderColor);
    }

    .FoodCycleMeal:last-child {
        border-right: 0;
    }

    .FoodCycleFoodPicker summary {
        padding: 8px;
        border: 1px solid var(--mainPageBorderColor);
        border-radius: 7px;
        cursor: pointer;
    }

    .FoodCycleFoodOptions {
        display: grid;
        gap: 5px;
        max-height: 220px;
        margin-top: 5px;
        padding: 8px;
        overflow-y: auto;
        border: 1px solid var(--mainPageBorderColor);
        border-radius: 7px;
        background: var(--mainPageCardBgColor);
    }

    .FoodCycleFoodOptions label {
        display: grid;
        grid-template-columns: 20px minmax(0, 1fr);
        align-items: center;
        gap: 7px;
        font-size: .78rem;
    }

    .FoodCycleFoodOptions input {
        min-height: 18px;
    }

    .FoodContentManualAddFood {
        /* min-height: 100%; */

        h5 {
            margin: 18px 0 10px;
            font-size: 20px;
        }
    }

    .FoodContentCalculateAddFood {
        h5 {
            margin: 18px 0 10px;
        }

        .FoodContentCalculateNutrients {
            max-height: 420px;
            margin-top: 14px;
            padding-right: 8px;
            overflow-y: auto;

            .SettingsFormGrid {
                grid-template-columns: repeat(2, minmax(0, 1fr));
            }

            .FoodContentCalculateMicroNutrients {
                grid-template-columns: repeat(auto-fit, 80px);
                justify-content: start;
            }

            h5{
                font-size: 20px;
            }

            .FoodCalculatedNutrientValue {
                min-height: 1em;
                color: var(--activeElementBgColor);
                font-weight: 600;
                opacity: 1;
            }

        }

        .SettingsResultGrid {
            display: grid;
            grid-template-columns: repeat(3, minmax(0, 1fr));
            gap: 10px;
            margin: 14px 0 18px;

            div {
                padding: 12px;
                border: 1px solid var(--activeElementBgColor);
                border-radius: 8px;
                background-color: var(--mainPageBodyBgColor);
            }

            span, small {
                display: block;
                opacity: 0.75;
            }

            strong {
                display: block;
                margin: 6px 0;
                font-size: 1.4rem;
            }
        }

        .SettingsHelp {
            margin: 12px 0 0;
            padding: 12px;
            border-left: 4px solid var(--activeElementBgColor);
            background-color: var(--mainPageBodyBgColor);
        }
    }

    .FoodContentDailyGoals {
        .SettingsGoal {
            display: grid;
            grid-template-columns: 90px 1fr 70px;
            gap: 12px;
            align-items: center;
            margin-top: 10px;
        }

        progress {
            width: 100%;
            height: 10px;
            accent-color: var(--activeElementBgColor);
        }
    }

    .FoodContentFoodArray {
        grid-column: 1 / -1;
        overflow-x: auto;

        table {
            width: 100%;
            border-collapse: collapse;
        }

        th, td {
            padding: 12px 10px;
            border-bottom: 1px solid var(--mainPageBorderColor);
            text-align: left;
            white-space: nowrap;
        }

        th {
            color: var(--textColor);
            opacity: 0.75;
        }

        .FoodSavedFilters {
            margin-top: 0;

            label {
                display: flex;
                flex-direction: column;
                gap: 4px;
                font-size: 0.8rem;
            }
        }

        .FoodSavedRow {
            cursor: pointer;

            &:hover, &:focus {
                background-color: var(--mainPageBodyBgColor);
                outline: none;
            }
        }

        .FoodDependentNutrient {
            padding-left: 22px;
            font-size: 0.9em;
            opacity: 0.72;
            background-color: color-mix(in srgb, var(--mainPageBodyBgColor) 55%, transparent);
        }

        .FoodDeleteButton {
            border-color: #b43b3b;
            color: #d96a6a;
        }

        .FoodSavedEmpty {
            padding: 24px 10px;
            text-align: center;
            opacity: 0.7;
        }
    }

    .FoodContentDietaryPattern {
        grid-column: 1 / -1;
        width: 100%;
        min-width: 0;
        box-sizing: border-box;

        .FoodWeekPlanDays {
            display: grid;
            gap: 20px;
        }

        .FoodWeekPlanDay {
            padding-top: 16px;
            border-top: 1px solid var(--mainPageBorderColor);

            > h5 {
                margin-bottom: 12px;
                font-size: 1.05rem;
            }
        }

        .SettingsMealsGrid {
            display: grid;
            grid-template-columns: repeat(5, minmax(150px, 1fr));
            gap: 12px;
        }

        .SettingsMealCard {
            padding: 12px;
            border: 1px solid var(--mainPageBorderColor);
            border-radius: 8px;
            background-color: var(--mainPageBodyBgColor);

            h5 {
                margin-bottom: 10px;
            }

            h6 {
                min-height: 2.4em;
                margin: 0 0 10px;
                font-size: 0.9rem;
            }

            label {
                display: block;
                margin: 10px 0;
            }

            input[type="time"] {
                width: 100%;
                margin-top: 6px;
                box-sizing: border-box;
            }

            input[type="checkbox"] {
                min-height: auto;
                margin: 0;
            }

            small {
                display: block;
                opacity: 0.7;
            }

            .FoodWeekPlanFoodChoices {
                min-width: 0;
                margin: 10px 0;
                padding: 0;
                border: 0;

                legend {
                    margin-bottom: 6px;
                }

                .FoodWeekPlanFoodDropdown {
                    position: relative;

                    summary {
                        min-height: 38px;
                        box-sizing: border-box;
                        padding: 9px 30px 9px 10px;
                        overflow: hidden;
                        border: 1px solid var(--mainPageBorderColor);
                        border-radius: 8px;
                        background-color: var(--mainPageButtonBgColor);
                        cursor: pointer;
                        text-overflow: ellipsis;
                        white-space: nowrap;
                    }

                    .FoodWeekPlanFoodMenu {
                        position: absolute;
                        z-index: 20;
                        top: calc(100% + 4px);
                        right: 0;
                        left: 0;
                        padding: 6px;
                        border: 1px solid var(--mainPageBorderColor);
                        border-radius: 8px;
                        background-color: var(--mainPageCardBgColor);
                        box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);

                        .FoodWeekPlanFoodSearch {
                            width: 100%;
                            box-sizing: border-box;
                            margin-bottom: 6px;
                        }
                    }
                }

                .FoodWeekPlanFoodList {
                    display: grid;
                    gap: 4px;
                    max-height: 180px;
                    padding: 6px;
                    overflow-y: auto;
                    border-top: 1px solid var(--mainPageBorderColor);

                    .FoodWeekPlanFoodOption {
                        display: grid;
                        grid-template-columns: auto minmax(0, 1fr);
                        align-items: center;
                        gap: 8px;
                        margin: 0;
                        padding: 6px;
                        border-radius: 6px;
                        cursor: pointer;

                        &[hidden] {
                            display: none;
                        }

                        &:hover {
                            background-color: var(--activeElementHoverColor);
                        }

                        span {
                            overflow-wrap: anywhere;
                        }
                    }

                    .FoodWeekPlanFoodEmpty {
                        margin: 0;
                        padding: 8px;
                        text-align: center;
                        opacity: 0.7;
                    }
                }
            }
        }
    }
}

/* Nouveau calendrier hebdomadaire */
.FoodContentDietaryPattern .FoodWeekPlanDays {
    position: relative;
    isolation: isolate;
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 16px;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    box-sizing: border-box;
    contain: layout paint;
}

.FoodWeekPlanCalendarScroll { width: 100%; max-width: 100%; min-width: 0; box-sizing: border-box; overflow-x: auto; padding-bottom: 6px; }
.FoodWeekPlanCalendar {
    display: grid;
    grid-template-columns: minmax(110px, .7fr) repeat(5, minmax(175px, 1fr));
    min-width: 1000px;
    overflow: hidden;
    border: 1px solid var(--mainPageBorderColor);
    border-radius: 10px;
}
.FoodWeekPlanCorner, .FoodWeekPlanDayHeader, .FoodWeekPlanMealHeader, .FoodWeekPlanCell {
    min-width: 0;
    padding: 10px;
    border-right: 1px solid var(--mainPageBorderColor);
    border-bottom: 1px solid var(--mainPageBorderColor);
}
.FoodWeekPlanCorner, .FoodWeekPlanDayHeader {
    position: sticky;
    top: 0;
    z-index: 2;
    display: grid;
    place-items: center;
    min-height: 42px;
    font-weight: 700;
    background: var(--mainPageCardBgColor);
}
.FoodWeekPlanMealHeader {
    position: sticky;
    left: 0;
    z-index: 1;
    display: flex;
    align-items: center;
    font-weight: 700;
    background: var(--mainPageCardBgColor);
}
.FoodWeekPlanCell { display: flex; flex-direction: column; gap: 8px; min-height: 155px; background: var(--mainPageBodyBgColor); }
.FoodWeekPlanCell.IsSelecting { outline: 2px solid var(--activeElementBgColor); outline-offset: -2px; }
.FoodWeekPlanCell input[type="time"] { width: 100%; box-sizing: border-box; }
.FoodWeekPlanCellFoods { display: flex; flex: 1; flex-direction: column; gap: 5px; }
.FoodWeekPlanCellEmpty { opacity: .55; }
.FoodWeekPlanFoodChip { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 5px; padding: 5px 7px; border-radius: 6px; background: var(--mainPageCardBgColor); }
.FoodWeekPlanFoodChip > span { overflow: hidden; font-size: .82rem; text-overflow: ellipsis; white-space: nowrap; }
.FoodWeekPlanFoodChip button { min-height: 24px; padding: 0 6px; border: 0; font-size: 1rem; }
.FoodWeekPlanAddFood { width: 100%; margin-top: auto; }

.FoodWeekPlanCatalog {
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-width: 0;
    padding: 14px;
    border: 1px solid var(--mainPageBorderColor);
    border-radius: 10px;
    background: var(--mainPageCardBgColor);
}
.FoodWeekPlanCatalogHeader { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.FoodWeekPlanCatalogHeader h5, .FoodWeekPlanCatalog > p { margin: 0; }
.FoodWeekPlanCatalog > p { min-height: 2.5em; font-size: .85rem; opacity: .7; }
.FoodWeekPlanCatalog input { width: 100%; box-sizing: border-box; }
.FoodWeekPlanCatalogList { display: grid; align-content: start; gap: 6px; overflow-y: auto; }
.FoodWeekPlanCatalogGroup { display: grid; gap: 6px; }
.FoodWeekPlanCatalogGroup + .FoodWeekPlanCatalogGroup { margin-top: 8px; padding-top: 12px; border-top: 1px solid var(--mainPageBorderColor); }
.FoodWeekPlanCatalogGroup h6 { margin: 0; font-size: .9rem; }
.FoodWeekPlanCatalogGroupList { display: grid; gap: 6px; }
.FoodWeekPlanCategoryEmpty { padding: 5px 2px; opacity: .5; }
.FoodWeekPlanCatalogFood { display: flex; flex-direction: column; align-items: flex-start; min-height: 52px; text-align: left; }
.FoodWeekPlanCatalogFood small { margin-top: 3px; opacity: .68; }
.FoodWeekPlanCatalogFood.IsSelected { border-color: var(--activeElementBgColor); background: var(--activeElementHoverColor); }
.FoodWeekPlanCatalogClose { font-size: 1.25rem; }
.FoodWeekPlanCatalogBackdrop { display: none; }

@media (min-width: 1500px) {
    .FoodContentDietaryPattern .FoodWeekPlanDays {
        grid-template-columns: minmax(0, 1fr) 300px;
        overflow: visible;
    }
    .FoodWeekPlanCatalog {
        position: relative;
        z-index: auto;
        inset: auto;
        width: auto;
        max-height: 690px;
        clip-path: none;
        visibility: visible;
        will-change: auto;
    }
    .FoodWeekPlanCatalogBackdrop,
    .FoodWeekPlanCatalogClose { display: none; }
}

@media (max-width: 1499px) {
    .FoodContentDietaryPattern .FoodWeekPlanDays {
        overflow: hidden;
        border-radius: 10px;
    }

    .FoodWeekPlanCatalog {
        position: absolute;
        z-index: 12;
        top: 0;
        right: 0;
        bottom: 0;
        width: min(360px, 88%);
        max-height: 100%;
        box-sizing: border-box;
        border-radius: 10px 0 0 10px;
        box-shadow: -12px 0 32px rgba(0, 0, 0, .28);
        clip-path: inset(0 0 0 100%);
        will-change: clip-path;
        transition: clip-path .25s ease;
        visibility: hidden;
    }
    .FoodContentDietaryPattern .FoodWeekPlanCatalogBackdrop {
        position: absolute;
        z-index: 11;
        inset: 0;
        display: block;
        width: 100%;
        height: 100%;
        min-height: 0;
        padding: 0;
        border: 0 !important;
        border-radius: 10px;
        background: transparent !important;
        -webkit-backdrop-filter: blur(1px);
        backdrop-filter: blur(1px);
        opacity: 0;
        visibility: hidden;
        cursor: default;
        transition: opacity .25s ease, visibility .25s ease;
    }
    .FoodWeekPlanDays.CatalogOpen .FoodWeekPlanCatalogBackdrop { opacity: 1; visibility: visible; }
    .FoodWeekPlanDays.CatalogOpen .FoodWeekPlanCatalog { clip-path: inset(0 0 0 0); visibility: visible; }
}

/* Smartphones */
@media (max-width: 767px) {
    .SettingsContentArea {
        grid-template-columns: 1fr;
        gap: 10px;

        .SettingsPanel { padding: 12px; }

        .SettingsPanelHeader {
            flex-direction: column;
            align-items: stretch;
        }

        .SettingsFormGrid,
        .SettingsFormGridCompact,
        .FoodContentCalculateAddFood .SettingsResultGrid,
        .FoodContentDietaryPattern .SettingsMealsGrid {
            grid-template-columns: repeat(2, minmax(0, 1fr));
        }

        .FoodContentBodyMicroNutrients,
        .FoodContentCalculateMicroNutrients {
            grid-template-columns: repeat(auto-fit, minmax(72px, 1fr));
        }

        .FoodContentBodyMicroNutrients input,
        .FoodContentCalculateMicroNutrients input { width: 100%; }

        .SettingsActions {
            flex-direction: column;

            button { width: 100%; min-height: 44px; }
        }

        .FoodContentDailyGoals .SettingsGoal {
            grid-template-columns: 72px minmax(0, 1fr) 55px;
            gap: 7px;
            font-size: .82rem;
        }

        .FoodContentFoodArray {
            margin-inline: -12px;
            padding-inline: 12px;
        }
    }

    /* Keep the scrollable box at least as wide as the minimum size of all
       six grid tracks; otherwise the final (dinner) track is clipped by the
       calendar's overflow without becoming reachable through scrolling. */
    .FoodWeekPlanCalendar { min-width: 1000px; }
    .FoodWeekPlanCorner,
    .FoodWeekPlanDayHeader,
    .FoodWeekPlanMealHeader,
    .FoodWeekPlanCell { padding: 8px; }
    .FoodWeekPlanCatalog { width: min(340px, 94%) !important; }
}

/* Téléphones étroits : une seule colonne uniquement quand deux champs
   ne disposent réellement plus d'une largeur confortable. */
@media (max-width: 520px) {
    .SettingsContentArea {
        .SettingsFormGrid,
        .SettingsFormGridCompact,
        .FoodContentCalculateAddFood .SettingsResultGrid,
        .FoodContentDietaryPattern .SettingsMealsGrid {
            grid-template-columns: 1fr;
        }

        .FoodContentBodyMicroNutrients,
        .FoodContentCalculateMicroNutrients {
            grid-template-columns: repeat(2, minmax(0, 1fr));
        }
    }
}

/* Tablettes */
@media (min-width: 768px) and (max-width: 1024px) {
    .SettingsContentArea {
        grid-template-columns: 1fr;

        .SettingsFormGrid { grid-template-columns: repeat(2, minmax(0, 1fr)); }

        .FoodContentDietaryPattern .SettingsMealsGrid {
            grid-template-columns: repeat(2, minmax(0, 1fr));
        }
    }
}

/* Petits laptops */
@media (min-width: 1025px) and (max-width: 1919px) { }

/* Desktop */
@media (min-width: 1920px) { }

@media (max-width: 1100px) {
    .SettingsContentArea {
        .FoodCycleConfiguration { grid-template-columns: repeat(2, minmax(0, 1fr)); }
        .FoodCycleMeals { grid-template-columns: 1fr; }
        .FoodCycleMeal { border-right: 0; border-bottom: 1px solid var(--mainPageBorderColor); }
        .FoodCycleMeal:last-child { border-bottom: 0; }
    }
}

@media (max-width: 520px) {
    .SettingsContentArea {
        .FoodCycleConfiguration { grid-template-columns: 1fr; }
        .FoodCycleDayHeader { grid-template-columns: 1fr; }
    }
}
