/* ============================================================
   EditPDF-TVTC — Styles
   Arabic RTL PDF Editor (Blur + Delete Pages)
   Design system matching the sister MergePDF-TVTC project
   ============================================================ */

/* ==============================================
   1. CSS Variables — Dark Theme (Default)
   ============================================== */
:root {
    /* Teal Palette */
    --teal-50: #e6f7f7;
    --teal-100: #b3e8e9;
    --teal-200: #80d9db;
    --teal-300: #4dcacd;
    --teal-400: #26bdc0;
    --teal-500: #1a9ca0;
    --teal-600: #158387;
    --teal-700: #106a6e;
    --teal-800: #0b5255;
    --teal-900: #063a3c;

    /* Gray Palette */
    --gray-50: #f5f5f6;
    --gray-100: #e0e1e3;
    --gray-200: #c2c4c7;
    --gray-300: #a3a6ab;
    --gray-400: #6b7078;
    --gray-500: #4a4f56;
    --gray-600: #3d4148;
    --gray-700: #30343a;
    --gray-800: #24272c;
    --gray-900: #18191e;

    /* Semantic Colors */
    --bg-primary: #0b0e11;
    --bg-secondary: #11151a;
    --bg-card: rgba(17, 25, 32, 0.7);
    --bg-card-hover: rgba(24, 35, 44, 0.8);
    --bg-input: rgba(255, 255, 255, 0.04);
    --text-primary: #eef2f5;
    --text-secondary: #a0b0ba;
    --text-muted: #627380;
    --border-color: rgba(26, 156, 160, 0.15);
    --border-hover: rgba(26, 156, 160, 0.3);

    /* Danger */
    --danger-400: #ef5350;
    --danger-500: #d32f2f;
    --danger-bg: rgba(211, 47, 47, 0.1);

    /* Success */
    --success-400: #66bb6a;
    --success-500: #43a047;
    --success-bg: rgba(67, 160, 71, 0.1);

    /* Warning */
    --warning-400: #ffa726;
    --warning-500: #f57f17;

    /* Radius */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    --radius-full: 9999px;

    /* Shadows */
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);
    --glow-teal: 0 0 20px rgba(26, 156, 160, 0.15);
    --glow-teal-strong: 0 0 30px rgba(26, 156, 160, 0.25);

    /* Extra tokens used by the Merge tab (scoped css/merge.css) */
    --shadow-glow-teal: 0 0 30px rgba(26, 156, 160, 0.15);
    --shadow-glow-gray: 0 0 30px rgba(100, 115, 125, 0.15);
    --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-base: 250ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-slow: 400ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-spring: 500ms cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* ==============================================
   Light Theme Override
   ============================================== */
[data-theme="light"] {
    --shadow-glow-teal: 0 0 30px rgba(26, 156, 160, 0.1);
    --shadow-glow-gray: 0 0 30px rgba(100, 115, 125, 0.08);
    --danger-bg: rgba(211, 47, 47, 0.08);
    --bg-primary: #f0f4f8;
    --bg-secondary: #e8ecf1;
    --bg-card: rgba(255, 255, 255, 0.85);
    --bg-card-hover: rgba(255, 255, 255, 0.95);
    --bg-input: rgba(0, 0, 0, 0.04);
    --text-primary: #1a2332;
    --text-secondary: #4a5568;
    --text-muted: #718096;
    --border-color: rgba(26, 156, 160, 0.2);
    --border-hover: rgba(26, 156, 160, 0.4);
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.08);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.12);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.16);
    --glow-teal: 0 0 20px rgba(26, 156, 160, 0.1);
}

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

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

/* ==============================================
   Lucide Icons General Styling
   ============================================== */
.lucide {
    width: 1.15em;
    height: 1.15em;
    stroke-width: 2px;
    display: inline-block;
    vertical-align: middle;
}

/* Align icons inside buttons and list headers */
.btn .lucide,
.tab .lucide,
.toast .lucide,
.footer-link .lucide,
.deleted-pages-info h3 .lucide,
.blur-regions h3 .lucide {
    margin-inline-end: 8px;
    vertical-align: -0.18em;
}

/* Adjustments for icons placed after text */
.btn .btn-next-icon {
    margin-inline-start: 8px !important;
    margin-inline-end: 0 !important;
}

