.hidden {
    display: none !important;
}

svg {
    fill: none;
}

.hero {
    padding: 40px 40px 80px;
}

body {
    overflow-x: hidden;
}

body.download-active {
    height: calc(100vh - 81px);
    overflow-y: visible;
}

body.selection-active {
    overflow-y: hidden;
}

/* 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;
}

/* Progress mode: bar fills left-to-right based on width, no animation */
.loading-bar-container.progress-mode .loading-bar {
    animation: none;
    width: 0%;
    transition: width 0.2s ease;
}

.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. */
body:not(.selection-active):not(.download-active) {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}
body:not(.selection-active):not(.download-active) .hero {
    margin-top: auto;
}
body:not(.selection-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);
}

.file-input-label.drag-over {
    background-color: #e5554a;
    transform: scale(1.05);
}

.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;
}

/* Selection Panel - Split View Layout */
.selection-panel {
    margin-top: 0;
    background: transparent;
    border: none;
    padding: 0;
    box-shadow: none;
    position: fixed;
    top: 81px;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: calc(100vh - 81px);
}

.selection-content {
    display: flex;
    gap: 0;
    align-items: stretch;
    height: 100%;
    width: 100%;
    overflow: hidden;
    position: relative;
}

/* Left side - Crop Preview */
.files-preview-section {
    flex: 1;
    background-color: #f5f6f8;
    background-image: radial-gradient(circle, #e0e2e6 1px, transparent 1px);
    background-size: 20px 20px;
    padding: 32px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    overflow-y: auto;
    margin-right: 420px;
    box-sizing: border-box;
    position: relative;
}

.files-preview-section.full-preview-mode {
    justify-content: flex-start;
    padding-top: 56px;
}

/* Preview Mode Toggle */
.preview-mode-toggle {
    position: absolute;
    top: 16px;
    right: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
    background: white;
    padding: 6px 12px;
    border-radius: 10px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
    z-index: 10;
}

.preview-mode-label {
    font-size: 0.8rem;
    font-weight: 500;
    color: #6b7280;
    white-space: nowrap;
}

.toggle-switch {
    position: relative;
    width: 44px;
    height: 24px;
    background: #d1d5db;
    border-radius: 12px;
    cursor: pointer;
    transition: background-color 0.3s ease;
    flex-shrink: 0;
}

.toggle-switch.active {
    background: #ff6154;
}

.toggle-slider {
    position: absolute;
    top: 3px;
    left: 3px;
    width: 18px;
    height: 18px;
    background: white;
    border-radius: 50%;
    transition: transform 0.3s ease;
}

.toggle-switch.active .toggle-slider {
    transform: translateX(20px);
}

/* Full Preview Mode */
.preview-full-container {
    width: 100%;
    max-width: 600px;
    display: flex;
    flex-direction: column;
}

.preview-full-container .preview-page-outer {
    position: relative;
}

.preview-full-container .preview-page-wrapper {
    background: white;
    border-radius: 6px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
    overflow: clip;
    position: relative;
}

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

.preview-full-container .preview-page-outer > .page-number-badge {
    position: absolute;
    top: 14px;
    right: -28px;
    left: auto;
    background: #1f2937;
    color: #fff;
    font-size: 0.6rem;
    font-weight: 600;
    padding: 3px 8px;
    border-radius: 4px;
    z-index: 5;
}

/* Full preview crop overlay */
.crop-overlay-full {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 2;
    pointer-events: none;
}

.crop-box-full {
    position: absolute;
    border: 2px solid rgba(255, 97, 84, 0.9);
    background: transparent;
    cursor: move;
    pointer-events: auto;
    box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.45);
    box-sizing: border-box;
    transition: none;
}

/* Rule-of-thirds grid inside crop box */
.crop-box-full::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background:
        linear-gradient(to right, rgba(255,255,255,0.15) 1px, transparent 1px),
        linear-gradient(to bottom, rgba(255,255,255,0.15) 1px, transparent 1px);
    background-size: 33.333% 33.333%;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.crop-box-full.dragging::before,
.crop-box-full:hover::before {
    opacity: 1;
}

/* Full preview handles - matching compact mode */
.crop-handle-full {
    position: absolute;
    z-index: 10;
    pointer-events: auto;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.crop-handle-full:hover {
    transform: scale(1.2);
}

/* Corner handles */
.crop-handle-full.top-left,
.crop-handle-full.top-right,
.crop-handle-full.bottom-left,
.crop-handle-full.bottom-right {
    width: 16px;
    height: 16px;
    background: white;
    border: 2.5px solid #ff6154;
    border-radius: 3px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.2);
}

