/* Products Page Optimized Styles - Responsive Design with Better Image Centering */

/* Header Spacer - Ensure proper spacing for fixed navigation */
.header-spacer {
    min-height: 80px;
    transition: height var(--transition-base);
}

@media (max-width: 768px) {
    .header-spacer {
        min-height: 120px; /* More space on mobile for category nav + subcategory filters */
    }
}

/* Products Section - Better spacing and max-width */
.products-section {
    padding: 24px 40px;
    max-width: 1600px;
    margin: 0 auto;
    width: 100%;
    box-sizing: border-box;
}

/* Products Grid - Responsive columns */
.products-grid-full {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 24px;
    padding: 2px 0;
    width: 100%;
    box-sizing: border-box;
}

/* Desktop: Larger grid with more columns */
@media (min-width: 1400px) {
    .products-grid-full {
        grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
        gap: 28px;
    }
}

@media (min-width: 1200px) and (max-width: 1399px) {
    .products-grid-full {
        grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
        gap: 24px;
    }
}

@media (min-width: 992px) and (max-width: 1199px) {
    .products-grid-full {
        grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
        gap: 22px;
    }
}

@media (min-width: 768px) and (max-width: 991px) {
    .products-grid-full {
        grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
        gap: 20px;
    }
}

/* Product Item - Full width, no fixed width constraints */
.products-grid-full .product-item {
    width: 100% !important;
    min-width: unset !important;
    max-width: none !important;
    background: var(--surface);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06), 0 1px 3px rgba(0, 0, 0, 0.04);
    transition: all var(--transition-base);
    cursor: pointer;
    display: flex;
    flex-direction: column;
    height: auto;
    min-height: unset;
    max-height: none;
    flex-shrink: 0;
    scroll-snap-align: start;
    border: 1px solid rgba(226, 232, 240, 0.6);
    position: relative;
    will-change: transform;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.products-grid-full .product-item:hover {
    transform: translateY(-8px) scale(1.02);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12), 0 4px 8px rgba(0, 0, 0, 0.08);
    border-color: var(--primary-color);
}

/* Product Image Container - Flexbox for perfect centering */
.products-grid-full .product-image-container {
    position: relative;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 320px;
    background: linear-gradient(135deg, #fafbfc 0%, #ffffff 100%);
    border-radius: var(--radius-md) var(--radius-md) 0 0;
    overflow: hidden;
    box-sizing: border-box;
}

/* Product Image - Bigger and perfectly centered */
.products-grid-full .product-image {
    width: 100%;
    height: auto;
    min-height: 320px;
    max-height: 450px;
    object-fit: contain;
    object-position: center center;
    background: transparent;
    padding: 20px;
    display: block;
    margin: 0 auto;
    transition: all var(--transition-base);
    position: relative;
    z-index: 1;
    border-radius: var(--radius-md) var(--radius-md) 0 0;
    text-align: center;
    vertical-align: middle;
    align-self: center;
    justify-self: center;
    box-sizing: border-box;
}

.products-grid-full .product-item:hover .product-image {
    transform: scale(1.1);
    filter: brightness(1.08) contrast(1.03);
    padding: 16px;
}

/* Tablet Responsive */
@media (max-width: 768px) {
    .products-section {
        padding: 16px 16px;
    }
    
    .products-header h2 {
        font-size: 24px;
        margin-bottom: 20px;
    }
    
    .products-grid-full {
        grid-template-columns: repeat(2, 1fr);
        gap: 14px;
    }
    
    .products-grid-full .product-image-container {
        min-height: 280px;
    }
    
    .products-grid-full .product-image {
        min-height: 280px;
        max-height: 360px;
        padding: 16px;
    }
    
    .products-grid-full .product-item:hover .product-image {
        padding: 14px;
        transform: scale(1.08);
    }
}

/* Mobile Responsive */
@media (max-width: 480px) {
    .products-section {
        padding: 12px 12px;
    }
    
    .products-header h2 {
        font-size: 22px;
        margin-bottom: 16px;
    }
    
    .products-grid-full {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }
    
    .products-grid-full .product-image-container {
        min-height: 240px;
    }
    
    .products-grid-full .product-image {
        min-height: 240px;
        max-height: 300px;
        padding: 12px;
    }
    
    .products-grid-full .product-item:hover .product-image {
        transform: scale(1.05);
        padding: 10px;
    }
    
    .products-grid-full .product-item:hover {
        transform: translateY(-4px) scale(1.01);
    }
}

/* Extra Small Mobile */
@media (max-width: 360px) {
    .products-section {
        padding: 10px 8px;
    }
    
    .products-grid-full {
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
    }
    
    .products-grid-full .product-image-container {
        min-height: 200px;
    }
    
    .products-grid-full .product-image {
        min-height: 200px;
        max-height: 260px;
        padding: 10px;
    }
}

/* Large Desktop - More columns */
@media (min-width: 1600px) {
    .products-grid-full {
        grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
        gap: 32px;
    }
    
    .products-grid-full .product-image-container {
        min-height: 360px;
    }
    
    .products-grid-full .product-image {
        min-height: 360px;
        max-height: 500px;
        padding: 24px;
    }
}

/* Loading and Empty States */
.products-loading,
.products-empty {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-secondary);
    font-size: 18px;
    grid-column: 1 / -1;
}

