/* /styles/compatibility.css */
/* Universal Browser Compatibility Layer */
/* This file fixes browser-specific issues without changing your existing design */

/* ======================================== */
/* BROWSER DETECTION & FEATURE SUPPORT */
/* ======================================== */

/* Safari/WebKit specific fixes */
@supports (-webkit-appearance: none) {
    /* Fix CSS Grid + Flexbox nesting issues in Safari */
    .calendar-grid {
        -webkit-transform: translateZ(0);
        -webkit-backface-visibility: hidden;
    }
    
    /* Fix positioning issues in Safari */
    .calendar-day {
        -webkit-transform: translateZ(0);
    }
    
    /* Fix viewport height issues in iOS Safari */
    @media screen and (max-width: 768px) {
        body {
            height: 100vh;
            height: -webkit-fill-available;
        }
        
        .app-container {
            height: 100vh;
            height: -webkit-fill-available;
        }
    }
}

/* Firefox specific fixes */
@supports (-moz-appearance: none) {
    /* Fix CSS Grid sizing issues in Firefox */
    .calendar-grid {
        min-height: 0;
        min-width: 0;
    }
    
    /* Fix flexbox sizing in Firefox */
    .calendar-day {
        min-height: 0;
        flex-shrink: 1;
    }
    
    /* Fix box-shadow performance in Firefox */
    .card-3d:hover {
        -moz-transform: translateY(-5px);
    }
}

/* Edge/Chromium specific fixes */
@supports (-ms-ime-align: auto) {
    /* Fix CSS Grid in older Edge versions */
    .calendar-grid {
        display: -ms-grid;
        -ms-grid-columns: 1fr 1fr 1fr 1fr 1fr 1fr 1fr;
        -ms-grid-rows: auto auto auto auto auto auto auto;
    }
}

/* ======================================== */
/* UNIVERSAL LAYOUT FALLBACKS */
/* ======================================== */

/* Fallback for browsers that don't support CSS Grid */
@supports not (display: grid) {
    .calendar-grid {
        display: flex;
        flex-wrap: wrap;
        gap: 4px;
    }
    
    .calendar-day {
        flex: 1 1 calc(14.28% - 4px);
        min-width: 80px;
        max-width: calc(14.28% - 4px);
    }
}

/* Fallback for browsers that don't support flexbox */
@supports not (display: flex) {
    .app-container {
        display: block;
        width: 80%;
        margin: 0 auto;
    }
    
    .calendar-grid {
        display: block;
    }
    
    .calendar-day {
        display: inline-block;
        width: calc(14.28% - 4px);
        vertical-align: top;
    }
}

/* ======================================== */
/* MOBILE COMPATIBILITY FIXES */
/* ======================================== */

/* Universal mobile fixes */
@media (max-width: 768px) {
    /* Fix viewport width issues */
    .app-container {
        width: 95vw;
        max-width: 100vw;
        min-width: 320px;
    }
    
    /* Fix touch target sizes */
    .add-btn, .action-btn {
        min-width: 44px;
        min-height: 44px;
        touch-action: manipulation;
    }
    
    /* Fix mobile scrolling */
    .calendar-wrapper {
        -webkit-overflow-scrolling: touch;
        overflow-scrolling: touch;
    }
}

/* ======================================== */
/* POSITIONING FALLBACKS */
/* ======================================== */

/* Fix absolute positioning issues */
.calendar-day {
    position: relative;
}

/* Ensure add buttons are always visible */
.add-btn {
    position: absolute !important;
    left: 50% !important;
    top: 10px !important;
    transform: translateX(-50%) !important;
    z-index: 10 !important;
}

/* Fallback positioning for browsers that don't support transform */
@supports not (transform: translateX(-50%)) {
    .add-btn {
        left: 0 !important;
        right: 0 !important;
        margin: 0 auto !important;
        transform: none !important;
    }
}

/* ======================================== */
/* CSS GRID FALLBACKS */
/* ======================================== */

/* Ensure grid columns work consistently */
.calendar-grid {
    grid-template-columns: repeat(7, 1fr);
    grid-auto-rows: minmax(80px, auto);
}

/* Fix grid cell sizing issues */
.calendar-day {
    min-height: 80px;
    overflow: hidden;
}

/* ======================================== */
/* TRANSFORM & ANIMATION FALLBACKS */
/* ======================================== */

/* Fallback for browsers that don't support transforms */
@supports not (transform: translateY(-2px)) {
    .calendar-day:hover {
        transform: none;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    }
    
    .btn-3d:hover {
        transform: none;
        box-shadow: 0 6px 16px rgba(0, 0, 0, 0.4);
    }
}

/* ======================================== */
/* VIEWPORT UNIT FALLBACKS */
/* ======================================== */

/* Fallback for browsers with viewport issues */
@supports not (height: 100vh) {
    body {
        height: 100%;
    }
    
    .app-container {
        height: 100%;
        width: 80%;
    }
}

/* ======================================== */
/* BROWSER-SPECIFIC OVERRIDES */
/* ======================================== */

/* Safari iOS specific overrides */
@media screen and (-webkit-min-device-pixel-ratio: 2) and (max-width: 768px) {
    .calendar-day {
        -webkit-transform: translateZ(0);
        -webkit-backface-visibility: hidden;
    }
}

/* Firefox mobile specific overrides */
@media screen and (max-width: 768px) {
    @supports (-moz-appearance: none) {
        .calendar-grid {
            display: flex;
            flex-wrap: wrap;
        }
        
        .calendar-day {
            flex: 1 1 calc(14.28% - 4px);
        }
    }
}

/* ======================================== */
/* CRITICAL FALLBACKS FOR BROKEN LAYOUTS */
/* ======================================== */

/* Nuclear option: if everything else fails, show basic table */
@supports not (display: flex) and not (display: grid) {
    .calendar-grid {
        display: table;
        width: 100%;
        border-collapse: collapse;
    }
    
    .calendar-day {
        display: table-cell;
        width: 14.28%;
        border: 1px solid #334155;
        padding: 8px;
        vertical-align: top;
    }
}

/* ======================================== */
/* DEBUGGING & TESTING */
/* ======================================== */

/* Add this class to test compatibility layer */
.compatibility-test {
    border: 2px solid #ff0000 !important;
    background: rgba(255, 0, 0, 0.1) !important;
}

/* ======================================== */
/* END OF COMPATIBILITY LAYER */
/* ======================================== */
