/* ============================================
   ROOT VARIABLES & RESET
============================================ */
:root {
    --bg-primary: #0a0a0f;
    --bg-secondary: #12121a;
    --bg-glass: rgba(255, 255, 255, 0.05);
    --border-glass: rgba(255, 255, 255, 0.1);
    --text-primary: #ffffff;
    --text-secondary: #a1a1aa;
    --text-muted: #71717a;
    --accent-primary: #8b5cf6;
    --accent-secondary: #06b6d4;
    --accent-gradient: linear-gradient(135deg, #8b5cf6 0%, #06b6d4 100%);
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
    --shadow-glow: 0 0 40px rgba(139, 92, 246, 0.15);
    --transition-fast: 0.15s ease;
    --transition-normal: 0.3s ease;
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;
}

*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    scroll-behavior: smooth;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    min-height: 100dvh;
    line-height: 1.5;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

/* Background Orbs */
body::before {
    content: '';
    position: fixed;
    width: 300px;
    height: 300px;
    border-radius: 50%;
    filter: blur(80px);
    opacity: 0.3;
    z-index: -1;
    pointer-events: none;
    background: var(--accent-primary);
    top: -100px;
    right: -100px;
}

/* ============================================
   NAVBAR
============================================ */
.navbar {
    position: sticky;
    top: 0;
    z-index: 100;
    background: rgba(10, 10, 15, 0.9);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border-glass);
    padding: 0 1rem;
}

.navbar-inner {
    max-width: 1400px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 50px;
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    text-decoration: none;
}

.logo-icon {
    width: 32px;
    height: 32px;
    background: var(--accent-gradient);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.9rem;
    color: white;
}

.logo-text {
    font-weight: 800;
    font-size: 1rem;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.navbar-tagline {
    font-size: 0.7rem;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 0.3rem;
}

.navbar-tagline i {
    color: var(--success);
}

/* ============================================
   MAIN CONTAINER - MOBILE FIRST
============================================ */
.main-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0.5rem;
}

.app-grid {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

/* ============================================
   GLASS CARD
============================================ */
.glass-card {
    background: var(--bg-glass);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

/* ============================================
   PREVIEW PANEL - FIXED HEIGHT ON MOBILE
============================================ */
.preview-panel {
    display: flex;
    flex-direction: column;
    height: 45vh;
    min-height: 200px;
    max-height: 400px;
}

.empty-state {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
    text-align: center;
}

.empty-state.hidden {
    display: none;
}

.empty-icon {
    width: 60px;
    height: 60px;
    background: var(--bg-glass);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 0.75rem;
}

.empty-icon i {
    font-size: 1.5rem;
    color: var(--text-muted);
}

.empty-state p {
    color: var(--text-muted);
    font-size: 0.85rem;
}

.preview-content {
    display: none;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}

.preview-content.visible {
    display: flex;
}

/* Stats Header - Compact */
.stats-header {
    padding: 0.5rem 0.75rem;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-glass);
    flex-shrink: 0;
}

.stats-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.4rem;
}

.stats-left h3 {
    display: none;
}