/* Toast specific icon color */
.toast-success .lucide {
    color: var(--success-400);
}
.toast-error .lucide {
    color: var(--danger-400);
}
.toast-warning .lucide {
    color: var(--warning-400);
}

/* ==============================================
   3. Preloader
   ============================================== */
.preloader {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 9999;
    background: var(--bg-primary);
    display: flex;
    align-items: center;
    justify-content: center;
}

.preloader-spinner {
    width: 60px;
    height: 60px;
    border: 4px solid var(--border-color);
    border-top-color: var(--teal-500);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.preloader.hidden {
    opacity: 0;
    pointer-events: none;
    visibility: hidden;
    transition: opacity 0.5s ease, visibility 0.5s ease;
}

/* ==============================================
   4. Background Particles
   ============================================== */
.bg-particles {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 0;
    pointer-events: none;
}

.bg-particles::before {
    content: '';
    position: absolute;
    width: 500px;
    height: 500px;
    background: radial-gradient(circle, rgba(26, 156, 160, 0.08) 0%, transparent 70%);
    border-radius: 50%;
    top: -100px;
    right: -100px;
    animation: float1 20s ease-in-out infinite;
}

.bg-particles::after {
    content: '';
    position: absolute;
    width: 400px;
    height: 400px;
    background: radial-gradient(circle, rgba(107, 112, 120, 0.06) 0%, transparent 70%);
    border-radius: 50%;
    bottom: -100px;
    left: -100px;
    animation: float2 25s ease-in-out infinite;
}

/* ==============================================
   5. App Container
   ============================================== */
.app-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px 20px 40px;
    position: relative;
    z-index: 1;
    transition: max-width 0.3s ease;
}

/* Wider container when blur workspace is active */
.app-container.wide-mode {
    max-width: 1500px;
}

/* ==============================================
   6. Header
   ============================================== */
.app-header {
    text-align: center;
    padding: 40px 20px 30px;
    animation: fadeInUp 0.6s ease-out;
}

.header-logo {
    width: 90px;
    height: 90px;
    border-radius: 50%;
    border: 3px solid rgba(26, 156, 160, 0.3);
    object-fit: contain;
    background: white;
    padding: 8px;
    animation: logoFloat 4s ease-in-out infinite;
    box-shadow: var(--glow-teal);
}

.header-title {
    font-size: 1.8rem;
    font-weight: 800;
    background: linear-gradient(135deg, var(--teal-400), var(--gray-400));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-top: 18px;
}

.header-subtitle {
    font-size: 0.88rem;
    color: var(--text-muted);
    margin-top: 6px;
}

.header-credit {
    font-size: 0.78rem;
    color: var(--gray-500);
    font-weight: 500;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    margin-top: 10px;
}

.telegram-link {
    color: #229ED9;
    transition: color 0.3s ease;
    display: inline-flex;
    text-decoration: none;
}

.telegram-link:hover {
    color: #1a7fae;
    transform: scale(1.2);
}

.telegram-icon {
    width: 17px;
    height: 17px;
}

.header-privacy {
    font-size: 0.74rem;
    color: var(--teal-500);
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    margin-top: 8px;
    opacity: 0.9;
}

.privacy-icon {
    width: 14px;
    height: 14px;
}

/* ==============================================
   7. Theme Toggle
   ============================================== */
.top-actions {
    position: fixed;
    top: 20px;
    left: 20px;
    z-index: 100;
    display: flex;
    gap: 10px;
}

.top-action-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--bg-card);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid var(--border-color);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    color: var(--text-primary);
    transition: all 0.3s ease;
    box-shadow: var(--shadow-sm);
}

.top-action-btn:hover {
    background: var(--bg-card-hover);
    border-color: var(--border-hover);
    transform: scale(1.1);
}

.top-action-btn .lucide {
    width: 20px;
    height: 20px;
}

/* ==============================================
   8. Tabs
   ============================================== */
.tabs-container {
    display: flex;
    gap: 8px;
    justify-content: center;
    margin: 25px auto 30px;
    max-width: 800px;
    background: var(--bg-card);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-radius: var(--radius-lg);
    padding: 6px;
    border: 1px solid var(--border-color);
    animation: fadeInUp 0.7s ease-out;
}

.tab {
    flex: 1;
    padding: 10px 14px;
    border-radius: var(--radius-md);
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-family: 'Tajawal', sans-serif;
    font-size: 0.92rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    line-height: 1.3;
}