.crop-handle-full.top-left { top: -8px; left: -8px; cursor: nw-resize; }
.crop-handle-full.top-right { top: -8px; right: -8px; cursor: ne-resize; }
.crop-handle-full.bottom-left { bottom: -8px; left: -8px; cursor: sw-resize; }
.crop-handle-full.bottom-right { bottom: -8px; right: -8px; cursor: se-resize; }

.crop-handle-full.top-left:hover,
.crop-handle-full.top-right:hover,
.crop-handle-full.bottom-left:hover,
.crop-handle-full.bottom-right:hover {
    box-shadow: 0 2px 8px rgba(255, 97, 84, 0.4);
    transform: scale(1.15);
}

/* Edge handles - pill shaped */
.crop-handle-full.top,
.crop-handle-full.bottom {
    width: 32px;
    height: 6px;
    background: white;
    border: 2px solid #ff6154;
    border-radius: 3px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}

.crop-handle-full.left,
.crop-handle-full.right {
    width: 6px;
    height: 32px;
    background: white;
    border: 2px solid #ff6154;
    border-radius: 3px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}

.crop-handle-full.top { top: -4px; left: 50%; transform: translateX(-50%); cursor: n-resize; }
.crop-handle-full.bottom { bottom: -4px; left: 50%; transform: translateX(-50%); cursor: s-resize; }
.crop-handle-full.left { top: 50%; left: -4px; transform: translateY(-50%); cursor: w-resize; }
.crop-handle-full.right { top: 50%; right: -4px; transform: translateY(-50%); cursor: e-resize; }

.crop-handle-full.top:hover { transform: translateX(-50%) scaleY(1.4); }
.crop-handle-full.bottom:hover { transform: translateX(-50%) scaleY(1.4); }
.crop-handle-full.left:hover { transform: translateY(-50%) scaleX(1.4); }
.crop-handle-full.right:hover { transform: translateY(-50%) scaleX(1.4); }

.crop-preview-area {
    max-width: 600px;
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
}

.crop-canvas-wrapper {
    position: relative;
    display: inline-block;
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08), 0 0 0 1px rgba(0, 0, 0, 0.04);
    overflow: clip;
    line-height: 0;
    max-width: 100%;
}

.crop-canvas-wrapper canvas {
    display: block;
}

/* Auto-crop scan overlay */
.autocrop-scan-overlay {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    z-index: 20;
    background: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    border-radius: 8px;
    overflow: hidden;
    pointer-events: none;
    display: flex;
    align-items: center;
    justify-content: center;
}

.scan-favicon {
    width: 36px; height: 36px;
    object-fit: contain;
    animation: scanPulse 1.4s ease-in-out infinite;
}

@keyframes scanPulse {
    0%, 100% {
        filter: grayscale(100%);
        opacity: 0.4;
        transform: scale(0.95);
    }
    50% {
        filter: grayscale(0%);
        opacity: 1;
        transform: scale(1.05);
    }
}

/* Crop Overlay */
.crop-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    cursor: crosshair;
}

.crop-box {
    position: absolute;
    border: 2px solid rgba(255, 97, 84, 0.9);
    background: transparent;
    cursor: move;
    box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.45);
    box-sizing: border-box;
    transition: none;
}

/* Rule-of-thirds grid inside crop box */
.crop-box::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background:
        linear-gradient(to right, rgba(255,255,255,0.15) 1px, transparent 1px),
        linear-gradient(to bottom, rgba(255,255,255,0.15) 1px, transparent 1px);
    background-size: 33.333% 33.333%;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.crop-box.dragging::before,
.crop-box:hover::before {
    opacity: 1;
}

/* Corner handles - larger, square with rounded corners */
.crop-handle {
    position: absolute;
    z-index: 10;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.crop-handle:hover {
    transform: scale(1.2);
}

/* Corner handles */
.crop-handle.top-left,
.crop-handle.top-right,
.crop-handle.bottom-left,
.crop-handle.bottom-right {
    width: 16px;
    height: 16px;
    background: white;
    border: 2.5px solid #ff6154;
    border-radius: 3px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.2);
}

.crop-handle.top-left { top: -8px; left: -8px; cursor: nw-resize; }
.crop-handle.top-right { top: -8px; right: -8px; cursor: ne-resize; }
.crop-handle.bottom-left { bottom: -8px; left: -8px; cursor: sw-resize; }
.crop-handle.bottom-right { bottom: -8px; right: -8px; cursor: se-resize; }

