/* CSS Variables for Premium Design System */
:root {
    --bg-color: #08090c;
    --card-bg: rgba(17, 19, 28, 0.7);
    --card-border: rgba(255, 255, 255, 0.06);
    --card-border-hover: rgba(99, 102, 241, 0.35);
    
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    
    --primary: #6366f1; /* Indigo */
    --primary-hover: #4f46e5;
    --primary-glow: rgba(99, 102, 241, 0.4);
    
    --accent: #8b5cf6; /* Violet */
    --accent-cyan: #06b6d4; /* Cyan */
    
    --success: #10b981; /* Emerald green */
    --success-glow: rgba(16, 185, 129, 0.25);
    
    --danger: #ef4444; /* Red */
    --danger-hover: #dc2626;
    
    --transition-smooth: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    --radius-sm: 8px;
    --radius-md: 14px;
    --radius-lg: 20px;
}

/* Global Reset */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    background-color: var(--bg-color);
    color: var(--text-primary);
    font-family: 'Inter', sans-serif;
    min-height: 100vh;
    overflow-x: hidden;
    position: relative;
}

/* Ambient Glow Background */
.glow-bg {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: -1;
    overflow: hidden;
    pointer-events: none;
}

.glow-bg::before,
.glow-bg::after {
    content: '';
    position: absolute;
    width: 400px;
    height: 400px;
    border-radius: 50%;
    filter: blur(150px);
    opacity: 0.12;
    animation: floatGlow 12s infinite alternate ease-in-out;
}

.glow-bg::before {
    top: -10%;
    left: 10%;
    background: var(--primary);
}

.glow-bg::after {
    bottom: -10%;
    right: 15%;
    background: var(--accent-cyan);
    animation-delay: -6s;
}

@keyframes floatGlow {
    0% { transform: translate(0, 0) scale(1); }
    100% { transform: translate(50px, 30px) scale(1.2); }
}