.tab span {
    text-align: center;
    display: inline-block;
}

.tab:hover {
    background: rgba(26, 156, 160, 0.08);
    color: var(--text-primary);
}

.tab.active {
    background: linear-gradient(135deg, var(--teal-500), var(--teal-600));
    color: white;
    box-shadow: 0 4px 15px rgba(26, 156, 160, 0.3);
}

.tab-content {
    display: none;
    animation: fadeInUp 0.4s ease-out;
}

.tab-content.active {
    display: block;
}

/* ==============================================
   9. Upload Area
   ============================================== */
.upload-area {
    background: var(--bg-card);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 2px dashed var(--border-color);
    border-radius: var(--radius-xl);
    padding: 60px 40px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    max-width: 700px;
    margin: 0 auto 30px;
}

.upload-area:hover {
    border-color: var(--teal-400);
    background: var(--bg-card-hover);
    transform: translateY(-2px);
    box-shadow: var(--glow-teal);
}

.upload-area.dragover {
    border-color: var(--teal-400);
    background: rgba(26, 156, 160, 0.05);
    transform: scale(1.02);
}

.upload-icon {
    display: block;
    margin-bottom: 15px;
}

.upload-icon .lucide {
    width: 64px;
    height: 64px;
    stroke-width: 1.5px;
    color: var(--teal-500);
}

.upload-title {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.upload-subtitle {
    font-size: 0.88rem;
    color: var(--text-muted);
}

/* ==============================================
   10. Workspace Card
   ============================================== */
.workspace {
    display: none;
    margin-bottom: 30px;
}

/* General hidden utility */
.hidden {
    display: none !important;
}

/* Upload area hidden */
.upload-area.hidden {
    display: none !important;
}

.workspace-card {
    background: var(--bg-card);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-radius: var(--radius-xl);
    border: 1px solid var(--border-color);
    padding: 25px;
    margin-bottom: 20px;
    animation: fadeInUp 0.5s ease-out;
}

/* ==============================================
   11. Toolbar
   ============================================== */
.toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
    padding: 15px 20px;
    background: var(--bg-card);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    margin-bottom: 20px;
}

.toolbar.justify-center {
    justify-content: center;
}

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

/* ==============================================
   12. Buttons
   ============================================== */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    border-radius: var(--radius-md);
    border: none;
    font-family: 'Tajawal', sans-serif;
    font-size: 0.9rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 250ms cubic-bezier(0.4, 0, 0.2, 1);
}

.btn:active {
    transform: scale(0.97);
}

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

.btn-sm {
    padding: 8px 16px;
    font-size: 0.8rem;
}

.btn-primary {
    background: linear-gradient(135deg, var(--teal-500), var(--teal-600));
    color: white;
}

.btn-primary:hover {
    background: linear-gradient(135deg, var(--teal-400), var(--teal-500));
    transform: translateY(-1px);
    box-shadow: 0 4px 15px rgba(26, 156, 160, 0.3);
}

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

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

.btn-danger {
    background: transparent;
    color: var(--danger-400);
    border: 1px solid rgba(211, 47, 47, 0.2);
}

.btn-danger:hover {
    background: var(--danger-bg);
    border-color: var(--danger-400);
}

.btn-success {
    background: linear-gradient(135deg, var(--success-500), #2e7d32);
    color: white;
}

.btn-success:hover {
    background: linear-gradient(135deg, var(--success-400), var(--success-500));
    transform: translateY(-1px);
    box-shadow: 0 4px 15px rgba(67, 160, 71, 0.3);
}

.btn-warning {
    background: transparent;
    color: var(--warning-400);
    border: 1px solid rgba(255, 167, 38, 0.2);
}

.btn-warning:hover {
    background: rgba(255, 167, 38, 0.1);
    border-color: var(--warning-400);
}

.btn-ghost {
    background: transparent;
    color: var(--teal-400);
    border: none;
}

.btn-ghost:hover {
    background: rgba(26, 156, 160, 0.1);
}

.btn-icon {
    width: 38px;
    height: 38px;
    padding: 0;
    justify-content: center;
}

/* ==============================================
   13. Thumbnail Grid (Delete Section)
   ============================================== */
.thumbnail-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    padding: 20px;
    justify-content: flex-start;
    /* Lay pages out left-to-right (1,2,3…) so SortableJS's grid logic, which
       assumes LTR, can compute drop positions correctly in every row. An RTL
       grid put page 1 at the top-right and broke SortableJS's first/last
       insertion checks, forcing any drop in the first row to position 1. */
    direction: ltr;
}

