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

:root {
    --bg: #0f172a;
    --surface: #1e293b;
    --surface-light: #273549;
    --accent: #60a5fa;
    --accent-bold: #3b82f6;
    --accent-hover: #2563eb;
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-dim: #64748b;
    --border: rgba(255, 255, 255, 0.08);
    --border-light: rgba(255, 255, 255, 0.12);
    --radius: 10px;
    --radius-sm: 6px;
    --radius-lg: 14px;
    --shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
    --gradient: linear-gradient(135deg, #1e3a5f 0%, #2563eb 50%, #7c3aed 100%);
    --green: #34d399;
    --red: #f87171;
    --yellow: #fbbf24;
}

html {
    font-size: 14px;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg);
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ===== Header ===== */
.header {
    background: var(--gradient);
    padding: 1px;
    position: relative;
}

.header::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: var(--border);
}

.header-inner {
    background: linear-gradient(135deg, rgba(15, 23, 42, 0.85) 0%, rgba(15, 23, 42, 0.7) 100%);
    padding: 1.25rem 2rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.header-title {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.header-icon {
    width: 28px;
    height: 28px;
    color: var(--accent);
}

.header-title h1 {
    font-size: 1.35rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.header-accent {
    color: var(--accent);
    font-weight: 500;
}

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

/* ===== Main Content ===== */
.main-content {
    max-width: 1600px;
    margin: 0 auto;
    padding: 1.5rem;
    min-height: calc(100vh - 80px);
}

/* ===== Drop Zone ===== */
.drop-zone {
    border: 2px dashed var(--text-dim);
    border-radius: var(--radius-lg);
    padding: 4rem 2rem;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    background: rgba(30, 41, 59, 0.3);
    max-width: 700px;
    margin: 6vh auto 0;
    position: relative;
}

.drop-zone:hover,
.drop-zone.drag-over {
    border-color: var(--accent);
    background: rgba(96, 165, 250, 0.06);
    transform: translateY(-2px);
}

.drop-zone.drag-over {
    box-shadow: 0 0 40px rgba(96, 165, 250, 0.15);
}

.drop-icon {
    width: 80px;
    height: 80px;
    margin: 0 auto 1.5rem;
    color: var(--text-dim);
    transition: color 0.3s ease;
}

.drop-zone:hover .drop-icon {
    color: var(--accent);
}

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

.drop-subtitle {
    color: var(--text-secondary);
    margin-bottom: 0.75rem;
    font-size: 0.95rem;
}

.drop-formats {
    color: var(--text-dim);
    font-size: 0.8rem;
    margin-bottom: 1.5rem;
}

.browse-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.65rem 1.5rem;
    background: var(--accent-bold);
    color: white;
    border: none;
    border-radius: var(--radius);
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.browse-btn:hover {
    background: var(--accent-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 16px rgba(59, 130, 246, 0.3);
}

/* ===== Workspace ===== */
.workspace {
    display: grid;
    grid-template-columns: 340px 1fr;
    gap: 1.5rem;
    height: calc(100vh - 130px);
    animation: fadeIn 0.35s ease;
}

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

.hidden {
    display: none !important;
}

/* ===== Settings Panel ===== */
.settings-panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.settings-panel::-webkit-scrollbar {
    width: 5px;
}

.settings-panel::-webkit-scrollbar-track {
    background: transparent;
}

.settings-panel::-webkit-scrollbar-thumb {
    background: var(--text-dim);
    border-radius: 4px;
}

.panel-section {
    padding: 1rem 0;
    border-bottom: 1px solid var(--border);
}

.panel-section:first-child {
    padding-top: 0.25rem;
}

.panel-section:last-child {
    border-bottom: none;
}

.panel-heading {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.85rem;
}

.panel-heading svg {
    color: var(--accent);
}

/* ===== Resize Mode Tabs ===== */
.resize-mode-tabs {
    display: flex;
    background: rgba(0, 0, 0, 0.25);
    border-radius: var(--radius-sm);
    padding: 3px;
    margin-bottom: 1rem;
    gap: 2px;
}

.tab-btn {
    flex: 1;
    padding: 0.45rem 0.5rem;
    border: none;
    border-radius: 4px;
    background: transparent;
    color: var(--text-dim);
    font-family: inherit;
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.tab-btn:hover {
    color: var(--text-secondary);
}

.tab-btn.active {
    background: var(--accent-bold);
    color: white;
    box-shadow: 0 2px 8px rgba(59, 130, 246, 0.25);
}

.resize-mode {
    display: none;
}

.resize-mode.active {
    display: block;
}

/* ===== Dimension Inputs ===== */
.dimension-row {
    display: flex;
    align-items: flex-end;
    gap: 0.5rem;
}

.dimension-field {
    flex: 1;
}

.dimension-field label,
.percentage-field label {
    display: block;
    font-size: 0.75rem;
    color: var(--text-dim);
    margin-bottom: 0.35rem;
    font-weight: 500;
}

.input-with-unit {
    display: flex;
    align-items: center;
    background: rgba(0, 0, 0, 0.25);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    overflow: hidden;
    transition: border-color 0.2s ease;
}

.input-with-unit:focus-within {
    border-color: var(--accent);
}

.input-with-unit input {
    flex: 1;
    width: 100%;
    background: transparent;
    border: none;
    padding: 0.5rem 0.6rem;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.9rem;
    outline: none;
    min-width: 0;
}

.input-with-unit input::placeholder {
    color: var(--text-dim);
}

.input-with-unit input::-webkit-inner-spin-button,
.input-with-unit input::-webkit-outer-spin-button {
    -webkit-appearance: none;
}

.input-with-unit .unit {
    padding: 0.5rem 0.5rem;
    color: var(--text-dim);
    font-size: 0.8rem;
    font-weight: 500;
    background: rgba(0, 0, 0, 0.15);
    border-left: 1px solid var(--border);
}

.lock-btn {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: rgba(0, 0, 0, 0.2);
    color: var(--text-dim);
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0;
    margin-bottom: 1px;
}

.lock-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.lock-btn.active {
    background: rgba(96, 165, 250, 0.1);
    border-color: var(--accent);
    color: var(--accent);
}

.lock-btn .lock-icon.unlocked {
    display: none;
}

.lock-btn .lock-icon.locked {
    display: block;
}

.lock-btn:not(.active) .lock-icon.unlocked {
    display: block;
}

.lock-btn:not(.active) .lock-icon.locked {
    display: none;
}

/* ===== Percentage Mode ===== */
.percentage-field {
    max-width: 180px;
    margin-bottom: 0.75rem;
}

.percentage-presets {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
}

.preset-chip {
    padding: 0.3rem 0.7rem;
    border: 1px solid var(--border);
    border-radius: 20px;
    background: transparent;
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 0.78rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.preset-chip:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: rgba(96, 165, 250, 0.08);
}

.preset-chip.active {
    background: var(--accent-bold);
    border-color: var(--accent-bold);
    color: white;
}

/* ===== Preset Grid ===== */
.preset-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.4rem;
    max-height: 280px;
    overflow-y: auto;
    padding-right: 4px;
}

.preset-grid::-webkit-scrollbar {
    width: 4px;
}

.preset-grid::-webkit-scrollbar-thumb {
    background: var(--text-dim);
    border-radius: 4px;
}

.preset-card {
    display: flex;
    flex-direction: column;
    padding: 0.55rem 0.65rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: rgba(0, 0, 0, 0.15);
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: left;
}

.preset-card:hover {
    border-color: var(--accent);
    background: rgba(96, 165, 250, 0.06);
}

.preset-card.active {
    border-color: var(--accent-bold);
    background: rgba(96, 165, 250, 0.12);
}

.preset-name {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-primary);
}

.preset-size {
    font-size: 0.7rem;
    color: var(--text-dim);
    margin-top: 0.1rem;
}

/* ===== Format Options ===== */
.format-options {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.format-radio {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.55rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.2s ease;
}

.format-radio:hover {
    border-color: var(--border-light);
    background: rgba(255, 255, 255, 0.02);
}

.format-radio:has(input:checked) {
    border-color: var(--accent);
    background: rgba(96, 165, 250, 0.06);
}

.format-radio input[type="radio"] {
    appearance: none;
    width: 16px;
    height: 16px;
    border: 2px solid var(--text-dim);
    border-radius: 50%;
    position: relative;
    cursor: pointer;
    flex-shrink: 0;
    transition: all 0.2s ease;
}

.format-radio input[type="radio"]:checked {
    border-color: var(--accent-bold);
    background: var(--accent-bold);
}

.format-radio input[type="radio"]:checked::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 6px;
    height: 6px;
    background: white;
    border-radius: 50%;
}

.format-label {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    flex: 1;
}

.format-tag {
    font-size: 0.7rem;
    font-weight: 700;
    padding: 0.15rem 0.45rem;
    border-radius: 3px;
    letter-spacing: 0.03em;
}

.format-tag.jpeg { background: #b45309; color: #fef3c7; }
.format-tag.png { background: #047857; color: #d1fae5; }
.format-tag.webp { background: #7c3aed; color: #ede9fe; }

.format-desc {
    font-size: 0.78rem;
    color: var(--text-dim);
}

/* ===== Quality Slider ===== */
.quality-value {
    margin-left: auto;
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--accent);
}

.quality-slider-wrap {
    padding: 0 0.25rem;
}

.quality-slider {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background: linear-gradient(to right, var(--red), var(--yellow), var(--green));
    outline: none;
    cursor: pointer;
}

.quality-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: white;
    border: 3px solid var(--accent-bold);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
    cursor: pointer;
    transition: transform 0.15s ease;
}

.quality-slider::-webkit-slider-thumb:hover {
    transform: scale(1.15);
}

.quality-slider::-moz-range-thumb {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: white;
    border: 3px solid var(--accent-bold);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
    cursor: pointer;
}

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

/* ===== Buttons ===== */
.panel-actions {
    padding: 1rem 0 0.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.7rem 1rem;
    border: none;
    border-radius: var(--radius);
    font-family: inherit;
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    width: 100%;
}

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

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

.btn-primary:hover:not(:disabled) {
    background: var(--accent-hover);
    box-shadow: 0 4px 16px rgba(59, 130, 246, 0.3);
    transform: translateY(-1px);
}

.btn-secondary {
    background: rgba(96, 165, 250, 0.12);
    color: var(--accent);
    border: 1px solid rgba(96, 165, 250, 0.2);
}

.btn-secondary:hover:not(:disabled) {
    background: rgba(96, 165, 250, 0.18);
    border-color: var(--accent);
}

.btn-ghost {
    background: transparent;
    color: var(--text-dim);
    font-weight: 500;
    padding: 0.5rem 1rem;
}

.btn-ghost:hover {
    color: var(--red);
    background: rgba(248, 113, 113, 0.08);
}

.btn-outline {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border);
    font-weight: 500;
}

.btn-outline:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: rgba(96, 165, 250, 0.06);
}

.add-more-section {
    border-bottom: none !important;
    padding-bottom: 0.5rem !important;
}

/* ===== Preview Area ===== */
.preview-area {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    min-width: 0;
    overflow: hidden;
}

.preview-content {
    flex: 1;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    min-height: 300px;
}

.preview-placeholder {
    text-align: center;
    color: var(--text-dim);
    padding: 2rem;
}

.preview-placeholder svg {
    margin-bottom: 1rem;
    opacity: 0.4;
}

.preview-placeholder p {
    font-size: 0.9rem;
}

/* ===== Side-by-Side Preview ===== */
.preview-compare {
    display: flex;
    width: 100%;
    height: 100%;
    position: relative;
}

.preview-pane {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    overflow: hidden;
    position: relative;
}

.preview-pane:first-child {
    border-right: 1px solid var(--border);
}

.preview-pane-label {
    position: absolute;
    top: 0.75rem;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-dim);
    background: rgba(0, 0, 0, 0.5);
    padding: 0.2rem 0.65rem;
    border-radius: 20px;
    z-index: 2;
}

.preview-pane img {
    max-width: 100%;
    max-height: calc(100% - 60px);
    object-fit: contain;
    border-radius: 4px;
    background: repeating-conic-gradient(rgba(255,255,255,0.05) 0% 25%, transparent 0% 50%) 0 0 / 16px 16px;
}

.preview-pane-info {
    position: absolute;
    bottom: 0.6rem;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 0.75rem;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(8px);
    padding: 0.35rem 0.75rem;
    border-radius: 20px;
    white-space: nowrap;
}

.preview-pane-info span {
    font-size: 0.72rem;
    color: var(--text-secondary);
}

.preview-pane-info .size-value {
    font-weight: 600;
    color: var(--text-primary);
}

.preview-pane-info .savings {
    font-weight: 600;
    color: var(--green);
}

.preview-pane-info .increase {
    font-weight: 600;
    color: var(--red);
}

.preview-pane-actions {
    position: absolute;
    top: 0.75rem;
    right: 0.75rem;
    z-index: 2;
}

.btn-download-single {
    padding: 0.35rem 0.7rem;
    background: var(--accent-bold);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.3rem;
    transition: all 0.2s ease;
}

.btn-download-single:hover {
    background: var(--accent-hover);
    transform: translateY(-1px);
}

/* ===== Progress Bar ===== */
.progress-bar {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.85rem 1rem;
    animation: fadeIn 0.3s ease;
}

.progress-info {
    display: flex;
    justify-content: space-between;
    margin-bottom: 0.5rem;
}

#progressText {
    font-size: 0.82rem;
    font-weight: 500;
    color: var(--text-primary);
}

