/* PERF: Performance Optimization Styles */

/* PERF: Force visibility for parent container */
.therapist-image {
    opacity: 1 !important;  /* ✅ แก้ parent container opacity: 0 */
}

/* PERF: Lazy loading states */
.therapist-image-wrapper {
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: 100% !important;
    overflow: hidden;
    background: linear-gradient(135deg, var(--primary-light), var(--secondary-color));
    z-index: 0;
    opacity: 1 !important;  /* ✅ แก้ปัญหา opacity: 0 */
}

/* PERF: Ensure images are visible by default (for base64 images) */
.therapist-image-wrapper img {
    display: block !important;
    width: 100% !important;
    height: 100% !important;
    object-fit: cover !important;
    object-position: center center !important;
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
    z-index: 1 !important;
    opacity: 1 !important;  /* ✅ แก้ปัญหา opacity: 0 */
}

.therapist-image-wrapper.lazy-loading {
    background: linear-gradient(135deg, var(--primary-light), var(--secondary-color));
    animation: pulse 1.5s ease-in-out infinite;
}

/* PERF: Smooth fade in for lazy loaded images */
.therapist-image-wrapper.lazy-loaded img {
    animation: fadeIn 0.3s ease-in;
}

.therapist-image-wrapper.lazy-error {
    background: #dc3545;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
}

.therapist-image-wrapper.lazy-error::after {
    content: '⚠️ Error';
    font-size: 1rem;
}

/* PERF: Hide error images */
.therapist-image-wrapper.lazy-error img {
    display: none;
}

/* PERF: LQIP placeholder styles */
.lqip-placeholder {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    filter: blur(20px);
    transform: scale(1.1);
    transition: opacity 0.3s ease;
    z-index: 1;
}

.lazy-loaded .lqip-placeholder {
    opacity: 0;
}

/* PERF: Loading spinner */
@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.7;
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

/* PERF: Loading therapists indicator */
.loading-therapists {
    grid-column: 1 / -1;
    text-align: center;
    padding: 60px 20px;
    color: var(--text-medium);
    font-size: 1.2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 15px;
}

.loading-therapists::before {
    content: '';
    width: 24px;
    height: 24px;
    border: 3px solid var(--primary-light);
    border-top: 3px solid var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* PERF: Infinite scroll loading indicator */
.loading-more {
    grid-column: 1 / -1;
    text-align: center;
    padding: 20px;
    color: var(--text-medium);
    font-size: 1rem;
    animation: fadeIn 0.3s ease;
}

/* PERF: Skeleton loading for cards */
.therapist-card-skeleton {
    background: var(--white);
    border-radius: var(--border-radius);
    overflow: hidden;
    box-shadow: var(--shadow);
    animation: pulse 1.5s ease-in-out infinite;
}

.therapist-card-skeleton .skeleton-image {
    height: 350px;
    background: linear-gradient(135deg, var(--primary-light), var(--secondary-color));
}

.therapist-card-skeleton .skeleton-info {
    padding: 1rem;
}

.therapist-card-skeleton .skeleton-line {
    height: 16px;
    background: var(--cream);
    border-radius: 4px;
    margin-bottom: 8px;
}

.therapist-card-skeleton .skeleton-line:nth-child(1) {
    width: 70%;
}

.therapist-card-skeleton .skeleton-line:nth-child(2) {
    width: 50%;
}

.therapist-card-skeleton .skeleton-line:nth-child(3) {
    width: 40%;
}

/* PERF: Infinite scroll sentinel */
.infinite-scroll-sentinel {
    height: 1px;
    width: 100%;
    margin-top: 20px;
    visibility: hidden;
}

/* PERF: Image fade-in effect */
.therapist-image {
    opacity: 0;
    transition: opacity 0.3s ease;
}

.therapist-image.loaded {
    opacity: 1;
}

/* PERF: Optimize for rendering performance */
.therapist-card {
    will-change: transform;
    contain: layout style paint;
}

.therapist-image-wrapper {
    contain: layout style paint;
    content-visibility: auto;
}

/* PERF: Reduce paint on hover */
.therapist-card:hover {
    transform: translateY(-10px) translateZ(0);
    backface-visibility: hidden;
}

/* PERF: Optimize animations */
@media (prefers-reduced-motion: reduce) {
    .therapist-card,
    .lqip-placeholder,
    .therapist-image {
        transition: none !important;
        animation: none !important;
    }
}

/* PERF: Force GPU acceleration */
.therapist-image-wrapper img {
    transform: translateZ(0);
    backface-visibility: hidden;
}

/* PERF: Improve font rendering */
.therapist-info {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

/* PERF: Reduce reflow */
.therapist-card .therapist-image-wrapper {
    aspect-ratio: 3/4;
    height: auto;
}

/* PERF: Loading overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(5px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.loading-overlay.active {
    opacity: 1;
    pointer-events: all;
}

.loading-overlay .spinner {
    width: 60px;
    height: 60px;
    border: 4px solid var(--primary-light);
    border-top: 4px solid var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

/* PERF: Success indicator */
.load-success {
    animation: successPulse 0.5s ease;
}

@keyframes successPulse {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.05);
    }
}

/* PERF: Mobile optimizations */
@media (max-width: 768px) {
    /* Reduce animations on mobile for performance */
    .therapist-card:hover {
        transform: translateY(-5px) translateZ(0);
    }
    
    /* Simplify effects */
    .lqip-placeholder {
        filter: blur(10px);
    }
    
    /* Optimize scrolling */
    .therapists-grid {
        -webkit-overflow-scrolling: touch;
    }
}

/* PERF: Print styles */
@media print {
    .lqip-placeholder,
    .loading-therapists,
    .loading-more {
        display: none !important;
    }
}