/* Product Watermark - Better positioning */
.products-grid-full .product-watermark {
    position: absolute;
    bottom: 12px;
    right: 12px;
    background: rgba(0, 0, 0, 0.75);
    color: white;
    padding: 6px 10px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 600;
    font-family: 'Courier New', monospace;
    z-index: 10;
    pointer-events: none;
    user-select: none;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
    line-height: 1.2;
}

/* Smooth animations */
.products-grid-full .product-item {
    animation: fadeInUp 0.4s ease-out;
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Better touch targets on mobile */
@media (max-width: 768px) {
    .products-grid-full .product-item {
        -webkit-tap-highlight-color: rgba(0, 0, 0, 0.1);
        touch-action: manipulation;
    }
    
    .products-grid-full .product-item:active {
        transform: scale(0.98);
    }
}

/* Ensure main content doesn't overlap with fixed header */
.main-content {
    padding-top: 0;
    margin-top: 0;
}

/* Products Header - Better styling */
.products-header {
    margin-bottom: 24px;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    flex-wrap: wrap;
    gap: 16px;
}

.products-header-left {
    display: flex;
    flex-direction: column;
    gap: 16px;
    flex: 1;
    min-width: 0;
}

.products-header-right {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

.products-header h2 {
    font-size: 28px;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0;
}

/* Products Categories Navigation */
.products-categories-nav {
    width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
}

.products-categories-nav::-webkit-scrollbar {
    height: 4px;
}

.products-categories-nav::-webkit-scrollbar-thumb {
    background: var(--primary-color);
    border-radius: 2px;
}

.products-categories-list {
    display: flex;
    list-style: none;
    margin: 0;
    padding: 0;
    gap: 8px;
    flex-wrap: wrap;
}

.products-category-nav-item {
    position: relative;
    flex-shrink: 0;
}

.products-category-link {
    display: inline-block;
    padding: 8px 16px;
    color: var(--text-primary);
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    border-radius: var(--radius-md);
    transition: all var(--transition-base);
    white-space: nowrap;
    background: var(--surface);
    border: 1px solid var(--border-color);
}

.products-category-link:hover {
    background: var(--gradient-primary);
    color: white;
    border-color: var(--primary-color);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.products-category-link.active {
    background: var(--gradient-primary);
    color: white;
    border-color: var(--primary-color);
    font-weight: 600;
}

/* Dropdown positioning for products header */
.products-category-nav-item .category-subcategories-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    margin-top: 4px;
    z-index: 1000;
    min-width: 200px;
}

@media (max-width: 768px) {
    .products-header {
        flex-direction: column;
        align-items: stretch;
    }
    
    .products-header-left {
        width: 100%;
    }
    
    .products-categories-list {
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .products-category-link {
        font-size: 13px;
        padding: 6px 12px;
    }
}

/* Edit Mode Button - Hidden by default, shown only when authenticated */
.btn-edit-mode {
    display: none; /* Hidden by default, JavaScript will show if authenticated */
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    background: var(--surface);
    border: 2px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-base);
}

/* Show button when authenticated */
.btn-edit-mode.authenticated {
    display: flex;
}

.btn-edit-mode:hover {
    background: var(--gradient-primary);
    color: white;
    border-color: var(--primary-color);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.btn-edit-mode .edit-icon {
    font-size: 18px;
}

/* Export Products Button - Hidden by default, shown only when authenticated */
.btn-export-products {
    display: none; /* Hidden by default, JavaScript will show if authenticated */
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    background: var(--surface);
    border: 2px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-base);
    margin-right: 10px;
}

/* Show button when authenticated */
.btn-export-products.authenticated {
    display: flex;
}

.btn-export-products:hover {
    background: var(--gradient-primary);
    color: white;
    border-color: var(--primary-color);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.btn-export-products:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

.btn-export-products .export-icon {
    font-size: 18px;
}

/* Selection Mode Button */
.btn-selection-mode {
    display: none;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    background: var(--surface);
    border: 2px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-base);
    margin-right: 10px;
}

.btn-selection-mode.authenticated {
    display: flex;
}

.btn-selection-mode:hover {
    background: var(--gradient-primary);
    color: white;
    border-color: var(--primary-color);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.btn-selection-mode.active {
    background: var(--gradient-primary);
    color: white;
    border-color: var(--primary-color);
}

.btn-selection-mode .selection-icon {
    font-size: 18px;
}

/* Product Selection Checkbox */
.product-item {
    position: relative;
}

.product-selection-checkbox {
    position: absolute;
    top: 10px;
    left: 10px;
    width: 24px;
    height: 24px;
    z-index: 10;
    cursor: pointer;
    opacity: 0;
    transition: opacity var(--transition-base);
}

.selection-mode .product-selection-checkbox {
    opacity: 1;
}

.product-selection-checkbox:checked + .product-selection-checkbox-label {
    background: var(--primary-color);
    border-color: var(--primary-color);
}

.product-selection-checkbox-label {
    position: absolute;
    top: 10px;
    left: 10px;
    width: 24px;
    height: 24px;
    background: rgba(255, 255, 255, 0.9);
    border: 2px solid var(--border-color);
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9;
    transition: all var(--transition-base);
}

.product-selection-checkbox-label::after {
    content: '✓';
    color: white;
    font-size: 16px;
    font-weight: bold;
    opacity: 0;
    transition: opacity var(--transition-base);
}

.product-selection-checkbox:checked + .product-selection-checkbox-label {
    background: var(--primary-color);
    border-color: var(--primary-color);
}

.product-selection-checkbox:checked + .product-selection-checkbox-label::after {
    opacity: 1;
}

/* Selection Panel */
.selection-panel {
    position: fixed;
    right: 0;
    top: 0;
    width: 350px;
    height: 100vh;
    background: var(--surface);
    border-left: 2px solid var(--border-color);
    box-shadow: -2px 0 10px rgba(0, 0, 0, 0.1);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.selection-panel-header {
    padding: 20px;
    border-bottom: 2px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--gradient-primary);
    color: white;
}

.selection-panel-header h3 {
    margin: 0;
    font-size: 18px;
}

.selection-panel-close {
    background: none;
    border: none;
    color: white;
    font-size: 24px;
    cursor: pointer;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background var(--transition-base);
}

.selection-panel-close:hover {
    background: rgba(255, 255, 255, 0.2);
}

.selection-panel-content {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
}

.selection-actions {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
}

.btn-select-all,
.btn-clear-selection {
    flex: 1;
    padding: 10px;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--surface);
    color: var(--text-primary);
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-base);
}

.btn-select-all:hover,
.btn-clear-selection:hover {
    background: var(--gradient-primary);
    color: white;
    border-color: var(--primary-color);
}

.selection-export-options {
    margin-bottom: 20px;
}

.selection-export-options h4 {
    margin: 0 0 15px 0;
    font-size: 16px;
    color: var(--text-primary);
}

.export-option-group {
    margin-bottom: 15px;
}

.export-option-group label {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
    cursor: pointer;
}

.export-option-group input[type="radio"] {
    width: auto;
    margin: 0;
}

.export-option-group input[type="number"] {
    width: 80px;
    padding: 8px;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-md);
    font-size: 14px;
}

