:root {
    --bg-dark: #f0f4f8;
    --bg-panel: #ffffff;
    --bg-card: #ffffff;
    --border: #e2e8f0;
    --primary: #3b82f6;
    --primary-light: #eff6ff;
    --primary-hover: #2563eb;
    --text-main: #1e293b;
    --text-muted: #64748b;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --shadow: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -1px rgba(0,0,0,0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -2px rgba(0,0,0,0.05);
    --font-main: 'Cairo', sans-serif;
    --radius: 12px;
    --radius-lg: 16px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    background: linear-gradient(135deg, var(--bg-dark) 0%, #e2e8f0 100%);
    color: var(--text-main);
    font-family: var(--font-main);
    height: 100vh;
    overflow: hidden;
}

.app-container {
    display: flex;
    height: 100%;
    justify-content: center; /* Center horizontally */
}

/* ============ MAIN CONTENT ============ */
.main-content {
    flex: 1;
    max-width: 1200px; /* Limit width for readability */
    height: 100vh;
    overflow-y: auto;
    padding: 2.5rem 3rem;
    background: transparent;
    margin: 0 auto;
}

.section-header {
    margin-bottom: 2rem;
    text-align: center;
}

.section-header h1 {
    font-size: 2.25rem;
    font-weight: 700;
    color: var(--text-main);
    margin-bottom: 0.5rem;
    letter-spacing: -0.5px;
}

.section-header p {
    color: var(--text-muted);
    font-size: 1.05rem;
}

/* ============ UPLOAD ZONE ============ */
.upload-zone {
    border: 2px dashed var(--border);
    border-radius: var(--radius-lg);
    padding: 3.5rem 2rem;
    text-align: center;
    background: linear-gradient(135deg, #ffffff 0%, #f8fafc 100%);
    cursor: pointer;
    transition: all 0.3s ease;
    margin-bottom: 2rem;
    box-shadow: var(--shadow-sm);
    position: relative;
    overflow: hidden;
}

.upload-zone::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, rgba(59,130,246,0.03) 0%, rgba(139,92,246,0.03) 100%);
    opacity: 0;
    transition: opacity 0.3s ease;
}

.upload-zone:hover {
    border-color: var(--primary);
    box-shadow: var(--shadow), 0 0 0 4px rgba(59, 130, 246, 0.1);
    transform: translateY(-2px);
}

.upload-zone:hover::before {
    opacity: 1;
}

.upload-content {
    position: relative;
    z-index: 1;
}

.upload-content i {
    font-size: 3.5rem;
    background: linear-gradient(135deg, var(--primary) 0%, #8b5cf6 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 1rem;
    display: block;
}

.upload-content h3 {
    font-size: 1.35rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: var(--text-main);
}

.upload-content p {
    color: var(--text-muted);
    font-size: 0.95rem;
}

.supported-formats {
    display: inline-block;
    margin-top: 0.75rem;
    padding: 0.35rem 0.75rem;
    font-size: 0.8rem;
    color: var(--text-muted);
    background: var(--bg-dark);
    border-radius: 20px;
}

/* ============ LOADING BAR ============ */
.loading-bar-container {
    width: 100%;
    margin-top: 1.5rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
}

.loading-info {
    display: flex;
    align-items: center;
    width: 100%;
    gap: 1rem;
}

.loading-bar {
    flex-grow: 1;
    height: 8px;
    background: #e2e8f0;
    border-radius: 4px;
    overflow: hidden;
}

/* ... existing progress bar styles ... */

.btn-danger {
    background-color: #ef4444;
    color: white;
}

.btn-danger:hover:not(:disabled) {
    background-color: #dc2626;
}

.btn-danger:disabled {
    background-color: #fca5a5;
    cursor: not-allowed;
}

/* ============ RESULTS HEADER ============ */
.results-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 3rem;
    margin-bottom: 1.5rem;
    padding-bottom: 1.25rem;
    border-bottom: 1px solid var(--border);
}

.results-header h2 {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text-main);
}

.results-actions {
    display: flex;
    gap: 0.75rem;
}

.btn {
    padding: 0.6rem 1.25rem;
    font-size: 0.9rem;
    font-weight: 500;
    border-radius: var(--radius);
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    border: none;
    transition: all 0.2s ease;
    font-family: inherit;
    text-decoration: none;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary) 0%, #2563eb 100%);
    color: #ffffff;
    box-shadow: 0 2px 8px rgba(59, 130, 246, 0.25);
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 16px rgba(59, 130, 246, 0.35);
}

.btn-secondary {
    background: #ffffff;
    color: var(--text-muted);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background: var(--bg-dark);
    border-color: #cbd5e1;
}

#clear-all-btn {
    background: #fef2f2;
    border: 1px solid #fecaca;
    color: #dc2626;
}

#clear-all-btn:hover {
    background: #fee2e2;
    border-color: #f87171;
}

/* ============ RESULTS GRID ============ */
.results-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1.5rem;
}

.result-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    position: relative;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-sm);
    transition: all 0.3s ease;
}

.result-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
    border-color: var(--primary);
}

