/*!
 * My Dine — Shared Page Styles (v1)
 * File: /frontend/css/md-pages.v1.css
 * Purpose: Shared, reusable layout + typography primitives for frontend pages.
 *
 * Conventions:
 *  - Keep selectors prefixed with `md-` to avoid collisions with legacy CSS.
 *  - Pages compose these primitives and keep page-specific rules local.
 *  - Navbar height is injected via CSS var `--md-nav-h` (fallback 76px).
 */

/* =========================
   Tokens
   ========================= */
:root{
    --md-nav-h: 76px;

    /* ✅ iOS safe-area insets (viewport-fit=cover) */
    --md-safe-top: env(safe-area-inset-top, 0px);
    --md-safe-bottom: env(safe-area-inset-bottom, 0px);
    --md-safe-left: env(safe-area-inset-left, 0px);
    --md-safe-right: env(safe-area-inset-right, 0px);

    --md-text: #111827;
    --md-muted: #6b7280;
    --md-border: #e5e7eb;
    --md-border-soft: #f1f5f9;
    --md-surface: #ffffff;
    --md-surface-subtle: #f3f4f6;

    /* ✅ Brand accents (purple) */
    --md-accent: #953d96;               /* primary */
    --md-accent-soft: #d39bd4;          /* secondary */
    --md-accent-tint: rgba(149, 61, 150, .10);
    --md-accent-ring: rgba(149, 61, 150, .18);

    --md-radius-sm: 10px;
    --md-radius-lg: 14px;
    --md-radius-xl: 16px;

    --md-shadow-sm: 0 4px 10px rgba(0,0,0,.05);
    --md-shadow-lg: 0 10px 25px rgba(0,0,0,.08);

    --md-focus: 0 0 0 .2rem var(--md-accent-ring);

    /* Voucher card tokens */
    --md-voucher-media-ratio: 3 / 2;       /* 1.5:1 */
    --md-voucher-media-fallback: 66.6667%; /* 2/3 * 100 */
    --md-voucher-logo-w: 76px;             /* “a touch smaller” */
    --md-voucher-logo-h: 28px;             /* fixed height */
}

/* =========================================================
   ✅ Header offset without JS class toggling (reduces “jump”)
   - Pages that use .md-page already self-offset.
   - Pages that do NOT use .md-page get offset via main.
   ========================================================= */

/* default: no extra padding */
.md-site-main{ padding-top: 0; }

/* Modern Safari/Chrome: :has() supported */
.md-site-main:not(:has(.md-page)){
    padding-top: calc(var(--md-nav-h, 76px) + var(--md-safe-top, 0px) + 12px);
}

/* =========================
   Base helpers
   ========================= */
.md-page{
    /* ✅ Real mobile Safari: account for fixed header + safe-area */
    padding: calc(var(--md-nav-h, 76px) + var(--md-safe-top, 0px) + 1.5rem) 0 calc(2.25rem + var(--md-safe-bottom, 0px));
}

.md-link{
    color: inherit;
    text-decoration: none;
}
.md-link:hover{
    text-decoration: underline;
}

.md-link-accent{
    color: var(--md-accent);
    font-weight: 900;
    text-decoration: none;
}
.md-link-accent:hover{
    text-decoration: underline;
}

.md-visually-hidden{
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    white-space: nowrap !important;
    border: 0 !important;
}

/* Respect reduced-motion */
@media (prefers-reduced-motion: reduce){
    *{
        scroll-behavior: auto !important;
        transition-duration: 0.001ms !important;
        animation-duration: 0.001ms !important;
        animation-iteration-count: 1 !important;
    }
}

/* =========================
   Shared page header
   ========================= */
.md-header{
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 1.25rem;
}

.md-title{
    font-weight: 900;
    letter-spacing: -0.02em;
    margin: 0;
    font-size: clamp(1.8rem, 2.6vw, 2.4rem);
    color: var(--md-text);
}