.size-display {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.orig-size {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.size-arrow {
    color: var(--text-muted);
    font-size: 0.6rem;
}

.comp-size {
    font-size: 1rem;
    font-weight: 700;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.savings-badge {
    padding: 0.2rem 0.5rem;
    border-radius: 9999px;
    font-size: 0.65rem;
    font-weight: 700;
}

.savings-badge.positive {
    background: rgba(16, 185, 129, 0.2);
    color: var(--success);
}

.savings-badge.negative {
    background: rgba(239, 68, 68, 0.2);
    color: var(--danger);
}

.progress-bar-container {
    width: 100%;
    height: 4px;
    background: var(--bg-glass);
    border-radius: 2px;
    overflow: hidden;
}

.progress-bar {
    height: 100%;
    background: var(--accent-gradient);
    border-radius: 2px;
    transition: width 0.4s ease;
}

.progress-bar.warning {
    background: linear-gradient(135deg, var(--danger) 0%, var(--warning) 100%);
}

/* Preview Area - Fill remaining space */
.preview-area {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem;
    background: var(--bg-secondary);
    position: relative;
    overflow: hidden;
    min-height: 0;
}

.preview-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    max-width: 100%;
    max-height: 100%;
}

.preview-image {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border-radius: var(--radius-sm);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

/* Crop Canvas */
.crop-canvas {
    position: absolute;
    top: 0;
    left: 0;
    border-radius: var(--radius-sm);
    display: none;
    z-index: 10;
    touch-action: none;
}

.crop-canvas.visible {
    display: block;
}

/* Loading Overlay */
.loading-overlay {
    position: absolute;
    inset: 0;
    background: rgba(10, 10, 15, 0.85);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    z-index: 20;
}

.loading-overlay.visible {
    opacity: 1;
    pointer-events: all;
}

.spinner {
    width: 36px;
    height: 36px;
    border: 3px solid var(--bg-glass);
    border-top-color: var(--accent-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* ============================================
   CONTROLS PANEL
============================================ */
.controls-panel {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

/* Upload Zone - Compact */
.upload-zone {
    padding: 1rem;
    text-align: center;
    cursor: pointer;
    position: relative;
    touch-action: manipulation;
}

.upload-zone input[type="file"] {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
    z-index: 10;
}

.upload-content {
    position: relative;
    z-index: 5;
}

.upload-icon {
    width: 50px;
    height: 50px;
    margin: 0 auto 0.5rem;
    background: var(--bg-glass);
    border: 2px dashed var(--border-glass);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.upload-icon i {
    font-size: 1.25rem;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.upload-title {
    font-weight: 600;
    font-size: 0.9rem;
    margin-bottom: 0.15rem;
}

.upload-subtitle {
    font-size: 0.7rem;
    color: var(--text-muted);
}

.file-info {
    display: none;
}

.file-info.visible {
    display: block;
}

.upload-prompt.hidden {
    display: none;
}

.file-info-icon {
    width: 40px;
    height: 40px;
    margin: 0 auto 0.4rem;
    background: linear-gradient(135deg, var(--success) 0%, #0d9488 100%);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    color: white;
}

.file-name {
    font-family: monospace;
    font-size: 0.75rem;
    color: var(--text-primary);
    padding: 0.3rem 0.6rem;
    background: var(--bg-glass);
    border-radius: var(--radius-sm);
    display: inline-block;
}

.file-label {
    font-size: 0.6rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
    text-transform: uppercase;
}

/* Settings Panel */
.settings-panel {
    padding: 0.75rem;
    opacity: 0.5;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.settings-panel.active {
    opacity: 1;
    pointer-events: all;
}

.settings-header {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    margin-bottom: 0.75rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border-glass);
}

.settings-header i {
    color: var(--accent-primary);
    font-size: 0.85rem;
}

.settings-header h2 {
    font-size: 0.85rem;
    font-weight: 600;
}

/* Section Title */
.section-title {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.65rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.section-title i {
    color: var(--accent-secondary);
    font-size: 0.75rem;
}

/* Setting Group */
.setting-group {
    margin-bottom: 0.875rem;
}

.setting-label {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.35rem;
}

.setting-label span {
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.setting-value {
    font-weight: 700;
    font-size: 0.75rem;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* Range Slider */
.quality-slider {
    width: 100%;
    height: 8px;
    border-radius: 4px;
    background: var(--bg-secondary);
    outline: none;
    -webkit-appearance: none;
    appearance: none;
    cursor: pointer;
    touch-action: manipulation;
}

.quality-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 26px;
    height: 26px;
    background: var(--accent-gradient);
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 0 10px rgba(139, 92, 246, 0.5);
}

.quality-slider::-moz-range-thumb {
    width: 26px;
    height: 26px;
    background: var(--accent-gradient);
    border: none;
    border-radius: 50%;
    cursor: pointer;
}

.target-helper {
    display: flex;
    justify-content: space-between;
    margin-top: 0.25rem;
    font-size: 0.6rem;
    color: var(--text-muted);
}

/* Target Size Display */
.target-size-display {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem;
    background: var(--bg-secondary);
    border-radius: var(--radius-sm);
    margin-top: 0.4rem;
    border: 1px solid var(--border-glass);
    font-size: 0.85rem;
}

/* Quick Size Buttons */
.quick-sizes {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.35rem;
}

.size-btn {
    padding: 0.6rem 0.3rem;
    background: var(--bg-glass);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 0.7rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    touch-action: manipulation;
    min-height: 44px;
}

.size-btn:active {
    background: var(--accent-primary);
    border-color: var(--accent-primary);
    color: white;
}

/* Control Buttons */
.control-buttons {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.4rem;
}

.control-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    padding: 0.6rem 0.4rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.7rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    touch-action: manipulation;
    min-height: 44px;
}

.control-btn:active {
    background: var(--bg-glass);
    border-color: var(--accent-primary);
}

.control-btn i {
    font-size: 0.85rem;
    color: var(--accent-primary);
}

.control-btn.active {
    background: var(--accent-primary);
    border-color: var(--accent-primary);
}

.control-btn.active i,
.control-btn.active span {
    color: white;
}

/* Enhance Buttons */
.enhance-buttons {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.35rem;
    margin-top: 0.5rem;
}

.enhance-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.25rem;
    padding: 0.5rem;
    background: var(--bg-glass);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 0.65rem;
    font-weight: 500;
    cursor: pointer;
    touch-action: manipulation;
    min-height: 40px;
}

.enhance-btn:active {
    border-color: var(--accent-secondary);
    color: var(--text-primary);
}

.enhance-btn.auto {
    background: linear-gradient(135deg, rgba(139, 92, 246, 0.15), rgba(6, 182, 212, 0.15));
    border-color: var(--accent-primary);
}

/* Crop Controls */
.crop-controls {
    display: none;
    grid-template-columns: 1fr 1fr;
    gap: 0.4rem;
    margin-top: 0.5rem;
}

.crop-controls.visible {
    display: grid;
}

.crop-btn {
    padding: 0.6rem;
    border-radius: var(--radius-sm);
    font-size: 0.7rem;
    font-weight: 600;
    cursor: pointer;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.25rem;
    touch-action: manipulation;
    min-height: 44px;
}

.crop-btn.apply {
    background: var(--success);
    color: white;
}

.crop-btn.cancel {
    background: var(--bg-secondary);
    color: var(--text-secondary);
    border: 1px solid var(--border-glass);
}

.crop-hint {
    font-size: 0.65rem;
    color: var(--accent-primary);
    margin-top: 0.35rem;
    text-align: center;
    display: none;
}

.crop-hint.visible {
    display: block;
}

/* Action Buttons */
.action-buttons {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.4rem;
    padding-top: 0.6rem;
    border-top: 1px solid var(--border-glass);
    margin-top: 0.4rem;
}

.btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.75rem 0.5rem;
    border: none;
    border-radius: var(--radius-md);
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    touch-action: manipulation;
    min-height: 48px;
}

.btn-primary {
    background: var(--accent-gradient);
    color: white;
    box-shadow: 0 4px 12px rgba(139, 92, 246, 0.3);
}

.btn-primary:active {
    transform: scale(0.98);
}

.btn-secondary {
    background: var(--bg-secondary);
    color: var(--text-primary);
    border: 1px solid var(--border-glass);
}

.btn-secondary:active {
    background: var(--bg-glass);
}

/* ============================================
   FOOTER
============================================ */
.footer {
    text-align: center;
    padding: 0.75rem;
    border-top: 1px solid var(--border-glass);
    background: rgba(10, 10, 15, 0.5);
    margin-top: 0.5rem;
}

.footer-text {
    font-size: 0.7rem;
    color: var(--text-muted);
}

.footer-text strong {
    color: var(--text-secondary);
    font-weight: 600;
}

/* ============================================
   DESKTOP LAYOUT
============================================ */
@media (min-width: 768px) {
    .main-container {
        padding: 1rem;
    }

    .app-grid {
        display: grid;
        grid-template-columns: 360px 1fr;
        gap: 1rem;
    }

    .preview-panel {
        height: auto;
        min-height: 500px;
        max-height: none;
    }

    .preview-image {
        max-height: calc(100vh - 250px);
    }

    .navbar-inner {
        height: 56px;
    }

    .logo-icon {
        width: 36px;
        height: 36px;
        font-size: 1rem;
    }

    .logo-text {
        font-size: 1.1rem;
    }

    .upload-zone {
        padding: 1.5rem;
    }

    .settings-panel {
        padding: 1rem;
    }

    .action-buttons {
        grid-template-columns: 1fr;
    }
}

/* Safe areas */
@supports (padding: max(0px)) {
    .navbar {
        padding-left: max(1rem, env(safe-area-inset-left));
        padding-right: max(1rem, env(safe-area-inset-right));
    }

    .main-container {
        padding-left: max(0.5rem, env(safe-area-inset-left));
        padding-right: max(0.5rem, env(safe-area-inset-right));
    }

    .footer {
        padding-bottom: max(0.75rem, env(safe-area-inset-bottom));
    }
}