.crop-handle.top-left:hover,
.crop-handle.top-right:hover,
.crop-handle.bottom-left:hover,
.crop-handle.bottom-right:hover {
    box-shadow: 0 2px 8px rgba(255, 97, 84, 0.4);
    transform: scale(1.15);
}

/* Edge handles - pill shaped */
.crop-handle.top,
.crop-handle.bottom {
    width: 32px;
    height: 6px;
    background: white;
    border: 2px solid #ff6154;
    border-radius: 3px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}

.crop-handle.left,
.crop-handle.right {
    width: 6px;
    height: 32px;
    background: white;
    border: 2px solid #ff6154;
    border-radius: 3px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}

.crop-handle.top { top: -4px; left: 50%; transform: translateX(-50%); cursor: n-resize; }
.crop-handle.bottom { bottom: -4px; left: 50%; transform: translateX(-50%); cursor: s-resize; }
.crop-handle.left { top: 50%; left: -4px; transform: translateY(-50%); cursor: w-resize; }
.crop-handle.right { top: 50%; right: -4px; transform: translateY(-50%); cursor: e-resize; }

.crop-handle.top:hover { transform: translateX(-50%) scaleY(1.4); }
.crop-handle.bottom:hover { transform: translateX(-50%) scaleY(1.4); }
.crop-handle.left:hover { transform: translateY(-50%) scaleX(1.4); }
.crop-handle.right:hover { transform: translateY(-50%) scaleX(1.4); }

