/**
 * Mobile Enhancement Styles
 * =========================
 *
 * Pull-to-Refresh, Bottom Sheets, Touch Interactions,
 * Mobile-Optimized Components
 */

/* ============================================================================
   PULL TO REFRESH
   ============================================================================ */

.pull-to-refresh-indicator {
    position: fixed;
    top: -80px;
    left: 0;
    right: 0;
    height: 80px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: white;
    z-index: 9999;
    transition: transform 0.3s ease, opacity 0.3s ease;
    opacity: 0;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.pull-to-refresh-indicator.ready {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.pull-to-refresh-indicator.refreshing .pull-spinner {
    animation: spin 1s linear infinite;
}

.pull-spinner {
    width: 30px;
    height: 30px;
    border: 3px solid #ecf0f1;
    border-top-color: #667eea;
    border-radius: 50%;
    margin-bottom: 8px;
}

.pull-to-refresh-indicator.ready .pull-spinner {
    border-color: rgba(255, 255, 255, 0.3);
    border-top-color: white;
}

.pull-text {
    font-size: 14px;
    font-weight: 600;
    color: #7f8c8d;
}

.pull-to-refresh-indicator.ready .pull-text {
    color: white;
}

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


/* ============================================================================
   BOTTOM SHEET
   ============================================================================ */

.bottom-sheet-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 9998;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.bottom-sheet-overlay.active {
    opacity: 1;
    visibility: visible;
}

.bottom-sheet {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: white;
    border-radius: 20px 20px 0 0;
    padding: 20px;
    max-height: 80vh;
    z-index: 9999;
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1);
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.15);
    overflow-y: auto;
}

.bottom-sheet.active {
    transform: translateY(0);
}

.bottom-sheet-handle {
    width: 40px;
    height: 4px;
    background: #ddd;
    border-radius: 2px;
    margin: 0 auto 20px;
    cursor: grab;
}

.bottom-sheet-handle:active {
    cursor: grabbing;
}

.bottom-sheet-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 1px solid #ecf0f1;
}

.bottom-sheet-header h3 {
    font-size: 20px;
    color: #2c3e50;
    margin: 0;
}

