/*
 |--------------------------------------------------------------------------
 | AGMULA Flutter Product Card Parity
 |--------------------------------------------------------------------------
 | Isolated card layer based on Flutter BuyerProductGridCard.
 | Loaded after legacy/theme CSS so only .agm-flutter-* product cards are
 | changed. Homepage, public marketplace, and buyer marketplace share it.
 */

:root {
    --agm-card-forest: #0b5a34;
    --agm-card-leaf: #43a047;
    --agm-card-surface: #fffefa;
    --agm-card-mint: #eaf5ec;
    --agm-card-ink: #15372a;
    --agm-card-muted: #6c7a72;
    --agm-card-outline: #dde6de;
    --agm-card-warning: #b8751a;
    --agm-card-danger: #b44343;
}

/* Flutter grid behavior: desktop web can show more columns, while phone
   widths keep the Flutter 2-column layout from 360px upward. */
.agm-ref-product-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;
}

body.agmula-theme .marketplace-product-grid:not(.is-list) {
    gap: 12px;
}

body.agmula-theme .marketplace-product-card.agm-flutter-product-card {
    min-width: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    border: 1px solid var(--agm-card-outline) !important;
    border-radius: 21px !important;
    background: var(--agm-card-surface) !important;
    box-shadow: 0 2px 8px rgba(0, 0, 0, .06) !important;
    transition: transform 160ms ease, box-shadow 160ms ease, border-color 160ms ease;
}

body.agmula-theme .marketplace-product-card.agm-flutter-product-card:hover {
    transform: translateY(-2px);
    border-color: #cddacf !important;
    box-shadow: 0 8px 20px rgba(11, 90, 52, .09) !important;
}

body.agmula-theme .agm-flutter-product-card .marketplace-product-image,
body.agmula-theme .agm-flutter-product-card .agm-flutter-product-card__image {
    position: relative;
    width: 100%;
    height: auto !important;
    min-height: 0 !important;
    aspect-ratio: 1.17 / 1 !important;
    flex: 0 0 auto;
    display: block;
    overflow: hidden;
    border-radius: 0 !important;
    background: var(--agm-card-mint);
}

body.agmula-theme .agm-flutter-product-card .marketplace-product-image > img {
    width: 100% !important;
    height: 100% !important;
    object-fit: cover;
    transition: transform 180ms ease;
}

body.agmula-theme .agm-flutter-product-card:hover .marketplace-product-image > img {
    transform: scale(1.018);
}

body.agmula-theme .agm-flutter-product-card__placeholder {
    width: 100%;
    height: 100%;
    display: grid;
    place-items: center;
    background: var(--agm-card-mint);
    color: var(--agm-card-leaf);
}

body.agmula-theme .agm-flutter-product-card__placeholder svg {
    width: 36px;
    height: 36px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.7;
    stroke-linecap: round;
    stroke-linejoin: round;
}

body.agmula-theme .agm-flutter-favorite {
    position: absolute;
    z-index: 4;
    top: 7px;
    right: 7px;
    width: 30px;
    height: 30px;
    display: grid;
    place-items: center;
    border-radius: 999px;
    background: rgba(255, 255, 255, .96);
    color: var(--agm-card-forest);
    box-shadow: 0 2px 8px rgba(0, 0, 0, .08);
    pointer-events: none;
}

body.agmula-theme .agm-flutter-favorite svg {
    width: 17px;
    height: 17px;
    fill: transparent;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
}

body.agmula-theme .agm-flutter-favorite.is-favorite {
    color: #ef5350;
}

body.agmula-theme .agm-flutter-favorite.is-favorite svg {
    fill: currentColor;
}

body.agmula-theme .agm-flutter-product-card .agm-flutter-product-card__sold-out {
    top: auto !important;
    right: auto !important;
    bottom: 8px !important;
    left: 8px !important;
    min-height: 0;
    padding: 4px 7px !important;
    border: 0 !important;
    border-radius: 999px !important;
    background: rgba(255, 240, 239, .96) !important;
    color: var(--agm-card-danger) !important;
    font-size: .58rem !important;
    font-weight: 850 !important;
    box-shadow: 0 2px 8px rgba(0, 0, 0, .06) !important;
}

body.agmula-theme .agm-flutter-product-card .marketplace-product-body,
body.agmula-theme .agm-flutter-product-card .agm-flutter-product-card__body {
    min-width: 0;
    min-height: 126px;
    display: flex !important;
    flex: 1 1 auto;
    flex-direction: column;
    padding: 10px 12px 11px !important;
    overflow: hidden;
    background: var(--agm-card-surface);
}

body.agmula-theme .agm-flutter-product-card .lux-card-meta.agm-flutter-product-card__category {
    display: block !important;
    min-width: 0;
    margin: 0 !important;
    padding: 0 !important;
    overflow: hidden;
    color: var(--agm-card-leaf) !important;
    background: transparent !important;
    font-size: 9.5px !important;
    font-weight: 900 !important;
    line-height: 1.2;
    letter-spacing: .7px !important;
    text-transform: uppercase;
    text-overflow: ellipsis;
    white-space: nowrap;
}

