/**
 * تنسيقات إيصال صرف المرتب
 * تصميم نصف صفحة A4 (210mm × 148.5mm)
 */

/* ========== Modal Container ========== */
.receipt-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 9999;
    align-items: center;
    justify-content: center;
    direction: rtl;
}

.receipt-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    z-index: 1;
}

.receipt-container {
    position: relative;
    z-index: 2;
    max-width: 95%;
    max-height: 95vh;
    overflow-y: auto;
    background: white;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    padding: 20px;
}

/* ========== الإيصال الرئيسي ========== */
.salary-receipt {
    width: 210mm;
    min-height: 148.5mm;
    background: white;
    padding: 15mm;
    margin: 0 auto;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    color: #333;
    direction: rtl;
}

/* ========== رأس الإيصال ========== */
.receipt-header {
    background: linear-gradient(135deg, #1976d2 0%, #1565c0 100%);
    padding: 20px;
    margin-bottom: 15px;
    border-radius: 8px;
    color: white;
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.header-title h2 {
    margin: 0;
    font-size: 24px;
    font-weight: bold;
}

.header-info {
    text-align: left;
    font-size: 14px;
}

.header-info div {
    margin: 5px 0;
}

/* ========== بيانات الموظف ========== */
.receipt-employee-info {
    background: #f5f5f5;
    padding: 15px 20px;
    margin-bottom: 15px;
    border-radius: 6px;
    border-right: 4px solid #1976d2;
}

.employee-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 15px;
}

/* ========== المستحقات والخصومات ========== */
.receipt-details {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
    margin-bottom: 15px;
}

/* المستحقات */
.earnings-section {
    background: #e8f5e9;
    padding: 15px;
    border-radius: 8px;
    border-right: 4px solid #4caf50;
}

.earnings-section .section-title {
    color: #2e7d32;
    font-weight: bold;
    margin: 0 0 10px 0;
    text-align: center;
    font-size: 18px;
}

/* الخصومات */
.deductions-section {
    background: #ffebee;
    padding: 15px;
    border-radius: 8px;
    border-right: 4px solid #f44336;
}

.deductions-section .section-title {
    color: #c62828;
    font-weight: bold;
    margin: 0 0 10px 0;
    text-align: center;
    font-size: 18px;
}

/* ========== الجداول ========== */
.receipt-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.receipt-table td {
    padding: 8px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.08);
}

.receipt-table tr:last-child td {
    border-bottom: none;
}

.receipt-table .total-row {
    background: rgba(0, 0, 0, 0.05);
    font-weight: bold;
    font-size: 15px;
}

.text-left {
    text-align: left;
}

/* ========== صافي المرتب ========== */
.net-salary-section {
    background: linear-gradient(135deg, #4caf50 0%, #388e3c 100%);
    padding: 20px;
    margin-bottom: 15px;
    border-radius: 8px;
    text-align: center;
    color: white;
}

.net-salary-section h3 {
    margin: 0 0 10px 0;
    font-size: 20px;
    font-weight: bold;
}

.net-amount {
    font-size: 32px;
    font-weight: bold;
    margin-top: 10px;
}

/* ========== التوقيع ========== */
.signature-section {
    padding: 15px 20px;
    border-top: 2px dashed #ccc;
    margin-top: 10px;
}

.signature-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 14px;
}

/* ========== أزرار التحكم ========== */
.receipt-actions {
    display: flex;
    justify-content: center;
    gap: 15px;
    margin-top: 20px;
    padding-top: 20px;
    border-top: 2px solid #eee;
}