#progressCount {
    font-size: 0.82rem;
    color: var(--text-dim);
    font-variant-numeric: tabular-nums;
}

.progress-track {
    height: 6px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 3px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    width: 0%;
    background: var(--gradient);
    border-radius: 3px;
    transition: width 0.35s ease;
}

/* ===== Thumbnail Strip ===== */
.thumbnail-strip {
    display: flex;
    gap: 0.5rem;
    padding: 0.75rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow-x: auto;
    min-height: 90px;
    align-items: center;
}

.thumbnail-strip::-webkit-scrollbar {
    height: 5px;
}

.thumbnail-strip::-webkit-scrollbar-thumb {
    background: var(--text-dim);
    border-radius: 4px;
}

.thumbnail-item {
    flex-shrink: 0;
    width: 72px;
    height: 72px;
    border-radius: var(--radius-sm);
    border: 2px solid transparent;
    overflow: hidden;
    cursor: pointer;
    position: relative;
    transition: all 0.2s ease;
    background: rgba(0, 0, 0, 0.2);
}

.thumbnail-item:hover {
    border-color: var(--border-light);
    transform: translateY(-2px);
}

.thumbnail-item.active {
    border-color: var(--accent-bold);
    box-shadow: 0 0 12px rgba(59, 130, 246, 0.25);
}

