/* ========================================
   Cross-Browser Compatibility Fixes
   VladlenFM VPN Panel Frontend
   ========================================
   
   This file contains browser-specific fixes,
   vendor prefixes, fallbacks, and progressive
   enhancement patterns for maximum compatibility.
   
   Generated: March 14, 2026
   Version: 1.0.0
   ======================================== */

/* ========================================
   1. VENDOR PREFIXES
   ======================================== */

/* backdrop-filter with Safari prefix */
.modal-overlay,
.sidebar-overlay,
.terms-modal-overlay,
.notification-dropdown,
.tip-modal {
    -webkit-backdrop-filter: blur(4px);
    backdrop-filter: blur(4px);
}

/* Transform with prefixes for older browsers */
.btn:hover,
.nav-item:hover,
.card:hover,
.tariff-card:hover {
    -webkit-transform: translateY(-2px);
    -ms-transform: translateY(-2px);
    transform: translateY(-2px);
}

/* Transition with prefixes */
.btn,
.nav-item,
.card,
.form-input {
    -webkit-transition: all 0.2s ease;
    -moz-transition: all 0.2s ease;
    -o-transition: all 0.2s ease;
    transition: all 0.2s ease;
}

/* Animation with prefixes */
@-webkit-keyframes fadeIn {
    from { opacity: 0; -webkit-transform: translateY(10px); transform: translateY(10px); }
    to { opacity: 1; -webkit-transform: translateY(0); transform: translateY(0); }
}

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

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

@-webkit-keyframes spin {
    to { -webkit-transform: rotate(360deg); transform: rotate(360deg); }
}

@-moz-keyframes spin {
    to { -moz-transform: rotate(360deg); transform: rotate(360deg); }
}

@keyframes spin {
    to { -webkit-transform: rotate(360deg); -moz-transform: rotate(360deg); transform: rotate(360deg); }
}

@-webkit-keyframes shake {
    0%, 100% { -webkit-transform: translateX(0); transform: translateX(0); }
    25% { -webkit-transform: translateX(-8px); transform: translateX(-8px); }
    75% { -webkit-transform: translateX(8px); transform: translateX(8px); }
}

@-moz-keyframes shake {
    0%, 100% { -moz-transform: translateX(0); transform: translateX(0); }
    25% { -moz-transform: translateX(-8px); transform: translateX(-8px); }
    75% { -moz-transform: translateX(8px); transform: translateX(8px); }
}

@keyframes shake {
    0%, 100% { -webkit-transform: translateX(0); -moz-transform: translateX(0); transform: translateX(0); }
    25% { -webkit-transform: translateX(-8px); -moz-transform: translateX(-8px); transform: translateX(-8px); }
    75% { -webkit-transform: translateX(8px); -moz-transform: translateX(8px); transform: translateX(8px); }
}