.thumbnail-card {
    position: relative;
    background: var(--bg-card);
    border-radius: var(--radius-md);
    border: 2px solid var(--border-color);
    overflow: hidden;
    cursor: pointer;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    width: 160px;
    flex: 0 0 160px;
    aspect-ratio: auto;
}

.thumbnail-card:hover {
    border-color: var(--teal-400);
    transform: translateY(-3px);
    box-shadow: var(--glow-teal);
    transition: transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

.thumbnail-card.selected {
    border-color: var(--danger-400);
    box-shadow: 0 0 20px rgba(239, 83, 80, 0.2);
}

.thumbnail-card.selected::after {
    content: '✕';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(211, 47, 47, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.5rem;
    font-weight: 900;
    color: white;
}

.thumbnail-card img {
    width: 100%;
    display: block;
    background: white;
}

.thumbnail-card .page-number {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(0, 0, 0, 0.7);
    color: white;
    text-align: center;
    padding: 6px;
    font-size: 0.8rem;
    font-weight: 600;
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
}

.thumbnail-card .drag-handle {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 28px;
    height: 28px;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 0.8rem;
    cursor: grab;
    opacity: 0;
    transition: opacity 0.3s ease;
    z-index: 2;
}

.thumbnail-card:hover .drag-handle {
    opacity: 1;
}

.thumbnail-card .drag-handle:active {
    cursor: grabbing;
}

.thumbnail-card .drag-handle .lucide {
    width: 16px;
    height: 16px;
    stroke-width: 2.5px;
}

/* SortableJS Classes & Drag-Drop Indicator */
.sortable-ghost {
    background: rgba(26, 156, 160, 0.03) !important;
    border: 2px dashed rgba(26, 156, 160, 0.4) !important;
    border-radius: var(--radius-md);
    box-shadow: none !important;
    position: relative;
    overflow: visible !important;
}

.sortable-ghost img,
.sortable-ghost .page-number,
.sortable-ghost .drag-handle,
.sortable-ghost::after {
    display: none !important;
}

.sortable-ghost::before {
    content: '';
    position: absolute;
    top: -5%;
    right: -10px; /* Centered in the 16px grid gap */
    height: 110%;
    width: 4px;
    background: var(--teal-500);
    border-radius: var(--radius-full);
    box-shadow: 0 0 12px rgba(26, 156, 160, 0.8);
    z-index: 10;
}

.sortable-chosen {
    box-shadow: var(--glow-teal-strong);
    transform: scale(1.02);
}

.sortable-drag {
    opacity: 0.95;
    transform: rotate(3deg) scale(1.06);
    box-shadow: var(--shadow-lg);
    z-index: 1000;
}

/* ==============================================
   14. Page Info Bar / Stats
   ============================================== */
.page-stats {
    display: flex;
    gap: 15px;
    align-items: center;
    justify-content: center;
    padding: 12px;
    background: var(--bg-card);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    font-size: 0.88rem;
}

.stat-item {
    display: flex;
    align-items: center;
    gap: 5px;
}

.stat-value {
    font-weight: 700;
    color: var(--teal-400);
}

.stat-separator {
    color: var(--border-color);
}

/* ==============================================
   15. Split Workspace Layout (Blur Section)
   ============================================== */
.workspace-split {
    display: flex;
    gap: 16px;
    align-items: flex-start;
    min-height: 500px;
}

/* Sidebar — tools & info panels (appears on the right in RTL) */
.workspace-sidebar {
    width: 370px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 12px;
    max-height: calc(100vh - 60px);
    overflow-y: auto;
    position: sticky;
    top: 20px;
    /* Custom scrollbar for sidebar */
    scrollbar-width: thin;
    scrollbar-color: var(--gray-600) transparent;
}

.workspace-sidebar::-webkit-scrollbar {
    width: 5px;
}

.workspace-sidebar::-webkit-scrollbar-track {
    background: transparent;
}

.workspace-sidebar::-webkit-scrollbar-thumb {
    background: var(--gray-600);
    border-radius: 4px;
}

/* Sidebar section cards */
.sidebar-section {
    background: var(--bg-card);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    padding: 16px;
    animation: fadeInUp 0.4s ease-out;
}

.sidebar-section-title {
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.sidebar-section-title .lucide {
    width: 16px;
    height: 16px;
    color: var(--teal-400);
}

.sidebar-section-title .count-badge {
    background: var(--teal-500);
    color: white;
    padding: 2px 10px;
    border-radius: var(--radius-full);
    font-size: 0.75rem;
    margin-inline-start: auto;
}

.sidebar-tools {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.sidebar-btn {
    width: 100%;
    justify-content: center;
}

/* Override blur-regions when inside sidebar */
.workspace-sidebar .blur-regions {
    margin-top: 0;
    padding: 16px;
}

.workspace-sidebar .blur-regions h3 {
    font-size: 0.9rem;
}

.workspace-sidebar .deleted-pages-info {
    margin-top: 0;
    padding: 16px;
}

/* Main canvas area — takes remaining space */
.workspace-main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

/* Canvas container — fit page within viewport */
.canvas-container {
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    padding: 20px;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 400px;
    max-height: calc(100vh - 130px);
    position: relative;
    border: 1px solid var(--border-color);
    overflow: hidden;
}

#pdfCanvas {
    max-width: 100%;
    max-height: calc(100vh - 170px);
    width: auto;
    height: auto;
    object-fit: contain;
    box-shadow: var(--shadow-lg);
    background: white;
    border-radius: 4px;
}

#pdfCanvas.blur-mode {
    cursor: crosshair;
}

#pdfCanvas.normal-mode {
    cursor: default;
}

.deleted-overlay {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(211, 47, 47, 0.9);
    color: white;
    padding: 25px 40px;
    border-radius: var(--radius-lg);
    font-size: 1.3rem;
    font-weight: 700;
    box-shadow: var(--shadow-lg);
    z-index: 10;
    text-align: center;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.page-nav-info {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--bg-input);
    padding: 8px 16px;
    border-radius: var(--radius-md);
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text-primary);
}

