/*
 * Affiliate Hub — base styles, theme isolation and shared components.
 *
 * How the isolation works
 * -----------------------
 * Every output is wrapped in <div class="afh">. All plugin selectors start with
 *
 *     :is(.afh, #afh#afh)
 *
 * It only matches ".afh", but :is() takes the specificity of its most specific
 * argument, "#afh#afh" (two ids, never matches anything). So every plugin rule
 * has specificity >= (2,0,0) and beats theme rules such as
 * ".entry-content a:not(.button)" (0,3,1) or "#main .entry-content a" (1,1,1).
 *
 * 1. The root resets typography that would be inherited from the theme.
 * 2. Every element inside the root gets "all: revert", which drops all theme
 *    styles back to browser defaults. Template CSS then styles from scratch.
 *    SVG is excluded so presentation attributes (fill, stroke) keep working.
 *
 * Only theme rules with !important can still leak in (rare in content areas).
 *
 * Customizing
 * -----------
 * Brand colors and font come from Configurações → Aparência (printed as CSS
 * variables right after this file). Tokens use :where() (zero specificity),
 * so custom CSS can override them easily: .afh { --afh-radius: 4px; }
 */

:where(.afh) {
    /* Brand (overridden by the Aparência settings). */
    --afh-primary: #f43676;
    --afh-accent: #fed267;
    --afh-title: #302d55;
    --afh-text: #002050;
    --afh-gradient-from: #8b5e3b;
    --afh-gradient-to: #a67c52;
    --afh-font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;

    /* Derived. The button is a bit darker than the brand color so white text passes WCAG AA. */
    --afh-button-bg: color-mix(in srgb, var(--afh-primary) 88%, #000);
    --afh-button-bg-hover: color-mix(in srgb, var(--afh-primary) 76%, #000);
    --afh-button-text: #fff;
    --afh-price: var(--afh-title);
    --afh-muted: color-mix(in srgb, var(--afh-text) 66%, #fff);
    --afh-bg: #fff;
    --afh-soft: color-mix(in srgb, var(--afh-gradient-to) 8%, #fff);
    --afh-border: color-mix(in srgb, var(--afh-gradient-to) 24%, #fff);
    --afh-deal-bg: color-mix(in srgb, var(--afh-gradient-from) 12%, #fff);
    --afh-deal-text: var(--afh-gradient-from);
    --afh-success: #1d7a4a;
    --afh-radius: 14px;
    --afh-shadow: 0 1px 2px rgba(48, 45, 85, 0.06), 0 10px 28px -14px rgba(48, 45, 85, 0.22);
    --afh-cover-shadow: 0 10px 22px -8px rgba(0, 0, 0, 0.38);
    --afh-font-size: 16px;
    --afh-line-height: 1.45;
}

/* 1. Root: own typography, vertical rhythm. Width/centering stay with the theme. */
:is(.afh, #afh#afh) {
    display: block;
    box-sizing: border-box;
    margin-top: 1.75em;
    margin-bottom: 1.75em;
    padding: 0;
    border: 0;
    background: none;
    color: var(--afh-text);
    font-family: var(--afh-font);
    font-size: var(--afh-font-size);
    font-style: normal;
    font-weight: 400;
    font-variant: normal;
    line-height: var(--afh-line-height);
    letter-spacing: normal;
    word-spacing: normal;
    text-align: left;
    text-indent: 0;
    text-shadow: none;
    text-transform: none;
    white-space: normal;
    -webkit-font-smoothing: antialiased;
}

/* 2. Everything inside: back to browser defaults, ignoring the theme. */
:is(.afh, #afh#afh) :where(*:not(svg, svg *)) {
    all: revert;
    box-sizing: border-box;
}

/* ---------- Shared components (used by every template) ---------- */

/* Cover image: always fully visible, with a soft book shadow. */
:is(.afh, #afh#afh) .afh-cover {
    display: block;
    width: auto;
    height: auto;
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border-radius: 3px;
    box-shadow: var(--afh-cover-shadow);
}

/* Discount badge, e.g. "-35%". */
:is(.afh, #afh#afh) .afh-badge {
    position: absolute;
    top: 8px;
    left: 8px;
    z-index: 1;
    padding: 3px 9px;
    background: var(--afh-accent);
    border-radius: 999px;
    color: var(--afh-title);
    font-size: 0.8rem;
    font-weight: 700;
    line-height: 1.3;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.12);
}

/* Small labels: store deal ("Oferta Relâmpago") and Prime. */
:is(.afh, #afh#afh) .afh-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

:is(.afh, #afh#afh) .afh-tag {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 9px;
    background: var(--afh-deal-bg);
    border-radius: 999px;
    color: var(--afh-deal-text);
    font-size: 0.78rem;
    font-weight: 600;
    line-height: 1.3;
}

:is(.afh, #afh#afh) .afh-tag--prime {
    background: #e3f4fd;
    color: #0b5f91;
}

/* Price: current (big) + old (struck through). */
:is(.afh, #afh#afh) .afh-price {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 2px 8px;
    line-height: 1.15;
}

:is(.afh, #afh#afh) .afh-price__current {
    color: var(--afh-price);
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.01em;
}

:is(.afh, #afh#afh) .afh-price__old {
    color: var(--afh-muted);
    font-size: 0.9rem;
}

:is(.afh, #afh#afh) .afh-status {
    color: var(--afh-muted);
    font-size: 0.9rem;
}

:is(.afh, #afh#afh) .afh-stock {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--afh-success);
    font-size: 0.9rem;
    font-weight: 500;
}

/* Call to action. */
:is(.afh, #afh#afh) .afh-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 20px;
    background: var(--afh-button-bg);
    border: 0;
    border-radius: 10px;
    color: var(--afh-button-text);
    font-family: inherit;
    font-size: 1rem;
    font-weight: 700;
    line-height: 1.2;
    text-align: center;
    text-decoration: none;
    cursor: pointer;
    box-shadow: 0 6px 16px -8px color-mix(in srgb, var(--afh-primary) 80%, transparent);
    transition: background-color 0.15s ease, transform 0.15s ease, box-shadow 0.15s ease;
}

:is(.afh, #afh#afh) .afh-btn:hover,
:is(.afh, #afh#afh) .afh-btn:focus-visible {
    background: var(--afh-button-bg-hover);
    transform: translateY(-1px);
    box-shadow: 0 10px 20px -10px color-mix(in srgb, var(--afh-primary) 90%, transparent);
}

:is(.afh, #afh#afh) .afh-btn:focus-visible {
    outline: 3px solid color-mix(in srgb, var(--afh-primary) 40%, transparent);
    outline-offset: 2px;
}

:is(.afh, #afh#afh) .afh-merchant {
    color: var(--afh-muted);
    font-size: 0.85rem;
}

/* "Preços atualizados em…" with the store's price disclaimer on hover/focus. */
:is(.afh, #afh#afh) .afh-updated {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 6px;
    margin-top: 10px;
    color: var(--afh-muted);
    font-size: 0.82rem;
    font-style: italic;
}

:is(.afh, #afh#afh) .afh-info {
    position: relative;
    display: inline-flex;
    cursor: help;
    outline-offset: 2px;
}

:is(.afh, #afh#afh) .afh-info::after {
    content: attr(data-tip);
    position: absolute;
    right: 0;
    bottom: calc(100% + 8px);
    z-index: 10;
    width: 260px;
    padding: 10px 12px;
    background: var(--afh-title);
    border-radius: 8px;
    color: #fff;
    font-size: 0.8rem;
    font-style: normal;
    line-height: 1.45;
    text-align: left;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.15s ease;
    pointer-events: none;
}

:is(.afh, #afh#afh) .afh-info:hover::after,
:is(.afh, #afh#afh) .afh-info:focus::after {
    opacity: 1;
    visibility: visible;
}

/* Broken references, visible to editors only. */
:is(.afh, #afh#afh) .afh-missing {
    margin: 0 0 12px;
    padding: 12px 16px;
    border: 1px dashed #d63638;
    border-radius: 6px;
    color: #d63638;
    font-size: 14px;
}

@media (prefers-reduced-motion: reduce) {
    :is(.afh, #afh#afh) .afh-btn {
        transition: none;
    }

    :is(.afh, #afh#afh) .afh-btn:hover {
        transform: none;
    }
}
