/* =========================================================
   GLOBAL.CSS — Shared rules loaded on every page, after the theme
   ========================================================= */

/* ---- Image placeholder (missing product / menu image) ---- */
.img-placeholder {
    align-items: center;
    background: var(--primary-light, #EEF1FD);
    border-radius: 8px;
    color: var(--primary, #4F72E3);
    display: inline-flex;
    font-size: 1.6rem;
    justify-content: center;
}
span.product-image.img-placeholder {
    display: flex;
    font-size: 3rem;
    min-height: 200px;
    width: 100%;
}

/* ---- Charts: fixed-height box, canvas uses maintainAspectRatio:false ---- */
.chart-box {
    height: clamp(220px, 40vh, 320px);
    position: relative;
}

/* ---- Headings inside colored card headers keep the header text color ---- */
.card-header.text-white :is(h1, h2, h3, h4, h5, h6) {
    color: inherit;
}

/* ---- Activity level tiles: equal widths ---- */
.activity-levels > .btn {
    flex: 1 1 140px;
}

/* ---- Quick-add offcanvas: keep last actions above the iOS home bar ---- */
.quick-add-offcanvas .offcanvas-body {
    padding-bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
}

@media (max-width: 991.98px) {
    /* iOS Safari zooms on focus when an input is under 16px */
    input:not([type="checkbox"]):not([type="radio"]):not([type="range"]),
    select,
    textarea,
    .form-control,
    .form-control-sm,
    .form-select,
    .form-select-sm {
        font-size: 16px !important;
    }
}


/* ---- Meal edit: one card per item, quantity and delete reachable without horizontal scroll ---- */
.meal-edit-item {
    align-items: center;
    background: var(--surface, #fff);
    border: 1px solid var(--border, #E5E7EB);
    border-radius: 14px;
    display: grid;
    gap: 0.5rem 0.75rem;
    grid-template-columns: 56px minmax(0, 1fr) auto auto;
    margin-bottom: 0.6rem;
    padding: 0.65rem;
}
.meal-edit-item.is-menu {
    border-left: 4px solid var(--primary, #4F72E3);
}
.meal-edit-item__img {
    border-radius: 10px;
    height: 56px;
    object-fit: cover;
    width: 56px;
}
.meal-edit-item__body {
    display: flex;
    flex-direction: column;
    min-width: 0;
}
.meal-edit-item__name {
    overflow-wrap: anywhere;
}
.meal-edit-item__qty {
    display: flex;
    gap: 0.4rem;
}
.meal-edit-item__qty .input-group {
    width: 8.5rem;
}
.meal-edit-item__save,
.meal-edit-item__delete {
    min-height: 44px;
    min-width: 44px;
}
.meal-edit-totals {
    display: grid;
    gap: 0.5rem;
    grid-template-columns: repeat(4, minmax(0, 1fr));
}

@media (max-width: 576px) {
    /* Row 2: quantity under the name, delete on the right */
    .meal-edit-item {
        grid-template-columns: 56px minmax(0, 1fr) auto;
    }
    .meal-edit-item__qty {
        grid-column: 2;
    }
    .meal-edit-item__delete {
        grid-column: 3;
        grid-row: 1 / span 2;
    }
    .meal-edit-totals {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

/* ---- Viewport height that follows the mobile URL bar ---- */
body {
    min-height: 100dvh;
}

/* ---- Long product names (OpenFoodFacts) never widen their column ---- */
.product-thumb-content strong,
.quick-add-product strong,
.card-title {
    overflow-wrap: anywhere;
}

/* ---- Pages already wrapped by <main class="container">: no second gutter ---- */
main.container > .container {
    max-width: none;
    padding-inline: 0;
}

/* ---- Toasts: above everything, bottom of the screen on phones (thumb zone, not over the navbar) ---- */
.app-toasts {
    /* Above the cookie banner (3000) so an "Annuler" action stays tappable. */
    z-index: 3100;
}

/* Toast action ("Annuler"): an outlined pill in the toast's own text colour */
.toast-action {
    align-self: center;
    background: transparent;
    border: 1.5px solid currentColor;
    border-radius: 999px;
    color: inherit;
    flex: 0 0 auto;
    font-weight: 700;
    margin-inline-start: auto;
    min-height: 36px;
    padding: 0.25rem 0.85rem;
    white-space: nowrap;
}
.toast-action:hover,
.toast-action:focus-visible {
    background: rgba(255, 255, 255, 0.18);
    color: inherit;
}
.toast-action + .btn-close {
    margin-inline-start: 0.5rem !important;
}

/* ---- Cookie banner ---- */
.cookie-banner {
    background: #0f172a;
    border-top: 1px solid #1e293b;
    bottom: 0;
    left: 0;
    padding: 0.75rem max(1rem, env(safe-area-inset-right, 0px)) calc(0.75rem + env(safe-area-inset-bottom, 0px)) max(1rem, env(safe-area-inset-left, 0px));
    position: fixed;
    right: 0;
    z-index: 3000;
}
.cookie-banner__inner {
    align-items: center;
    display: flex;
    gap: 0.75rem;
    justify-content: space-between;
    margin: 0 auto;
    max-width: 900px;
}
.cookie-banner__text {
    color: #94a3b8;
    font-size: 0.85rem;
    line-height: 1.5;
    margin: 0;
}
.cookie-banner__text .bi {
    color: #f59e0b;
}
.cookie-banner__text a {
    color: #60a5fa;
    text-decoration: underline;
}
.cookie-banner__short {
    display: none;
}
.cookie-banner__btn {
    background: #4F72E3;
    border: none;
    border-radius: 8px;
    color: #fff;
    cursor: pointer;
    flex-shrink: 0;
    font-size: 0.85rem;
    font-weight: 600;
    min-height: 44px;
    padding: 0.5rem 1.25rem;
    white-space: nowrap;
}

/* ---- Touch screens: no hover lift/sticky hover state after a tap ---- */
@media (hover: none) {
    .card:hover,
    .btn:hover,
    .quick-link:hover {
        transform: none !important;
    }
}

@media (max-width: 991.98px) {
    /* 44px touch targets */
    .btn:not(.btn-link) {
        min-height: 44px;
    }
    .btn-sm:not(.btn-link) {
        align-items: center;
        display: inline-flex;
        justify-content: center;
        min-height: 44px;
        min-width: 44px;
    }
    /* !important: Bootstrap resizes it inside .offcanvas-header / .modal-header */
    .btn-close {
        padding: 0.9rem !important;
    }
    .btn:not(.btn-link) {
        min-width: 44px;
    }
    .form-control,
    .form-select,
    .form-control-sm,
    .form-select-sm {
        min-height: 44px;
    }
    .form-switch .form-check-input {
        height: 1.6em;
        width: 2.9em;
    }
    .form-check-input {
        margin-top: 0.1em;
    }
    .form-check-label {
        padding-block: 0.35rem;
    }
    .today-link,
    #renameBtn {
        align-items: center;
        display: inline-flex;
        justify-content: center;
        min-height: 44px;
        min-width: 44px;
    }
    /* body prefix: these classes are styled again in the page <style> block, which comes later */
    body .hist-delete,
    body .rgpd-btn {
        align-items: center;
        display: inline-flex;
        justify-content: center;
        min-height: 44px;
        min-width: 44px;
    }
    .form-check-input {
        height: 1.4em;
        width: 1.4em;
    }
    .app-footer__links a {
        min-height: 44px;
    }

    /* Logged-out menu: "Connexion" as a real button next to the sign-up CTA */
    .app-navbar .nav-link-login {
        align-items: center;
        border: 1.5px solid currentColor;
        border-radius: 10px;
        display: flex;
        justify-content: center;
        margin-block: 0.5rem;
        min-height: 44px;
    }

    /* Notch in landscape */
    .app-navbar .container-fluid,
    .app-footer {
        padding-left: max(1rem, env(safe-area-inset-left, 0px));
        padding-right: max(1rem, env(safe-area-inset-right, 0px));
    }

    /* Toasts at the bottom, above the bottom nav */
    .app-toasts {
        bottom: calc(76px + env(safe-area-inset-bottom, 0px));
        left: 0;
        right: 0;
        top: auto !important;
    }
    .app-toasts .toast {
        margin-inline: auto;
    }
}

@media (max-width: 576px) {
    .cookie-banner__long {
        display: none;
    }
    .cookie-banner__short {
        display: inline;
    }
    .cookie-banner__text {
        font-size: 0.8rem;
    }
    .cookie-banner__btn {
        min-width: 56px;
        padding-inline: 0.9rem;
    }

    /* Dashboard date picker: one compact row, the date submits on change */
    .date-picker-form .form-label {
        display: none;
    }
}

/* ---- Day calorie bar: green under the target, amber close to it, red beyond ---- */
.kcal-bar--under { background-color: #10B981; }
.kcal-bar--near { background-color: #F59E0B; }
.kcal-bar--over { background-color: #DC2626; }

/* ---- Page header: one title style for every page, actions wrap below the text on phones ---- */
.page-header {
    align-items: center;
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem 1rem;
    justify-content: space-between;
    margin-bottom: 1.25rem;
}
.page-header__text {
    flex: 1 1 240px;
    min-width: 0;
}
.page-header__title {
    color: var(--heading, #111827);
    font-size: clamp(1.35rem, 5vw, 1.75rem);
    font-weight: 700;
    line-height: 1.2;
    margin: 0;
}
.page-header__subtitle {
    color: var(--muted, #6B7280);
    font-size: 0.875rem;
    margin: 0.2rem 0 0;
}
.page-header__actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

/* ---- Camera barcode view (BarcodeScanner: dashboard quick add, food search) ---- */
.barcode-view {
    aspect-ratio: 4 / 3;
    background: #000;
    border-radius: 14px;
    max-width: 100%;
    overflow: hidden;
    position: relative;
}
.barcode-view video,
.barcode-view canvas {
    height: 100%;
    left: 0;
    object-fit: cover;
    position: absolute;
    top: 0;
    width: 100%;
}
.barcode-view canvas.drawingBuffer {
    pointer-events: none;
}
/* Aiming frame */
.barcode-view__frame {
    border: 2px solid rgba(255, 255, 255, 0.85);
    border-radius: 10px;
    box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.25);
    height: 40%;
    left: 10%;
    position: absolute;
    top: 30%;
    width: 80%;
    z-index: 1;
}

/* ---- Pages opting in with {% block main_class %}main--gutter{% endblock %}: 16px side gutter on phones ---- */
main.main--gutter {
    --main-gutter: calc(var(--bs-gutter-x, 1.5rem) * 0.5);
}
@media (max-width: 575.98px) {
    main.main--gutter {
        --main-gutter: 16px;
        padding-inline: var(--main-gutter);
    }
}