.crop-dimensions {
    position: absolute;
    bottom: -30px;
    left: 50%;
    transform: translateX(-50%);
    background: #1f2937;
    color: white;
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 0.6rem;
    font-weight: 600;
    white-space: nowrap;
    pointer-events: none;
    letter-spacing: 0.3px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

/* Page Navigation */
.page-nav {
    display: flex;
    align-items: center;
    gap: 8px;
    background: white;
    padding: 6px 8px;
    border-radius: 10px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
}

.page-nav-btn {
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 8px;
    background: transparent;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    color: #6b7280;
}

.page-nav-btn:hover:not(:disabled) {
    background: #f3f4f6;
    color: #ff6154;
}

.page-nav-btn:disabled {
    opacity: 0.25;
    cursor: not-allowed;
}

.page-nav-btn svg {
    width: 16px;
    height: 16px;
    stroke: currentColor;
}

.page-info {
    font-size: 0.85rem;
    color: #6b7280;
    font-weight: 600;
    min-width: 100px;
    text-align: center;
    font-variant-numeric: tabular-nums;
}

/* Right side - Controls Panel (Fixed Overlay) */
.controls-panel {
    position: fixed;
    right: 0;
    top: 81px;
    width: 420px;
    box-sizing: border-box;
    padding: 40px;
    padding-bottom: 0;
    height: calc(100vh - 81px);
    background: white;
    border-left: 2px solid #e5e7eb;
    box-shadow: -4px 0 24px rgba(0, 0, 0, 0.06);
    overflow-y: auto;
    z-index: 100;
    display: flex;
    flex-direction: column;
}

.control-section {
    margin-bottom: 24px;
}

.control-section:last-child {
    margin-top: auto;
    margin-bottom: 0;
    padding-bottom: 45px;
}

.control-section-title {
    font-size: 0.75rem;
    font-weight: 600;
    color: #9ca3af;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin: 0 0 10px 0;
}

/* Visual Margin Diagram */
.margin-visual {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.margin-visual-page {
    background: #f3f4f6;
    border: 2px dashed #d1d5db;
    border-radius: 14px;
    padding: 10px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}

.margin-visual-row {
    display: flex;
    align-items: center;
    gap: 6px;
    width: 100%;
}

.margin-visual-center {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 56px;
    background: white;
    border-radius: 8px;
    border: 1.5px solid #e5e7eb;
}

.margin-visual-content {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.75rem;
    font-weight: 600;
    color: #9ca3af;
}

.margin-visual-content svg {
    stroke: #d1d5db;
}

.margin-visual-input {
    display: flex;
    align-items: center;
    justify-content: center;
}

.margin-visual-input.top-input,
.margin-visual-input.bottom-input {
    width: 80px;
}

.margin-visual-input.left-input,
.margin-visual-input.right-input {
    width: 64px;
    flex-shrink: 0;
}

.margin-input {
    width: 100%;
    padding: 7px 6px;
    border: 2px solid #e5e7eb;
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 700;
    color: #1f2937;
    background: white;
    transition: all 0.2s ease;
    box-sizing: border-box;
    text-align: center;
    -moz-appearance: textfield;
}

.margin-input::-webkit-inner-spin-button,
.margin-input::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.margin-input:focus {
    outline: none;
    border-color: #ff6154;
    box-shadow: 0 0 0 3px rgba(255, 97, 84, 0.1);
}

.margin-unit-label {
    font-size: 0.65rem;
    color: #b0b5bc;
    text-align: center;
    font-weight: 500;
}

/* Quick Actions */
.quick-actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.quick-action-btn {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 16px;
    background: #f8f9fa;
    border: 2px solid #e5e7eb;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: left;
    font-family: inherit;
    width: 100%;
}

.quick-action-btn:hover {
    border-color: #ff6154;
    background: #fff5f4;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(255, 97, 84, 0.12);
}

.quick-action-btn:active {
    transform: translateY(0);
}

.quick-action-icon {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: white;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}

.quick-action-icon svg {
    width: 26px;
    height: 26px;
    stroke: #ff6154;
}

.quick-action-text {
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.quick-action-label {
    font-size: 0.88rem;
    font-weight: 700;
    color: #1f2937;
}

.quick-action-desc {
    font-size: 0.72rem;
    color: #9ca3af;
    font-weight: 500;
}

.preset-row {
    display: flex;
    gap: 6px;
}

.preset-btn {
    flex: 1;
    padding: 9px 10px;
    background: white;
    border: 1.5px solid #e5e7eb;
    border-radius: 10px;
    cursor: pointer;
    font-size: 0.78rem;
    font-weight: 600;
    color: #6b7280;
    transition: all 0.2s ease;
    font-family: inherit;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
}

.preset-btn:hover {
    border-color: #ff6154;
    color: #ff6154;
    background: #fff5f4;
}

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

.preset-btn.reset {
    color: #9ca3af;
}

.preset-btn.reset svg {
    stroke: #9ca3af;
}

.preset-btn.reset:hover {
    color: #6b7280;
    border-color: #d1d5db;
    background: #f3f4f6;
}

.preset-btn.reset:hover svg {
    stroke: #6b7280;
}

/* Apply Toggle (segmented control) */
.apply-toggle {
    display: flex;
    background: #f3f4f6;
    border-radius: 10px;
    padding: 3px;
    gap: 2px;
}

.apply-toggle-btn {
    flex: 1;
    padding: 8px 6px;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: #6b7280;
    font-size: 0.78rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: inherit;
    white-space: nowrap;
}

.apply-toggle-btn:hover:not(.active) {
    color: #374151;
    background: rgba(255,255,255,0.5);
}

.apply-toggle-btn.active {
    background: white;
    color: #1f2937;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.custom-range-wrapper {
    margin-top: 8px;
}

.page-input {
    width: 100%;
    padding: 10px 14px;
    border: 2px solid #e5e7eb;
    border-radius: 10px;
    font-size: 0.9rem;
    font-weight: 600;
    color: #1f2937;
    background: #f8f9fa;
    transition: all 0.2s ease;
    box-sizing: border-box;
}

.page-input::placeholder {
    color: #9ca3af;
    font-weight: 500;
}

.page-input:focus {
    outline: none;
    border-color: #ff6154;
    box-shadow: 0 0 0 3px rgba(255, 97, 84, 0.1);
    background: white;
}

/* Extract Actions */
.extract-actions-vertical {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.btn-extract {
    width: 100%;
    padding: 20px;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 600;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 14px;
    text-align: left;
    position: relative;
}

.btn-extract.single {
    background-color: #ff6154;
    color: white;
}

.btn-extract.single:hover:not(:disabled) {
    background: #e5554a;
    box-shadow: 0 6px 16px rgba(255, 97, 84, 0.4);
    transform: translateY(-2px);
}

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

.btn-extract.btn-loading:disabled {
    opacity: 1;
    cursor: default;
}

.btn-arrow {
    width: 24px;
    height: 24px;
    stroke: white;
    flex-shrink: 0;
    margin-left: auto;
    transition: transform 0.2s ease;
}

.btn-extract:hover:not(:disabled) .btn-arrow {
    transform: translateX(4px);
}

.btn-extract-content {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1;
}

.btn-extract-title {
    font-size: 1rem;
    font-weight: 700;
}

.btn-extract-desc {
    font-size: 0.8rem;
    opacity: 0.8;
    font-weight: 400;
}

.btn-spinner {
    display: none;
    width: 24px;
    height: 24px;
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    position: absolute;
    left: 0;
    right: 0;
    top: 0;
    bottom: 0;
    margin: auto;
}

.btn-extract.btn-loading .btn-spinner {
    display: block;
    animation: btn-spinner 0.7s linear infinite;
}

.btn-extract.btn-loading .btn-arrow {
    display: none;
}

.btn-extract.btn-loading {
    pointer-events: none;
}

.btn-extract.btn-loading .btn-extract-content {
    visibility: hidden;
}

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

/* 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);
}

.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;
}

.pdf-preview-section::-webkit-scrollbar {
    width: 6px;
}

.pdf-preview-section::-webkit-scrollbar-track {
    background: #f3f4f6;
    border-radius: 10px;
}

.pdf-preview-section::-webkit-scrollbar-thumb {
    background: #d1d5db;
    border-radius: 10px;
}

.pdf-preview-section::-webkit-scrollbar-thumb:hover {
    background: #9ca3af;
}

.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;
    align-items: center;
    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;
}

.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;
}

#download-files-list {
    margin-top: 50px;
    margin-bottom: 24px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    max-height: calc(100vh - 400px);
    overflow-y: auto;
    padding-right: 8px;

    /* Thin custom scrollbar so a long batch list still feels at home
       inside the right-side panel. Matches .acl-files-grid in step 2
       so the visual treatment is consistent across screens. */
    scrollbar-width: thin;
    scrollbar-color: #d1d5db transparent;
}
#download-files-list::-webkit-scrollbar       { width: 6px; }
#download-files-list::-webkit-scrollbar-track { background: transparent; }
#download-files-list::-webkit-scrollbar-thumb {
    background: #d1d5db;
    border-radius: 10px;
}
#download-files-list::-webkit-scrollbar-thumb:hover {
    background: #9ca3af;
}

.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-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: 1000;
    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);
}

