/*
 * Presence widgets: floating video bubble and quick contact card.
 *
 * z-index 998 is load-bearing: the mini-cart bubble is 999, the floating
 * location widget 9998 and the open cart drawer 99999. If any of them overlaps
 * us they win, so a video never sits on top of the pay button.
 */

.wpc-presence {
    position: fixed;
    z-index: 998;
    font-family: inherit;
    box-sizing: border-box;
}

.wpc-presence *,
.wpc-presence *::before,
.wpc-presence *::after {
    box-sizing: inherit;
}

/*
 * Placement stays physical, not logical: the owner picks a corner on a visual
 * grid in the settings, so inset-inline-* would move the widget to the other
 * side of an RTL site from the one they clicked. Text inside the card still
 * follows the page's dir, because nothing here sets direction.
 */
.wpc-presence.is-bottom-right {
    right: var(--wpc-presence-x, 24px);
    bottom: var(--wpc-presence-y, 24px);
}

.wpc-presence.is-bottom-left {
    left: var(--wpc-presence-x, 24px);
    bottom: var(--wpc-presence-y, 24px);
}

.wpc-presence.is-top-right {
    right: var(--wpc-presence-x, 24px);
    top: var(--wpc-presence-y, 24px);
}

.wpc-presence.is-top-left {
    left: var(--wpc-presence-x, 24px);
    top: var(--wpc-presence-y, 24px);
}

/* The admin bar covers the top 32px of the viewport for logged-in users. */
body.admin-bar .wpc-presence.is-top-right,
body.admin-bar .wpc-presence.is-top-left {
    top: calc(var(--wpc-presence-y, 24px) + 32px);
}

/*
 * The controls are frosted pills over whatever the owner uploaded, so the
 * browser's default ring is often invisible against a bright frame. A light
 * ring with a dark halo reads on any footage.
 */
.wpc-presence :is(button, a):focus-visible {
    outline: 2px solid #fff;
    outline-offset: 2px;
    box-shadow: 0 0 0 4px rgba(0, 0, 0, 0.5);
}

/* The card itself sits on the page, not on the video, so it wants the reverse. */
.wpc-presence-contact :is(button, a):focus-visible {
    outline: 2px solid var(--wpc-presence-primary, #c82333);
    outline-offset: 2px;
    box-shadow: none;
}

.wpc-presence[hidden] {
    display: none !important;
}

/*
 * A widget set to appear after a delay or a scroll depth starts invisible and
 * JS adds .is-ready. "On load" is not hidden here, so a page whose JS failed
 * still shows it.
 */
.wpc-presence[data-trigger="delay"]:not(.is-ready),
.wpc-presence[data-trigger="scroll"]:not(.is-ready) {
    opacity: 0;
    transform: translateY(14px);
    pointer-events: none;
}

.wpc-presence[data-trigger="delay"],
.wpc-presence[data-trigger="scroll"] {
    transition:
        opacity 0.4s ease,
        transform 0.45s cubic-bezier(0.22, 1, 0.36, 1);
}

/* --- video widget --- */

.wpc-presence-video .wpc-presence-video__panel {
    position: relative;
    width: 108px;
    height: 144px;
    border-radius: 18px;
    overflow: hidden;
    background: #16161a;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.28);
    transition:
        width 0.42s cubic-bezier(0.22, 1, 0.36, 1),
        height 0.42s cubic-bezier(0.22, 1, 0.36, 1),
        border-radius 0.42s cubic-bezier(0.22, 1, 0.36, 1),
        box-shadow 0.42s ease;
}

.wpc-presence-video[data-state="open"] .wpc-presence-video__panel {
    width: 288px;
    height: 384px;
    border-radius: 22px;
    box-shadow: 0 18px 48px rgba(0, 0, 0, 0.34);
}

.wpc-presence-video__media {
    position: absolute;
    inset: 0;
}

.wpc-presence-video__player,
.wpc-presence-video__embed {
    width: 100%;
    height: 100%;
    display: block;
    object-fit: cover;
    background-size: cover;
    background-position: center;
    border: 0;
}

.wpc-presence-video__embed iframe {
    width: 100%;
    height: 100%;
    border: 0;
    display: block;
    pointer-events: none;
}

/*
 * The dark wash is what makes white text and buttons readable on top of an
 * arbitrary video the owner uploaded. It stays on (weaker) while minimized so
 * the expand icon in the corner never disappears into a bright frame.
 */
.wpc-presence-video__scrim {
    position: absolute;
    inset: 0;
    pointer-events: none;
    opacity: 0.35;
    transition: opacity 0.35s ease;
    background:
        linear-gradient(
            to top,
            rgba(0, 0, 0, 0.88) 0%,
            rgba(0, 0, 0, 0.55) 26%,
            rgba(0, 0, 0, 0.08) 58%,
            rgba(0, 0, 0, 0) 78%
        ),
        linear-gradient(to bottom, rgba(0, 0, 0, 0.42) 0%, rgba(0, 0, 0, 0) 32%);
}

.wpc-presence-video[data-state="open"] .wpc-presence-video__scrim {
    opacity: 1;
}

/* Frosted pill shared by the corner toggle and the playback buttons. */
.wpc-presence-video__toggle,
.wpc-presence-video__control {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    cursor: pointer;
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.28);
    background: rgba(20, 20, 24, 0.42);
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
    transition:
        background 0.2s ease,
        transform 0.2s ease,
        opacity 0.25s ease;
}

