/* ═══ Globals ═══ */
.hidden { display: none !important; }
.hero { padding: 40px 40px 80px; }
svg { fill: none; }
body { overflow-x: hidden; }
body.download-active { height: calc(100vh - 81px); overflow: hidden; }
body.reorder-active { overflow-y: auto; }

/* ── Fullscreen drop zone (matches add-restrictions / OCR / compress) ── */
.drop-zone-overlay {
    position: fixed;
    inset: 0;
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s ease;
}
.drop-zone-overlay.active { opacity: 1; pointer-events: all; }
.dz-bg {
    position: absolute;
    inset: 0;
    background: rgba(255, 255, 255, 0.92);
    box-sizing: border-box;
}
.dz-bg::before {
    content: '';
    position: absolute;
    inset: 14px;
    border-radius: 16px;
    background-image:
        repeating-linear-gradient(0deg,   #1f2937 0, #1f2937 8px, transparent 8px, transparent 16px),
        repeating-linear-gradient(90deg,  #1f2937 0, #1f2937 8px, transparent 8px, transparent 16px),
        repeating-linear-gradient(180deg, #1f2937 0, #1f2937 8px, transparent 8px, transparent 16px),
        repeating-linear-gradient(270deg, #1f2937 0, #1f2937 8px, transparent 8px, transparent 16px);
    background-size: 2px 100%, 100% 2px, 2px 100%, 100% 2px;
    background-position: 0 0, 0 0, 100% 0, 0 100%;
    background-repeat: no-repeat;
    opacity: 0.14;
    animation: dzMarch 0.8s linear infinite;
}
@keyframes dzMarch {
    to { background-position: 0 16px, -16px 0, 100% -16px, 16px 100%; }
}
.dz-pill {
    position: relative;
    z-index: 1;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    background: #1f2937;
    color: rgba(255, 255, 255, 0.9);
    font-size: 0.85rem;
    font-weight: 500;
    border-radius: 10px;
    transform: translateY(6px);
    opacity: 0;
    transition: transform 0.3s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.2s ease;
}
.dz-pill svg {
    flex-shrink: 0;
    width: 15px;
    height: 15px;
    stroke: rgba(255, 255, 255, 0.7);
    animation: dzPulse 1.8s ease-in-out infinite;
}
.drop-zone-overlay.active .dz-pill { transform: translateY(0); opacity: 1; }
@keyframes dzPulse {
    0%, 100% { opacity: 0.7; transform: scale(1); }
    50%      { opacity: 1;   transform: scale(1.1); }
}

/* Locked-PDF state — modifier on the shared error modal (mirrors compress-pdf).
   Swaps the icon to a grey lock + amber badge, demotes the Cancel button to a
   secondary outline, and reveals an "Unlock PDF" primary CTA via
   #rateLimitActions. */
.error-modal-overlay.locked-pdf .error-modal-icon > svg {
    stroke: #9ca3af;
}
.error-modal-icon-badge {
    position: absolute;
    bottom: -2px;
    right: -2px;
    background: #fff;
    border-radius: 8px;
    padding: 4px;
    box-sizing: content-box;
    width: 14px;
    height: 14px;
    color: #f59e0b;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
    display: flex;
    align-items: center;
    justify-content: center;
}
.error-modal-icon {
    position: relative;
}
.error-modal-icon-badge svg {
    width: 18px;
    height: 18px;
    stroke: currentColor;
    animation: none;
}
.rate-limit-actions {
    display: none;
    width: 100%;
    margin-bottom: 10px;
}
.rate-limit-actions.active { display: block; }
.upgrade-btn {
    display: inline-block;
    background: #1f2937;
    color: white;
    border: none;
    border-radius: 14px;
    padding: 12px;
    font-size: 0.88rem;
    font-weight: 700;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.15s;
    text-decoration: none;
    width: 100%;
    box-sizing: border-box;
}
.upgrade-btn:hover { background: #374151; }
.error-modal-overlay.locked-pdf .error-modal-btn {
    background: transparent;
    color: #6b7280;
    border: 2px solid #e5e7eb;
    box-shadow: none;
}
.error-modal-overlay.locked-pdf .error-modal-btn:hover {
    border-color: #ff6154;
    color: #ff6154;
    background: #fff5f4;
    box-shadow: none;
}

/* Generic confirm modal — used for bulk-delete + last-page warnings. */
.organize-confirm-overlay {
    position: fixed;
    inset: 0;
    z-index: 10010;
    background: rgba(15, 23, 42, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    animation: organizeConfirmFade 0.15s ease;
}
.organize-confirm-overlay.hidden { display: none !important; }
@keyframes organizeConfirmFade { from { opacity: 0; } to { opacity: 1; } }
.organize-confirm-card {
    width: 380px;
    max-width: 100%;
    background: #fff;
    border-radius: 14px;
    padding: 22px 22px 18px;
    box-shadow: 0 24px 60px rgba(15, 23, 42, 0.28),
                0 6px 16px rgba(15, 23, 42, 0.12);
    animation: organizeConfirmPop 0.18s cubic-bezier(0.32, 0.72, 0, 1);
}
@keyframes organizeConfirmPop {
    from { opacity: 0; transform: translateY(8px) scale(0.985); }
    to   { opacity: 1; transform: translateY(0)   scale(1); }
}
.organize-confirm-title {
    margin: 0 0 6px;
    font-size: 16px;
    font-weight: 700;
    color: #0f172a;
    letter-spacing: -0.01em;
}
.organize-confirm-message {
    margin: 0 0 18px;
    font-size: 13.5px;
    color: #64748b;
    line-height: 1.5;
}
.organize-confirm-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}
.organize-confirm-cancel,
.organize-confirm-ok {
    height: 36px;
    padding: 0 14px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    border: 1.5px solid;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.organize-confirm-cancel {
    background: #fff;
    border-color: #e5e7eb;
    color: #475569;
}
.organize-confirm-cancel:hover {
    background: #f9fafb;
    border-color: #d1d5db;
    color: #1f2937;
}
.organize-confirm-ok {
    background: #ff3b30;
    border-color: #ff3b30;
    color: #fff;
}
.organize-confirm-ok:hover {
    background: #e5342a;
    border-color: #e5342a;
}

/* Bottom-center toast (mirrors flatten's .encrypted-toast) */
.organize-toast {
    position: fixed;
    bottom: 32px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    display: inline-flex;
    align-items: center;
    gap: 10px;
    color: #fff;
    background: #1f2937;
    border-radius: 12px;
    padding: 12px 20px;
    font-size: 0.85rem;
    font-weight: 500;
    opacity: 0;
    transition: opacity 0.25s ease, transform 0.25s ease;
    pointer-events: none;
    z-index: 9000;
    box-shadow: 0 8px 24px rgba(0,0,0,0.15);
}
.organize-toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
    pointer-events: auto;
}
.organize-toast svg { color: rgba(255,255,255,0.6); flex-shrink: 0; }

.container {
    background-color: transparent;
    box-sizing: border-box;
    padding: 20px;
    border-radius: 16px;
    max-width: 1400px;
    width: 100%;
    margin: 0 auto 10px auto;
    overflow: visible;
}

/* Import-screen vertical centering — body flex column at step 1
   with auto margins on hero + container so they center as a pair.
   Matches step-based tools' rhythm for cross-tool consistency.
   Organize-pdf uses selection-mode (page picker), reorder-active
   (drag reorder mode), and download-active. Step 1 = none. */
body:not(.selection-mode):not(.reorder-active):not(.download-active) {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}
body:not(.selection-mode):not(.reorder-active):not(.download-active) .hero {
    margin-top: auto;
}
body:not(.selection-mode):not(.reorder-active):not(.download-active) .container {
    margin-bottom: auto;
}

/* ═══ Upload Area ═══ */
.upload-area {
    display: flex;
    justify-content: center;
    align-items: center;
    margin-bottom: 1.5rem;
    gap: 12px;
    flex-wrap: wrap;
}

.file-input-label {
    display: inline-block;
    padding: 16px 48px;
    background-color: #ff6154;
    color: white;
    border-radius: 12px;
    cursor: pointer;
    font-size: 1.1rem;
    font-weight: 600;
    transition: all 0.3s ease;
    border: none;
    text-align: center;
    flex-shrink: 0;
}

.file-input-label:hover {
    background: #e5554a;
    box-shadow: 0 4px 12px rgba(255, 97, 84, 0.4);
    transform: translateY(-1px);
}

#upload-label.drag-over { background-color: #e5554a; transform: scale(1.05); }
#upload-label { outline: none; }

.upload-content {
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.upload-icon {
    position: absolute;
    width: 24px;
    height: 24px;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.upload-text {
    font-size: 1.1rem;
    font-weight: 600;
    color: white;
    margin: 0;
    transition: opacity 0.3s ease;
}

.file-input-label:hover .upload-icon { opacity: 1; }
.file-input-label:hover .upload-text { opacity: 0; visibility: hidden; }
input[type="file"] { display: none; }

/* ═══ Loading Screen ═══ */
.loading-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: white;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.loading-screen.active {
    opacity: 1;
    pointer-events: all;
}

.loading-center-group {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
}

.loading-bar-container {
    width: 300px;
    height: 5px;
    background: #fff;
    border-radius: 2px;
    overflow: hidden;
    position: relative;
}

.loading-bar {
    position: absolute;
    height: 100%;
    background: #ff6154;
    border-radius: 2px;
    width: 40%;
    will-change: transform;
    animation: loading 1.2s cubic-bezier(0.4, 0, 0.2, 1) infinite;
}

@keyframes loading {
    0% { transform: translateX(-100%); }
    50% { transform: translateX(200%); }
    100% { transform: translateX(500%); }
}

.loading-text {
    font-size: 1.05rem;
    color: #1f2937;
    font-weight: 600;
    transition: opacity 0.3s ease;
}

.loading-subtext {
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.8rem;
    color: #9ca3af;
    font-weight: 400;
    min-height: 18px;
    margin-top: 16px;
    white-space: nowrap;
    transition: opacity 0.3s ease;
}

.loading-percent {
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    font-size: 13px;
    color: #999;
    font-weight: 500;
    min-height: 18px;
    font-variant-numeric: tabular-nums;
    margin-top: 40px;
    white-space: nowrap;
}

/* ═══ Reorder Panel (full width, no sidebar) ═══ */
.reorder-panel {
    margin-top: 0;
    background: transparent;
    border: none;
    padding: 0;
    box-shadow: none;
}

.pages-reorder-section {
    padding: 30px 45px 120px 45px;
    display: flex;
    flex-direction: column;
    align-items: center;
    max-width: 1200px;
    margin: 0 auto;
    box-sizing: border-box;
}



/* ═══ Pages Grid ═══ */
.pages-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 24px;
    width: 100%;
    margin-bottom: 40px;
}

.pages-grid[data-page-count="1"] { grid-template-columns: repeat(1, minmax(220px, 300px)); justify-content: center; }
.pages-grid[data-page-count="2"] { grid-template-columns: repeat(2, minmax(200px, 280px)); justify-content: center; }
.pages-grid[data-page-count="3"] { grid-template-columns: repeat(3, minmax(180px, 240px)); justify-content: center; }
.pages-grid[data-page-count="4"] { grid-template-columns: repeat(4, minmax(170px, 220px)); justify-content: center; }

/* Thumb mode: larger thumbnails */
.pages-grid.thumb-large {
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 24px;
}

/* ═══ Page Thumbnail Wrapper ═══ */
.page-thumbnail-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    position: relative;
}

.page-thumbnail-wrapper.sortable-chosen .page-item {
    box-shadow: 0 0 0 3px #ff6154, 0 8px 12px rgba(255, 97, 84, 0.4);
    transform: translateY(-4px);
}

.page-thumbnail-wrapper.sortable-ghost { opacity: 0.4; }

/* ═══ Per-Page Buttons ═══ */
.page-buttons-container {
    display: flex;
    flex-direction: row;
    gap: 5px;
    justify-content: center;
    margin-bottom: 6px;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.page-thumbnail-wrapper:hover:not(:has(.grid-insert-trigger:hover)) .page-buttons-container { opacity: 1; }
.page-buttons-container:hover { opacity: 1 !important; }
.sortable-chosen .page-buttons-container,
.sortable-ghost .page-buttons-container,
.dragging .page-buttons-container { opacity: 0 !important; }
.pages-grid.sortable-drag .page-buttons-container { opacity: 0 !important; }

/* Drag Handle */
.drag-handle {
    width: 28px; height: 28px;
    background: #ff6154;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: grab;
    transition: all 0.15s ease;
}
.drag-handle:active { cursor: grabbing; }
.drag-handle svg { width: 16px; height: 16px; stroke: white; }
.drag-handle:hover { background: #e5554a; transform: scale(1.1); }

/* Action Buttons (rotate, duplicate, delete) */
.page-action-btn {
    width: 28px; height: 28px;
    border-radius: 6px;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
    padding: 0;
}
.page-action-btn svg { width: 14px; height: 14px; stroke: #374151; }
.page-action-btn:hover { transform: scale(1.1); }

.rotate-btn { background: #f5f6f8; }
.rotate-btn:hover { background: #e5e7eb; }

.duplicate-btn { background: #f5f6f8; }
.duplicate-btn:hover { background: #e5e7eb; }

.delete-btn { background: #f5f6f8; }
.delete-btn:hover { background: #ff3b30; }
.delete-btn:hover svg { stroke: white; }

/* ═══ Page Item (card) ═══ */
.page-item {
    position: relative;
    border-radius: 12px;
    cursor: grab;
    width: 100%;
    overflow: hidden;
    background: white;
    box-shadow: 0 8px 14px rgba(0, 0, 0, 0.10);
    border: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    transition: box-shadow 0.2s ease, transform 0.2s ease;
}
.page-item:active { cursor: grabbing; }
.page-item:hover { box-shadow: 0 12px 12px rgba(0, 0, 0, 0.18); transform: translateY(-2px); }

/* Selection mode disables sortable — show a hand instead of grab/grabbing
   so the cursor matches the click-to-toggle behavior. */
body.selection-mode .page-item,
body.selection-mode .page-item:active,
body.selection-mode .drag-handle,
body.selection-mode .drag-handle:active { cursor: pointer; }
.page-item canvas { width: 100%; height: auto; display: block; border-radius: 12px; transform-origin: center center; }

.page-item.rotated-landscape {
    justify-content: center;
}


/* Page Label */
.page-label {
    padding: 5px 14px;
    text-align: center;
    font-size: 0.8rem;
    color: #374151;
    font-weight: 600;
    background: #f3f4f6;
    border-radius: 20px;
    border: none;
    display: inline-block;
}

/* ═══ Selection Checkbox Overlay ═══ */
.selection-checkbox {
    position: absolute;
    top: 8px; left: 8px;
    z-index: 5;
}

.selection-checkbox input[type="checkbox"] {
    -webkit-appearance: none;
    appearance: none;
    width: 20px; height: 20px;
    border: 2px solid #d1d5db;
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.85);
    cursor: pointer;
    position: relative;
    transition: background 0.15s ease, border-color 0.15s ease;
}
.selection-checkbox input[type="checkbox"]:checked {
    background-color: #ff6154;
    border-color: #ff6154;
    /* ::after pseudo-elements don't render on <input> (replaced element)
       in Chrome / Safari / Firefox, so the checkmark is an inline SVG
       background instead of a border-rotated diamond. */
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3.5' stroke-linecap='round' stroke-linejoin='round'><polyline points='20 6 9 17 4 12'/></svg>");
    background-repeat: no-repeat;
    background-position: center;
    background-size: 14px 14px;
}

.page-thumbnail-wrapper.selected .page-item {
    box-shadow: 0 0 0 3px #ff6154;
}
/* Hide rotate/duplicate/delete + drag handle when the card is checked —
   the only legitimate action while selected is "deselect", and the bulk
   action bar is the canonical surface for everything else. */
.page-thumbnail-wrapper.selected .page-buttons-container { display: none !important; }

/* Delete animation — scale-down + fade so it's obvious which card just
   left, even on PDFs where pages look near-identical. The wrapper is
   removed from the DOM after 220ms so the grid reflows once. */
.page-thumbnail-wrapper.deleting {
    transition: transform 0.22s cubic-bezier(0.4, 0, 0.6, 1),
                opacity 0.22s cubic-bezier(0.4, 0, 0.6, 1),
                filter 0.22s ease;
    transform: scale(0.6);
    opacity: 0;
    filter: blur(2px);
    pointer-events: none;
    z-index: 0;
}

/* ═══ Source Badge (inserted PDFs) ═══ */
.source-badge {
    position: absolute;
    bottom: 6px; left: 6px; right: 6px;
    background: var(--source-color, #8b5cf6);
    color: white;
    padding: 3px 8px;
    border-radius: 6px;
    font-size: 0.65rem;
    font-weight: 600;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    pointer-events: none;
}

/* Source colors for different inserted PDFs */
.page-thumbnail-wrapper.inserted-page .page-item { border: 2px solid var(--source-color, #8b5cf6); }
.page-thumbnail-wrapper.inserted-page .source-badge { background: var(--source-color, #8b5cf6); }

.page-thumbnail-wrapper.blank-page .page-item {
    border: 2px dashed #d1d5db;
}

/* ═══ Grid-mode Insert Trigger ═══ */
/* Absolutely positioned on the left edge of each thumbnail in grid mode */
.grid-insert-trigger {
    position: absolute;
    left: -24px;
    top: 0;
    width: 24px;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.15s ease;
    /* height set by JS to match page-item height */
}


.grid-insert-trigger:hover {
    opacity: 1;
}

.grid-insert-trigger .grid-insert-line {
    position: absolute;
    top: 10%;
    bottom: 10%;
    left: 50%;
    width: 2px;
    background: #ff6154;
    pointer-events: none;
    transform: translateX(-50%);
    border-radius: 1px;
}

.grid-insert-trigger .grid-insert-btn {
    position: relative;
    z-index: 2;
    width: 22px; height: 22px;
    border-radius: 50%;
    border: none;
    background: #ff6154;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    padding: 0;
    box-shadow: 0 2px 8px rgba(255, 97, 84, 0.35);
    transition: transform 0.15s ease;
}
.grid-insert-trigger .grid-insert-btn:hover { transform: scale(1.15); }
.grid-insert-trigger .grid-insert-btn svg { width: 12px; height: 12px; stroke: currentColor; pointer-events: none; }

/* Hide grid triggers in list view */
.pages-grid.list-view .grid-insert-trigger { display: none; }

/* ═══ List-mode Insert Gap (grid child) ═══ */
/* A thin gap element between grid items in list view */
.insert-gap {
    grid-column: 1;
    height: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    cursor: pointer;
    margin: -5px 0;
    z-index: 10;
}

.insert-gap-line {
    position: absolute;
    left: 0; right: 0;
    top: 50%;
    height: 2px;
    background: transparent;
    pointer-events: none;
    transition: background 0.15s ease;
}

.insert-gap-btn {
    position: relative;
    z-index: 2;
    width: 22px; height: 22px;
    border-radius: 50%;
    border: none;
    background: transparent;
    color: transparent;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    padding: 0;
    transition: all 0.15s ease;
}
.insert-gap-btn svg { width: 12px; height: 12px; stroke: currentColor; pointer-events: none; }

.insert-gap:hover .insert-gap-line {
    background: #ff6154;
}
.insert-gap:hover .insert-gap-btn {
    background: #ff6154;
    color: white;
    box-shadow: 0 2px 8px rgba(255, 97, 84, 0.35);
}

/* "Add page" card at the end of the grid */
.add-page-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    align-self: center;
    gap: 8px;
    border: 2px dashed #d1d5db;
    border-radius: 12px;
    cursor: pointer;
    color: #9ca3af;
    background: transparent;
    padding: 0;
    font-family: inherit;
    transition: border-color 0.15s ease, color 0.15s ease, background 0.15s ease;
}
.add-page-card:hover {
    border-color: #ff6154;
    color: #ff6154;
    background: #fff8f7;
}
.add-page-card svg { width: 28px; height: 28px; stroke: currentColor; }
.add-page-card span { font-size: 0.82rem; font-weight: 600; }

/* ═══ Insert Tooltip (popover menu on gap click) ═══ */
.insert-tooltip {
    position: fixed;
    z-index: 100;
    background: white;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.14), 0 2px 8px rgba(0, 0, 0, 0.06);
    border: 1px solid rgba(0, 0, 0, 0.06);
    padding: 5px;
    min-width: 170px;
}
.insert-tooltip.hidden { display: none !important; }

.insert-tooltip-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 9px 12px;
    border: none;
    border-radius: 8px;
    background: none;
    color: #374151;
    font-size: 0.82rem;
    font-weight: 500;
    cursor: pointer;
    text-align: left;
    font-family: inherit;
}
.insert-tooltip-item:hover { background: #f3f4f6; }
.insert-tooltip-item svg { width: 16px; height: 16px; stroke: currentColor; flex-shrink: 0; }

/* In list view - gaps align with the page-item area */
.pages-grid.list-view .insert-gap {
    grid-column: 1;
    height: 8px;
    margin: -4px 0 -4px 38px;
}
.pages-grid.list-view .add-page-card {
    display: none;
}

/* ═══ List View ═══ */
/* Vertically stacked medium-sized page previews with action buttons on the left */
.pages-grid.list-view {
    grid-template-columns: 1fr;
    gap: 16px;
    max-width: 320px;
    margin-left: auto;
    margin-right: auto;
}

.pages-grid.list-view.thumb-large {
    max-width: 420px;
    gap: 20px;
}

.pages-grid.list-view .page-thumbnail-wrapper {
    flex-direction: row;
    align-items: stretch;
    gap: 0;
}

.pages-grid.list-view .page-buttons-container {
    flex-direction: column;
    gap: 4px;
    justify-content: center;
    margin-bottom: 0;
    margin-right: 10px;
    opacity: 1;
    order: -1;
}

.pages-grid.list-view .page-thumbnail-wrapper:hover .page-buttons-container { opacity: 1; }

.pages-grid.list-view .page-thumbnail-wrapper.sortable-chosen .page-item {
    box-shadow: 0 0 0 3px #ff6154, 0 8px 12px rgba(255, 97, 84, 0.3);
}

.pages-grid.list-view .page-thumbnail-wrapper.sortable-ghost { opacity: 0.4; }

.pages-grid.list-view .page-item {
    flex: 1;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.10);
    background: white;
}
.pages-grid.list-view .page-item:hover { box-shadow: 0 6px 16px rgba(0, 0, 0, 0.14); transform: none; }
.pages-grid.list-view .page-item canvas { border-radius: 10px; }

/* In list view, hide the standalone label - page number is shown inside page-item via JS */
.pages-grid.list-view .page-label {
    display: none;
}

/* Page number overlay shown inside page-item in list view */
.page-item .page-number-overlay {
    display: none;
    position: absolute;
    bottom: 8px;
    right: 8px;
    padding: 3px 10px;
    font-size: 0.72rem;
    background: rgba(0, 0, 0, 0.6);
    color: white;
    border-radius: 6px;
    z-index: 3;
    font-weight: 600;
}
.pages-grid.list-view .page-item .page-number-overlay { display: block; }

/* ═══ Floating Action Bar ═══ */
.floating-action-bar {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 90;
    display: flex;
    flex-direction: column;
    align-items: center;
    animation: fabSlideUp 0.35s cubic-bezier(0.34, 1.4, 0.64, 1);
}

@keyframes fabSlideUp {
    from { opacity: 0; transform: translateX(-50%) translateY(20px); }
    to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

.fab-bar-row {
    display: flex;
    gap: 8px;
    align-items: center;
}

.fab-settings {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px;
    background: white;
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12), 0 2px 8px rgba(0, 0, 0, 0.08);
    border: 1px solid rgba(0, 0, 0, 0.06);
}

.fab-inner {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px;
    background: white;
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12), 0 2px 8px rgba(0, 0, 0, 0.08);
    border: 1px solid rgba(0, 0, 0, 0.06);
}

/* Segmented switch toggle */
.fab-switch {
    display: inline-flex;
    background: #e5e7eb;
    border-radius: 9px;
    padding: 2px;
    gap: 2px;
}

.fab-switch-opt {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px; height: 34px;
    padding: 0;
    border: none;
    border-radius: 7px;
    background: transparent;
    cursor: pointer;
    transition: all 0.2s ease;
}

.fab-switch-opt svg { stroke: #9ca3af; transition: stroke 0.2s ease; }
.fab-switch-opt.active { background: white; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08); }
.fab-switch-opt.active svg { stroke: #374151; }
.fab-switch-opt:not(.active):hover svg { stroke: #6b7280; }
.fab-switch-opt:hover { background: transparent; }
.fab-switch-opt.active:hover { background: white; }
/* .fab-switch.disabled removed - thumb toggle works in all modes */

.fab-secondary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px; height: 44px;
    padding: 0;
    background: #f5f6f8;
    color: #6b7280;
    border: none;
    border-radius: 11px;
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.fab-secondary svg { stroke: #9ca3af; transition: all 0.2s; }
.fab-secondary:hover { background: #eef0f3; }
.fab-secondary:hover svg { stroke: #374151; }
.fab-secondary:disabled { opacity: 0.3; cursor: not-allowed; }
.fab-secondary.active { background: #ff6154; }
.fab-secondary.active svg { stroke: white; }
.fab-secondary.active:hover { background: #e5554a; }
.fab-secondary.danger:hover { background: #fef2f2; }
.fab-secondary.danger:hover svg { stroke: #ef4444; }

.fab-primary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 12px 20px;
    height: 44px;
    background: #ff6154;
    color: white;
    border: none;
    border-radius: 11px;
    font-size: 0.95rem;
    font-weight: 700;
    cursor: pointer;
    transition: background 0.25s ease, box-shadow 0.25s ease, transform 0.25s ease;
    white-space: nowrap;
    letter-spacing: 0.01em;
    position: relative;
    overflow: hidden;
    flex-shrink: 0;
    font-family: inherit;
}

.fab-primary-arrow { stroke: white; transition: transform 0.2s ease; flex-shrink: 0; }
.fab-primary:hover:not(:disabled) .fab-primary-arrow { transform: translateX(3px); }
.fab-primary:hover:not(:disabled) { background: #e5554a; box-shadow: 0 4px 16px rgba(255, 97, 84, 0.4); }
.fab-primary:disabled { opacity: 0.4; cursor: not-allowed; }

/* Fab primary loading state */
.fab-primary.loading {
    pointer-events: none;
    position: relative;
    background-color: #f3f4f6;
    box-shadow: none;
    transform: none;
}
.fab-primary.loading .fab-primary-text,
.fab-primary.loading .fab-primary-arrow {
    visibility: hidden;
}
.fab-primary.loading::after {
    content: '';
    position: absolute;
    left: 20%;
    width: 60%;
    height: 3px;
    background: #e5e7eb;
    border-radius: 3px;
}
.fab-primary.loading::before {
    content: '';
    position: absolute;
    left: 20%;
    width: 0%;
    height: 3px;
    background: #ff6154;
    z-index: 1;
    border-radius: 3px;
    animation: fabLoadingFill 2s ease-out forwards;
}
@keyframes fabLoadingFill {
    0%   { width: 0%; }
    30%  { width: 30%; }
    50%  { width: 42%; }
    70%  { width: 50%; }
    85%  { width: 55%; }
    100% { width: 60%; }
}

.fab-divider {
    width: 1px; height: 24px;
    background: #d1d5db;
    flex-shrink: 0;
    margin: 0 4px;
}

/* ═══ Bulk Actions Bar ═══ */
.bulk-bar {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 91;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 14px 6px 18px;
    background: white;
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12), 0 2px 8px rgba(0, 0, 0, 0.08);
    border: 1px solid rgba(0, 0, 0, 0.06);
    animation: fabSlideUp 0.35s cubic-bezier(0.34, 1.4, 0.64, 1);
}

.bulk-bar-count {
    font-size: 0.85rem;
    font-weight: 600;
    color: #ef4444;
    white-space: nowrap;
}

.bulk-bar-btns { display: flex; gap: 4px; }

/* ═══ Sort Popup ═══ */
.sort-popup {
    position: fixed;
    z-index: 95;
    background: white;
    border-radius: 14px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.14), 0 2px 8px rgba(0, 0, 0, 0.06);
    border: 1px solid rgba(0, 0, 0, 0.06);
    padding: 6px;
    min-width: 200px;
    animation: sortPopIn 0.18s cubic-bezier(0.34, 1.4, 0.64, 1);
}

@keyframes sortPopIn {
    from { opacity: 0; transform: translateY(8px) scale(0.96); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.sort-popup-item {
    display: block;
    width: 100%;
    padding: 9px 14px;
    border: none;
    border-radius: 8px;
    background: none;
    color: #374151;
    font-size: 0.82rem;
    font-weight: 500;
    cursor: pointer;
    text-align: left;
    transition: background 0.12s;
    font-family: inherit;
}
.sort-popup-item:hover { background: #f3f4f6; }
.sort-arrow-icon { width: 10px; height: 10px; vertical-align: middle; display: inline-block; }

.sort-popup-divider {
    height: 1px;
    background: #e5e7eb;
    margin: 4px 8px;
}

/* ═══ Add Files Modal (merge-pdf pattern) ═══ */
.add-files-modal {
    position: fixed;
    inset: 0;
    z-index: 8000;
    display: flex;
    align-items: center;
    justify-content: center;
}
.add-files-modal.hidden { display: none !important; }

.add-files-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 15, 25, 0.4);
    animation: addFilesBackdropIn 0.18s ease;
}

@keyframes addFilesBackdropIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}

.add-files-dialog {
    position: relative;
    background: #ffffff;
    border-radius: 20px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.06), 0 24px 64px rgba(0,0,0,0.14);
    padding: 18px;
    width: 380px;
    max-width: calc(100vw - 32px);
    overflow: hidden;
    transition: width 0.22s cubic-bezier(0.4, 0, 0.2, 1);
    animation: addFilesDialogIn 0.24s cubic-bezier(0.34, 1.4, 0.64, 1);
}

@keyframes addFilesDialogIn {
    from { opacity: 0; transform: translateY(16px) scale(0.96); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

.add-files-dialog.wide { width: 720px; }

.add-files-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 14px;
    padding: 0 2px;
}

.add-files-title {
    font-size: 0.9rem;
    font-weight: 600;
    color: #111827;
    letter-spacing: -0.01em;
}

.add-files-close {
    width: 30px; height: 30px;
    border: none;
    background: #f3f4f6;
    color: #6b7280;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    padding: 0;
    flex-shrink: 0;
}
.add-files-close:hover { background: #fee2e2; color: #ef4444; }

.add-files-dropzone {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    background: #f9fafb;
    border: 1.5px dashed #d1d5db;
    border-radius: 16px;
    padding: 44px 28px 36px;
    cursor: default;
    text-align: center;
}
.add-files-dropzone.drag-over { border-color: #ff6154; background: #fff8f7; }

.add-files-icon-wrap {
    width: 52px; height: 52px;
    background: #fff;
    border-radius: 14px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.06);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 4px;
    color: #6b7280;
}
.add-files-dropzone.drag-over .add-files-icon-wrap { color: #ff6154; box-shadow: 0 1px 3px rgba(0,0,0,0.08), 0 4px 16px rgba(255,97,84,0.2); }

.add-files-dropzone-title { font-size: 0.9rem; font-weight: 600; color: #111827; margin: 0; }
.add-files-dropzone-sub { font-size: 0.78rem; color: #9ca3af; margin: 0; }

.add-files-browse-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-top: 6px;
    padding: 8px 20px;
    background: #111827;
    color: #fff;
    border-radius: 10px;
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    letter-spacing: 0.01em;
}
.add-files-browse-btn:hover { background: #1f2937; }

/* When files are staged */
.add-files-dropzone.has-files {
    padding: 16px 20px;
    flex-direction: row;
    justify-content: flex-start;
    gap: 12px;
    text-align: left;
}
.add-files-dropzone.has-files .add-files-icon-wrap { width: 36px; height: 36px; border-radius: 10px; margin-bottom: 0; flex-shrink: 0; }
.add-files-dropzone.has-files .add-files-icon-wrap svg { width: 16px; height: 16px; }
.add-files-dropzone.has-files .add-files-dropzone-title { font-size: 0.82rem; }
.add-files-dropzone.has-files .add-files-dropzone-sub { font-size: 0.74rem; }
.add-files-dropzone.has-files .add-files-browse-btn { display: none; }

.add-files-dropzone-text { display: flex; flex-direction: column; gap: 2px; flex: 1; }

.add-files-dropzone-add-more {
    font-size: 0.78rem; font-weight: 600; color: #ff6154;
    cursor: pointer; white-space: nowrap;
    padding: 6px 12px; border-radius: 8px;
    background: #fff5f4; border: none; flex-shrink: 0;
}
.add-files-dropzone-add-more:hover { background: #fee2e0; }

.add-files-staged { margin-top: 10px; }
.add-files-staged-scroll { max-height: 220px; overflow-y: auto; margin: 0 0 10px; scrollbar-width: none; }
.add-files-staged-scroll::-webkit-scrollbar { display: none; }

.add-files-staged-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.add-files-staged-list.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; }

.add-files-staged-item {
    display: flex; align-items: center; gap: 10px;
    padding: 9px 12px; background: #f9fafb; border-radius: 10px;
}
.add-files-staged-item:hover { background: #f3f4f6; }

.add-files-staged-info { flex: 1; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.add-files-staged-name { font-size: 0.8rem; font-weight: 500; color: #111827; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.add-files-staged-meta { font-size: 0.71rem; color: #9ca3af; white-space: nowrap; }

.add-files-staged-remove {
    width: 24px; height: 24px; border: none; background: transparent;
    color: #c4c9d4; border-radius: 6px; display: flex;
    align-items: center; justify-content: center; cursor: pointer; padding: 0; flex-shrink: 0;
}
.add-files-staged-remove:hover { background: #fee2e2; color: #ef4444; }

.add-files-confirm-btn {
    width: 100%; padding: 11px; background: #111827; color: #fff;
    border: none; border-radius: 12px; font-size: 0.88rem;
    font-weight: 600; cursor: pointer; letter-spacing: 0.01em; font-family: inherit;
}
.add-files-confirm-btn:hover { background: #1f2937; }

/* ═══ Loading State ═══ */
.loading-preview {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 40px;
    color: #6b7280;
    grid-column: 1 / -1;
}

.loading-spinner {
    width: 48px; height: 48px;
    border: 4px solid #e5e7eb;
    border-radius: 50%;
    border-top-color: #ff6154;
    animation: spin 0.8s linear infinite;
    margin-bottom: 20px;
}

@keyframes spin { to { transform: rotate(360deg); } }

.loading-preview p { font-size: 1rem; font-weight: 500; }

/* ═══ Drag Scroll Indicators ═══
   Small white pill labels that float at the top/bottom edges of the page
   list during a drag-reorder, hinting where the auto-scroll zone is. A
   full-width 3-layer fade sits behind each pill so the underlying content
   softens out toward the edge instead of running flush into the pill. */
.drag-scroll-indicator {
    position: fixed;
    left: 0;
    right: 0;
    display: flex;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.15s ease, transform 0.2s ease;
    pointer-events: none;
    z-index: 99999;
}
.drag-scroll-indicator::before {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    height: 110px;
    pointer-events: none;
    z-index: 0;
}
.drag-scroll-indicator .drag-scroll-inner {
    position: relative;
    z-index: 1;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 14px;
    background: #fff;
    color: #374151;
    font-size: 0.75rem;
    font-weight: 600;
    white-space: nowrap;
    border-radius: 50px;
    box-shadow: 0 6px 18px rgba(15, 23, 42, 0.12),
                0 1px 3px rgba(15, 23, 42, 0.08),
                0 0 0 1px rgba(15, 23, 42, 0.04);
}
.drag-scroll-indicator svg {
    display: block;
    flex-shrink: 0;
    stroke: #6b7280;
}
.drag-scroll-indicator.active { opacity: 1; }
.drag-scroll-top {
    top: 12px;
    transform: translateY(-6px);
}
.drag-scroll-top::before {
    top: -12px;
    background:
        linear-gradient(to bottom, rgba(255,255,255,1) 0%, rgba(255,255,255,0) 30%),
        linear-gradient(to bottom, rgba(255,255,255,0.7) 0%, rgba(255,255,255,0) 65%),
        linear-gradient(to bottom, rgba(255,255,255,0.35) 0%, rgba(255,255,255,0) 100%);
}
.drag-scroll-bottom {
    bottom: 12px;
    transform: translateY(6px);
}
.drag-scroll-bottom::before {
    bottom: -12px;
    background:
        linear-gradient(to top, rgba(255,255,255,1) 0%, rgba(255,255,255,0) 30%),
        linear-gradient(to top, rgba(255,255,255,0.7) 0%, rgba(255,255,255,0) 65%),
        linear-gradient(to top, rgba(255,255,255,0.35) 0%, rgba(255,255,255,0) 100%);
}
.drag-scroll-top.active,
.drag-scroll-bottom.active {
    transform: translateY(0);
}

/* ═══ Download Screen ═══ */
.download-screen {
    display: none;
    padding: 0;
    max-width: 100%;
    margin: 0;
    min-height: calc(100vh - 81px);
    background: #f8f9fa;
}
.download-screen.active { display: block; }

.download-content {
    display: flex;
    width: 100%;
    min-height: calc(100vh - 81px);
}

/* Left: PDF Preview */
.pdf-preview-section {
    flex: 1;
    background: #f8f9fa;
    padding: 40px;
    display: flex;
    flex-direction: column;
    align-items: center;
    overflow-y: auto;
    margin-right: 420px;
    height: calc(100vh - 81px);
    box-sizing: border-box;
}

.preview-canvas-container {
    width: 100%;
    background: transparent;
    border-radius: 0;
    box-shadow: none;
    overflow: visible;
    margin-bottom: 20px;
    max-width: 700px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.preview-page-wrapper {
    background: white;
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
    overflow: hidden;
    position: relative;
}
.preview-page-wrapper canvas { width: 100%; height: auto; display: block; }

.page-number-badge {
    position: absolute;
    top: 12px; right: 12px;
    background: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 600;
    z-index: 10;
}

.preview-controls {
    display: none;
    align-items: center;
    gap: 16px;
    margin-top: 8px;
}

.preview-controls button {
    padding: 10px 18px;
    font-size: 0.9rem;
    background: white;
    border: 2px solid #e5e7eb;
    color: #374151;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 44px;
    cursor: pointer;
}
.preview-controls button svg { width: 18px; height: 18px; stroke: currentColor; }
.preview-controls button:hover:not(:disabled) { border-color: #ff6154; background: #fff5f4; color: #ff6154; }
.preview-controls button:disabled { opacity: 0.3; cursor: not-allowed; }

.preview-page-info { color: #374151; font-size: 0.95rem; font-weight: 600; min-width: 60px; text-align: center; }

/* Right: Download Actions */
.download-actions-section {
    position: fixed;
    right: 0; top: 81px;
    width: 420px;
    height: calc(100vh - 81px);
    background: white;
    border-left: 2px solid #e5e7eb;
    display: flex;
    flex-direction: column;
    padding: 40px;
    overflow-y: auto;
    box-sizing: border-box;
    box-shadow: -4px 0 24px rgba(0, 0, 0, 0.06);
}

.back-button {
    background: none;
    color: #8e96a7;
    border: none;
    padding: 0;
    font-size: 0.95rem;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 24px;
    font-weight: 500;
    position: absolute;
    margin-top: -10px;
    left: 40px;
    cursor: pointer;
    transition: color 0.15s ease;
}
.back-button:hover { background: none; color: #374151; box-shadow: none; transform: none; }
.back-button svg {
    width: 18px; height: 18px;
    background: #f9f9f9;
    padding: 6px;
    border-radius: 8px;
    box-sizing: content-box;
    transition: background 0.15s ease;
}
.back-button:hover svg { background: #f0f0f0; }

/* File Card */
#download-files-list { margin-top: 50px; margin-bottom: 24px; }

.single-file-card {
    background: none;
    border: none;
    border-radius: 12px;
    padding: 0;
    display: flex;
    align-items: center;
    gap: 16px;
    margin-top: 10px;
    margin-bottom: 10px;
}

.single-file-thumb {
    width: 68px; height: 82px;
    background: white;
    border-radius: 6px;
    flex-shrink: 0;
    overflow: hidden;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1), 0 0 0 1px rgba(0, 0, 0, 0.05);
}
.single-file-thumb canvas { width: 100%; height: 100%; display: block; object-fit: cover; }

.single-file-details { flex: 1; text-align: left; min-width: 0; }

.single-file-name {
    font-size: 1rem;
    font-weight: 600;
    color: #1f2937;
    display: flex;
    align-items: center;
    flex: 1;
    min-width: 0;
    background: #f9f9f9;
    padding: 8px;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.15s;
}
.single-file-name:hover { background: #f0f1f3; }
.single-file-name-base { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.single-file-name-ext { white-space: nowrap; flex-shrink: 0; color: #9ca3af; margin-left: auto; }
.single-file-info { font-size: 0.7rem; color: #9ca3af; }
.single-file-name-row { display: flex; align-items: center; gap: 6px; }

.file-more-btn {
    background: #f9f9f9;
    border: none;
    border-radius: 8px;
    padding: 8px 6px;
    cursor: pointer;
    color: #9ca3af;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
}
.file-more-btn:hover { background: #f3f4f6; color: #6b7280; }

.done-button {
    background: #10b981;
    color: white;
    padding: 2px 7px;
    border-radius: 8px;
    font-size: 0.6rem;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 3px;
    margin-bottom: 3px;
}
.done-dot { width: 4px; height: 4px; border-radius: 50%; background: white; }

/* Download Button */
.download-primary {
    width: 100%;
    padding: 18px 32px;
    font-size: 1.2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    background-color: #ff6154;
    color: white;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: 600;
}
.download-primary:hover { background: #e5554a; box-shadow: 0 6px 16px rgba(255, 97, 84, 0.4); transform: translateY(-2px); }
.download-primary svg { width: 20px; height: 20px; stroke: white; fill: none; }

/* Another Button */
.extract-another-btn {
    width: 100%;
    padding: 13px 32px;
    margin-top: 12px;
    background: transparent;
    color: #ff6154;
    border: 1.5px solid #ff6154;
    border-radius: 10px;
    cursor: pointer;
    font-size: 0.95rem;
    font-weight: 600;
    transition: background 0.2s ease, box-shadow 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}
.another-btn-text, .another-btn-arrow { transition: opacity 0.25s ease; }
.another-btn-arrow { position: absolute; opacity: 0; }
.extract-another-btn:hover { background: #fff5f4; box-shadow: 0 4px 12px rgba(255, 97, 84, 0.2); }
.extract-another-btn:hover .another-btn-text { opacity: 0; }
.extract-another-btn:hover .another-btn-arrow { opacity: 1; }

/* ═══ File More Action Sheet ═══ */
.file-more-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.35);
    z-index: 2000;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding: 16px;
    animation: modalFadeIn 0.15s ease;
}
.file-more-overlay.hidden { display: none !important; }

@keyframes modalFadeIn { from { opacity: 0; } to { opacity: 1; } }

.file-more-sheet {
    width: 100%; max-width: 340px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    animation: sheetSlideUp 0.3s cubic-bezier(0.32, 0.72, 0, 1);
}

@keyframes sheetSlideUp { from { opacity: 0; transform: translateY(100%); } to { opacity: 1; transform: translateY(0); } }

.file-more-group { background: white; border-radius: 16px; overflow: hidden; }

.file-more-action {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 18px;
    border: none;
    background: none;
    cursor: pointer;
    font-family: inherit;
    text-align: left;
    transition: background 0.15s;
}
.file-more-action:hover { background: #f9fafb; }

.file-more-action-icon {
    width: 40px; height: 40px;
    border-radius: 10px;
    background: #f3f4f6;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.file-more-action-icon svg { color: #374151; }

.file-more-action-text { display: flex; flex-direction: column; gap: 1px; }
.file-more-action-label { font-size: 0.92rem; font-weight: 600; color: #1f2937; }
.file-more-action-desc { font-size: 0.75rem; color: #9ca3af; }
.file-more-divider { height: 1px; background: #f3f4f6; margin: 0 18px; }

.file-more-cancel {
    width: 100%;
    padding: 16px;
    border: none;
    border-radius: 16px;
    background: white;
    color: #6b7280;
    font-size: 0.92rem;
    font-weight: 700;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.15s;
}
.file-more-cancel:hover { background: #f9fafb; color: #374151; }

/* ═══ Rename Modal ═══ */
.popup-modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: modalFadeIn 0.15s ease;
}
.popup-modal-overlay.hidden { display: none !important; }

.rename-modal-card {
    background: white;
    border-radius: 24px;
    padding: 24px;
    width: 320px;
    box-shadow: 0 24px 48px rgba(0, 0, 0, 0.15), 0 0 0 1px rgba(0, 0, 0, 0.04);
    animation: modalSlideUp 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes modalSlideUp { from { opacity: 0; transform: translateY(16px) scale(0.97); } to { opacity: 1; transform: translateY(0) scale(1); } }

.rename-modal-title { font-size: 1rem; font-weight: 700; color: #1f2937; margin-bottom: 16px; }

.rename-modal-input-wrap {
    display: flex;
    align-items: center;
    background: #f5f6f8;
    border-radius: 12px;
    padding: 0;
    margin-bottom: 16px;
    overflow: hidden;
}

.rename-modal-input {
    flex: 1;
    border: none;
    background: transparent;
    padding: 12px 14px;
    font-size: 0.92rem;
    font-weight: 600;
    font-family: inherit;
    color: #1f2937;
    outline: none;
    min-width: 0;
}

.rename-modal-ext { padding: 12px 14px 12px 0; font-size: 0.92rem; font-weight: 600; color: #9ca3af; flex-shrink: 0; }
.rename-modal-actions { display: flex; gap: 8px; }

.rename-modal-cancel {
    flex: 1;
    padding: 12px;
    border: none;
    border-radius: 14px;
    background: #f5f6f8;
    color: #6b7280;
    font-size: 0.88rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.15s;
}
.rename-modal-cancel:hover { background: #f9fafb; color: #374151; }

.rename-modal-save {
    flex: 1;
    padding: 12px;
    border: none;
    border-radius: 14px;
    background: #1f2937;
    color: white;
    font-size: 0.88rem;
    font-weight: 700;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.15s;
}
.rename-modal-save:hover { background: #374151; }

/* Hide elements when showing download screen */
.content-hidden { display: none !important; }

/* ═══ Custom Scrollbar ═══ */
.pages-reorder-section::-webkit-scrollbar,
.pdf-preview-section::-webkit-scrollbar,
.download-actions-section::-webkit-scrollbar,
.preview-canvas-container::-webkit-scrollbar { width: 6px; }

.pages-reorder-section::-webkit-scrollbar-track,
.pdf-preview-section::-webkit-scrollbar-track,
.download-actions-section::-webkit-scrollbar-track,
.preview-canvas-container::-webkit-scrollbar-track { background: #f3f4f6; }

.pages-reorder-section::-webkit-scrollbar-thumb,
.pdf-preview-section::-webkit-scrollbar-thumb,
.download-actions-section::-webkit-scrollbar-thumb,
.preview-canvas-container::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 10px; }

.pages-reorder-section::-webkit-scrollbar-thumb:hover,
.pdf-preview-section::-webkit-scrollbar-thumb:hover,
.download-actions-section::-webkit-scrollbar-thumb:hover,
.preview-canvas-container::-webkit-scrollbar-thumb:hover { background: #9ca3af; }

/* ═══ Responsive ═══ */
@media (max-width: 1200px) {
    .download-actions-section { width: 380px; }
    .pdf-preview-section { margin-right: 380px; }
    .pages-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 20px; }
}

@media (max-width: 968px) {
    .reorder-panel { position: relative; height: auto; min-height: calc(100vh - 81px); }

    .pages-reorder-section { padding: 30px 24px 120px 24px; }

    .download-screen { position: relative; height: auto; min-height: calc(100vh - 81px); }
    .download-content { flex-direction: column; height: auto; min-height: calc(100vh - 81px); }

    .download-actions-section {
        position: relative;
        width: 100%;
        height: auto;
        border-left: none;
        border-top: 2px solid #e5e7eb;
        box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.06);
    }

    .pdf-preview-section { margin-right: 0; padding: 100px 20px 20px 20px; height: auto; min-height: 50vh; }
    .back-button { top: 20px; left: 20px; }
}

@media (max-width: 768px) {
    .container { padding: 16px; }
    .pages-reorder-section { padding: 24px 16px 120px 16px; min-height: auto; }
    .pages-grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 20px; margin-bottom: 24px; }
    .pdf-preview-section { padding: 80px 16px 24px 16px; }
    .download-actions-section { padding: 24px 16px; }
    .back-button { font-size: 0.9rem; }

    .preview-canvas-container { gap: 0; }
    .preview-page-wrapper { display: none; }
    .preview-page-wrapper.active { display: block; }
    .page-number-badge { display: none; }
    .preview-controls { display: flex; }

    .fab-settings { display: none; }
}

@media (max-width: 640px) {
    /* Lock to 4 columns instead of auto-fill minmax(100px, 1fr).
       The minmax(100px) at this width packs 5+ columns, but the
       wider ≤768 tier above shows 4 columns with minmax(120px) —
       so going from 641px (4 cols) to 640px (5 cols) felt like a
       backwards jump. Fixed grid count makes the transition
       monotonic: more columns only on wider viewports. */
    .pages-grid { grid-template-columns: repeat(4, 1fr); gap: 16px; }
}

@media (max-width: 590px) {
    .pages-grid { grid-template-columns: repeat(3, 1fr); gap: 14px; }
}

@media (max-width: 465px) {
    .pages-grid { grid-template-columns: repeat(2, 1fr); gap: 12px; }
}

@media (max-width: 340px) {
    .pages-grid { grid-template-columns: 1fr; gap: 12px; }
}

/* Grid containment defense — grid items default to
   `min-width: min-content`, and the PDF canvas inside .page-item
   has an intrinsic high-res width (PDF.js renders at e.g. 600+ px)
   which stretches each grid column to fit, pushing the whole grid
   past the viewport on phone. min-width: 0 lets the column shrink
   below the canvas's natural width; the canvas's `width: 100%`
   then scales it down to the column. Box-sizing on the section +
   grid keeps padding inside the viewport content area. */
.pages-grid,
.pages-reorder-section {
    box-sizing: border-box;
    max-width: 100%;
}
.pages-grid > .page-thumbnail-wrapper,
.pages-grid > .add-page-card {
    min-width: 0;
}

/* ── Wrong-format error modal (mirrors compress-pdf's showErrorModal) ── */
.error-modal-overlay {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.4);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
}
.error-modal-overlay.active {
    opacity: 1;
    pointer-events: all;
}
.error-modal {
    background: white;
    border-radius: 24px;
    padding: 32px;
    max-width: 340px;
    width: 90%;
    box-shadow: 0 24px 48px rgba(0, 0, 0, 0.15), 0 0 0 1px rgba(0, 0, 0, 0.04);
    transform: scale(0.9);
    transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
}
.error-modal-overlay.active .error-modal { transform: scale(1); }
.error-modal-icon {
    width: 52px;
    height: 52px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 16px;
}
.error-modal-icon svg {
    width: 40px;
    height: 40px;
    stroke: #f59e0b;
    animation: errorModalPulse 0.5s ease-out;
}
@keyframes errorModalPulse {
    0%   { transform: scale(0.8); opacity: 0; }
    50%  { transform: scale(1.1); }
    100% { transform: scale(1); opacity: 1; }
}
.error-modal-title {
    font-size: 1.1rem;
    font-weight: 700;
    color: #1f2937;
    margin: 0 0 8px 0;
}
.error-modal-message {
    font-size: 0.88rem;
    color: #6b7280;
    line-height: 1.4;
    margin: 0 0 20px 0;
}
.error-modal-btn {
    background: #1f2937;
    color: white;
    border: none;
    border-radius: 14px;
    padding: 12px;
    font-size: 0.88rem;
    font-weight: 700;
    font-family: inherit;
    cursor: pointer;
    transition: background 0.15s;
    width: 100%;
}
.error-modal-btn:hover { background: #374151; }

/* ============================================================
   MOBILE & TABLET OVERRIDES — added 2026-05-07
   Organize-pdf has its own architecture (full-width pages-grid +
   floating action bar + bulk-bar). Existing 968/768/640 blocks
   already adjust grid columns and hide fab-settings. This block
   adds the standard iOS-zoom + safe-area + touch-revealed
   handles + merge-style ≤970 full-screen download recipe.
   ============================================================ */

/* ---- Phone (≤768px) ---- */
@media (max-width: 768px) {
    /* iOS auto-zoom prevention. .rename-modal-input is 0.92rem
       (~14.7px) — triggers Safari's input-focus zoom. */
    input, textarea, select { font-size: 16px; }
    .rename-modal-input { font-size: 16px !important; }

    /* Hover-revealed per-page action buttons (rotate, delete) are
       opacity:0 by default → opacity:1 on .page-thumbnail-wrapper:hover.
       Touch users have no :hover state so the buttons are
       unreachable. Force visible at phone widths. The .sortable-*
       drag-state rules in desktop CSS still hide them during drag. */
    .page-thumbnail-wrapper .page-buttons-container {
        opacity: 1;
    }

    /* Floating action bar + bulk bar — supplement bottom: 24px
       with safe-area inset for iPhone home indicator. */
    .floating-action-bar,
    .bulk-bar {
        bottom: max(16px, env(safe-area-inset-bottom, 16px));
    }

    /* File-more bottom sheet safe-area. */
    .file-more-sheet {
        padding-bottom: env(safe-area-inset-bottom, 0px);
    }

    /* Rename modal card — cap to viewport on smallest phones. */
    .rename-modal-card {
        width: calc(100% - 24px) !important;
        max-width: 360px;
        margin: 12px;
    }

    /* Sort popup + insert tooltip — clamp width so they can't
       push the page horizontally when spawned near the edge. */
    .sort-popup,
    .insert-tooltip {
        max-width: calc(100vw - 32px);
    }
}

/* ---- Tablet & narrow desktop — download view full-screen (≤970px) ----
   Mirrors the merge/sign/redact recipe: hide PDF preview canvas,
   hide page hero, full-bleed actions section with content capped
   to 480px and centered. */
@media (max-width: 970px) {
    .download-screen .pdf-preview-section { display: none !important; }

    /* Hero ("Organize PDF" + subtitle) sits above the download
       screen in the DOM; without this it remains visible during
       the success state and pushes the back button down. */
    body.download-active .hero { display: none !important; }

    .download-screen { background: white !important; }
    .download-content {
        flex-direction: column;
        height: auto;
        min-height: calc(100vh - 81px) !important;
        background: white;
    }
    .download-actions-section {
        position: relative !important;
        width: 100% !important;
        height: auto !important;
        min-height: calc(100vh - 81px) !important;
        padding: 32px 20px max(32px, env(safe-area-inset-bottom)) !important;
        border: none !important;
        box-shadow: none !important;
        background: white;
        display: flex !important;
        flex-direction: column;
        justify-content: flex-start;
        align-items: center;
        box-sizing: border-box;
    }

    .download-actions-section > * {
        width: 100%;
        max-width: 480px;
    }
    .download-primary,
    #download-files-list,
    .single-file-card,
    .extract-another-btn {
        max-width: 480px;
        margin-left: auto;
        margin-right: auto;
    }

    /* Back button into normal flow at top of column, left-aligned. */
    .back-button {
        position: relative !important;
        top: auto !important;
        left: auto !important;
        margin: 0 auto 32px !important;
        width: 100%;
        max-width: 480px !important;
        justify-content: flex-start;
    }

    /* Vertical rhythm: back → 32 → file row → 40 → Download
       → 12 → Organize Another. */
    #download-files-list {
        margin-top: 0 !important;
        margin-bottom: 40px !important;
    }
    .single-file-card { margin: 0 !important; }
    .download-primary { margin-bottom: 0 !important; }
    .extract-another-btn { margin-top: 12px !important; }
}
