/* ==========================================================================
   Canonical Product Card — static/css/product_card.css
   Single source of truth for every product grid on the storefront.
   Loaded once, globally, from store/templates/store/main.html.

   Self-contained on purpose: the only external variable it relies on is
   --primary-color (set globally in main.html from SiteSettings), so this
   file works identically no matter which page includes the card partial —
   it never depends on a host template's own local CSS variables.
   ========================================================================== */

.product-card {
    --pc-primary: var(--primary-color, #2E4220);
    --pc-primary-soft: color-mix(in srgb, var(--pc-primary) 14%, white);
    --pc-primary-glow: color-mix(in srgb, var(--pc-primary) 35%, transparent);
    --pc-radius: 18px;
    --pc-radius-pill: 999px;
    --pc-border: rgba(15, 23, 42, 0.08);
    --pc-text-heading: #1c1a17;
    --pc-text-muted: #6b7280;

    background: #ffffff;
    border-radius: var(--pc-radius);
    border: 1.5px solid var(--pc-border);
    overflow: hidden;
    box-shadow: 0 6px 20px rgba(15, 23, 42, 0.06);
    transition: transform 0.35s cubic-bezier(0.16, 1, 0.3, 1), box-shadow 0.35s cubic-bezier(0.16, 1, 0.3, 1), border-color 0.35s ease;
    height: 100%;
    width: 100%;
    position: relative;
    display: flex;
    flex-direction: column;
}

.product-card:hover {
    transform: translateY(-6px);
    box-shadow: 0 18px 36px rgba(15, 23, 42, 0.14);
    border-color: var(--pc-primary-glow);
}

/* ============ Image area ============ */
.product-card .product-image {
    width: 100%;
    aspect-ratio: 1 / 1;
    overflow: hidden;
    position: relative;
    background: linear-gradient(135deg, #f1f5f9 0%, #eef1f4 50%, #f1f5f9 100%);
}

.product-image-link {
    display: block;
    width: 100%;
    height: 100%;
}

.product-card .product-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center;
    display: block;
    transition: transform 0.6s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.3s ease;
    opacity: 0;
}

.product-card .product-img.is-loaded {
    opacity: 1;
}

.product-card:hover .product-img {
    transform: scale(1.07);
}

/* No image / broken image fallback — never the browser's broken-image icon. */
.product-img-fallback {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f1f5f9;
    color: #cbd5e1;
    font-size: 2.4rem;
}

.product-image.img-fallback {
    background: #f1f5f9;
}

.noscript-pc-fix { display: none; }

/* ============ Wishlist heart ============ */
.card-wishlist-btn {
    position: absolute;
    top: 12px;
    inset-inline-end: 12px;
    z-index: 5;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.8);
    color: #94a3b8;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    padding: 0;
    box-shadow: 0 6px 16px rgba(15, 23, 42, 0.12);
    transition: all 0.25s ease;
}

.card-wishlist-btn:focus-visible {
    outline: 2px solid var(--pc-primary);
    outline-offset: 2px;
}

.card-wishlist-btn:hover {
    transform: scale(1.12);
    background: #ffffff;
    color: #ef4444;
    box-shadow: 0 8px 20px rgba(239, 68, 68, 0.3);
}

.card-wishlist-btn.active { color: #ef4444; background: #ffffff; }

.card-wishlist-btn.active i { animation: pcHeartPulse 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275); }

@keyframes pcHeartPulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.35); }
    100% { transform: scale(1); }
}

/* Out-of-stock, not-yet-favorited: kept visible but inert (removal of an
   existing favorite must always still work — see the template condition
   that only adds .is-disabled when the product is NOT already wishlisted). */