body.agmula-theme .agm-flutter-product-card h3 {
    min-width: 0;
    min-height: 0 !important;
    margin: 3px 0 3px !important;
    padding: 0 !important;
    overflow: hidden;
    color: var(--agm-card-ink) !important;
    font-size: .875rem !important;
    font-weight: 800 !important;
    line-height: 1.16 !important;
    letter-spacing: 0 !important;
    text-overflow: ellipsis;
    white-space: nowrap;
}

body.agmula-theme .agm-flutter-product-card h3 a {
    display: block;
    min-width: 0;
    overflow: hidden;
    color: var(--agm-card-ink) !important;
    text-overflow: ellipsis;
    white-space: nowrap;
}

body.agmula-theme .agm-flutter-product-card .lux-card-farm.agm-flutter-seller {
    min-width: 0;
    max-width: 100%;
    display: flex !important;
    align-items: center;
    gap: 5px !important;
    margin: 0 !important;
    padding: 2px 0 !important;
    overflow: hidden;
    color: var(--agm-card-forest) !important;
    background: transparent !important;
    font-size: 11.5px !important;
    font-weight: 800 !important;
    line-height: 1.25;
    text-decoration: none;
}

body.agmula-theme .agm-flutter-seller__avatar {
    position: relative;
    width: 16px;
    height: 16px;
    flex: 0 0 16px;
    display: grid;
    place-items: center;
    border-radius: 999px;
    background: var(--agm-card-mint);
    color: var(--agm-card-forest);
    font-size: 8px;
    font-weight: 900;
}

body.agmula-theme .agm-flutter-seller__verified {
    position: absolute;
    right: -3px;
    bottom: -3px;
    width: 8px !important;
    height: 8px !important;
    object-fit: contain;
    border-radius: 999px;
    background: var(--agm-card-surface);
}

body.agmula-theme .agm-flutter-seller__name {
    min-width: 0;
    flex: 1 1 auto;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

body.agmula-theme .agm-flutter-seller__certified {
    width: 13px !important;
    height: 13px !important;
    flex: 0 0 13px;
    object-fit: contain;
}

body.agmula-theme .agm-flutter-product-card .agm-flutter-seller__chevron {
    width: 15px !important;
    height: 15px !important;
    flex: 0 0 15px;
    fill: none;
    stroke: var(--agm-card-forest);
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

body.agmula-theme .agm-flutter-social {
    min-width: 0;
    display: flex !important;
    align-items: center;
    gap: 7px;
    margin-top: 3px;
    overflow: hidden;
    color: var(--agm-card-muted);
    font-size: 10.5px;
    line-height: 1.2;
}

body.agmula-theme .agm-flutter-social__rating,
body.agmula-theme .agm-flutter-social__sold {
    min-width: 0;
    display: inline-flex;
    align-items: center;
    gap: 2px;
    font-weight: 800;
    white-space: nowrap;
}

body.agmula-theme .agm-flutter-social__rating small {
    color: var(--agm-card-muted);
    font-size: 10px;
    font-weight: 500;
}

body.agmula-theme .agm-flutter-social__star {
    color: var(--agm-card-warning);
    font-size: 13px;
    line-height: 1;
}

body.agmula-theme .agm-flutter-social__sold {
    overflow: hidden;
}

body.agmula-theme .agm-flutter-social__sold svg {
    width: 12px;
    height: 12px;
    flex: 0 0 12px;
    fill: none;
    stroke: var(--agm-card-muted);
    stroke-width: 1.7;
    stroke-linecap: round;
    stroke-linejoin: round;
}

body.agmula-theme .agm-flutter-social__sold span {
    overflow: hidden;
    text-overflow: ellipsis;
}

body.agmula-theme .agm-flutter-product-card .marketplace-product-footer.agm-flutter-product-card__footer {
    min-width: 0;
    display: flex !important;
    align-items: center;
    gap: 8px;
    margin-top: auto !important;
    padding: 7px 0 0 !important;
    border: 0 !important;
    background: transparent !important;
}

body.agmula-theme .agm-flutter-product-card .agm-flutter-product-card__footer strong {
    min-width: 0;
    display: block;
    overflow: hidden;
    color: var(--agm-card-forest) !important;
    font-size: .9rem !important;
    font-weight: 900 !important;
    line-height: 1.15;
    text-overflow: ellipsis;
    white-space: nowrap;
}

body.agmula-theme .agm-flutter-product-card .agm-flutter-product-card__footer strong span {
    color: inherit !important;
    font: inherit !important;
}

body.agmula-theme .agm-flutter-product-card .agm-flutter-view {
    display: none !important;
}

/* Existing list view remains useful and is not forced into the phone grid card. */
body.agmula-theme .marketplace-product-grid.is-list .agm-flutter-product-card {
    border-radius: 17px !important;
}

body.agmula-theme .marketplace-product-grid.is-list .agm-flutter-product-card .agm-flutter-favorite {
    top: 8px;
    right: 8px;
}

body.agmula-theme .marketplace-product-grid.is-list .agm-flutter-product-card .agm-flutter-view {
    display: inline-flex !important;
}

/* Large tablet / small desktop. */
@media (max-width: 1180px) and (min-width: 901px) {
    .agm-ref-product-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}

/* Tablet portrait and phone landscape: two Flutter-like columns. */
@media (max-width: 900px) {
    .agm-ref-product-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
        gap: 12px;
    }

    body.agmula-theme .marketplace-catalog-results .marketplace-product-grid.is-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
        gap: 12px !important;
    }
}

