/**
 * @package   paddlesubs
 * @author    Samuel Marshall <samuel@paddlesubs.com>
 * @copyright Copyright (c) 2026 Samuel Marshall
 * @license   GNU/GPLv3, or later. See LICENSE file
 *
 * If LICENSE file missing, see <http://www.gnu.org/licenses/>.
 */

/*
 * Automatic discounts on the site's prices: the normal price crossed out, the discounted price and the discount's
 * label. Colours follow Bootstrap 5.3's danger tokens, which change with its dark mode, and fall back to fixed ones;
 * a template can set the --paddlesubs-discount-* properties instead.
 */
:root {
    --paddlesubs-discount-color: var(--bs-danger-text-emphasis, #842029);
    --paddlesubs-discount-bg: var(--bs-danger-bg-subtle, #f8d7da);
    --paddlesubs-discount-border: var(--bs-danger-border-subtle, #f1aeb5);
    --paddlesubs-discount-tooltip-color: var(--bs-body-bg, #fff);
    --paddlesubs-discount-tooltip-bg: var(--bs-emphasis-color, #212529);
}

.paddlesubs-price-sale {
    display: inline-flex;
    flex-wrap: wrap;
    align-items: baseline;
    column-gap: .4em;
}

.paddlesubs-price-original {
    font-size: .65em;
    font-weight: 400;
    opacity: .7;
    text-decoration-thickness: .08em;
}

/*
 * In a price card (the product page's prices and the products grid) the crossed-out price has a line of its own above
 * the price, so a long price doesn't wrap and the prices of discounted cards stay level
 */
.paddlesubs-price-amount > [data-paddlesubs-discounted],
.js-paddle-product-price[data-paddlesubs-discounted] {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    column-gap: .4em;
}

.paddlesubs-price-amount > [data-paddlesubs-discounted] .paddlesubs-price-sale,
.js-paddle-product-price[data-paddlesubs-discounted] .paddlesubs-price-sale {
    display: contents;
}

.paddlesubs-price-amount > [data-paddlesubs-discounted] .paddlesubs-price-original,
.js-paddle-product-price[data-paddlesubs-discounted] .paddlesubs-price-original {
    order: -1;
    flex-basis: 100%;
    margin-bottom: .25rem;
}

.js-paddle-product-price[data-paddlesubs-discounted] .paddlesubs-discount-line {
    flex-basis: 100%;
}

/*
 * A card without a discount in a row of cards with one keeps the room of the crossed-out line (and, on the product
 * page, of the discount's label), so its price stays level with theirs
 */
.row:has(.paddlesubs-price-amount [data-paddlesubs-discounted]) .paddlesubs-price-amount:not(:has([data-paddlesubs-discounted]))::before,
.row:has(.js-paddle-product-price[data-paddlesubs-discounted]) .js-paddle-product-price:not([data-paddlesubs-discounted])::before {
    content: "\00a0";
    display: block;
    margin-bottom: .25rem;
    font-size: .65em;
}

.row:has(.paddlesubs-price-amount [data-paddlesubs-discounted]) .paddlesubs-discount-line[hidden] {
    /* over Bootstrap's and templates' [hidden] { display: none !important } */
    display: flex !important;
    visibility: hidden;
    min-height: calc(.8125rem * 1.8 + 2px);
}

.paddlesubs-price-discounted {
    color: var(--paddlesubs-discount-color);
}

.paddlesubs-price-suffix,
.paddlesubs-price-from {
    font-weight: inherit;
}

.paddlesubs-price-from {
    margin-right: .3em;
}

.paddlesubs-discount-line {
    display: flex;
    max-width: 100%;
    margin-top: .5rem;
}

p.paddlesubs-discount-line {
    margin-top: 0;
}

.paddlesubs-discount-line[hidden] {
    display: none;
}

.paddlesubs-discount {
    position: relative;
    display: inline-flex;
    align-items: center;
    max-width: 100%;
    padding: .25em .7em;
    border: 1px solid var(--paddlesubs-discount-border);
    border-radius: 999px;
    background: var(--paddlesubs-discount-bg);
    color: var(--paddlesubs-discount-color);
    font-size: .8125rem;
    font-weight: 600;
    line-height: 1.3;
    vertical-align: middle;
}

/* A price in running text keeps its sentence: the label follows it */
:not(.paddlesubs-discount-line) > .paddlesubs-discount {
    margin-left: .5em;
}

.paddlesubs-discount-label {
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.paddlesubs-discount[data-truncated] {
    cursor: help;
}

.paddlesubs-discount[data-truncated]:focus-visible {
    outline: 2px solid currentColor;
    outline-offset: 2px;
}

/* The whole label of one cut short, above it on hover or focus */
.paddlesubs-discount[data-truncated]::after {
    content: attr(data-full-label);
    position: absolute;
    bottom: calc(100% + .5rem);
    left: 0;
    z-index: 10;
    width: max-content;
    max-width: min(20rem, 80vw);
    padding: .5rem .75rem;
    border-radius: .375rem;
    background: var(--paddlesubs-discount-tooltip-bg);
    color: var(--paddlesubs-discount-tooltip-color);
    font-weight: 400;
    white-space: normal;
    box-shadow: 0 .25rem .75rem rgba(0, 0, 0, .2);
    opacity: 0;
    visibility: hidden;
    transform: translateY(.25rem);
    transition: opacity .15s ease, transform .15s ease, visibility .15s;
    pointer-events: none;
}

.paddlesubs-discount[data-truncated]:hover::after,
.paddlesubs-discount[data-truncated]:focus::after {
    opacity: 1;
    visibility: visible;
    transform: none;
}

@media (prefers-reduced-motion: reduce) {
    .paddlesubs-discount[data-truncated]::after {
        transition: none;
    }
}

/* Not Bootstrap's .visually-hidden: the Options can leave Bootstrap off */
.paddlesubs-visually-hidden {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    white-space: nowrap !important;
    border: 0 !important;
}