.md-subtitle{
    margin: .35rem 0 0;
    color: var(--md-muted);
    font-size: .98rem;
    max-width: 56ch;
}

/* =========================
   Shared card primitive
   ========================= */
.md-card{
    border: 1px solid rgba(0,0,0,.07);
    border-radius: var(--md-radius-xl);
    overflow: hidden;
    background: var(--md-surface);
    box-shadow: var(--md-shadow-sm);
    transition: transform .18s ease, box-shadow .18s ease;
    height: 100%;
}
.md-card:hover{
    transform: translateY(-2px);
    box-shadow: var(--md-shadow-lg);
}

/* Fixed-aspect media slot */
.md-card-media{
    background: var(--md-surface-subtle);
    overflow: hidden;
}
.md-card-media > img{
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

/* =========================
   Shared chips & pills
   ========================= */
.md-pill{
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    border-radius: 999px;
    background: var(--md-surface-subtle);
    color: var(--md-text);
    font-weight: 800;
    font-size: .82rem;
    width: fit-content;
}

.md-chip{
    display: inline-flex;
    gap: .5rem;
    align-items: center;
    border: 1px solid var(--md-border);
    background: var(--md-surface);
    border-radius: 999px;
    padding: .55rem .85rem;
    font-weight: 900;
    color: var(--md-text);
    box-shadow: 0 2px 10px rgba(0,0,0,.04);
}

/* =========================
   Shared filter pills (v1)
   ========================= */
.md-filterbar{
    display:flex;
    align-items:center;
    gap: .6rem;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: .35rem;
    margin: .25rem 0 1rem;
}

.md-filterbar::-webkit-scrollbar{ height: 8px; }
.md-filterbar::-webkit-scrollbar-thumb{
    background: rgba(0,0,0,.10);
    border-radius: 999px;
}

.md-filter-pill{
    display:inline-flex;
    align-items:center;
    gap: .6rem;
    min-height: 44px;
    padding: 10px 14px;
    border-radius: 14px; /* “pill box” (not full capsule) */
    border: 1px solid rgba(0,0,0,.14);
    background: #fff;
    color: var(--md-text) !important; /* ✅ hard stop: never blue */
    text-decoration: none !important;
    font-weight: 900;
    white-space: nowrap;
    user-select: none;
    transition: background .15s ease, border-color .15s ease, transform .15s ease;
}

.md-filter-pill:hover{
    background: #fafafa;
    border-color: rgba(0,0,0,.20);
}

.md-filter-pill:focus-visible{
    outline: none;
    box-shadow: 0 0 0 .2rem var(--md-accent-ring);
}

.md-filter-pill.is-active{
    border-color: var(--md-accent);
    background: var(--md-accent-tint);
    color: var(--md-accent) !important;
}

.md-filter-count{
    display:inline-flex;
    align-items:center;
    justify-content:center;
    min-width: 28px;
    height: 22px;
    padding: 0 8px;
    border-radius: 999px;
    background: var(--md-surface-subtle);
    border: 1px solid rgba(0,0,0,.06);
    color: var(--md-text);
    font-weight: 900;
    font-size: .85rem;
    line-height: 1;
}

.md-filter-pill.is-active .md-filter-count{
    background: rgba(149,61,150,.22);
    border-color: rgba(149,61,150,.25);
}

/* =========================
   Shared form focus
   ========================= */
.md-input{
    border: 1px solid #d1d5db;
    border-radius: 999px;
    padding: 10px 14px;
    outline: none;
}
.md-input:focus{
    border-color: var(--md-accent);
    box-shadow: var(--md-focus);
}

/* =========================
   Shared dropdown shell (optional)
   ========================= */
.md-dropdown{ position: relative; }

.md-dropdown-label{
    display:flex;
    justify-content:space-between;
    align-items:center;
    padding:10px 12px;
    background: var(--md-surface);
    border:1px solid #d1d5db;
    border-radius: var(--md-radius-sm);
    cursor:pointer;
    user-select: none;
}
.md-dropdown-label:hover{ background:#f9fafb; }

.md-dropdown-options{
    position:absolute;
    top:calc(100% + 6px);
    left:0;
    right:0;
    background: var(--md-surface);
    border:1px solid #d1d5db;
    border-radius: var(--md-radius-sm);
    box-shadow: var(--md-shadow-lg);
    margin:0;
    padding:6px;
    display:none;
    z-index:50;
}
.md-dropdown.open .md-dropdown-options{ display:block; }

.md-dropdown-options > li{
    list-style:none;
    padding:10px;
    border-radius: 8px;
    cursor:pointer;
}
.md-dropdown-options > li:hover{ background: var(--md-surface-subtle); }
.md-dropdown-options > li.md-selected{
    background: var(--md-accent-tint);
    font-weight:900;
}

/* =========================
   Shared voucher card (v1)
   ========================= */
.md-voucher-card-link{
    display:block;
    height:100%;
    width:100%;
    color:inherit;
    text-decoration:none;
}

.md-voucher-card-link:focus-visible{ outline: none; }

.md-voucher-card-link:focus-visible .md-voucher-card{
    box-shadow: var(--md-shadow-lg), 0 0 0 .2rem var(--md-accent-ring);
}

/* ✅ iPhone Safari hardening: consistent sizing */
.md-voucher-card,
.md-voucher-card *{
    box-sizing: border-box;
}

.md-voucher-card{
    width:100%;
    border: 1px solid rgba(0,0,0,.07);
    border-radius: 18px;
    overflow: hidden;
    background: var(--md-surface);
    box-shadow: var(--md-shadow-sm);
    transition: transform .18s ease, box-shadow .18s ease;
    height: 100%;
    display:flex;
    flex-direction:column;
}

.md-voucher-card:hover{
    transform: translateY(-2px);
    box-shadow: var(--md-shadow-lg);
}

.md-voucher-media{
    position: relative;
    aspect-ratio: var(--md-voucher-media-ratio);
    background: var(--md-surface-subtle);
    overflow:hidden;
}

.md-voucher-media > img{
    width:100%;
    height:100%;
    object-fit:cover;
    display:block;
}

.md-voucher-media-placeholder{
    width:100%;
    height:100%;
}

@supports not (aspect-ratio: 1 / 1){
    .md-voucher-media{
        height:0;
        padding-top: var(--md-voucher-media-fallback);
    }
    .md-voucher-media > img,
    .md-voucher-media-placeholder{
        position:absolute;
        inset:0;
    }
}

.md-voucher-venue-logo{
    position:absolute;
    left: 12px;
    top: 12px;

    width: var(--md-voucher-logo-w);
    height: var(--md-voucher-logo-h);

    display:inline-flex;
    align-items:center;
    justify-content:center;

    padding: 4px 6px;
    border-radius: 12px;
    background: rgba(255,255,255,.92);
    border: 1px solid rgba(0,0,0,.08);
    box-shadow: 0 6px 18px rgba(0,0,0,.10);
}

.md-voucher-venue-logo img{
    width: var(--md-voucher-logo-w);
    height: var(--md-voucher-logo-h);
    object-fit: contain;
    display:block;
}

/* Small screens: slightly tighter badge */
@media (max-width: 420px){
    :root{
        --md-voucher-logo-w: 70px;
        --md-voucher-logo-h: 26px;
    }
}

.md-voucher-body{
    padding: 12px 14px 14px;
    display:flex;
    flex-direction:column;
    gap: 6px;
    flex: 1;
    min-width: 0;
}

/* ✅ keep venue line stable (no reflow → no height variance) */
.md-voucher-venue{
    font-weight: 950;
    letter-spacing: -0.01em;
    color: var(--md-text);
    font-size: 1.05rem;
    line-height: 1.2;

    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.md-voucher-title{
    font-weight: 800;
    color: #374151;
    font-size: .95rem;
    line-height: 1.25;

    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow:hidden;
}

/* ✅ enforce consistent minimum content height on mobile */
@media (max-width: 575.98px){
    .md-voucher-body{
        min-height: 150px;
    }
}

.md-voucher-footer{
    margin-top: auto;
    display:flex;
    flex-direction:column;
    gap: 8px;
    padding-top: 8px;
}

.md-voucher-price{
    font-weight: 950;
    color: var(--md-text);
    font-size: 1.05rem;
    line-height: 1;
}

/* ✅ keep tags to a single line (stable card height) */
.md-voucher-tags{
    display:flex;
    flex-wrap: nowrap;
    gap: 6px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 2px;
}
.md-voucher-tags::-webkit-scrollbar{ height: 6px; }
.md-voucher-tags::-webkit-scrollbar-thumb{
    background: rgba(0,0,0,.12);
    border-radius: 999px;
}

.md-voucher-tag{
    display:inline-flex;
    align-items:center;
    padding: 6px 10px;
    border-radius: 999px;
    background: var(--md-surface-subtle);
    border: 1px solid rgba(0,0,0,.06);
    color: var(--md-text);
    font-weight: 850;
    font-size: .78rem;
    line-height: 1;

    white-space: nowrap;
    flex: 0 0 auto;
}

/* ----------------------------
   My Dine Pagination (custom)
   ---------------------------- */
.md-pagination{
    margin-top: 1.25rem;
    display:flex;
    flex-direction:column;
    align-items:center;
    gap: 10px;
}

.md-pagination-meta{
    color: var(--md-muted);
    font-weight: 850;
    font-size: .92rem;
    text-align:center;
}

.md-pagination-list{
    list-style:none;
    padding:0;
    margin:0;
    display:flex;
    gap:8px;
    flex-wrap:wrap;
    justify-content:center;
}

.md-page-link{
    min-width: 42px;
    height: 42px;
    display:inline-flex;
    align-items:center;
    justify-content:center;
    border-radius: 12px;
    border: 1px solid var(--md-border);
    background:#fff;
    color: var(--md-text);
    font-weight: 950;
    text-decoration:none;
    box-shadow: 0 2px 10px rgba(0,0,0,.03);
}

.md-page-link:hover{
    border-color: rgba(0,0,0,.18);
    color: var(--md-text);
}

.md-page-link:focus{ outline:none; }
.md-page-link:focus-visible{
    box-shadow: 0 0 0 .2rem rgba(149,61,150,.18), 0 10px 22px rgba(0,0,0,.10);
}

.md-page-link.is-active{
    background:#111827;
    color:#fff;
    border-color: rgba(0,0,0,.08);
}

.md-page-link.is-disabled{
    opacity:.55;
    pointer-events:none;
}

.md-page-ellipsis{
    min-width: 42px;
    height: 42px;
    display:inline-flex;
    align-items:center;
    justify-content:center;
    border-radius: 12px;
    color: var(--md-muted);
    font-weight: 950;
}

/* =========================================================
   Modal + Transform Flicker Fix (Account / Vouchers)
   ========================================================= */

/* When modal is open, disable transforms ONLY within account/page containers */
html.md-modal-open .md-page .md-card,
html.md-modal-open .md-account-shell,
html.md-modal-open .md-account-content-card,
html.md-modal-open .md-account-nav-card{
    transform: none !important;
    filter: none !important;
    perspective: none !important;
}

/* Never hover-lift structural account layout cards */
.md-account-shell .md-card:hover,
.md-account-nav-card:hover,
.md-account-content-card:hover{
    transform: none !important;
}

/* Optional: in Account vouchers list, keep cards stable */
.md-vouchers-list .md-card:hover{
    transform: none !important;
}

/* Bootstrap modal layering safety */
.modal{ z-index: 2200; }
.modal-backdrop{ z-index: 2190; }
.md-modal{ z-index: 3000; }
