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

:root {
    --primary: #6C5CE7;
    --primary-dark: #5A4BD1;
    --primary-light: #A29BFE;
    --accent: #00CEC9;
    --accent-dark: #00B5B0;
    --bg-dark: #0F0E17;
    --bg-card: #1A1929;
    --bg-card-hover: #232240;
    --text-primary: #FFFFFE;
    --text-secondary: #A7A9BE;
    --text-muted: #6B6D80;
    --success: #00D68F;
    --error: #FF6B6B;
    --warning: #FFC048;
    --border: rgba(108, 92, 231, 0.2);
    --shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 16px 64px rgba(0, 0, 0, 0.4);
    --radius: 16px;
    --radius-sm: 10px;
    --radius-xs: 6px;
    --transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-dark);
    color: var(--text-primary);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

/* ===== ANIMATED BACKGROUND ===== */
.bg-animation {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    z-index: 0;
    overflow: hidden;
    pointer-events: none;
}

.bg-animation .orb {
    position: absolute;
    border-radius: 50%;
    filter: blur(80px);
    opacity: 0.15;
    animation: orbFloat 20s ease-in-out infinite;
}

.bg-animation .orb:nth-child(1) {
    width: 500px; height: 500px;
    background: var(--primary);
    top: -100px; left: -100px;
    animation-delay: 0s;
}

.bg-animation .orb:nth-child(2) {
    width: 400px; height: 400px;
    background: var(--accent);
    bottom: -100px; right: -100px;
    animation-delay: -7s;
}

.bg-animation .orb:nth-child(3) {
    width: 300px; height: 300px;
    background: #FD79A8;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    animation-delay: -14s;
}

@keyframes orbFloat {
    0%, 100% { transform: translate(0, 0) scale(1); }
    25% { transform: translate(60px, -80px) scale(1.1); }
    50% { transform: translate(-40px, 60px) scale(0.9); }
    75% { transform: translate(80px, 40px) scale(1.05); }
}

/* ===== APP CONTAINER ===== */
.app-container {
    position: relative;
    z-index: 1;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ===== HEADER ===== */
.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 28px;
    background: rgba(26, 25, 41, 0.8);
    backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    min-height: 60px;
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo-icon {
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    box-shadow: 0 4px 16px rgba(108, 92, 231, 0.3);
}

.logo-text {
    font-size: 20px;
    font-weight: 700;
    letter-spacing: -0.5px;
}

.logo-text span {
    background: linear-gradient(135deg, var(--primary-light), var(--accent));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.header-controls {
    display: flex;
    align-items: center;
    gap: 12px;
}

/* ===== SETTINGS PANEL ===== */
.settings-group {
    display: flex;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
}

.setting-item {
    display: flex;
    align-items: center;
    gap: 8px;
}

.setting-item label {
    font-size: 12px;
    color: var(--text-secondary);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    white-space: nowrap;
}

.setting-item select,
.setting-item input[type="range"] {
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text-primary);
    padding: 6px 10px;
    border-radius: var(--radius-xs);
    font-size: 13px;
    cursor: pointer;
    outline: none;
    transition: var(--transition);
}

.setting-item select:hover,
.setting-item select:focus {
    border-color: var(--primary);
}

.setting-item select option {
    background: var(--bg-card);
}

.quality-value {
    font-size: 13px;
    color: var(--accent);
    font-weight: 700;
    min-width: 32px;
    text-align: center;
}

input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    width: 100px;
    height: 6px;
    background: var(--bg-card);
    border-radius: 3px;
    outline: none;
    border: none !important;
    padding: 0 !important;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(108, 92, 231, 0.4);
}

input[type="range"]::-moz-range-thumb {
    width: 18px;
    height: 18px;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    border-radius: 50%;
    cursor: pointer;
    border: none;
}

/* ===== MAIN CONTENT ===== */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
}

/* ===== UPLOAD AREA ===== */
.upload-section {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.upload-zone {
    width: 100%;
    max-width: 680px;
    padding: 60px 40px;
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    text-align: center;
    cursor: pointer;
    transition: var(--transition);
    background: rgba(26, 25, 41, 0.5);
    backdrop-filter: blur(10px);
    position: relative;
    overflow: hidden;
}

.upload-zone::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, rgba(108, 92, 231, 0.05), rgba(0, 206, 201, 0.05));
    opacity: 0;
    transition: var(--transition);
}

.upload-zone:hover,
.upload-zone.drag-over {
    border-color: var(--primary);
    transform: translateY(-2px);
    box-shadow: var(--shadow);
}

.upload-zone:hover::before,
.upload-zone.drag-over::before {
    opacity: 1;
}

.upload-zone.drag-over {
    border-color: var(--accent);
    background: rgba(0, 206, 201, 0.05);
}

.upload-icon {
    width: 80px;
    height: 80px;
    margin: 0 auto 20px;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 36px;
    box-shadow: 0 8px 32px rgba(108, 92, 231, 0.3);
    animation: iconPulse 3s ease-in-out infinite;
}

@keyframes iconPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

.upload-title {
    font-size: 22px;
    font-weight: 700;
    margin-bottom: 8px;
}