.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;
}

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

/* Hide elements when showing download screen */
.content-hidden {
    display: none !important;
}

.controls-panel::-webkit-scrollbar,
.files-preview-section::-webkit-scrollbar {
    width: 6px;
}

.controls-panel::-webkit-scrollbar-track,
.files-preview-section::-webkit-scrollbar-track {
    background: #f3f4f6;
}

.controls-panel::-webkit-scrollbar-thumb,
.files-preview-section::-webkit-scrollbar-thumb {
    background: #d1d5db;
    border-radius: 10px;
}

.controls-panel::-webkit-scrollbar-thumb:hover,
.files-preview-section::-webkit-scrollbar-thumb:hover {
    background: #9ca3af;
}

@media (max-width: 1200px) {
    .controls-panel {
        width: 380px;
    }

    .files-preview-section {
        margin-right: 380px;
    }

    .download-actions-section {
        width: 380px;
    }

    .pdf-preview-section {
        margin-right: 380px;
    }
}

@media (max-width: 968px) {
    body.selection-active {
        overflow-y: auto;
    }

    /* Reset top:81px from desktop fixed-position rule. When position
       flips to relative, top:81 stays in effect and shifts the panel
       81px DOWN from natural document flow, leaving a blank gap below
       the header. */
    .selection-panel {
        position: relative;
        top: auto;
        height: auto;
        min-height: calc(100vh - 81px);
    }

    .selection-content {
        flex-direction: column;
        height: auto;
    }

    /* Controls panel sits BELOW preview (order: 2). Border + shadow
       point UP (border-top + upward shadow) instead of down, since
       the panel is at the bottom of the column. */
    .controls-panel {
        position: relative;
        width: 100%;
        height: auto;
        top: 0;
        border-left: none;
        border-top: 2px solid #e5e7eb;
        box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.06);
        order: 2;
    }

    .files-preview-section {
        margin-right: 0;
        height: auto;
        order: 1;
        padding: 32px 24px;
        overflow-y: visible;
    }

    /* Hide .container at step 2 — JS hides .upload-area inside but
       leaves the empty container with its 20px padding visible
       above the selection-panel, creating dead space. */
    body.selection-active .container {
        display: none;
    }

    .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;
        top: auto;
        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;
    }

    .files-preview-section {
        padding: 24px 16px 40px 16px;
        min-height: auto;
    }

    .controls-panel {
        padding: 24px 16px;
    }

    .pdf-preview-section {
        padding: 80px 16px 24px 16px;
    }

    .download-actions-section {
        padding: 24px 16px;
    }

    .back-button {
        font-size: 0.9rem;
    }

    #download-files-list {
        max-height: none;
    }

    .margin-inputs {
        grid-template-columns: 1fr 1fr;
    }
}

