/* TP4R Product Filter - Frontend Styles */

:root {
    --tp4r-primary: #2271b1;
    --tp4r-primary-hover: #135e96;
    --tp4r-accent: #00a0a0;
    --tp4r-border: #dcdcde;
    --tp4r-bg: #f6f7f7;
    --tp4r-text: #1d2327;
    --tp4r-text-muted: #646970;
    --tp4r-chip-bg: #e8f0fe;
    --tp4r-chip-text: #1a56db;
    --tp4r-swatch-size: 28px;
    --tp4r-drawer-width: 320px;
    --tp4r-transition: 0.25s ease;
}

/* Filter Wrap */
.tp4r-filter-wrap {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-size: 14px;
    color: var(--tp4r-text);
    line-height: 1.5;
}

.tp4r-filter-inline {
    background: #fff;
    border: 1px solid var(--tp4r-border);
    border-radius: 8px;
    padding: 16px;
    margin-bottom: 20px;
}

/* Active Filters Bar */
.tp4r-active-filters {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    padding-bottom: 12px;
    margin-bottom: 12px;
    border-bottom: 1px solid var(--tp4r-border);
}

.tp4r-sort-select {
    width: 100%;
    border-radius: 5px;
    padding: 10px;
    border: 1px solid #ccc;
}

.tp4r-active-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    flex: 1;
}

.tp4r-active-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: var(--tp4r-chip-bg);
    color: var(--tp4r-chip-text);
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 500;
}

.tp4r-remove-filter {
    background: none;
    border: none;
    color: var(--tp4r-chip-text);
    cursor: pointer;
    font-size: 14px;
    line-height: 1;
    padding: 0 2px;
    opacity: 0.7;
}

.tp4r-remove-filter:hover {
    opacity: 1;
}

.tp4r-reset-all,
.tp4r-reset-btn {
    background: none;
    border: 1px solid var(--tp4r-border);
    color: var(--tp4r-text-muted);
    padding: 4px 12px;
    border-radius: 4px;
    font-size: 12px;
    cursor: pointer;
    transition: all var(--tp4r-transition);
}

.tp4r-reset-all:hover,
.tp4r-reset-btn:hover {
    border-color: var(--tp4r-primary);
    color: var(--tp4r-primary);
}

/* Filter Groups */
.tp4r-filter-group {
    border-bottom: 1px solid var(--tp4r-border);
    padding-bottom: 12px;
    margin-bottom: 12px;
}

.tp4r-filter-group:last-child {
    border-bottom: none;
    padding-bottom: 0;
    margin-bottom: 0;
}

.tp4r-group-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    padding: 6px 0;
    user-select: none;
}

.tp4r-group-label {
    font-weight: 600;
    font-size: 14px;
    color: var(--tp4r-text);
}

.tp4r-group-toggle {
    color: var(--tp4r-text-muted);
    transition: transform var(--tp4r-transition);
    display: flex;
    align-items: center;
}

.tp4r-group-header.tp4r-collapsed .tp4r-group-toggle {
    transform: rotate(-90deg);
}

[dir="rtl"] .tp4r-group-header.tp4r-collapsed .tp4r-group-toggle {
    transform: rotate(90deg);
}

.tp4r-group-body {
    padding-top: 8px;
    overflow-y: auto;
    max-height: 200px;
}

/* Checkbox / Radio List */
.tp4r-checkbox-list,
.tp4r-radio-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.tp4r-checkbox-list li,
.tp4r-radio-list li {
    margin-bottom: 4px;
}

.tp4r-checkbox-list label,
.tp4r-radio-list label {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 0 0 10px;
    margin: 0 !important;
    border-radius: 4px;
    cursor: pointer;
    transition: background var(--tp4r-transition);
    font-size: 13px;
}

.tp4r-checkbox-list label:hover,
.tp4r-radio-list label:hover {
    background: var(--tp4r-bg);
}

/* Custom checkbox */
.tp4r-checkbox-list input[type="checkbox"],
.tp4r-radio-list input[type="radio"] {
    appearance: none;
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    border: 2px solid var(--tp4r-border);
    border-radius: 3px;
    cursor: pointer;
    position: relative;
    flex-shrink: 0;
    transition: all 0.15s;
}

.tp4r-radio-list input[type="radio"] {
    border-radius: 50%;
}

