/* CSS Variables */
:root {
    --primary-color: #6366f1;
    --primary-hover: #4f46e5;
    --secondary-color: #64748b;
    --secondary-hover: #475569;
    --success-color: #10b981;
    --warning-color: #f59e0b;
    --danger-color: #ef4444;
    --background: #f8fafc;
    --surface: #ffffff;
    --surface-hover: #f1f5f9;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --border-color: #e2e8f0;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 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-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
}

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

/* Base Styles */
html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

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

/* App Container */
.app-container {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header */
header {
    text-align: center;
    padding: 2rem 1rem;
    background: linear-gradient(135deg, var(--primary-color), #8b5cf6);
    color: white;
}

header h1 {
    font-size: 2rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
}

header .subtitle {
    font-size: 1.1rem;
    opacity: 0.9;
}

/* Main Content */
main {
    flex: 1;
    max-width: 1200px;
    width: 100%;
    margin: 0 auto;
    padding: 2rem 1rem;
}

section {
    margin-bottom: 2rem;
}

section h2 {
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 1.5rem;
    text-align: center;
    color: var(--text-primary);
}

/* Upload Section */
.upload-section {
    max-width: 600px;
    margin: 0 auto;
}

.upload-area {
    border: 2px dashed var(--border-color);
    border-radius: var(--radius-lg);
    padding: 3rem 2rem;
    text-align: center;
    background: var(--surface);
    cursor: pointer;
    transition: all 0.3s ease;
}

.upload-area:hover,
.upload-area.dragover {
    border-color: var(--primary-color);
    background: #f5f3ff;
}

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

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

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

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

/* Controls Section */
.controls-section {
    background: var(--surface);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    box-shadow: var(--shadow-md);
}

.controls-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1.5rem;
    align-items: end;
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.control-group label {
    font-weight: 500;
    color: var(--text-primary);
    font-size: 0.9rem;
}

.control-group select {
    padding: 0.75rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 1rem;
    background: var(--surface);
    cursor: pointer;
    transition: border-color 0.2s;
}

.control-group select:focus {
    outline: none;
    border-color: var(--primary-color);
}

.control-group input[type="range"] {
    -webkit-appearance: none;
    width: 100%;
    height: 8px;
    border-radius: 4px;
    background: var(--border-color);
    outline: none;
}

.control-group input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--primary-color);
    cursor: pointer;
    transition: transform 0.2s;
}

.control-group input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.1);
}

.control-group input[type="range"]::-moz-range-thumb {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--primary-color);
    cursor: pointer;
    border: none;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    font-size: 1rem;
    font-weight: 500;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.2s ease;
}

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

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

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

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

.btn-download {
    background: var(--success-color);
    color: white;
    padding: 1rem 2rem;
    font-size: 1.1rem;
}

.btn-download:hover {
    background: #059669;
}

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

/* Presets */
.presets {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.75rem;
    margin-top: 1.5rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border-color);
}

.preset-label {
    font-weight: 500;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.preset-btn {
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.2s;
}

.preset-btn:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
}

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

/* Size Analysis */
.size-analysis {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 1.5rem;
    margin-bottom: 2rem;
    flex-wrap: wrap;
}

.size-card {
    background: var(--surface);
    border-radius: var(--radius-md);
    padding: 1.5rem 2rem;
    text-align: center;
    box-shadow: var(--shadow-sm);
    min-width: 150px;
}

.size-card h3 {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.size-card .size-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
}

.size-card .size-dimensions {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-top: 0.25rem;
}

.size-card .size-reduction {
    font-size: 1rem;
    font-weight: 600;
    color: var(--success-color);
    margin-top: 0.25rem;
}

.size-card.arrow {
    background: transparent;
    box-shadow: none;
    padding: 0;
    min-width: auto;
}

.size-card.arrow svg {
    width: 32px;
    height: 32px;
    color: var(--text-secondary);
}

/* View Toggle */
.view-toggle {
    display: flex;
    justify-content: center;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
}

.view-btn {
    padding: 0.6rem 1.2rem;
    font-size: 0.9rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s;
}

.view-btn:hover {
    background: var(--surface-hover);
}

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

/* Comparison Views */
.comparison-view {
    background: var(--surface);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    box-shadow: var(--shadow-md);
}

/* Side by Side View */
.side-by-side-view {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
}

.image-panel {
    text-align: center;
}

.image-panel h3 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 1rem;
    color: var(--text-primary);
}

.image-container {
    background: #f1f5f9;
    border-radius: var(--radius-md);
    padding: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 300px;
    overflow: hidden;
}

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

/* Slider View */
.slider-view {
    padding: 1.5rem;
}