/* ── 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; }

/* Bottom-center toast (mirrors ocr-pdf's .ocr-toast). Used to inform the user
   when multiple PDFs were dropped — crop is single-file, so we take the first
   and surface a non-blocking notice. */
.crop-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);
}
.crop-toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
    pointer-events: auto;
}
.crop-toast svg { color: rgba(255,255,255,0.6); flex-shrink: 0; }

/* ── Fullscreen drop zone (matches compress-pdf / split-pdf) ── */
.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;
}

/* ============================================================
   MOBILE & TABLET OVERRIDES — added 2026-05-07
   Standard phone fixes layered on top of the existing 1200/968/
   768 blocks. Existing 968 already has step-2 reorder (preview top,
   controls bottom) + top:auto reset + container-hide. This block
   adds iOS-zoom + safe-area + modal-bounds + ≤970 download
   full-screen 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; }

    /* "Compact Preview" toggle into normal flow above page-nav
       (same fix as redact/add-page-numbers/watermark). */
    .preview-mode-toggle {
        position: relative;
        top: auto;
        right: auto;
        align-self: flex-end;
        margin-bottom: 12px;
    }

    /* Safe-area on bottom-anchored UI for iPhone home indicator. */
    .controls-panel {
        padding-bottom: max(20px, env(safe-area-inset-bottom));
    }
    .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;
    }
}

/* ---- Tablet & narrow desktop — download view full-screen (≤970px) ----
   Mirrors the merge/sign/redact/grayscale recipe with the lessons
   learned: min-height: 0 on screen + content prevents the short
   success view from forcing itself to fill the viewport. */
@media (max-width: 970px) {
    .download-screen .pdf-preview-section { display: none !important; }
    body.download-active .hero { display: none !important; }

    .download-screen {
        background: white !important;
        min-height: 0 !important;
        height: auto !important;
    }
    .download-content {
        flex-direction: column;
        height: auto !important;
        min-height: 0 !important;
        background: white;
    }
    .download-actions-section {
        position: relative !important;
        width: 100% !important;
        height: auto !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;
        /* Kill desktop's `overflow-y: auto` (which implicitly sets
           overflow-x:auto per CSS spec) — on tablet/phone the
           section flows with the page; nothing inside should
           need an internal horizontal scrollbar. */
        overflow: visible !important;
    }

    .download-actions-section > * {
        width: 100%;
        max-width: 480px;
        box-sizing: border-box;
    }
    .download-primary,
    #download-files-list,
    .single-file-card,
    .extract-another-btn {
        max-width: 480px;
        margin-left: auto;
        margin-right: auto;
    }

    /* Back button stays inside the same 480px centered content
       column as the file row + Download button, so its arrow icon
       lines up with the LEFT edge of that column. On tablet
       widths the section is wider than 480px (e.g. 800px viewport
       → ~110px gutter on each side), and using `align-self:
       flex-start` would have anchored the back-button to the
       section's left edge instead — making it look detached from
       the centered content. width: 100% + max-width: 480 + auto
       margins keeps it in the column; justify-content: flex-start
       (the button itself is a flex container) keeps the icon +
       text on the LEFT inside that column. */
    .back-button {
        position: relative !important;
        top: auto !important;
        left: auto !important;
        margin: 0 auto 24px !important;
        padding: 0 !important;
        width: 100% !important;
        max-width: 480px !important;
        display: flex !important;
        justify-content: flex-start !important;
        align-self: auto !important;
    }

    #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; }
}

/* ─── Multi-file step 2 (batch upload) ─────────────────────────────
   Used when the user picks 2+ PDFs and the .crop-preview-area is
   hidden. Lays out file cards in a responsive grid that scrolls
   inside the .files-preview-section. The parent has its own padding
   and centers content; we override with align-self: stretch and let
   the inner grid handle scrolling. */
#aclMultiList {
    align-self: stretch;
    flex: 1;
    min-height: 0;
    width: 100%;
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
    overflow: hidden;
}

.acl-files-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 18px;
    flex-shrink: 0;
}

.acl-files-header-title {
    font-size: 15px;
    font-weight: 600;
    color: #1f2937;
}

.acl-files-header-meta {
    font-size: 13px;
    color: #6b7280;
    font-weight: 500;
}

