/* ───────────────────────────────────────────────────────────────────
 * Fresh Bazaar — Discovery features
 *
 *  1.  Mega menu  (desktop dropdown + mobile drawer)
 *  2.  Discovery strips  (horizontal scrolling product carousels)
 *  3.  Discovery cards   (slim variant of product card)
 *
 *  This file is loaded after main.css.
 * ─────────────────────────────────────────────────────────────────── */


/* ═══════════════════════════════════════════════════════════════════
 * 1. FAST CUSTOMER-FRIENDLY MEGA MENU
 * ═══════════════════════════════════════════════════════════════════ */

/* main.css hides overflow on this strip; desktop dropdown was getting clipped. */
.category-nav-wrap {
    overflow: visible;
}

.category-nav-flex {
    display: flex;
    align-items: center;
    gap: 12px;
    position: relative;
}

.mega-menu-wrapper {
    position: relative;
    flex-shrink: 0;
    z-index: 260;
}

.mega-menu-trigger {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    min-height: 36px;
    padding: 9px 14px;
    background: var(--green-700);
    color: #fff;
    border: none;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 13.5px;
    font-weight: 800;
    cursor: pointer;
    white-space: nowrap;
    touch-action: manipulation;
    box-shadow: 0 3px 10px rgba(4, 120, 87, .16);
    transition: background .12s ease, box-shadow .12s ease;
}
.mega-menu-trigger:hover,
.mega-menu-open .mega-menu-trigger {
    background: var(--green-800);
    box-shadow: 0 5px 14px rgba(4, 120, 87, .22);
}
.mega-menu-trigger:focus-visible {
    outline: 2px solid var(--green-300);
    outline-offset: 2px;
}
.mega-menu-trigger svg { flex-shrink: 0; }

/* Desktop dropdown */
.mega-menu-panel {
    position: absolute;
    top: calc(100% + 9px);
    left: 0;
    z-index: 280;
    width: min(1120px, calc(100vw - 24px));
    max-height: min(72vh, 620px);
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    background: #fff;
    border: 1px solid rgba(6, 95, 70, .12);
    border-radius: 18px;
    box-shadow: 0 18px 42px rgba(15, 23, 42, .16);
    padding: 18px;
    animation: megaMenuFadeIn .12s ease-out;
}

@keyframes megaMenuFadeIn {
    from { opacity: 0; transform: translateY(-4px); }
    to { opacity: 1; transform: translateY(0); }
}

.mega-menu-panel::-webkit-scrollbar { width: 8px; }
.mega-menu-panel::-webkit-scrollbar-track { background: transparent; }
.mega-menu-panel::-webkit-scrollbar-thumb {
    background: var(--green-200);
    border-radius: 999px;
}

.mega-menu-mobile-head { display: none; }

.mega-menu-close {
    display: none;
    align-items: center;
    justify-content: center;
    width: 42px;
    height: 42px;
    border: 1px solid rgba(6, 95, 70, .10);
    border-radius: 50%;
    background: #fff;
    color: var(--green-900);
    cursor: pointer;
    touch-action: manipulation;
}

.mega-menu-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
    gap: 14px;
}

.mega-menu-column {
    min-width: 0;
    overflow: hidden;
    background: #fff;
    border: 1px solid rgba(6, 95, 70, .10);
    border-radius: 16px;
}

.mega-menu-col-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    min-height: 54px;
    padding: 9px 10px;
    background: linear-gradient(135deg, var(--green-700), var(--green-800));
    color: #fff;
    text-decoration: none;
    font-family: inherit;
    font-size: 14px;
    font-weight: 800;
    line-height: 1.25;
}
.mega-menu-col-heading:hover,
.mega-menu-col-heading:focus-visible,
.mega-menu-col-heading.active {
    color: #fff;
    background: linear-gradient(135deg, var(--green-800), var(--green-900));
    outline: none;
}

.mega-menu-heading-main {
    display: inline-flex;
    align-items: center;
    gap: 9px;
    min-width: 0;
}

