/* iOS Web App Styles */
@supports (padding: max(0px)) {
    .pt-safe {
        padding-top: max(env(safe-area-inset-top), 0px);
    }
    
    .pb-safe {
        padding-bottom: max(env(safe-area-inset-bottom), 0px);
    }
    
    .pl-safe {
        padding-left: max(env(safe-area-inset-left), 0px);
    }
    
    .pr-safe {
        padding-right: max(env(safe-area-inset-right), 0px);
    }
}

/* Prevent zoom on input focus for iOS */
@media screen and (-webkit-min-device-pixel-ratio: 0) {
    select,
    textarea,
    input {
        font-size: 16px;
    }
}

/* Hide Safari UI elements in standalone mode */
@media all and (display-mode: standalone) {
    body {
        -webkit-user-select: none;
        -webkit-touch-callout: none;
        -webkit-tap-highlight-color: transparent;
    }
    
    /* Hide address bar on scroll */
    html {
        height: 100vh;
        overflow: hidden;
    }
    
    body {
        height: 100vh;
        overflow-y: auto;
        overflow-x: hidden;
        -webkit-overflow-scrolling: touch;
    }
}

/* iOS specific styles */
@supports (-webkit-touch-callout: none) {
    /* Prevent rubber band scrolling */
    html, body {
        position: fixed;
        width: 100%;
        height: 100%;
        overflow: hidden;
    }
    
    #root {
        height: 100%;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    /* Improve touch targets */
    button, a, input, select, textarea {
        min-height: 44px;
        min-width: 44px;
    }
    
    /* Prevent text selection */
    * {
        -webkit-user-select: none;
        -webkit-touch-callout: none;
    }
    
    /* Allow text selection in inputs */
    input, textarea {
        -webkit-user-select: text;
    }
}

/* Burger Menu Styles */
.burger-menu {
    position: relative;
    z-index: 100;
}

.burger-menu button {
    width: 44px;
    height: 44px;
    background: white;
    border-radius: 50%;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    outline: none;
    -webkit-tap-highlight-color: transparent;
}

.burger-menu button:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    transform: scale(1.05);
}

.burger-menu button:active {
    transform: scale(1.05);
}

/* Burger icon animation */
.burger-icon {
    width: 20px;
    height: 20px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 2px;
}

.burger-line {
    width: 16px;
    height: 2px;
    background-color: #374151;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    border-radius: 1px;
}

.burger-line.open:nth-child(1) {
    transform: rotate(45deg) translate(4px, 4px);
}

.burger-line.open:nth-child(2) {
    opacity: 0;
    transform: scale(0);
}

.burger-line.open:nth-child(3) {
    transform: rotate(-45deg) translate(4px, -4px);
}

/* Dropdown menu styles */
.dropdown-menu {
    position: absolute;
    top: 100%;
    left: 0;
    margin-top: 8px;
    background: white;
    border-radius: 12px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15);
    border: 1px solid #e5e7eb;
    overflow: hidden;
    z-index: 50;
    min-width: 200px;
    animation: dropdownSlide 0.2s ease-out;
    transform: translateX(-100%) translateX(-30px);
}

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

.dropdown-menu a {
    display: block;
    padding: 12px 16px;
    font-size: 14px;
    font-weight: 500;
    color: #374151;
    text-decoration: none;
    transition: all 0.2s ease;
    border-bottom: 1px solid #f3f4f6;
    -webkit-tap-highlight-color: transparent;
}

.dropdown-menu a:last-child {
    border-bottom: none;
}

.dropdown-menu a:hover {
    background-color: #3B82F6;
    color: white;
}

.dropdown-menu a:active {
    background-color: #2563EB;
}

/* Mobile specific burger menu adjustments */
@media (max-width: 768px) {
    .burger-menu button {
        width: 40px;
        height: 40px;
    }
    
    .burger-icon {
        width: 18px;
        height: 18px;
    }
    
    .burger-line {
        width: 14px;
        height: 1.5px;
    }
    
    .dropdown-menu {
        min-width: 180px;
        right: -8px;
    }
    
    .dropdown-menu a {
        padding: 14px 16px;
        font-size: 15px;
    }
}

/* Webapp mode burger menu enhancements */
@media all and (display-mode: standalone) {
    .burger-menu button {
        /* Ensure proper touch target in webapp mode */
        min-width: 44px;
        min-height: 44px;
    }
    
    .dropdown-menu {
        /* Better positioning in webapp mode */
        position: fixed;
        top: auto;
        right: 16px;
        margin-top: 0;
        margin-bottom: 8px;
    }
}

