@import url('https://fonts.googleapis.com/css2?family=Roboto:wght@400;700&display=swap');

@font-face { font-family: 'Roboto'; src: url('Roboto Regular.ttf') format('truetype'); font-display: swap; }
@font-face { font-family: 'Jameel Noori'; src: url('urdu.ttf') format('truetype'); font-display: swap; }
@font-face { font-family: 'Jameel Kasheeda'; src: url('Jameel Noori Nastaleeq Kasheeda.ttf') format('truetype'); font-display: swap; }

body { background-color: #3e4144; margin: 0; padding: 0; overflow-x: hidden; }
#pages-wrapper { display: flex; flex-direction: column; align-items: center; width: 100%; }

.a4-container { display: flex; flex-direction: column; align-items: center; margin-bottom: 40px; position: relative; max-width: 100%; }

.a4-page { 
    width: 210mm; height: 297mm; background: white; 
    position: relative; box-shadow: 0 0 20px rgba(0,0,0,0.5); 
    max-width: none; 
}

.content-boundary {
    position: absolute;
    top: 10mm; left: 10mm; right: 10mm; bottom: 10mm;
    border: 1px solid #000;
    overflow: hidden; 
    z-index: 5;
}

.editor-area { 
    width: 100%; height: 100%; outline: none; padding: 5mm; 
    box-sizing: border-box; word-wrap: break-word; font-family: 'Jameel Noori', serif; 
    font-size: 24px; line-height: 1.8; direction: rtl; text-align: right; 
}

.active-page { border: 2px solid #3b82f6; }
.active-tool { background-color: #bfdbfe !important; color: #1e40af !important; }

.page-insert-controls { display: flex; gap: 15px; margin-top: 20px; }
.insert-btn {
    padding: 8px 25px; border-radius: 30px; font-weight: bold; font-size: 11px;
    cursor: pointer; border: none; color: white; box-shadow: 0 4px 10px rgba(0,0,0,0.3);
}
.add-page { background: #4f46e5; }
.add-pdf { background: #059669; }

.page-controls { 
    position: absolute; top: 10mm; left: -130px; 
    display: flex; flex-direction: column; gap: 10px; z-index: 10; 
}
.control-btn { 
    border: none; border-radius: 6px; color: white; padding: 10px; 
    font-size: 12px; font-weight: bold; cursor: pointer; width: 115px; 
    box-shadow: 0 2px 5px rgba(0,0,0,0.3); transition: transform 0.1s; text-align: center;
}
.control-btn:active { transform: scale(0.95); }
.del-btn { background: #dc2626; } 
.img-btn { background: #2563eb; } 
.png-btn { background: #8b5cf6; } 

.fixed.top-0 { z-index: 9999 !important; }

.resize-container { position: absolute; cursor: move; border: 1.5px dashed transparent; z-index: 100; }
.resize-container.selected { border: 1.5px solid #3b82f6; background: rgba(59, 130, 246, 0.05); }
.resize-container img { width: 100%; height: 100%; display: block; user-select: none; }

.img-control-btn {
    position: absolute; color: white; border: 2px solid white; border-radius: 4px; 
    padding: 3px 8px; font-size: 10px; font-weight: bold; cursor: pointer; 
    display: none; z-index: 1010; box-shadow: 0 2px 5px rgba(0,0,0,0.3);
}
.resize-container.selected .img-control-btn { display: block; }
.crop-btn-corner { top: -15px; left: -15px; background: #3b82f6; }
.del-btn-corner { top: -15px; right: -15px; background: #ef4444; }

.rotate-handle {
    position: absolute; top: -30px; left: calc(50% - 14px);
    width: 28px; height: 28px; background: #10b981; border: 2px solid white; 
    border-radius: 50%; display: none; cursor: crosshair; z-index: 1010;
    box-shadow: 0 2px 5px rgba(0,0,0,0.3); color: white; font-size: 14px;
    text-align: center; line-height: 24px; font-weight: bold;
}
.resize-container.selected .rotate-handle { display: block; }

.page-footer { position: absolute; bottom: -20px; left: 50%; transform: translateX(-50%); color: #999; font-size: 10px; }

.print-exact {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
}

/* === نیا: موبائل فرینڈلی سیٹنگز (Mobile Responsiveness) === */
@media (max-width: 900px) {
    #pages-wrapper {
        align-items: flex-start !important; /* پیپر کو درمیان میں پھنسنے سے روکے گا */
        padding-left: 10px !important;
        padding-right: 10px !important;
        overflow-x: auto !important; /* دائیں بائیں اسکرول کرنے کی اجازت */
        -webkit-overflow-scrolling: touch;
    }
    .a4-container {
        align-items: flex-start !important;
        margin-left: 0 !important;
    }
    .page-controls {
        position: relative !important;
        left: 0 !important;
        top: 0 !important;
        flex-direction: row !important; /* بٹنز کو ایک سیدھی لائن میں لائے گا */
        width: 210mm !important; 
        justify-content: center !important;
        margin-bottom: 15px !important;
        gap: 15px !important;
    }
    .control-btn {
        width: auto !important;
        padding: 10px 20px !important;
    }
    .editor-area {
        padding: 15px !important; /* ٹیکسٹ کو کٹنے سے بچانے کے لیے محفوظ فاصلہ */
    }
}

@media print {
    @page { margin: 0; size: A4 portrait; }
    body { background-color: #ffffff !important; margin: 0 !important; padding: 0 !important; }
    .fixed, .page-controls, .page-insert-controls, .img-control-btn, .rotate-handle, #toast-container, footer, .bg-yellow-50, .bg-blue-50, .w-full.bg-white.border-t { display: none !important; }
    
    #pages-wrapper { padding: 0 !important; margin: 0 !important; width: 100% !important; overflow: visible !important; }
    .a4-container { margin: 0 auto !important; page-break-after: always; box-shadow: none !important; padding: 0 !important; border: none !important; }
    .a4-page { box-shadow: none !important; border: none !important; margin: 0 auto !important; width: 210mm !important; height: 297mm !important; }
    
    .content-boundary { border: none !important; }
    .paper-body { border: 2px solid #000 !important; }
}