.tp4r-checkbox-list input[type="checkbox"]:checked,
.tp4r-radio-list input[type="radio"]:checked {
    background: var(--tp4r-primary);
    border-color: var(--tp4r-primary);
}

.tp4r-checkbox-list input[type="checkbox"]:checked::after {
    content: '';
    position: absolute;
    top: 1px;
    left: 4px;
    width: 4px;
    height: 8px;
    border: solid #fff;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}

.tp4r-radio-list input[type="radio"]:checked::after {
    content: '';
    position: absolute;
    top: 3px;
    left: 3px;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #fff;
}

.tp4r-term-name {
    flex: 1;
}

.tp4r-term-count {
    color: var(--tp4r-text-muted);
    font-size: 11px;
}

/* Hierarchical (nested) */
.tp4r-checkbox-list .tp4r-children {
    padding-inline-start: 20px;
    list-style: none;
    margin: 0;
}

/* Dropdown / Select */
.tp4r-select {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--tp4r-border);
    border-radius: 4px;
    font-size: 13px;
    color: var(--tp4r-text);
    background: #fff;
    cursor: pointer;
}

.tp4r-select:focus {
    border-color: var(--tp4r-primary);
    outline: none;
    box-shadow: 0 0 0 1px var(--tp4r-primary);
}

/* Swatch Widget */
.tp4r-swatch-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.tp4r-swatch-item {
    width: var(--tp4r-swatch-size);
    height: var(--tp4r-swatch-size);
    border-radius: 4px;
    cursor: pointer;
    position: relative;
    border: 2px solid transparent;
    transition: all 0.15s;
}

.tp4r-swatch-item:hover {
    transform: scale(1.1);
}

.tp4r-swatch-item.tp4r-selected {
    border-color: var(--tp4r-primary);
    box-shadow: 0 0 0 1px var(--tp4r-primary);
}

.tp4r-swatch-item.tp4r-selected::after {
    content: '✓';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: #fff;
    font-size: 14px;
    font-weight: bold;
    text-shadow: 0 1px 2px rgba(0,0,0,0.5);
}

.tp4r-swatch-color {
    display: block;
    width: 100%;
    height: 100%;
    border-radius: 2px;
}

.tp4r-swatch-count {
    position: absolute;
    top: -6px;
    inset-inline-end: -6px;
    background: var(--tp4r-primary);
    color: #fff;
    font-size: 9px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Range Slider (Price) */
.tp4r-range-slider {
    padding: 8px 0;
}

.tp4r-range-track {
    position: relative;
    height: 6px;
    background: var(--tp4r-border);
    border-radius: 3px;
    margin: 16px 0;
}

.tp4r-range-fill {
    position: absolute;
    height: 100%;
    background: var(--tp4r-primary);
    border-radius: 3px;
    left: 0;
    right: unset;
}

.tp4r-range-track input[type="range"] {
    position: absolute;
    width: 100%;
    top: -6px;
    height: 18px;
    appearance: none;
    -webkit-appearance: none;
    background: transparent;
    pointer-events: none;
    margin: 0;
}

.tp4r-range-track input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--tp4r-primary);
    border: 2px solid #fff;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
    cursor: pointer;
    pointer-events: all;
}

.tp4r-range-track input[type="range"]::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--tp4r-primary);
    border: 2px solid #fff;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
    cursor: pointer;
    pointer-events: all;
}

.tp4r-range-inputs {
    display: flex;
    align-items: center;
    gap: 8px;
    justify-content: space-between;
}

[dir="rtl"] .tp4r-range-inputs {
    flex-direction: row-reverse;
}

.tp4r-range-inputs input[type="number"] {
    width: 80px;
    padding: 6px 8px;
    border: 1px solid var(--tp4r-border);
    border-radius: 4px;
    font-size: 13px;
    text-align: center;
}

.tp4r-range-inputs input[type="number"]:focus {
    border-color: var(--tp4r-primary);
    outline: none;
}

.tp4r-range-inputs span {
    color: var(--tp4r-text-muted);
}

/* Toggle Widget */
.tp4r-toggle-label {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    padding: 4px 0;
}

.tp4r-toggle-input {
    display: none;
}

.tp4r-toggle-track {
    position: relative;
    width: 40px;
    height: 22px;
    background: var(--tp4r-border);
    border-radius: 11px;
    transition: background var(--tp4r-transition);
    flex-shrink: 0;
}

