/* ==========================================================================
   Damaged items on product cards (ARKAN-490)

   The design ("QtrShoe – New vs Damaged price card", Option B – two price
   rows). A product with damaged pieces at the branch (QSDamaged in
   js/utilities.js):

   - Two price rows: New (its price, on sale with the before price; or
     "Sold out" when New is sold out here) and, under a dashed line, Damaged
     in brown (the cheapest piece sold on its own, or "Price on request").
     The Damaged row opens the product page in Damaged mode.
   - The DAMAGED badge: a brown pill, white uppercase text, in the card
     label's place (top row, level with the heart). Every such card carries
     it; it shows only in a Damaged Items homepage section
     (.qs-damaged-section) and on a Damaged collection page
     (body.qs-damaged-collection, template-collection.php), where it takes the label's place.

   Places: the shop grid (template-collection.php), the homepage cards
   (js/products.js .qs-home-card), the search and photo search results pages
   (.product-card), the search drop-down (.qs-dmg-line). Loaded on every page
   (functions.php), after sale-price.css.

   Sizes win with !important: the card price rules they replace set theirs
   with higher specificity (and some with !important).
   ========================================================================== */

:root {
    --qs-damaged-color: #7A3E0C;
}

/* --------------------------------------------------------------------------
   The two price rows
   -------------------------------------------------------------------------- */
/* The rows fill the card's width, label at the start and price at the end.
   Names and prices line up across a grid row (the cards push their name and
   price to the bottom): the two rows are 25px taller than the one price row
   (19px on phones), the room that row keeps under it for the colour circles.
   So a card without circles keeps no room under its rows, and a card with
   circles lets them hang that much into the gap below. */
.product-card-price.qs-dmg-prices {
    display: flex !important;
    flex-direction: column !important;
    align-items: stretch !important;
    align-self: stretch !important;
    width: 100% !important;
    box-sizing: border-box;
    gap: 4px !important;
    height: auto !important;
    white-space: normal !important;
    font-family: var(--qs-font-body);
}

.product-card > .product-card-price.qs-dmg-prices {
    margin-bottom: 0 !important;
}

.product-card:has(> .product-card-price.qs-dmg-prices) > .color-swatches {
    margin-bottom: -25px;
}

.qs-dmg-prices__row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    min-width: 0;
    min-height: 18px;
}

/* One line height for everything in a row, so every row is exactly 18px (16px on phones) */
.qs-dmg-prices__row,
.qs-dmg-prices__row * {
    line-height: 18px !important;
}

.qs-dmg-prices__row--damaged {
    border-top: 1px dashed #D6D6D6;
    padding-top: 4px;
    cursor: pointer;
}

.qs-dmg-prices__label {
    flex: none;
    font-size: 12px !important;
    line-height: 16px;
    font-weight: 400 !important;
    letter-spacing: 0;
    color: #555555 !important;
}

.qs-dmg-prices__row--damaged .qs-dmg-prices__label {
    color: var(--qs-damaged-color) !important;
}

/* Arabic: the label ends at the card's edge, where the shop grid clips; the
   first letter of "متضرر" reaches past its box, so it gets 2px of room */
html[dir="rtl"] .qs-dmg-prices__label {
    padding-inline-start: 2px;
}

.qs-dmg-prices__row--damaged:hover .qs-dmg-prices__label {
    text-decoration: underline;
}

.qs-dmg-prices__amount {
    display: inline-flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    align-items: baseline;
    column-gap: 6px;
    min-width: 0;
    text-align: end;
}

.qs-dmg-prices .price {
    font-size: 14px !important;
    line-height: 18px;
    font-weight: 600 !important;
    letter-spacing: 0 !important;
    color: #1A1A1A !important;
    white-space: nowrap;
}

