/* =====================================
   Sunpics — Edit WAPF Fields in Cart
   Chrome only (button, panel, actions, loader). WAPF's own CSS drives the inputs/swatches inside the panel.
   ===================================== */

.sun-edit-wapf-in-cart {
    display: inline-block;
}

/* === Edit button === */

.sun-edit-wapf-in-cart__btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    background: transparent;
    border: 1px solid #ccc;
    border-radius: var(--sun-radius-lg, 6px);
    color: #555;
    cursor: pointer;
    font-size: 0.85em;
    line-height: 1.2;
    transition: background-color 0.15s ease, border-color 0.15s ease;
}

.sun-edit-wapf-in-cart__btn:hover {
    background: #f5f5f5;
    border-color: #888;
}

/* Preserve visible outline for keyboard users; remove only when focus came from a pointer. */
.sun-edit-wapf-in-cart__btn:focus-visible {
    outline: 2px solid var(--sun-color-primary, #555);
    outline-offset: 2px;
    background: #f5f5f5;
    border-color: #888;
}

.sun-edit-wapf-in-cart__btn:focus:not(:focus-visible) {
    outline: none;
}

.sun-edit-wapf-in-cart__btn .dashicons {
    font-size: 1em;
    width: 1em;
    height: 1em;
    line-height: 1;
}

/* === Panel container === */

.sun-edit-wapf-panel-row > td {
    background: #fafafa;
    padding: 16px 20px;
    border-bottom: 1px solid #eee;
}

.sun-edit-wapf-panel {
    position: relative;
    background: #fff;
    border: 1px solid #e2e2e2;
    border-radius: var(--sun-radius-lg, 6px);
    padding: 16px;
    scroll-margin-top: 80px; /* leave space for sticky headers when scrolling into view */
}

.sun-edit-wapf-panel__body {
    min-height: 60px;
}

.sun-edit-wapf-panel__actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid #eee;
}

.sun-edit-wapf-panel--busy {
    opacity: 0.6;
    pointer-events: none;
    cursor: wait;
}

/* === Row state (disabled while a panel is open) === */

.woocommerce-cart-form__cart-item.sun-edit-wapf-row-disabled {
    opacity: 0.5;
    pointer-events: none;
}

/* === Loaders === */

.sun-edit-wapf-row-loader,
.sun-edit-wapf-panel-loader {
    position: absolute;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.75);
    backdrop-filter: blur(1px);
    z-index: 1000;
}

.sun-edit-wapf-row-loader {
    pointer-events: all;
}

.sun-edit-wapf-panel-loader {
    inset: 0;
    border-radius: var(--sun-radius-lg, 6px);
}

.sun-edit-wapf-row-loader__spinner {
    width: 36px;
    height: 36px;
    border: 3px solid #e2e2e2;
    border-top-color: var(--sun-color-primary, #555);
    border-radius: 50%;
    animation: sun-edit-wapf-spin 0.8s linear infinite;
    will-change: transform;
}

.sun-edit-wapf-sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

@keyframes sun-edit-wapf-spin {
    to { transform: rotate(360deg); }
}

/* === WAPF field layout overrides (scoped to panel) === */
/* --wapf-cols and --apf-col-width are set inline by WAPF's image-swatch template. */

.sun-edit-wapf-panel .wapf-swatch-wrapper {
    display: flex;
    flex-wrap: wrap;
}

.sun-edit-wapf-panel .wapf-image-swatch-wrapper {
    display: grid;
    grid-template-columns: repeat(var(--wapf-cols, auto-fill), var(--apf-col-width, var(--sun-image-sm, 150px)));
    gap: 10px;
}

.sun-edit-wapf-panel .wapf-checkboxes,
.sun-edit-wapf-panel .wapf-radios {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

/* WooCommerce forces `table.cart img { width: 32px }` — reset for swatch images inside our panel. */
.sun-edit-wapf-panel .wapf-swatch--image img,
.sun-edit-wapf-panel .wapf-image-swatch-wrapper img {
    width: auto !important;
}

/* WAPF re-injects `display: block` via inline style after computing totals; hard override required. */
.sun-edit-wapf-panel .wapf-product-totals {
    display: none !important;
}

/* === Responsive === */

@media (max-width: 600px) {
    .sun-edit-wapf-panel-row > td {
        padding: 12px 10px;
    }

    .sun-edit-wapf-panel {
        padding: 12px;
    }

    .sun-edit-wapf-panel__actions {
        flex-direction: column-reverse;
    }

    .sun-edit-wapf-panel__actions .button {
        width: 100%;
    }

    .sun-edit-wapf-panel .wapf-image-swatch-wrapper {
        grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    }
}

/* === Accessibility: respect user motion preference === */

@media (prefers-reduced-motion: reduce) {
    .sun-edit-wapf-in-cart__btn {
        transition: none;
    }

    .sun-edit-wapf-row-loader__spinner {
        animation-duration: 3s;
    }
}
