/* Mobile-First Responsive Design for SXM Tools */

/* Mobile Detection and Base Styles */
@media only screen and (max-width: 768px) {
    
    /* Reset and Base */
    * {
        -webkit-tap-highlight-color: rgba(0, 0, 0, 0.1);
        -webkit-touch-callout: none;
    }
    
    html {
        font-size: 16px;
        -webkit-text-size-adjust: 100%;
    }
    
    body {
        font-size: 16px;
        line-height: 1.6;
        padding: 0;
        margin: 0;
        overflow-x: hidden;
    }
    
    /* Touch-Friendly Buttons - Minimum 44x44px */
    button, .btn, a.button, input[type="submit"], input[type="button"] {
        min-height: 44px;
        min-width: 44px;
        padding: 12px 20px;
        font-size: 16px;
        border-radius: 12px;
        font-weight: 600;
        cursor: pointer;
        transition: all 0.2s ease;
        touch-action: manipulation;
    }
    
    button:active, .btn:active {
        transform: scale(0.96);
    }
    
    /* Form Inputs - Touch Optimized */
    input[type="text"],
    input[type="url"],
    input[type="email"],
    input[type="password"],
    textarea,
    select {
        min-height: 44px;
        padding: 12px 16px;
        font-size: 16px; /* Prevents zoom on iOS */
        border-radius: 12px;
        border: 2px solid #e0e0e0;
        width: 100%;
        box-sizing: border-box;
        transition: border-color 0.2s ease;
    }
    
    input:focus, textarea:focus, select:focus {
        outline: none;
        border-color: #667eea;
        box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
    }
    
    textarea {
        min-height: 120px;
        resize: vertical;
    }
    
    /* Container and Layout */
    .container, .main-container {
        padding: 16px;
        max-width: 100%;
        margin: 0 auto;
    }
    
    /* Single Column Layout */
    .row, .grid, .flex-container {
        display: flex;
        flex-direction: column;
        gap: 16px;
    }
    
    .col, .grid-item, .flex-item {
        width: 100%;
        margin-bottom: 16px;
    }
    
    /* Header - Mobile Optimized */
    header, .header {
        padding: 16px;
        position: sticky;
        top: 0;
        z-index: 1000;
        background: white;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    }
    
    header h1, .header h1 {
        font-size: 24px;
        margin: 0;
    }
    
    /* Navigation - Bottom Navigation for Thumb Zone */
    nav, .navigation {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: white;
        box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.1);
        z-index: 1000;
        padding: 8px;
    }
    
    nav ul, .navigation ul {
        display: flex;
        justify-content: space-around;
        align-items: center;
        list-style: none;
        margin: 0;
        padding: 0;
    }
    
    nav li, .navigation li {
        flex: 1;
        text-align: center;
    }
    
    nav a, .navigation a {
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 4px;
        padding: 8px;
        color: #666;
        text-decoration: none;
        font-size: 12px;
        transition: color 0.2s ease;
    }
    
    nav a:active, .navigation a:active {
        color: #667eea;
    }
    
    nav a i, .navigation a i {
        font-size: 24px;
    }
    
    /* Content Area - Account for Bottom Nav */
    main, .main-content {
        padding-bottom: 80px; /* Space for bottom nav */
        min-height: calc(100vh - 80px);
    }
    
    /* Cards - Mobile Optimized */
    .card, .box, .panel {
        border-radius: 16px;
        padding: 20px;
        margin-bottom: 16px;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
        background: white;
    }
    
    .card-title, .box-title {
        font-size: 20px;
        font-weight: 700;
        margin-bottom: 12px;
    }
    
    /* Download Sections */
    .download-section {
        margin: 20px 0;
    }
    
    .url-input-container {
        display: flex;
        flex-direction: column;
        gap: 12px;
        margin-bottom: 20px;
    }
    
    .url-input {
        width: 100%;
        padding: 14px 16px;
        font-size: 16px;
        border: 2px solid #e0e0e0;
        border-radius: 12px;
        transition: all 0.2s ease;
    }
    
    .url-input:focus {
        border-color: #667eea;
        box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
    }
    
    .download-btn {
        width: 100%;
        padding: 16px;
        font-size: 18px;
        font-weight: 700;
        background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        color: white;
        border: none;
        border-radius: 12px;
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 10px;
        min-height: 56px;
    }
    
    .download-btn:active {
        transform: scale(0.98);
    }
    
    .download-btn:disabled {
        opacity: 0.6;
        cursor: not-allowed;
    }
    
    /* Platform Selection */
    .platform-selector {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
        gap: 12px;
        margin: 20px 0;
    }
    
    .platform-card {
        padding: 20px;
        border-radius: 16px;
        text-align: center;
        background: white;
        border: 2px solid #e0e0e0;
        transition: all 0.2s ease;
        cursor: pointer;
        min-height: 120px;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 8px;
    }
    
    .platform-card:active {
        transform: scale(0.96);
        border-color: #667eea;
        box-shadow: 0 4px 12px rgba(102, 126, 234, 0.2);
    }
    
    .platform-card i {
        font-size: 40px;
        margin-bottom: 8px;
    }
    
    .platform-card span {
        font-size: 14px;
        font-weight: 600;
    }
    
    /* Results and Media Preview */
    .result-container {
        margin: 20px 0;
    }
    
    .media-preview {
        width: 100%;
        border-radius: 12px;
        overflow: hidden;
        margin-bottom: 16px;
    }
    
    .media-preview img,
    .media-preview video {
        width: 100%;
        height: auto;
        display: block;
    }
    
    .thumbnail {
        width: 100%;
        height: auto;
        border-radius: 12px;
        margin-bottom: 12px;
    }
    
    /* Quality Selection */
    .quality-options {
        display: flex;
        flex-direction: column;
        gap: 12px;
        margin: 16px 0;
    }
    
    .quality-btn {
        width: 100%;
        padding: 16px;
        border: 2px solid #e0e0e0;
        background: white;
        border-radius: 12px;
        font-size: 16px;
        font-weight: 600;
        display: flex;
        align-items: center;
        justify-content: space-between;
        cursor: pointer;
        transition: all 0.2s ease;
    }
    
    .quality-btn:active {
        border-color: #667eea;
        background: #f8f9ff;
    }
    
    .quality-btn.selected {
        border-color: #667eea;
        background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        color: white;
    }
    
    /* Loading States */
    .loading-spinner {
        border: 4px solid #f3f3f3;
        border-top: 4px solid #667eea;
        border-radius: 50%;
        width: 50px;
        height: 50px;
        animation: spin 1s linear infinite;
        margin: 20px auto;
    }
    
    @keyframes spin {
        0% { transform: rotate(0deg); }
        100% { transform: rotate(360deg); }
    }
    
    .loading-text {
        text-align: center;
        color: #666;
        font-size: 16px;
        margin-top: 12px;
    }
    
    /* Alerts and Messages */
    .alert, .message, .notification {
        padding: 16px;
        border-radius: 12px;
        margin: 16px 0;
        font-size: 15px;
        line-height: 1.5;
    }
    
    .alert-success, .message-success {
        background: #d1fae5;
        color: #065f46;
        border: 2px solid #10b981;
    }
    
    .alert-error, .message-error {
        background: #fee;
        color: #991b1b;
        border: 2px solid #ef4444;
    }
    
    .alert-info, .message-info {
        background: #dbeafe;
        color: #1e40af;
        border: 2px solid #3b82f6;
    }
    
    .alert-warning, .message-warning {
        background: #fef3c7;
        color: #92400e;
        border: 2px solid #f59e0b;
    }
    
    /* Modal - Full Screen on Mobile */
    .modal {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: white;
        z-index: 2000;
        overflow-y: auto;
        animation: slideUp 0.3s ease-out;
    }
    
    @keyframes slideUp {
        from {
            transform: translateY(100%);
        }
        to {
            transform: translateY(0);
        }
    }
    
    .modal-header {
        padding: 16px;
        border-bottom: 1px solid #e0e0e0;
        display: flex;
        align-items: center;
        justify-content: space-between;
        position: sticky;
        top: 0;
        background: white;
        z-index: 10;
    }
    
    .modal-close {
        min-width: 44px;
        min-height: 44px;
        border-radius: 50%;
        background: #f5f5f5;
        border: none;
        font-size: 20px;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    
    .modal-body {
        padding: 20px;
    }
    
    /* Tables - Scroll Horizontally */
    .table-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        margin: 16px 0;
    }
    
    table {
        width: 100%;
        border-collapse: collapse;
        font-size: 14px;
    }
    
    th, td {
        padding: 12px 8px;
        text-align: left;
        border-bottom: 1px solid #e0e0e0;
    }
    
    /* Typography - Mobile Optimized */
    h1 { font-size: 28px; line-height: 1.2; margin-bottom: 16px; }
    h2 { font-size: 24px; line-height: 1.3; margin-bottom: 14px; }
    h3 { font-size: 20px; line-height: 1.4; margin-bottom: 12px; }
    h4 { font-size: 18px; line-height: 1.4; margin-bottom: 10px; }
    h5 { font-size: 16px; line-height: 1.5; margin-bottom: 8px; }
    h6 { font-size: 14px; line-height: 1.5; margin-bottom: 8px; }
    
    p {
        font-size: 16px;
        line-height: 1.6;
        margin-bottom: 12px;
    }
    
    /* Links - Touch Friendly */
    a {
        color: #667eea;
        text-decoration: none;
        padding: 4px 0;
        display: inline-block;
    }
    
    a:active {
        opacity: 0.7;
    }
    
    /* Spacing Utilities */
    .mt-mobile { margin-top: 16px; }
    .mb-mobile { margin-bottom: 16px; }
    .ml-mobile { margin-left: 16px; }
    .mr-mobile { margin-right: 16px; }
    .pt-mobile { padding-top: 16px; }
    .pb-mobile { padding-bottom: 16px; }
    .pl-mobile { padding-left: 16px; }
    .pr-mobile { padding-right: 16px; }
    
    /* Hide on Mobile */
    .hide-mobile, .desktop-only {
        display: none !important;
    }
    
    /* Show Only on Mobile */
    .show-mobile, .mobile-only {
        display: block !important;
    }
    
    /* Landscape Orientation Adjustments */
    @media (orientation: landscape) and (max-height: 500px) {
        nav, .navigation {
            position: relative;
            box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
        }
        
        nav ul, .navigation ul {
            flex-direction: row;
        }
        
        main, .main-content {
            padding-bottom: 20px;
        }
        
        .platform-selector {
            grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
        }
        
        .platform-card {
            min-height: 80px;
            padding: 12px;
        }
        
        .platform-card i {
            font-size: 28px;
        }
    }
    
    /* Scrollbar Styling for Mobile */
    ::-webkit-scrollbar {
        width: 6px;
        height: 6px;
    }
    
    ::-webkit-scrollbar-track {
        background: #f1f1f1;
    }
    
    ::-webkit-scrollbar-thumb {
        background: #888;
        border-radius: 3px;
    }
    
    ::-webkit-scrollbar-thumb:hover {
        background: #555;
    }
    
    /* Pull to Refresh Indicator */
    .pull-refresh {
        position: fixed;
        top: 0;
        left: 50%;
        transform: translateX(-50%);
        padding: 12px 24px;
        background: white;
        border-radius: 24px;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
        z-index: 3000;
        display: none;
    }
    
    .pull-refresh.show {
        display: block;
        animation: slideDown 0.3s ease-out;
    }
    
    @keyframes slideDown {
        from {
            opacity: 0;
            transform: translateX(-50%) translateY(-20px);
        }
        to {
            opacity: 1;
            transform: translateX(-50%) translateY(0);
        }
    }
    
    /* Safe Area Insets for Notched Devices */
    @supports (padding: max(0px)) {
        body {
            padding-left: max(0px, env(safe-area-inset-left));
            padding-right: max(0px, env(safe-area-inset-right));
        }
        
        header, .header {
            padding-top: max(16px, env(safe-area-inset-top));
        }
        
        nav, .navigation {
            padding-bottom: max(8px, env(safe-area-inset-bottom));
        }
    }
}

/* Small Mobile Devices (< 375px) */
@media only screen and (max-width: 374px) {
    html {
        font-size: 14px;
    }
    
    .platform-selector {
        grid-template-columns: repeat(2, 1fr);
    }
    
    button, .btn {
        font-size: 14px;
        padding: 10px 16px;
    }
    
    h1 { font-size: 24px; }
    h2 { font-size: 20px; }
    h3 { font-size: 18px; }
}

/* Large Mobile / Small Tablets (> 480px) */
@media only screen and (min-width: 480px) and (max-width: 768px) {
    .platform-selector {
        grid-template-columns: repeat(3, 1fr);
    }
    
    .container, .main-container {
        padding: 20px;
    }
    
    .card, .box, .panel {
        padding: 24px;
    }
}