/* Container */
.app-container {
    max-width: 1280px;
    margin: 0 auto;
    padding: 30px 20px;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* Header */
.app-header {
    margin-bottom: 24px;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.logo {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    font-family: 'Outfit', sans-serif;
    margin-bottom: 8px;
}

.logo-icon {
    font-size: 2.2rem;
    filter: drop-shadow(0 0 10px var(--primary-glow));
    animation: pulsate 2s infinite alternate;
}

@keyframes pulsate {
    0% { transform: scale(1); }
    100% { transform: scale(1.1); }
}

.logo h1 {
    font-size: 2.2rem;
    font-weight: 800;
    letter-spacing: -1px;
    background: linear-gradient(135deg, var(--text-primary) 40%, var(--primary) 70%, var(--accent-cyan));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.logo h1 span {
    font-weight: 400;
    color: var(--text-primary);
    -webkit-text-fill-color: var(--text-primary);
}

.subtitle {
    color: var(--text-secondary);
    font-size: 0.95rem;
    font-weight: 300;
    margin-bottom: 24px;
}

/* Segmented Tabs Navigation Control */
.tabs-nav {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 100px;
    padding: 5px;
    display: inline-flex;
    gap: 4px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

.tab-btn {
    background: none;
    border: none;
    padding: 10px 24px;
    border-radius: 100px;
    font-family: 'Outfit', sans-serif;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: var(--transition-smooth);
}

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

.tab-btn.active {
    background: linear-gradient(135deg, var(--primary), var(--accent));
    color: white;
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.35);
}

.tab-icon {
    font-size: 1.05rem;
}

/* Main Grid Layout */
.app-main {
    display: grid;
    grid-template-columns: 380px 1fr;
    gap: 24px;
    flex: 1;
    align-items: start;
}

@media (max-width: 968px) {
    .app-main {
        grid-template-columns: 1fr;
    }
}

/* Tabs Content Display States */
.tab-content {
    display: none !important;
    animation: tabFadeIn 0.4s ease-out;
}

.tab-content.active {
    display: flex !important;
}

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

/* Panels */
.panel-left, .panel-right {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

/* Premium Card Glassmorphism Style */
.card {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: var(--radius-lg);
    padding: 24px;
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
    transition: var(--transition-smooth);
}

.card:hover {
    border-color: rgba(255, 255, 255, 0.09);
}

.card h2 {
    font-family: 'Outfit', sans-serif;
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 20px;
    border-left: 3px solid var(--primary);
    padding-left: 10px;
}

/* Drag & Drop Zone */
.dropzone-card {
    padding: 12px;
}

.dropzone {
    border: 2px dashed rgba(255, 255, 255, 0.15);
    border-radius: var(--radius-md);
    padding: 40px 20px;
    text-align: center;
    cursor: pointer;
    background: rgba(255, 255, 255, 0.01);
    transition: var(--transition-smooth);
    position: relative;
    overflow: hidden;
}

.dropzone:hover, .dropzone.dragover {
    border-color: var(--primary);
    background: rgba(99, 102, 241, 0.04);
    box-shadow: inset 0 0 20px rgba(99, 102, 241, 0.05);
}

.dropzone.dragover {
    transform: scale(0.99);
}

.dropzone-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.dropzone-icon {
    color: var(--text-secondary);
    margin-bottom: 16px;
    transition: var(--transition-smooth);
}

.dropzone:hover .dropzone-icon {
    color: var(--primary);
    transform: translateY(-5px);
}

.dropzone h3 {
    font-family: 'Outfit', sans-serif;
    font-size: 1.1rem;
    font-weight: 500;
    margin-bottom: 6px;
}

.dropzone p {
    color: var(--text-secondary);
    font-size: 0.85rem;
    margin-bottom: 16px;
}

.file-badge {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.05);
    padding: 4px 12px;
    border-radius: 100px;
    font-size: 0.75rem;
    color: var(--text-secondary);
}

/* File Info Box */
.file-info {
    display: flex;
    align-items: center;
    gap: 12px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: var(--radius-sm);
    padding: 12px;
    margin-top: 10px;
    animation: slideDown 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

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

.file-info.hidden {
    display: none !important;
}

.file-info-icon {
    font-size: 1.8rem;
}

.file-info-details {
    flex: 1;
    min-width: 0;
}

.file-info-details h4 {
    font-size: 0.85rem;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 2px;
}

.file-info-details p {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.btn-icon {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 0.9rem;
    cursor: pointer;
    padding: 4px;
    border-radius: 50%;
    transition: var(--transition-smooth);
}

.btn-icon:hover {
    background: rgba(239, 68, 68, 0.1);
    color: var(--danger);
}

/* Config panel items */
.control-group {
    margin-bottom: 24px;
}

.control-group:last-of-type {
    margin-bottom: 12px;
}

.control-label-wrapper {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.control-label {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.badge {
    background: rgba(99, 102, 241, 0.1);
    border: 1px solid rgba(99, 102, 241, 0.2);
    color: var(--primary);
    padding: 2px 8px;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 600;
}

/* Custom Checkboxes */
.checkbox-options {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.checkbox-container {
    display: flex;
    align-items: center;
    position: relative;
    padding-left: 36px;
    cursor: pointer;
    user-select: none;
}

.checkbox-container input {
    position: absolute;
    opacity: 0;
    cursor: pointer;
    height: 0;
    width: 0;
}

.checkmark {
    position: absolute;
    top: 50%;
    left: 0;
    transform: translateY(-50%);
    height: 20px;
    width: 20px;
    background-color: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 6px;
    transition: var(--transition-smooth);
}

.checkbox-container:hover input ~ .checkmark {
    border-color: var(--primary);
    background-color: rgba(99, 102, 241, 0.05);
}

.checkbox-container input:checked ~ .checkmark {
    background-color: var(--primary);
    border-color: var(--primary);
    box-shadow: 0 0 10px rgba(99, 102, 241, 0.3);
}

.checkmark:after {
    content: "";
    position: absolute;
    display: none;
}

.checkbox-container input:checked ~ .checkmark:after {
    display: block;
}

.checkbox-container .checkmark:after {
    left: 7px;
    top: 3px;
    width: 5px;
    height: 10px;
    border: solid white;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}

.option-info {
    display: flex;
    flex-direction: column;
}

.option-title {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary);
}

.option-desc {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

/* Styled Range Input */
.styled-range {
    -webkit-appearance: none;
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background: rgba(255, 255, 255, 0.1);
    outline: none;
    margin: 12px 0;
}

.styled-range::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--primary);
    cursor: pointer;
    box-shadow: 0 0 10px rgba(99, 102, 241, 0.5);
    transition: var(--transition-smooth);
}

.styled-range::-webkit-slider-thumb:hover {
    transform: scale(1.15);
    background: var(--accent-cyan);
    box-shadow: 0 0 15px rgba(6, 182, 212, 0.6);
}

.range-markers {
    display: flex;
    justify-content: space-between;
    font-size: 0.7rem;
    color: var(--text-muted);
}

/* Styled Text Input */
.styled-input {
    width: 100%;
    padding: 11px 14px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.9rem;
    outline: none;
    transition: var(--transition-smooth);
}

.styled-input:hover {
    border-color: rgba(255, 255, 255, 0.2);
    background: rgba(255, 255, 255, 0.05);
}

.styled-input:focus {
    border-color: var(--primary);
    background: rgba(255, 255, 255, 0.06);
    box-shadow: 0 0 10px var(--primary-glow);
}

.styled-input::placeholder {
    color: var(--text-muted);
}

/* Buttons */
.btn {
    width: 100%;
    padding: 14px 20px;
    border: none;
    border-radius: var(--radius-md);
    font-family: 'Outfit', sans-serif;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: var(--transition-smooth);
}

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

.btn-primary {
    background: linear-gradient(135deg, var(--primary), var(--accent));
    color: white;
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.2);
}

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

.btn-secondary {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.08);
    color: var(--text-primary);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.08);
}

.btn-success {
    background: linear-gradient(135deg, #10b981, #059669);
    color: white;
    box-shadow: 0 4px 15px rgba(16, 185, 129, 0.2);
}

.btn-success:not(:disabled):hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(16, 185, 129, 0.35);
}

/* Stats Card */
.stats-card {
    border-color: rgba(99, 102, 241, 0.15);
    animation: fadeIn 0.4s ease-out;
}

.stats-card.hidden {
    display: none !important;
}

@keyframes fadeIn {
    from { opacity: 0; transform: scale(0.98); }
    to { opacity: 1; transform: scale(1); }
}

.stats-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.stats-header h2 {
    margin-bottom: 0;
}

.stats-counter {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.progress-bar-container {
    height: 10px;
    background: rgba(255, 255, 255, 0.06);
    border-radius: 5px;
    overflow: hidden;
    position: relative;
    margin-bottom: 20px;
}

.progress-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary), var(--accent-cyan));
    border-radius: 5px;
    transition: width 0.2s ease-out;
    box-shadow: 0 0 10px var(--primary-glow);
}

.progress-percent {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.65rem;
    font-weight: 600;
    color: white;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
    display: none;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    margin-bottom: 20px;
}

@media (max-width: 480px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }
}

