/* ===== 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;
    --danger: #FF6B6B;
    --danger-dark: #EE5A5A;
    --success: #00B894;
    --warning: #FDCB6E;
    --bg-dark: #0F0F1A;
    --bg-card: #1A1A2E;
    --bg-card-hover: #222240;
    --bg-surface: #16213E;
    --text-primary: #EAEAEA;
    --text-secondary: #A0A0B8;
    --text-muted: #6C6C80;
    --border: #2A2A45;
    --border-light: #3A3A5A;
    --shadow: rgba(0, 0, 0, 0.4);
    --radius: 12px;
    --radius-lg: 20px;
    --transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

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

/* ===== APP LAYOUT ===== */
.app-container {
    display: flex;
    flex-direction: column;
    width: 100vw;
    height: 100vh;
    overflow: hidden;
}

/* ===== HEADER ===== */
.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 24px;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    z-index: 100;
}

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

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

.logo-text h1 {
    font-size: 20px;
    font-weight: 700;
    background: linear-gradient(135deg, var(--primary-light), var(--accent));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.logo-text p {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: -2px;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.header-info {
    display: flex;
    align-items: center;
    gap: 16px;
    font-size: 13px;
    color: var(--text-secondary);
}

.file-info-badge {
    display: none;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    background: var(--bg-surface);
    border-radius: 20px;
    border: 1px solid var(--border);
    font-size: 12px;
}

.file-info-badge.visible {
    display: flex;
}

.file-info-badge .dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--success);
}

/* ===== BUTTONS ===== */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    text-decoration: none;
    white-space: nowrap;
    font-family: inherit;
}

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

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

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

.btn-accent {
    background: linear-gradient(135deg, var(--accent), var(--accent-dark));
    color: white;
    box-shadow: 0 4px 15px rgba(0, 206, 201, 0.3);
}

.btn-accent:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(0, 206, 201, 0.4);
}

.btn-danger {
    background: linear-gradient(135deg, var(--danger), var(--danger-dark));
    color: white;
}

.btn-danger:hover:not(:disabled) {
    transform: translateY(-1px);
}

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

.btn-outline:hover:not(:disabled) {
    background: var(--bg-card-hover);
    border-color: var(--border-light);
    color: var(--text-primary);
}

.btn-sm {
    padding: 6px 14px;
    font-size: 12px;
}

.btn-lg {
    padding: 14px 32px;
    font-size: 16px;
    border-radius: 12px;
}

.btn-icon {
    width: 38px;
    height: 38px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
}

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

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

.upload-zone {
    width: 100%;
    max-width: 640px;
    padding: 60px 40px;
    border: 2px dashed var(--border-light);
    border-radius: var(--radius-lg);
    text-align: center;
    cursor: pointer;
    transition: var(--transition);
    background: var(--bg-card);
    position: relative;
}

.upload-zone:hover,
.upload-zone.drag-over {
    border-color: var(--primary);
    background: rgba(108, 92, 231, 0.05);
    transform: scale(1.01);
}

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

.upload-icon {
    width: 80px;
    height: 80px;
    margin: 0 auto 20px;
    background: linear-gradient(135deg, rgba(108, 92, 231, 0.15), rgba(0, 206, 201, 0.15));
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 36px;
}

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

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

.upload-zone .file-types {
    font-size: 12px;
    color: var(--text-muted);
}

#fileInput {
    display: none;
}

/* ===== WORKSPACE (after file loaded) ===== */
.workspace {
    display: none;
    flex: 1;
    overflow: hidden;
}

.workspace.active {
    display: flex;
    flex-direction: column;
}

/* ===== TOOLBAR ===== */
.toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 24px;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    gap: 12px;
    flex-shrink: 0;
    flex-wrap: wrap;
}

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

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

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

.split-mode-group {
    display: flex;
    background: var(--bg-surface);
    border-radius: 8px;
    border: 1px solid var(--border);
    overflow: hidden;
}

.split-mode-btn {
    padding: 8px 16px;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    font-family: inherit;
}

.split-mode-btn:hover {
    color: var(--text-primary);
    background: rgba(255,255,255,0.05);
}

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

.range-input-group {
    display: none;
    align-items: center;
    gap: 6px;
}

.range-input-group.visible {
    display: flex;
}

.range-input-group input {
    width: 100px;
    padding: 7px 12px;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 13px;
    font-family: inherit;
}

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

.range-input-group label {
    font-size: 12px;
    color: var(--text-secondary);
}

.chunk-size-group {
    display: none;
    align-items: center;
    gap: 6px;
}

.chunk-size-group.visible {
    display: flex;
}

.chunk-size-group input {
    width: 60px;
    padding: 7px 12px;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 13px;
    text-align: center;
    font-family: inherit;
}

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

.chunk-size-group label {
    font-size: 12px;
    color: var(--text-secondary);
}

.select-actions {
    display: flex;
    align-items: center;
    gap: 4px;
}

.selection-count {
    font-size: 12px;
    color: var(--text-muted);
    padding: 0 8px;
}

/* ===== PAGE GRID ===== */
.pages-container {
    flex: 1;
    overflow-y: auto;
    padding: 20px 24px;
    background: var(--bg-dark);
}

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

.pages-container::-webkit-scrollbar-track {
    background: var(--bg-dark);
}

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

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