.acl-files-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 14px;
    overflow-y: auto;
    align-content: start;
    padding-right: 6px;
    padding-bottom: 8px;
    flex: 1;
    min-height: 0;
}

.acl-files-grid::-webkit-scrollbar { width: 6px; }
.acl-files-grid::-webkit-scrollbar-track { background: transparent; }
.acl-files-grid::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 10px; }
.acl-files-grid::-webkit-scrollbar-thumb:hover { background: #9ca3af; }

.acl-file-card {
    background: white;
    border: 2px solid #e5e7eb;
    border-radius: 12px;
    padding: 14px;
    display: flex;
    align-items: center;
    gap: 12px;
    box-sizing: border-box;
    transition: border-color 0.15s ease, background-color 0.15s ease;
    min-width: 0;
}

.acl-file-card:hover {
    border-color: #ff6154;
    background: #fff5f4;
}

.acl-file-card.removing {
    opacity: 0.4;
    transform: scale(0.97);
    transition: opacity 0.2s, transform 0.2s;
}

.acl-file-thumb {
    width: 44px;
    height: 56px;
    background: #f9fafb;
    border-radius: 4px;
    flex-shrink: 0;
    overflow: hidden;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08), 0 0 0 1px rgba(0, 0, 0, 0.04);
    display: flex;
    align-items: center;
    justify-content: center;
}

.acl-file-thumb canvas {
    width: 100%;
    height: 100%;
    display: block;
    object-fit: cover;
}

.acl-file-thumb-fallback {
    font-size: 9px;
    font-weight: 700;
    color: #9ca3af;
    letter-spacing: .5px;
}

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

.acl-file-name {
    font-size: 13.5px;
    font-weight: 600;
    color: #1f2937;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 3px;
}

.acl-file-meta {
    font-size: 12px;
    color: #6b7280;
    display: flex;
    align-items: center;
    gap: 6px;
}

.acl-file-meta-dot {
    width: 3px;
    height: 3px;
    border-radius: 50%;
    background: #d1d5db;
}

.acl-file-remove {
    width: 30px;
    height: 30px;
    border-radius: 6px;
    border: none;
    background: transparent;
    color: #9ca3af;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.15s, color 0.15s;
}

.acl-file-remove:hover {
    background: #fee2e2;
    color: #b91c1c;
}

.acl-file-remove svg {
    width: 16px;
    height: 16px;
}

@media (max-width: 970px) {
    .acl-files-grid {
        grid-template-columns: 1fr;
        gap: 10px;
    }
}

/* ─── Multi-file download screen (per-file cards) ──────────────────
   Matches the extract-pdf-pages download layout: preview on left,
   list of file-preview-cards on right. Clicking a card switches the
   preview to that file. */
.file-preview-card {
    background: none;
    border: none;
    border-radius: 10px;
    padding: 8px 10px;
    display: flex;
    align-items: center;
    gap: 12px;
    transition: background 0.15s ease;
    cursor: pointer;
}

.file-preview-card:hover {
    background: #f5f5f5;
}

.file-preview-card.active {
    background: #f0f1f3;
}

.file-preview-thumb {
    width: 48px;
    height: 58px;
    background: white;
    border-radius: 4px;
    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);
}

.file-preview-thumb canvas {
    width: 100%;
    height: 100%;
    display: block;
    object-fit: cover;
}

.file-preview-details {
    flex: 1;
    text-align: left;
    min-width: 0;
}

.file-preview-name {
    font-size: 0.85rem;
    font-weight: 600;
    color: #1f2937;
    margin-bottom: 2px;
    display: flex;
    align-items: center;
    min-width: 0;
}

.file-preview-name-base {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
}

.file-preview-name-ext {
    white-space: nowrap;
    flex-shrink: 0;
    color: #9ca3af;
    margin-left: auto;
}

.file-preview-info {
    font-size: 0.7rem;
    color: #9ca3af;
}