.mega-menu-heading-icon,
.mega-menu-sub-image {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    background: rgba(255,255,255,.18);
    color: #fff;
    font-weight: 900;
}

.mega-menu-heading-icon {
    width: 34px;
    height: 34px;
    border-radius: 11px;
    border: 1px solid rgba(255,255,255,.22);
}
.mega-menu-heading-icon img,
.mega-menu-sub-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.mega-menu-heading-text,
.mega-menu-sub-name {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
}

.mega-menu-sub-name {
    white-space: nowrap;
}

.mega-menu-heading-meta {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    gap: 7px;
}

.mega-menu-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 28px;
    height: 22px;
    padding: 0 8px;
    border-radius: 999px;
    background: rgba(255,255,255,.18);
    color: #fff;
    font-size: 11px;
    font-weight: 800;
}

.mega-menu-chevron {
    font-size: 22px;
    line-height: 1;
    opacity: .9;
}

.mega-menu-sublist {
    list-style: none;
    margin: 0;
    padding: 9px;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
}

.mega-menu-sub-link {
    display: flex;
    align-items: center;
    gap: 9px;
    min-width: 0;
    min-height: 42px;
    padding: 5px 8px 5px 5px;
    border: 1px solid transparent;
    border-radius: 13px;
    background: #fff;
    color: var(--green-950, var(--green-900));
    text-decoration: none;
    font-size: 13px;
    font-weight: 750;
    line-height: 1.25;
    touch-action: manipulation;
    transition: background .1s ease, border-color .1s ease, color .1s ease;
}
.mega-menu-sub-link:hover,
.mega-menu-sub-link:focus-visible,
.mega-menu-sub-link.active {
    background: var(--green-50);
    border-color: var(--green-200);
    color: var(--green-800);
    outline: none;
}

.mega-menu-sub-image {
    width: 32px;
    height: 32px;
    border-radius: 11px;
    border: 1px solid rgba(6, 95, 70, .10);
    background: var(--green-50);
    color: var(--green-800);
    font-size: 13px;
}

.mega-menu-backdrop {
    display: none;
}

/* Laptop/desktop: keep it compact and easy to scan. */
@media (min-width: 900px) {
    .mega-menu-panel {
        left: max(0px, min(0px, calc(100vw - 1120px)));
    }

    .mega-menu-column {
        box-shadow: 0 1px 4px rgba(15, 23, 42, .04);
    }

    .mega-menu-sublist {
        max-height: 260px;
        overflow-y: auto;
        overscroll-behavior: contain;
        scrollbar-width: thin;
        scrollbar-color: var(--green-200) transparent;
    }
}

