/* ===== CSS Variables ===== */
:root {
    /* Colors */
    --color-primary: #6366f1;
    --color-primary-hover: #4f46e5;
    --color-primary-light: #e0e7ff;
    --color-success: #10b981;
    --color-success-light: #d1fae5;
    --color-warning: #f59e0b;
    --color-error: #ef4444;
    --color-error-light: #fee2e2;

    /* Background */
    --bg-primary: #ffffff;
    --bg-secondary: #f8fafc;
    --bg-tertiary: #f1f5f9;
    --bg-hover: #e2e8f0;

    /* Text */
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #94a3b8;

    /* Border */
    --border-color: #e2e8f0;
    --border-color-hover: #cbd5e1;

    /* Misc */
    --border-radius: 12px;
    --border-radius-sm: 8px;
    --border-radius-lg: 16px;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md:
        0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1);
    --shadow-lg:
        0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1);
    --transition: 200ms ease;
}

/* Dark Mode */
[data-theme="dark"] {
    --color-primary: #818cf8;
    --color-primary-hover: #6366f1;
    --color-primary-light: #312e81;
    --color-success-light: #064e3b;
    --color-error-light: #7f1d1d;

    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --bg-tertiary: #334155;
    --bg-hover: #475569;

    --text-primary: #f1f5f9;
    --text-secondary: #cbd5e1;
    --text-muted: #64748b;

    --border-color: #334155;
    --border-color-hover: #475569;
}

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

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-color: var(--bg-secondary);
    color: var(--text-primary);
    line-height: 1.5;
    min-height: 100vh;
}

/* ===== App Layout ===== */
.app {
    max-width: 1200px;
    margin: 0 auto;
    padding: 1rem;
}

/* ===== Header ===== */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 0;
    margin-bottom: 1.5rem;
}

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

.header__icon {
    width: 32px;
    height: 32px;
    color: var(--color-primary);
}

.header__title {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
}

.header__theme-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: none;
    border-radius: var(--border-radius-sm);
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    cursor: pointer;
    transition: var(--transition);
}

.header__theme-toggle:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.header__theme-toggle svg {
    width: 20px;
    height: 20px;
}

.icon-moon {
    display: none;
}
[data-theme="dark"] .icon-sun {
    display: none;
}
[data-theme="dark"] .icon-moon {
    display: block;
}

/* Install Button */
.header__install-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    border: none;
    border-radius: var(--border-radius-sm);
    background: var(--color-primary);
    color: white;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
}

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

.header__install-btn svg {
    width: 18px;
    height: 18px;
}

.header__install-btn[hidden] {
    display: none;
}

/* ===== Drop Zone ===== */
.dropzone {
    border: 2px dashed var(--border-color);
    border-radius: var(--border-radius-lg);
    background: var(--bg-primary);
    padding: 3rem 2rem;
    text-align: center;
    cursor: pointer;
    transition: var(--transition);
    position: relative;
}

.dropzone:hover,
.dropzone.dropzone--active {
    border-color: var(--color-primary);
    background: var(--color-primary-light);
}

.dropzone__content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
}

.dropzone__icon {
    width: 48px;
    height: 48px;
    color: var(--text-muted);
    transition: var(--transition);
}

.dropzone:hover .dropzone__icon,
.dropzone.dropzone--active .dropzone__icon {
    color: var(--color-primary);
}

.dropzone__text {
    font-size: 1rem;
    font-weight: 500;
    color: var(--text-primary);
}

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

.dropzone__input {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
}

/* ===== Controls ===== */
.controls {
    background: var(--bg-primary);
    border-radius: var(--border-radius);
    padding: 1.5rem;
    margin-top: 1.5rem;
    box-shadow: var(--shadow-sm);
}

.controls__row {
    display: flex;
    flex-wrap: wrap;
    gap: 1.5rem;
    margin-bottom: 1.5rem;
}

.controls__row:last-child {
    margin-bottom: 0;
}

.control-group {
    flex: 1;
    min-width: 200px;
}

.control-group__label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
}

.control-group__presets {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

/* Slider */
.slider {
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background: var(--bg-tertiary);
    outline: none;
    -webkit-appearance: none;
    appearance: none;
}

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

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

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

/* Select */
.select {
    width: 100%;
    padding: 0.625rem 1rem;
    font-size: 0.875rem;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-sm);
    background: var(--bg-primary);
    color: var(--text-primary);
    cursor: pointer;
    transition: var(--transition);
}

.select:hover {
    border-color: var(--border-color-hover);
}

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

/* Input */
.input {
    padding: 0.625rem 1rem;
    font-size: 0.875rem;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-sm);
    background: var(--bg-primary);
    color: var(--text-primary);
    transition: var(--transition);
}

.input:focus {
    outline: none;
    border-color: var(--color-primary);
}

.input--small {
    width: 80px;
    padding: 0.5rem 0.75rem;
}

/* Size Presets */
.size-presets {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

/* Custom Size */
.control-group--custom-size {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.custom-size-inputs {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.custom-size-separator {
    color: var(--text-muted);
}

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

/* Checkbox */
.checkbox {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
    color: var(--text-secondary);
    cursor: pointer;
}

.checkbox input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--color-primary);
}

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

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

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

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

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

.btn--secondary {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

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

.btn--ghost {
    background: transparent;
    color: var(--text-secondary);
}

.btn--ghost:hover:not(:disabled) {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.btn--icon {
    padding: 0.5rem;
    border-radius: var(--border-radius-sm);
}

.btn--download {
    color: var(--color-success);
}

.btn--remove {
    color: var(--color-error);
}

.preset-btn {
    padding: 0.375rem 0.75rem;
    font-size: 0.75rem;
    font-weight: 500;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-sm);
    background: var(--bg-primary);
    color: var(--text-secondary);
    cursor: pointer;
    transition: var(--transition);
}

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

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

/* Controls Actions */
.controls__actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border-color);
}