.slider-container {
    position: relative;
    width: 100%;
    max-width: 800px;
    margin: 0 auto;
    overflow: hidden;
    border-radius: var(--radius-md);
    cursor: ew-resize;
    user-select: none;
}

.slider-img {
    display: block;
    width: 100%;
    max-height: 500px;
    object-fit: contain;
}

.slider-img.original {
    position: absolute;
    top: 0;
    left: 0;
    clip-path: inset(0 50% 0 0);
}

.slider-img.compressed {
    position: relative;
}

.slider-handle {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 50%;
    width: 4px;
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 10;
}

.slider-line {
    flex: 1;
    width: 3px;
    background: white;
    box-shadow: 0 0 4px rgba(0, 0, 0, 0.3);
}

.slider-circle {
    width: 40px;
    height: 40px;
    background: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-md);
}

.slider-circle svg {
    width: 20px;
    height: 20px;
    color: var(--text-secondary);
}

.slider-labels {
    position: absolute;
    top: 10px;
    left: 0;
    right: 0;
    display: flex;
    justify-content: space-between;
    padding: 0 1rem;
    pointer-events: none;
}

.slider-labels span {
    background: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 0.25rem 0.75rem;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    font-weight: 500;
}

/* Difference View */
.difference-view {
    text-align: center;
}

.difference-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
}

.difference-container canvas {
    max-width: 100%;
    max-height: 500px;
    border-radius: var(--radius-md);
    background: #1e293b;
}

.difference-info {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

/* Download Section */
.download-section {
    text-align: center;
    margin-top: 2rem;
}

/* Batch Section */
.batch-section {
    text-align: center;
}

.batch-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-top: 1.5rem;
}

.batch-card {
    background: var(--surface);
    border-radius: var(--radius-md);
    padding: 1rem;
    box-shadow: var(--shadow-sm);
    transition: transform 0.2s, box-shadow 0.2s;
}

.batch-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.batch-card img {
    width: 100%;
    height: 150px;
    object-fit: contain;
    background: #f1f5f9;
    border-radius: var(--radius-sm);
    margin-bottom: 0.75rem;
}

.batch-card h4 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.batch-card p {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.batch-card .reduction {
    color: var(--success-color);
    font-weight: 500;
}

.batch-card button {
    margin-top: 0.75rem;
    width: 100%;
    padding: 0.5rem;
    font-size: 0.85rem;
}

/* Footer */
footer {
    text-align: center;
    padding: 1.5rem;
    background: var(--text-primary);
    color: white;
}

footer p {
    font-size: 0.9rem;
}

footer a {
    color: #a5b4fc;
    text-decoration: none;
    font-weight: 500;
    transition: color 0.2s;
}

footer a:hover {
    color: white;
    text-decoration: underline;
}

/* Responsive Styles */
@media (max-width: 768px) {
    header h1 {
        font-size: 1.5rem;
    }

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

    main {
        padding: 1rem;
    }

    .upload-area {
        padding: 2rem 1rem;
    }

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

    .controls-grid {
        grid-template-columns: 1fr;
    }

    .control-group {
        flex-direction: column;
    }

    .control-group .btn {
        width: 100%;
    }

    .presets {
        justify-content: center;
    }

    .preset-label {
        width: 100%;
        text-align: center;
    }

    .size-analysis {
        flex-direction: column;
        gap: 1rem;
    }

    .size-card.arrow {
        transform: rotate(90deg);
    }

    .side-by-side-view {
        grid-template-columns: 1fr;
    }

    .image-container {
        min-height: 200px;
    }

    .view-toggle {
        gap: 0.25rem;
    }

    .view-btn {
        padding: 0.5rem 0.8rem;
        font-size: 0.8rem;
    }

    .batch-grid {
        grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    }
}

@media (max-width: 480px) {
    header {
        padding: 1.5rem 1rem;
    }

    header h1 {
        font-size: 1.25rem;
    }

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

    .btn {
        padding: 0.6rem 1rem;
        font-size: 0.9rem;
    }

    .btn-download {
        padding: 0.75rem 1.5rem;
        font-size: 1rem;
    }

    .preset-btn {
        padding: 0.4rem 0.8rem;
        font-size: 0.8rem;
    }

    .size-card {
        padding: 1rem;
        min-width: 120px;
    }

    .size-card .size-value {
        font-size: 1.25rem;
    }
}

/* Loading State */
.loading {
    position: relative;
    pointer-events: none;
}

.loading::after {
    content: '';
    position: absolute;
    inset: 0;
    background: rgba(255, 255, 255, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: inherit;
}

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

.fade-in {
    animation: fadeIn 0.3s ease-out;
}