.selection-panel-export {
    padding-top: 20px;
    border-top: 2px solid var(--border-color);
}

.btn-export-selected {
    width: 100%;
    padding: 15px;
    background: var(--gradient-primary);
    color: white;
    border: none;
    border-radius: var(--radius-md);
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-base);
}

.btn-export-selected:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.btn-export-selected:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

/* Disabled products styling */
.products-grid-full .product-item.product-disabled {
    opacity: 0.5;
    filter: grayscale(0.3);
}

.products-grid-full .product-item.product-disabled:hover {
    opacity: 0.7;
    filter: grayscale(0.2);
}

/* Product Price Container */
.products-grid-full .product-price-container {
    padding: 12px 16px;
    background: linear-gradient(135deg, #f8f9fa 0%, #ffffff 100%);
    border-top: 1px solid rgba(226, 232, 240, 0.6);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    min-height: 60px;
    justify-content: center;
}

.products-grid-full .product-price-normal {
    font-size: 18px;
    font-weight: 700;
    color: var(--primary-color);
    text-align: center;
}

.products-grid-full .product-price-discounted {
    font-size: 20px;
    font-weight: 700;
    color: #10b981;
    text-align: center;
}

.products-grid-full .product-price-original {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-secondary);
    text-decoration: line-through;
    text-align: center;
}

@media (max-width: 768px) {
    .products-grid-full .product-price-container {
        padding: 10px 12px;
        min-height: 55px;
    }
    
    .products-grid-full .product-price-normal {
        font-size: 16px;
    }
    
    .products-grid-full .product-price-discounted {
        font-size: 18px;
    }
    
    .products-grid-full .product-price-original {
        font-size: 12px;
    }
}