/* Splash screen styles */
.app-splash {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.app-splash img {
    max-width: 200px;
    height: auto;
}

/* Install prompt animations */
.install-prompt-enter {
    opacity: 0;
    transform: scale(0.9);
}

.install-prompt-enter-active {
    opacity: 1;
    transform: scale(1);
    transition: opacity 300ms, transform 300ms;
}

.install-prompt-exit {
    opacity: 1;
    transform: scale(1);
}

.install-prompt-exit-active {
    opacity: 0;
    transform: scale(0.9);
    transition: opacity 300ms, transform 300ms;
}

/* Status bar styling for iOS */
@supports (padding-top: env(safe-area-inset-top)) {
    .status-bar {
        height: env(safe-area-inset-top);
        background-color: #3B82F6;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        z-index: 1000;
    }
}

/* Prevent pull-to-refresh in standalone mode */
@media all and (display-mode: standalone) {
    body {
        overscroll-behavior: none;
    }
}

/* Improve scrolling performance */
* {
    -webkit-overflow-scrolling: touch;
}

/* Hide scrollbars in webapp mode */
@media all and (display-mode: standalone) {
    ::-webkit-scrollbar {
        display: none;
    }
    
    * {
        -ms-overflow-style: none;
        scrollbar-width: none;
    }
}

/* iOS Safe Areas and transparent home indicator */
@supports (padding: max(0px)) {
    /* Keep safe areas but make home indicator transparent */
    .pt-safe {
        padding-top: max(env(safe-area-inset-top), 0px);
    }
    
    .pb-safe {
        padding-bottom: max(env(safe-area-inset-bottom), 0px);
    }
    
    .pl-safe {
        padding-left: max(env(safe-area-inset-left), 0px);
    }
    
    .pr-safe {
        padding-right: max(env(safe-area-inset-right), 0px);
    }
    
    /* Make the home indicator area transparent instead of gray */
    body {
        background: transparent !important;
    }
}

/* iOS specific styles with safe areas */
@supports (-webkit-touch-callout: none) {
    /* For iOS devices - keep safe areas */
    html, body {
        background: transparent !important;
    }
    
    /* Ensure safe areas are respected */
    .pt-safe {
        padding-top: max(env(safe-area-inset-top), 0px) !important;
    }
    
    .pb-safe {
        padding-bottom: max(env(safe-area-inset-bottom), 0px) !important;
    }
}

/* Webapp mode with transparent home indicator */
@media all and (display-mode: standalone) {
    /* Keep safe areas but make home indicator transparent */
    html, body {
        background: transparent !important;
    }
    
    /* Ensure safe areas are respected in webapp mode */
    .pt-safe {
        padding-top: max(env(safe-area-inset-top), 0px) !important;
    }
    
    .pb-safe {
        padding-bottom: max(env(safe-area-inset-bottom), 0px) !important;
    }
}

/* Convert Top 10 to Top 8 on mobile devices */
@media (max-width: 768px) {
    /* Hide 9th and 10th items in card grids */
    .card-container:nth-child(n+9) {
        display: none !important;
    }
    
    /* Update "Top 10" text to "Top 8" on mobile */
    h2 {
        position: relative;
    }
    
    /* Replace "Top 10" with "Top 8" */
    h2:contains("Top 10") {
        visibility: hidden;
    }
    
    h2:contains("Top 10")::after {
        content: "Top 8";
        visibility: visible;
        position: absolute;
        left: 0;
        right: 0;
        top: 0;
        background: linear-gradient(to right, #3B82F6, #1E40AF);
        -webkit-background-clip: text;
        -webkit-text-fill-color: transparent;
        background-clip: text;
    }
}

/* Additional mobile detection for better compatibility */
@media (max-width: 768px), (orientation: portrait) and (max-width: 1024px) {
    /* Ensure footer buttons are properly centered on all mobile devices */
    .footer-button, 
    footer a, 
    footer button {
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        text-align: center !important;
        min-height: 44px !important;
        line-height: 1.2 !important;
    }
    
    /* Force top 8 on all mobile devices */
    .card-container:nth-child(n+9) {
        display: none !important;
    }
}

/* Better footer button alignment */
.footer-button {
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    text-align: center !important;
    min-height: 44px !important;
}

/* Burger Menu Container - Allineamento universale */
.dropdown-container {
    position: relative;
    display: flex;
    justify-content: flex-end;
}

.dropdown-container > div {
    position: relative;
}

/* Garantisce che il dropdown sia sempre allineato a destra */
.dropdown-container .absolute {
    right: 0;
    left: auto;
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .dropdown-container {
        justify-content: flex-end;
    }
    
    .dropdown-container .absolute {
        right: 0;
        min-width: 200px;
    }
}

/* Webapp mode adjustments */
@media all and (display-mode: standalone) {
    .dropdown-container {
        justify-content: flex-end;
    }
    
    .dropdown-container .absolute {
        right: 0;
    }
}
