/* =========================================================
   PRODUCT CARDS (shared by shop.php and product.php)
   Product card, wishlist heart, star ratings, variant picker
   and the "Added to cart" popup. Used with product-cards.js.
   Uses the design tokens from each page's base-styles (:root).
   Each block is followed by its own media rules.
   ========================================================= */

/* ---------- CARDS 1: Buttons ---------- */
.btn-primary,
.btn-ghost {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 11px 18px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 700;
    transition: background var(--transition), border-color var(--transition);
}

.btn-primary {
    border: 0;
    background: var(--primary);
    color: #fff;
}

.btn-primary:hover { background: var(--primary-hover); }
.btn-primary:disabled { opacity: .55; cursor: not-allowed; }

.btn-ghost {
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
}

.btn-ghost:hover { border-color: var(--primary); }

@media (max-width: 480px) {
    .btn-primary, .btn-ghost { padding: 10px 14px; font-size: 13px; }
}

/* ---------- CARDS 2: Product grid ---------- */
.products-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 20px;
}

@media (max-width: 1279px) {
    .products-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 640px) {
    .products-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
}

@media (max-width: 360px) {
    .products-grid { gap: 8px; }
}

/* ---------- CARDS 3: Product card ---------- */
.product-card {
    position: relative;
    display: flex;
    flex-direction: column;
    min-width: 0;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--surface);
    overflow: hidden;
    transition: box-shadow var(--transition), transform var(--transition), border-color var(--transition);
}

.product-card:hover {
    border-color: transparent;
    box-shadow: var(--shadow-md);
    transform: translateY(-3px);
}

.card-media {
    position: relative;
    display: block;
    aspect-ratio: 1 / 1;
    background: var(--surface-2);
    overflow: hidden;
}

.card-media img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: opacity var(--transition), transform .4s ease;
}

.card-media .img-alt {
    opacity: 0;
}