.page-nav-info.deleted-page {
    background: var(--danger-bg);
    color: var(--danger-400);
    border: 1px solid rgba(211, 47, 47, 0.3);
}

/* ==============================================
   16. Blur Regions List
   ============================================== */
.blur-regions {
    background: var(--bg-card);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    padding: 20px;
    margin-top: 20px;
}

.blur-regions h3 {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.blur-regions h3 .count-badge {
    background: var(--teal-500);
    color: white;
    padding: 2px 10px;
    border-radius: var(--radius-full);
    font-size: 0.8rem;
}

.blur-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 10px;
    background: var(--bg-input);
    border-radius: var(--radius-sm);
    margin-bottom: 6px;
    border-right: 3px solid var(--teal-500);
    gap: 8px;
}

.blur-item-info {
    font-size: 0.82rem;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
}

.btn-icon-sm {
    width: 28px;
    height: 28px;
    padding: 0 !important;
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    flex-shrink: 0;
}

.btn-icon-sm .lucide,
.btn-icon-sm svg {
    margin: 0 !important;
    width: 14px;
    height: 14px;
    vertical-align: middle;
}

.deleted-pages-info {
    background: var(--bg-card);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    padding: 20px;
    margin-top: 20px;
}

.deleted-pages-info h3 {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.deleted-pages-info .count-badge {
    background: var(--danger-400);
    color: white;
    padding: 2px 10px;
    border-radius: var(--radius-full);
    font-size: 0.8rem;
}

.danger-badge {
    background: var(--danger-400) !important;
}

.deleted-pages-info .blur-item {
    border-right-color: var(--danger-400);
}

.deleted-page-badge {
    display: inline-block;
    background: var(--danger-bg);
    color: var(--danger-400);
    border: 1px solid rgba(211, 47, 47, 0.3);
    border-radius: var(--radius-full);
    padding: 4px 12px;
    font-size: 0.82rem;
    font-weight: 600;
    margin: 4px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.deleted-page-badge:hover {
    background: var(--danger-400);
    color: white;
}

/* Active state for blur tool button */
.btn.active {
    background: var(--warning-400) !important;
    color: #000 !important;
    border-color: var(--warning-400) !important;
}

.deleted-page-info {
    background: var(--danger-bg) !important;
    color: var(--danger-400) !important;
    border: 1px solid rgba(211, 47, 47, 0.3) !important;
}

/* Thumbnail loader */
.thumbnail-loader {
    text-align: center;
    padding: 40px;
    color: var(--text-muted);
    grid-column: 1 / -1;
}

.thumbnail-loader .spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border-color);
    border-top-color: var(--teal-500);
    border-radius: 50%;
    margin: 0 auto 12px;
    animation: spin 0.8s linear infinite;
}