.wpc-presence-video__toggle:hover,
.wpc-presence-video__control:hover {
    background: rgba(20, 20, 24, 0.66);
}

.wpc-presence-video__toggle svg,
.wpc-presence-video__control svg {
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
    display: block;
}

.wpc-presence-video__toggle {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 30px;
    height: 30px;
    border-radius: 50%;
}

/*
 * Minimized, the toggle is the whole card: the visitor should be able to click
 * anywhere on the bubble to open it, and a 30px target in the corner of a
 * 108px card is not that.
 */
.wpc-presence-video[data-state="minimized"] .wpc-presence-video__toggle {
    inset: 0;
    width: 100%;
    height: 100%;
    border: 0;
    border-radius: inherit;
    background: transparent;
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
}

.wpc-presence-video[data-state="minimized"] .wpc-presence-video__toggle:hover {
    background: rgba(0, 0, 0, 0.12);
}

/*
 * The expand icon carries its own frosted chip while minimized. The scrim
 * alone loses it on a bright video: a white icon on a pale sky is invisible.
 */
.wpc-presence-video[data-state="minimized"] .wpc-presence-video__toggle > span {
    position: absolute;
    top: 8px;
    right: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    border: 1px solid rgba(255, 255, 255, 0.28);
    background: rgba(20, 20, 24, 0.45);
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
}

.wpc-presence-video[data-state="minimized"] .wpc-presence-video__toggle-icon--open,
.wpc-presence-video[data-state="open"] .wpc-presence-video__toggle-icon--closed {
    display: none;
}

.wpc-presence-video__controls {
    position: absolute;
    right: 10px;
    bottom: 14px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    opacity: 0;
    pointer-events: none;
    transform: translateX(10px);
    transition:
        opacity 0.28s ease 0.08s,
        transform 0.32s cubic-bezier(0.22, 1, 0.36, 1) 0.08s;
}

.wpc-presence-video.has-cta .wpc-presence-video__controls {
    bottom: 68px;
}

.wpc-presence-video[data-state="open"] .wpc-presence-video__controls {
    opacity: 1;
    pointer-events: auto;
    transform: none;
}

.wpc-presence-video__control {
    width: 36px;
    height: 36px;
    border-radius: 50%;
}

