/* CSS Reset and Base Styles */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --primary-color: #6366f1;
    --primary-hover: #4f46e5;
    --secondary-color: #10b981;
    --secondary-hover: #059669;
    --danger-color: #ef4444;
    --danger-hover: #dc2626;
    --background: #f8fafc;
    --surface: #ffffff;
    --surface-hover: #f1f5f9;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    --border-color: #e2e8f0;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    --radius: 12px;
    --radius-sm: 8px;
    --transition: all 0.2s ease;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--background);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem 1rem;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header */
header {
    text-align: center;
    margin-bottom: 2rem;
}

header h1 {
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
}

header .subtitle {
    color: var(--text-secondary);
    font-size: 1.125rem;
}

/* Main Content */
main {
    flex: 1;
}

/* Upload Section */
.upload-section {
    margin-bottom: 2rem;
}

.drop-zone {
    background: var(--surface);
    border: 2px dashed var(--border-color);
    border-radius: var(--radius);
    padding: 3rem 2rem;
    text-align: center;
    cursor: pointer;
    transition: var(--transition);
}

.drop-zone:hover,
.drop-zone.drag-over {
    border-color: var(--primary-color);
    background: #f0f1ff;
}

.drop-zone.drag-over {
    transform: scale(1.01);
}

.drop-zone-content {
    pointer-events: none;
}

.upload-icon {
    width: 64px;
    height: 64px;
    color: var(--primary-color);
    margin-bottom: 1rem;
}

.drop-text {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.25rem;
}

.drop-subtext {
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
}

.supported-formats {
    font-size: 0.875rem;
    color: var(--text-muted);
}

/* Controls Section */
.controls-section {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 1.5rem;
    margin-bottom: 2rem;
    box-shadow: var(--shadow-sm);
    display: none;
}

.controls-section.visible {
    display: block;
}

.quality-control {
    margin-bottom: 1.5rem;
}

.quality-control label {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
    font-weight: 500;
}

.quality-value {
    color: var(--primary-color);
    font-weight: 700;
    font-size: 1.125rem;
}

.quality-slider {
    width: 100%;
    height: 8px;
    border-radius: 4px;
    background: var(--border-color);
    outline: none;
    -webkit-appearance: none;
    appearance: none;
}

.quality-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--primary-color);
    cursor: pointer;
    box-shadow: var(--shadow);
    transition: var(--transition);
}

.quality-slider::-webkit-slider-thumb:hover {
    transform: scale(1.1);
    background: var(--primary-hover);
}

.quality-slider::-moz-range-thumb {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--primary-color);
    cursor: pointer;
    border: none;
    box-shadow: var(--shadow);
}

.quality-labels {
    display: flex;
    justify-content: space-between;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 0.5rem;
}

.action-buttons {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    border-radius: var(--radius-sm);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    border: 2px solid transparent;
}

.btn svg {
    width: 20px;
    height: 20px;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
}

.btn-primary:hover:not(:disabled) {
    background: var(--primary-hover);
}

.btn-secondary {
    background: var(--secondary-color);
    color: white;
}

.btn-secondary:hover:not(:disabled) {
    background: var(--secondary-hover);
}

.btn-outline {
    background: transparent;
    color: var(--danger-color);
    border-color: var(--danger-color);
}

.btn-outline:hover:not(:disabled) {
    background: var(--danger-color);
    color: white;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Images Section */
.images-section {
    display: none;
}

.images-section.visible {
    display: block;
}

.images-list {
    display: grid;
    gap: 1rem;
}

/* Image Card */
.image-card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 1rem;
    box-shadow: var(--shadow-sm);
    display: grid;
    grid-template-columns: 80px 1fr auto;
    gap: 1rem;
    align-items: center;
}

.image-card .thumbnail {
    width: 80px;
    height: 80px;
    object-fit: cover;
    border-radius: var(--radius-sm);
    background: var(--background);
}

.image-card .info {
    min-width: 0;
}

