/**
 * Exchange Form - Optimized CSS
 * Performance improvements:
 * - Reduced animations (will-change)
 * - Hardware acceleration (transform3d)
 * - Containment (contain property)
 * - Reduced repaints/reflows
 */

/* ============================================
   1. CSS VARIABLES (Optimized)
   ============================================ */
:root {
    --primary: #FF8C00;
    --primary-light: #FFA500;
    --primary-dark: #FF6B00;
    --primary-soft: rgba(255, 140, 0, 0.1);
    --primary-medium: rgba(255, 140, 0, 0.2);
    --primary-strong: rgba(255, 140, 0, 0.3);
    
    --white: #FFFFFF;
    --white-soft: rgba(255, 255, 255, 0.9);
    --white-light: rgba(255, 255, 255, 0.1);
    
    --gray-50: #F8FAFC;
    --gray-100: #F1F5F9;
    --gray-200: #E2E8F0;
    --gray-300: #CBD5E1;
    --gray-600: #475569;
    --gray-900: #0F172A;
    
    --success: #10B981;
    --danger: #EF4444;
    
    --radius: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    
    --shadow: 0 4px 15px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 8px 25px rgba(0, 0, 0, 0.12);
    --shadow-xl: 0 20px 40px rgba(0, 0, 0, 0.15);
    
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ============================================
   2. BASE OPTIMIZATIONS
   ============================================ */
* {
    box-sizing: border-box;
}

/* Reduce paint areas */
.modern-exchange-wrapper {
    contain: layout style paint;
    position: relative;
    max-width: 480px;
    margin: 0 auto;
    padding: 2rem;
    background: var(--white);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-xl);
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

/* ============================================
   3. GLASS OVERLAY (Optimized)
   ============================================ */
.glass-overlay {
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, 
        rgba(255, 255, 255, 0.1) 0%, 
        rgba(255, 140, 0, 0.05) 50%, 
        rgba(255, 255, 255, 0.1) 100%);
    pointer-events: none;
    will-change: auto; /* Only animate when needed */
}

/* ============================================
   4. GRADIENT ORBS (Performance Critical)
   ============================================ */
.gradient-orb {
    position: absolute;
    border-radius: 50%;
    filter: blur(40px);
    opacity: 0.6;
    pointer-events: none;
    /* Use transform3d for GPU acceleration */
    transform: translate3d(0, 0, 0);
    will-change: transform;
}

.orb-1 {
    width: 120px;
    height: 120px;
    background: radial-gradient(circle, var(--primary-medium), transparent);
    top: -60px;
    right: -60px;
    animation: float-orb 6s ease-in-out infinite;
}

.orb-2 {
    width: 80px;
    height: 80px;
    background: radial-gradient(circle, var(--primary-soft), transparent);
    bottom: -40px;
    left: -40px;
    animation: float-orb 6s ease-in-out infinite 3s;
}

/* Optimized animation with transform3d */
@keyframes float-orb {
    0%, 100% { 
        transform: translate3d(0, 0, 0) scale(1); 
    }
    50% { 
        transform: translate3d(0, -20px, 0) scale(1.1); 
    }
}

/* Pause animations when not visible (IntersectionObserver support) */
@media (prefers-reduced-motion: reduce) {
    .gradient-orb {
        animation: none;
    }
}

/* ============================================
   5. HEADER SECTION (Optimized)
   ============================================ */
.exchange-header {
    contain: layout style;
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 2rem;
    position: relative;
    z-index: 2;
}

.header-icon {
    width: 56px;
    height: 56px;
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 1.5rem;
    box-shadow: 0 8px 20px var(--primary-strong);
    /* GPU acceleration */
    transform: translate3d(0, 0, 0);
}

.header-content {
    flex: 1;
}

.header-content h2 {
    margin: 0 0 0.25rem 0;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--gray-900);
    letter-spacing: -0.025em;
}

.header-content p {
    margin: 0;
    font-size: 0.875rem;
    color: var(--gray-600);
    font-weight: 500;
}

.header-decoration {
    display: flex;
    gap: 4px;
}