.receipt-actions button {
    padding: 12px 30px;
    font-size: 16px;
    font-weight: bold;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

.btn-print {
    background: linear-gradient(135deg, #2196f3 0%, #1976d2 100%);
    color: white;
}

.btn-print:hover {
    background: linear-gradient(135deg, #1976d2 0%, #1565c0 100%);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(33, 150, 243, 0.4);
}

.btn-pdf {
    background: linear-gradient(135deg, #4caf50 0%, #388e3c 100%);
    color: white;
}

.btn-pdf:hover {
    background: linear-gradient(135deg, #388e3c 0%, #2e7d32 100%);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(76, 175, 80, 0.4);
}

.btn-close {
    background: linear-gradient(135deg, #757575 0%, #616161 100%);
    color: white;
}

.btn-close:hover {
    background: linear-gradient(135deg, #616161 0%, #424242 100%);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(117, 117, 117, 0.4);
}

/* ========== تنسيقات الطباعة ========== */
@media print {
    /* إخفاء جميع العناصر غير الضرورية */
    body > *:not(.receipt-modal) {
        display: none !important;
    }

    /* إخفاء الأزرار والـ Overlay */
    .receipt-actions,
    .receipt-overlay {
        display: none !important;
    }

    /* إظهار Modal والـ Container والإيصال */
    .receipt-modal {
        display: block !important;
        position: static !important;
        width: 100% !important;
        height: 100% !important;
        background: white !important;
    }

    .receipt-container {
        position: static !important;
        max-width: 100% !important;
        max-height: 100% !important;
        overflow: visible !important;
        background: white !important;
        border-radius: 0 !important;
        box-shadow: none !important;
        padding: 0 !important;
        margin: 0 !important;
    }

    .salary-receipt {
        position: static !important;
        width: 100% !important;
        height: auto !important;
        padding: 10mm !important;
        box-shadow: none !important;
        margin: 0 !important;
    }

    /* ضبط الصفحة */
    @page {
        size: A4 landscape;
        margin: 0;
    }

    /* الحفاظ على الألوان */
    .receipt-header,
    .net-salary-section,
    .earnings-section,
    .deductions-section {
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
        color-adjust: exact;
    }

    /* تحسين الخطوط */
    .salary-receipt {
        font-size: 12pt;
    }

    .header-title h2 {
        font-size: 20pt;
    }

    .net-amount {
        font-size: 28pt;
    }
}

/* ========== Responsive للشاشات الصغيرة ========== */
@media screen and (max-width: 768px) {
    .salary-receipt {
        width: 100%;
        min-height: auto;
        padding: 10px;
    }

    .receipt-details {
        grid-template-columns: 1fr;
    }

    .header-content {
        flex-direction: column;
        text-align: center;
    }

    .header-info {
        text-align: center;
        margin-top: 10px;
    }

    .employee-row,
    .signature-row {
        flex-direction: column;
        gap: 10px;
    }

    .receipt-actions {
        flex-direction: column;
    }

    .receipt-actions button {
        width: 100%;
    }
}

/* ========== Responsive للهواتف المحمولة - عرض كامل بدون Scroll ========== */
@media screen and (max-width: 599px) {
    /* الـ Container الرئيسي */
    .receipt-container {
        max-height: 100vh;
        padding: 10px;
        overflow-y: auto;
    }

    /* الإيصال الرئيسي */
    .salary-receipt {
        width: 100%;
        min-height: auto;
        padding: 8px;
    }

    /* رأس الإيصال */
    .receipt-header {
        padding: 10px;
        margin-bottom: 8px;
        border-radius: 4px;
    }

    .header-title h2 {
        font-size: 16px;
        margin: 0;
    }

    .header-info {
        font-size: 10px;
        text-align: center;
        margin-top: 5px;
    }

    .header-info div {
        margin: 2px 0;
    }

    .header-content {
        flex-direction: column;
        text-align: center;
    }

    /* بيانات الموظف */
    .receipt-employee-info {
        padding: 8px 10px;
        margin-bottom: 8px;
        border-radius: 4px;
    }

    .employee-row {
        font-size: 11px;
        flex-direction: column;
        gap: 5px;
        align-items: flex-start;
    }

    /* المستحقات والخصومات */
    .receipt-details {
        grid-template-columns: 1fr;
        gap: 8px;
        margin-bottom: 8px;
    }

    .earnings-section,
    .deductions-section {
        padding: 8px;
        border-radius: 4px;
    }

    .earnings-section .section-title,
    .deductions-section .section-title {
        font-size: 13px;
        margin: 0 0 5px 0;
    }

    /* الجداول */
    .receipt-table {
        font-size: 10px;
    }

    .receipt-table td {
        padding: 4px;
    }

    .receipt-table .total-row {
        font-size: 11px;
    }

    /* صافي المرتب */
    .net-salary-section {
        padding: 10px;
        margin-bottom: 8px;
        border-radius: 4px;
    }

    .net-salary-section h3 {
        font-size: 14px;
        margin: 0 0 5px 0;
    }

    .net-amount {
        font-size: 20px;
        margin-top: 5px;
    }

    /* التوقيع */
    .signature-section {
        padding: 8px 10px;
        margin-top: 5px;
    }

    .signature-row {
        font-size: 10px;
        flex-direction: column;
        gap: 5px;
        align-items: flex-start;
    }

    /* الأزرار */
    .receipt-actions {
        gap: 8px;
        margin-top: 10px;
        padding-top: 10px;
        flex-direction: column;
    }

    .receipt-actions button {
        padding: 8px 15px;
        font-size: 12px;
        width: 100%;
    }
}

/* ========== Page Breaks للطباعة الجماعية ========== */

/**
 * تنسيقات خاصة بطباعة إيصالات متعددة
 * يضمن أن كل إيصال يطبع في صفحة منفصلة
 */

.receipt-page {
    position: relative;
    margin-bottom: 20px;
}

/* فاصل صفحات للطباعة */
.page-break-after {
    page-break-after: always;
    break-after: page;
}

/* تنسيقات الطباعة للإيصالات المتعددة */
@media print {
    /* إزالة الهوامش من الصفحة */
    @page {
        margin: 10mm;
        size: A4 portrait;
    }

    body {
        margin: 0;
        padding: 0;
    }

    /* كل إيصال في صفحة منفصلة */
    .receipt-page {
        page-break-after: always;
        break-after: page;
        margin: 0;
        padding: 0;
    }

    /* آخر إيصال لا يحتاج page break */
    .receipt-page:last-child {
        page-break-after: auto;
        break-after: auto;
    }

    /* التأكد من عدم تقسيم الإيصال */
    .salary-receipt {
        page-break-inside: avoid;
        break-inside: avoid;
    }

    /* إخفاء أي عناصر غير ضرورية */
    .receipt-modal,
    .receipt-overlay,
    .receipt-actions {
        display: none !important;
    }
}

