/* ==========================================================================
   Template Product Manager — Frontend Styles
   ========================================================================== */

/* ---- Wrapper ------------------------------------------------------------- */
.tpm-wrapper {
    box-sizing: border-box;
}

/* ---- Filter bar ---------------------------------------------------------- */
.tpm-filters {
    background: #fff;
    padding: 15px;
    margin-bottom: 15px;
    border: 1px solid #ddd;
    border-radius: 4px;
}

.tpm-filter-form {
    margin: 0;
}

.tpm-filter-row {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.tpm-filter-input {
    box-sizing: border-box;
    flex: 1;
    min-width: 200px;
    padding: 8px 12px;
    border: 1px solid #ccc;
    border-radius: 3px;
}

.tpm-filter-select {
    box-sizing: border-box;
    min-width: 120px;
    padding: 8px 12px;
    border: 1px solid #ccc;
    border-radius: 3px;
    width: auto !important;
}

/*
 * Specificity note: WoodMart sets a theme-wide fixed height on form
 * controls via `input[type='text'], ... , :root select { height:
 * var(--wd-form-height); }`. Because native <select> and <input>
 * elements render their padding/line-height differently even at an
 * identical explicit height, that shared height value produces visibly
 * different total heights per element -- selects and text inputs end up
 * misaligned. Forcing height back to auto (matched here by ancestor +
 * class = (0,2,0) plus !important) lets each control size itself from
 * its own padding instead, which is what actually keeps them aligned.
 */
.tpm-wrapper .tpm-filter-select,
.tpm-wrapper .tpm-filter-input {
    height: auto !important;
}

.tpm-filter-btn,
.tpm-clear-btn {
    white-space: nowrap;
    padding: 8px 16px;
    border-radius: 3px;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    display: inline-block;
}

/* ---- Secondary filter row (Product Type, Sort By, Price, Visibility, ID) - */
.tpm-filter-row--secondary {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid #eee;
    align-items: flex-end;
}

.tpm-filter-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 150px;
    flex: 1;
}

.tpm-filter-label {
    font-size: 12px;
    font-weight: 600;
    color: #555;
}

.tpm-filter-group .tpm-filter-select,
.tpm-filter-group .tpm-filter-input {
    width: 100%;
    min-width: 0;
}

.tpm-filter-input--id {
    padding: 8px 12px;
    border: 1px solid #ccc;
    border-radius: 3px;
}