/* ==============================================
   17. Compress Options
   ============================================== */
.compress-section {
    background: var(--bg-card);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    padding: 20px;
    margin-top: 20px;
}

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

.switch {
    position: relative;
    width: 48px;
    height: 26px;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    background: var(--bg-input);
    border-radius: var(--radius-full);
    border: 1px solid var(--border-color);
    cursor: pointer;
    transition: all 0.3s ease;
    outline: none;
}

.switch:checked {
    background: var(--teal-500);
    border-color: var(--teal-500);
}

.switch::before {
    content: '';
    position: absolute;
    top: 2px;
    right: 2px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: white;
    transition: transform 0.3s ease;
}

.switch:checked::before {
    transform: translateX(-20px);
}

.compress-options {
    margin-top: 15px;
    padding-top: 15px;
    border-top: 1px solid var(--border-color);
}

.compress-options.hidden {
    display: none;
}

.input-group {
    display: flex;
    align-items: center;
    gap: 10px;
}

.input-field {
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 8px 14px;
    color: var(--text-primary);
    font-family: 'Tajawal', sans-serif;
    font-size: 0.9rem;
    width: 80px;
    text-align: center;
}

.input-field:focus {
    border-color: var(--teal-400);
    outline: none;
    box-shadow: 0 0 0 3px rgba(26, 156, 160, 0.1);
}

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

/* ==============================================
   18. Progress Section
   ============================================== */
.progress-section {
    text-align: center;
    padding: 40px 20px;
}

.progress-section.hidden {
    display: none;
}

.progress-ring-container {
    position: relative;
    width: 120px;
    height: 120px;
    margin: 0 auto 20px;
}

.progress-ring circle {
    fill: none;
    stroke-width: 8;
}

.progress-ring .ring-bg {
    stroke: var(--bg-input);
}

.progress-ring .ring-fill {
    stroke: var(--teal-500);
    stroke-linecap: round;
    transition: stroke-dashoffset 0.5s ease;
}

.progress-percent {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--teal-400);
}

.progress-bar-container {
    width: 100%;
    max-width: 500px;
    margin: 15px auto;
    height: 6px;
    background: var(--bg-input);
    border-radius: var(--radius-full);
    overflow: hidden;
}

.progress-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--teal-500), var(--gray-400));
    border-radius: var(--radius-full);
    transition: width 0.5s ease;
}

.progress-detail {
    font-size: 0.88rem;
    color: var(--text-secondary);
    margin-top: 10px;
}

/* ==============================================
   19. Toast Notifications
   ============================================== */
.toast-container {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 10000;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    background: var(--bg-card);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-radius: var(--radius-md);
    padding: 14px 20px;
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-lg);
    color: var(--text-primary);
    font-size: 0.88rem;
    font-weight: 500;
    animation: toastIn 0.3s ease-out;
    max-width: 400px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.toast.toast-success {
    border-color: rgba(67, 160, 71, 0.3);
}

.toast.toast-error {
    border-color: rgba(211, 47, 47, 0.3);
}

.toast.toast-out {
    animation: toastOut 0.3s ease-in forwards;
}

/* ==============================================
   20. Instructions Box
   ============================================== */
.instructions {
    background: var(--bg-card);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    border-right: 4px solid var(--warning-400);
    padding: 18px 22px;
    margin-bottom: 20px;
}

.instructions h4 {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--warning-400);
    margin-bottom: 10px;
}

.instructions ul {
    margin-right: 20px;
    list-style-type: disc;
}

.instructions li {
    margin-bottom: 6px;
    font-size: 0.85rem;
    color: var(--text-secondary);
    line-height: 1.6;
}

/* ==============================================
   21. Footer
   ============================================== */
.app-footer {
    text-align: center;
    padding: 30px 20px;
    margin-top: 40px;
}

.footer-copy {
    font-size: 0.78rem;
    color: var(--text-muted);
}

.footer-link {
    color: var(--teal-400);
    text-decoration: none;
    transition: color 0.3s ease;
}

.footer-link:hover {
    color: var(--teal-300);
}