/* Search Container - In Header */
.categories-carousel-wrapper .search-container {
    position: relative;
    display: flex;
    align-items: center;
    flex-shrink: 0;
}

.categories-carousel-wrapper .btn-search-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    padding: 0;
    background: var(--surface);
    border: 2px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    cursor: pointer;
    transition: all var(--transition-base);
    flex-shrink: 0;
    position: relative;
    z-index: 1;
    pointer-events: auto;
}

.categories-carousel-wrapper .btn-search-toggle:hover {
    background: var(--gradient-primary);
    color: white;
    border-color: var(--primary-color);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.categories-carousel-wrapper .search-input-wrapper {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    display: none; /* Hidden by default */
    align-items: center;
    gap: 8px;
    background: var(--surface);
    border: 2px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 8px 12px;
    animation: slideDown 0.3s ease-out;
    min-width: 300px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: 1001;
    visibility: visible;
    opacity: 1;
}

.categories-carousel-wrapper .search-input-wrapper[style*="flex"] {
    display: flex !important;
    visibility: visible !important;
    opacity: 1 !important;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.categories-carousel-wrapper .search-input-container {
    position: relative;
    flex: 1;
    min-width: 0;
}

.categories-carousel-wrapper .search-input {
    width: 100%;
    border: none;
    outline: none;
    background: transparent;
    color: var(--text-primary);
    font-size: 14px;
    min-width: 0;
}

.categories-carousel-wrapper .search-input::placeholder {
    color: var(--text-secondary);
}

/* Autocomplete Dropdown */
.categories-carousel-wrapper .autocomplete-dropdown {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    background: var(--surface);
    border: 2px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    max-height: 300px;
    overflow-y: auto;
    z-index: 1002;
    display: none;
    margin-top: 4px;
}

.categories-carousel-wrapper .autocomplete-dropdown.show {
    display: block;
}

.categories-carousel-wrapper .autocomplete-item {
    padding: 12px 16px;
    cursor: pointer;
    border-bottom: 1px solid rgba(226, 232, 240, 0.5);
    transition: all var(--transition-base);
    display: flex;
    align-items: flex-start;
    gap: 12px;
}

.categories-carousel-wrapper .autocomplete-item:last-child {
    border-bottom: none;
}

.categories-carousel-wrapper .autocomplete-item:hover,
.categories-carousel-wrapper .autocomplete-item.highlighted {
    background: var(--gradient-primary);
    color: white;
}

.categories-carousel-wrapper .autocomplete-item-id {
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 12px;
    min-width: 50px;
    flex-shrink: 0;
}

.categories-carousel-wrapper .autocomplete-item:hover .autocomplete-item-id,
.categories-carousel-wrapper .autocomplete-item.highlighted .autocomplete-item-id {
    color: rgba(255, 255, 255, 0.9);
}

.categories-carousel-wrapper .autocomplete-item-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
}

.categories-carousel-wrapper .autocomplete-item-title {
    font-size: 14px;
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.categories-carousel-wrapper .autocomplete-item-category {
    font-size: 12px;
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.categories-carousel-wrapper .autocomplete-item:hover .autocomplete-item-category,
.categories-carousel-wrapper .autocomplete-item.highlighted .autocomplete-item-category {
    color: rgba(255, 255, 255, 0.8);
}

.categories-carousel-wrapper .autocomplete-item-empty {
    padding: 16px;
    text-align: center;
    color: var(--text-secondary);
    font-size: 14px;
}

.categories-carousel-wrapper .btn-search-submit,
.categories-carousel-wrapper .btn-search-close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    padding: 0;
    background: transparent;
    border: none;
    color: var(--text-primary);
    cursor: pointer;
    transition: all var(--transition-base);
    border-radius: var(--radius-sm);
    flex-shrink: 0;
}

.categories-carousel-wrapper .btn-search-submit:hover {
    background: var(--gradient-primary);
    color: white;
}

.categories-carousel-wrapper .btn-search-close:hover {
    background: rgba(239, 68, 68, 0.1);
    color: #ef4444;
}

@media (max-width: 768px) {
    .categories-carousel-wrapper .search-input-wrapper {
        min-width: 250px;
        right: 0;
        left: auto;
    }
    
    .categories-carousel-wrapper .search-input {
        font-size: 13px;
    }
    
    .categories-carousel-wrapper .btn-search-toggle {
        width: 36px;
        height: 36px;
    }
    
    .categories-carousel-wrapper .autocomplete-dropdown {
        max-height: 200px;
    }
    
    .categories-carousel-wrapper .autocomplete-item {
        padding: 10px 12px;
        font-size: 13px;
    }
}

