/* ========================================
   CSS Variables & Reset
======================================== */
:root {
    --primary: #6366f1;
    --primary-hover: #4f46e5;
    --primary-light: rgba(99, 102, 241, 0.1);
    --success: #10b981;
    --success-hover: #059669;
    --danger: #ef4444;
    --warning: #f59e0b;
    
    --bg-main: #0f172a;
    --bg-card: #1e293b;
    --bg-card-hover: #334155;
    --bg-input: #0f172a;
    
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    
    --border-color: #334155;
    --border-radius: 12px;
    --border-radius-sm: 8px;
    
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.3), 0 2px 4px -2px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.3), 0 4px 6px -4px rgba(0, 0, 0, 0.3);
    
    --transition: all 0.2s ease;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg-main);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
}

/* ========================================
   Layout
======================================== */
.app-container {
    max-width: 1000px;
    margin: 0 auto;
    padding: 20px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ========================================
   Header
======================================== */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 0;
    margin-bottom: 30px;
    border-bottom: 1px solid var(--border-color);
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
}

.logo svg {
    color: var(--primary);
}

.header-badge {
    background: linear-gradient(135deg, var(--success), #34d399);
    color: white;
    padding: 6px 16px;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 500;
}

/* ========================================
   Main Content
======================================== */
.main-content {
    flex: 1;
}

/* ========================================
   Upload Section
======================================== */
.upload-section {
    margin-bottom: 30px;
}

.upload-area {
    background: var(--bg-card);
    border: 2px dashed var(--border-color);
    border-radius: var(--border-radius);
    padding: 60px 40px;
    text-align: center;
    cursor: pointer;
    transition: var(--transition);
}

.upload-area:hover,
.upload-area.dragover {
    border-color: var(--primary);
    background: var(--primary-light);
}

.upload-icon {
    margin-bottom: 20px;
    color: var(--primary);
}

.upload-area h2 {
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 8px;
}

.upload-area p {
    color: var(--text-secondary);
}

.upload-hint {
    margin-top: 16px;
    font-size: 0.875rem;
    color: var(--text-muted);
}

/* ========================================
   Settings Section
======================================== */
.settings-section {
    background: var(--bg-card);
    border-radius: var(--border-radius);
    padding: 24px;
    margin-bottom: 30px;
    display: none;
}

.settings-section.visible {
    display: block;
}

.settings-section h3 {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 20px;
    color: var(--text-primary);
}

.settings-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 24px;
}

.setting-item {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.setting-item label {
    font-weight: 500;
    color: var(--text-primary);
}

.setting-hint {
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* Slider */
.slider-container {
    display: flex;
    align-items: center;
    gap: 12px;
}

input[type="range"] {
    flex: 1;
    height: 6px;
    background: var(--bg-input);
    border-radius: 3px;
    -webkit-appearance: none;
    appearance: none;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 18px;
    height: 18px;
    background: var(--primary);
    border-radius: 50%;
    cursor: pointer;
    transition: var(--transition);
}

input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.1);
    background: var(--primary-hover);
}

.slider-value {
    font-weight: 600;
    color: var(--primary);
    min-width: 45px;
    text-align: right;
}

/* Input & Select */
input[type="number"],
select {
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-sm);
    padding: 10px 14px;
    color: var(--text-primary);
    font-size: 0.95rem;
    transition: var(--transition);
}

input[type="number"]:focus,
select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

select {
    cursor: pointer;
}

/* ========================================
   Images Section
======================================== */
.images-section,
.results-section {
    background: var(--bg-card);
    border-radius: var(--border-radius);
    padding: 24px;
    margin-bottom: 30px;
    display: none;
}

.images-section.visible,
.results-section.visible {
    display: block;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 12px;
}

.section-header h3 {
    font-size: 1.1rem;
    font-weight: 600;
}

.section-actions {
    display: flex;
    gap: 12px;
}

/* ========================================
   Buttons
======================================== */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    border: none;
    border-radius: var(--border-radius-sm);
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
}

.btn-primary {
    background: var(--primary);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
}

