/*
 * CharitySync for JustGiving — front-end embed styles.
 *
 * Theme-compatible: no colours hardcoded except as CSS variable fallbacks.
 * Sizing uses relative units (em/rem). Mobile-responsive from 320px (FR-FPE-015).
 * WCAG 2.1 AA: progress bar uses ARIA attributes set in PHP; this CSS is visual only.
 */

/* ---- Fundraising Page embed (charitysync/fundraising-page) ---- */

.charitysync-fundraising-page {
    box-sizing: border-box;
    font-family: inherit;
    line-height: 1.5;
}

/* Hero image */
.charitysync-fp__hero-image {
    display: block;
    width: 100%;
    max-height: 360px;
    object-fit: cover;
    border-radius: 4px;
    margin-bottom: 1em;
}

.charitysync-fp__title {
    margin-top: 0;
    margin-bottom: 0.5em;
}

.charitysync-fp__fundraiser {
    margin: 0.25em 0 0.75em;
    font-size: 0.95em;
}

.charitysync-fp__story {
    margin: 0.75em 0;
    font-size: 0.95em;
}

/* Stats row */
.charitysync-fp__stats {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5em 1.5em;
    margin: 1em 0;
    padding: 0.75em 1em;
    background-color: var(--wp--preset--color--light, rgba(0,0,0,0.04));
    border-radius: 4px;
}

.charitysync-fp__stat {
    display: flex;
    flex-direction: column;
    min-width: 5em;
}

.charitysync-fp__stat-value {
    font-size: 1.2em;
    font-weight: 700;
    line-height: 1.2;
}