.tp4r-toggle-track::after {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #fff;
    top: 3px;
    inset-inline-start: 3px;
    transition: all var(--tp4r-transition);
}

.tp4r-toggle-input:checked + .tp4r-toggle-track {
    background: var(--tp4r-primary);
}

.tp4r-toggle-input:checked + .tp4r-toggle-track::after {
    inset-inline-start: 21px;
}

.tp4r-toggle-text {
    font-size: 13px;
}

/* Star Rating Widget */
.tp4r-star-rating {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.tp4r-star-option {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 6px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    color: #dba617;
    transition: background var(--tp4r-transition);
}

.tp4r-star-option:hover {
    background: var(--tp4r-bg);
}

.tp4r-star-option.tp4r-selected {
    background: var(--tp4r-chip-bg);
}

.tp4r-star-option .tp4r-star-label {
    color: var(--tp4r-text-muted);
    font-size: 12px;
}

/* Button Group */
.tp4r-button-group {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.tp4r-button-group-item {
    padding: 6px 14px;
    border: 1px solid var(--tp4r-border);
    border-radius: 20px;
    background: #fff;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.15s;
    color: var(--tp4r-text);
}

.tp4r-button-group-item:hover {
    border-color: var(--tp4r-primary);
    color: var(--tp4r-primary);
}

.tp4r-button-group-item.tp4r-selected {
    background: var(--tp4r-primary);
    border-color: var(--tp4r-primary);
    color: #fff;
}

.tp4r-button-count {
    font-size: 10px;
    opacity: 0.7;
    margin-inline-start: 4px;
}

/* Search Widget */
.tp4r-search-input {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--tp4r-border);
    border-radius: 4px;
    font-size: 13px;
}

.tp4r-search-input:focus {
    border-color: var(--tp4r-primary);
    outline: none;
    box-shadow: 0 0 0 1px var(--tp4r-primary);
}

/* Term search within filter group */
.tp4r-term-search {
    margin-bottom: 8px;
}

.tp4r-term-search input {
    width: 100%;
    padding: 6px 10px;
    border: 1px solid var(--tp4r-border);
    border-radius: 4px;
    font-size: 12px;
}

/* Submit button (manual mode) */
.tp4r-submit-btn,
.tp4r-apply-btn {
    display: block;
    width: 100%;
    padding: 10px 20px;
    background: var(--tp4r-primary);
    color: #fff;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background var(--tp4r-transition);
    margin-top: 12px;
}

.tp4r-submit-btn:hover,
.tp4r-apply-btn:hover {
    background: var(--tp4r-primary-hover);
}

/* Drawer trigger button - base styles (shared between drawer mode and mobile inline) */
.tp4r-drawer-trigger {
    position: fixed;
    bottom: 24px;
    inset-inline-start: 24px;
    z-index: 9998;
    background: var(--tp4r-primary);
    color: #fff;
    border: none;
    border-radius: 50%;
    width: 52px;
    height: 52px;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
    transition: all var(--tp4r-transition);
}

/* Full drawer mode trigger - always visible */
.tp4r-drawer-trigger:not(.tp4r-mobile-drawer-trigger) {
    display: flex;
}

.tp4r-drawer-trigger:hover {
    background: var(--tp4r-primary-hover);
    transform: scale(1.05);
}

.tp4r-active-count {
    position: absolute;
    top: -4px;
    inset-inline-end: -4px;
    background: #d63638;
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.tp4r-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 9998;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity var(--tp4r-transition);
}

.tp4r-overlay.tp4r-visible {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

.tp4r-drawer-panel {
    position: fixed;
    top: 0;
    bottom: 0;
    width: var(--tp4r-drawer-width);
    background: #fff;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    box-shadow: -4px 0 20px rgba(0,0,0,0.15);
    transition: transform var(--tp4r-transition);
}

.tp4r-drawer-right {
    right: 0;
    transform: translateX(100%);
}

.tp4r-drawer-left {
    left: 0;
    transform: translateX(-100%);
}

.tp4r-drawer-panel.tp4r-drawer-open {
    transform: translateX(0);
}

.tp4r-drawer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--tp4r-border);
    flex-shrink: 0;
}

