/* Layout & Container */
.pdf-app-body { position: relative; }
.tool-container { max-width: 700px; margin: 0 auto; padding: 20px 16px; display: flex; flex-direction: column; gap: 20px; }

/* Upload Area */
.upload-area { border: 2px dashed var(--border-color); border-radius: 20px; background-color: var(--bg-surface); padding: 50px 20px; text-align: center; transition: all 0.3s ease; cursor: pointer; }
.upload-area:hover, .upload-area.dragover { border-color: var(--primary-blue); background-color: rgba(37, 99, 235, 0.05); }
.upload-icon-wrapper { color: var(--primary-blue); margin-bottom: 16px; font-size: 56px; }
.upload-area h3 { font-size: 1.25rem; font-weight: 800; color: var(--text-main); margin-bottom: 8px; }
.upload-area p { color: var(--text-muted); font-size: 0.95rem; margin-bottom: 24px; font-weight: 500;}

/* Workspace & Grid */
.workspace-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; background: var(--bg-surface); padding: 12px 16px; border-radius: 16px; border: 1px solid var(--border-color); }
.page-count-badge { display: flex; align-items: center; gap: 8px; font-size: 1rem; font-weight: 800; color: var(--text-main); }
.page-count-badge i { color: var(--primary-blue); font-size: 20px; }
.workspace-actions { display: flex; gap: 12px; }
.helper-text { font-size: 0.85rem; color: var(--text-muted); font-weight: 600; margin-bottom: 16px; display: flex; align-items: center; gap: 6px; }
.document-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 16px; margin-bottom: 24px; }

/* 🔥 BULLETPROOF MOBILE TOUCH CSS 🔥 */
.doc-card {
    position: relative; width: 100%; aspect-ratio: 3 / 4; 
    border-radius: 12px; overflow: hidden;
    border: 2px solid var(--border-color);
    box-shadow: var(--shadow-sm); animation: popIn 0.3s ease;
    background: var(--bg-surface); cursor: grab;
    /* Block default mobile actions */
    -webkit-touch-callout: none !important;
    -webkit-user-select: none !important;
    user-select: none !important;
    touch-action: pan-y !important;
}
.doc-card:active { cursor: grabbing; border-color: var(--primary-blue); }

.doc-card img { 
    width: 100%; height: 100%; object-fit: cover; transition: transform 0.3s;
    /* Force touch events to pass to the card, not the image itself */
    pointer-events: none !important; 
    -webkit-user-drag: none !important;
}

.page-badge { position: absolute; top: 6px; left: 6px; background: rgba(0, 0, 0, 0.8); color: white; font-size: 0.75rem; font-weight: 800; padding: 4px 8px; border-radius: 8px; z-index: 2; pointer-events: none; }

.card-overlay {
    position: absolute; bottom: 0; left: 0; right: 0; background: linear-gradient(transparent, rgba(0,0,0,0.85));
    padding: 24px 8px 8px; display: flex; justify-content: space-between;
    opacity: 0.85; transition: opacity 0.2s; z-index: 2;
}
@media (hover: hover) { .card-overlay { opacity: 0; } .doc-card:hover .card-overlay, .doc-card:active .card-overlay { opacity: 1; } }

