/* Post Guard Variable Products Table - Front-end styles */

/* --------------------------------------------------------------
 * Table
 * -------------------------------------------------------------- */
.vptd-wrapper { margin: 10px 0; }
.vptd-table { width: 100%; border-collapse: collapse; margin-bottom: 10px; background: #fff; }
.vptd-table th,
.vptd-table td { padding: 6px; text-align: left; border-bottom: 1px solid #ddd; vertical-align: top; }
.vptd-table th { background-color: #f8f9fa; font-weight: 600; font-size: 12px; }
.vptd-product-row { border-bottom: 10px solid transparent; }
.vptd-col-image { width: 60px; }
.vptd-col-image img { max-width: 40px; height: auto; }
.vptd-col-title h4 { margin: 0 0 2px; font-size: 14px; }
.vptd-col-title a { text-decoration: none; color: #333; }
.vptd-col-title a:hover { color: var(--wd-primary-color, #007cba); }
.vptd-short-desc { font-size: 11px; color: #666; margin-top: 2px; }
.vptd-col-price { min-width: 130px; white-space: nowrap; }
.vptd-price-display { font-size: 14px; font-weight: 600; white-space: nowrap; }
.vptd-price-display .woocommerce-Price-amount { white-space: nowrap; }
.vptd-col-variations { display: none; }
.vptd-variations-row { border-bottom: 10px solid transparent; display: none; }
.vptd-variations-row td { padding: 8px 0; background: transparent; border: none; }
.vptd-wrapper.show-variations .vptd-variations-row,
.vptd-variations-row.show-variation { display: table-row; }

.vptd-variations-repeater { border: 1px solid #ddd; border-radius: 2px; padding: 8px; background: #fff; }
.vptd-variation-item { background: #fff; border: 1px solid #ddd; border-radius: 2px; padding: 4px; margin-bottom: 4px; position: relative; }
.vptd-variation-item:last-child { margin-bottom: 0; }

.vptd-variation-header {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 3px; padding-bottom: 2px; border-bottom: 1px solid #eee;
    min-height: 18px; max-height: 18px; overflow: hidden;
}
.vptd-variation-label { font-weight: 600; color: #333; font-size: 11px; line-height: 14px; flex: 1; }
.vptd-remove-variation-btn {
    background: #dc3545; color: #fff; border: none; border-radius: 1px;
    padding: 0; cursor: pointer; font-size: 8px;
    width: 14px; height: 14px; line-height: 14px; text-align: center; flex-shrink: 0;
}
.vptd-remove-variation-btn:hover { background: #c82333; }

.vptd-form-grid {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 4px; align-items: start;
}
.vptd-field { display: flex; flex-direction: column; gap: 1px; }
.vptd-field label { font-size: 9px; color: #666; font-weight: 500; margin: 0; line-height: 12px; }
.vptd-field-content { display: flex; flex-direction: column; gap: 1px; }

.vptd-attribute-select,
.vptd-quantity {
    padding: 2px 4px; border: 1px solid #ddd; border-radius: 2px;
    font-size: 11px; background: #fff; width: 100%; box-sizing: border-box; height: 22px;
}
.vptd-quantity { max-width: 50px; }

.vptd-custom-length { margin-top: 1px; }
.vptd-custom-length small { color: #666; font-size: 8px; display: block; margin-bottom: 1px; line-height: 10px; }
.vptd-custom-length-input {
    padding: 2px 3px; border: 1px solid #ddd; border-radius: 2px;
    font-size: 10px; width: 50px; height: 20px;
}

.vptd-variation-price {
    font-size: 11px; font-weight: 600; color: var(--wd-primary-color, #007cba);
    min-height: 14px; padding: 1px 0; line-height: 14px;
}

.vptd-col-action { width: 120px; }
.vptd-product-actions { display: flex; flex-direction: column; gap: 4px; }
.vptd-action-buttons { display: flex; gap: 4px; align-items: stretch; }

.vptd-add-product-variations {
    background-color: #000 !important;
    color: #FDE140 !important;
    border: 2px solid #000 !important;
    padding: 4px 8px !important;
    border-radius: 2px;
    cursor: pointer;
    font-size: 12px !important;
    font-weight: 600 !important;
    text-transform: uppercase !important;
    letter-spacing: 0 !important;
    white-space: nowrap !important;
    height: 26px !important;
    line-height: 18px !important;
    flex: 1;
    min-width: 120px;
    transition: background-color 0.15s ease, color 0.15s ease;
}
.vptd-add-product-variations:hover,
.vptd-bulk-add-btn:hover:not(:disabled) {
    background-color: #FDE140 !important;
    color: #000 !important;
    border-color: #000 !important;
}

.vptd-bulk-add-btn {
    background-color: #000 !important;
    color: #FDE140 !important;
    border: 2px solid #000 !important;
    padding: 6px 12px; border-radius: 2px; cursor: pointer;
    font-size: 12px; font-weight: 600;
    transition: background-color 0.15s ease, color 0.15s ease;
}
.vptd-bulk-add-btn:disabled { background-color: #ccc !important; color: #666 !important; border-color: #ccc !important; cursor: not-allowed; opacity: .6; }

.vptd-actions { display: flex; align-items: center; gap: 12px; margin-top: 10px; }
.vptd-message,
.vptd-product-message { flex: 1; }

.vptd-success {
    color: var(--wd-success-color, #155724); padding: 6px;
    background: var(--wd-success-bg, #d4edda); border: 1px solid var(--wd-success-border, #c3e6cb);
    border-radius: 2px; margin-top: 4px; font-size: 11px;
}
.vptd-error {
    color: var(--wd-error-color, #721c24); padding: 6px;
    background: var(--wd-error-bg, #f8d7da); border: 1px solid var(--wd-error-border, #f5c6cb);
    border-radius: 2px; margin-top: 4px; font-size: 11px;
}
.vptd-success a { margin-left: 6px; font-weight: 600; color: var(--wd-success-color, #155724); text-decoration: underline; }

/* --------------------------------------------------------------
 * Inline "Add Variation" button
 * -------------------------------------------------------------- */
.vptd-add-variation-inline-btn {
    background: #000 !important;
    color: #FDE140 !important;
    border: 2px solid #000 !important;
    border-radius: 2px;
    padding: 4px 8px !important;
    cursor: pointer;
    font-size: 0 !important; /* hide the "+" so ::after label takes over */
    font-weight: 600 !important;
    text-transform: uppercase !important;
    white-space: nowrap !important;
    height: 26px !important;
    width: auto !important;
    min-width: 120px !important;
    line-height: 18px !important;
    text-align: center;
    flex: 1 !important;
    transition: background-color 0.15s ease, color 0.15s ease;
}
.vptd-add-variation-inline-btn::after {
    content: "+VARIATION" !important;
    font-size: 12px !important;
    font-weight: 600 !important;
    letter-spacing: 0 !important;
    color: inherit !important;
}
.vptd-add-variation-inline-btn:hover {
    background: #FDE140 !important;
    color: #000 !important;
    border-color: #000 !important;
}

/* --------------------------------------------------------------
 * Popup
 * -------------------------------------------------------------- */
.vptd-popup-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.8); z-index: 999999; display: none;
}
.vptd-popup-content {
    position: fixed; top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    background: white; padding: 20px; border-radius: 2px;
    max-width: 95vw; max-height: 90vh; overflow: auto; z-index: 1000000;
}
.vptd-popup-header {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 20px; padding-bottom: 10px; border-bottom: 1px solid #ddd;
}
.vptd-popup-close {
    background: #dc3545; color: white; border: none; border-radius: 2px;
    width: 30px; height: 30px; cursor: pointer; font-size: 18px; line-height: 1;
}
.vptd-popup-close:hover { background: #c82333; }

/* --------------------------------------------------------------
 * Link box
 * -------------------------------------------------------------- */
.vptd-product-table-link-wrapper { margin: 15px 0; position: relative; z-index: 1; }

.vptd-open-table-popup {
    display: flex; align-items: center; justify-content: center; gap: 8px;
    width: 100%; text-decoration: none; cursor: pointer; font-family: inherit;
    transition: all 0.3s ease; position: relative; overflow: hidden;
}
.vptd-link-text { position: relative; z-index: 2; }
.vptd-link-icon::after {
    content: "\2192"; display: inline-block; transition: transform 0.3s ease;
}
.vptd-open-table-popup:hover .vptd-link-icon::after { transform: translateX(4px); }

/* Style 1: Gradient Glow */
.vptd-style-gradient-glow .vptd-open-table-popup {
    padding: 14px 24px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: none; border-radius: 2px; color: white;
    font-size: 15px; font-weight: 600;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
}
.vptd-style-gradient-glow .vptd-open-table-popup:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.6);
    color: white;
}

/* Style 2: Yellow & Black */
.vptd-style-yellow-black .vptd-open-table-popup {
    padding: 14px 24px;
    background: linear-gradient(135deg, #fde140 0%, #f9c74f 100%);
    border: 2px solid #000; border-radius: 2px; color: #000;
    font-size: 15px; font-weight: 700;
    box-shadow: 0 4px 15px rgba(253, 225, 64, 0.4);
    text-transform: uppercase; letter-spacing: 0.5px;
}
.vptd-style-yellow-black .vptd-open-table-popup:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(253, 225, 64, 0.6), 0 8px 25px rgba(0, 0, 0, 0.15);
    background: linear-gradient(135deg, #f9c74f 0%, #fde140 100%);
    color: #000;
}
.vptd-style-yellow-black .vptd-open-table-popup::before {
    content: ""; position: absolute; top: 0; left: -100%;
    width: 100%; height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.4), transparent);
    transition: left 0.5s ease;
}
.vptd-style-yellow-black .vptd-open-table-popup:hover::before { left: 100%; }

/* --------------------------------------------------------------
 * Responsive
 *
 * Below 768px the <table> layout is broken: with min-widths on the
 * price (130px) and action (200px) columns plus white-space:nowrap on
 * price, the 5-column grid won't fit on a phone and the title column
 * gets crushed. We break out of table layout entirely and render each
 * product as a stacked card. Each <tr> and <td> becomes a block; the
 * variations form drops below the product row as the card's body.
 *
 * The show/hide toggle for .vptd-variations-row is preserved because
 * the JS always pairs .show()/.hide() with addClass/removeClass of
 * 'show-variation' (see pgvt-frontend.js lines 107 and 277), so a
 * class-based CSS toggle stays in sync with the rest of the script.
 * -------------------------------------------------------------- */
@media (max-width: 767px) {
    .vptd-hide-mobile { display: none !important; }
}

@media (max-width: 768px) {
    /* Popup chrome - full-bleed sheet, top-aligned (not centered) so the
       header is at the very top edge of the viewport. */
    .vptd-popup-overlay {
        position: fixed !important; top: 0 !important; left: 0 !important;
        right: 0 !important; bottom: 0 !important;
        width: 100% !important; height: 100% !important; overflow: hidden !important;
    }
    .vptd-popup-content {
        top: 0 !important; left: 0 !important;
        transform: none !important;
        width: 100vw !important; max-width: 100vw !important;
        /* 100vh on iOS Safari extends behind the URL bar, hiding the
           bottom of the popup. 100dvh tracks the actually visible
           viewport. The 100vh line is the fallback for older browsers. */
        height: 100vh !important; max-height: 100vh !important;
        height: 100dvh !important; max-height: 100dvh !important;
        padding: 0 10px max(10px, env(safe-area-inset-bottom)) !important;
        margin: 0 !important;
        border-radius: 0 !important;
        /* Offset scrollIntoView so newly-added variations don't hide
           behind the sticky header */
        scroll-padding-top: 70px;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
    }
    /* Pin the header so the close button is always reachable while
       scrolling through products. Negative horizontal margin lets it
       span edge-to-edge across the popup's 10px side padding. */
    .vptd-popup-header {
        position: sticky !important;
        top: 0 !important;
        z-index: 10 !important;
        background: #fff !important;
        margin: 0 -10px 10px !important;
        padding: 10px 14px !important;
        border-bottom: 1px solid #ddd !important;
    }
    .vptd-popup-header h3 { font-size: 18px !important; margin: 0 !important; }
    .vptd-popup-close {
        width: 44px !important; height: 44px !important;
        font-size: 22px !important; line-height: 1 !important;
        border-radius: 4px !important;
        flex-shrink: 0;
    }

    /* Link box */
    .vptd-product-table-link-wrapper { margin: 10px 0; }
    .vptd-open-table-popup { font-size: 13px; padding: 10px 16px; }
    .vptd-style-gradient-glow .vptd-open-table-popup,
    .vptd-style-yellow-black .vptd-open-table-popup { padding: 12px 18px; font-size: 14px; }

    /* Break out of <table> layout into vertical block flow */
    .vptd-table,
    .vptd-table thead,
    .vptd-table tbody,
    .vptd-table th,
    .vptd-table td {
        display: block;
        width: auto;
        max-width: none;
        min-width: 0;
        white-space: normal;
    }
    .vptd-table { border-collapse: separate; min-width: 0 !important; }
    .vptd-table thead { display: none; }

    /* Empty placeholder columns - keep hidden */
    .vptd-col-image,
    .vptd-col-variations { display: none !important; }

    /* Product row = card */
    .vptd-product-row {
        display: block;
        background: #f8f9fa;
        border: 1px solid #ddd;
        border-radius: 4px;
        padding: 10px;
        margin-top: 14px;
    }
    .vptd-product-row > td {
        padding: 4px 0 !important;
        border: none !important;
        background: transparent !important;
    }

    /* Variations row toggle - keep in sync with the JS class toggle.
       Base hidden via !important so jQuery's inline display:none from
       .hide() isn't needed; show-variation class drives visibility. */
    .vptd-variations-row { display: none !important; padding: 0 !important; margin: 0 0 14px !important; }
    .vptd-wrapper.show-variations .vptd-variations-row,
    .vptd-variations-row.show-variation { display: block !important; }
    .vptd-variations-row > td {
        padding: 8px 0 0 !important;
        border: none !important;
        background: transparent !important;
    }

    /* Title + description */
    .vptd-col-title h4 { font-size: 16px; margin: 0 0 4px; line-height: 1.25; }
    .vptd-short-desc { font-size: 12px; margin-top: 4px; }

    /* Price - drop the desktop nowrap/min-width constraints */
    .vptd-col-price { font-size: 15px; }
    .vptd-price-display { font-size: 15px; white-space: normal; }
    .vptd-price-display .woocommerce-Price-amount { white-space: normal; }

    /* Variation form - 2-column grid, tap-sized inputs */
    .vptd-form-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
    .vptd-field label { font-size: 11px; line-height: 14px; }
    .vptd-attribute-select,
    .vptd-quantity {
        font-size: 14px;
        height: 36px;
        padding: 6px 8px;
        max-width: none;
    }
    .vptd-quantity { max-width: 80px; }
    .vptd-custom-length-input {
        width: 80px;
        height: 32px;
        font-size: 13px;
        padding: 4px 6px;
    }
    .vptd-custom-length small { font-size: 11px; line-height: 14px; }

    .vptd-variation-item { padding: 8px; margin-bottom: 8px; }
    .vptd-variation-header {
        min-height: 22px; max-height: none;
        margin-bottom: 6px; padding-bottom: 4px;
    }
    .vptd-variation-label { font-size: 13px; line-height: 18px; }
    .vptd-remove-variation-btn {
        width: 24px; height: 24px;
        font-size: 14px; line-height: 24px;
        border-radius: 2px;
    }
    .vptd-variation-price { font-size: 13px; min-height: 18px; line-height: 18px; }

    /* Per-product action buttons - side-by-side, tap-friendly */
    .vptd-col-action { padding-top: 8px !important; }
    .vptd-product-actions { width: 100%; }
    .vptd-action-buttons {
        flex-direction: row !important;
        gap: 8px !important;
    }
    .vptd-add-product-variations,
    .vptd-add-variation-inline-btn {
        flex: 1 !important;
        min-width: 0 !important;
        width: auto !important;
        font-size: 13px !important;
        padding: 8px 6px !important;
        height: 40px !important;
        line-height: 24px !important;
    }
    .vptd-add-variation-inline-btn::after { font-size: 13px !important; }

    /* Bottom-of-table bulk add */
    .vptd-actions { flex-direction: column; align-items: stretch; gap: 8px; margin-top: 16px; }
    .vptd-bulk-add-btn { padding: 12px; font-size: 14px; }

    /* Inside the popup, pin the bulk action bar to the bottom of the
       scroll viewport so it's always reachable - mirrors the sticky
       header. Scoped to .vptd-popup-content so inline shortcode usage
       is unaffected. */
    .vptd-popup-content .vptd-actions {
        position: sticky;
        bottom: 0;
        z-index: 5;
        background: #fff;
        margin: 16px -10px 0;
        padding: 10px 14px;
        border-top: 1px solid #ddd;
    }
}

@media (max-width: 480px) {
    /* Popup is already full-bleed from the 768px block; no further
       overrides needed. Keep buttons side-by-side on phones - vertical
       stacking wastes space and pushes the bulk-add button below the
       fold. */
}