body { font-family: 'Cairo', sans-serif; background-color: #F8FAFC; transition: all 0.3s ease; }
.hidden-section { display: none !important; }
.perm-denied { display: none !important; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: #f1f1f1; border-radius: 4px; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }
.excel-table { border-collapse: collapse; width: 100%; background: #ffffff; position: relative; z-index: 5; }
.excel-table th, .excel-table td { border: 1px solid #000 !important; padding: 5px 8px; font-size: 11px; color: #000; background-color: #ffffff; }
.excel-table th { background-color: #e5e7eb !important; text-align: center; font-weight: bold; }

/* ضبط حاوية اللوجو والترويسة للطباعة ومنع التداخل */
.print-bg-container { display: none; pointer-events: none; overflow: hidden; }
.print-bg-container img { display: block; width: 100%; height: 100%; object-fit: fill; }

/* ===== واجهة عروض الأسعار ===== */
.qt-card { background: #fff; border: 1px solid #e5e7eb; border-radius: 1rem; padding: 1.25rem; box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04); }
.qt-card-title { display: flex; align-items: center; gap: .5rem; font-weight: 800; color: #111827; font-size: .95rem; margin-bottom: 1rem; }
.qt-card-title > i { color: #0284C7; }
.qt-field { display: flex; flex-direction: column; gap: .375rem; font-size: .75rem; font-weight: 700; color: #4b5563; min-width: 0; }
.qt-input { width: 100%; padding: .625rem .75rem; border: 1px solid #e5e7eb; background: #f9fafb; border-radius: .75rem; font-size: 16px; font-weight: 600; color: #111827; outline: none; transition: border-color .15s, box-shadow .15s, background-color .15s; }
.q-desc.qt-input, .item-desc { min-height: 2.5rem; height: auto; resize: vertical !important; overflow-y: auto; line-height: 1.45; font-family: inherit; display: block; box-sizing: border-box; unicode-bidi: plaintext; text-align: start; }
@media (min-width: 768px) { .qt-input { font-size: .875rem; } }
.qt-input:focus { background: #fff; border-color: #0284C7; box-shadow: 0 0 0 3px rgba(2, 132, 199, .15); }
.qt-input::placeholder { color: #9ca3af; font-weight: 500; }
.qt-input[type=number]::-webkit-inner-spin-button, .qt-input[type=number]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.qt-input[type=number] { -moz-appearance: textfield; }
/* قائمة اختيار العملاء مع بحث */
.qt-combo { position: relative; }
.qt-combo-btn { position: absolute; top: .35rem; inset-inline-end: .5rem; width: 1.75rem; height: 1.75rem; display: flex; align-items: center; justify-content: center; color: #9ca3af; font-size: .75rem; border-radius: .375rem; transition: color .15s, transform .15s, background-color .15s; z-index: 2; }
.qt-combo-btn:hover { color: #0284C7; background-color: #f0f9ff; }
.qt-combo.open .qt-combo-btn i { transform: rotate(180deg); }
.qt-combo-pop { position: absolute; z-index: 40; top: calc(100% + .375rem); inset-inline: 0; max-height: 16rem; overflow-y: auto; background: #fff; border: 1px solid #e5e7eb; border-radius: .875rem; box-shadow: 0 12px 32px rgba(15, 23, 42, .14); padding: .375rem; }
.qt-combo-opt { display: flex; align-items: center; justify-content: space-between; gap: .5rem; width: 100%; padding: .55rem .75rem; border-radius: .6rem; font-size: .875rem; font-weight: 600; color: #1f2937; text-align: start; cursor: pointer; }
.qt-combo-opt[aria-selected=true], .qt-combo-opt:hover { background: #f0f9ff; color: #0369A1; }
.qt-combo-opt mark { background: #fef08a; color: inherit; border-radius: .2rem; padding: 0 .05rem; }
.qt-combo-pop-wide { min-width: min(26rem, calc(100vw - 3rem)); }
.qt-combo-sub { flex-shrink: 0; font-size: .7rem; font-weight: 700; color: #9ca3af; font-family: ui-monospace, monospace; }
.qt-combo-group { padding: .5rem .75rem .25rem; font-size: .7rem; font-weight: 800; color: #9ca3af; }
.qt-combo-empty { padding: .75rem; font-size: .8rem; font-weight: 600; color: #6b7280; text-align: center; }
.qt-btn-primary { display: inline-flex; align-items: center; justify-content: center; gap: .5rem; background: #0284C7; color: #fff; font-weight: 700; font-size: .875rem; padding: .75rem 1rem; border-radius: .75rem; box-shadow: 0 4px 12px rgba(2, 132, 199, .25); transition: background-color .15s, opacity .15s; }
.qt-btn-primary:hover { background: #0369A1; }
.qt-btn-primary:disabled { opacity: .6; cursor: wait; }
.qt-btn-secondary { display: inline-flex; align-items: center; justify-content: center; gap: .5rem; background: #fff; color: #374151; font-weight: 700; font-size: .875rem; padding: .625rem 1rem; border-radius: .75rem; border: 1px solid #e5e7eb; transition: background-color .15s, border-color .15s, color .15s; }
.qt-btn-secondary:hover { background: #f9fafb; border-color: #d1d5db; color: #111827; }
.qt-btn-flow { display: flex; align-items: center; justify-content: center; gap: .5rem; width: 100%; font-weight: 700; font-size: .875rem; padding: .75rem 1rem; border-radius: .75rem; transition: background-color .15s; }
.qt-stat { display: flex; align-items: center; gap: .75rem; background: #fff; border: 1px solid #e5e7eb; border-radius: 1rem; padding: .75rem; min-width: 0; }
.qt-stat-icon { width: 2.5rem; height: 2.5rem; border-radius: .75rem; display: none; align-items: center; justify-content: center; flex-shrink: 0; }
@media (min-width: 640px) { .qt-stat { padding: 1rem; } .qt-stat-icon { display: flex; } }
.qt-stat-label { font-size: .7rem; font-weight: 700; color: #6b7280; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.qt-stat-value { font-size: 1.125rem; font-weight: 900; color: #111827; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@media (min-width: 640px) { .qt-stat-value { font-size: 1.375rem; } }
.qt-tab { display: inline-flex; align-items: center; justify-content: center; gap: .35rem; white-space: nowrap; padding: .5rem .4rem; border-radius: .625rem; font-size: .75rem; font-weight: 700; color: #6b7280; transition: background-color .15s, color .15s; min-width: 0; }
.qt-tab > i { display: none; }
@media (min-width: 640px) { .qt-tab { padding: .5rem .875rem; font-size: .8rem; } .qt-tab > i { display: inline; } }
.qt-tab:hover { color: #111827; }
.qt-tab[aria-selected=true] { background: #fff; color: #0284C7; box-shadow: 0 1px 3px rgba(15, 23, 42, .1); }
.qt-tab-count { display: inline-flex; align-items: center; justify-content: center; min-width: 1.4rem; height: 1.25rem; padding: 0 .35rem; border-radius: 999px; background: #e5e7eb; color: #4b5563; font-size: .7rem; font-weight: 800; }
.qt-tab[aria-selected=true] .qt-tab-count { background: #e0f2fe; color: #0369A1; }
.qt-list-row { display: flex; align-items: center; gap: .875rem; width: 100%; padding: .875rem 1rem; text-align: start; cursor: pointer; transition: background-color .15s; }
.qt-list-row:hover, .qt-list-row:focus-visible { background: #f9fafb; outline: none; }
.qt-badge { display: inline-flex; align-items: center; gap: .3rem; white-space: nowrap; font-size: .7rem; font-weight: 700; padding: .15rem .55rem; border-radius: 999px; box-shadow: inset 0 0 0 1px currentColor; }
.qt-bg-group { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .25rem; background: #f3f4f6; padding: .25rem; border-radius: .75rem; }
.qt-bg-opt { padding: .5rem .25rem; border-radius: .55rem; font-size: .75rem; font-weight: 700; color: #6b7280; transition: background-color .15s, color .15s; white-space: nowrap; }
.qt-bg-opt[aria-pressed=true] { background: #fff; color: #0284C7; box-shadow: 0 1px 3px rgba(15, 23, 42, .12); }
.qt-bg-group-dark { background: rgba(255, 255, 255, .08); }
.qt-bg-group-dark .qt-bg-opt { color: #d1d5db; }
.qt-price-toggle { color: #374151; }
.qt-price-toggle-dark { color: #e5e7eb; }
.qt-bg-group-dark .qt-bg-opt[aria-pressed=true] { background: #fff; color: #0369A1; }

/* بنود العرض: كروت على الموبايل وصفوف جدول على الشاشات الكبيرة */
.qt-row-grid { grid-template-columns: 2.25rem minmax(0, 1fr) 5.5rem 7rem 8rem 5rem; gap: .75rem; align-items: start; }
.q-row { position: relative; border: 1px solid #e5e7eb; border-radius: .875rem; padding: .75rem; background: #fff; transition: background-color .15s, opacity .15s; }
@media (min-width: 768px) { .q-row { display: grid; border: 0; border-radius: 0; padding: .625rem 1.25rem; } .q-row:hover { background: #fafafa; } }
.q-row .qt-input { padding: .5rem .625rem; }
.item-desc { min-height: 2.625rem; resize: vertical !important; line-height: 1.45; }
.q-index { width: 1.75rem; height: 1.75rem; border-radius: 999px; background: #f3f4f6; color: #4b5563; font-size: .75rem; font-weight: 800; display: inline-flex; align-items: center; justify-content: center; }
.q-mini-label { display: block; font-size: .7rem; font-weight: 700; color: #6b7280; margin-bottom: .25rem; }
@media (min-width: 768px) { .q-mini-label { display: none; } }
.q-total-box { padding: .5rem .625rem; border-radius: .75rem; background: #f3f4f6; text-align: center; font-weight: 900; color: #111827; font-size: .875rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.q-actions { position: absolute; top: .5rem; inset-inline-end: .5rem; display: flex; gap: .125rem; }
@media (min-width: 768px) { .q-actions { position: static; justify-content: center; } }
.q-act { width: 2.25rem; height: 2.25rem; border-radius: .6rem; display: inline-flex; align-items: center; justify-content: center; color: #9ca3af; cursor: pointer; transition: background-color .15s, color .15s; }
.q-act:hover { background: #f3f4f6; color: #374151; }
.q-act.q-del:hover { background: #fef2f2; color: #dc2626; }
.q-hidden-badge { display: none; }
.q-row.hide-on-print { background: #fffbeb; }
.q-row.hide-on-print .q-desc, .q-row.hide-on-print .q-total-box { color: #9ca3af; }
.q-row.hide-on-print .q-hidden-badge { display: inline-flex; }
.q-row.hide-on-print .q-hide-toggle { color: #d97706; background: #fef3c7; }
#quotation-items-body:empty::before { content: attr(data-empty); display: block; text-align: center; color: #9ca3af; font-size: .875rem; font-weight: 600; padding: 1.5rem; }
.q-row-new { animation: qRowIn .25s ease-out; }
@keyframes qRowIn { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }

/* ورقة الطباعة مخفية على الشاشة، وبتظهر في الطباعة والمعاينة */
.qt-doc { display: none; }
#qt-preview-paper, #qt-export-paper, .qt-export-paper, .qt-page-sheet, .qt-print-page { width: 210mm; min-height: 297mm; background: #fff; position: relative; box-shadow: 0 20px 50px rgba(0, 0, 0, .45); overflow: hidden; box-sizing: border-box; }
.qt-page-sheet { height: 297mm; max-height: 297mm; margin: 0 auto; }
.qt-print-page { height: 297mm; max-height: 297mm; margin: 0 auto; box-shadow: none; }
#qt-preview-paper .pv-bg, #qt-export-paper .pv-bg, .qt-export-paper .pv-bg, .qt-page-sheet .pv-bg, .qt-print-page .pv-bg { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: fill; pointer-events: none; z-index: 0; }
#qt-preview-paper .pv-content, #qt-export-paper .pv-content, .qt-export-paper .pv-content, .qt-page-sheet .pv-content, .qt-print-page .pv-content { position: relative; z-index: 1; padding: 48mm 12mm 28mm; box-sizing: border-box; }
#qt-preview-paper[data-bg=mpl] .pv-content, #qt-export-paper[data-bg=mpl] .pv-content, .qt-export-paper[data-bg=mpl] .pv-content, .qt-page-sheet[data-bg=mpl] .pv-content, .qt-print-page[data-bg=mpl] .pv-content { padding: 48mm 12mm 32mm; }
#qt-preview-paper[data-bg=trading] .pv-content, #qt-export-paper[data-bg=trading] .pv-content, .qt-export-paper[data-bg=trading] .pv-content, .qt-page-sheet[data-bg=trading] .pv-content, .qt-print-page[data-bg=trading] .pv-content { padding: 48mm 12mm 28mm; }
#qt-preview-paper[data-bg=ub] .pv-content, #qt-export-paper[data-bg=ub] .pv-content, .qt-export-paper[data-bg=ub] .pv-content, .qt-page-sheet[data-bg=ub] .pv-content, .qt-print-page[data-bg=ub] .pv-content { padding: 48mm 12mm 28mm; }
#qt-preview-paper .excel-table, #qt-export-paper .excel-table, .qt-export-paper .excel-table, .qt-page-sheet .excel-table, .qt-print-page .excel-table, #qt-preview-paper .excel-table td, #qt-export-paper .excel-table td, .qt-export-paper .excel-table td, .qt-page-sheet .excel-table td, .qt-print-page .excel-table td { background-color: transparent; }
#qt-preview-paper .excel-table th, #qt-export-paper .excel-table th, .qt-export-paper .excel-table th, .qt-page-sheet .excel-table th, .qt-print-page .excel-table th, #qt-preview-paper .excel-table td.bg-gray-50, #qt-export-paper .excel-table td.bg-gray-50, .qt-export-paper .excel-table td.bg-gray-50, .qt-page-sheet .excel-table td.bg-gray-50, .qt-print-page .excel-table td.bg-gray-50, #qt-preview-paper .excel-table td.bg-gray-100, #qt-export-paper .excel-table td.bg-gray-100, .qt-export-paper .excel-table td.bg-gray-100, .qt-page-sheet .excel-table td.bg-gray-100, .qt-print-page .excel-table td.bg-gray-100, #qt-preview-paper .excel-table td.bg-gray-200, #qt-export-paper .excel-table td.bg-gray-200, .qt-export-paper .excel-table td.bg-gray-200, .qt-page-sheet .excel-table td.bg-gray-200, .qt-print-page .excel-table td.bg-gray-200 { background-color: rgba(229, 231, 235, .55) !important; }
.qt-page-number { position: absolute; bottom: 8mm; left: 12mm; z-index: 2; font-size: 10px; font-weight: bold; color: #64748b; }
[dir=rtl] .qt-page-number { left: auto; right: 12mm; }

/* حركات القوائم */
.qt-fade { animation: qtFade .2s ease-out; }
@keyframes qtFade { from { opacity: 0; } to { opacity: 1; } }
.qt-sheet-panel { animation: qtSheetUp .25s cubic-bezier(.2, .8, .2, 1); }
@keyframes qtSheetUp { from { transform: translateY(100%); } to { transform: none; } }
[dir=rtl] .nav-drawer-panel { animation: drawerInRtl .25s cubic-bezier(.2, .8, .2, 1); }
[dir=ltr] .nav-drawer-panel { animation: drawerInLtr .25s cubic-bezier(.2, .8, .2, 1); }
@keyframes drawerInRtl { from { transform: translateX(100%); } to { transform: none; } }
@keyframes drawerInLtr { from { transform: translateX(-100%); } to { transform: none; } }
.drawer-link { display: flex; align-items: center; gap: .75rem; width: 100%; padding: .75rem .875rem; border-radius: .75rem; font-weight: 700; font-size: .9rem; color: #374151; transition: background-color .15s, color .15s; }
.drawer-link > i { width: 1.25rem; text-align: center; color: #9ca3af; }
.drawer-link:hover { background: #f3f4f6; }
.drawer-link[aria-current=page] { background: #f0f9ff; color: #0369A1; }
.drawer-link[aria-current=page] > i { color: #0284C7; }
[dir=ltr] .flip-x { transform: scaleX(-1); }

@media print {
    @page { size: A4; margin: 0; }
    html, body { height: auto !important; overflow: visible !important; background-color: white !important; }
    body { display: block !important; margin: 0; -webkit-print-color-adjust: exact; print-color-adjust: exact; }

    /* إخفاء عناصر السيستم غير المرغوبة عند الطباعة */
    body > *:not(#main-content):not(#invoice-bg-container) { display: none !important; }
    #main-navbar, #loader, #login-screen, .no-print, .hide-on-print { display: none !important; }
    .qt-doc { display: block !important; }
    #quotation-section #quotation-bg-container, #quotation-bg-container { display: none !important; }
    #quotation-section { padding: 0 !important; margin: 0 !important; }
    #quotation-print-area { padding: 0 !important; margin: 0 !important; width: 100% !important; }

    .qt-print-page {
        width: 210mm !important;
        height: 296mm !important;
        max-height: 296.5mm !important;
        position: relative !important;
        overflow: hidden !important;
        page-break-after: always !important;
        break-after: page !important;
        page-break-inside: avoid !important;
        break-inside: avoid !important;
        box-sizing: border-box !important;
        margin: 0 auto !important;
        padding: 0 !important;
        box-shadow: none !important;
        background: #fff !important;
    }
    .qt-print-page:last-child {
        page-break-after: avoid !important;
        break-after: avoid !important;
    }
    .qt-print-page {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }
    .qt-print-page .pv-bg {
        display: block !important;
        position: absolute !important;
        top: 0 !important;
        left: 0 !important;
        width: 210mm !important;
        height: 296.5mm !important;
        object-fit: fill !important;
        z-index: 0 !important;
        pointer-events: none !important;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }
    .qt-print-page .pv-content {
        position: relative !important;
        z-index: 1 !important;
        width: 100% !important;
        box-sizing: border-box !important;
    }
    .qt-print-page[data-bg=mpl] .pv-content {
        padding: 48mm 12mm 32mm !important;
    }
    .qt-print-page[data-bg=trading] .pv-content {
        padding: 48mm 12mm 28mm !important;
    }
    .qt-print-page[data-bg=ub] .pv-content {
        padding: 34mm 12mm 54mm !important;
    }
    .qt-print-page:not([data-bg]) .pv-content, .qt-print-page[data-bg=""] .pv-content {
        padding: 48mm 12mm 28mm !important;
    }

    /* المحتوى يمشي بعرض الصفحة المتاح بدل عرض ثابت 210mm، عشان الطابعات اللي ليها هوامش ما تقصش الجزء الشمال (RTL) */
    #main-content { position: static !important; display: block !important; width: auto !important; height: auto !important; padding: 0 !important; margin: 0 !important; background: transparent !important; overflow: visible !important; }
    #main-content > div, #quotation-section > div { max-width: none !important; height: auto !important; margin: 0 !important; }

    #invoice-detail-section:not(.hidden-section) {
        display: block !important;
        position: relative !important;
        width: auto !important;
        margin: 0 !important;
        padding: 48mm 12mm 28mm !important;
        background: transparent !important;
        border: none !important;
        box-shadow: none !important;
        z-index: 1 !important;
        /* الـ padding يتكرر في كل صفحة مش في أول صفحة بس، عشان الجدول ما يركبش على الترويسة في الصفحة التانية */
        -webkit-box-decoration-break: clone;
        box-decoration-break: clone;
    }
    .excel-table tr, #invoice-detail-section tr { break-inside: avoid; }

    /* نزول المحتوى تحت الترويسة وفوق الفوتر حسب الخلفية المختارة للفاتورة */
    #invoice-detail-section:has(.active-print-bg[data-bg="mpl"]),
    body:has(#invoice-bg-container.active-print-bg[data-bg="mpl"]) #invoice-detail-section { padding-top: 48mm !important; padding-bottom: 32mm !important; }
    #invoice-detail-section:has(.active-print-bg[data-bg="trading"]),
    #invoice-detail-section:has(.active-print-bg[data-bg="ub"]),
    body:has(#invoice-bg-container.active-print-bg[data-bg="trading"]) #invoice-detail-section,
    body:has(#invoice-bg-container.active-print-bg[data-bg="ub"]) #invoice-detail-section { padding-top: 48mm !important; padding-bottom: 28mm !important; }
    body:not(:has(#invoice-bg-container.active-print-bg)) #invoice-detail-section { padding-top: 20mm !important; padding-bottom: 20mm !important; }

    #invoice-bg-container.active-print-bg {
        display: block !important;
        position: fixed !important;
        top: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        left: 0 !important;
        width: 100vw !important;
        height: 100vh !important;
        z-index: 0 !important;
        pointer-events: none !important;
    }
    #invoice-bg-container.active-print-bg img {
        display: block !important;
        width: 100% !important;
        height: 100% !important;
        object-fit: fill !important;
    }
    #invoice-printable-card {
        position: relative !important;
        z-index: 1 !important;
        overflow: visible !important;
        max-width: 100% !important;
        width: 100% !important;
        box-shadow: none !important;
        border: none !important;
        background: transparent !important;
        padding: 0 !important;
        margin: 0 !important;
    }

    /* خلفيات شفافة بالكامل حتى تظهر العلامة المائية في منتصف الورقة تحت الجداول بوضوح */
    #quotation-print-area, #invoice-detail-section > .bg-white, #invoice-detail-section table, #invoice-detail-section td, #invoice-detail-section tbody tr {
        background-color: transparent !important;
    }
    #invoice-detail-section table thead tr {
        background-color: rgba(229, 231, 235, 0.7) !important;
        color: #111827 !important;
    }
    #invoice-detail-section table th {
        color: #111827 !important;
    }
    .excel-table, .excel-table td { background-color: transparent !important; }
    .excel-table th, .excel-table td.bg-gray-50, .excel-table td.bg-gray-100, .excel-table td.bg-gray-200 { background-color: rgba(229, 231, 235, 0.55) !important; }
    #invoice-detail-section .bg-gray-50, #invoice-detail-section .bg-gray-100, #invoice-detail-section .bg-blue-50 { background-color: rgba(243, 244, 246, 0.45) !important; }

    /* منع قص الجداول من الجهة اليسرى في طباعة A4 */
    [class*="min-w-"], .min-w-\[500px\], .min-w-\[600px\], .min-w-\[700px\] {
        min-width: 0 !important;
    }
    table {
        width: 100% !important;
        max-width: 100% !important;
        table-layout: auto !important;
    }
    #invoice-detail-section:not(.hidden-section) {
        padding-left: 8mm !important;
        padding-right: 8mm !important;
    }

    /* إخفاء أسهم الأرقام وأيقونة التقويم حتى لا تقص القيم */
    input[type=number]::-webkit-inner-spin-button, input[type=number]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
    input[type=number] { -moz-appearance: textfield; }
    input[type=date]::-webkit-calendar-picker-indicator { display: none; }
}
.toast-enter { animation: toastEnter 0.3s ease-out forwards; }
.toast-exit { animation: toastExit 0.3s ease-in forwards; }
@keyframes toastEnter { from { transform: translateY(100%); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
@keyframes toastExit { from { transform: translateY(0); opacity: 1; } to { transform: translateY(100%); opacity: 0; } }

/* Contenteditable placeholder styling */
.q-desc[contenteditable]:empty:before {
    content: attr(data-placeholder);
    color: #9ca3af;
    font-weight: normal;
    pointer-events: none;
    display: block;
}