/* Mobile / tablet: old always-open design, only drawer open/close. */
@media (max-width: 899px) {
    .mega-menu-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        z-index: 390;
        background: rgba(15, 23, 42, .42);
    }
    .mega-menu-backdrop[hidden] { display: none; }

    body.mega-menu-body-lock {
        overflow: hidden;
        touch-action: none;
    }

    .mega-menu-trigger {
        min-width: 42px;
        min-height: 38px;
        padding: 9px 12px;
        border-radius: 13px;
    }

    .mega-menu-trigger span {
        position: absolute;
        width: 1px;
        height: 1px;
        padding: 0;
        margin: -1px;
        overflow: hidden;
        clip: rect(0, 0, 0, 0);
        white-space: nowrap;
        border: 0;
    }

    .mega-menu-panel {
        position: fixed;
        inset: 0 auto 0 0;
        width: min(390px, 92vw);
        height: 100dvh;
        max-height: none;
        padding: 0 10px 18px;
        border: none;
        border-right: 1px solid rgba(6, 95, 70, .12);
        border-radius: 0 22px 22px 0;
        z-index: 400;
        background: #f7fffb;
        box-shadow: 14px 0 32px rgba(15, 23, 42, .18);
        animation: mobileMenuSlideIn .16s ease-out;
        -webkit-overflow-scrolling: touch;
    }

    @keyframes mobileMenuSlideIn {
        from { transform: translate3d(-100%, 0, 0); }
        to { transform: translate3d(0, 0, 0); }
    }

    .mega-menu-mobile-head {
        position: sticky;
        top: 0;
        z-index: 2;
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 10px;
        margin: 0 -10px 10px;
        padding: calc(10px + env(safe-area-inset-top, 0px)) 12px 10px;
        background: rgba(247, 255, 251, .96);
        border-bottom: 1px solid rgba(6, 95, 70, .10);
        backdrop-filter: blur(10px);
        -webkit-backdrop-filter: blur(10px);
    }

    .mega-menu-mobile-head strong {
        display: block;
        color: var(--green-900);
        font-size: 17px;
        font-weight: 900;
        line-height: 1.2;
    }

    .mega-menu-mobile-head span {
        display: block;
        color: var(--muted);
        font-size: 12px;
        font-weight: 700;
        margin-top: 2px;
    }

    .mega-menu-close { display: inline-flex; }

    .mega-menu-grid {
        display: flex;
        flex-direction: column;
        gap: 10px;
    }

    .mega-menu-column {
        border-radius: 14px;
        border-color: rgba(6, 95, 70, .12);
        background: #fff;
        box-shadow: 0 1px 3px rgba(15, 23, 42, .04);
    }

    .mega-menu-col-heading {
        min-height: 52px;
        padding: 8px 9px;
        border-radius: 14px 14px 0 0;
        font-size: 13.5px;
    }

    .mega-menu-heading-icon {
        width: 32px;
        height: 32px;
        border-radius: 10px;
    }

    .mega-menu-count {
        min-width: 25px;
        height: 20px;
        padding: 0 7px;
        font-size: 10px;
    }

    .mega-menu-sublist {
        padding: 8px;
        gap: 5px;
    }

    .mega-menu-sub-link {
        min-height: 40px;
        padding: 4px 8px 4px 4px;
        border-radius: 999px;
        font-size: 12.5px;
        background: #fff;
        border-color: rgba(4, 120, 87, .10);
    }

    .mega-menu-sub-link:active {
        background: var(--green-50);
    }

    .mega-menu-sub-image {
        width: 30px;
        height: 30px;
        border-radius: 999px;
    }
}

@media (max-width: 360px) {
    .mega-menu-panel { width: 94vw; }
    .mega-menu-col-heading { font-size: 12.5px; }
    .mega-menu-sub-link { font-size: 12px; }
}

@media (prefers-reduced-motion: reduce) {
    .mega-menu-panel,
    .mega-menu-trigger,
    .mega-menu-sub-link {
        animation: none !important;
        transition: none !important;
    }
}

/* ═══════════════════════════════════════════════════════════════════
 * 2. DISCOVERY STRIP  (horizontal scrolling row)
 * ═══════════════════════════════════════════════════════════════════ */

.discovery-strip-section {
    padding: 36px 0 12px;
}
.discovery-strip-section + .discovery-strip-section {
    padding-top: 12px;
}

.discovery-strip {
    position: relative;
    margin-top: 18px;
}

.discovery-strip-track {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: minmax(180px, 200px);
    gap: 14px;
    overflow-x: auto;
    scroll-snap-type: x proximity;
    scroll-padding-left: 8px;
    padding: 4px 4px 12px;
    /* Hide scrollbar but keep functionality */
    scrollbar-width: thin;
    scrollbar-color: var(--green-200) transparent;
}
.discovery-strip-track::-webkit-scrollbar {
    height: 8px;
}
.discovery-strip-track::-webkit-scrollbar-track {
    background: transparent;
}
.discovery-strip-track::-webkit-scrollbar-thumb {
    background: var(--green-200);
    border-radius: 999px;
}
.discovery-strip-track::-webkit-scrollbar-thumb:hover {
    background: var(--green-400);
}

