/**
 * TKD Mobile Enhancements
 * Mobile-first responsive design enhancements for the niche page
 * Phase 6: Mobile & UI Enhancement
 */

/* === MOBILE FILTER PANEL SYSTEM === */

/* Mobile Filter Toggle Button */
.tkd-mobile-filter-toggle {
    display: none;
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 1000;
    background: linear-gradient(135deg, rgba(var(--tkd-accent-rgb, 255, 149, 0), 0.95), rgba(var(--tkd-accent-rgb, 255, 149, 0), 0.85));
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    width: 56px;
    height: 56px;
    box-shadow: 0 8px 25px rgba(var(--tkd-accent-rgb, 255, 149, 0), 0.4);
    cursor: pointer;
    transition: all 0.3s ease;
    animation: tkd-fab-bounce 0.6s ease-out;
}

.tkd-mobile-filter-toggle:hover {
    transform: scale(1.1);
    box-shadow: 0 12px 35px rgba(var(--tkd-accent-rgb, 255, 149, 0), 0.5);
}

.tkd-mobile-filter-toggle i {
    color: white;
    font-size: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    transition: transform 0.3s ease;
}

.tkd-mobile-filter-toggle.active i {
    transform: rotate(45deg);
}

@keyframes tkd-fab-bounce {
    0% {
        transform: scale(0) rotate(-180deg);
        opacity: 0;
    }
    50% {
        transform: scale(1.2) rotate(-90deg);
        opacity: 0.8;
    }
    100% {
        transform: scale(1) rotate(0deg);
        opacity: 1;
    }
}

/* Mobile Filter Panel */
.tkd-mobile-filter-panel {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 999;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
}

.tkd-mobile-filter-content {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.95), rgba(255, 255, 255, 0.9));
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-radius: 20px 20px 0 0;
    border: 1px solid rgba(255, 255, 255, 0.3);
    max-height: 85vh;
    overflow-y: auto;
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.tkd-mobile-filter-panel.active .tkd-mobile-filter-content {
    transform: translateY(0);
}

.tkd-mobile-filter-header {
    padding: 20px 20px 10px 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.3);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.tkd-mobile-filter-title {
    font-size: 1.4rem;
    font-weight: 600;
    color: #2c3e50;
    margin: 0;
}

.tkd-mobile-filter-close {
    background: none;
    border: none;
    font-size: 24px;
    color: #666;
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    transition: all 0.2s ease;
}

.tkd-mobile-filter-close:hover {
    background: rgba(0, 0, 0, 0.1);
    color: #333;
}

.tkd-mobile-filter-body {
    padding: 20px;
}

/* Mobile Filter Sections */
.tkd-mobile-filter-section {
    margin-bottom: 24px;
}

.tkd-mobile-filter-section-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: #2c3e50;
    margin: 0 0 12px 0;
    display: flex;
    align-items: center;
    gap: 8px;
}

.tkd-mobile-filter-section-title i {
    color: rgba(var(--tkd-accent-rgb, 255, 149, 0), 0.8);
    font-size: 1rem;
}

/* Touch-Optimized Form Controls */
.tkd-mobile-search-input {
    width: 100%;
    padding: 16px 20px 16px 50px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(10px);
    font-size: 16px; /* Prevents zoom on iOS */
    color: #2c3e50;
    transition: all 0.3s ease;
    position: relative;
}

.tkd-mobile-search-input:focus {
    outline: none;
    border-color: rgba(var(--tkd-accent-rgb, 255, 149, 0), 0.8);
    box-shadow: 0 0 0 3px rgba(var(--tkd-accent-rgb, 255, 149, 0), 0.1);
    background: rgba(255, 255, 255, 1);
}

.tkd-mobile-search-wrapper {
    position: relative;
    margin-bottom: 20px;
}

.tkd-mobile-search-icon {
    position: absolute;
    left: 18px;
    top: 50%;
    transform: translateY(-50%);
    color: rgba(var(--tkd-accent-rgb, 255, 149, 0), 0.6);
    font-size: 18px;
    z-index: 2;
}