.pulse-dot {
    width: 8px;
    height: 8px;
    background: var(--primary);
    border-radius: 50%;
    animation: pulse-dot 2s ease-in-out infinite;
    will-change: opacity, transform;
}

.pulse-dot:nth-child(2) { animation-delay: 0.5s; }
.pulse-dot:nth-child(3) { animation-delay: 1s; }

@keyframes pulse-dot {
    0%, 100% { 
        opacity: 0.4; 
        transform: scale(1); 
    }
    50% { 
        opacity: 1; 
        transform: scale(1.2); 
    }
}

/* ============================================
   6. EXCHANGE NAVIGATION (Optimized)
   ============================================ */
.exchange-nav {
    contain: layout style;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-bottom: 2rem;
    background: var(--gray-50);
    padding: 4px;
    border-radius: var(--radius);
    position: relative;
    z-index: 2;
}

.nav-btn {
    padding: 0.75rem 1rem;
    background: transparent;
    border: none;
    border-radius: calc(var(--radius) - 4px);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    transition: var(--transition);
    cursor: pointer;
    font-weight: 500;
    color: var(--gray-600);
    /* GPU acceleration */
    transform: translate3d(0, 0, 0);
    will-change: transform, background-color;
}

.nav-btn.active {
    background: var(--white);
    color: var(--primary);
    box-shadow: var(--shadow);
    transform: translate3d(0, -1px, 0);
}

/* ============================================
   7. EXCHANGE GRID (Optimized)
   ============================================ */
.exchange-grid {
    contain: layout;
    display: grid;
    gap: 1.5rem;
    margin-bottom: 2rem;
    position: relative;
    z-index: 2;
}

.exchange-section {
    contain: layout style paint;
    background: var(--gray-50);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    border: 2px solid transparent;
    transition: var(--transition);
    position: relative;
    overflow: hidden;
    /* GPU acceleration */
    transform: translate3d(0, 0, 0);
    will-change: transform, border-color;
}

.exchange-section::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

.send-section::before {
    background: linear-gradient(90deg, var(--danger), #DC2626);
}

.receive-section::before {
    background: linear-gradient(90deg, var(--success), #059669);
}

.exchange-section:hover {
    border-color: var(--primary-soft);
    transform: translate3d(0, -2px, 0);
    box-shadow: var(--shadow-lg);
}

/* ============================================
   8. INPUT FIELDS (Critical Performance)
   ============================================ */
.input-container {
    contain: layout;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.amount-field {
    position: relative;
}

.amount-input {
    width: 100%;
    padding: 1rem;
    background: var(--white);
    border: 2px solid var(--gray-200);
    border-radius: var(--radius);
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--gray-900);
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    text-align: center;
    /* Optimize text rendering */
    font-variant-numeric: tabular-nums;
}

.amount-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-soft);
}

.input-glow {
    position: absolute;
    inset: -2px;
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
    border-radius: var(--radius);
    opacity: 0;
    transition: opacity 0.3s ease;
    z-index: -1;
    filter: blur(8px);
    pointer-events: none;
}

.amount-input:focus + .input-glow {
    opacity: 1;
}

/* ============================================
   9. CURRENCY FIELD (Optimized)
   ============================================ */
.simple-currency-field {
    contain: layout style;
    position: relative;
    margin-bottom: 1rem;
    /* Mobile: Better touch response */
    cursor: pointer;
    -webkit-tap-highlight-color: rgba(255, 153, 68, 0.1);
    /* Ensure minimum touch target */
    min-height: 44px;
    /* Prevent text selection on mobile when tapping */
    -webkit-user-select: none;
    -moz-user-select: none;
    user-select: none;
}

