/* ================================================================
   AP Bike Finance Calculator
   Builds on autotrader-sync's detail.css (.atd-details-section card)
   and the theme: colours fall back from the AutoTrader colour settings
   (--ats-*) to Avada's global palette (--awb-*).
   ================================================================ */

.apbf-section,
.apbf-cta,
body.apbf-has-finance .atd-header-right {
    --apbf-accent: var(--ats-button-color, var(--awb-color5, #d71920));
    --apbf-accent-text: var(--ats-button-text-color, #fff);
    --apbf-muted: rgba(0, 0, 0, 0.6);
    --apbf-border: #e0e0e0;
}

/* ===== Price card (header, right) =====
   On vehicles with finance the price and the button form one card, the
   same width as the enquiry card below it (380px column in detail.css). */
body.apbf-has-finance .atd-header-right {
    width: 380px;
    max-width: 100%;
    padding: 18px 20px 20px;
    border: 1px solid var(--apbf-border);
    border-radius: 12px;
    background: #fff;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.04);
}

body.apbf-has-finance .atd-header-right .atd-price {
    line-height: 1.1;
}

body.apbf-has-finance .atd-header-right .atd-price::before {
    content: "Price";
    display: block;
    margin-bottom: 4px;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--apbf-muted);
}

/* ===== Button under the price ===== */
.apbf-cta {
    margin-top: 14px;
}

/* Extra specificity: the theme's paragraph margins otherwise win. */
.apbf-cta p.apbf-cta-note {
    margin: 10px 0 0;
    font-size: 0.85em;
    line-height: 1.4;
    color: var(--apbf-muted);
    text-align: center;
}

.apbf-cta-btn,
.apbf-cta-btn:visited {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 13px 22px;
    background: var(--apbf-accent);
    color: var(--apbf-accent-text);
    border-radius: 8px;
    font-weight: 700;
    font-size: 1em;
    line-height: 1.2;
    text-decoration: none;
    transition: opacity 0.15s ease, transform 0.15s ease;
}

.apbf-cta-btn:hover,
.apbf-cta-btn:focus {
    color: var(--apbf-accent-text);
    opacity: 0.9;
    text-decoration: none;
}

.apbf-cta-btn:focus-visible {
    outline: 2px solid var(--apbf-accent);
    outline-offset: 3px;
}

.apbf-cta-btn:active {
    transform: translateY(1px);
}


/* ===== Finance section ===== */
.apbf-section {
    /* Fallback for no-JS anchor jumps; JS measures the real sticky header. */
    scroll-margin-top: 120px;
}

.apbf-section.apbf-placement-full {
    margin-top: 24px;
}

.apbf-intro {
    margin: 0 0 18px;
    color: var(--apbf-muted);
}

.apbf-plugin-wrap {
    position: relative;
    min-height: 120px;
}

/* Collapsed until the calculator reports it has loaded: the SDK inserts
   its iframe at 2000px high and resizes it once content arrives. */
.apbf-plugin-container {
    width: 100%;
    height: 0;
    overflow: hidden;
}

.apbf-plugin-wrap.is-ready .apbf-plugin-container {
    height: auto;
    overflow: visible;
}

.apbf-plugin-wrap.is-failed .apbf-plugin-container,
.apbf-plugin-wrap.is-failed .apbf-loading {
    display: none;
}

.apbf-plugin-container iframe {
    display: block;
    width: 100%;
    max-width: 100%;
    border: 0;
}

.apbf-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    min-height: 120px;
    color: var(--apbf-muted);
    font-size: 0.9em;
}

/* Spinner: in click mode only once a load has been requested; in scroll
   mode from the start (the load begins as the section approaches). */
.apbf-trigger-click .apbf-loading,
.apbf-plugin-wrap.is-ready .apbf-loading,
.apbf-plugin-wrap.is-limited .apbf-loading {
    display: none;
}

.apbf-trigger-click.is-loading .apbf-loading {
    display: flex;
}

/* Click mode: nothing is loaded from Codeweavers until the visitor asks. */
.apbf-start {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 14px;
    min-height: 120px;
    padding: 20px;
    border: 1px dashed var(--apbf-border);
    border-radius: 8px;
    text-align: center;
}

.apbf-start[hidden] {
    display: none;
}

.apbf-start p {
    margin: 0;
    color: var(--apbf-muted);
}

.apbf-start-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 12px 22px;
    border: 0;
    border-radius: 8px;
    background: var(--apbf-accent);
    color: var(--apbf-accent-text);
    font: inherit;
    font-weight: 700;
    cursor: pointer;
}

.apbf-start-btn:hover {
    opacity: 0.9;
}

.apbf-start-btn:focus-visible {
    outline: 2px solid var(--apbf-accent);
    outline-offset: 3px;
}