.discovery-strip-arrow {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 50%;
    background: #fff;
    color: var(--green-800);
    cursor: pointer;
    z-index: 5;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-md);
    transition: opacity 0.2s, transform 0.15s;
}
.discovery-strip-arrow:hover {
    transform: translateY(-50%) scale(1.08);
}
.discovery-strip-arrow.is-hidden {
    opacity: 0;
    pointer-events: none;
}
.discovery-strip-arrow-left { left: -8px; }
.discovery-strip-arrow-right { right: -8px; }

@media (hover: none) {
    /* Touch devices: hide arrows — let users swipe */
    .discovery-strip-arrow { display: none; }
}

.discovery-strip-empty {
    color: var(--muted);
    font-size: 14px;
    margin-top: 12px;
}

/* ═══════════════════════════════════════════════════════════════════
 * 3. DISCOVERY CARD  (slim product card variant)
 * ═══════════════════════════════════════════════════════════════════ */

.discovery-card {
    display: flex;
    flex-direction: column;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    overflow: hidden;
    scroll-snap-align: start;
    transition: transform 0.18s, box-shadow 0.18s, border-color 0.18s;
}
.discovery-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow);
    border-color: var(--green-300);
}

.discovery-card-image {
    position: relative;
    aspect-ratio: 1 / 1;
    display: block;
    background: var(--light);
}
.discovery-card-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.discovery-card-image .image-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--muted-lt);
    font-size: 12px;
}
.discovery-card-image .discount-badge {
    position: absolute;
    top: 6px;
    left: 6px;
    background: var(--orange);
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    padding: 3px 6px;
    border-radius: 999px;
    letter-spacing: 0.02em;
}

.discovery-card-body {
    padding: 10px 12px 12px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.discovery-card-body h3 {
    font-family: inherit;
    font-size: 13.5px;
    font-weight: 600;
    line-height: 1.3;
    margin: 0;
    /* clamp to 2 lines */
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    min-height: 35px;
}
.discovery-card-body h3 a {
    color: var(--dark);
    text-decoration: none;
}
.discovery-card-body h3 a:hover { color: var(--green-700); }

.discovery-card-unit {
    font-size: 11px;
    color: var(--muted);
    margin: 0;
}

.discovery-card-price {
    display: flex;
    align-items: baseline;
    gap: 6px;
    margin-top: 4px;
}
.discovery-card-price strong {
    color: var(--green-900);
    font-size: 15px;
    font-weight: 700;
}
.discovery-card-price span {
    color: var(--muted-lt);
    font-size: 12px;
    text-decoration: line-through;
}

/* ── Discovery card actions: stepper + Add button stacked ── */
.discovery-card-actions {
    margin-top: 8px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

/* Compact quantity stepper — mobile-first.
   IMPORTANT NOTES ON CENTERING:
   1. Mobile browsers (Chrome/Safari on Android & iOS) add their own
      user-agent padding to <button> elements that breaks flex centering
      of single characters like "−" and "+". We explicitly strip every
      possible UA default (`appearance: none`, `padding: 0`, `margin: 0`,
      `border: 0`).
   2. We use `line-height: <button-height>` as the PRIMARY vertical
      centering method (works in 100% of browsers), with flex as a
      defence-in-depth backup. Setting line-height equal to the
      container height forces the character glyph baseline to sit at
      the perfect vertical center.
   3. main.css has a competing `.quantity-control { display: grid }`
      global. We override with higher specificity AND `display: flex`. */

.discovery-card .discovery-quantity-control {
    display: flex !important;
    grid-template-columns: none;
    align-items: stretch;
    width: 100%;
    height: 38px;
    background: #fff;
    border: 1.5px solid var(--green-200);
    border-radius: var(--radius-sm);
    overflow: hidden;
    margin: 0;
    padding: 0;
    user-select: none;
    /* Ensure no leading/trailing whitespace between children adds height */
    font-size: 0;
}
.discovery-card .discovery-quantity-control:focus-within {
    border-color: var(--green-500);
    box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.12);
}

.discovery-card .discovery-quantity-control .quantity-btn {
    /* ── Reset user-agent button defaults aggressively ── */
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    background: var(--green-100);
    color: var(--green-900);
    border: 0;
    margin: 0;
    padding: 0;
    outline: none;
    cursor: pointer;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;

    /* ── Sizing ── */
    flex: 0 0 38px;
    width: 38px;
    height: 38px;
    min-width: 0;
    min-height: 0;

    /* ── PRIMARY centering: line-height = button height ── */
    line-height: 38px;
    text-align: center;
    vertical-align: middle;

    /* ── Backup centering: flex (in case some browser ignores line-height) ── */
    display: flex;
    align-items: center;
    justify-content: center;

    /* ── Typography ── */
    font-family: inherit;
    font-size: 22px;
    font-weight: 900;

    transition: background 0.12s, color 0.12s;
}
.discovery-card .discovery-quantity-control .quantity-btn:hover {
    background: var(--green-300);
    color: var(--green-900);
}
.discovery-card .discovery-quantity-control .quantity-btn:active {
    background: var(--green-400);
}
.discovery-card .discovery-quantity-control .quantity-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.discovery-card .discovery-quantity-input {
    /* ── Reset UA input defaults ── */
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: textfield;
    -webkit-tap-highlight-color: transparent;
    border: 0;
    border-left: 1.5px solid var(--green-200);
    border-right: 1.5px solid var(--green-200);
    margin: 0;
    padding: 0;
    outline: none;

    /* ── Sizing ── */
    flex: 1 1 auto;
    width: 100%;
    height: 38px;
    line-height: 38px;
    min-width: 0;

    /* ── Visuals ── */
    background: #fff;
    text-align: center;
    font-family: inherit;
    font-size: 15px;
    font-weight: 800;
    color: var(--green-900);
}
.discovery-card .discovery-quantity-input::-webkit-outer-spin-button,
.discovery-card .discovery-quantity-input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}
.discovery-quantity-input:focus {
    outline: none;
    background: var(--green-50);
}