/* On sale: the red sale price (sale-price.css), the before price beside it */
.qs-dmg-prices .price.has-discount {
    color: var(--qs-sale-price-color, #c41e3a) !important;
    font-weight: 700 !important;
}

.qs-dmg-prices .compare-price {
    display: inline !important;
    font-size: 12px !important;
    line-height: 16px;
    color: #6B6B6B !important;
    white-space: nowrap;
}

.qs-dmg-prices__row--damaged .price {
    color: var(--qs-damaged-color) !important;
}

/* "Sold out" (New) and "Price on request" (Damaged) */
.qs-dmg-prices__note {
    font-size: 12px !important;
    line-height: 16px;
    font-weight: 500;
    color: #555555;
    white-space: nowrap;
}

.qs-dmg-prices__row--damaged .qs-dmg-prices__note {
    color: var(--qs-damaged-color);
}

/* Phones: 2 × 16px rows, 2px apart, 2px under the line: 19px over the price row */
@media (max-width: 767px) {
    .product-card-price.qs-dmg-prices {
        gap: 2px !important;
    }

    .product-card:has(> .product-card-price.qs-dmg-prices) > .color-swatches {
        margin-bottom: -19px;
    }

    .qs-dmg-prices__row {
        gap: 6px;
        min-height: 16px;
    }

    .qs-dmg-prices__row,
    .qs-dmg-prices__row * {
        line-height: 16px !important;
    }

    .qs-dmg-prices__row--damaged {
        padding-top: 2px;
    }

    .qs-dmg-prices__label,
    .qs-dmg-prices__note,
    .qs-dmg-prices .compare-price {
        font-size: 11px !important;
        line-height: 14px;
    }

    .qs-dmg-prices .price {
        font-size: 13px !important;
        line-height: 16px;
    }
}

/* Search and photo search results pages (visual-search.css): their cards keep no
   room under the price, so the rows reach into the card's bottom padding (32px,
   16px under 1024px) by as much as they would lift the name, and names line up
   across a row as there */
.vs-shop-page-body .product-card > .product-card-price.qs-dmg-prices {
    margin-bottom: -26px !important;
}

@media (min-width: 768px) and (max-width: 1023px) {
    .vs-shop-page-body .product-card > .product-card-price.qs-dmg-prices {
        margin-bottom: -25px !important;
    }
}

@media (max-width: 767px) {
    .vs-shop-page-body .product-card > .product-card-price.qs-dmg-prices {
        margin-bottom: -19px !important;
    }
}

/* Search drop-down: the Damaged price on a line of its own under the price */
.qs-dmg-line {
    display: flex;
    align-items: baseline;
    gap: 6px;
    margin-top: 2px;
    font-size: 12px;
    line-height: 16px;
    color: var(--qs-damaged-color);
}

.qs-dmg-line .price {
    font-weight: 600;
    color: var(--qs-damaged-color) !important;
}

/* --------------------------------------------------------------------------
   The DAMAGED badge: hidden, but in a Damaged Items section and on a Damaged
   collection page
   -------------------------------------------------------------------------- */
.qs-damaged-badge {
    display: none !important;
}

.qs-damaged-collection #product-grid .product-card > .qs-damaged-badge,
.qs-damaged-section .qs-home-card > .qs-damaged-badge {
    display: inline-flex !important;
    align-items: center;
    position: absolute;
    z-index: 5;
    top: 16px;
    left: 12px;
    right: auto;
    transform: translateY(-50%);
    padding: 5px 10px;
    border: none;
    border-radius: 999px;
    background: var(--qs-damaged-color);
    box-sizing: border-box;
    font-family: var(--qs-font-body);
    font-size: 10px;
    font-weight: 600;
    line-height: 12px;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    color: #FFFFFF;
    white-space: nowrap;
    pointer-events: none;
}

.qs-damaged-section .qs-home-card > .qs-damaged-badge {
    left: 0;
}

html[dir="rtl"] .qs-damaged-collection #product-grid .product-card > .qs-damaged-badge {
    left: auto;
    right: 12px;
}

html[dir="rtl"] .qs-damaged-section .qs-home-card > .qs-damaged-badge {
    left: auto;
    right: 0;
}

/* The badge takes the label's place: one label per card */
.qs-damaged-collection #product-grid .product-card:has(> .qs-damaged-badge) > :is(.new-badge, .best-seller-badge, .sale-badge, .sold-out-badge, .low-stock-badge, .qs-custom-badge),
.qs-damaged-section .qs-home-card:has(> .qs-damaged-badge) > :is(.new-badge, .best-seller-badge, .sale-badge, .sold-out-badge, .low-stock-badge, .qs-custom-badge) {
    display: none !important;
}

/* Phones: no top row; the badge 6px down at the photo box's start, as the labels */
@media (max-width: 767px) {
    .qs-damaged-collection #product-grid .product-card > .qs-damaged-badge,
    .qs-damaged-section .qs-home-card > .qs-damaged-badge {
        top: 6px;
        left: 0;
        transform: none;
        padding: 3px 8px;
        font-size: 9px;
        line-height: 12px;
        letter-spacing: 0.12em;
    }

    html[dir="rtl"] .qs-damaged-collection #product-grid .product-card > .qs-damaged-badge,
    html[dir="rtl"] .qs-damaged-section .qs-home-card > .qs-damaged-badge {
        left: auto;
        right: 0;
    }
}