.upload-subtitle {
    color: var(--text-secondary);
    font-size: 14px;
    margin-bottom: 20px;
}

.upload-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 12px 28px;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
    border: none;
    border-radius: 50px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    box-shadow: 0 4px 16px rgba(108, 92, 231, 0.3);
}

.upload-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(108, 92, 231, 0.4);
}

.upload-formats {
    margin-top: 16px;
    font-size: 12px;
    color: var(--text-muted);
}

/* ===== WORKSPACE (shown after upload) ===== */
.workspace {
    flex: 1;
    display: none;
    flex-direction: column;
    overflow: hidden;
}

.workspace.active {
    display: flex;
}

/* ===== TOOLBAR ===== */
.toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 24px;
    background: rgba(26, 25, 41, 0.6);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    gap: 12px;
    flex-wrap: wrap;
}

.toolbar-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.toolbar-center {
    display: flex;
    align-items: center;
    gap: 8px;
}

.toolbar-right {
    display: flex;
    align-items: center;
    gap: 10px;
}

.file-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.file-info-icon {
    width: 36px;
    height: 36px;
    background: linear-gradient(135deg, #FF6B6B, #EE5A24);
    border-radius: var(--radius-xs);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
}

.file-info-text h4 {
    font-size: 13px;
    font-weight: 600;
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.file-info-text span {
    font-size: 11px;
    color: var(--text-muted);
}

.page-badge {
    background: var(--bg-card);
    border: 1px solid var(--border);
    padding: 4px 12px;
    border-radius: 50px;
    font-size: 12px;
    color: var(--text-secondary);
    font-weight: 600;
}

.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border: none;
    border-radius: var(--radius-xs);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    white-space: nowrap;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
    box-shadow: 0 4px 12px rgba(108, 92, 231, 0.3);
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(108, 92, 231, 0.4);
}

.btn-success {
    background: linear-gradient(135deg, var(--success), #00B87D);
    color: white;
    box-shadow: 0 4px 12px rgba(0, 214, 143, 0.3);
}

.btn-success:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(0, 214, 143, 0.4);
}

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

.btn-outline:hover {
    border-color: var(--primary);
    color: var(--text-primary);
    background: rgba(108, 92, 231, 0.1);
}

.btn-danger {
    background: rgba(255, 107, 107, 0.1);
    color: var(--error);
    border: 1px solid rgba(255, 107, 107, 0.2);
}

.btn-danger:hover {
    background: rgba(255, 107, 107, 0.2);
}

.btn-icon {
    width: 36px;
    height: 36px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-xs);
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    cursor: pointer;
    transition: var(--transition);
    font-size: 16px;
}

.btn-icon:hover {
    border-color: var(--primary);
    color: var(--text-primary);
    background: rgba(108, 92, 231, 0.1);
}

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

/* ===== PAGE SELECTION BAR ===== */
.selection-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 24px;
    background: rgba(108, 92, 231, 0.08);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.selection-bar-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.selection-bar-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.select-toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: var(--text-secondary);
    cursor: pointer;
    user-select: none;
}

.select-toggle input[type="checkbox"] {
    appearance: none;
    -webkit-appearance: none;
    width: 18px;
    height: 18px;
    border: 2px solid var(--border);
    border-radius: 4px;
    cursor: pointer;
    transition: var(--transition);
    position: relative;
}

.select-toggle input[type="checkbox"]:checked {
    background: var(--primary);
    border-color: var(--primary);
}

.select-toggle input[type="checkbox"]:checked::after {
    content: '✓';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: white;
    font-size: 12px;
    font-weight: 700;
}

.selection-count {
    font-size: 13px;
    color: var(--accent);
    font-weight: 600;
}

/* ===== PAGES GRID ===== */
.pages-container {
    flex: 1;
    overflow-y: auto;
    padding: 20px 24px;
    scroll-behavior: smooth;
}

.pages-container::-webkit-scrollbar {
    width: 8px;
}

.pages-container::-webkit-scrollbar-track {
    background: transparent;
}

.pages-container::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
}

.pages-container::-webkit-scrollbar-thumb:hover {
    background: var(--primary);
}

.pages-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 20px;
}

.page-card {
    background: var(--bg-card);
    border: 2px solid transparent;
    border-radius: var(--radius);
    overflow: hidden;
    cursor: pointer;
    transition: var(--transition);
    position: relative;
    group: true;
}

.page-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow);
    border-color: var(--border);
}

.page-card.selected {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(108, 92, 231, 0.2);
}

.page-card .check-overlay {
    position: absolute;
    top: 10px;
    left: 10px;
    width: 28px;
    height: 28px;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    color: transparent;
    transition: var(--transition);
    z-index: 2;
}

.page-card.selected .check-overlay {
    background: var(--primary);
    border-color: var(--primary);
    color: white;
}

.page-card:hover .check-overlay {
    border-color: var(--primary-light);
}

.page-thumb-wrapper {
    position: relative;
    width: 100%;
    background: #2D2B42;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 200px;
    overflow: hidden;
}