/* Touch-Friendly Select Dropdowns */
.tkd-mobile-select {
    width: 100%;
    padding: 16px 20px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(10px);
    font-size: 16px; /* Prevents zoom on iOS */
    color: #2c3e50;
    cursor: pointer;
    transition: all 0.3s ease;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23666' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6,9 12,15 18,9'%3e%3c/polyline%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 16px center;
    background-size: 16px;
    padding-right: 50px;
    margin-bottom: 16px;
}

.tkd-mobile-select:focus {
    outline: none;
    border-color: rgba(var(--tkd-accent-rgb, 255, 149, 0), 0.8);
    box-shadow: 0 0 0 3px rgba(var(--tkd-accent-rgb, 255, 149, 0), 0.1);
    background-color: rgba(255, 255, 255, 1);
}

/* Rating Filter Pills */
.tkd-mobile-rating-pills {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 20px;
}

.tkd-mobile-rating-pill {
    padding: 12px 16px;
    background: rgba(255, 255, 255, 0.8);
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 25px;
    font-size: 14px;
    font-weight: 500;
    color: #666;
    cursor: pointer;
    transition: all 0.3s ease;
    min-height: 44px; /* iOS touch target */
    display: flex;
    align-items: center;
    gap: 6px;
}

.tkd-mobile-rating-pill:hover,
.tkd-mobile-rating-pill.active {
    background: rgba(var(--tkd-accent-rgb, 255, 149, 0), 0.15);
    border-color: rgba(var(--tkd-accent-rgb, 255, 149, 0), 0.5);
    color: #2c3e50;
    transform: translateY(-1px);
}

.tkd-mobile-rating-pill i {
    color: #ffd700;
    font-size: 12px;
}

/* Sort Options */
.tkd-mobile-sort-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.tkd-mobile-sort-option {
    padding: 16px 12px;
    background: rgba(255, 255, 255, 0.8);
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 12px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    min-height: 60px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
}

.tkd-mobile-sort-option:hover,
.tkd-mobile-sort-option.active {
    background: rgba(var(--tkd-accent-rgb, 255, 149, 0), 0.15);
    border-color: rgba(var(--tkd-accent-rgb, 255, 149, 0), 0.5);
    transform: translateY(-1px);
}

.tkd-mobile-sort-option i {
    font-size: 18px;
    color: rgba(var(--tkd-accent-rgb, 255, 149, 0), 0.8);
    margin-bottom: 4px;
}

.tkd-mobile-sort-option span {
    font-size: 12px;
    font-weight: 500;
    color: #2c3e50;
}

/* Near Me Button */
.tkd-mobile-near-me {
    width: 100%;
    padding: 16px;
    background: linear-gradient(135deg, rgba(34, 197, 94, 0.9), rgba(22, 163, 74, 0.9));
    color: white;
    border: none;
    border-radius: 12px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-bottom: 20px;
    min-height: 52px;
}

.tkd-mobile-near-me:hover {
    background: linear-gradient(135deg, rgba(34, 197, 94, 1), rgba(22, 163, 74, 1));
    transform: translateY(-1px);
    box-shadow: 0 8px 25px rgba(34, 197, 94, 0.3);
}

.tkd-mobile-near-me:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Filter Actions */
.tkd-mobile-filter-actions {
    padding: 20px;
    border-top: 1px solid rgba(255, 255, 255, 0.3);
    display: flex;
    gap: 12px;
}