.file-download-btn {
    background: #f9f9f9;
    border: none;
    color: #9ca3af;
    padding: 8px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.15s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.file-download-btn:hover {
    background: #f3f4f6;
    color: #6b7280;
}

.file-download-btn svg {
    width: 16px;
    height: 16px;
}

/* ─── Upload Overlay (circle ring) ─────────────────────────────────
   Mirrors compress-pdf's upload UX: ring fills with upload %, then
   morphs to a thin bar as the loading-screen fades in behind it for
   the server-processing phase. */
.upload-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.97);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.35s ease;
}
.upload-overlay.active {
    opacity: 1;
    pointer-events: all;
}
.upload-overlay.hidden {
    display: none;
}
.upload-overlay-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    animation: aclUploadCardIn 0.5s cubic-bezier(0.32, 0.72, 0, 1) both;
}
.upload-center-group {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 28px;
}
@keyframes aclUploadCardIn {
    from { opacity: 0; transform: translateY(16px) scale(0.97); }
    to   { opacity: 1; transform: translateY(0)    scale(1); }
}
.upload-ring-wrap {
    position: relative;
    width: 120px;
    height: 120px;
    overflow: hidden;
    transition: width 0.7s cubic-bezier(0.4, 0, 0.2, 1),
                height 0.7s cubic-bezier(0.4, 0, 0.2, 1),
                border-radius 0.7s cubic-bezier(0.4, 0, 0.2, 1);
}
.upload-ring {
    width: 100%;
    height: 100%;
    transform: rotate(-90deg);
}
.upload-ring-track {
    fill: none;
    stroke: #fff;
    stroke-width: 5;
}
.upload-ring-fill {
    fill: none;
    stroke: #ff6154;
    stroke-width: 5;
    stroke-linecap: round;
    stroke-dasharray: 263.89;
    stroke-dashoffset: 263.89;
    transition: stroke-dashoffset 0.3s ease;
}
.upload-ring-center {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.2s ease;
}
.upload-ring-percent {
    font-size: 1.5rem;
    font-weight: 700;
    color: #1f2937;
    font-variant-numeric: tabular-nums;
}
.upload-phase {
    font-size: 1.05rem;
    font-weight: 600;
    color: #1f2937;
    transition: opacity 0.3s ease;
}
.upload-file-name {
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.8rem;
    color: #9ca3af;
    max-width: 260px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 12px;
    transition: opacity 0.3s ease;
}
/* Morph: ring-wrap shrinks to a thin bar shape; SVG + text fade out so
   the loading-screen behind takes over visually. */
.upload-overlay-card.morphing .upload-ring-wrap {
    width: 300px;
    height: 4px;
    border-radius: 2px;
}
.upload-overlay-card.morphing .upload-ring { opacity: 0; transition: opacity 0.2s ease; }
.upload-overlay-card.morphing .upload-ring-center { opacity: 0; }
.upload-overlay-card.morphing .upload-phase,
.upload-overlay-card.morphing .upload-file-name { opacity: 0; }

/* Disabled state for an .apply-toggle-btn (used to grey out "Single
   merged" when Thermal mode is active — merged + thermal is awkward
   on a fixed-stock device). */
.apply-toggle-btn.disabled,
.apply-toggle-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    pointer-events: auto; /* keep tooltip cursor visible */
}
.apply-toggle-btn.disabled:hover {
    background: transparent;
}

/* Printer-mode hint text below the Thermal/Normal toggle. */
.acl-mode-hint {
    font-size: 12.5px;
    color: #6b7280;
    line-height: 1.5;
    margin: 10px 0 0;
}

/* ─── Download All loading state ───────────────────────────────────
   Mirrors flatten-pdf's "Download All" animation: while the zip
   download is triggering, the button collapses to a white pill with
   a narrow coral progress line filling 0%→40% over 2s. Same keyframe
   timings so the visual matches flatten's batch mode exactly. */
.download-primary.loading {
    pointer-events: none;
    position: relative;
    background-color: #fff;
    box-shadow: 0 0 0 1px #e5e7eb;
    transform: none;
    color: transparent;
}
.download-primary.loading svg { opacity: 0; }
.download-primary.loading::after {
    content: '';
    position: absolute;
    left: 30%;
    width: 40%;
    height: 5px;
    background: #fff;
    border-radius: 4px;
    opacity: 0;
    animation: aclLoadingFadeIn 0.18s 0.15s ease forwards;
}
.download-primary.loading::before {
    content: '';
    position: absolute;
    left: 30%;
    width: 0%;
    height: 5px;
    background: #ff6154;
    z-index: 1;
    border-radius: 4px;
    opacity: 0;
    animation: aclLoadingFadeIn 0.18s 0.15s ease forwards,
               aclLoadingFill 2s 0.15s ease-out forwards;
}
@keyframes aclLoadingFadeIn { to { opacity: 1; } }
@keyframes aclLoadingFill {
    0%   { width: 0%; }
    30%  { width: 20%; }
    50%  { width: 28%; }
    70%  { width: 33%; }
    85%  { width: 36%; }
    100% { width: 40%; }
}