/* ===== Gallery ===== */
.gallery {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1rem;
    margin-top: 1.5rem;
}

.gallery:empty {
    display: none;
}

/* Image Card */
.image-card {
    background: var(--bg-primary);
    border-radius: var(--border-radius);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
    transition: var(--transition);
}

.image-card:hover {
    box-shadow: var(--shadow-md);
}

.image-card__preview {
    position: relative;
    aspect-ratio: 4/3;
    background: var(--bg-tertiary);
    overflow: hidden;
}

.image-card__img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.image-card__overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: var(--transition);
}

.image-card.processing .image-card__overlay {
    opacity: 1;
}

.image-card__progress {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    color: white;
}

.progress-bar {
    width: 120px;
    height: 6px;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 3px;
    overflow: hidden;
}

.progress-bar__fill {
    height: 100%;
    background: var(--color-primary);
    border-radius: 3px;
    width: 0%;
    transition: width 200ms ease;
}

.progress-bar__text {
    font-size: 0.875rem;
    font-weight: 500;
}

.image-card__info {
    padding: 0.75rem 1rem;
}

.image-card__name {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.image-card__size {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
}

.image-card__arrow {
    color: var(--text-muted);
}

.image-card__new-size {
    color: var(--color-success);
    font-weight: 500;
}

.image-card__savings {
    color: var(--color-success);
    font-weight: 600;
}

.image-card.error .image-card__new-size,
.image-card.error .image-card__savings {
    color: var(--color-error);
}

.image-card__actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
    padding: 0 1rem 0.75rem;
}

/* ===== Empty State ===== */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 4rem 2rem;
    text-align: center;
}

.empty-state__icon {
    width: 80px;
    height: 80px;
    color: var(--text-muted);
    opacity: 0.5;
    margin-bottom: 1rem;
}

.empty-state__text {
    font-size: 1.125rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.empty-state__subtext {
    font-size: 0.875rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
}

.gallery:not(:empty) + .empty-state {
    display: none;
}

/* ===== Toast ===== */
.toast-container {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    z-index: 1000;
}

.toast {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.875rem 1rem;
    background: var(--bg-primary);
    border-radius: var(--border-radius-sm);
    box-shadow: var(--shadow-lg);
    animation: slideIn 300ms ease;
}

.toast--success {
    border-left: 4px solid var(--color-success);
}

.toast--error {
    border-left: 4px solid var(--color-error);
}

.toast--warning {
    border-left: 4px solid var(--color-warning);
}

.toast__message {
    font-size: 0.875rem;
    color: var(--text-primary);
}

.toast__close {
    display: flex;
    padding: 0.25rem;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    transition: var(--transition);
}

.toast__close:hover {
    color: var(--text-primary);
}

.toast__close svg {
    width: 16px;
    height: 16px;
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
    .header__title {
        font-size: 1rem;
    }

    .dropzone {
        padding: 2rem 1rem;
    }

    .controls {
        padding: 1rem;
    }

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

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

    .controls__actions {
        flex-direction: column;
    }

    .controls__actions .btn {
        width: 100%;
    }

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

@media (max-width: 480px) {
    .app {
        padding: 0.5rem;
    }

    .size-presets {
        flex-wrap: wrap;
    }

    .preset-btn {
        flex: 1;
        min-width: calc(50% - 0.25rem);
    }
}

/* ===== Spinner ===== */
.spinner {
    animation: spin 1s linear infinite;
}

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

/* ===== Toast Info ===== */
.toast--info {
    border-left: 4px solid var(--color-primary);
}

/* ===== Focus States ===== */
.btn:focus-visible,
.select:focus-visible,
.slider:focus-visible,
.input:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
}

/* ===== Drag Active State ===== */
.dropzone--active .dropzone__icon {
    transform: scale(1.1);
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-tertiary);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb {
    background: var(--text-muted);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

/* ===== Footer ===== */
.footer {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--bg-primary);
    border-top: 1px solid var(--border-color);
    padding: 0.75rem 1rem;
    z-index: 100;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.05);
}

.footer__content {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    max-width: 1200px;
    margin: 0 auto;
}

.footer__logo {
    width: 24px;
    height: 24px;
    object-fit: contain;
}

.footer__logo--light {
    display: block;
}

.footer__logo--dark {
    display: none;
}

[data-theme="dark"] .footer__logo--light {
    display: none;
}

[data-theme="dark"] .footer__logo--dark {
    display: block;
}

.footer__text {
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-align: center;
}

.footer__text strong {
    color: var(--text-primary);
    font-weight: 600;
}

/* Ajustar padding inferior del body para el footer fijo */
body {
    padding-bottom: 60px;
}

@media (max-width: 480px) {
    .footer__content {
        flex-direction: column;
        gap: 0.5rem;
    }

    .footer__text {
        font-size: 0.625rem;
    }

    body {
        padding-bottom: 80px;
    }
}