.card-wishlist-btn.is-disabled { cursor: not-allowed; color: #d1d5db; }
.card-wishlist-btn.is-disabled:hover { transform: none; color: #d1d5db; background: rgba(255, 255, 255, 0.75); box-shadow: 0 6px 16px rgba(15, 23, 42, 0.12); }

/* ============ Badges (discount / OOS / rating) ============ */
.discount-tag {
    position: absolute;
    top: 12px;
    inset-inline-start: 12px;
    background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
    color: #ffffff;
    padding: 4px 12px;
    border-radius: var(--pc-radius-pill);
    font-weight: 800;
    font-size: 0.72rem;
    letter-spacing: 0.02em;
    z-index: 2;
    box-shadow: 0 6px 14px rgba(239, 68, 68, 0.35);
}

.out-of-stock-badge {
    position: absolute;
    top: 12px;
    inset-inline-start: 12px;
    z-index: 6;
    display: inline-flex;
    align-items: center;
    background: #dc2626;
    color: #ffffff;
    padding: 4px 11px;
    border-radius: var(--pc-radius-pill);
    font-weight: 800;
    font-size: 0.72rem;
    line-height: 1.2;
    letter-spacing: 0.02em;
    white-space: nowrap;
    max-width: calc(100% - 74px);
    overflow: hidden;
    text-overflow: ellipsis;
    box-shadow: 0 6px 14px rgba(220, 38, 38, 0.32);
    pointer-events: none;
}

.product-image.is-out-of-stock .discount-tag { top: 46px; }

.card-rating-badge {
    position: absolute;
    bottom: 10px;
    inset-inline-start: 10px;
    z-index: 6;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    color: #92400e;
    padding: 4px 9px;
    border-radius: var(--pc-radius-pill);
    font-size: 0.74rem;
    font-weight: 800;
    line-height: 1;
    box-shadow: 0 6px 14px rgba(15, 23, 42, 0.18);
}

.card-rating-badge i { color: #f59e0b; font-size: 0.78rem; }
.card-rating-count { font-weight: 700; color: #a16207; font-size: 0.7rem; }

.price-row {
    position: absolute;
    bottom: 10px;
    inset-inline-end: 10px;
    z-index: 6;
    display: flex;
    align-items: baseline;
    justify-content: center;
    gap: 5px;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    padding: 4px 9px;
    border-radius: var(--pc-radius-pill);
    box-shadow: 0 6px 14px rgba(15, 23, 42, 0.18);
}

.old-price-text { text-decoration: line-through; font-size: 0.68rem; color: #94a3b8; font-weight: 600; }
.current-price { font-weight: 900; font-size: 0.95rem; color: var(--pc-text-heading); white-space: nowrap; }
.currency-badge {
    display: inline-flex; align-items: center; justify-content: center;
    padding: 2px 7px; border-radius: var(--pc-radius-pill);
    background: var(--pc-primary); color: #ffffff;
    font-size: 0.62rem; font-weight: 800; letter-spacing: 0.03em;
}

/* ============ Info section ============ */
.product-info {
    padding: 12px 14px 14px;
    display: flex;
    flex-direction: column;
    flex-grow: 1;
    gap: 6px;
}

.product-title-link { text-decoration: none !important; }

.product-title {
    font-size: clamp(0.9rem, 0.84rem + 0.3vw, 1rem);
    font-weight: 800;
    color: var(--pc-text-heading);
    margin: 0;
    line-height: 1.28;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    overflow-wrap: break-word;
    word-break: break-word;
    min-height: 2.3em;
    text-align: start;
    transition: color 0.2s ease;
}

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

.product-measurement {
    display: flex;
    align-items: center;
    gap: 5px;
    min-width: 0;
    margin: 0;
    text-align: start;
    font-size: 0.74rem;
    font-weight: 500;
    line-height: 1.3;
    color: var(--pc-text-muted);
}

.product-measurement i { flex-shrink: 0; font-size: 0.68rem; opacity: 0.85; }
.product-measurement-text { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; unicode-bidi: plaintext; }

/* ============ Action buttons (View / Add) ============ */
.product-card-actions {
    display: flex;
    align-items: stretch;
    gap: 8px;
    margin-top: auto;
    padding-top: 6px;
}

.pc-btn {
    flex: 1 1 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    height: 38px;
    border-radius: var(--pc-radius-pill);
    font-weight: 700;
    font-size: 0.82rem;
    border: none;
    cursor: pointer;
    text-decoration: none !important;
    transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
    white-space: nowrap;
    padding: 0 10px;
    min-width: 0;
}

.pc-btn i { font-size: 0.82rem; flex-shrink: 0; }
.pc-btn span { overflow: hidden; text-overflow: ellipsis; }

.pc-btn-view {
    background: var(--pc-primary-soft);
    color: var(--pc-primary);
    border: 1.5px solid color-mix(in srgb, var(--pc-primary) 22%, transparent);
}

.pc-btn-view:hover {
    background: color-mix(in srgb, var(--pc-primary) 22%, white);
    color: var(--pc-primary);
    transform: translateY(-1px);
}

.pc-btn-add {
    background: var(--pc-primary);
    color: #ffffff;
    box-shadow: 0 6px 16px var(--pc-primary-glow);
}

.pc-btn-add:hover:not(:disabled) {
    filter: brightness(1.08);
    transform: translateY(-1px);
    box-shadow: 0 10px 22px var(--pc-primary-glow);
}

.pc-btn-add:active:not(:disabled) { transform: translateY(0); filter: brightness(0.97); }

.pc-btn:focus-visible { outline: 2px solid var(--pc-primary); outline-offset: 2px; }

.pc-btn-add:disabled {
    background: #e5e7eb;
    color: #9ca3af;
    box-shadow: none;
    cursor: not-allowed;
}

/* Loading state while a quick-add request is in flight. */
.pc-btn-add.is-loading { pointer-events: none; }
.pc-btn-add.is-loading i { animation: pcSpin 0.7s linear infinite; }
.pc-btn-add.is-loading .pc-btn-add-label { opacity: 0.85; }

@keyframes pcSpin { to { transform: rotate(360deg); } }

/* Success flash after a quick add. */
.pc-btn-add.is-added {
    background: #059669;
    box-shadow: 0 6px 16px rgba(5, 150, 105, 0.35);
}

/* Un-favoriting from a grid that opts in via data-remove-on-unfavorite
   (the Favorites page) — see static/js/product-card.js. */
.product-card.is-removing {
    opacity: 0;
    transform: scale(0.92);
    transition: opacity 0.22s ease, transform 0.22s ease;
}

/* ============ Very narrow (2-up mobile) tuning ============ */
@media (max-width: 400px) {
    .card-wishlist-btn { width: 32px; height: 32px; top: 8px; inset-inline-end: 8px; }
    .card-wishlist-btn i { font-size: 0.8rem; }
    .discount-tag { top: 8px; inset-inline-start: 8px; padding: 3px 8px; font-size: 0.64rem; }
    .out-of-stock-badge { top: 8px; inset-inline-start: 8px; padding: 3px 7px; font-size: 0.6rem; max-width: calc(100% - 56px); }
    .product-image.is-out-of-stock .discount-tag { top: 34px; }
    .price-row { bottom: 7px; inset-inline-end: 7px; padding: 3px 6px; gap: 3px; }
    .current-price { font-size: 0.82rem; }
    .old-price-text { font-size: 0.6rem; }
    .currency-badge { font-size: 0.56rem; padding: 2px 5px; }
    .card-rating-badge { bottom: 7px; inset-inline-start: 7px; padding: 3px 6px; font-size: 0.66rem; gap: 3px; }
    .card-rating-count { font-size: 0.62rem; }
    .product-info { padding: 9px 10px 10px; gap: 5px; }
    .product-measurement { font-size: 0.7rem; }
    .product-card-actions { gap: 6px; }
    .pc-btn { height: 34px; font-size: 0.74rem; padding: 0 6px; gap: 4px; }
    .pc-btn i { font-size: 0.74rem; }
}

/* If JS never runs (disabled/failed), never leave images invisible. */
.no-js .product-card .product-img,
noscript ~ .product-card .product-img { opacity: 1; }