.result-image-wrapper {
    height: 220px;
    background-color: #f8fafc;
    background-image: 
        linear-gradient(45deg, #e2e8f0 25%, transparent 25%), 
        linear-gradient(-45deg, #e2e8f0 25%, transparent 25%), 
        linear-gradient(45deg, transparent 75%, #e2e8f0 75%), 
        linear-gradient(-45deg, transparent 75%, #e2e8f0 75%);
    background-size: 16px 16px;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
}

.delete-btn {
    position: absolute;
    top: 12px;
    left: 12px; /* Changed from right to left for RTL */
    background: rgba(255, 255, 255, 0.95);
    border: none;
    color: #ef4444;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    opacity: 0;
    box-shadow: var(--shadow);
}

.result-card:hover .delete-btn {
    opacity: 1;
}

.delete-btn:hover {
    background: #ef4444;
    color: white;
    transform: scale(1.1);
}

.result-image-wrapper img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.result-footer {
    padding: 1rem 1.25rem;
    background: #ffffff;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-top: 1px solid var(--border);
}

.file-name {
    font-size: 0.875rem;
    color: var(--text-main);
    font-weight: 500;
    max-width: 150px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ============ TOAST ============ */
.toast {
    position: fixed;
    bottom: 24px;
    left: 24px; /* Changed from right to left */
    padding: 1rem 1.5rem;
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    transform: translateY(100px);
    opacity: 0;
    transition: all 0.4s cubic-bezier(0.16, 1, 0.3, 1);
    z-index: 1000;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.toast.show {
    transform: translateY(0);
    opacity: 1;
}

/* ============ SPINNER ============ */
.spinner {
    width: 20px;
    height: 20px;
    border: 2px solid rgba(255,255,255,0.3);
    border-radius: 50%;
    border-top-color: #fff;
    animation: spin 0.8s linear infinite;
    display: inline-block;
}

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

/* ============ SCROLLBAR ============ */
.main-content::-webkit-scrollbar {
    width: 8px;
}

.main-content::-webkit-scrollbar-track {
    background: transparent;
}

.main-content::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 4px;
}

.main-content::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

/* ============ MOBILE RESPONSIVE ============ */
@media screen and (max-width: 768px) {
    body {
        overflow: auto;
        height: auto;
        min-height: 100vh;
    }
    
    .main-content {
        padding: 1.5rem 1rem;
        height: auto;
        min-height: 100vh;
    }
    
    .section-header {
        margin-bottom: 1.5rem;
        padding-top: 40px; /* Space for user button */
    }
    
    .section-header h1 {
        font-size: 1.75rem;
    }
    
    .section-header p {
        font-size: 0.95rem;
    }
    
    /* User button positioning for mobile */
    #user-button-container {
        position: fixed !important;
        top: 10px !important;
        left: 10px !important;
        z-index: 200;
    }
    
    /* Upload Zone */
    .upload-zone {
        padding: 2rem 1.25rem;
        margin-bottom: 1.5rem;
    }
    
    .upload-content i {
        font-size: 2.5rem;
    }
    
    .upload-content h3 {
        font-size: 1.15rem;
    }
    
    .upload-content p {
        font-size: 0.85rem;
    }
    
    .supported-formats {
        font-size: 0.7rem;
        padding: 0.25rem 0.5rem;
    }
    
    /* Results Header */
    .results-header {
        flex-direction: column;
        gap: 1rem;
        align-items: stretch;
        margin-top: 2rem;
        padding-bottom: 1rem;
    }
    
    .results-header h2 {
        font-size: 1.25rem;
        text-align: center;
    }
    
    .results-actions {
        flex-direction: column;
        gap: 0.5rem;
    }
    
    .results-actions .btn {
        justify-content: center;
        width: 100%;
    }
    
    /* Results Grid */
    .results-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
    
    .result-image-wrapper {
        height: 200px;
    }
    
    .result-footer {
        padding: 0.75rem 1rem;
        flex-direction: column;
        gap: 0.75rem;
        align-items: stretch;
    }
    
    .file-name {
        max-width: 100%;
        text-align: center;
    }
    
    .result-footer .btn {
        justify-content: center;
        width: 100%;
    }
    
    /* Delete button always visible on mobile */
    .delete-btn {
        opacity: 1;
    }
    
    /* Toast */
    .toast {
        left: 12px;
        right: 12px;
        bottom: 12px;
        font-size: 0.9rem;
        padding: 0.75rem 1rem;
    }
    
    /* Loading bar */
    .loading-bar-container {
        margin: 1.5rem 0;
        padding: 1rem;
    }
    
    #progress-text {
        font-size: 0.85rem;
        text-align: center;
    }
    
    /* Iframe warning banner */
    #iframe-warning {
        font-size: 12px !important;
        padding: 8px 12px !important;
    }
}

/* Extra small devices */
@media screen and (max-width: 400px) {
    .main-content {
        padding: 1rem 0.75rem;
    }
    
    .section-header h1 {
        font-size: 1.5rem;
    }
    
    .upload-zone {
        padding: 1.5rem 1rem;
    }
    
    .upload-content i {
        font-size: 2rem;
    }
    
    .btn {
        padding: 0.5rem 1rem;
        font-size: 0.85rem;
    }
}