.tp4r-drawer-title {
    font-size: 16px;
    font-weight: 700;
    color: var(--tp4r-text);
}

.tp4r-drawer-close {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--tp4r-text-muted);
    padding: 4px;
    border-radius: 4px;
    display: flex;
    align-items: center;
}

.tp4r-drawer-close:hover {
    color: var(--tp4r-text);
    background: var(--tp4r-bg);
}

.tp4r-drawer-body {
    flex: 1;
    overflow-y: auto;
    padding: 16px 20px;
}

.tp4r-drawer-footer {
    display: flex;
    gap: 8px;
    padding: 16px 20px;
    border-top: 1px solid var(--tp4r-border);
    flex-shrink: 0;
}

.tp4r-drawer-footer .tp4r-apply-btn {
    flex: 1;
    margin-top: 0;
}

.tp4r-drawer-footer .tp4r-reset-btn {
    padding: 10px 16px;
    flex-shrink: 0;
}

/* Mobile drawer trigger - hidden by default, shown only on mobile */
.tp4r-mobile-drawer-trigger {
    display: none !important;
}

.tp4r-mobile-drawer-header {
    display: none;
}

.tp4r-mobile-drawer-body {
    display: block;
}

/* Loading overlay */
/* Loading overlay — base */
.tp4r-loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
}

/* Loading: Spinner */
.tp4r-spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--tp4r-border, #e0e0e0);
    border-top-color: var(--tp4r-primary, #2271b1);
    border-radius: 50%;
    animation: tp4r-spin 0.7s linear infinite;
}

@keyframes tp4r-spin {
    to { transform: rotate(360deg); }
}

/* Loading: Skeleton */
.tp4r-loading-skeleton {
    background: rgba(255, 255, 255, 0.9);
    align-items: flex-start;
    padding: 16px;
}

.tp4r-skeleton-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
    width: 100%;
}

.tp4r-skeleton-card {
    height: 260px;
    border-radius: 8px;
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: tp4r-shimmer 1.5s ease-in-out infinite;
}

@keyframes tp4r-shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* Loading: Fade */
.tp4r-loading-fade {
    background: rgba(255, 255, 255, 0);
    animation: tp4r-fade-pulse 1s ease-in-out infinite alternate;
}

@keyframes tp4r-fade-pulse {
    0% { background: rgba(255, 255, 255, 0.3); }
    100% { background: rgba(255, 255, 255, 0.7); }
}

.tp4r-results-container {
    position: relative;
}

/* Mobile responsive */
@media (max-width: 768px) {
    .tp4r-drawer-panel {
        width: 100%;
    }

    .tp4r-mobile-drawer-trigger {
        display: flex !important;
    }

    .tp4r-filter-inline.tp4r-mobile-drawer {
        position: fixed;
        top: 0;
        bottom: 0;
        left: 0;
        width: min(100%, var(--tp4r-drawer-width));
        max-width: 100%;
        margin: 0;
        border-radius: 0;
        border: none;
        z-index: 9999;
        display: flex;
        flex-direction: column;
        padding: 0;
        transform: translateX(-100%);
        transition: transform var(--tp4r-transition);
        box-shadow: -4px 0 20px rgba(0,0,0,0.15);
    }

    .tp4r-filter-inline.tp4r-mobile-drawer[dir="rtl"] {
        left: auto;
        right: 0;
        transform: translateX(100%);
        box-shadow: 4px 0 20px rgba(0,0,0,0.15);
    }

    .tp4r-filter-inline.tp4r-mobile-drawer.tp4r-drawer-open {
        transform: translateX(0);
    }

    .tp4r-mobile-drawer-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 16px 20px;
        border-bottom: 1px solid var(--tp4r-border);
        flex-shrink: 0;
        background: #fff;
    }

    .tp4r-mobile-drawer-body {
        flex: 1;
        overflow-y: auto;
        padding: 16px 20px;
    }

    .tp4r-mobile-drawer-footer {
        padding: 16px 20px;
        border-top: 1px solid var(--tp4r-border);
        background: #fff;
        flex-shrink: 0;
    }

    .tp4r-filter-inline {
        padding: 12px;
    }

    .tp4r-range-inputs input[type="number"] {
        width: 60px;
    }
}

/* Body lock when drawer open */
body.tp4r-body-locked {
    overflow: hidden;
}