.charitysync-fp__stat-label {
    font-size: 0.8em;
    opacity: 0.72;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.charitysync-fp__stat--gift-aid .charitysync-fp__stat-value {
    color: var(--wp--preset--color--vivid-green-cyan, #00a32a);
}

/* Progress bar */
.charitysync-fp__progress {
    position: relative;
    width: 100%;
    height: 0.75em;
    background-color: #e0e0e0;
    border-radius: 0.5em;
    overflow: hidden;
    margin: 0 0 1em;
}

.charitysync-fp__progress-bar {
    height: 100%;
    background-color: var(--porto-primary-color, #0066cc);
    border-radius: 0.5em;
    transition: width 0.4s ease;
}

@media (prefers-reduced-motion: reduce) {
    .charitysync-fp__progress-bar {
        transition: none;
    }
}

/* Donate button */
.charitysync-fp__donate-btn {
    display: inline-block;
    margin-top: 0.5em;
    padding: 0.65em 1.5em;
    text-decoration: none;
    border-radius: 4px;
    font-weight: 600;
    background-color: var(--porto-primary-color, #0066cc);
    color: #ffffff;
    border: 2px solid transparent;
}

.charitysync-fp__donate-btn:hover,
.charitysync-fp__donate-btn:focus {
    opacity: 0.88;
    color: #ffffff;
    text-decoration: none;
}

.charitysync-fp__donate-btn:focus-visible {
    outline: 3px solid currentColor;
    outline-offset: 2px;
}

.charitysync-fp__closed {
    margin-top: 1em;
    font-style: italic;
    opacity: 0.75;
}

/* ---- Checkout Button — Custom HTML mode (charitysync/checkout-button) ---- */

/*
 * Default: uses theme primary colour as background. Charities can override
 * by setting Background/Text colour in the block inspector (FR-CHK-014).
 * The inline style from the renderer takes precedence over this rule when set.
 */
.charitysync-checkout-btn {
    display: inline-block;
    padding: 0.65em 1.6em;
    text-decoration: none !important;
    font-weight: 600;
    border-radius: 4px;
    background-color: var(--porto-primary-color, #0066cc);
    color: #ffffff !important;
    border: 2px solid transparent;
    cursor: pointer;
    transition: opacity 0.2s ease;
}

.charitysync-checkout-btn:hover,
.charitysync-checkout-btn:focus {
    opacity: 0.88;
    color: #ffffff !important;
    text-decoration: none !important;
}

.charitysync-checkout-btn:focus-visible {
    outline: 3px solid currentColor;
    outline-offset: 2px;
}

/* ---- Responsive (FR-FPE-015) ---- */

@media (max-width: 480px) {
    .charitysync-fp__donate-btn,
    .charitysync-checkout-btn {
        display: block;
        text-align: center;
    }
}

/* ---- Live Monitor embed (charitysync/live-monitor) — P3-S2/S3 ---- */
/* FR-MON-016: mobile-responsive from 320px, CSS-only.                  */
/* FR-MON-017: WCAG 2.1 AA — ARIA is set in PHP; CSS respects
   prefers-reduced-motion for the progress bar transition.              */

.charitysync-live-monitor {
    box-sizing: border-box;
    font-family: inherit;
    line-height: 1.4;
    padding: 1em;
    border-radius: 6px;
    background: rgba(0, 0, 0, 0.03);
}

.charitysync-live-monitor__total-region {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 0.5em;
    margin-bottom: 0.75em;
}

.charitysync-live-monitor__total {
    font-size: 2em;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.charitysync-live-monitor__target-label {
    font-size: 0.95em;
    opacity: 0.75;
}

.charitysync-live-monitor__progress {
    width: 100%;
    height: 14px;
    background: rgba(0, 0, 0, 0.1);
    border-radius: 999px;
    overflow: hidden;
    position: relative;
}

.charitysync-live-monitor__progress-bar {
    height: 100%;
    width: 0;
    background: currentColor;
    opacity: 0.75;
    border-radius: 999px;
    transition: width 0.6s ease-out;
}

/* Counter-only mode: wider total, no progress bar rendered. */
.charitysync-live-monitor--counter .charitysync-live-monitor__total {
    font-size: 2.5em;
}

/* Respect reduced-motion preference (FR-MON-017 / FR-NFR-014). */
@media (prefers-reduced-motion: reduce) {
    .charitysync-live-monitor__progress-bar {
        transition: none;
    }
}

/* Visible state hint when a poll has failed (no visitor-facing error). */
.charitysync-live-monitor[data-charitysync-poll-state="error"] {
    /* Intentionally visually identical — state used for diagnostics, not UX. */
}

/* Mobile (FR-MON-016: responsive from 320px). */
@media (max-width: 480px) {
    .charitysync-live-monitor__total {
        font-size: 1.6em;
    }
    .charitysync-live-monitor--counter .charitysync-live-monitor__total {
        font-size: 2em;
    }
}

/* -----------------------------------------------------------------------
 * Donor leaderboard (FR-MON-013)
 *
 * Rendered below the total/thermometer region when displayStyle is
 * 'leaderboard' and the server returned donations. Each row: avatar
 * circle, donor name, optional message, and an optional amount +
 * Gift Aid block.
 *
 * Specificity notes: WordPress themes frequently apply `ol li`, `ul li`
 * styling (including `display: list-item`, padding, list markers, and
 * margins) with enough specificity to beat a single-class selector.
 * Every rule below is scoped to the component root class so specificity
 * stays above typical theme list rules. `list-style: none` is declared
 * on both the <ol> and the <li> to prevent marker leakage.
 * -----------------------------------------------------------------------
 */

.charitysync-live-monitor--leaderboard .charitysync-live-monitor__leaderboard {
    list-style: none;
    margin: 1.25em 0 0;
    padding: 0;
    display: block; /* Overrides any inherited flex/grid from a parent. */
}

.charitysync-live-monitor--leaderboard .charitysync-live-monitor__leaderboard > li.charitysync-live-monitor__row {
    /* Raise specificity past typical theme `ol li` rules. */
    display: grid;
    grid-template-columns: 2.75em minmax(0, 1fr) minmax(6em, max-content);
    column-gap: 1em;
    row-gap: 0.25em;
    align-items: start;
    padding: 0.9em 0;
    margin: 0;
    border-bottom: 1px solid rgba(0, 0, 0, 0.08);
    list-style: none;
    list-style-type: none;
    background: transparent;
}

/* Belt-and-braces: suppress any marker leaked by the theme. */
.charitysync-live-monitor--leaderboard .charitysync-live-monitor__leaderboard > li.charitysync-live-monitor__row::marker {
    content: '';
}

.charitysync-live-monitor--leaderboard .charitysync-live-monitor__leaderboard > li.charitysync-live-monitor__row:first-child {
    padding-top: 0.25em;
}

.charitysync-live-monitor--leaderboard .charitysync-live-monitor__leaderboard > li.charitysync-live-monitor__row:last-child {
    border-bottom: none;
    padding-bottom: 0.25em;
}

.charitysync-live-monitor--leaderboard .charitysync-live-monitor__avatar {
    width: 2.75em;
    height: 2.75em;
    border-radius: 50%;
    background: #4a90e2;
    color: #fff;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1em;
    line-height: 1;
    text-transform: uppercase;
    flex-shrink: 0;
}

.charitysync-live-monitor--leaderboard .charitysync-live-monitor__row-body {
    min-width: 0;
    align-self: center; /* Vertically centre on the avatar for single-line rows. */
}

.charitysync-live-monitor--leaderboard .charitysync-live-monitor__donor-name {
    margin: 0;
    padding: 0;
    font-weight: 600;
    line-height: 1.25;
    font-size: 1em;
    color: inherit;
}

.charitysync-live-monitor--leaderboard .charitysync-live-monitor__donor-message {
    margin: 0.3em 0 0;
    padding: 0;
    font-size: 0.9em;
    color: #555;
    line-height: 1.4;
    word-wrap: break-word;
    overflow-wrap: anywhere;
    font-weight: 400;
}

.charitysync-live-monitor--leaderboard .charitysync-live-monitor__row-amount {
    text-align: right;
    align-self: center;
    white-space: nowrap;
}

.charitysync-live-monitor--leaderboard .charitysync-live-monitor__amount {
    display: block;
    font-size: 1.2em;
    font-weight: 700;
    color: #2b2b2b;
    line-height: 1.2;
}

.charitysync-live-monitor--leaderboard .charitysync-live-monitor__gift-aid {
    display: block;
    margin-top: 0.15em;
    font-size: 0.8em;
    font-weight: 400;
    color: #666;
    line-height: 1.2;
}

/* Narrow viewports (FR-MON-016: responsive from 320px).
   Reflow to a two-column grid with the amount on its own row beneath the
   body. Threshold 420px — wide enough to keep desktop/tablet content
   columns on the primary layout, narrow enough that phone-width sidebars
   and a few tight-template columns reflow cleanly.
*/
@media (max-width: 420px) {
    .charitysync-live-monitor--leaderboard .charitysync-live-monitor__leaderboard > li.charitysync-live-monitor__row {
        grid-template-columns: 2.25em minmax(0, 1fr);
        grid-template-areas:
            "avatar body"
            "avatar amount";
        column-gap: 0.75em;
        row-gap: 0.35em;
    }
    .charitysync-live-monitor--leaderboard .charitysync-live-monitor__avatar {
        width: 2.25em;
        height: 2.25em;
        font-size: 0.9em;
        grid-area: avatar;
        align-self: start;
        margin-top: 0.15em;
    }
    .charitysync-live-monitor--leaderboard .charitysync-live-monitor__row-body {
        grid-area: body;
        align-self: start;
    }
    .charitysync-live-monitor--leaderboard .charitysync-live-monitor__row-amount {
        grid-area: amount;
        text-align: left;
        align-self: start;
    }
    .charitysync-live-monitor--leaderboard .charitysync-live-monitor__amount {
        display: inline;
        font-size: 1.05em;
    }
    .charitysync-live-monitor--leaderboard .charitysync-live-monitor__gift-aid {
        display: inline;
        margin-top: 0;
        margin-left: 0.4em;
    }
}