/* Phone: keep 2 columns from 360px, just like Flutter. */
@media (max-width: 600px) {
    body.agmula-theme .agm-flutter-product-card .marketplace-product-body,
    body.agmula-theme .agm-flutter-product-card .agm-flutter-product-card__body {
        min-height: 122px;
        padding: 10px 10px 11px !important;
    }

    body.agmula-theme .agm-flutter-product-card h3 {
        font-size: .82rem !important;
    }

    body.agmula-theme .agm-flutter-product-card .lux-card-farm.agm-flutter-seller {
        font-size: 10.5px !important;
    }

    body.agmula-theme .agm-flutter-product-card .agm-flutter-product-card__footer strong {
        font-size: .86rem !important;
    }
}

/* Flutter falls back to one card below 360 logical pixels. */
@media (max-width: 359px) {
    .agm-ref-product-grid,
    body.agmula-theme .marketplace-catalog-results .marketplace-product-grid.is-grid {
        grid-template-columns: 1fr !important;
    }

    body.agmula-theme .agm-flutter-product-card .marketplace-product-body,
    body.agmula-theme .agm-flutter-product-card .agm-flutter-product-card__body {
        min-height: 126px;
    }
}

/* Large-screen card refinement.
   Preserve the Flutter proportions rather than enlarging cards aggressively. */
@media (min-width: 1440px) {
    .agm-ref-product-grid {
        gap: 20px;
    }

    body.agmula-theme .marketplace-product-card.agm-flutter-product-card {
        border-radius: 21px !important;
    }

    body.agmula-theme .agm-flutter-product-card .marketplace-product-body,
    body.agmula-theme .agm-flutter-product-card .agm-flutter-product-card__body {
        min-height: 128px;
        padding: 11px 12px 12px !important;
    }

    body.agmula-theme .agm-flutter-product-card .lux-card-meta.agm-flutter-product-card__category {
        font-size: 9.5px !important;
    }

    body.agmula-theme .agm-flutter-product-card h3 {
        font-size: .88rem !important;
    }

    body.agmula-theme .agm-flutter-product-card .lux-card-farm.agm-flutter-seller {
        font-size: 11px !important;
    }

    body.agmula-theme .agm-flutter-social {
        font-size: 10.5px;
    }

    body.agmula-theme .agm-flutter-product-card .agm-flutter-product-card__footer strong {
        font-size: .92rem !important;
    }

    body.agmula-theme .agm-flutter-favorite {
        width: 30px;
        height: 30px;
    }
}

@media (min-width: 1920px) {
    .agm-ref-product-grid {
        gap: 22px;
    }

    body.agmula-theme .agm-flutter-product-card .marketplace-product-body,
    body.agmula-theme .agm-flutter-product-card .agm-flutter-product-card__body {
        min-height: 132px;
    }
}

/* Reference hover motion — desktop/mouse only. */
@media (hover: hover) and (pointer: fine) {
    body.agmula-theme .marketplace-product-card.agm-flutter-product-card {
        transition: transform .22s cubic-bezier(.2,.75,.2,1), box-shadow .22s ease, border-color .22s ease;
    }

    body.agmula-theme .marketplace-product-card.agm-flutter-product-card:hover {
        transform: translateY(-6px);
        border-color: #cddccf;
        box-shadow: 0 16px 34px rgba(17,63,37,.12);
    }

    body.agmula-theme .agm-flutter-product-card:hover .marketplace-product-image > img {
        transform: scale(1.025);
    }

    body.agmula-theme .agm-flutter-product-card .agm-flutter-heart {
        transition: transform .18s ease, background .18s ease, box-shadow .18s ease;
    }

    body.agmula-theme .agm-flutter-product-card:hover .agm-flutter-heart {
        transform: translateY(-1px) scale(1.05);
        box-shadow: 0 6px 14px rgba(17,63,37,.12);
    }
}

@media (prefers-reduced-motion: reduce) {
    body.agmula-theme .marketplace-product-card.agm-flutter-product-card,
    body.agmula-theme .agm-flutter-product-card .marketplace-product-image > img,
    body.agmula-theme .agm-flutter-product-card .agm-flutter-heart {
        transition-duration: .001ms !important;
    }
}