.apbf-spinner {
    width: 22px;
    height: 22px;
    border: 3px solid rgba(0, 0, 0, 0.1);
    border-top-color: var(--apbf-accent);
    border-radius: 50%;
    animation: apbf-spin 0.8s linear infinite;
}

@keyframes apbf-spin {
    to { transform: rotate(360deg); }
}

.apbf-error {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    padding: 14px 16px;
    border-radius: 8px;
    background: #fff4e5;
    color: #663c00;
    font-size: 0.9em;
}

.apbf-error[hidden] {
    display: none;
}

.apbf-error i {
    margin-top: 3px;
}

/* ===== How-to guide (shown once the calculator has loaded) =====
   The Codeweavers controls live in a cross-origin iframe we cannot style,
   so this explains them from outside. */
.apbf-guide {
    display: none;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
    margin: 0 0 16px;
    padding: 0;
    list-style: none;
}

.apbf-plugin-wrap.is-ready .apbf-guide {
    display: grid;
}

.apbf-guide li {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    margin: 0;
    padding: 12px 14px;
    border: 1px solid var(--apbf-border);
    border-radius: 8px;
    background: #fafafa;
    font-size: 0.85em;
    line-height: 1.45;
}

.apbf-guide-num {
    display: flex;
    flex: 0 0 auto;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: var(--apbf-accent);
    color: var(--apbf-accent-text);
    font-weight: 700;
    font-size: 13px;
}

.apbf-guide strong {
    display: block;
    margin-bottom: 2px;
    font-size: 1.05em;
}

.apbf-guide span:not(.apbf-guide-num) {
    color: var(--apbf-muted);
}

/* ===== Explainer videos ===== */
.apbf-videos {
    margin-top: 28px;
    padding-top: 20px;
    border-top: 1px solid #eee;
}

.apbf-videos-title {
    margin: 0 0 14px;
    font-size: 1.05em;
}

.apbf-videos-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
}

.apbf-video {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    width: 100%;
    aspect-ratio: 16 / 9;
    padding: 12px;
    border: 1px solid var(--apbf-border);
    border-radius: 8px;
    background: #1b1b1b;
    color: #fff;
    font: inherit;
    text-align: center;
    cursor: pointer;
    overflow: hidden;
}

.apbf-video:hover .apbf-video-play,
.apbf-video:focus-visible .apbf-video-play {
    transform: scale(1.08);
}

.apbf-video:focus-visible {
    outline: 2px solid var(--apbf-accent);
    outline-offset: 2px;
}

.apbf-video-play {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: var(--apbf-accent);
    color: var(--apbf-accent-text);
    font-size: 18px;
    transition: transform 0.15s ease;
}

.apbf-video-play i {
    margin-left: 3px;
}

.apbf-video-title {
    font-size: 0.9em;
    font-weight: 600;
    line-height: 1.3;
}

.apbf-video.is-playing {
    padding: 0;
    cursor: default;
}

.apbf-video iframe {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border: 0;
}

/* Safari <= 14: no aspect-ratio, so reserve 16:9 with padding. */
@supports not (aspect-ratio: 1 / 1) {
    .apbf-video,
    .apbf-video.is-playing {
        height: 0;
        padding: 56.25% 0 0;
    }
    .apbf-video:not(.is-playing) > span {
        position: absolute;
    }
    .apbf-video:not(.is-playing) .apbf-video-play {
        top: calc(50% - 36px);
    }
    .apbf-video:not(.is-playing) .apbf-video-title {
        bottom: 14px;
        left: 12px;
        right: 12px;
    }
}

/* ===== Disclaimer =====
   Status, broker and commission wording must be prominent (FCA): normal
   text size in a bordered panel, directly under the calculator. */
.apbf-disclaimer {
    margin-top: 20px;
    padding: 16px 18px;
    border: 1px solid var(--apbf-border);
    border-left: 4px solid var(--apbf-accent);
    border-radius: 8px;
    background: #fafafa;
    font-size: 0.95em;
    line-height: 1.6;
}

.apbf-disclaimer p {
    margin: 0 0 10px;
}

.apbf-disclaimer p:last-child {
    margin-bottom: 0;
}

.apbf-disclaimer-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 18px;
    font-weight: 600;
}

.apbf-disclaimer a {
    color: var(--ats-link-color, inherit);
    text-decoration: underline;
}

/* ===== Responsive (matches detail.css breakpoints) ===== */
@media (max-width: 960px) {
    /* detail.css stacks the header here: the price card spans the width. */
    body.apbf-has-finance .atd-header-right { width: 100%; }
}

@media (max-width: 760px) {
    .apbf-guide { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
    .apbf-videos-grid { grid-template-columns: 1fr; }
    .apbf-section { padding: 18px; }
}

@media (prefers-reduced-motion: reduce) {
    .apbf-spinner { animation-duration: 2s; }
    .apbf-cta-btn,
    .apbf-video-play { transition: none; }
}