.currency-display {
    display: flex;
    align-items: center;
    background: linear-gradient(135deg, #ffffff 0%, #f8fafc 100%);
    border: 2px solid #e2e8f0;
    border-radius: 12px;
    padding: 16px;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    position: relative;
    z-index: 1;
    /* GPU acceleration */
    transform: translate3d(0, 0, 0);
    /* Mobile: Ensure touch events work */
    -webkit-tap-highlight-color: rgba(255, 153, 68, 0.1);
}

/* Desktop: Let clicks pass through */
@media (hover: hover) and (pointer: fine) {
    .currency-display {
        pointer-events: none;
    }
    
    .currency-display * {
        pointer-events: none;
    }
}

.simple-currency-field:hover .currency-display {
    border-color: #ff9944;
    box-shadow: 0 4px 12px rgba(255, 153, 68, 0.15);
}

.simple-currency-field.selected .currency-display {
    border-color: #2a1f62;
    background: linear-gradient(135deg, #f8f9ff 0%, #ffffff 100%);
    box-shadow: 0 6px 20px rgba(42, 31, 98, 0.2);
}

.currency-icon-container {
    margin-right: 16px;
}

.currency-icon-circle {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: linear-gradient(135deg, #ffb366 0%, #ff9944 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(255, 179, 102, 0.3);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    position: relative;
    overflow: hidden;
    /* GPU acceleration */
    transform: translate3d(0, 0, 0);
    will-change: transform;
}

.simple-currency-field .lightning-icon {
    font-size: 24px;
    color: white;
    text-shadow: 0 0 8px rgba(255, 255, 255, 0.8);
}

.simple-currency-field .currency-image {
    width: 38px;
    height: 38px;
    object-fit: cover;
    border-radius: 50%;
    border: 2px solid white;
}

.simple-currency-field.selected .currency-icon-circle {
    background: linear-gradient(135deg, #ff9944 0%, #ff7722 100%);
    box-shadow: 0 6px 16px rgba(255, 153, 68, 0.4);
    transform: translate3d(0, 0, 0) scale(1.05);
}

.currency-text {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.simple-currency-field .currency-name {
    font-size: 16px;
    font-weight: 600;
    color: #2d3748;
    transition: color 0.2s ease;
}

.simple-currency-field .currency-symbol {
    font-size: 14px;
    font-weight: 500;
    color: #718096;
    transition: color 0.2s ease;
}

.simple-currency-field.selected .currency-name {
    color: #ff7722;
    font-weight: 700;
}

.simple-currency-field.selected .currency-symbol {
    color: #ff9944;
}

.simple-currency-select {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    min-height: 44px; /* iOS touch target minimum */
    opacity: 0;
    cursor: pointer;
    z-index: 100; /* Higher z-index for mobile */
    /* Mobile touch optimization */
    font-size: 16px; /* Prevents zoom on iOS */
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    pointer-events: auto !important; /* CRITICAL for mobile */
    /* Remove browser default styling */
    background: transparent;
    border: none;
    outline: none;
}

/* ============================================
   10. SUBMIT BUTTON (Optimized)
   ============================================ */
.submit-button {
    contain: layout style paint;
    position: relative;
    width: 100%;
    padding: 1rem 2rem;
    border: none;
    border-radius: var(--radius);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    overflow: hidden;
    z-index: 2;
    /* GPU acceleration */
    transform: translate3d(0, 0, 0);
    will-change: transform;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.btn-gradient {
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
    transition: background 0.3s ease;
}

.btn-content {
    position: relative;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    color: white;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
    font-weight: 700;
}

.btn-shine {
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.3), transparent);
    transition: left 0.5s ease;
    pointer-events: none;
}

.submit-button:hover {
    transform: translate3d(0, -2px, 0);
    box-shadow: 0 8px 25px var(--primary-strong);
}

.submit-button:hover .btn-shine {
    left: 100%;
}

.submit-button:disabled {
    opacity: 0.7;
    cursor: not-allowed;
    transform: translate3d(0, 0, 0);
}

/* ============================================
   11. RULES STYLES (Optimized)
   ============================================ */
.smart-rules-alert {
    contain: layout style;
    background: linear-gradient(135deg, #fff5f5 0%, #fef2f2 100%);
    border: 2px solid #fecaca;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
    margin-bottom: 1.5rem;
}

.rules-header {
    padding: 1rem 1.25rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 1rem;
    background: linear-gradient(135deg, #fee2e2 0%, #fecaca 100%);
    border-bottom: 1px solid #fecaca;
    transition: background 0.2s ease;
}

.rules-icon {
    width: 45px;
    height: 45px;
    background: linear-gradient(135deg, var(--danger), #dc2626);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 1.3rem;
    box-shadow: 0 3px 10px rgba(239, 68, 68, 0.3);
}

.rules-icon.pulsing {
    animation: pulse-alert 2s infinite;
}

@keyframes pulse-alert {
    0% { transform: scale(1); }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

.rule-item {
    contain: layout style;
    display: flex;
    align-items: flex-start;
    gap: 1.25rem;
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    background: white;
    border-radius: var(--radius-lg);
    border: 2px solid #e2e8f0;
    box-shadow: var(--shadow);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    /* GPU acceleration */
    transform: translate3d(0, 0, 0);
    will-change: transform;
}

.rule-item:hover {
    transform: translate3d(10px, -2px, 0);
    box-shadow: var(--shadow-lg);
}

/* ============================================
   12. RESPONSIVE (Optimized)
   ============================================ */
@media (max-width: 768px) {
    /* Mobile: Reduce complex gradients for better paint performance */
    .modern-exchange-wrapper {
        margin: 1rem;
        padding: 1.5rem;
    }
    
    /* Simplify gradients on mobile */
    .gradient-orb {
        opacity: 0.4; /* Reduce opacity for better performance */
        filter: blur(30px); /* Less blur = better performance */
    }
    
    .input-container {
        grid-template-columns: 1fr;
    }
    
    .exchange-nav {
        gap: 6px;
    }
    
    .nav-btn {
        padding: 0.625rem 0.75rem;
        flex-direction: column;
        gap: 0.25rem;
    }
    
    /* Mobile: Optimize touch targets (minimum 44x44px) */
    .nav-btn,
    .favorite-btn,
    .submit-button {
        min-height: 44px;
        min-width: 44px;
    }
    
    /* Mobile: Reduce shadow complexity */
    .exchange-section,
    .submit-button {
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    }
    
    /* Mobile: Optimize animations */
    .pulse-dot {
        animation-duration: 3s; /* Slower = less CPU */
    }
}

@media (max-width: 480px) {
    .modern-exchange-wrapper {
        margin: 0.5rem;
        padding: 1rem;
    }
    
    .header-content h2 {
        font-size: 1.25rem;
    }
    
    .amount-input {
        padding: 0.75rem;
        font-size: 0.875rem;
    }
    
    /* Mobile: Larger touch targets for currency selection */
    .simple-currency-field {
        min-height: 56px;
    }
    
    .currency-display {
        padding: 12px 14px;
        min-height: 56px;
    }
    
    /* Mobile: Larger currency icon */
    .currency-icon-circle {
        width: 40px;
        height: 40px;
    }
    
    .simple-currency-field .currency-image {
        width: 32px;
        height: 32px;
    }
}

/* Touch device specific optimizations */
@media (hover: none) and (pointer: coarse) {
    /* This targets touch devices specifically */
    .simple-currency-field {
        -webkit-tap-highlight-color: rgba(255, 153, 68, 0.2);
        cursor: pointer;
    }
    
    .simple-currency-field:active .currency-display {
        transform: translate3d(0, 0, 0) scale(0.98);
        border-color: #ff9944;
    }
    
    /* 🔥 Ensure select is ALWAYS interactive on mobile */
    .simple-currency-select {
        pointer-events: auto !important;
        -webkit-appearance: menulist !important;
        -moz-appearance: menulist !important;
        appearance: menulist !important;
        touch-action: manipulation !important;
        z-index: 10 !important;
    }
    
    /* Mobile: Make entire field clickable */
    .currency-display {
        cursor: pointer !important;
        user-select: none !important;
        -webkit-user-select: none !important;
    }
}

/* ============================================
   13. PERFORMANCE HINTS
   ============================================ */
/* Note: Font optimization should be done in main CSS with actual fonts */

/* Mobile: Pause animations during scroll for better performance */
body.scrolling .gradient-orb,
body.scrolling .pulse-dot,
body.scrolling .btn-shine {
    animation-play-state: paused !important;
}

/* 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;
    }
}

/* Print styles */
@media print {
    .gradient-orb,
    .glass-overlay,
    .btn-shine,
    .pulse-dot {
        display: none !important;
    }
}
