/**
 * Browser Compatibility Styles
 * Ensures compatibility with all major browsers including IE11, Edge, Chrome, Firefox, Safari
 */

/* ============================================
   CSS GRID FALLBACKS FOR OLDER BROWSERS
   ============================================ */

/* Fallback for browsers that don't support CSS Grid */
@supports not (display: grid) {
    .project-grid,
    .shot-grid {
        display: -webkit-box;
        display: -moz-box;
        display: -ms-flexbox;
        display: -webkit-flex;
        display: flex;
        -webkit-flex-wrap: wrap;
        -ms-flex-wrap: wrap;
        flex-wrap: wrap;
        -webkit-box-pack: start;
        -ms-flex-pack: start;
        -webkit-justify-content: flex-start;
        justify-content: flex-start;
    }
    
    .project-grid > *,
    .shot-grid > * {
        -webkit-box-flex: 0;
        -webkit-flex: 0 1 300px;
        -ms-flex: 0 1 300px;
        flex: 0 1 300px;
        margin: 10px;
    }
}

/* Grid with vendor prefixes for older browsers */
.project-grid,
.shot-grid {
    display: -ms-grid;
    display: grid;
    -ms-grid-columns: repeat(auto-fill, minmax(300px, 1fr));
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 20px;
    -ms-grid-rows: auto;
    grid-auto-rows: auto;
}

/* Gap property fallback */
@supports not (gap: 20px) {
    .project-grid > *,
    .shot-grid > * {
        margin: 10px;
    }
    .project-grid,
    .shot-grid {
        margin: -10px;
    }
}

/* ============================================
   FLEXBOX VENDOR PREFIXES
   ============================================ */

.container,
.panel,
header,
.brand-container,
.sidebar,
.appearance-selector,
.appearance-modes,
.size-selector,
.library-tabs {
    display: -webkit-box;
    display: -moz-box;
    display: -ms-flexbox;
    display: -webkit-flex;
    display: flex;
}

/* Flex direction */
.field,
.seq-header,
.card-body {
    -webkit-box-orient: vertical;
    -webkit-box-direction: normal;
    -ms-flex-direction: column;
    -webkit-flex-direction: column;
    flex-direction: column;
}

/* Flex properties */
.flex-1,
.brand-text,
.seq-title {
    -webkit-box-flex: 1;
    -webkit-flex: 1;
    -ms-flex: 1;
    flex: 1;
}

/* Align items */
.brand-container,
header,
.appearance-selector,
.appearance-modes {
    -webkit-box-align: center;
    -ms-flex-align: center;
    -webkit-align-items: center;
    align-items: center;
}

/* Justify content */
header,
.appearance-selector {
    -webkit-box-pack: justify;
    -ms-flex-pack: justify;
    -webkit-justify-content: space-between;
    justify-content: space-between;
}

/* ============================================
   TRANSFORM & TRANSITION VENDOR PREFIXES
   ============================================ */

.card,
.button,
.proj-card,
.appearance-btn,
.size-btn {
    -webkit-transition: all 0.2s ease;
    -moz-transition: all 0.2s ease;
    -o-transition: all 0.2s ease;
    transition: all 0.2s ease;
}

/* Transform */
.brand-container img,
.card-img img {
    -webkit-transform: translateZ(0);
    -moz-transform: translateZ(0);
    -ms-transform: translateZ(0);
    -o-transform: translateZ(0);
    transform: translateZ(0);
}

/* ============================================
   BORDER RADIUS FALLBACK
   ============================================ */

.panel,
.proj-card,
.card,
.button,
.appearance-btn,
.size-btn {
    -webkit-border-radius: 8px;
    -moz-border-radius: 8px;
    border-radius: 8px;
}

/* ============================================
   BOX SHADOW VENDOR PREFIXES
   ============================================ */

