/**
 * Shipping protection opt-in — cart, checkout and the [pa_shipping_insurance]
 * shortcode.
 *
 * Every rule is scoped under `.pa-insurance-wrap`. The panel renders inside the
 * order-summary column, where themes style `label`, `span` and `input` globally,
 * so the component resets what it needs instead of inheriting it. It must also
 * survive a narrow, shrink-to-fit parent: that is what `min-width: 0` on the
 * flex children is for — without it a flex item cannot shrink below its
 * min-content width and the headline collapses to one word per line.
 */

.pa-insurance-wrap,
.pa-insurance-wrap *,
.pa-insurance-wrap *::before,
.pa-insurance-wrap *::after {
    box-sizing: border-box;
}

.pa-insurance-wrap {
    /* Every colour of the panel lives here, so restyling it is a one-line
       change rather than a hunt through the rules below. */

    /* Switch accent when it is on. */
    --pa-insurance-on: #4caf50;

    /* Resting state — an offer the shopper has not taken yet. Warm on purpose:
       it has to pull the eye away from the totals above it, and it must NOT be
       green, or it would blend into the checkout button sitting right below. */
    --pa-insurance-bg: #fff7e3;
    --pa-insurance-border: #e3bd5c;

    /* Taken — the panel stops selling and starts confirming. */
    --pa-insurance-bg-on: #ecf6ed;
    --pa-insurance-border-on: #6cbb71;

    display: block;
    position: static;
    float: none;
    clear: both;
    width: 100%;
    max-width: 100%;
    margin: 0 0 16px;
    text-align: left;
}

/* No offer for this cart: the wrapper still has to exist so WooCommerce's
   fragment replacement keeps a target, but it must take up no space. */
.pa-insurance-wrap:empty {
    display: none;
    margin: 0;
}

.pa-insurance-wrap .pa-insurance {
    position: relative;
    display: block;
    width: 100%;
    max-width: 100%;
    margin: 0;
    padding: 16px;
    border: 2px solid var(--pa-insurance-border);
    border-radius: 8px;
    background: var(--pa-insurance-bg);
    box-shadow: 0 1px 2px rgba(0, 0, 0, .05);
    font-size: 14px;
    font-weight: 400;
    line-height: 1.5;
    color: inherit;
    transition: background-color .2s ease, border-color .2s ease;
}

/* The state class is rendered server-side AND toggled by the script the moment
   the shopper flips the switch, so the panel confirms instantly instead of
   waiting for the cart round-trip. A class rather than :has() keeps this working
   on older browsers, where :has() would silently leave the panel in its resting
   colours. */
.pa-insurance-wrap .pa-insurance--on {
    border-color: var(--pa-insurance-border-on);
    background: var(--pa-insurance-bg-on);
}

.pa-insurance-wrap .pa-insurance.is-busy {
    opacity: .55;
    pointer-events: none;
}

/* Content filters. A cart shortcode placed in a text widget gets wpautop()
   run over its output, which injects <br> and <p> into this markup. The PHP
   renders it autop-proof (one line, block wrappers); these rules neutralise
   whatever another filter might still slip into the structural levels. The
   coverage text is left alone: its paragraphs are real content. */
.pa-insurance-wrap > br,
.pa-insurance-wrap .pa-insurance > br,
.pa-insurance-wrap .pa-insurance__row > br,
.pa-insurance-wrap .pa-insurance__toggle > br,
.pa-insurance-wrap .pa-insurance__switch > br,
.pa-insurance-wrap .pa-insurance__details > br,
.pa-insurance-wrap > p:empty,
.pa-insurance-wrap .pa-insurance > p:empty {
    display: none;
}

.pa-insurance-wrap > p,
.pa-insurance-wrap .pa-insurance > p {
    margin: 0;
    padding: 0;
}

/* ------------------------------------------------------------------ the row */

.pa-insurance-wrap .pa-insurance__row {
    display: block;
    margin: 0;
    padding: 0;
}

.pa-insurance-wrap .pa-insurance__toggle {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px 12px;
    width: 100%;
    max-width: 100%;
    margin: 0;
    padding: 0;
    float: none;
    font-weight: 400;
    line-height: 1.5;
    cursor: pointer;
}

.pa-insurance-wrap .pa-insurance__headline {
    flex: 1 1 12em;
    min-width: 0;
    font-weight: 500;
    overflow-wrap: break-word;
    word-break: normal;
    hyphens: none;
}

.pa-insurance-wrap .pa-insurance__price {
    flex: 0 0 auto;
    margin-left: auto;
    padding: 0;
    white-space: nowrap;
    font-weight: 700;
}

.pa-insurance-wrap .pa-insurance__price .amount,
.pa-insurance-wrap .pa-insurance__price bdi {
    white-space: nowrap;
}

/* --------------------------------------------------------- the switch itself */

.pa-insurance-wrap .pa-insurance__switch {
    position: relative;
    flex: 0 0 auto;
    display: inline-block;
    width: 44px;
    height: 24px;
    margin: 0;
    padding: 0;
    vertical-align: middle;
}

/* The real control: invisible but still present, focusable and clickable.
   Never `display: none` — that would take it out of the tab order and stop it
   from being announced.

   The heavier selector and the !important flags are deliberate: themes restyle
   checkboxes with rules like `.woocommerce input[type=checkbox]`, often with
   !important of their own, and a checkbox that becomes visible (or zero-sized)
   on top of the switch is exactly the kind of breakage this panel must survive. */
