/**
 * Linked Products for WooCommerce - Frontend Styles
 * Compatible with Kadence Theme and most WooCommerce themes
 */

/* ========================================
   WRAPPER
   ======================================== */
.lpw-wrapper {
    margin: 1.5em 0;
    padding: 1.5em;
    border: 1px solid #e5e7eb;
    border-radius: var(--lpw-radius, 8px);
    background: #fafbfc;
    font-size: 0.95em;
}

.lpw-heading {
    margin: 0 0 1em 0;
    padding: 0 0 0.6em 0;
    border-bottom: 2px solid #e5e7eb;
    font-size: 1.15em;
    font-weight: 600;
    color: inherit;
    line-height: 1.4;
}

/* ========================================
   LIST LAYOUT
   ======================================== */
.lpw-list .lpw-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 0;
    border-bottom: 1px solid #f0f0f0;
    transition: background-color 0.2s ease;
}

.lpw-list .lpw-item:last-child {
    border-bottom: none;
}

.lpw-list .lpw-item:hover {
    background-color: #f5f7ff;
    border-radius: var(--lpw-radius, 8px);
    padding-left: 8px;
    padding-right: 8px;
    margin-left: -8px;
    margin-right: -8px;
}

/* ========================================
   GRID LAYOUT
   ======================================== */
.lpw-grid {
    display: grid;
    grid-template-columns: repeat(var(--lpw-columns, 3), 1fr);
    gap: 16px;
}

.lpw-grid .lpw-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: 16px 12px;
    border: 1px solid #e5e7eb;
    border-radius: var(--lpw-radius, 8px);
    background: #fff;
    transition: box-shadow 0.2s ease, border-color 0.2s ease;
}

.lpw-grid .lpw-item:hover {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    border-color: #d1d5db;
}

.lpw-grid .lpw-item.lpw-item-checked {
    border-color: var(--lpw-accent, #2563eb);
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.15);
}

/* ========================================
   CHECKBOX
   ======================================== */
.lpw-checkbox-wrap {
    position: relative;
    display: inline-flex;
    align-items: center;
    cursor: pointer;
    flex-shrink: 0;
}

