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

:root {
    --primary: #6366F1;
    --primary-hover: #4F46E5;
    --primary-light: #EEF2FF;
    --primary-surface: #F8F7FF;
    --success: #22C55E;
    --success-hover: #16A34A;
    --success-light: #F0FDF4;
    --warning: #F59E0B;
    --warning-light: #FFFBEB;
    --error: #EF4444;
    --error-light: #FEF2F2;
    --text-primary: #0F172A;
    --text-secondary: #475569;
    --text-tertiary: #94A3B8;
    --bg-primary: #F1F5F9;
    --bg-card: #FFFFFF;
    --bg-input: #F8FAFC;
    --border-color: #E2E8F0;
    --border-hover: #C7D2FE;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.10);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

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

.app {
    max-width: 1400px;
    margin: 0 auto;
    min-height: calc(100vh - 3rem);
    display: flex;
    flex-direction: column;
}

/* ===== HEADER ===== */
.app-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.5rem 0 1.5rem 0;
    flex-shrink: 0;
}

.app-header .logo {
    width: 40px;
    height: 40px;
    color: var(--primary);
    flex-shrink: 0;
}

.app-header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.025em;
    color: var(--text-primary);
}

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

/* ===== MAIN LAYOUT ===== */
.main-layout {
    display: flex;
    gap: 1.5rem;
    flex: 1;
    min-height: 0;
}

/* ===== LEFT: GALLERY SECTION ===== */
.gallery-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    min-width: 0;
}

/* ===== DROP ZONE ===== */
.drop-zone {
    background: var(--bg-card);
    border: 2px dashed var(--border-color);
    border-radius: var(--radius-md);
    padding: 1.5rem;
    text-align: center;
    cursor: pointer;
    transition: var(--transition);
    flex-shrink: 0;
    box-shadow: var(--shadow-sm);
}

.drop-zone:hover {
    border-color: var(--primary);
    background: var(--primary-surface);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.drop-zone.dragover {
    border-color: var(--primary);
    background: var(--primary-light);
    transform: scale(1.01);
    box-shadow: var(--shadow-md);
}

.drop-zone-content {
    pointer-events: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
}

.drop-icon {
    width: 40px;
    height: 40px;
    color: var(--primary);
}

.drop-zone h3 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.drop-zone p {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.browse-link {
    color: var(--primary);
    font-weight: 600;
    cursor: pointer;
    text-decoration: underline;
    text-underline-offset: 2px;
    pointer-events: all;
    transition: var(--transition);
}

.browse-link:hover {
    color: var(--primary-hover);
}

/* ===== GALLERY ===== */
.gallery {
    flex: 1;
    overflow-y: auto;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 0.75rem;
    align-content: start;
    padding-right: 0.25rem;
    min-height: 0;
}

.empty-state {
    grid-column: 1 / -1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2rem 1rem;
    color: var(--text-tertiary);
    background: var(--bg-card);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    gap: 0.25rem;
    min-height: 200px;
}

.empty-state svg {
    opacity: 0.4;
    height: 4rem;
    width: auto;
}

.empty-state p {
    font-size: 0.95rem;
    font-weight: 500;
}

.empty-hint {
    font-size: 0.8rem;
    color: var(--text-tertiary);
}

/* ===== GALLERY ITEMS ===== */
.gallery-item {
    background: var(--bg-card);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
    transition: var(--transition);
    position: relative;
    border: 1px solid var(--border-color);
    aspect-ratio: 1 / 1;
    display: flex;
    flex-direction: column;
}

.gallery-item:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
    border-color: var(--border-hover);
}

.gallery-item .thumbnail-wrapper {
    flex: 1;
    position: relative;
    overflow: hidden;
    background: var(--bg-input);
}

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

.gallery-item .thumbnail-wrapper .error-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: var(--error-light);
    color: var(--error);
    padding: 0.5rem;
    text-align: center;
}