.pa-insurance-wrap .pa-insurance .pa-insurance__switch input.pa-insurance__checkbox[type="checkbox"] {
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
    display: block !important;
    width: 100% !important;
    height: 100% !important;
    min-width: 0;
    min-height: 0;
    max-width: none;
    margin: 0 !important;
    padding: 0;
    border: 0;
    background: none;
    box-shadow: none;
    opacity: 0 !important;
    visibility: visible !important;
    pointer-events: auto !important;
    cursor: pointer;
    z-index: 2;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
}

/* Theme "custom checkbox" skins hang pseudo-elements off the input itself. */
.pa-insurance-wrap .pa-insurance .pa-insurance__switch input.pa-insurance__checkbox[type="checkbox"]::before,
.pa-insurance-wrap .pa-insurance .pa-insurance__switch input.pa-insurance__checkbox[type="checkbox"]::after {
    display: none !important;
    content: none !important;
}

.pa-insurance-wrap .pa-insurance__slider {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border-radius: 999px;
    background: rgba(0, 0, 0, .26);
    pointer-events: none;
    transition: background-color .18s ease;
}

.pa-insurance-wrap .pa-insurance__slider::before {
    content: "";
    position: absolute;
    top: 3px;
    left: 3px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 1px 3px rgba(0, 0, 0, .35);
    transition: transform .18s ease;
}

/* The knob follows the panel's state class (rendered by the server, flipped by
   the script on click) instead of `:checked + .slider`. The sibling selector
   broke whenever a theme or a checkbox-replacement script touched the input —
   and the checkbox now sits AFTER the slider precisely so theme rules such as
   `input[type=checkbox] + span::before` cannot reach the knob. */
.pa-insurance-wrap .pa-insurance--on .pa-insurance__slider {
    background: #4caf50;
    background: var(--pa-insurance-on, #4caf50);
}

.pa-insurance-wrap .pa-insurance--on .pa-insurance__slider::before {
    -webkit-transform: translateX(20px);
    transform: translateX(20px);
}

/* Focus ring. :focus-within works everywhere; where :has() exists, the second
   rule limits the ring to keyboard focus (older browsers drop that rule as a
   whole, which is why it is kept separate). */
.pa-insurance-wrap .pa-insurance__switch:focus-within .pa-insurance__slider {
    box-shadow: 0 0 0 3px rgba(76, 175, 80, .38);
}

.pa-insurance-wrap .pa-insurance__switch:focus-within:not(:has(:focus-visible)) .pa-insurance__slider {
    box-shadow: none;
}

/* ---------------------------------------------------------------- disclosure */

/* Indent to line up with the headline: switch (44px) + row gap (12px). */
.pa-insurance-wrap .pa-insurance__details {
    margin: 10px 0 0 56px;
    padding: 0;
    font-size: .92em;
}

.pa-insurance-wrap .pa-insurance__details > summary {
    display: block;
    list-style: none;
    margin: 0;
    padding: 0;
    cursor: pointer;
    opacity: .85;
    -webkit-user-select: none;
    user-select: none;
}

/* Themes often blanket-reset list markers, which silently removes the native
   disclosure triangle — so the arrow is drawn here instead. */
.pa-insurance-wrap .pa-insurance__details > summary::-webkit-details-marker {
    display: none;
}

.pa-insurance-wrap .pa-insurance__details > summary::after {
    content: "";
    display: inline-block;
    width: .42em;
    height: .42em;
    margin-left: .5em;
    border-right: 2px solid currentColor;
    border-bottom: 2px solid currentColor;
    transform: rotate(45deg) translate(-.1em, -.1em);
    transition: transform .15s ease;
}

.pa-insurance-wrap .pa-insurance__details[open] > summary::after {
    transform: rotate(-135deg) translate(-.1em, -.1em);
}

.pa-insurance-wrap .pa-insurance__coverage {
    margin-top: 8px;
}

.pa-insurance-wrap .pa-insurance__coverage p,
.pa-insurance-wrap .pa-insurance__coverage ul,
.pa-insurance-wrap .pa-insurance__coverage ol {
    margin: 0 0 .6em;
    padding: 0;
}

.pa-insurance-wrap .pa-insurance__coverage ul,
.pa-insurance-wrap .pa-insurance__coverage ol {
    padding-left: 1.25em;
}

.pa-insurance-wrap .pa-insurance__coverage ul {
    list-style: disc;
}

.pa-insurance-wrap .pa-insurance__coverage li {
    margin: 0 0 .25em;
    list-style-position: outside;
}

.pa-insurance-wrap .pa-insurance__coverage > *:last-child {
    margin-bottom: 0;
}

/* ------------------------------------------------------------------ spinner */

.pa-insurance-wrap .pa-insurance__spinner {
    display: none;
    position: absolute;
    top: 14px;
    right: 14px;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(0, 0, 0, .18);
    border-top-color: rgba(0, 0, 0, .55);
    border-radius: 50%;
    animation: pa-insurance-spin .7s linear infinite;
}

.pa-insurance-wrap .pa-insurance.is-busy .pa-insurance__spinner {
    display: block;
}

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

@media (prefers-reduced-motion: reduce) {
    .pa-insurance-wrap .pa-insurance__spinner,
    .pa-insurance-wrap .pa-insurance__slider,
    .pa-insurance-wrap .pa-insurance__slider::before,
    .pa-insurance-wrap .pa-insurance__details > summary::after {
        transition: none;
        animation: none;
    }
}

/* ------------------------------------------------------- very narrow columns */

@media (max-width: 420px) {
    .pa-insurance-wrap .pa-insurance {
        padding: 12px;
    }

    .pa-insurance-wrap .pa-insurance__details {
        margin-left: 0;
    }
}
