/* iOS-like Effects and Animations */

/* 1. Smooth Transitions for all interactive elements */
* {
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
}

button, .btn-primary, .btn-secondary, .glass-card, .nav-item, 
.service-item, .key-card, .platform-card, .payment-method-card,
.device-item, .node-item, .ref-item, .app-tab-btn, a {
    transition: all 0.2s cubic-bezier(0.4, 0.0, 0.2, 1);
}

/* 2. Scale on Tap Effect */
button:active, 
.btn-primary:active, 
.btn-secondary:active,
.service-item:active,
.key-card:active,
.platform-card:active,
.payment-method-card:active,
.app-tab-btn:active,
.nav-item:active,
.preset-btn:active {
    transform: scale(0.96);
}

/* 3. Momentum Scrolling (iOS style) */
.page,
#active-subs-slider,
.services-list,
#history-list,
#troubleshooting-list,
#ref-list,
.apps-content,
.nodes-compact-list,
.devices-list,
.app-tabs {
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
}

/* 4. Smooth Page Transitions */
.page {
    transition: opacity 0.3s ease-in-out, transform 0.3s ease-in-out;
}

.page:not(.active) {
    opacity: 0;
    transform: translateX(20px);
    pointer-events: none;
}

.page.active {
    opacity: 1;
    transform: translateX(0);
    pointer-events: auto;
}

/* 5. Modal Animations */
#modal-overlay {
    transition: opacity 0.3s ease-in-out, backdrop-filter 0.3s ease-in-out;
}

#modal-overlay:not(.hidden) {
    animation: fadeIn 0.3s ease-in-out;
}

#modal-overlay.hidden {
    animation: fadeOut 0.2s ease-in-out;
}

.modal-content {
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.3s ease-in-out;
}

#modal-overlay:not(.hidden) .modal-content {
    animation: slideUp 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

#modal-overlay.hidden .modal-content {
    animation: slideDown 0.2s ease-in-out;
}

@keyframes slideUp {
    from {
        transform: translateY(100%);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

@keyframes slideDown {
    from {
        transform: translateY(0);
        opacity: 1;
    }
    to {
        transform: translateY(100%);
        opacity: 0;
    }
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes fadeOut {
    from { opacity: 1; }
    to { opacity: 0; }
}

/* 6. Menu Overlay Animation */
#menu-overlay {
    transition: opacity 0.3s ease-in-out, backdrop-filter 0.3s ease-in-out;
}

#menu-overlay:not(.hidden) {
    animation: fadeIn 0.3s ease-in-out;
}

.menu-content {
    transition: transform 0.3s cubic-bezier(0.4, 0.0, 0.2, 1);
}

#menu-overlay:not(.hidden) .menu-content {
    animation: slideFromLeft 0.3s cubic-bezier(0.4, 0.0, 0.2, 1);
}

#menu-overlay.hidden .menu-content {
    animation: slideToLeft 0.2s cubic-bezier(0.4, 0.0, 0.2, 1);
}

@keyframes slideFromLeft {
    from {
        transform: translateX(-100%);
    }
    to {
        transform: translateX(0);
    }
}

@keyframes slideToLeft {
    from {
        transform: translateX(0);
    }
    to {
        transform: translateX(-100%);
    }
}

/* 7. Card Hover Effects (for desktop/iPad) */
@media (hover: hover) {
    .glass-card:hover,
    .key-card:hover,
    .platform-card:hover,
    .payment-method-card:hover {
        transform: translateY(-2px);
        box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
    }
}

/* 8. Button Press Visual Feedback */
button:active::after,
.btn-primary:active::after,
.btn-secondary:active::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.2);
    border-radius: inherit;
    transform: translate(-50%, -50%) scale(0);
    animation: ripple 0.6s ease-out;
}

@keyframes ripple {
    to {
        transform: translate(-50%, -50%) scale(2);
        opacity: 0;
    }
}

/* 9. Input Focus Animation */
input:focus,
textarea:focus,
.glass-input:focus {
    outline: none;
    transform: scale(1.02);
    box-shadow: 0 0 0 2px var(--primary-color);
}

/* 10. Loading Spinner Animation */
.spinner {
    animation: spin 1s linear infinite;
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* 11. Status Badge Pulse (for active services) */
.status-badge.status-active {
    animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% {
        box-shadow: 0 0 0 0 rgba(76, 217, 100, 0.4);
    }
    50% {
        box-shadow: 0 0 0 8px rgba(76, 217, 100, 0);
    }
}

/* 12. Smooth Slider Scrolling */
#active-subs-slider {
    scroll-snap-type: x mandatory;
    scroll-padding: 0 20px;
}

#active-subs-slider > * {
    scroll-snap-align: center;
}

/* 13. Nav Item Active Animation */
.nav-item.active {
    animation: navActivate 0.3s ease-out;
}

@keyframes navActivate {
    0% {
        transform: scale(0.9);
        opacity: 0.5;
    }
    50% {
        transform: scale(1.05);
    }
    100% {
        transform: scale(1);
        opacity: 1;
    }
}

/* 14. Progressive Enhancement for High-End Devices */
@media (prefers-reduced-motion: no-preference) {
    /* Enable advanced animations only if user hasn't requested reduced motion */
    
    .large-card {
        transition: all 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
    }
    
    .service-item {
        transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    }
}

/* 15. Reduce Motion for Accessibility */
@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;
    }
}

/* 16. Pull-to-Refresh Visual Indicator (optional enhancement) */
.page::before {
    content: '';
    position: absolute;
    top: -50px;
    left: 50%;
    transform: translateX(-50%);
    width: 30px;
    height: 30px;
    border: 3px solid var(--primary-color);
    border-top-color: transparent;
    border-radius: 50%;
    opacity: 0;
    transition: opacity 0.2s;
}

/* 17. Skeleton Loading Animation */
@keyframes skeleton-loading {
    0% {
        background-position: -200% 0;
    }
    100% {
        background-position: 200% 0;
    }
}

.skeleton {
    background: linear-gradient(
        90deg,
        rgba(255, 255, 255, 0.05) 0%,
        rgba(255, 255, 255, 0.1) 50%,
        rgba(255, 255, 255, 0.05) 100%
    );
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s ease-in-out infinite;
    border-radius: 8px;
}

/* 18. iOS-style Bounce Effect on Scroll End */
.page {
    overscroll-behavior-y: contain;
}

/* 19. Safe Area Insets for Notch/Dynamic Island */
.app-header,
.bottom-nav {
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
}

/* 20. Improved Touch Targets (44x44 minimum for iOS) */
button,
.btn-primary,
.btn-secondary,
.nav-item,
a {
    min-height: 44px;
    min-width: 44px;
}

/* 21. iOS-style Alert/Confirm Modal Animation */
.tg-alert {
    animation: alertBounce 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes alertBounce {
    0% {
        transform: scale(0.8);
        opacity: 0;
    }
    50% {
        transform: scale(1.05);
    }
    100% {
        transform: scale(1);
        opacity: 1;
    }
}
