/*
 * components/product-modal.css
 *
 * What:  Styles for the fullscreen product detail popup mounted from
 *        partials/product-modal.ejs and driven by /js/ui/product-modal.js.
 *
 *        Two layered sheets share the same z-stack:
 *          .pm          — main product sheet (header, two-column body
 *                          [image left, info right on desktop], footer
 *                          with qty stepper + dark "Add N to order" CTA)
 *          .pm-group    — nested option-group sheet (radios / checks
 *                          for a single group at a time)
 *
 *        Layout:
 *          • mobile / tablet (≤ 899px) — fullscreen sheet; image sits
 *            on top in a contained box (not full-bleed hero), info +
 *            groups stack below, sticky footer.
 *          • desktop (≥ 900px) — centred card with TWO columns: image
 *            on the LEFT (square, contained), info on the RIGHT
 *            (name, price, description, badges, customise groups).
 *            Mirrors the Uber Eats / DoorDash product sheet.
 *
 *        Toasts and the confirm dialog now sit at z-index 1300 / 1200
 *        in base.css so they stack ABOVE this modal (1100) — earlier
 *        they rendered behind it and got swallowed.
 *
 *        PWA notes:
 *          • Sheet honours env(safe-area-inset-bottom) so the sticky
 *            footer doesn't sit under the iOS home indicator.
 *          • Body overflow lock is set by JS while the modal is up.
 */

/* ── Base layer ─────────────────────────────────────────────────── */
.pm {
    position: fixed; inset: 0;
    z-index: 1100;
    display: flex; align-items: stretch; justify-content: center;
}
.pm[hidden] { display: none !important; }
.pm__backdrop {
    position: absolute; inset: 0;
    background: rgba(15, 23, 42, 0.55);
    backdrop-filter: blur(2px);
    animation: pm-fade 180ms ease-out;
}
@keyframes pm-fade { from { opacity: 0; } to { opacity: 1; } }