.action-icon-btn { background: rgba(255, 255, 255, 0.2); backdrop-filter: blur(4px); border: none; color: white; width: 34px; height: 34px; border-radius: 50%; display: flex; align-items: center; justify-content: center; cursor: pointer; font-size: 18px; transition: 0.2s; }
.action-icon-btn.edit:active { background: var(--primary-blue); transform: scale(1.1); }
.action-icon-btn.delete:active { background: #ef4444; transform: scale(1.1); }

.sortable-ghost { opacity: 0.4; border: 2px dashed var(--primary-blue); transform: scale(0.95); }

/* PDF Settings */
.pdf-settings-card { background: var(--bg-surface); padding: 20px; border-radius: 16px; border: 1px solid var(--border-color); box-shadow: var(--shadow-sm); }
.settings-title { font-size: 1.1rem; color: var(--text-main); font-weight: 800; margin-bottom: 16px; display: flex; align-items: center; gap: 8px; }
.settings-title i { color: #f59e0b; }
.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.input-group { display: flex; flex-direction: column; gap: 8px; }
.input-group label { font-size: 0.85rem; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px;}
.custom-select { width: 100%; padding: 14px; border-radius: 12px; border: 2px solid var(--border-color); background: var(--bg-body); color: var(--text-main); font-size: 0.95rem; font-weight: 700; font-family: 'Inter', sans-serif; outline: none; transition: all 0.3s ease; cursor: pointer; }

/* Sticky Bottom Bar */
.bottom-action-bar { position: fixed; bottom: 0; left: 0; right: 0; background: var(--bg-surface); padding: 16px 20px; padding-bottom: calc(16px + env(safe-area-inset-bottom)); box-shadow: 0 -10px 30px rgba(0,0,0,0.1); border-top: 1px solid var(--border-color); z-index: 1000; display: flex; justify-content: center; }
.ultra-primary-btn { width: 100%; max-width: 500px; background: linear-gradient(135deg, var(--primary-blue), var(--primary-dark)); color: white; padding: 16px 24px; border-radius: 50px; font-weight: 800; font-size: 1.15rem; border: none; cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 10px; box-shadow: 0 8px 25px rgba(37, 99, 235, 0.4); transition: transform 0.2s, box-shadow 0.2s; }
.ultra-primary-btn:active { transform: scale(0.97); box-shadow: 0 4px 15px rgba(37, 99, 235, 0.3); }

/* Full Screen Editor */
.editor-modal { position: fixed; top: 0; left: 0; width: 100vw; height: 100vh; background: #0f172a; z-index: 3000; display: flex; flex-direction: column; transition: opacity 0.3s ease, transform 0.3s cubic-bezier(0.16, 1, 0.3, 1); }
.editor-modal.hidden { opacity: 0; transform: translateY(100%); pointer-events: none; }
.editor-header { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; background: rgba(0,0,0,0.5); color: white; padding-top: calc(16px + env(safe-area-inset-top)); border-bottom: 1px solid rgba(255,255,255,0.1); }
.editor-header h3 { font-size: 1.1rem; font-weight: 700; margin: 0; }
.editor-header .icon-button { color: white; font-size: 24px; }
.editor-workspace { flex: 1; background: #000; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.editor-workspace img { max-width: 100%; max-height: 100%; display: block; }
.editor-toolbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 20px; background: rgba(0,0,0,0.9); border-top: 1px solid rgba(255,255,255,0.1); padding-bottom: calc(20px + env(safe-area-inset-bottom)); }
.editor-tool-btn { background: rgba(255,255,255,0.15); color: white; border: none; width: 48px; height: 48px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 22px; cursor: pointer; transition: 0.2s; }
.editor-tool-btn:active { background: rgba(255,255,255,0.3); transform: scale(0.9); }
.editor-primary-btn { background: #10b981; color: white; border: none; padding: 14px 24px; border-radius: 50px; font-weight: 800; font-size: 1rem; display: flex; align-items: center; gap: 8px; cursor: pointer; margin-left: auto; }

/* Utilities */
.primary-btn { background-color: var(--primary-blue); color: white; padding: 14px 24px; border-radius: 50px; font-weight: 800; font-size: 1.05rem; border: none; cursor: pointer; display: inline-flex; align-items: center; gap: 8px; font-family: 'Inter', sans-serif; }
.text-btn { background: none; border: none; font-weight: 700; font-size: 0.95rem; cursor: pointer; display: flex; align-items: center; gap: 6px; }
.text-btn.success { color: #10b981; } .text-btn.danger { color: #ef4444; }

.toast { position: fixed; top: 80px; left: 50%; transform: translateX(-50%) translateY(-20px); background-color: #10b981; color: white; padding: 14px 28px; border-radius: 50px; font-weight: 700; font-size: 0.95rem; box-shadow: 0 10px 30px rgba(16, 185, 129, 0.4); opacity: 0; visibility: hidden; transition: all 0.3s ease; z-index: 4000; }
.toast.visible { opacity: 1; visibility: visible; transform: translateX(-50%) translateY(0); }
.hidden { display: none !important; }
@keyframes popIn { from { transform: scale(0.8); opacity: 0; } to { transform: scale(1); opacity: 1; } }

.modal-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0, 0, 0, 0.7); backdrop-filter: blur(5px); z-index: 2000; display: flex; align-items: center; justify-content: center; transition: all 0.3s ease; }
.modal-overlay.hidden { opacity: 0; visibility: hidden; pointer-events: none; }
.modal-content { background: var(--bg-surface); width: 90%; max-width: 400px; padding: 24px; border-radius: 24px; border: 1px solid var(--border-color); }