/* Products with only a video: the video's first frame with a play badge */
.card-media .card-video {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.card-play {
    position: absolute;
    top: 50%;
    left: 50%;
    display: grid;
    place-items: center;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: rgba(2, 6, 23, .6);
    color: #fff;
    font-size: 15px;
    pointer-events: none;
    transform: translate(-50%, -50%);
}

@media (hover: hover) {
    .product-card:hover .card-media .img-alt { opacity: 1; }
    .product-card:hover .card-media img:only-of-type { transform: scale(1.04); }
}

.card-noimg {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    color: var(--text-light);
    font-size: 34px;
    opacity: .5;
}

.card-noimg[hidden] { display: none; }

.card-badges {
    position: absolute;
    top: 10px;
    left: 10px;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 5px;
}

.card-badge {
    padding: 3px 8px;
    border-radius: 6px;
    background: var(--text);
    color: var(--surface);
    font-size: 11px;
    font-weight: 800;
    letter-spacing: .3px;
    text-transform: uppercase;
}

.card-badge.sale { background: var(--danger); color: #fff; }
.card-badge.new { background: var(--accent); color: #fff; }
.card-badge.offer { background: var(--brand-orange); color: #fff; }
.card-badge.quote { background: #475569; color: #fff; }

.card-body {
    display: flex;
    flex: 1;
    flex-direction: column;
    gap: 6px;
    padding: 14px;
}

.card-cat {
    overflow: hidden;
    color: var(--text-light);
    font-size: 12px;
    font-weight: 600;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.card-cat:hover { color: var(--primary); }

.card-title {
    display: -webkit-box;
    margin: 0;
    overflow: hidden;
    font-size: 15px;
    font-weight: 700;
    line-height: 1.35;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.card-title a:hover { color: var(--primary); }

.card-desc,
.card-features {
    display: none;
}

.card-options {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 5px;
    min-height: 18px;
    color: var(--text-light);
    font-size: 12px;
}

.swatch {
    width: 16px;
    height: 16px;
    border: 1px solid rgba(15, 23, 42, .2);
    border-radius: 50%;
    background: var(--sw, #ccc);
}

/* Picture swatch: the colour's own photo as a small rectangle */
.swatch.is-img {
    width: 22px;
    height: 16px;
    border-radius: 3px;
    background: var(--surface-2) center / cover no-repeat;
}

.card-foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-top: auto;
    padding-top: 8px;
}

.card-price {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 2px 8px;
    min-width: 0;
}

.price-now {
    color: var(--text);
    font-size: 17px;
    font-weight: 800;
}

.price-now.on-sale { color: var(--danger); }

.price-was {
    color: var(--text-light);
    font-size: 13px;
    text-decoration: line-through;
}

.price-ask {
    color: var(--text-light);
    font-size: 13px;
    font-weight: 600;
}

.card-cart {
    display: inline-flex;
    flex: 0 0 auto;
    align-items: center;
    justify-content: center;
    gap: 7px;
    height: 38px;
    padding: 0 14px;
    border: 0;
    border-radius: var(--radius-sm);
    background: var(--primary);
    color: #fff;
    font-size: 13px;
    font-weight: 700;
    transition: background var(--transition), transform var(--transition);
}

.card-cart:hover { background: var(--primary-hover); }
.card-cart:active { transform: scale(.96); }

.card-cart.is-quote {
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text);
}

.card-cart.is-added { background: var(--accent); }

.card-cart:disabled {
    opacity: .75;
    cursor: wait;
}

@media (max-width: 640px) {
    .card-body { gap: 4px; padding: 10px; }
    .card-title { font-size: 13px; }
    .card-cat { font-size: 11px; }
    .card-badges { top: 6px; left: 6px; gap: 4px; }
    .card-badge { padding: 2px 6px; font-size: 10px; }
    .price-now { font-size: 14px; }
    .price-was { font-size: 11px; }
    .card-cart { width: 36px; height: 36px; padding: 0; }
    .card-cart span { display: none; }
    .card-foot { gap: 6px; }
    .swatch { width: 13px; height: 13px; }
    .swatch.is-img { width: 18px; height: 13px; }
}

@media (max-width: 360px) {
    .card-body { padding: 8px; }
    .card-cart { width: 32px; height: 32px; }
}

/* ---------- CARDS 4: Wishlist heart ---------- */
.card-wish {
    position: absolute;
    top: 10px;
    right: 10px;
    z-index: 2;
    display: grid;
    place-items: center;
    width: 36px;
    height: 36px;
    border: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, .92);
    color: #0f172a;
    font-size: 16px;
    box-shadow: 0 2px 8px rgba(15, 23, 42, .15);
    transition: transform var(--transition), color var(--transition);
}

[data-theme="dark"] .card-wish {
    background: rgba(15, 23, 42, .85);
    color: #f8fafc;
}

.card-wish:hover { transform: scale(1.08); color: var(--danger); }

[data-wish][aria-pressed="true"] { color: var(--danger); }
[data-wish][aria-pressed="true"] i { animation: wish-pop .3s ease; }

[data-wish]:disabled { cursor: wait; opacity: .7; }

@keyframes wish-pop {
    50% { transform: scale(1.35); }
}

@media (max-width: 640px) {
    .card-wish { top: 6px; right: 6px; width: 30px; height: 30px; font-size: 13px; }
}

/* ---------- CARDS 5: Star ratings ---------- */
.stars {
    display: inline-flex;
    gap: 2px;
    color: #f59e0b;
    font-size: 12px;
    line-height: 1;
}

.card-rating {
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--text-light);
    font-size: 12px;
}

@media (max-width: 640px) {
    .stars { font-size: 10px; }
    .card-rating { gap: 4px; font-size: 11px; }
}

/* ---------- CARDS 6: List view ---------- */
.products-grid.is-list {
    grid-template-columns: minmax(0, 1fr);
    gap: 14px;
}

.products-grid.is-list .product-card { flex-direction: row; }

.products-grid.is-list .card-media {
    flex: 0 0 220px;
    aspect-ratio: auto;
    min-height: 220px;
}

.products-grid.is-list .card-wish { left: 172px; right: auto; }

.products-grid.is-list .card-body { padding: 18px 20px; }

.products-grid.is-list .card-title { font-size: 18px; }

.products-grid.is-list .card-desc {
    display: -webkit-box;
    margin: 2px 0;
    overflow: hidden;
    color: var(--text-light);
    font-size: 14px;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
}

.products-grid.is-list .card-features {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.products-grid.is-list .card-features li {
    padding: 3px 9px;
    border-radius: 999px;
    background: var(--surface-2);
    color: var(--text-light);
    font-size: 12px;
}

@media (max-width: 768px) {
    .products-grid.is-list .card-media { flex-basis: 150px; min-height: 160px; }
    .products-grid.is-list .card-wish { left: 108px; }
    .products-grid.is-list .card-features { display: none; }
}

/* ---------- CARDS 7: Variant picker modal ---------- */
.shop-modal {
    position: fixed;
    inset: 0;
    z-index: 1300;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.shop-modal[hidden] { display: none; }

.shop-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(2, 6, 23, .6);
}

.shop-modal-panel {
    position: relative;
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr);
    width: min(860px, 100%);
    max-height: calc(100vh - 40px);
    border-radius: var(--radius-lg);
    background: var(--surface);
    box-shadow: var(--shadow-md);
    overflow: hidden;
    animation: rm-pop .2s ease;
}

@keyframes rm-pop {
    from { opacity: 0; transform: translateY(12px) scale(.98); }
    to { opacity: 1; transform: none; }
}

.modal-close {
    position: absolute;
    top: 12px;
    right: 12px;
    z-index: 2;
    width: 38px;
    height: 38px;
    border: 1px solid var(--border);
    border-radius: 50%;
    background: var(--surface);
    color: var(--text);
}

.vm-media {
    position: relative;
    background: var(--surface-2);
}

.vm-media img {
    width: 100%;
    height: 100%;
    min-height: 320px;
    object-fit: cover;
}

.vm-media img[hidden] { display: none; }
.vm-media .card-noimg { min-height: 200px; }

.vm-body {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 26px 24px 22px;
    overflow-y: auto;
}

.vm-cat {
    margin: 0;
    color: var(--text-light);
    font-size: 13px;
    font-weight: 600;
}

.vm-body h2 {
    margin: 0;
    padding-right: 36px;
    font-size: 22px;
    line-height: 1.25;
}

.vm-offer {
    margin: 0;
    color: var(--brand-orange);
    font-size: 13px;
    font-weight: 700;
}

.vm-group {
    margin: 0;
    padding: 0;
    border: 0;
}

.vm-group legend {
    margin-bottom: 8px;
    padding: 0;
    font-size: 14px;
    font-weight: 700;
}

.vm-group legend span {
    color: var(--text-light);
    font-weight: 500;
}

.vm-options {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.vm-pill {
    min-width: 44px;
    padding: 8px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    font-size: 14px;
    font-weight: 600;
}

.vm-swatch {
    width: 34px;
    height: 34px;
    padding: 0;
    border: 2px solid var(--surface);
    border-radius: 50%;
    background: var(--sw, #ccc);
    box-shadow: 0 0 0 1px var(--border);
}

.vm-pill:hover,
.vm-swatch:hover { box-shadow: 0 0 0 1px var(--primary); }

.vm-pill[aria-pressed="true"] {
    border-color: var(--primary);
    background: var(--primary);
    color: #fff;
}

.vm-swatch[aria-pressed="true"] { box-shadow: 0 0 0 2px var(--primary); }

/* Picture swatch in the picker / product page: small photo rectangle */
.vm-swatch.is-img {
    width: 44px;
    height: 54px;
    border-radius: 8px;
    background: var(--surface-2) center / cover no-repeat;
}

.vm-swatch.is-img[aria-pressed="true"] { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--primary); }

.vm-qty {
    display: inline-flex;
    align-self: flex-start;
    align-items: center;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    overflow: hidden;
}

.vm-qty button {
    width: 40px;
    height: 40px;
    border: 0;
    background: var(--surface-2);
    color: var(--text);
}

.vm-qty input {
    width: 52px;
    height: 40px;
    border: 0;
    background: var(--surface);
    color: var(--text);
    font-weight: 700;
    text-align: center;
    -moz-appearance: textfield;
}

.vm-qty input::-webkit-outer-spin-button,
.vm-qty input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

.vm-hint {
    min-height: 20px;
    margin: 0;
    color: var(--text-light);
    font-size: 13px;
}

.vm-hint.is-error {
    color: var(--danger);
    font-weight: 600;
}

.vm-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: auto;
}

.vm-actions .btn-primary { flex: 1; }

@media (max-width: 768px) {
    .shop-modal { align-items: flex-end; padding: 0; }
    .shop-modal-panel {
        grid-template-columns: minmax(0, 1fr);
        grid-template-rows: auto minmax(0, 1fr);
        max-height: 92vh;
        border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    }
    .vm-media img { min-height: 0; height: 200px; }
    .vm-body { padding: 18px 16px 20px; }
    .vm-body h2 { font-size: 19px; }
}

@media (max-width: 380px) {
    .vm-media img { height: 160px; }
    .vm-actions { flex-direction: column; }
}

/* ---------- CARDS 8: "Added to cart" popup ---------- */
/* Same bottom sheet on every screen: full width on phones, centred (480px) on tablets & laptops */
.added-pop {
    position: fixed;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 1350;
    display: flex;
    flex-direction: column;
    gap: 14px;
    width: min(480px, 100%);
    margin: 0 auto;
    padding: 16px 20px calc(18px + env(safe-area-inset-bottom));
    border: 1px solid var(--border);
    border-bottom: 0;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    background: var(--surface);
    box-shadow: 0 -12px 40px rgba(15, 23, 42, .22);
    overflow: hidden;
    animation: ap-in .28s cubic-bezier(.2, .8, .2, 1);
}

.added-pop[hidden] { display: none; }

@keyframes ap-in {
    from { opacity: 0; transform: translateY(18px); }
    to { opacity: 1; transform: none; }
}

.ap-head {
    display: flex;
    align-items: center;
    gap: 10px;
}

.ap-head strong { flex: 1; font-size: 16px; }

.ap-check {
    display: grid;
    flex: 0 0 auto;
    place-items: center;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    font-size: 13px;
}

.ap-close {
    display: grid;
    flex: 0 0 auto;
    place-items: center;
    width: 32px;
    height: 32px;
    border: 0;
    border-radius: 50%;
    background: var(--surface-2);
    color: var(--text);
}

.ap-close:hover { background: var(--border); }

.ap-item {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 12px;
    border-radius: var(--radius-md);
    background: var(--surface-2);
}

.ap-thumb {
    display: grid;
    flex: 0 0 72px;
    place-items: center;
    width: 72px;
    height: 72px;
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text-light);
    font-size: 22px;
    overflow: hidden;
}

.ap-thumb img { width: 100%; height: 100%; object-fit: cover; }
.ap-thumb img[hidden], .ap-thumb i[hidden] { display: none; }

.ap-text {
    display: flex;
    flex-direction: column;
    gap: 3px;
    min-width: 0;
    font-size: 13px;
}

.ap-name {
    display: -webkit-box;
    overflow: hidden;
    font-size: 14px;
    font-weight: 700;
    line-height: 1.35;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.ap-variant { color: var(--text-light); }
.ap-variant[hidden] { display: none; }
.ap-line { color: var(--text); font-weight: 700; }

.ap-summary {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 10px;
    color: var(--text-light);
    font-size: 13px;
}

.ap-summary strong { margin-left: 4px; color: var(--text); font-size: 16px; }

.ap-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.ap-actions > * { padding: 12px; font-size: 14px; }

/* Thin bar that runs down until the popup closes (pauses while hovered / touched) */
.ap-timer {
    position: absolute;
    right: 0;
    bottom: 0;
    left: 0;
    height: 3px;
    background: var(--accent);
    transform-origin: left;
    animation: ap-timer var(--pop-time, 6s) linear forwards;
    top: 0;
    bottom: auto;
}

.added-pop.is-paused .ap-timer { animation-play-state: paused; opacity: .4; }

@keyframes ap-timer {
    from { transform: scaleX(1); }
    to { transform: scaleX(0); }
}

/* Phones: edge to edge, a little tighter */
@media (max-width: 640px) {
    .added-pop {
        width: 100%;
        padding: 14px 16px calc(16px + env(safe-area-inset-bottom));
        border-width: 1px 0 0;
    }
    .ap-thumb { flex-basis: 60px; width: 60px; height: 60px; }
}

@media (max-width: 360px) {
    .ap-actions { grid-template-columns: 1fr; }
}
/* ---------- CARDS 9: Small notice toast (wishlist messages) ---------- */
.rm-toast {
    position: fixed;
    left: 50%;
    bottom: 24px;
    z-index: 1360;
    max-width: calc(100vw - 32px);
    padding: 10px 18px;
    border-radius: 999px;
    background: var(--text);
    color: var(--surface);
    font-size: 14px;
    font-weight: 600;
    box-shadow: var(--shadow-md);
    transform: translateX(-50%);
    animation: rm-pop .2s ease;
}

.rm-toast[hidden] { display: none; }

@media (max-width: 640px) {
    .rm-toast { bottom: 16px; font-size: 13px; }
}