.tkd-mobile-apply-filters {
    flex: 2;
    padding: 16px;
    background: linear-gradient(135deg, var(--tkd-accent-color, #ff9500), rgba(var(--tkd-accent-rgb, 255, 149, 0), 0.85));
    color: white;
    border: none;
    border-radius: 12px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    min-height: 52px;
}

.tkd-mobile-apply-filters:hover {
    background: linear-gradient(135deg, rgba(var(--tkd-accent-rgb, 255, 149, 0), 0.9), var(--tkd-accent-color, #ff9500));
    transform: translateY(-1px);
    box-shadow: 0 8px 25px rgba(var(--tkd-accent-rgb, 255, 149, 0), 0.3);
}

.tkd-mobile-clear-filters {
    flex: 1;
    padding: 16px;
    background: rgba(108, 117, 125, 0.1);
    color: #6c757d;
    border: 2px solid rgba(108, 117, 125, 0.3);
    border-radius: 12px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    min-height: 52px;
}

.tkd-mobile-clear-filters:hover {
    background: rgba(108, 117, 125, 0.2);
    border-color: rgba(108, 117, 125, 0.5);
}

/* Active Filter Chips in Mobile */
.tkd-mobile-active-filters {
    margin-bottom: 20px;
}

.tkd-mobile-active-filters-title {
    font-size: 14px;
    font-weight: 600;
    color: #666;
    margin-bottom: 8px;
}

.tkd-mobile-filter-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.tkd-mobile-filter-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    background: rgba(var(--tkd-accent-rgb, 255, 149, 0), 0.1);
    border: 1px solid rgba(var(--tkd-accent-rgb, 255, 149, 0), 0.3);
    border-radius: 20px;
    font-size: 12px;
    color: #2c3e50;
}

.tkd-mobile-filter-chip-remove {
    background: none;
    border: none;
    color: rgba(var(--tkd-accent-rgb, 255, 149, 0), 0.8);
    font-size: 16px;
    cursor: pointer;
    padding: 2px;
    border-radius: 50%;
    transition: all 0.2s ease;
    line-height: 1;
}

.tkd-mobile-filter-chip-remove:hover {
    background: rgba(var(--tkd-accent-rgb, 255, 149, 0), 0.2);
    color: var(--tkd-accent-color, #ff9500);
}

/* === INFINITE SCROLL MOBILE ENHANCEMENTS === */

.tkd-mobile-infinite-scroll {
    display: none;
}

.tkd-mobile-load-more {
    width: 100%;
    padding: 16px;
    background: rgba(255, 255, 255, 0.8);
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 12px;
    color: #2c3e50;
    font-size: 16px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    margin: 20px 0;
    min-height: 52px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.tkd-mobile-load-more:hover {
    background: rgba(255, 255, 255, 1);
    border-color: rgba(var(--tkd-accent-rgb, 255, 149, 0), 0.3);
    transform: translateY(-1px);
}

.tkd-mobile-load-more:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* === QUICK VIEW MODAL === */

.tkd-quick-view-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1001;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
}

.tkd-quick-view-content {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 90%;
    max-width: 500px;
    max-height: 85vh;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.95), rgba(255, 255, 255, 0.9));
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-radius: 20px;
    border: 1px solid rgba(255, 255, 255, 0.3);
    overflow: hidden;
    animation: tkd-modal-slide-up 0.3s ease-out;
}

@keyframes tkd-modal-slide-up {
    from {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0.9) translateY(20px);
    }
    to {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1) translateY(0);
    }
}

.tkd-quick-view-header {
    padding: 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.3);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.tkd-quick-view-title {
    font-size: 1.2rem;
    font-weight: 600;
    color: #2c3e50;
    margin: 0;
}

.tkd-quick-view-close {
    background: none;
    border: none;
    font-size: 24px;
    color: #666;
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    transition: all 0.2s ease;
}

.tkd-quick-view-close:hover {
    background: rgba(0, 0, 0, 0.1);
    color: #333;
}

.tkd-quick-view-body {
    padding: 20px;
    overflow-y: auto;
    max-height: calc(85vh - 160px);
}

.tkd-quick-view-actions {
    padding: 20px;
    border-top: 1px solid rgba(255, 255, 255, 0.3);
    display: flex;
    gap: 12px;
}