.wpc-presence-video__play[data-playing="1"] .wpc-presence-video__icon--paused,
.wpc-presence-video__play[data-playing="0"] .wpc-presence-video__icon--playing,
.wpc-presence-video__mute[data-muted="1"] .wpc-presence-video__icon--loud,
.wpc-presence-video__mute[data-muted="0"] .wpc-presence-video__icon--muted {
    display: none;
}

.wpc-presence-video__cta {
    position: absolute;
    left: 14px;
    right: 14px;
    bottom: 14px;
    padding: 12px 16px;
    border-radius: 999px;
    text-align: center;
    text-decoration: none;
    font-weight: 600;
    font-size: 14px;
    line-height: 1.2;
    color: #fff;
    background: var(--wpc-presence-primary, #c82333);
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.32);
    opacity: 0;
    pointer-events: none;
    transform: translateY(10px);
    transition:
        opacity 0.28s ease 0.1s,
        transform 0.36s cubic-bezier(0.22, 1, 0.36, 1) 0.1s,
        filter 0.2s ease;
}

.wpc-presence-video[data-state="open"] .wpc-presence-video__cta {
    opacity: 1;
    pointer-events: auto;
    transform: none;
}

.wpc-presence-video__cta:hover {
    color: #fff;
    filter: brightness(1.08);
}

/* --- contact card --- */

.wpc-presence-contact {
    width: 260px;
    padding: 18px;
    border-radius: 16px;
    background: #fff;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.18);
}

.wpc-presence-contact__close {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 24px;
    height: 24px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    cursor: pointer;
    background: rgba(0, 0, 0, 0.06);
    line-height: 1;
    color: inherit;
}

.wpc-presence-contact__header {
    margin: 0 0 12px;
}

.wpc-presence-contact__title {
    margin: 0 0 2px;
    font-size: 15px;
    font-weight: 700;
}

.wpc-presence-contact__subtitle {
    margin: 0;
    font-size: 13px;
    opacity: 0.7;
}

/*
 * The list scrolls, the card does not grow past the viewport. There is no row
 * limit in the settings, so an owner who adds a dozen rows would otherwise
 * push the buttons off the bottom of a phone screen.
 */
.wpc-presence-contact__rows {
    margin: 0 0 14px;
    padding: 0;
    list-style: none;
    max-height: 40vh;
    overflow-y: auto;
    overscroll-behavior: contain;
}

.wpc-presence-contact__row {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    padding: 5px 0;
    margin: 0;
    font-size: 13px;
}

.wpc-presence-contact__row-icon {
    flex: 0 0 16px;
    line-height: 0;
    opacity: 0.75;
    margin-top: 2px;
}

.wpc-presence-contact__row-text {
    color: inherit;
}

a.wpc-presence-contact__row-text {
    text-decoration: none;
}

a.wpc-presence-contact__row-text:hover {
    text-decoration: underline;
}

.wpc-presence-contact__actions {
    display: grid;
    gap: 8px;
}

.wpc-presence-contact__btn {
    display: block;
    padding: 9px 14px;
    border-radius: 8px;
    text-align: center;
    text-decoration: none;
    font-size: 13px;
    font-weight: 600;
}

.wpc-presence-contact__btn--primary {
    color: #fff;
    background: var(--wpc-presence-primary, #c82333);
}

.wpc-presence-contact__btn--secondary {
    color: inherit;
    border: 1px solid rgba(0, 0, 0, 0.14);
}

@media (max-width: 480px) {
    .wpc-presence-contact {
        width: calc(100vw - 32px);
        max-width: 300px;
    }

    .wpc-presence-video[data-state="open"] .wpc-presence-video__panel {
        width: calc(100vw - 32px);
        max-width: 288px;
    }
}

/* Respect the visitor's OS setting: resize instantly, never animate. */
@media (prefers-reduced-motion: reduce) {
    .wpc-presence,
    .wpc-presence-video__panel,
    .wpc-presence-video__scrim,
    .wpc-presence-video__controls,
    .wpc-presence-video__cta,
    .wpc-presence-video__toggle,
    .wpc-presence-video__control {
        transition: none !important;
    }
}