.version-badge {
    display: inline-block;
    margin-top: 8px;
    font-size: 0.7rem;
    padding: 3px 10px;
    border-radius: var(--radius-full);
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    color: var(--text-muted);
}

/* ==============================================
   22. Animations
   ============================================== */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes logoFloat {
    0%, 100% {
        transform: translateY(0);
    }
    50% {
        transform: translateY(-6px);
    }
}

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

@keyframes float1 {
    0%, 100% {
        transform: translate(0, 0);
    }
    33% {
        transform: translate(30px, -30px);
    }
    66% {
        transform: translate(-20px, 20px);
    }
}

@keyframes float2 {
    0%, 100% {
        transform: translate(0, 0);
    }
    33% {
        transform: translate(-30px, 20px);
    }
    66% {
        transform: translate(20px, -30px);
    }
}

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

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

/* ==============================================
   23. Responsive Design
   ============================================== */

/* Medium screens — collapse split layout to vertical */
@media (max-width: 992px) {
    .workspace-split {
        flex-direction: column;
        min-height: auto;
    }

    .workspace-sidebar {
        width: 100%;
        max-height: none;
        position: static;
        flex-direction: row;
        flex-wrap: wrap;
        gap: 12px;
        overflow-y: visible;
    }

    .sidebar-section {
        flex: 1;
        min-width: 250px;
    }

    .sidebar-tools {
        flex-direction: row;
        flex-wrap: wrap;
    }

    .sidebar-btn {
        width: auto;
        flex: 1;
        min-width: 140px;
    }

    .workspace-main {
        order: -1; /* Canvas appears first on mobile */
    }

    .canvas-container {
        max-height: calc(100vh - 200px);
    }

    #pdfCanvas {
        max-height: calc(100vh - 240px);
    }
}

/* Small screens */
@media (max-width: 768px) {
    .app-container {
        padding: 10px 10px 30px;
    }

    .header-title {
        font-size: 1.4rem;
    }

    .tabs-container {
        flex-direction: column;
        gap: 6px;
    }

    .tab {
        padding: 12px 16px;
        font-size: 0.88rem;
    }

    .toolbar {
        flex-direction: column;
        gap: 10px;
    }

    .toolbar-group {
        width: 100%;
        justify-content: center;
    }

    .thumbnail-grid {
        gap: 10px;
        padding: 12px;
    }

    .thumbnail-card {
        width: 120px;
        flex: 0 0 120px;
    }

    .upload-area {
        padding: 40px 20px;
        margin: 0 10px;
    }

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

    .canvas-container {
        padding: 10px;
        min-height: 350px;
    }

    .sidebar-section {
        min-width: 100%;
    }

    .sidebar-btn {
        min-width: 100%;
    }
}

@media (max-width: 480px) {
    .thumbnail-card {
        width: 100px;
        flex: 0 0 100px;
    }

    .header-title {
        font-size: 1.2rem;
    }
}

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

::-webkit-scrollbar-track {
    background: var(--bg-secondary);
}

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

::-webkit-scrollbar-thumb:hover {
    background: var(--gray-500);
}

/* ==============================================
   25. Loading Overlay (Save Operations)
   ============================================== */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(11, 14, 17, 0.85);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 9000;
    gap: 20px;
}

.loading-overlay.hidden {
    display: none;
}

.loading-overlay p {
    color: var(--text-secondary);
    font-size: 0.95rem;
}

/* ==============================================
   26. Help Modal Styling
   ============================================== */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    transition: all 0.3s ease;
}

.modal.hidden {
    opacity: 0;
    pointer-events: none;
    display: none !important;
}

.modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
}

.modal-content {
    position: relative;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    backdrop-filter: blur(25px);
    -webkit-backdrop-filter: blur(25px);
    border-radius: var(--radius-xl);
    width: 100%;
    max-width: 600px;
    box-shadow: var(--shadow-lg);
    z-index: 10;
    animation: modalIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    padding: 30px;
    direction: rtl;
}

.modal.hidden .modal-content {
    transform: scale(0.9);
}

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

.modal-close {
    position: absolute;
    top: 20px;
    left: 20px;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.modal-close:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
}

.modal-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 20px;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 15px;
}

.modal-header-icon {
    color: var(--warning-400);
    width: 24px;
    height: 24px;
}

.modal-title {
    font-size: 1.2rem;
    font-weight: 800;
    color: var(--text-primary);
}