.panel,
.proj-card,
.card,
.login-box {
    -webkit-box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    -moz-box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

/* ============================================
   OBJECT FIT FALLBACK (for images)
   ============================================ */

.card-img img,
.proj-thumb img,
.project-image-preview img {
    -o-object-fit: cover;
    object-fit: cover;
}

@supports not (object-fit: cover) {
    .card-img img,
    .proj-thumb img,
    .project-image-preview img {
        width: 100%;
        height: 100%;
        /* Fallback: Center image */
        position: absolute;
        top: 50%;
        left: 50%;
        -webkit-transform: translate(-50%, -50%);
        -moz-transform: translate(-50%, -50%);
        -ms-transform: translate(-50%, -50%);
        -o-transform: translate(-50%, -50%);
        transform: translate(-50%, -50%);
    }
}

/* ============================================
   ASPECT RATIO FALLBACK
   ============================================ */

.card-img,
.proj-thumb,
.project-image-preview {
    position: relative;
}

.card-img::before,
.proj-thumb::before,
.project-image-preview::before {
    content: '';
    display: block;
    padding-bottom: 56.25%; /* 16:9 aspect ratio */
}

@supports (aspect-ratio: 16 / 9) {
    .card-img::before,
    .proj-thumb::before,
    .project-image-preview::before {
        display: none;
    }
    
    .card-img,
    .proj-thumb,
    .project-image-preview {
        aspect-ratio: 16 / 9;
    }
}

.card-img img,
.proj-thumb img,
.project-image-preview img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

/* ============================================
   SCROLLBAR STYLING (Webkit browsers)
   ============================================ */

.sidebar::-webkit-scrollbar,
.panel::-webkit-scrollbar,
.comments-panel::-webkit-scrollbar {
    width: 8px;
}

.sidebar::-webkit-scrollbar-track,
.panel::-webkit-scrollbar-track,
.comments-panel::-webkit-scrollbar-track {
    background: #f1f1f1;
}

.sidebar::-webkit-scrollbar-thumb,
.panel::-webkit-scrollbar-thumb,
.comments-panel::-webkit-scrollbar-thumb {
    background: #888;
    -webkit-border-radius: 4px;
    border-radius: 4px;
}

.sidebar::-webkit-scrollbar-thumb:hover,
.panel::-webkit-scrollbar-thumb:hover,
.comments-panel::-webkit-scrollbar-thumb:hover {
    background: #555;
}

/* Firefox scrollbar */
.sidebar,
.panel,
.comments-panel {
    scrollbar-width: thin;
    scrollbar-color: #888 #f1f1f1;
}

/* ============================================
   USER SELECT & APPEARANCE
   ============================================ */

.brand-container,
.button,
.appearance-btn,
.size-btn {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

input,
textarea,
select {
    -webkit-appearance: none;
    -moz-appearance: none;
    -ms-appearance: none;
    appearance: none;
}

/* ============================================
   IE11 SPECIFIC FIXES
   ============================================ */

@media screen and (-ms-high-contrast: active), (-ms-high-contrast: none) {
    /* IE11 Grid fallback */
    .project-grid {
        display: -ms-grid;
        -ms-grid-columns: 1fr 20px 1fr 20px 1fr;
        -ms-grid-rows: auto;
    }
    
    .project-grid > *:nth-child(1) { -ms-grid-column: 1; -ms-grid-row: 1; }
    .project-grid > *:nth-child(2) { -ms-grid-column: 3; -ms-grid-row: 1; }
    .project-grid > *:nth-child(3) { -ms-grid-column: 5; -ms-grid-row: 1; }
    .project-grid > *:nth-child(4) { -ms-grid-column: 1; -ms-grid-row: 2; }
    .project-grid > *:nth-child(5) { -ms-grid-column: 3; -ms-grid-row: 2; }
    .project-grid > *:nth-child(6) { -ms-grid-column: 5; -ms-grid-row: 2; }
    
    /* Flexbox fallback for IE11 */
    .container,
    header,
    .brand-container {
        display: -ms-flexbox;
        -ms-flex-direction: row;
        -ms-flex-wrap: nowrap;
        -ms-flex-pack: justify;
    }
    
    /* Fix for sticky positioning in IE11 */
    header {
        position: relative;
    }
    
    /* Fix for CSS variables in IE11 */
    .panel,
    .proj-card,
    .card {
        background: #FFFFFF;
    }
    
    header {
        background: #0F111A;
    }
}

/* ============================================
   SAFARI SPECIFIC FIXES
   ============================================ */

@supports (-webkit-appearance: none) {
    /* Fix for Safari flexbox issues */
    .project-grid,
    .shot-grid {
        -webkit-align-content: start;
        align-content: start;
    }
    
    /* Fix for Safari transform issues */
    .card:hover,
    .proj-card:hover {
        -webkit-transform: translateY(-2px);
        transform: translateY(-2px);
    }
}

/* ============================================
   FIREFOX SPECIFIC FIXES
   ============================================ */

@-moz-document url-prefix() {
    /* Fix for Firefox image rendering */
    .card-img img {
        image-rendering: -moz-crisp-edges;
    }
    
    /* Fix for Firefox button styling */
    button {
        -moz-appearance: none;
    }
}

/* ============================================
   MOBILE BROWSER FIXES
   ============================================ */

/* iOS Safari fixes */
@supports (-webkit-touch-callout: none) {
    /* Disable callout on iOS */
    .proj-card,
    .card {
        -webkit-touch-callout: none;
    }
    
    /* Fix for iOS viewport height */
    .view {
        min-height: -webkit-fill-available;
    }
}

/* Android Chrome fixes */
@media screen and (-webkit-min-device-pixel-ratio: 0) {
    input[type="text"],
    input[type="password"],
    textarea,
    select {
        -webkit-appearance: none;
    }
}

/* ============================================
   RESPONSIVE IMPROVEMENTS
   ============================================ */

/* Extra small devices (phones, 480px and down) */
@media only screen and (max-width: 480px) {
    .project-grid,
    .shot-grid {
        -ms-grid-columns: 1fr;
        grid-template-columns: 1fr;
        gap: 15px;
    }
    
    .container {
        padding: 0 10px;
    }
    
    header {
        padding: 10px 15px;
        -webkit-box-orient: vertical;
        -webkit-box-direction: normal;
        -ms-flex-direction: column;
        -webkit-flex-direction: column;
        flex-direction: column;
        -webkit-box-align: stretch;
        -ms-flex-align: stretch;
        -webkit-align-items: stretch;
        align-items: stretch;
    }
}

/* Small devices (phones, 768px and down) */
@media only screen and (max-width: 768px) {
    .project-grid,
    .shot-grid {
        -ms-grid-columns: repeat(2, 1fr);
        grid-template-columns: repeat(2, 1fr);
        gap: 15px;
    }
    
    .appearance-selector {
        -webkit-box-orient: vertical;
        -webkit-box-direction: normal;
        -ms-flex-direction: column;
        -webkit-flex-direction: column;
        flex-direction: column;
        -webkit-box-align: stretch;
        -ms-flex-align: stretch;
        -webkit-align-items: stretch;
        align-items: stretch;
    }
    
    .size-selector {
        margin-left: 0 !important;
        margin-top: 10px;
    }
    
    /* Hide library comments panel on mobile */
    .library-comments-panel {
        display: none !important;
    }
}

/* Medium devices (tablets, 992px and down) */
@media only screen and (max-width: 992px) {
    .project-grid,
    .shot-grid {
        -ms-grid-columns: repeat(auto-fill, minmax(250px, 1fr));
        grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    }
}

/* ============================================
   PRINT STYLES
   ============================================ */

@media print {
    .sidebar,
    header,
    .button,
    .appearance-selector {
        display: none !important;
    }
    
    .view {
        display: block !important;
    }
    
    .project-grid,
    .shot-grid {
        display: block;
    }
    
    .proj-card,
    .card {
        page-break-inside: avoid;
        margin-bottom: 20px;
    }
}

/* ============================================
   HIGH CONTRAST MODE SUPPORT
   ============================================ */

@media (prefers-contrast: high) {
    .panel,
    .proj-card,
    .card {
        border: 2px solid;
    }
    
    .button,
    .appearance-btn,
    .size-btn {
        border: 2px solid;
    }
}

/* ============================================
   REDUCED MOTION SUPPORT
   ============================================ */

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        -webkit-animation-duration: 0.01ms !important;
        animation-duration: 0.01ms !important;
        -webkit-animation-iteration-count: 1 !important;
        animation-iteration-count: 1 !important;
        -webkit-transition-duration: 0.01ms !important;
        -moz-transition-duration: 0.01ms !important;
        -o-transition-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}

/* ============================================
   DARK MODE SUPPORT (if needed)
   ============================================ */

@media (prefers-color-scheme: dark) {
    /* Keep light mode as default, but add dark mode support if needed */
    /* Uncomment to enable dark mode support */
    /*
    :root {
        --sb-bg: #1a1a1a;
        --sb-card: #2a2a2a;
        --sb-text: #ffffff;
        --sb-border: #444444;
    }
    */
}

