/* Google Fonts for Hindi support */
@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+Devanagari:wght@400;500;600&display=swap');

/* CSS Reset */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* Base Styles */
body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
    min-height: 100vh;
    line-height: 1.6;
}

/* Header */
.site-header {
    position: sticky;
    top: 0;
    z-index: 1100;
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid #e9ecef;
}

.header-content {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0.5rem 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.logo img {
    height: 36px;
    width: auto;
    display: block;
}

/* Hindi Font Support */
body[lang="hi"],
body[lang="hi"] * {
    font-family: 'Noto Sans Devanagari', 'Arial Unicode MS', sans-serif;
    line-height: 1.7;
}

/* Language Toggle Button */
.language-toggle {
    position: fixed;
    top: 1rem;
    right: 1rem;
    z-index: 1000;
}

/* When language toggle is inside header, use static flow positioning */
.site-header .language-toggle {
    position: static;
    top: auto;
    right: auto;
    z-index: auto;
}

.language-btn {
    background: rgba(255, 255, 255, 0.95);
    border: 2px solid #007bff;
    border-radius: 24px;
    padding: 0.75rem 1.125rem;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.875rem;
    color: #007bff;
    transition: all 0.3s ease;
    backdrop-filter: blur(10px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    min-width: 60px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.language-btn:hover {
    background: #007bff;
    color: white;
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(0, 123, 255, 0.3);
}

.language-btn:active {
    transform: scale(0.95);
}

/* Main Layout */
.container {
    display: grid;
    grid-template-columns: 2fr 1fr;
    grid-template-areas: 
        "model gallery"
        "design-info gallery";
    gap: 0.75rem;
    padding: 1rem;
    max-width: 1400px;
    margin: 0 auto;
    min-height: 100vh;
    align-items: start;
}

/* Model Container */
.model-container {
    grid-area: model;
    background: white;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
    overflow: hidden;
    min-height: 500px;
}

model-viewer {
    width: 100%;
    height: 600px;
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    --poster-color: #f8f9fa;
    --progress-bar-color: #007bff;
    --progress-bar-height: 4px;
}

/* Loading States */
.loading-overlay {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(255, 255, 255, 0.95);
    padding: 1.5rem;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
    display: none;
    z-index: 10;
    text-align: center;
}

.loading-spinner {
    width: 48px;
    height: 48px;
    border: 4px solid #e9ecef;
    border-top: 4px solid #007bff;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 1rem;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

/* Error States */
.error-message {
    background: #f8d7da;
    color: #721c24;
    padding: 1.25rem;
    border-radius: 8px;
    margin: 1rem;
    border: 1px solid #f5c6cb;
    display: none;
    text-align: center;
}

.retry-button {
    background: #007bff;
    color: white;
    border: none;
    padding: 0.75rem 1.5rem;
    border-radius: 6px;
    cursor: pointer;
    margin-top: 0.75rem;
    font-size: 0.875rem;
    font-weight: 500;
    transition: all 0.2s ease;
    min-height: 44px;
}

.retry-button:hover {
    background: #0056b3;
    transform: translateY(-1px);
}

/* Design Info Container */
.design-info-container {
    grid-area: design-info;
    background: white;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
    padding: 1.25rem 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    min-height: 80px;
}

.design-info {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 1.1em;
}

.design-label {
    color: #6c757d;
    font-weight: 500;
}

.design-number {
    color: #2c3e50;
    font-weight: 700;
    font-size: 1.2em;
    background: linear-gradient(135deg, #007bff, #0056b3);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.share-btn {
    background: #25d366;
    color: white;
    border: none;
    border-radius: 25px;
    padding: 0.75rem 1.25rem;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.875rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    transition: all 0.3s ease;
    box-shadow: 0 4px 12px rgba(37, 211, 102, 0.3);
    min-height: 44px;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.share-btn:hover {
    background: #128c7e;
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(37, 211, 102, 0.4);
}

.share-btn:active {
    transform: scale(0.95);
}

.whatsapp-icon {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

.share-text {
    font-weight: 600;
}

/* Gallery Container */
.gallery-container {
    grid-area: gallery;
    background: white;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
    padding: 1.5rem;
    max-height: 600px;
    overflow-y: auto;
}

.gallery-title {
    font-size: 1.3em;
    font-weight: 600;
    margin-bottom: 1.25rem;
    color: #2c3e50;
    text-align: center;
    padding-bottom: 0.75rem;
    border-bottom: 2px solid #e9ecef;
}

/* Image Gallery */
.image-gallery {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(90px, 1fr));
    gap: 0.75rem;
}

/* Thumbnails */
.thumbnail {
    aspect-ratio: 1;
    border-radius: 8px;
    overflow: hidden;
    cursor: pointer;
    transition: all 0.3s ease;
    border: 3px solid transparent;
    background: #f8f9fa;
    position: relative;
    min-height: 44px;
    min-width: 44px;
}

.thumbnail img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.3s ease;
}

.thumbnail:hover {
    transform: translateY(-4px) scale(1.05);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
    border-color: #007bff;
}

.thumbnail:hover img {
    transform: scale(1.1);
}

.thumbnail.active {
    border-color: #28a745;
    box-shadow: 0 0 0 3px rgba(40, 167, 69, 0.3);
    background: rgba(40, 167, 69, 0.08);
}

.thumbnail.active::after {
    content: '✓';
    position: absolute;
    top: 4px;
    right: 4px;
    background: #28a745;
    color: white;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: bold;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.thumbnail.loading {
    background: #e9ecef;
    animation: pulse 1.5s ease-in-out infinite;
}

.thumbnail.loading::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 24px;
    height: 24px;
    border: 2px solid #dee2e6;
    border-top: 2px solid #007bff;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes pulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.7;
    }
}

.thumbnail.error {
    background: #f8d7da;
    border-color: #dc3545;
    cursor: not-allowed;
}

.thumbnail.error::before {
    content: '⚠';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: #dc3545;
    font-size: 24px;
}

/* Custom Scrollbar */
.gallery-container::-webkit-scrollbar {
    width: 8px;
}

.gallery-container::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

.gallery-container::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 4px;
}

.gallery-container::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

/* Focus States for Accessibility */
.thumbnail:focus,
.retry-button:focus,
.language-btn:focus,
.share-btn:focus {
    outline: 2px solid #007bff;
    outline-offset: 2px;
}

/* Tablet Styles */
@media (max-width: 1024px) {
    .container {
        grid-template-columns: 1fr;
        grid-template-areas: 
            "model" 
            "design-info" 
            "gallery";
        gap: 0.75rem;
        padding: 1rem;
    }

    model-viewer {
        height: 500px;
    }

    .design-info-container {
        padding: 1rem 1.25rem;
        min-height: 70px;
    }

    .design-info {
        font-size: 1em;
    }

    .design-number {
        font-size: 1.1em;
    }

    .gallery-container {
        max-height: none;
    }

    .image-gallery {
        grid-template-columns: repeat(auto-fit, minmax(85px, 1fr));
    }
}

/* Mobile Styles */
@media (max-width: 768px) {
    .header-content {
        padding: 0.5rem 0.75rem;
    }

    .logo img {
        height: 30px;
    }

    .container {
        padding: 0.5rem;
        gap: 0.5rem;
        grid-template-columns: 1fr;
        grid-template-areas: 
            "model" 
            "design-info" 
            "gallery";
        min-height: 100vh;
    }

    .language-toggle {
        top: 0.5rem;
        right: 0.5rem;
        z-index: 1001;
    }

    .site-header .language-toggle {
        top: auto;
        right: auto;
    }

    .language-btn {
        padding: 0.625rem 0.875rem;
        font-size: 0.75rem;
        min-height: 44px;
        min-width: 50px;
        border-radius: 20px;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    }

    /* Optimize model viewer for mobile */
    .model-container {
        border-radius: 8px;
        min-height: 300px;
    }

    model-viewer {
        height: 50vh;
        min-height: 300px;
        max-height: 400px;
        --progress-bar-height: 6px;
        border-radius: 8px;
    }

    /* Compact gallery design */
    .gallery-container {
        padding: 0.75rem;
        border-radius: 8px;
        max-height: none;
        flex: 1;
    }

    .gallery-title {
        font-size: 1.1em;
        margin-bottom: 0.75rem;
        padding-bottom: 0.5rem;
        border-bottom: 1px solid #e9ecef;
    }

    /* Optimized thumbnail grid for mobile */
    .image-gallery {
        grid-template-columns: repeat(4, 1fr);
        gap: 0.5rem;
        max-height: calc(100vh - 50vh - 8rem);
        overflow-y: auto;
        padding: 0.25rem;
    }

    .thumbnail {
        aspect-ratio: 1;
        min-height: 70px;
        min-width: 70px;
        border-width: 2px;
        border-radius: 6px;
    }

    .thumbnail.active::after {
        width: 18px;
        height: 18px;
        font-size: 11px;
        top: 3px;
        right: 3px;
    }

    .retry-button {
        padding: 0.75rem 1.5rem;
        font-size: 0.875rem;
        min-height: 44px;
        border-radius: 8px;
    }

    /* Enhanced focus indicators for mobile */
    .thumbnail:focus {
        outline: 2px solid #007bff;
        outline-offset: 2px;
    }

    .thumbnail.active {
        border-width: 2px;
        box-shadow: 0 0 0 2px rgba(40, 167, 69, 0.3);
    }

    /* Design info mobile styles */
    .design-info-container {
        padding: 0.875rem 1rem;
        border-radius: 8px;
        min-height: 60px;
        gap: 0.75rem;
    }

    .design-info {
        font-size: 0.95em;
        gap: 0.5rem;
    }

    .design-number {
        font-size: 1.05em;
    }

    .share-btn {
        padding: 0.625rem 1rem;
        font-size: 0.8125rem;
        border-radius: 20px;
        min-height: 40px;
    }

    .whatsapp-icon {
        width: 18px;
        height: 18px;
    }

    /* Improve scrolling on mobile */
    .gallery-container::-webkit-scrollbar {
        width: 4px;
    }
}

/* Small Mobile Styles */
@media (max-width: 480px) {
    .container {
        padding: 0.375rem;
        gap: 0.375rem;
    }

    .language-toggle {
        top: 0.375rem;
        right: 0.375rem;
    }

    .site-header .language-toggle {
        top: auto;
        right: auto;
    }

    .language-btn {
        padding: 0.5rem 0.75rem;
        font-size: 0.6875rem;
        min-height: 40px;
        min-width: 46px;
        border-radius: 18px;
    }

    /* More compact model viewer */
    .model-container {
        border-radius: 6px;
        min-height: 280px;
    }

    model-viewer {
        height: 45vh;
        min-height: 280px;
        max-height: 350px;
        --progress-bar-height: 8px;
        border-radius: 6px;
    }

    .gallery-container {
        padding: 0.625rem;
        border-radius: 6px;
    }

    .gallery-title {
        font-size: 1em;
        margin-bottom: 0.625rem;
        padding-bottom: 0.375rem;
    }

    /* 5 columns for better space utilization */
    .image-gallery {
        grid-template-columns: repeat(5, 1fr);
        gap: 0.375rem;
        max-height: calc(100vh - 45vh - 7rem);
        padding: 0.125rem;
    }

    .thumbnail {
        min-height: 60px;
        min-width: 60px;
        border-radius: 4px;
    }

    .thumbnail.active::after {
        width: 16px;
        height: 16px;
        font-size: 10px;
        top: 2px;
        right: 2px;
    }

    .loading-overlay {
        padding: 1rem;
        border-radius: 8px;
    }

    .loading-spinner {
        width: 36px;
        height: 36px;
        border-width: 3px;
    }

    .error-message {
        margin: 0.5rem;
        padding: 0.875rem;
        font-size: 0.8125rem;
        border-radius: 6px;
    }

    .retry-button {
        padding: 0.625rem 1.25rem;
        font-size: 0.8125rem;
        min-height: 40px;
    }

    /* Small mobile design info styles */
    .design-info-container {
        padding: 0.75rem 0.875rem;
        border-radius: 6px;
        min-height: 55px;
        gap: 0.5rem;
    }

    .design-info {
        font-size: 0.875em;
        gap: 0.375rem;
    }

    .design-number {
        font-size: 1em;
    }

    .share-btn {
        padding: 0.5rem 0.875rem;
        font-size: 0.75rem;
        border-radius: 18px;
        min-height: 36px;
    }

    .whatsapp-icon {
        width: 16px;
        height: 16px;
    }
}

/* Extra Small Mobile */
@media (max-width: 375px) {
    .container {
        padding: 0.25rem;
        gap: 0.25rem;
    }

    .language-toggle {
        top: 0.25rem;
        right: 0.25rem;
    }

    .site-header .language-toggle {
        top: auto;
        right: auto;
    }

    .language-btn {
        padding: 0.5rem 0.625rem;
        font-size: 0.625rem;
        min-height: 38px;
        min-width: 42px;
        border-radius: 16px;
    }

    .model-container {
        min-height: 260px;
    }

    model-viewer {
        height: 42vh;
        min-height: 260px;
        max-height: 320px;
    }

    .gallery-container {
        padding: 0.5rem;
    }

    .gallery-title {
        font-size: 0.95em;
        margin-bottom: 0.5rem;
        padding-bottom: 0.25rem;
    }

    /* 6 columns for maximum space efficiency */
    .image-gallery {
        grid-template-columns: repeat(6, 1fr);
        gap: 0.25rem;
        max-height: calc(100vh - 42vh - 6rem);
        padding: 0.125rem;
    }

    .thumbnail {
        min-height: 50px;
        min-width: 50px;
        border-radius: 3px;
        border-width: 1px;
    }

    .thumbnail.active {
        border-width: 2px;
    }

    .thumbnail.active::after {
        width: 14px;
        height: 14px;
        font-size: 9px;
        top: 1px;
        right: 1px;
    }

    /* Extra small mobile design info styles */
    .design-info-container {
        padding: 0.625rem 0.75rem;
        border-radius: 6px;
        min-height: 50px;
        gap: 0.375rem;
        flex-direction: column;
        align-items: stretch;
        text-align: center;
    }

    .design-info {
        font-size: 0.8125em;
        gap: 0.25rem;
        justify-content: center;
    }

    .design-number {
        font-size: 0.95em;
    }

    .share-btn {
        padding: 0.5rem 0.75rem;
        font-size: 0.6875rem;
        border-radius: 16px;
        min-height: 32px;
        justify-content: center;
    }

    .whatsapp-icon {
        width: 14px;
        height: 14px;
    }
}

/* Landscape Mobile - Better space utilization */
@media (max-width: 896px) and (orientation: landscape) and (max-height: 500px) {
    .container {
        grid-template-columns: 1.8fr 1fr;
        grid-template-areas: 
            "model gallery"
            "design-info gallery";
        max-height: 100vh;
        padding: 0.375rem;
        gap: 0.375rem;
    }

    .design-info-container {
        padding: 0.5rem 0.75rem;
        border-radius: 4px;
        min-height: 45px;
        gap: 0.5rem;
    }

    .design-info {
        font-size: 0.8125em;
        gap: 0.375rem;
    }

    .design-number {
        font-size: 0.9375em;
    }

    .share-btn {
        padding: 0.375rem 0.75rem;
        font-size: 0.6875rem;
        border-radius: 16px;
        min-height: 32px;
    }

    .whatsapp-icon {
        width: 14px;
        height: 14px;
    }

    .language-toggle {
        top: 0.25rem;
        right: 0.25rem;
    }

    .site-header .language-toggle {
        top: auto;
        right: auto;
    }

    model-viewer {
        height: calc(100vh - 1rem);
        max-height: none;
        border-radius: 4px;
    }

    .gallery-container {
        max-height: calc(100vh - 1rem);
        overflow-y: auto;
        padding: 0.5rem;
        border-radius: 4px;
    }

    .gallery-title {
        font-size: 0.9em;
        margin-bottom: 0.5rem;
        padding-bottom: 0.25rem;
    }

    .image-gallery {
        grid-template-columns: repeat(3, 1fr);
        gap: 0.375rem;
    }

    .thumbnail {
        min-height: 55px;
        min-width: 55px;
        border-radius: 3px;
    }

    .thumbnail.active::after {
        width: 14px;
        height: 14px;
        font-size: 9px;
    }
}

/* Touch Device Optimizations */
@media (hover: none) and (pointer: coarse) {

    .language-btn,
    .thumbnail,
    .retry-button,
    .share-btn {
        -webkit-tap-highlight-color: transparent;
        -webkit-touch-callout: none;
        -webkit-user-select: none;
        user-select: none;
        touch-action: manipulation;
    }

    .language-btn:active {
        transform: scale(0.92);
        background: #0056b3;
        color: white;
        transition: all 0.1s ease;
    }

    .thumbnail:active {
        transform: scale(0.92);
        transition: transform 0.1s ease;
    }

    /* Remove hover effects on touch devices */
    .thumbnail:hover {
        transform: none;
        box-shadow: none;
        border-color: transparent;
    }

    .thumbnail:hover img {
        transform: none;
    }

    /* Add subtle press feedback */
    .thumbnail::before {
        content: '';
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 123, 255, 0.1);
        border-radius: inherit;
        opacity: 0;
        transition: opacity 0.15s ease;
        pointer-events: none;
    }

    .thumbnail:active::before {
        opacity: 1;
    }

    model-viewer {
        touch-action: pan-x pan-y;
        /* Improve touch responsiveness */
        --min-hotspot-opacity: 1;
    }

    /* Better visual feedback for active thumbnails on touch */
    .thumbnail.active {
        transform: scale(1.02);
    }

    .thumbnail.active:active {
        transform: scale(0.98);
    }

    .share-btn:active {
        transform: scale(0.92);
        background: #128c7e;
        transition: all 0.1s ease;
    }
}

/* High Contrast Mode */
@media (prefers-contrast: high) {
    .language-btn {
        border-width: 3px;
        border-color: #000;
        background: #fff;
        color: #000;
    }

    .language-btn:hover,
    .language-btn:focus {
        background: #000;
        color: #fff;
    }

    .thumbnail {
        border-width: 2px;
        border-color: #000;
    }

    .thumbnail:hover {
        border-color: #0066cc;
    }

    .thumbnail.active {
        border-color: #006600;
    }
}

/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {

    .thumbnail,
    .thumbnail img,
    .model-container,
    .gallery-container,
    .retry-button,
    .language-btn {
        transition: none;
    }

    .loading-spinner,
    .thumbnail.loading::before {
        animation: none;
    }

    .thumbnail:hover,
    .language-btn:hover {
        transform: none;
    }

    model-viewer {
        --auto-rotate: 0deg;
    }
}

/* iOS Safari Optimizations */
@supports (-webkit-touch-callout: none) {
    .container {
        min-height: -webkit-fill-available;
    }

    model-viewer {
        touch-action: manipulation;
    }

    /* Fix iOS Safari bounce scrolling */
    .gallery-container {
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
    }

    /* Prevent iOS zoom on double tap */
    .thumbnail {
        touch-action: manipulation;
    }
}

/* Performance optimizations for mobile */
@media (max-width: 768px) {

    /* Use GPU acceleration for smooth animations */
    .thumbnail {
        will-change: transform;
        transform: translateZ(0);
    }

    .language-btn {
        will-change: transform;
        transform: translateZ(0);
    }

    /* Optimize image rendering on mobile */
    .thumbnail img {
        image-rendering: optimizeSpeed;
        image-rendering: -webkit-optimize-contrast;
    }

    /* Smooth scrolling for gallery */
    .gallery-container {
        scroll-behavior: smooth;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior-y: contain;
    }

    /* Add momentum scrolling indicator */
    .image-gallery {
        position: relative;
    }

    .image-gallery::after {
        content: '';
        position: sticky;
        bottom: 0;
        left: 0;
        right: 0;
        height: 1px;
        background: linear-gradient(to right, transparent, rgba(0, 123, 255, 0.3), transparent);
        opacity: 0;
        transition: opacity 0.3s ease;
        pointer-events: none;
    }

    .gallery-container:not(:hover) .image-gallery::after {
        opacity: 1;
    }
}

/* Safe area adjustments for notched devices */
@supports (padding: max(0px)) {
    @media (max-width: 768px) {
        .container {
            padding-left: max(0.5rem, env(safe-area-inset-left));
            padding-right: max(0.5rem, env(safe-area-inset-right));
            padding-bottom: max(0.5rem, env(safe-area-inset-bottom));
        }

        .language-toggle {
            top: max(0.5rem, env(safe-area-inset-top));
            right: max(0.5rem, env(safe-area-inset-right));
        }

        .site-header .language-toggle {
            top: auto;
            right: auto;
        }
    }
}