.tkd-quick-view-call {
    flex: 1;
    padding: 16px;
    background: linear-gradient(135deg, rgba(34, 197, 94, 0.9), rgba(22, 163, 74, 0.9));
    color: white;
    border: none;
    border-radius: 12px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    text-decoration: none;
}

.tkd-quick-view-call:hover {
    background: linear-gradient(135deg, rgba(34, 197, 94, 1), rgba(22, 163, 74, 1));
    transform: translateY(-1px);
    color: white;
}

.tkd-quick-view-details {
    flex: 1;
    padding: 16px;
    background: rgba(var(--tkd-accent-rgb, 255, 149, 0), 0.1);
    color: rgba(var(--tkd-accent-rgb, 255, 149, 0), 0.9);
    border: 2px solid rgba(var(--tkd-accent-rgb, 255, 149, 0), 0.3);
    border-radius: 12px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    text-decoration: none;
}

.tkd-quick-view-details:hover {
    background: rgba(var(--tkd-accent-rgb, 255, 149, 0), 0.2);
    border-color: rgba(var(--tkd-accent-rgb, 255, 149, 0), 0.5);
    transform: translateY(-1px);
    color: var(--tkd-accent-color, #ff9500);
}

/* === SWIPEABLE BUSINESS CARDS === */

.tkd-mobile-card-container {
    position: relative;
    overflow: hidden;
}

.tkd-mobile-swipe-card {
    transform: translateX(0);
    transition: transform 0.3s ease;
    touch-action: pan-y;
}

.tkd-mobile-swipe-card.swiping {
    transition: none;
}

.tkd-mobile-swipe-actions {
    position: absolute;
    top: 0;
    right: -120px;
    width: 120px;
    height: 100%;
    display: flex;
    background: linear-gradient(135deg, rgba(34, 197, 94, 0.9), rgba(22, 163, 74, 0.9));
    border-radius: 0 16px 16px 0;
}

.tkd-mobile-swipe-action {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: white;
    cursor: pointer;
    transition: all 0.2s ease;
    border: none;
    background: none;
    font-size: 14px;
    padding: 8px;
}

.tkd-mobile-swipe-action:hover {
    background: rgba(255, 255, 255, 0.1);
}

.tkd-mobile-swipe-action i {
    font-size: 18px;
    margin-bottom: 4px;
}

/* === MOBILE RESPONSIVE OVERRIDES === */

/* Tablet optimizations */
@media (max-width: 1024px) and (min-width: 769px) {
    /* Show sidebar banners on tablet - they have space */
    .glass-ad-sidebar-left,
    .glass-ad-sidebar-right {
        display: block !important;
    }
    
    /* Optimize main content for tablet */
    .glass-main-card {
        width: 100% !important;
        max-width: 100% !important;
    }
    
    /* Optimize business container for tablet */
    .glass-business-container {
        flex-direction: column !important;
        padding: 30px 15px !important;
        gap: 20px !important;
    }
    
    /* Tablet card optimizations */
    .tkd-search-results-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 20px !important;
    }
}