/* ── Main sheet ─────────────────────────────────────────────────── */
.pm__sheet {
    position: relative;
    background: #fff; width: 100%; max-width: 980px;
    display: flex; flex-direction: column;
    box-shadow: 0 -24px 60px rgba(0, 0, 0, 0.18);
    animation: pm-rise 240ms cubic-bezier(0.2, 0.7, 0.3, 1);
    max-height: 100vh;
}
@keyframes pm-rise { from { transform: translateY(40px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

.pm__head {
    position: sticky; top: 0; z-index: 2;
    display: flex; align-items: center; justify-content: space-between;
    padding: 12px 12px;
    background: rgba(255, 255, 255, 0.98);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--color-border-soft);
}
.pm__head-spacer { flex: 1; }
.pm__head-icon {
    display: grid; place-items: center;
    width: 36px; height: 36px; border-radius: 50%;
    background: var(--color-bg-alt, #f3f4f6); border: 0; color: var(--color-text); cursor: pointer;
    transition: background 150ms ease, color 150ms ease;
}
.pm__head-icon:hover { background: var(--color-primary-soft); color: var(--color-primary); }

/* ── Main two-pane area ─────────────────────────────────────────── */
/* Mobile (default): a column. Hero on top, body fills the rest and
   scrolls. Desktop overrides to a side-by-side row where the hero
   stays parked while the body's right column scrolls. */
.pm__main {
    flex: 1; min-height: 0;
    display: flex; flex-direction: column;
    overflow: hidden;
}
.pm__hero {
    position: relative; background: var(--color-bg-alt, #f5f5f5);
    display: grid; place-items: center; overflow: hidden;
    aspect-ratio: 16 / 10; max-height: 36vh;
    flex-shrink: 0;
}
.pm__hero img { width: 100%; height: 100%; object-fit: contain; display: block; padding: var(--space-3); }
.pm__hero-placeholder { width: 60%; height: 60%; background: linear-gradient(110deg, #ececec 30%, #f5f5f5 50%, #ececec 70%); border-radius: 12px; animation: pm-skel 1.4s linear infinite; }
@keyframes pm-skel { 0% { background-position: 0% 0%; } 100% { background-position: -200% 0%; } }

.pm__body {
    flex: 1; min-height: 0;
    overflow-y: auto; -webkit-overflow-scrolling: touch;
}
.pm__loading, .pm__error {
    padding: var(--space-6) var(--space-4); text-align: center;
    color: var(--color-text-soft); margin: 0;
}
.pm__error { color: var(--color-primary); font-weight: 600; }

.pm__content { display: flex; flex-direction: column; gap: 0; }

/* Hero-rendered children (built into [data-pm-hero] by JS) ───────── */
/* When the product has NO image we render a contained tile (fixed
   size) instead of letting the placeholder fill the whole pane —
   keeps the layout visually balanced when only an initial is shown. */
.pm-hero__tile {
    width: 168px; height: 168px;
    background: rgba(0, 0, 0, 0.04);
    border: 1px solid var(--color-border-soft);
    border-radius: 18px;
    display: grid; place-items: center;
}
.pm-hero__initial {
    font-size: 3.4rem; font-weight: 800; color: var(--color-text-soft);
    line-height: 1;
}
@media (max-width: 480px) {
    .pm-hero__tile { width: 120px; height: 120px; border-radius: 16px; }
    .pm-hero__initial { font-size: 2.6rem; }
}

/* Veg / non-veg surfaced as a subtle text badge under the price.
   Cleaner than the FSSAI square+triangle inline marker, which clashed
   with the H1 visually. */
.pm-veg {
    display: inline-flex; align-items: center; gap: 6px;
    font-size: 0.78rem; font-weight: 700; letter-spacing: 0.02em;
    text-transform: uppercase; color: var(--color-text-soft);
    margin: 0;
}
.pm-veg__dot {
    width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0;
}
.pm-veg--veg    { color: #15803d; }
.pm-veg--veg    .pm-veg__dot { background: #16a34a; }
.pm-veg--nonveg { color: #b91c1c; }
.pm-veg--nonveg .pm-veg__dot { background: var(--color-primary, #e5252a); }

/* ── Info block ─────────────────────────────────────────────────── */
.pm-info { padding: var(--space-4) var(--space-4) var(--space-3); display: flex; flex-direction: column; gap: 6px; }
.pm-name { font-size: 1.5rem; font-weight: 800; margin: 0; line-height: 1.2; letter-spacing: -0.01em; }
.pm-price { font-size: 1.15rem; font-weight: 800; color: var(--color-text); margin: 2px 0 0; }
.pm-stock {
    display: inline-flex; align-items: center; gap: 6px;
    font-size: 0.85rem; font-weight: 600; margin: 0;
}
.pm-stock--in  { color: #166534; }
.pm-stock--out { color: var(--color-primary); }
.pm-desc { color: var(--color-text-soft); line-height: 1.55; margin: 4px 0 0; font-size: 0.95rem; }

/* ── Groups (inline level-1) ───────────────────────────────────── */
/* Each top-level group is rendered as its own section directly in the
   modal: title + Required/Optional hint, then the option list. Picking
   an option with a `linkedGroup` automatically opens the popup for
   that sub-group; otherwise selection is committed immediately. */
.pm-groups {
    padding: var(--space-2) var(--space-4) var(--space-3);
    display: flex; flex-direction: column; gap: var(--space-4);
    border-top: 1px solid var(--color-border-soft);
    margin-top: var(--space-3);
}
.pm-grp { display: flex; flex-direction: column; gap: 4px; }
.pm-grp__head {
    display: flex; align-items: baseline; justify-content: space-between;
    gap: var(--space-3); padding-bottom: 6px;
}
.pm-grp__name { font-size: 1.05rem; font-weight: 800; margin: 0; color: var(--color-text); }
.pm-grp__hint {
    font-size: 0.78rem; font-weight: 700; color: var(--color-text-soft);
    text-transform: uppercase; letter-spacing: 0.02em;
}
.pm-grp__opts {
    display: flex; flex-direction: column;
    background: #fff; border: 1px solid var(--color-border-soft); border-radius: 12px;
    overflow: hidden;
}
/* Wrapper around each option — owns the row divider so a picked
   option's linked summary stays inside the same visual cell. */
.pm-opt-wrap {
    border-bottom: 1px solid var(--color-border-soft);
}
.pm-opt-wrap:last-child { border-bottom: 0; }

/* Linked sub-group summary nested INSIDE the picked option's row.
   Indented left to align under the option's name (after the radio
   mark + gap = ~36px) so it visually belongs to that option. */
.pm-linked {
    display: flex; align-items: center; justify-content: space-between;
    gap: 10px;
    margin: 0 14px 12px 50px;
    padding: 10px 12px; border-radius: 10px;
    background: var(--color-bg-alt, #f3f4f6);
}
.pm-linked--filled { background: rgba(22, 163, 74, 0.07); }
.pm-linked__info { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.pm-linked__name { font-size: 0.72rem; font-weight: 700; color: var(--color-text-soft); text-transform: uppercase; letter-spacing: 0.02em; }
.pm-linked__sel  { font-size: 0.92rem; font-weight: 700; color: var(--color-text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pm-linked__edit {
    flex-shrink: 0;
    background: #1a1a1a; color: #fff; border: 0; border-radius: 999px;
    padding: 6px 14px; font-size: 0.76rem; font-weight: 800; cursor: pointer;
    letter-spacing: 0.02em;
}
.pm-linked__edit:hover { background: #2b2b2b; }

@media (max-width: 480px) {
    .pm-linked { margin-left: 44px; }
}

/* ── Note textarea ──────────────────────────────────────────────── */
.pm-note { padding: 0 var(--space-4) var(--space-4); display: flex; flex-direction: column; gap: 6px; }
.pm-note__label { font-size: 0.85rem; font-weight: 700; color: var(--color-text); }
.pm-note__input {
    width: 100%; padding: 10px 12px; border: 1px solid var(--color-border); border-radius: 10px;
    font-size: 0.95rem; font-family: inherit; resize: vertical; min-height: 56px;
    background: #fff; color: var(--color-text);
}
.pm-note__input:focus {
    outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 3px rgba(229, 37, 42, 0.12);
}

/* ── Sticky footer (qty + dark CTA) ─────────────────────────────── */
.pm__foot {
    position: sticky; bottom: 0; z-index: 2;
    display: flex; align-items: center; gap: 10px;
    padding: 10px 12px calc(10px + env(safe-area-inset-bottom, 0));
    background: rgba(255, 255, 255, 0.98);
    backdrop-filter: blur(8px);
    border-top: 1px solid var(--color-border-soft);
}
.pm-qty {
    display: inline-flex; align-items: center; gap: 0;
    background: var(--color-bg-alt, #f3f4f6); border-radius: 999px; padding: 4px;
    flex-shrink: 0;
}
.pm-qty__btn {
    background: #fff; border: 0; width: 36px; height: 36px; border-radius: 50%;
    font-size: 1.2rem; font-weight: 800; color: var(--color-text); cursor: pointer;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
    display: grid; place-items: center;
    transition: background 150ms ease, color 150ms ease, transform 80ms ease;
}
.pm-qty__btn:hover { color: var(--color-primary); }
.pm-qty__btn:active { transform: scale(0.94); }
.pm-qty__value { min-width: 36px; text-align: center; font-weight: 800; font-variant-numeric: tabular-nums; font-size: 1rem; }

.pm-add {
    flex: 1; min-width: 0;
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    background: #1a1a1a; color: #fff; border: 0; border-radius: 999px;
    padding: 14px 18px; font-size: 1rem; font-weight: 800; cursor: pointer;
    transition: background 150ms ease, transform 80ms ease;
    min-height: 48px;
    /* Keep the whole label on one line — at a 2-digit qty + a long
       total the flex content used to wrap to two lines and look broken
       on small phones. The label ellipsizes; the total stays pinned. */
    white-space: nowrap;
}
.pm-add:hover { background: #2b2b2b; }
.pm-add:active { transform: scale(0.99); }
.pm-add[disabled], .pm-add.is-loading { opacity: 0.65; cursor: progress; }
.pm-add__label { font-weight: 800; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.pm-add__sep   { opacity: 0.7; font-weight: 400; flex-shrink: 0; }
.pm-add__total { font-weight: 800; font-variant-numeric: tabular-nums; flex-shrink: 0; }

/* ── Nested group sheet ─────────────────────────────────────────── */
.pm-group {
    position: absolute; inset: 0; z-index: 3;
    display: flex; align-items: stretch; justify-content: center;
}
.pm-group[hidden] { display: none !important; }
.pm-group__backdrop {
    position: absolute; inset: 0;
    background: rgba(15, 23, 42, 0.55);
    animation: pm-fade 160ms ease-out;
}
.pm-group__sheet {
    position: relative; background: #fff; width: 100%; max-width: 560px;
    display: flex; flex-direction: column;
    box-shadow: 0 -20px 50px rgba(0, 0, 0, 0.22);
    animation: pm-rise 220ms cubic-bezier(0.2, 0.7, 0.3, 1);
    max-height: 100vh;
}
.pm-group__head {
    display: grid; grid-template-columns: 40px 1fr auto;
    align-items: center; gap: 8px;
    padding: 12px;
    border-bottom: 1px solid var(--color-border-soft);
}
.pm-group__back {
    width: 36px; height: 36px; border-radius: 50%;
    background: var(--color-bg-alt, #f3f4f6); border: 0; color: var(--color-text);
    cursor: pointer; display: grid; place-items: center;
}
.pm-group__back:hover { background: var(--color-primary-soft); color: var(--color-primary); }
.pm-group__title { margin: 0; font-size: 1.05rem; font-weight: 800; }
.pm-group__hint  { font-size: 0.75rem; color: var(--color-text-soft); font-weight: 600; }
.pm-group__body  { flex: 1; overflow-y: auto; padding: 8px var(--space-3); -webkit-overflow-scrolling: touch; }
.pm-group__empty { color: var(--color-text-soft); text-align: center; padding: var(--space-5); }
.pm-group__foot {
    display: flex; gap: 10px; padding: 10px 12px calc(10px + env(safe-area-inset-bottom, 0));
    border-top: 1px solid var(--color-border-soft);
}
.pm-group__cancel, .pm-group__apply {
    flex: 1; padding: 12px; border-radius: 999px; font-weight: 800; cursor: pointer; font-size: 0.95rem;
    border: 0;
}
.pm-group__cancel { background: #fff; border: 1px solid var(--color-border); color: var(--color-text); }
.pm-group__cancel:hover { border-color: var(--color-primary); color: var(--color-primary); }
.pm-group__apply  { background: #1a1a1a; color: #fff; }
.pm-group__apply:hover { background: #2b2b2b; }

/* ── Option rows ────────────────────────────────────────────────── */
/* Flex layout (not grid): mark on left, name fills the middle, price
   pinned to the right. Earlier grid template (1fr / auto / 22px) was
   squeezing "+£0.50" into a 22px column so the "+" stacked above the
   amount. Flex keeps price on one line. */
.pm-opt {
    display: flex; align-items: center; gap: 14px;
    padding: 14px 16px; cursor: pointer;
    transition: background 150ms ease;
    position: relative;
}
.pm-opt:hover { background: var(--color-bg-alt, #f3f4f6); }
.pm-opt input { position: absolute; opacity: 0; pointer-events: none; }
.pm-opt__mark {
    flex-shrink: 0;
    width: 22px; height: 22px; border-radius: 50%;
    border: 2px solid var(--color-border); display: inline-block; position: relative;
    transition: border-color 150ms ease, background 150ms ease;
}
.pm-opt input[type="checkbox"] + .pm-opt__mark { border-radius: 6px; }
.pm-opt input:checked + .pm-opt__mark { border-color: #1a1a1a; background: #1a1a1a; }
.pm-opt input:checked + .pm-opt__mark::after {
    content: ''; position: absolute; left: 50%; top: 50%;
    transform: translate(-50%, -55%) rotate(45deg);
    width: 5px; height: 10px; border: solid #fff; border-width: 0 2px 2px 0;
}
.pm-opt input[type="radio"]:checked + .pm-opt__mark::after {
    content: ''; position: absolute; inset: 4px;
    background: #fff; border-radius: 50%; transform: none;
    border: 0;
}
.pm-opt__name  {
    flex: 1; min-width: 0;
    font-weight: 600; color: var(--color-text); font-size: 0.95rem;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.pm-opt__price {
    flex-shrink: 0;
    font-size: 0.9rem; font-weight: 700; color: var(--color-text-soft);
    white-space: nowrap;
}

/* ── Desktop layout: row split (image LEFT static, info RIGHT scrolls) */
@media (min-width: 900px) {
    .pm { align-items: center; padding: 24px; }
    .pm__sheet { max-height: 90vh; border-radius: 18px; overflow: hidden; }

    /* Side-by-side. `.pm__main` already has `overflow: hidden`, so the
       hero stays parked while only `.pm__body` scrolls. */
    .pm__main { flex-direction: row; }
    .pm__hero {
        flex: 0 0 44%; max-width: 44%;
        aspect-ratio: auto; max-height: none; height: 100%;
        background: #fafafa;
        border-right: 1px solid var(--color-border-soft);
    }
    .pm__hero img { padding: var(--space-5); }
    .pm__body { flex: 1; min-width: 0; }

    .pm-info  { padding: var(--space-5) var(--space-4) var(--space-3); }
    .pm-name  { font-size: 1.7rem; }
    .pm-groups { padding: 0 var(--space-4) var(--space-3); border-top: 0; margin-top: 0; }
    .pm-note   { padding: 0 var(--space-4) var(--space-5); }

    .pm-group { align-items: center; padding: 24px; }
    .pm-group__sheet { max-width: 480px; max-height: 80vh; border-radius: 16px; overflow: hidden; }
}

/* ── Mobile tweaks (single column, contained image) ─────────────── */
@media (max-width: 899px) {
    .pm__hero { aspect-ratio: 16 / 10; max-height: 36vh; }
    .pm__hero img { padding: var(--space-3); }
    .pm-name { font-size: 1.3rem; }
    .pm-add  { padding: 12px 14px; font-size: 0.95rem; }
    .pm-add__label { font-size: 0.9rem; }
}

/* Touch targets — bump the qty steppers + header icons to the 44px
   minimum on phones so they're easy to hit and don't mis-tap. */
@media (max-width: 480px) {
    .pm-qty__btn   { width: 44px; height: 44px; }
    .pm-qty__value { min-width: 40px; }
    .pm__head-icon { width: 44px; height: 44px; }
    .pm-add        { gap: 6px; padding: 12px; }
}