.gallery-item .thumbnail-wrapper .error-overlay svg {
    margin-bottom: 0.25rem;
}

.gallery-item .thumbnail-wrapper .error-overlay span {
    font-size: 0.7rem;
    font-weight: 600;
    line-height: 1.3;
}

/* ---- Format label - TOP RIGHT over image (but above the bottom bar) ---- */
.gallery-item .format-label {
    position: absolute;
    bottom: 2.6rem;   /* lifted above the file-info bar */
    right: 0.4rem;
    background: white;
    backdrop-filter: blur(4px);
    color: var(--text-primary);
    padding: 0.1rem 0.5rem;
    border-radius: 10px;
    font-size: 0.55rem;
    font-weight: 600;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    pointer-events: none;
    z-index: 2;
}

/* ---- Status Badge - top right ---- */
.gallery-item .status-badge {
    position: absolute;
    top: 0.4rem;
    right: 0.4rem;
    background: rgba(15, 23, 42, 0.8);
    backdrop-filter: blur(4px);
    color: white;
    padding: 0.15rem 0.6rem;
    border-radius: 12px;
    font-size: 0.6rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    line-height: 1.5;
    white-space: nowrap;
    z-index: 2;
}

.gallery-item .status-badge.success {
    background: var(--success);
}

.gallery-item .status-badge.processing {
    background: var(--primary);
    animation: pulse 1s ease-in-out infinite;
}

.gallery-item .status-badge.error {
    background: var(--error);
}

.gallery-item .status-badge.pending {
    background: var(--warning);
}

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

/* ---- File info bar (bottom) ---- */
.gallery-item .file-info {
    padding: 0.5rem 0.6rem;
    font-size: 0.7rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.35rem;
    background: var(--bg-card);
    flex-shrink: 0;
    min-height: 32px;
    z-index: 1;
    position: relative;
}

.gallery-item .file-name {
    color: var(--text-primary);
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
    font-size: 0.7rem;
}

.gallery-item .file-size {
    color: var(--text-tertiary);
    font-size: 0.65rem;
    font-weight: 500;
    flex-shrink: 0;
}

.gallery-item .download-link {
    text-decoration: none;
    font-weight: bold;
    font-size: 0.65rem;
    padding: 0.15rem 0.4rem;
    border-radius: 4px;
    transition: var(--transition);
    flex-shrink: 0;
    line-height: 1.4;
    background: var(--success);
    color: white;
    box-shadow: 0 2px 8px rgba(34, 197, 94, 0.25);
}

.gallery-item .download-link:hover {
    color: white;
    background: var(--success);
}

.gallery-item .file-error {
    color: var(--error);
    font-size: 0.65rem;
    font-weight: 500;
    flex-shrink: 0;
}

/* ===== RIGHT: CONTROLS SECTION ===== */
.controls-section {
    width: 320px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.controls-card {
    background: var(--bg-card);
    border-radius: var(--radius-md);
    padding: 1.5rem;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.controls-title {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary);
    letter-spacing: 0.01em;
}

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

.control-group label {
    font-weight: 500;
    font-size: 0.8rem;
    color: var(--text-secondary);
    letter-spacing: 0.01em;
}

.control-group select,
.control-group input[type="range"] {
    padding: 0.5rem 0.75rem;
    border: 1.5px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    background: var(--bg-input);
    color: var(--text-primary);
    transition: var(--transition);
    width: 100%;
    appearance: none;
}

.control-group select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23475569' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    padding-right: 2.5rem;
    cursor: pointer;
}

.control-group select:focus,
.control-group input[type="range"]:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.12);
    background-color: white;
}

.control-group input[type="range"] {
    padding: 0.3rem 0;
    accent-color: var(--primary);
    background: transparent;
}

.control-group input[type="range"]::-webkit-slider-runnable-track {
    height: 4px;
    background: var(--border-color);
    border-radius: 2px;
}

.control-group input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--primary);
    cursor: pointer;
    margin-top: -6px;
    box-shadow: 0 1px 4px rgba(99, 102, 241, 0.3);
}