.tpm-clear-btn {
    background: var(--wd-secondary-color, #6c757d);
    border: none;
    transition: opacity 0.2s ease;
}

/*
 * Specificity note: this page embeds the shortcode inside an Elementor
 * Text Editor widget, which ships a global rule:
 *   .elementor-widget-text-editor a:not(.elementor-button) { color: #ad6738 !important; }
 * That selector has 2 classes + 1 tag (specificity 0,2,1). A plain
 * `.tpm-clear-btn { color: ... !important; }` (0,1,0) loses that fight
 * even though both are !important, since specificity still decides ties
 * within the !important tier. Qualifying with the .tpm-wrapper ancestor
 * plus the .button class already on the markup gets us to (0,3,1), which
 * wins cleanly without needing an even-later stylesheet or an ID hack.
 */
.tpm-wrapper a.button.tpm-clear-btn {
    color: var(--wd-secondary-color-text, #fff) !important;
}

.tpm-clear-btn:hover {
    opacity: 0.85;
    text-decoration: none;
}

.tpm-wrapper a.button.tpm-clear-btn:hover {
    color: var(--wd-secondary-color-text, #fff) !important;
}

/* ---- Table container (horizontal scroll) --------------------------------- */
.tpm-table-container {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border: 1px solid #ddd;
    border-radius: 4px;
    scroll-behavior: smooth;
}

.tpm-table-container::-webkit-scrollbar        { height: 8px; }
.tpm-table-container::-webkit-scrollbar-track  { background: #f1f1f1; border-radius: 4px; }
.tpm-table-container::-webkit-scrollbar-thumb  { background: #c1c1c1; border-radius: 4px; }
.tpm-table-container::-webkit-scrollbar-thumb:hover { background: #a1a1a1; }

/* ---- Products table ------------------------------------------------------ */
.tpm-products-table {
    min-width: 820px;
    margin: 0;
    border: none;
    border-collapse: collapse;
}

.tpm-products-table th {
    font-size: 14px !important;
    white-space: nowrap;
}

/* Column widths */
.tpm-col-image      { width: 80px;  min-width: 80px; }
.tpm-col-name       { width: 220px; min-width: 200px; }
.tpm-col-sku        { width: 110px; min-width: 100px; font-size: 12px; }
.tpm-col-price      { width: 110px; min-width: 100px; font-size: 12px; }
.tpm-col-visibility { width: 140px; min-width: 130px; }
.tpm-col-actions    { width: 90px;  min-width: 80px; }

/* ---- Product name cell --------------------------------------------------- */
.tpm-product-title {
    font-weight: bold;
    font-size: 14px;
    line-height: 1.4;
    margin-bottom: 4px;
}

.tpm-product-id {
    font-size: 12px;
    color: #666;
    line-height: 1.2;
}

/* ---- Clickable image thumbnail ------------------------------------------ */
.tpm-image-trigger {
    display: inline-block;
    cursor: zoom-in;
    border-radius: 2px;
    outline: none;
    transition: opacity 0.2s ease, box-shadow 0.2s ease;
}
.tpm-image-trigger:hover,
.tpm-image-trigger:focus {
    opacity: 0.85;
    box-shadow: 0 0 0 2px var(--wd-primary-color, #d4af37);
}
.tpm-image-trigger img {
    display: block;
}

/* ---- Lightbox modal ------------------------------------------------------ */
.tpm-modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 999999;
    align-items: center;
    justify-content: center;
}
.tpm-modal.tpm-modal--open {
    display: flex;
}
.tpm-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.75);
    cursor: pointer;
}
.tpm-modal-content {
    position: relative;
    background: #fff;
    border-radius: 6px;
    padding: 16px;
    max-width: 90vw;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.35);
    z-index: 1;
}
.tpm-modal-close {
    position: absolute;
    top: 8px;
    right: 10px;
    background: none;
    border: none;
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
    color: #555;
    padding: 0 4px;
    transition: color 0.2s ease;
}
.tpm-modal-close:hover { color: #000; }
.tpm-modal-title {
    margin: 0;
    font-size: 14px;
    font-weight: 600;
    color: #333;
    text-align: center;
    padding-right: 24px;
}
.tpm-modal-img {
    display: block;
    max-width: 80vw;
    max-height: 70vh;
    width: auto;
    height: auto;
    border-radius: 3px;
    object-fit: contain;
}

/* ---- No-image placeholder ------------------------------------------------ */
.tpm-no-image {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 50px;
    height: 50px;
    background: #f0f0f0;
    border: 1px solid #ddd;
    font-size: 10px;
    text-align: center;
    color: #666;
    border-radius: 2px;
}

/* ---- Visibility select & status ----------------------------------------- */
.tpm-visibility-select {
    width: 100%;
    padding: 5px 8px;
    border: 1px solid #ccc;
    border-radius: 3px;
}

.tpm-visibility-status {
    font-size: 11px;
    margin-top: 3px;
    min-height: 14px;
}

/* ---- View button (WordPress default button grey) -------------------------- */
.tpm-view-btn {
    padding: 5px 12px;
    text-decoration: none;
    display: inline-block;
    border-radius: 3px;
    font-weight: 500;
    font-size: 13px;
    transition: background 0.15s ease, border-color 0.15s ease;
}

/*
 * Specificity note: the theme also has:
 *   .btn-accented, .button-primary, .woodmart-button, a.button { background-color: #ad6738 !important; }
 * The relevant clause here, `a.button`, is (tag + class) = specificity
 * (0,1,1), which beats a plain `.tpm-view-btn { background: ... !important }`
 * (0,1,0) even though both are !important. Qualifying with the .tpm-wrapper
 * ancestor plus the .button class already on the markup gets us to (0,3,1),
 * which wins cleanly -- same fix already applied to the text color below.
 */
.tpm-wrapper a.button.tpm-view-btn {
    background: #f6f7f7 !important;
    border: 1px solid #dcdcde !important;
    color: #2c3338 !important;
}

.tpm-view-btn:hover {
    text-decoration: none;
}

.tpm-wrapper a.button.tpm-view-btn:hover {
    background: #f0f0f1 !important;
    border-color: #8c8f94 !important;
    color: #2c3338 !important;
}

/* ---- Summary line -------------------------------------------------------- */
.tpm-summary {
    margin-top: 10px;
    font-size: 13px;
    color: #555;
}

/* ---- Pagination ----------------------------------------------------------- */
.tpm-pagination {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    margin-top: 15px;
}

.tpm-pagination .page-numbers {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 34px;
    height: 34px;
    padding: 0 8px;
    border: 1px solid #ddd;
    border-radius: 3px;
    background: #fff;
    color: #333;
    text-decoration: none;
    font-size: 13px;
    transition: opacity 0.2s ease, background 0.2s ease;
}

.tpm-pagination .page-numbers:hover {
    background: #f5f5f5;
    text-decoration: none;
}

.tpm-wrapper .tpm-pagination .page-numbers.current {
    background: #dcdcde !important;
    color: #1d2327 !important;
    border-color: #8c8f94 !important;
    font-weight: 600;
}

.tpm-pagination .page-numbers.dots {
    border: none;
    background: none;
}

@media (max-width: 479px) {
    .tpm-pagination .page-numbers {
        min-width: 30px;
        height: 30px;
        font-size: 12px;
    }
}

/* ==========================================================================
   Desktop (≥ 768 px)
   ========================================================================== */
@media (min-width: 768px) {
    .tpm-filter-row {
        flex-wrap: nowrap;
        gap: 15px;
    }

    .tpm-filter-input {
        flex: 2;
        min-width: 250px;
        max-width: 400px;
        padding: 10px 12px;
    }

    .tpm-filter-select {
        flex: 0 0 auto;
        min-width: 140px;
        padding: 10px 12px;
    }

    .tpm-filter-btn,
    .tpm-clear-btn {
        flex: 0 0 auto;
        padding: 10px 20px;
        min-width: 80px;
    }

    .tpm-filter-row--secondary {
        flex-wrap: wrap;
    }

    .tpm-filter-group {
        flex: 1 1 180px;
    }
}

/* ==========================================================================
   Mobile (< 768 px)
   ========================================================================== */
@media (max-width: 767px) {
    .tpm-filter-row {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
    }

    .tpm-filter-input,
    .tpm-filter-select,
    .tpm-filter-btn,
    .tpm-clear-btn {
        width: 100%;
        min-width: unset;
    }

    .tpm-filter-input { padding: 10px; }

    .tpm-filter-row--secondary {
        flex-direction: column;
        align-items: stretch;
    }

    .tpm-filter-group { min-width: unset; }

    /* Wider table floor for small viewports */
    .tpm-products-table { min-width: 900px; font-size: 14px; }

    .tpm-products-table th,
    .tpm-products-table td {
        text-align: center;
        vertical-align: middle;
    }

    .tpm-col-name    { text-align: left; }
    .tpm-col-image   { text-align: center; }

    .tpm-col-image img,
    .tpm-no-image { margin: 0 auto; display: block; }

    .tpm-visibility-select { margin: 0 auto; display: block; }

    .tpm-products-table th { background: #f9f9f9; font-size: 12px !important; }

    .tpm-col-image    { width: 70px; min-width: 70px; }
    .tpm-col-name     { width: 180px; min-width: 180px; }

    .tpm-product-title { font-size: 13px; line-height: 1.3; margin-bottom: 2px; }
    .tpm-product-id    { font-size: 9px; }

    .tpm-visibility-select { padding: 6px; font-size: 10px; }

    .tpm-view-btn { padding: 4px 8px; font-size: 10px; }

    .tpm-no-image { width: 40px; height: 40px; font-size: 9px; }
}

/* ==========================================================================
   Small mobile (< 480 px)
   ========================================================================== */
@media (max-width: 479px) {
    .tpm-filters { padding: 10px; }
    .tpm-filter-row { gap: 6px; }

    .tpm-products-table { min-width: 950px; font-size: 10px; }

    .tpm-products-table th,
    .tpm-products-table td { padding: 6px 4px; }
}