.btn-secondary {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background: var(--bg-card-hover);
    color: var(--text-primary);
}

.btn-success {
    background: var(--success);
    color: white;
}

.btn-success:hover {
    background: var(--success-hover);
    transform: translateY(-1px);
}

.btn-large {
    padding: 14px 28px;
    font-size: 1rem;
    width: 100%;
    justify-content: center;
    margin-top: 20px;
}

.btn-small {
    padding: 6px 12px;
    font-size: 0.85rem;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* ========================================
   Image List
======================================== */
.images-list,
.results-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.image-item,
.result-item {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 16px;
    background: var(--bg-input);
    border-radius: var(--border-radius-sm);
    transition: var(--transition);
}

.image-item:hover,
.result-item:hover {
    background: var(--bg-card-hover);
}

.image-thumb {
    width: 60px;
    height: 60px;
    border-radius: 8px;
    object-fit: cover;
    background: var(--bg-card);
}

.image-info {
    flex: 1;
    min-width: 0;
}

.image-name {
    font-weight: 500;
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.image-meta {
    display: flex;
    gap: 16px;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.image-actions {
    display: flex;
    gap: 8px;
}

.btn-icon {
    width: 36px;
    height: 36px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    cursor: pointer;
    transition: var(--transition);
}

.btn-icon:hover {
    background: var(--bg-card-hover);
    color: var(--text-primary);
}

.btn-icon.danger:hover {
    background: rgba(239, 68, 68, 0.1);
    border-color: var(--danger);
    color: var(--danger);
}

/* ========================================
   Results Section
======================================== */
.total-savings {
    background: linear-gradient(135deg, var(--success), #34d399);
    color: white;
    padding: 8px 16px;
    border-radius: 20px;
    font-weight: 600;
    font-size: 0.9rem;
}

.result-item {
    position: relative;
}

.compression-stats {
    display: flex;
    align-items: center;
    gap: 12px;
}

.size-change {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 4px;
}

.original-size {
    font-size: 0.85rem;
    color: var(--text-muted);
    text-decoration: line-through;
}

.new-size {
    font-weight: 600;
    color: var(--success);
}

.savings-badge {
    background: rgba(16, 185, 129, 0.15);
    color: var(--success);
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 0.8rem;
    font-weight: 600;
}

/* ========================================
   Footer
======================================== */
.footer {
    text-align: center;
    padding: 20px;
    margin-top: auto;
    color: var(--text-muted);
    font-size: 0.9rem;
    border-top: 1px solid var(--border-color);
}

/* ========================================
   Loading Overlay
======================================== */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 23, 42, 0.9);
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 20px;
    z-index: 1000;
}

.loading-overlay.visible {
    display: flex;
}

.loading-spinner {
    width: 50px;
    height: 50px;
    border: 3px solid var(--border-color);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loading-overlay p {
    color: var(--text-secondary);
    font-size: 1.1rem;
}

/* ========================================
   Responsive
======================================== */
@media (max-width: 768px) {
    .app-container {
        padding: 15px;
    }
    
    .header {
        flex-direction: column;
        gap: 12px;
        text-align: center;
    }
    
    .upload-area {
        padding: 40px 20px;
    }
    
    .upload-area h2 {
        font-size: 1.25rem;
    }
    
    .settings-grid {
        grid-template-columns: 1fr;
    }
    
    .section-header {
        flex-direction: column;
        align-items: flex-start;
    }
    
    .section-actions {
        width: 100%;
    }
    
    .section-actions .btn {
        flex: 1;
        justify-content: center;
    }
    
    .image-item,
    .result-item {
        flex-wrap: wrap;
    }
    
    .image-info {
        flex: 1 1 calc(100% - 76px);
    }
    
    .image-actions,
    .compression-stats {
        width: 100%;
        justify-content: flex-end;
    }
}

@media (max-width: 480px) {
    .image-meta {
        flex-direction: column;
        gap: 4px;
    }
    
    .compression-stats {
        flex-direction: column;
        align-items: flex-end;
    }
}