.discovery-add-btn {
    width: 100%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 10px;
    background: var(--green-700);
    color: #fff;
    border: none;
    border-radius: var(--radius-xs);
    font-family: inherit;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, transform 0.1s;
}
/* When inside .discovery-card-actions, no top margin (gap handles it).
   The standalone "Out of stock" button keeps its margin. */
.discovery-card-body > .discovery-add-btn {
    margin-top: 8px;
}
.discovery-add-btn:hover { background: var(--green-800); }
.discovery-add-btn:active { transform: scale(0.97); }
.discovery-add-btn:disabled {
    cursor: not-allowed;
    opacity: 0.85;
}
.discovery-add-btn.is-success {
    background: var(--green-600);
}
.discovery-add-btn-disabled {
    background: var(--muted-lt);
}

/* ═══════════════════════════════════════════════════════════════════
 * 4. RESPONSIVE TWEAKS
 * ═══════════════════════════════════════════════════════════════════ */

@media (max-width: 600px) {
    .discovery-strip-track {
        grid-auto-columns: minmax(150px, 165px);
        gap: 10px;
    }
    .discovery-card-body { padding: 8px 10px 10px; }
    .discovery-card-body h3 { font-size: 12.5px; min-height: 32px; }
    .discovery-card-price strong { font-size: 14px; }
    .discovery-strip-section { padding: 24px 0 8px; }
    /* NOTE: Stepper sizes are intentionally NOT overridden here. The
       primary stepper rules above use 38px height + 38px line-height,
       which is the perfect pairing for vertical centering. Changing
       only height in this block (without also updating line-height)
       broke vertical centering on mobile — that's why "−" and "+"
       appeared stuck at the bottom of their buttons. */
    .discovery-add-btn { padding: 8px 10px; font-size: 13px; }
}