.control-group input[type="range"]::-moz-range-track {
    height: 4px;
    background: var(--border-color);
    border-radius: 2px;
    border: none;
}

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

.controls-actions {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.btn {
    padding: 0.6rem 1.25rem;
    border: none;
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: 0.85rem;
    cursor: pointer;
    transition: var(--transition);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    letter-spacing: 0.01em;
    width: 100%;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none !important;
}

.btn svg {
    flex-shrink: 0;
}

.btn-primary {
    background: var(--primary);
    color: white;
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.25);
}

.btn-primary:hover:not(:disabled) {
    background: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(99, 102, 241, 0.30);
}

.btn-primary:active:not(:disabled) {
    transform: translateY(0);
}

.btn-success {
    background: var(--success);
    color: white;
    box-shadow: 0 2px 8px rgba(34, 197, 94, 0.25);
}

.btn-success:hover:not(:disabled) {
    background: var(--success-hover);
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(34, 197, 94, 0.30);
}

.btn-success:active:not(:disabled) {
    transform: translateY(0);
}

/* ===== STATUS BAR - plain text ===== */
.status-bar {
    padding: 0.4rem 0.75rem;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 0.85rem;
    min-height: 2.2rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    border-radius: 0;
}

.status-bar .spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid var(--border-color);
    border-radius: 50%;
    border-top-color: var(--primary);
    animation: spin 0.8s linear infinite;
    flex-shrink: 0;
}

.status-bar .status-text {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex: 1;
}

.status-bar .status-success {
    color: var(--success);
}

.status-bar .status-error {
    color: var(--error);
}

.status-bar .status-warning {
    color: var(--warning);
}

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

/* ===== STATS ===== */
.stats {
    display: flex;
    justify-content: space-between;
    padding-top: 0.5rem;
    border-top: 1px solid var(--border-color);
    font-size: 0.75rem;
    color: var(--text-secondary);
}

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

/* ===== FOOTER - full width ===== */
.app-footer {
    text-align: center;
    padding: 1.5rem 0 0.5rem 0;
    color: var(--text-tertiary);
    font-size: 0.8rem;
    border-top: 1px solid var(--border-color);
    margin-top: 1.5rem;
    flex-shrink: 0;
}

.app-footer a {
    color: var(--text-secondary);
    text-decoration: underline;
    text-underline-offset: 2px;
    transition: var(--transition);
}

.app-footer a:hover {
    color: var(--primary);
}

/* ===== SCROLLBAR ===== */
.gallery::-webkit-scrollbar {
    width: 4px;
}

.gallery::-webkit-scrollbar-track {
    background: transparent;
}

.gallery::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 2px;
}

.gallery::-webkit-scrollbar-thumb:hover {
    background: var(--text-tertiary);
}

/* ===== RESPONSIVE ===== */
@media (max-width: 1024px) {
    .controls-section {
        width: 280px;
    }
}

@media (max-width: 820px) {
    .app {
        min-height: auto;
    }

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

    .controls-section {
        width: 100%;
    }

    .gallery {
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
        max-height: 400px;
    }

    body {
        padding: 1rem;
    }

    .app-footer {
        margin-top: 1rem;
    }
}

@media (max-width: 480px) {
    .gallery {
        grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
        max-height: 300px;
    }

    .app-header h1 {
        font-size: 1.25rem;
    }

    .app-header .subtitle {
        font-size: 0.75rem;
    }

    .controls-card {
        padding: 1rem;
    }

    /* Adjust format label position on small screens */
    .gallery-item .format-label {
        bottom: 2rem;
        font-size: 0.5rem;
        padding: 0.05rem 0.4rem;
    }
}


.btn svg {
    height: 2rem;
    width: auto;
}

.app-footer svg {
    height: 2rem;
    width: auto;
}
.app-footer .row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1em;
}

.is-hidden {
  display: none !important;
}