.page-thumb-wrapper canvas {
    width: 100%;
    height: auto;
    display: block;
}

.page-card-footer {
    padding: 10px 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.page-number {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
}

.page-size {
    font-size: 11px;
    color: var(--text-muted);
}

/* ===== CONVERTING STATUS OVERLAY ===== */
.page-card .converting-overlay {
    position: absolute;
    inset: 0;
    background: rgba(15, 14, 23, 0.85);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 3;
    opacity: 0;
    pointer-events: none;
    transition: var(--transition);
}

.page-card.converting .converting-overlay {
    opacity: 1;
}

.page-card.converted .check-overlay {
    background: var(--success);
    border-color: var(--success);
    color: white;
}

/* ===== PROGRESS BAR (BOTTOM) ===== */
.progress-section {
    display: none;
    padding: 12px 24px;
    background: rgba(26, 25, 41, 0.9);
    backdrop-filter: blur(20px);
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

.progress-section.active {
    display: block;
}

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

.progress-label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
}

.progress-percent {
    font-size: 13px;
    font-weight: 700;
    color: var(--accent);
}

.progress-bar-track {
    width: 100%;
    height: 6px;
    background: var(--bg-card);
    border-radius: 3px;
    overflow: hidden;
}

.progress-bar-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--primary), var(--accent));
    border-radius: 3px;
    transition: width 0.3s ease;
}

/* ===== FOOTER ===== */
.app-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 28px;
    background: rgba(26, 25, 41, 0.8);
    backdrop-filter: blur(20px);
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

.footer-left {
    font-size: 12px;
    color: var(--text-muted);
}

.footer-right {
    display: flex;
    align-items: center;
    gap: 16px;
}

.footer-right span {
    font-size: 12px;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 4px;
}

/* ===== LOADING SPINNER ===== */
.spinner {
    width: 24px;
    height: 24px;
    border: 3px solid rgba(255, 255, 255, 0.2);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.spinner-sm {
    width: 16px;
    height: 16px;
    border-width: 2px;
}

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

/* ===== TOAST NOTIFICATIONS ===== */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.toast {
    padding: 14px 20px;
    border-radius: var(--radius-sm);
    background: var(--bg-card);
    border: 1px solid var(--border);
    backdrop-filter: blur(20px);
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 14px;
    font-weight: 500;
    animation: toastIn 0.4s ease;
    max-width: 380px;
}

.toast.success { border-color: var(--success); }
.toast.error { border-color: var(--error); }
.toast.info { border-color: var(--primary); }

.toast-icon {
    font-size: 18px;
    flex-shrink: 0;
}

.toast.removing {
    animation: toastOut 0.3s ease forwards;
}

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

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

/* ===== MODAL ===== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(8px);
    z-index: 1000;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal-overlay.active {
    display: flex;
}

.modal {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 32px;
    max-width: 480px;
    width: 100%;
    box-shadow: var(--shadow-lg);
    animation: modalIn 0.3s ease;
}

@keyframes modalIn {
    from { transform: scale(0.9); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

.modal h3 {
    font-size: 20px;
    margin-bottom: 8px;
}

.modal p {
    color: var(--text-secondary);
    font-size: 14px;
    margin-bottom: 24px;
}

.modal-actions {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
}

/* ===== INITIAL LOADING SCREEN ===== */
.loading-screen {
    position: fixed;
    inset: 0;
    background: var(--bg-dark);
    z-index: 10000;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 20px;
    transition: opacity 0.5s ease;
}

.loading-screen.hidden {
    opacity: 0;
    pointer-events: none;
}

.loading-screen .logo-big {
    font-size: 28px;
    font-weight: 700;
}

.loading-screen .logo-big span {
    background: linear-gradient(135deg, var(--primary-light), var(--accent));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
    .app-header {
        padding: 10px 16px;
        flex-wrap: wrap;
        gap: 8px;
    }

    .header-controls {
        width: 100%;
        justify-content: flex-start;
    }

    .settings-group {
        gap: 10px;
    }

    .toolbar {
        padding: 8px 16px;
    }

    .pages-container {
        padding: 16px;
    }

    .pages-grid {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
        gap: 12px;
    }

    .upload-zone {
        padding: 40px 24px;
    }

    .upload-icon {
        width: 60px;
        height: 60px;
        font-size: 28px;
    }

    .upload-title {
        font-size: 18px;
    }

    .selection-bar {
        padding: 8px 16px;
        flex-wrap: wrap;
        gap: 8px;
    }

    .file-info-text h4 {
        max-width: 120px;
    }

    input[type="range"] {
        width: 70px;
    }

    .app-footer {
        padding: 8px 16px;
        flex-wrap: wrap;
        gap: 4px;
    }
}

@media (max-width: 480px) {
    .pages-grid {
        grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
        gap: 10px;
    }

    .toolbar-left, .toolbar-center, .toolbar-right {
        width: 100%;
        justify-content: center;
    }

    .btn span.btn-label {
        display: none;
    }
}

/* ===== UTILITY CLASSES ===== */
.hidden { display: none !important; }
.flex-center { display: flex; align-items: center; justify-content: center; }