.pages-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 16px;
    max-width: 1600px;
    margin: 0 auto;
}

/* ===== PAGE CARD ===== */
.page-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    border: 2px solid transparent;
    overflow: hidden;
    cursor: pointer;
    transition: var(--transition);
    position: relative;
    user-select: none;
}

.page-card:hover {
    border-color: var(--border-light);
    transform: translateY(-2px);
    box-shadow: 0 8px 25px var(--shadow);
}

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

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

.page-card.selected .page-check svg {
    opacity: 1;
}

.page-check {
    position: absolute;
    top: 8px;
    left: 8px;
    width: 24px;
    height: 24px;
    border-radius: 6px;
    border: 2px solid var(--border-light);
    background: rgba(26, 26, 46, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 5;
    transition: var(--transition);
    backdrop-filter: blur(4px);
}

.page-check svg {
    width: 14px;
    height: 14px;
    opacity: 0;
    transition: var(--transition);
    stroke: white;
    fill: none;
    stroke-width: 3;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.page-thumb-wrapper {
    position: relative;
    width: 100%;
    padding-top: 141.4%;
    background: #252540;
    overflow: hidden;
}

.page-thumb-wrapper canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.page-thumb-placeholder {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    font-size: 13px;
}

.page-label {
    padding: 8px 10px;
    text-align: center;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    background: var(--bg-card);
}

.page-card.selected .page-label {
    color: var(--primary-light);
}

/* ===== BOTTOM BAR ===== */
.bottom-bar {
    display: none;
    align-items: center;
    justify-content: space-between;
    padding: 12px 24px;
    background: var(--bg-card);
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

.bottom-bar.active {
    display: flex;
}

.bottom-info {
    display: flex;
    align-items: center;
    gap: 16px;
    font-size: 13px;
    color: var(--text-secondary);
}

.bottom-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

/* ===== PROGRESS OVERLAY ===== */
.progress-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 15, 26, 0.9);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(8px);
}

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

.progress-card {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: 40px 50px;
    text-align: center;
    min-width: 400px;
    border: 1px solid var(--border);
    box-shadow: 0 20px 60px var(--shadow);
}

.progress-spinner {
    width: 64px;
    height: 64px;
    border: 4px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 20px;
}

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

.progress-card h3 {
    font-size: 18px;
    margin-bottom: 8px;
}

.progress-card p {
    color: var(--text-secondary);
    font-size: 14px;
    margin-bottom: 20px;
}

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

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

/* ===== TOAST NOTIFICATION ===== */
.toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.toast {
    padding: 14px 20px;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 500;
    color: white;
    box-shadow: 0 8px 30px var(--shadow);
    animation: slideInRight 0.3s ease;
    display: flex;
    align-items: center;
    gap: 10px;
    max-width: 400px;
}

.toast.success {
    background: linear-gradient(135deg, #00B894, #00a884);
}

.toast.error {
    background: linear-gradient(135deg, #FF6B6B, #EE5A5A);
}

.toast.info {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
}

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

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

/* ===== MODAL ===== */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 15, 26, 0.85);
    z-index: 1500;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(6px);
}

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

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

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

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

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

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

/* ===== PREVIEW MODAL ===== */
.preview-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 15, 26, 0.92);
    z-index: 1600;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(8px);
}

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

.preview-content {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: 20px;
    max-width: 90vw;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    border: 1px solid var(--border);
    box-shadow: 0 20px 60px var(--shadow);
}

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

.preview-header h3 {
    font-size: 16px;
}

.preview-body {
    overflow: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    max-height: 75vh;
}

.preview-body canvas {
    max-width: 100%;
    max-height: 70vh;
    border-radius: 8px;
    box-shadow: 0 4px 20px var(--shadow);
}

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
    .app-header {
        padding: 10px 16px;
    }
    
    .logo-text p {
        display: none;
    }
    
    .toolbar {
        padding: 8px 16px;
    }
    
    .pages-container {
        padding: 12px 16px;
    }
    
    .pages-grid {
        grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
        gap: 10px;
    }
    
    .upload-zone {
        padding: 40px 24px;
    }
    
    .upload-icon {
        width: 60px;
        height: 60px;
        font-size: 28px;
    }
    
    .upload-zone h2 {
        font-size: 18px;
    }
    
    .bottom-bar {
        flex-direction: column;
        gap: 10px;
        padding: 10px 16px;
    }
    
    .progress-card {
        min-width: auto;
        padding: 30px 24px;
        margin: 0 16px;
    }

    .modal-box {
        padding: 24px;
        margin: 0 16px;
    }

    .header-info {
        display: none;
    }

    .split-mode-btn {
        padding: 6px 10px;
        font-size: 12px;
    }

    .btn {
        padding: 8px 14px;
        font-size: 13px;
    }

    .btn-lg {
        padding: 12px 24px;
        font-size: 14px;
    }
}

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

    .toolbar-left {
        width: 100%;
    }

    .toolbar-right {
        width: 100%;
        justify-content: flex-end;
    }

    .toolbar-center {
        width: 100%;
    }
}

/* ===== LOADING SHIMMER ===== */
.shimmer {
    background: linear-gradient(90deg, #252540 25%, #2d2d50 50%, #252540 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
}

@keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* ===== HIDDEN UTILITY ===== */
.hidden {
    display: none !important;
}