.bottom-sheet-close {
    background: none;
    border: none;
    font-size: 28px;
    color: #95a5a6;
    cursor: pointer;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.bottom-sheet-close:active {
    transform: scale(0.95);
}

.bottom-sheet-content {
    margin-bottom: 20px;
    color: #7f8c8d;
    line-height: 1.6;
}

.bottom-sheet-actions {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.bottom-sheet-action {
    width: 100%;
    padding: 16px;
    background: #667eea;
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.bottom-sheet-action:active {
    transform: scale(0.98);
    background: #5568d3;
}

.bottom-sheet-action.secondary {
    background: #ecf0f1;
    color: #2c3e50;
}

.bottom-sheet-action.secondary:active {
    background: #d5dbdf;
}


/* ============================================================================
   MOBILE INPUT CLEAR BUTTON
   ============================================================================ */

.input-clear {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    background: #95a5a6;
    color: white;
    border: none;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.input-clear:active {
    transform: translateY(-50%) scale(0.9);
    background: #7f8c8d;
}


/* ============================================================================
   TOUCH-FRIENDLY COMPONENTS
   ============================================================================ */

@media (max-width: 768px) {
    /* Larger touch targets */
    button,
    .btn,
    .scenario-card,
    .event-card,
    .alternative-card {
        min-height: 48px;
    }

    /* Better spacing for touch */
    .scenarios-grid,
    .events-grid,
    .trade-offs-grid {
        gap: 16px;
    }

    /* Star rating touch optimization */
    .star {
        font-size: 32px;
        padding: 8px;
        min-width: 44px;
        min-height: 44px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    /* Slider touch enhancements */
    input[type="range"] {
        height: 44px;
        -webkit-appearance: none;
        appearance: none;
        background: transparent;
    }

    input[type="range"]::-webkit-slider-track {
        height: 8px;
        background: #ecf0f1;
        border-radius: 4px;
    }

    input[type="range"]::-webkit-slider-thumb {
        -webkit-appearance: none;
        width: 32px;
        height: 32px;
        border-radius: 50%;
        background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        cursor: pointer;
        box-shadow: 0 2px 8px rgba(102, 126, 234, 0.4);
        margin-top: -12px;
    }

    input[type="range"].slider-active::-webkit-slider-thumb {
        box-shadow: 0 4px 12px rgba(102, 126, 234, 0.6);
        transform: scale(1.1);
    }

    /* Checkbox and radio touch optimization */
    input[type="checkbox"],
    input[type="radio"] {
        min-width: 24px;
        min-height: 24px;
        cursor: pointer;
    }
}


/* ============================================================================
   SWIPE INDICATORS
   ============================================================================ */

.swipe-indicator {
    position: relative;
}

.swipe-indicator::after {
    content: '';
    position: absolute;
    top: 50%;
    right: 20px;
    transform: translateY(-50%);
    width: 8px;
    height: 8px;
    border-right: 2px solid #667eea;
    border-bottom: 2px solid #667eea;
    transform: translateY(-50%) rotate(-45deg);
    opacity: 0.5;
    animation: swipe-hint 2s ease-in-out infinite;
}

@keyframes swipe-hint {
    0%, 100% {
        transform: translateY(-50%) rotate(-45deg) translateX(0);
        opacity: 0.5;
    }
    50% {
        transform: translateY(-50%) rotate(-45deg) translateX(5px);
        opacity: 1;
    }
}


/* ============================================================================
   MOBILE NAVIGATION
   ============================================================================ */

@media (max-width: 768px) {
    .header,
    .header-small {
        position: sticky;
        top: 0;
        z-index: 100;
        transition: transform 0.3s ease;
    }

    /* Mobile sticky footer */
    .mobile-footer-actions {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: white;
        padding: 12px 16px;
        box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
        z-index: 99;
        padding-bottom: calc(12px + env(safe-area-inset-bottom));
    }

    .mobile-footer-actions .btn-primary {
        width: 100%;
        margin: 0;
    }

    /* Add bottom padding to content when footer is present */
    body.has-mobile-footer .main-content {
        padding-bottom: calc(80px + env(safe-area-inset-bottom));
    }
}


/* ============================================================================
   SAFE AREA INSETS
   ============================================================================ */

@supports (padding: max(0px)) {
    .bottom-sheet {
        padding-bottom: max(20px, env(safe-area-inset-bottom));
    }

    .mobile-footer-actions {
        padding-bottom: max(12px, env(safe-area-inset-bottom));
    }

    .toast-container {
        bottom: max(20px, env(safe-area-inset-bottom));
    }

    body {
        padding-bottom: env(safe-area-inset-bottom);
    }
}


/* ============================================================================
   MOBILE MODAL ENHANCEMENTS
   ============================================================================ */

@media (max-width: 768px) {
    .modal-content {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        max-width: 100%;
        max-height: 90vh;
        border-radius: 20px 20px 0 0;
        margin: 0;
        animation: slideUpMobile 0.3s ease-out;
    }

    @keyframes slideUpMobile {
        from {
            transform: translateY(100%);
        }
        to {
            transform: translateY(0);
        }
    }

    .modal-content .modal-close {
        top: 12px;
        right: 12px;
        font-size: 36px;
    }
}


/* ============================================================================
   LOADING STATES FOR MOBILE
   ============================================================================ */

.mobile-loading-skeleton {
    display: none;
}

@media (max-width: 768px) {
    .mobile-loading-skeleton {
        display: block;
    }

    .mobile-loading-skeleton .skeleton-card {
        margin-bottom: 16px;
    }
}


/* ============================================================================
   TOUCH RIPPLE EFFECT
   ============================================================================ */

.touch-ripple {
    position: relative;
    overflow: hidden;
}

.touch-ripple::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.5);
    transform: translate(-50%, -50%);
    transition: width 0.6s, height 0.6s;
}

.touch-ripple:active::before {
    width: 300px;
    height: 300px;
}


/* ============================================================================
   MOBILE-OPTIMIZED CARDS
   ============================================================================ */

@media (max-width: 768px) {
    .scenario-card,
    .event-card,
    .result-card {
        border-radius: 16px;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    }

    .scenario-card:active,
    .event-card:active {
        transform: scale(0.98);
        transition: transform 0.1s ease;
    }
}


/* ============================================================================
   MOBILE FORM ENHANCEMENTS
   ============================================================================ */

@media (max-width: 768px) {
    /* Prevent zoom on input focus (iOS) */
    input[type="text"],
    input[type="number"],
    input[type="email"],
    select,
    textarea {
        font-size: 16px !important;
    }

    /* Better input spacing */
    .form-group {
        margin-bottom: 20px;
    }

    .input-wrapper {
        position: relative;
    }

    /* Add padding when keyboard is open */
    input:focus,
    textarea:focus,
    select:focus {
        scroll-margin-bottom: 150px;
    }
}


/* ============================================================================
   HORIZONTAL SCROLL HINT
   ============================================================================ */

.horizontal-scroll-hint {
    position: relative;
}

.horizontal-scroll-hint::after {
    content: '→';
    position: absolute;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    background: linear-gradient(to left, white, transparent);
    padding: 0 10px 0 30px;
    color: #667eea;
    font-size: 20px;
    pointer-events: none;
    opacity: 0.7;
}


/* ============================================================================
   MOBILE ACCESSIBILITY
   ============================================================================ */

@media (max-width: 768px) {
    /* Skip links more visible on mobile */
    .skip-links {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        z-index: 10000;
    }

    .skip-link {
        position: absolute;
        left: -9999px;
        background: #667eea;
        color: white;
        padding: 12px;
        text-decoration: none;
        font-weight: 600;
    }

    .skip-link:focus {
        left: 0;
        top: 0;
        z-index: 10001;
    }
}


/* ============================================================================
   REDUCED MOTION
   ============================================================================ */

@media (prefers-reduced-motion: reduce) {
    .bottom-sheet,
    .bottom-sheet-overlay,
    .pull-to-refresh-indicator {
        transition: none !important;
    }

    @keyframes swipe-hint {
        0%, 100% {
            transform: translateY(-50%) rotate(-45deg);
            opacity: 0.5;
        }
    }
}