.modal-body {
    max-height: 70vh;
    overflow-y: auto;
    padding-inline-end: 8px;
}

.help-sectionHelp h4 {
    font-size: 1rem;
    font-weight: 700;
    color: var(--warning-400);
    margin-bottom: 15px;
}

.help-sectionHelp ul {
    list-style-type: disc;
    margin-right: 20px;
}

.help-sectionHelp li {
    font-size: 0.9rem;
    color: var(--text-secondary);
    line-height: 1.7;
    margin-bottom: 10px;
}

.help-sectionHelp strong {
    color: var(--text-primary);
}

/* ==============================================
   27. Top Action Bar (Save, Stats, Compress)
   ============================================== */
.top-action-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
    background: var(--bg-card);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    margin-bottom: 15px;
    animation: fadeInUp 0.5s ease-out;
}

/* Inline compress section styling */
.compress-inline {
    display: flex;
    align-items: center;
    gap: 16px;
}

.compress-inline .compress-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
}

.compress-inline .compress-options {
    animation: fadeIn 0.25s ease;
}

.compress-inline .compress-options.hidden {
    display: none !important;
}

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

/* Stats inline adjustments */
.page-stats-inline {
    display: flex;
    gap: 15px;
    align-items: center;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.page-stats-inline .stat-item {
    display: flex;
    align-items: center;
    gap: 6px;
}

.page-stats-inline .stat-value {
    font-weight: 700;
    color: var(--teal-400);
}

.page-stats-inline .stat-separator {
    color: var(--border-color);
}

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

/* Responsive top bar */
@media (max-width: 992px) {
    .top-action-bar {
        flex-direction: column;
        gap: 16px;
        padding: 16px;
        border-radius: var(--radius-lg);
    }
    
    .bottom-actions-group {
        width: 100%;
        justify-content: space-between;
        flex-wrap: wrap;
        gap: 10px;
    }
    
    .compress-inline {
        width: 100%;
        justify-content: space-between;
    }
    
    .page-stats-inline {
        width: 100%;
        justify-content: center;
        border-bottom: 1px solid var(--border-color);
        padding-bottom: 10px;
    }
}

/* ── Browser recommendation notice (non-Chromium browsers) ── */
.browser-notice {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 0 0 20px;
    padding: 14px 18px;
    border-radius: var(--radius-md, 12px);
    background: linear-gradient(135deg, rgba(239, 83, 80, 0.12), rgba(255, 167, 38, 0.12));
    border: 1px solid rgba(239, 83, 80, 0.35);
    color: var(--text-primary);
    font-size: 0.95rem;
    line-height: 1.6;
    box-shadow: var(--shadow-sm, 0 2px 8px rgba(0, 0, 0, 0.2));
    animation: slideDown 0.4s ease both;
}
.browser-notice.hidden { display: none; }
.browser-notice-icon {
    flex-shrink: 0;
    display: inline-flex;
    color: #ef5350;
}
.browser-notice-icon svg { width: 24px; height: 24px; }
.browser-notice-text { flex: 1; }
.browser-notice-text strong { color: #1a9ca0; font-weight: 700; }
.browser-notice-close {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
}
.browser-notice-close:hover {
    background: rgba(239, 83, 80, 0.15);
    color: #ef5350;
}
.browser-notice-close svg { width: 18px; height: 18px; }
@media (max-width: 640px) {
    .browser-notice { font-size: 0.85rem; padding: 12px 14px; gap: 10px; }
    .browser-notice-icon svg { width: 20px; height: 20px; }
}

/* ── Password modal (encrypted PDFs) ── */
.pw-modal-content { max-width: 420px; }
.pw-modal-msg {
    margin: 0 0 16px;
    color: var(--text-secondary);
    font-size: 0.95rem;
    line-height: 1.6;
}
.pw-modal-input {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm, 8px);
    background: var(--bg-input);
    color: var(--text-primary);
    font-size: 1rem;
    font-family: inherit;
    margin-bottom: 18px;
    box-sizing: border-box;
}
.pw-modal-input:focus {
    outline: none;
    border-color: var(--teal-500, #1a9ca0);
    box-shadow: 0 0 0 3px rgba(26, 156, 160, 0.15);
}
.pw-modal-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-start;
}
.pw-modal-actions .btn { flex: 1; justify-content: center; }