.stat-box {
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid rgba(255, 255, 255, 0.04);
    border-radius: var(--radius-sm);
    padding: 10px;
    text-align: center;
}

.stat-box.highlight {
    background: rgba(16, 185, 129, 0.04);
    border-color: rgba(16, 185, 129, 0.15);
}

.stat-box.highlight .stat-value {
    color: var(--success);
    text-shadow: 0 0 8px rgba(16, 185, 129, 0.2);
}

.stat-label {
    display: block;
    font-size: 0.7rem;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.stat-value {
    font-family: 'Outfit', sans-serif;
    font-size: 0.95rem;
    font-weight: 700;
}

.action-buttons-wrapper {
    display: flex;
    gap: 12px;
}

.action-buttons-wrapper button {
    flex: 1;
}

/* Preview Card */
.preview-card {
    flex: 1;
    min-height: 400px;
    display: flex;
    flex-direction: column;
}

.preview-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.preview-header h2 {
    margin-bottom: 0;
}

.status-badge {
    font-size: 0.75rem;
    font-weight: 500;
    padding: 4px 10px;
    border-radius: 100px;
}

.status-badge.idle {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-secondary);
}

.status-badge.processing {
    background: rgba(99, 102, 241, 0.1);
    color: var(--primary);
    animation: pulse 1.5s infinite;
}