.image-card .filename {
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.25rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.image-card .details {
    font-size: 0.875rem;
    color: var(--text-secondary);
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem 1rem;
}

.image-card .size-info {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.image-card .size-original {
    color: var(--text-muted);
}

.image-card .size-arrow {
    color: var(--text-muted);
}

.image-card .size-compressed {
    color: var(--secondary-color);
    font-weight: 600;
}

.image-card .savings {
    color: var(--secondary-color);
    font-weight: 600;
}

.image-card .actions {
    display: flex;
    gap: 0.5rem;
    flex-shrink: 0;
}

.image-card .btn-icon {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-sm);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
    background: var(--surface-hover);
    color: var(--text-secondary);
}

.image-card .btn-icon:hover:not(:disabled) {
    background: var(--primary-color);
    color: white;
}

.image-card .btn-icon.btn-download {
    background: var(--secondary-color);
    color: white;
}

.image-card .btn-icon.btn-download:hover:not(:disabled) {
    background: var(--secondary-hover);
}

.image-card .btn-icon.btn-delete:hover {
    background: var(--danger-color);
    color: white;
}

.image-card .btn-icon:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.image-card .btn-icon svg {
    width: 20px;
    height: 20px;
}

/* Progress Bar */
.image-card .progress-container {
    margin-top: 0.5rem;
}

.progress-bar {
    width: 100%;
    height: 4px;
    background: var(--border-color);
    border-radius: 2px;
    overflow: hidden;
}

.progress-bar .progress {
    height: 100%;
    background: var(--primary-color);
    border-radius: 2px;
    transition: width 0.3s ease;
}

.image-card .status {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
}

.image-card .status.completed {
    color: var(--secondary-color);
}

.image-card .status.error {
    color: var(--danger-color);
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 1rem;
}

.modal.visible {
    display: flex;
}

.modal-content {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 2rem;
    max-width: 900px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    position: relative;
}

.modal-close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    width: 40px;
    height: 40px;
    border: none;
    background: var(--surface-hover);
    border-radius: 50%;
    font-size: 1.5rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
    color: var(--text-secondary);
}

.modal-close:hover {
    background: var(--danger-color);
    color: white;
}

.modal-content h2 {
    margin-bottom: 1.5rem;
    font-size: 1.5rem;
}

/* Comparison */
.comparison-container {
    margin-bottom: 1.5rem;
}

.comparison-wrapper {
    position: relative;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    background: var(--background);
    border-radius: var(--radius-sm);
    padding: 1rem;
}

.comparison-image {
    position: relative;
}

.comparison-image img {
    width: 100%;
    height: auto;
    max-height: 400px;
    object-fit: contain;
    border-radius: var(--radius-sm);
    background: white;
}

.comparison-label {
    position: absolute;
    top: 0.5rem;
    left: 0.5rem;
    background: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 0.25rem 0.75rem;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
}

.comparison-slider-container {
    display: none;
}

.comparison-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 1rem;
}

.stat-item {
    background: var(--background);
    padding: 1rem;
    border-radius: var(--radius-sm);
    text-align: center;
}

.stat-item .stat-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.25rem;
}

.stat-item .stat-value {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-primary);
}

.stat-item .stat-value.highlight {
    color: var(--secondary-color);
}

/* Footer */
footer {
    text-align: center;
    padding: 2rem 1rem;
    margin-top: auto;
    border-top: 1px solid var(--border-color);
}

footer p {
    color: var(--text-secondary);
    font-size: 0.875rem;
}

footer a {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 500;
    transition: var(--transition);
}

footer a:hover {
    color: var(--primary-hover);
    text-decoration: underline;
}

/* Responsive Design */
@media (max-width: 768px) {
    .container {
        padding: 1rem;
    }

    header h1 {
        font-size: 1.75rem;
    }

    header .subtitle {
        font-size: 1rem;
    }

    .drop-zone {
        padding: 2rem 1rem;
    }

    .upload-icon {
        width: 48px;
        height: 48px;
    }

    .drop-text {
        font-size: 1rem;
    }

    .action-buttons {
        flex-direction: column;
    }

    .btn {
        width: 100%;
        justify-content: center;
    }

    .image-card {
        grid-template-columns: 60px 1fr;
        grid-template-rows: auto auto;
    }

    .image-card .thumbnail {
        width: 60px;
        height: 60px;
    }

    .image-card .actions {
        grid-column: 1 / -1;
        justify-content: flex-end;
    }

    .modal-content {
        padding: 1.5rem;
    }

    .comparison-wrapper {
        grid-template-columns: 1fr;
    }

    .comparison-image img {
        max-height: 250px;
    }
}

@media (max-width: 480px) {
    header h1 {
        font-size: 1.5rem;
    }

    .controls-section {
        padding: 1rem;
    }

    .image-card {
        padding: 0.75rem;
    }

    .image-card .filename {
        font-size: 0.875rem;
    }

    .image-card .details {
        font-size: 0.75rem;
    }
}

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.image-card {
    animation: fadeIn 0.3s ease;
}

/* Loading Spinner */
.spinner {
    width: 20px;
    height: 20px;
    border: 2px solid var(--border-color);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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