@media (max-width: 768px) {
    /* Show mobile filter toggle */
    .tkd-mobile-filter-toggle {
        display: flex;
        align-items: center;
        justify-content: center;
    }
    
    /* Hide desktop search form on mobile */
    .tkd-search-form-container {
        display: none;
    }
    
    /* Enable mobile infinite scroll */
    .tkd-mobile-infinite-scroll {
        display: block;
    }
    
    /* Hide desktop pagination on mobile */
    .tkd-pagination {
        display: none;
    }
    
    /* Hide sidebar banners on mobile - no space for them */
    .glass-ad-sidebar-left,
    .glass-ad-sidebar-right {
        display: none !important;
    }
    
    /* Optimize main content for mobile */
    .glass-main-card {
        width: 100% !important;
        max-width: 100% !important;
        margin: 0 !important;
        padding: 0 !important;
    }
    
    /* Optimize business container for mobile */
    .glass-business-container {
        flex-direction: column !important;
        padding: 20px 10px !important;
        gap: 15px !important;
    }
    
    /* Mobile card optimizations */
    .tkd-search-results-grid {
        grid-template-columns: 1fr !important;
        gap: 12px !important;
    }
    
    .tkd-business-card {
        margin-bottom: 12px !important;
        border-radius: 12px !important;
        overflow: hidden !important;
        box-shadow: 0 2px 8px rgba(0,0,0,0.1) !important;
    }
    
    /* Optimize card content for mobile */
    .tkd-business-card-header {
        padding: 16px !important;
    }
    
    .tkd-business-name {
        font-size: 1.1rem !important;
        line-height: 1.3 !important;
        margin-bottom: 8px !important;
    }
    
    /* Optimize action buttons for mobile */
    .tkd-business-actions {
        padding: 12px 16px !important;
        display: flex !important;
        flex-direction: column !important;
        gap: 8px !important;
    }
    
    .tkd-view-business-btn {
        width: 100% !important;
        padding: 12px 16px !important;
        font-size: 14px !important;
        min-height: 44px !important;
        text-align: center !important;
    }
    
    /* Optimize hero section for mobile */
    .tkd-hero-header {
        padding: 1.5rem 0;
        margin-bottom: 2rem;
    }
    
    .tkd-hero-header h1 {
        font-size: 2rem;
    }
    
    .tkd-hero-subtitle {
        font-size: 1rem;
    }
    
    .tkd-hero-stats {
        grid-template-columns: repeat(2, 1fr);
        gap: 1rem;
    }
    
    /* Mobile sections spacing */
    .tkd-cities-section,
    .tkd-insights-section,
    .tkd-faq-section {
        margin: 2rem 0;
    }
    
    .tkd-section-title {
        font-size: 1.5rem;
    }
    
    /* Mobile breadcrumb */
    .tkd-breadcrumb {
        padding: 0.75rem 1rem;
        margin: 1rem 0;
    }
    
    .tkd-breadcrumb ol {
        font-size: 0.85rem;
        gap: 0.5rem;
    }
}

@media (max-width: 480px) {
    /* Extra small mobile optimizations */
    .tkd-mobile-filter-content {
        max-height: 90vh;
    }
    
    .tkd-mobile-filter-header,
    .tkd-mobile-filter-body,
    .tkd-mobile-filter-actions {
        padding: 16px;
    }
    
    .tkd-quick-view-content {
        width: 95%;
        max-height: 90vh;
    }
    
    .tkd-quick-view-header,
    .tkd-quick-view-body,
    .tkd-quick-view-actions {
        padding: 16px;
    }
    
    .tkd-hero-stats {
        grid-template-columns: 1fr;
    }
    
    .tkd-mobile-sort-grid {
        grid-template-columns: 1fr;
    }
}

/* === TOUCH GESTURE IMPROVEMENTS === */

/* Improve touch targets */
.tkd-business-card,
.tkd-city-card,
.tkd-insight-card {
    min-height: 44px; /* iOS minimum touch target */
}

/* Reduce hover states on touch devices */
@media (hover: none) and (pointer: coarse) {
    .tkd-business-card:hover,
    .tkd-city-card:hover,
    .tkd-insight-card:hover {
        transform: none;
        box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
    }
}

/* === PERFORMANCE OPTIMIZATIONS === */

/* Reduce motion for better performance on lower-end devices */
@media (prefers-reduced-motion: reduce) {
    .tkd-mobile-filter-content,
    .tkd-quick-view-content,
    .tkd-mobile-swipe-card {
        transition: none;
    }
    
    .tkd-mobile-filter-toggle {
        animation: none;
    }
    
    @keyframes tkd-fab-bounce,
    @keyframes tkd-modal-slide-up {
        from, to {
            transform: none;
            opacity: 1;
        }
    }
}

/* Optimize for high DPI displays */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .tkd-mobile-filter-toggle,
    .tkd-quick-view-content {
        border-width: 0.5px;
    }
}