.status-badge.done {
    background: var(--success-glow);
    color: var(--success);
}

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

/* Welcome Screen in Preview */
.welcome-preview {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    color: var(--text-secondary);
    text-align: center;
    padding: 40px;
}

.welcome-preview.hidden {
    display: none !important;
}

.welcome-icon {
    font-size: 3rem;
    margin-bottom: 16px;
    opacity: 0.6;
}

.welcome-preview h3 {
    font-family: 'Outfit', sans-serif;
    font-size: 1.1rem;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 6px;
}

.welcome-preview p {
    font-size: 0.85rem;
    max-width: 320px;
}

/* Pages Queue Grid */
.pages-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 16px;
    overflow-y: auto;
    max-height: 520px;
    padding-right: 6px;
}

.pages-grid.hidden {
    display: none !important;
}

/* Scrollbar styling for queue */
.pages-grid::-webkit-scrollbar {
    width: 6px;
}

.pages-grid::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.02);
    border-radius: 3px;
}

.pages-grid::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
}

.pages-grid::-webkit-scrollbar-thumb:hover {
    background: rgba(99, 102, 241, 0.3);
}

/* Page Thumbnail Item */
.page-item {
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: var(--radius-md);
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    position: relative;
    transition: var(--transition-smooth);
}

.page-item:hover {
    border-color: var(--card-border-hover);
    transform: translateY(-2px);
    background: rgba(255, 255, 255, 0.03);
}

.page-item.processing {
    border-color: var(--primary);
    box-shadow: 0 0 12px rgba(99, 102, 241, 0.15);
}

.page-item.done {
    border-color: rgba(16, 185, 129, 0.3);
}

.thumbnail-container {
    width: 100%;
    aspect-ratio: 1 / 1.414; /* Standard A4 ratio */
    background: #1e2028;
    border-radius: var(--radius-sm);
    overflow: hidden;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid rgba(255, 255, 255, 0.04);
}

/* Ratio adjustments for normal images in the second PNG tab */
#pages-grid-png .thumbnail-container {
    aspect-ratio: 1.2 / 1; /* More horizontal/standard ratio for generic images */
}

.thumbnail-container canvas, .thumbnail-container img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

/* Page overlay overlay icons (loading, checkmark) */
.page-status-overlay {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}

.page-status-overlay.pending {
    background: rgba(0, 0, 0, 0.6);
    color: var(--text-secondary);
}

.page-status-overlay.processing {
    background: var(--primary);
    color: white;
}

.page-status-overlay.processing::after {
    content: '';
    width: 12px;
    height: 12px;
    border: 2px solid white;
    border-top-color: transparent;
    border-radius: 50%;
    animation: spinner 0.8s linear infinite;
}

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

.page-status-overlay.done {
    background: var(--success);
    color: white;
}

.page-label {
    font-size: 0.8rem;
    font-weight: 600;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Small detail tags */
.page-stats {
    display: flex;
    flex-direction: column;
    gap: 4px;
    background: rgba(0, 0, 0, 0.2);
    padding: 6px;
    border-radius: 6px;
    font-size: 0.68rem;
}

.page-stat-row {
    display: flex;
    justify-content: space-between;
    color: var(--text-secondary);
}

.page-stat-row span.val {
    font-weight: 500;
    color: var(--text-primary);
}

.page-stat-row span.val.webp-val {
    color: var(--accent-cyan);
}

/* Footer */
.app-footer {
    margin-top: 40px;
    padding-top: 20px;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
    text-align: center;
    color: var(--text-muted);
    font-size: 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.copyright {
    color: var(--text-secondary);
}