/* Gradient with fallback */
.btn-primary {
    /* Fallback for older browsers */
    background: #6366F1;
    background: -webkit-linear-gradient(135deg, #6366F1 0%, #8B5CF6 100%);
    background: -moz-linear-gradient(135deg, #6366F1 0%, #8B5CF6 100%);
    background: -o-linear-gradient(135deg, #6366F1 0%, #8B5CF6 100%);
    background: linear-gradient(135deg, #6366F1 0%, #8B5CF6 100%);
}

/* Flexbox with prefixes */
.sidebar,
.stats-grid,
.cards-grid,
.tariffs-grid,
.dashboard-grid {
    display: -webkit-box;
    display: -webkit-flex;
    display: -moz-flex;
    display: -ms-flexbox;
    display: flex;
}

/* Grid with fallback */
.stats-grid,
.cards-grid,
.tariffs-grid {
    display: -ms-grid;
    display: grid;
}

/* ========================================
   2. FOCUS INDICATORS (Cross-Browser)
   ======================================== */

/* Enhanced focus for Safari */
button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    -webkit-outline-offset: 2px;
}

/* Fallback for browsers without :focus-visible */
button:focus,
a:focus,
input:focus,
select:focus,
textarea:focus {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* Safari-specific focus ring */
@supports (-webkit-touch-callout: none) {
    button:focus,
    a:focus,
    input:focus {
        outline: 2px solid -webkit-focus-ring-color;
        outline-offset: 2px;
    }
}

/* ========================================
   3. SCROLL BEHAVIOR (Safari Fallback)
   ======================================== */

html {
    scroll-behavior: smooth;
}

/* JavaScript will handle smooth scroll for Safari if needed */
/* Add this JS fallback:
   if ('scrollBehavior' in document.documentElement.style === false) {
       // Use smoothscroll polyfill
   }
*/

/* ========================================
   4. FONT LOADING OPTIMIZATION
   ======================================== */

/* Add font-display swap via JS or update Google Fonts URL */
/* Recommended Google Fonts link:
   <link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap" rel="stylesheet">
*/

/* Font smoothing for different browsers */
body {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

/* ========================================
   5. MOBILE TOUCH TARGETS
   ======================================== */

/* Ensure minimum 44x44px touch targets for mobile */
@media (pointer: coarse) {
    .btn,
    .nav-item,
    .icon-btn,
    .copy-btn,
    .action-btn,
    .device-tab,
    .range-btn,
    .terms-tab-btn {
        min-height: 44px;
        min-width: 44px;
    }
    
    .form-input {
        min-height: 44px;
        font-size: 16px; /* Prevent iOS zoom on focus */
    }
}

/* iOS-specific: Prevent zoom on input focus */
@supports (-webkit-touch-callout: none) {
    .form-input {
        font-size: 16px;
    }
}

/* ========================================
   6. OVERFLOW PREVENTION
   ======================================== */

/* Prevent horizontal scroll on mobile */
body {
    overflow-x: hidden;
    max-width: 100vw;
    position: relative;
}

/* Image containment */
img {
    max-width: 100%;
    height: auto;
    display: block;
}

/* Code/text wrapping */
code,
.link-text code,
.info-value.code {
    word-break: break-all;
    word-wrap: break-word;
    overflow-wrap: break-word;
    hyphens: auto;
}

/* ========================================
   7. COLOR CONTRAST FIXES
   ======================================== */

/* Dark theme text contrast improvement */
[data-theme="dark"] {
    --text-primary: #FFFFFF;
    --text-secondary: #B0B0B0;
    --text-muted: #9CA3AF;
}

/* High contrast mode support */
@media (forced-colors: active) {
    .btn-primary {
        background: CanvasText;
        color: Canvas;
    }
    
    .nav-item.active {
        background: Highlight;
        color: HighlightText;
    }
    
    .form-input:focus {
        border-color: CanvasText;
    }
}

/* ========================================
   8. PRINT STYLES
   ======================================== */

@media print {
    .sidebar,
    .sidebar-overlay,
    .mobile-header,
    .theme-toggle,
    .toast,
    .modal,
    .notification-dropdown,
    .btn,
    .action-btn {
        display: none !important;
    }
    
    .main-content {
        margin-left: 0 !important;
        padding: 0 !important;
    }
    
    .card {
        break-inside: avoid;
        box-shadow: none !important;
        border: 1px solid #000 !important;
    }
    
    body {
        background: white !important;
        color: black !important;
        font-size: 12pt;
    }
    
    a {
        text-decoration: underline;
    }
    
    .skip-link {
        display: none;
    }
}

/* ========================================
   9. REDUCED MOTION SUPPORT
   ======================================== */

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
    
    .skip-link {
        transition: none;
    }
}

/* ========================================
   10. SYSTEM FONT STACKS
   ======================================== */

/* Enhanced font stack for better fallbacks */
body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif;
}

/* Monospace font stack */
code,
.info-value.code,
.link-text code {
    font-family: 'SF Mono', 'Monaco', 'Inconsolata', 'Fira Code', 'Droid Sans Mono', 'Source Code Pro', monospace;
}

/* ========================================
   11. SVG ICONS COMPATIBILITY
   ======================================== */

/* Ensure icons render correctly across browsers */
svg {
    max-width: 100%;
    height: auto;
    vertical-align: middle;
}

/* Lucide icons specific fix */
i[data-lucide] svg {
    width: inherit;
    height: inherit;
}

/* ========================================
   12. TABLE COMPATIBILITY
   ======================================== */

/* Mobile table scroll */
.table-wrapper {
    -webkit-overflow-scrolling: touch;
    overflow-x: auto;
    width: 100%;
}

/* Sticky headers for modern browsers */
th {
    position: -webkit-sticky;
    position: sticky;
    top: 0;
    z-index: 10;
}

/* ========================================
   13. MODAL COMPATIBILITY
   ======================================== */

/* Modal centering fallback */
.modal-overlay {
    display: -webkit-box;
    display: -webkit-flex;
    display: -moz-flex;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-align: center;
    -webkit-align-items: center;
    -moz-align-items: center;
    -ms-flex-align: center;
    align-items: center;
    -webkit-box-pack: center;
    -webkit-justify-content: center;
    -moz-justify-content: center;
    -ms-flex-pack: center;
    justify-content: center;
}

/* Modal max-height for mobile */
.modal,
.terms-modal-content {
    max-height: calc(100vh - 40px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

/* ========================================
   14. CHART.JS CONTAINER FIXES
   ======================================== */

.chart-container {
    position: relative;
    height: 250px;
    max-height: 250px;
}

#trafficChart,
#loadChart {
    max-height: 250px;
}

/* ========================================
   15. QR CODE DISPLAY
   ======================================== */

/* QR code container for all browsers */
.link-qr,
.qr-code {
    background: #FFFFFF;
    padding: 12px;
    border-radius: 8px;
    display: -webkit-box;
    display: -webkit-flex;
    display: -moz-flex;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-pack: center;
    -webkit-justify-content: center;
    -moz-justify-content: center;
    -ms-flex-pack: center;
    justify-content: center;
    -webkit-box-align: center;
    -webkit-align-items: center;
    -moz-align-items: center;
    -ms-flex-align: center;
    align-items: center;
}

.link-qr img,
.qr-code img {
    max-width: 180px;
    height: auto;
}

/* ========================================
   16. SIDEBAR TRANSITION FIX
   ======================================== */

.sidebar {
    -webkit-transition: -webkit-transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    transition: -webkit-transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    -moz-transition: -moz-transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    -o-transition: -o-transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), -webkit-transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), -moz-transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), -o-transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ========================================
   17. SAFE AREA INSETS (iPhone X+)
   ======================================== */

@supports (padding: max(0px)) {
    .main-content,
    .mobile-header,
    .sidebar {
        padding-left: max(20px, env(safe-area-inset-left));
        padding-right: max(20px, env(safe-area-inset-right));
    }
    
    .toast {
        bottom: max(20px, env(safe-area-inset-bottom));
        right: max(20px, env(safe-area-inset-right));
    }
}

/* ========================================
   18. DARK MODE SYSTEM PREFERENCE
   ======================================== */

/* Auto-detect system dark mode */
@media (prefers-color-scheme: dark) {
    :root.auto-theme {
        --bg-primary: #0A0A0F;
        --bg-primary-rgb: 10, 10, 15;
        --bg-secondary: #12121A;
        --bg-card: #16161F;
        --bg-hover: #1E1E2A;
        --text-primary: #FFFFFF;
        --text-secondary: #B0B0B0;
        --text-muted: #808080;
        --border-color: #3A3A4A;
    }
}

/* ========================================
   19. PROGRESSIVE ENHANCEMENT
   ======================================== */

/* Modern features with fallbacks */
@supports (backdrop-filter: blur(4px)) {
    .modal-overlay,
    .sidebar-overlay {
        -webkit-backdrop-filter: blur(4px);
        backdrop-filter: blur(4px);
    }
}

@supports not (backdrop-filter: blur(4px)) {
    .modal-overlay,
    .sidebar-overlay {
        background: rgba(0, 0, 0, 0.7);
    }
}

@supports (display: grid) {
    .stats-grid,
    .cards-grid,
    .tariffs-grid {
        display: grid;
    }
}

@supports not (display: grid) {
    .stats-grid,
    .cards-grid,
    .tariffs-grid {
        display: -webkit-box;
        display: -webkit-flex;
        display: -moz-flex;
        display: -ms-flexbox;
        display: flex;
        -webkit-box-orient: vertical;
        -webkit-box-direction: normal;
        -webkit-flex-direction: column;
        -moz-flex-direction: column;
        -ms-flex-direction: column;
        flex-direction: column;
    }
}

/* ========================================
   20. BROWSER-SPECIFIC HACKS (Use Sparingly)
   ======================================== */

/* Safari 15+ specific */
@supports (-webkit-hyphens: none) {
    .welcome-banner {
        -webkit-mask-image: -webkit-radial-gradient(white, black);
    }
}

/* Edge-specific fixes */
@supports (-ms-ime-align: auto) {
    .btn-primary {
        background: #6366F1;
    }
}

/* Firefox-specific */
@-moz-document url-prefix() {
    .form-input {
        padding-block: 12px;
    }
    
    .card {
        padding: 24px;
    }
}

/* ========================================
   END OF CROSS-BROWSER FIXES
   ======================================== */