.thumbnail-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.thumbnail-status {
    position: absolute;
    bottom: 3px;
    right: 3px;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 8px;
    font-weight: 700;
    border: 1.5px solid var(--surface);
}

.thumbnail-status.pending {
    background: var(--text-dim);
    color: transparent;
}

.thumbnail-status.done {
    background: var(--green);
    color: white;
}

.thumbnail-status.processing {
    background: var(--yellow);
    animation: pulse 1s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.thumbnail-remove {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.7);
    color: var(--text-dim);
    border: none;
    font-size: 10px;
    line-height: 1;
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
}

.thumbnail-item:hover .thumbnail-remove {
    display: flex;
}

.thumbnail-remove:hover {
    background: var(--red);
    color: white;
}

.thumbnail-name {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: linear-gradient(transparent, rgba(0, 0, 0, 0.8));
    padding: 10px 4px 3px;
    font-size: 0.55rem;
    color: var(--text-secondary);
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    pointer-events: none;
}

/* ===== Responsive ===== */
@media (max-width: 900px) {
    .workspace {
        grid-template-columns: 1fr;
        height: auto;
    }

    .settings-panel {
        order: 2;
        max-height: none;
    }

    .preview-area {
        order: 1;
    }

    .header-inner {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.25rem;
    }

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

    .preview-compare {
        flex-direction: column;
    }

    .preview-pane:first-child {
        border-right: none;
        border-bottom: 1px solid var(--border);
    }

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

@media (max-width: 600px) {
    .main-content {
        padding: 0.75rem;
    }

    .drop-zone {
        padding: 2.5rem 1.25rem;
    }

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

/* ===== Utility Animations ===== */
@keyframes slideUp {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

.thumbnail-item {
    animation: slideUp 0.3s ease backwards;
}

.thumbnail-item:nth-child(1) { animation-delay: 0s; }
.thumbnail-item:nth-child(2) { animation-delay: 0.03s; }
.thumbnail-item:nth-child(3) { animation-delay: 0.06s; }
.thumbnail-item:nth-child(4) { animation-delay: 0.09s; }
.thumbnail-item:nth-child(5) { animation-delay: 0.12s; }
.thumbnail-item:nth-child(6) { animation-delay: 0.15s; }
.thumbnail-item:nth-child(7) { animation-delay: 0.18s; }
.thumbnail-item:nth-child(8) { animation-delay: 0.21s; }