.lpw-checkbox-wrap input[type="checkbox"] {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.lpw-checkmark {
    display: inline-block;
    width: 22px;
    height: 22px;
    border: 2px solid #cbd5e1;
    border-radius: 4px;
    background: #fff;
    transition: all 0.15s ease;
    position: relative;
    flex-shrink: 0;
}

.lpw-checkbox-wrap input:checked + .lpw-checkmark {
    background-color: var(--lpw-accent, #2563eb);
    border-color: var(--lpw-accent, #2563eb);
}

.lpw-checkbox-wrap input:checked + .lpw-checkmark::after {
    content: '';
    position: absolute;
    left: 6px;
    top: 2px;
    width: 6px;
    height: 11px;
    border: solid #fff;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}

.lpw-checkbox-wrap input:focus-visible + .lpw-checkmark {
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.3);
}

.lpw-checkbox-wrap input:disabled + .lpw-checkmark {
    opacity: 0.4;
    cursor: not-allowed;
}

/* ========================================
   PRODUCT IMAGE
   ======================================== */
.lpw-item-image {
    flex-shrink: 0;
    width: 60px;
    height: 60px;
    overflow: hidden;
    border-radius: calc(var(--lpw-radius, 8px) / 2);
    background: #fff;
    border: 1px solid #eee;
}

.lpw-item-image a {
    display: block;
    line-height: 0;
}

.lpw-item-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.2s ease;
}

.lpw-item:hover .lpw-item-image img {
    transform: scale(1.05);
}

.lpw-grid .lpw-item-image {
    width: 80px;
    height: 80px;
    margin-bottom: 8px;
}

/* ========================================
   PRODUCT DETAILS
   ======================================== */
.lpw-item-details {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.lpw-item-name {
    color: inherit;
    text-decoration: none;
    font-weight: 600;
    font-size: 0.95em;
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.lpw-item-name:hover {
    color: var(--lpw-accent, #2563eb);
    text-decoration: underline;
}

.lpw-item-sku {
    font-size: 0.8em;
    color: #9ca3af;
}

.lpw-item-desc {
    font-size: 0.85em;
    color: #6b7280;
    margin: 2px 0 0 0;
    line-height: 1.4;
}

.lpw-item-price {
    font-weight: 600;
    color: #111;
    font-size: 0.95em;
}

.lpw-item-price del {
    color: #9ca3af;
    font-weight: 400;
}

.lpw-item-price ins {
    text-decoration: none;
    color: #dc2626;
}

.lpw-stock-badge {
    display: inline-block;
    font-size: 0.75em;
    padding: 2px 8px;
    border-radius: 3px;
    font-weight: 500;
}

.lpw-stock-out {
    background: #fef2f2;
    color: #dc2626;
}

/* ========================================
   QUANTITY CONTROL
   ======================================== */
.lpw-item-qty {
    flex-shrink: 0;
}

.lpw-qty-control {
    display: inline-flex;
    align-items: center;
    border: 1px solid #d1d5db;
    border-radius: calc(var(--lpw-radius, 8px) / 2);
    overflow: hidden;
    background: #fff;
}

.lpw-qty-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 36px;
    border: none;
    background: #f9fafb;
    color: #374151;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
    line-height: 1;
    padding: 0;
}

.lpw-qty-btn:hover {
    background: #e5e7eb;
}

.lpw-qty-btn:active {
    background: #d1d5db;
}

.lpw-qty-input {
    width: 44px !important;
    height: 36px;
    text-align: center;
    border: none !important;
    border-left: 1px solid #e5e7eb !important;
    border-right: 1px solid #e5e7eb !important;
    font-size: 14px;
    font-weight: 500;
    -moz-appearance: textfield;
    padding: 0 !important;
    margin: 0 !important;
    background: #fff !important;
    box-shadow: none !important;
    outline: none !important;
    border-radius: 0 !important;
    min-height: auto !important;
}

.lpw-qty-input::-webkit-outer-spin-button,
.lpw-qty-input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.lpw-qty-input:disabled {
    opacity: 0.4;
}

/* ========================================
   OUT OF STOCK ITEM
   ======================================== */
.lpw-item.lpw-out-of-stock {
    opacity: 0.5;
    pointer-events: none;
}

.lpw-item.lpw-out-of-stock .lpw-item-name {
    pointer-events: auto;
}

/* ========================================
   FOOTER (Button + Select All)
   ======================================== */
.lpw-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-top: 1em;
    padding-top: 1em;
    border-top: 1px solid #e5e7eb;
    flex-wrap: wrap;
}

.lpw-select-all-wrap {
    flex-shrink: 0;
}

.lpw-select-all-label {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    font-size: 0.9em;
    color: #6b7280;
    font-weight: 500;
}

.lpw-select-all-label:hover {
    color: #374151;
}

.lpw-add-to-cart-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.95em;
    transition: all 0.2s ease;
    white-space: nowrap;
}

/* Custom button style */
.lpw-btn-custom {
    padding: 10px 24px;
    border: none;
    border-radius: var(--lpw-radius, 8px);
    background-color: var(--lpw-btn-bg, #2563eb);
    color: var(--lpw-btn-color, #fff);
}

.lpw-btn-custom:hover {
    opacity: 0.9;
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.lpw-btn-custom:active {
    transform: translateY(0);
}

.lpw-add-to-cart-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none !important;
}

/* Spinner animation */
.lpw-btn-spinner svg {
    animation: lpw-spin 1s linear infinite;
}

@keyframes lpw-spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* ========================================
   MESSAGE / NOTIFICATION
   ======================================== */
.lpw-message {
    margin-top: 12px;
    padding: 10px 14px;
    border-radius: calc(var(--lpw-radius, 8px) / 2);
    font-size: 0.9em;
    line-height: 1.4;
    animation: lpw-fadeIn 0.3s ease;
}

.lpw-message-success {
    background: #f0fdf4;
    color: #166534;
    border: 1px solid #bbf7d0;
}

.lpw-message-error {
    background: #fef2f2;
    color: #991b1b;
    border: 1px solid #fecaca;
}

@keyframes lpw-fadeIn {
    from { opacity: 0; transform: translateY(-4px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ========================================
   RESPONSIVE
   ======================================== */
@media (max-width: 768px) {
    .lpw-wrapper {
        padding: 1em;
    }

    .lpw-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }

    .lpw-list .lpw-item {
        flex-wrap: wrap;
        gap: 8px;
    }

    .lpw-item-details {
        flex-basis: calc(100% - 100px);
    }

    .lpw-item-qty {
        margin-left: auto;
    }

    .lpw-footer {
        flex-direction: column;
        align-items: stretch;
    }

    .lpw-add-to-cart-btn {
        width: 100%;
        justify-content: center;
        padding: 12px 16px;
    }
}

@media (max-width: 480px) {
    .lpw-grid {
        grid-template-columns: 1fr;
    }

    .lpw-item-image {
        width: 50px;
        height: 50px;
    }

    .lpw-qty-btn {
        width: 28px;
        height: 32px;
    }

    .lpw-qty-input {
        width: 36px !important;
        height: 32px;
    }
}

/* ========================================
   KADENCE THEME COMPATIBILITY
   ======================================== */
.entry-content .lpw-wrapper,
.single-product .lpw-wrapper {
    max-width: 100%;
}

.kadence-pro .lpw-wrapper,
.kb-row-layout-inner .lpw-wrapper {
    font-family: inherit;
}

/* Reset Kadence button overrides */
.lpw-wrapper .lpw-qty-btn,
.lpw-wrapper .lpw-add-to-cart-btn {
    letter-spacing: normal;
    text-transform: none;
}

/* Ensure WooCommerce button styles apply well */
.lpw-wrapper .button.alt {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

/* Fix Kadence's aggressive input styling */
.lpw-wrapper input[type="number"].lpw-qty-input {
    border-radius: 0 !important;
    min-height: auto !important;
    line-height: normal !important;
}

/* ========================================
   DARK MODE SUPPORT (if theme supports)
   ======================================== */
@media (prefers-color-scheme: dark) {
    .lpw-wrapper[data-theme="auto"] {
        background: #1f2937;
        border-color: #374151;
    }

    .lpw-wrapper[data-theme="auto"] .lpw-heading {
        border-color: #374151;
    }

    .lpw-wrapper[data-theme="auto"] .lpw-grid .lpw-item {
        background: #111827;
        border-color: #374151;
    }
}

/* ========================================
   PRINT
   ======================================== */
@media print {
    .lpw-wrapper {
        border: 1px solid #ccc;
        background: #fff;
    }

    .lpw-add-to-cart-btn,
    .lpw-qty-control,
    .lpw-checkbox-wrap,
    .lpw-select-all-wrap,
    .lpw-footer {
        display: none !important;
    }
}
