/* استيراد خط كايرو للهوية العربية */
@import url('https://fonts.googleapis.com/css2?family=Cairo:wght@400;700&display=swap');

@page {
    size: A4;
    margin: 0;
}

body {
    background: #f0f2f5;
    margin: 0;
    padding: 0;
    font-family: 'Cairo', sans-serif; /* الخط الجديد */
    direction: rtl;
}

/* حاوية الصفحة A4 */
.a4-page {
    width: 210mm;
    height: 297mm;
    margin: 20px auto;
    background: white;
    position: relative;
    box-shadow: 0 10px 30px rgba(0,0,0,0.15);
    overflow: hidden;
    box-sizing: border-box;
}

/* الخلفية (Letterhead) */
.letterhead-bg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image: url('HeadـLetter.jpg');
    background-size: 100% 100%;
    z-index: 1;
}

/* منطقة المحتوى - تعديل المسافة العلوية لتكون احترافية */
.invoice-content {
    position: relative;
    z-index: 2;
    padding-top: 45mm; /* تم تصغيرها لتبدأ بعد الشعار مباشرة */
    padding-bottom: 35mm; /* هامش قبل الفوتر السفلي */
    padding-left: 15mm;
    padding-right: 15mm;
    display: flex;
    flex-direction: column;
    height: 100%;
    box-sizing: border-box;
}

/* تفاصيل الفاتورة (الرقم والتاريخ) */
.invoice-meta {
    display: flex;
    justify-content: space-between;
    margin-bottom: 20px;
    border-bottom: 2px solid #1a2a3a;
    padding-bottom: 10px;
}

.invoice-meta div span {
    font-weight: bold;
    color: #1a2a3a;
}

/* تنسيق الجدول */
/* تنسيق الجدول الاحترافي لبرزة */
table {
    width: 100%;
    border-collapse: separate; /* لتفعيل حواف الزوايا المنحنية */
    border-spacing: 0;
    margin-top: 30px;
    border: 1px solid #e1e8ed;
    border-radius: 8px;
    overflow: hidden; /* لضمان ظهور الزوايا المنحنية */
}

thead {
    background-color: #1a2a3a; /* لون برزة الكحلي */
    color: #ffffff;
}

th {
    padding: 15px 10px;
    font-weight: 700;
    font-size: 14px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-left: 1px solid rgba(255, 255, 255, 0.1); /* فواصل أعمدة شفافة في الهيدر */
}

th:last-child {
    border-left: none;
}

td {
    padding: 12px 15px;
    color: #444;
    font-size: 14px;
    border-bottom: 1px solid #e1e8ed;
    border-left: 1px solid #e1e8ed; /* فواصل الأعمدة */
    background-color: rgba(255, 255, 255, 0.5); /* شفافية بسيطة لإظهار اللترهيد خلفه */
}

/* إلغاء الفاصل العمودي الأخير جهة اليمين (لأننا في RTL) */
td:last-child {
    border-left: none;
}

/* تمييز الصفوف الفردية بلون خفيف جداً */
tbody tr:nth-child(even) {
    background-color: rgba(248, 249, 250, 0.5);
}

/* إزالة حدود الصف الأخير */
tbody tr:last-child td {
    border-bottom: none;
}

/* تحسين شكل خانة الإجمالي */
.totals {
    margin-top: 30px;
    display: flex;
    justify-content: flex-start; /* ليكون جهة اليمين في RTL */
}

.total-box {
    background: linear-gradient(135deg, #1a2a3a 0%, #2c3e50 100%);
    color: white;
    padding: 15px 40px;
    border-radius: 50px 0 50px 50px; /* شكل هندسي مميز */
    box-shadow: 0 4px 15px rgba(26, 42, 58, 0.2);
    font-size: 18px;
    border: 2px solid #f39c12; /* خط ذهبي نحيف يعطي لمسة فخامة */
}

#grandTotal {
    font-weight: 700;
    font-size: 22px;
    margin-right: 10px;
}

/* لوحة التحكم (تختفي عند الطباعة) */
.admin-panel {
    background: #1a2a3a;
    color: white;
    padding: 15px;
    text-align: center;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 2px 10px rgba(0,0,0,0.3);
}

.admin-panel input {
    padding: 8px;
    margin: 5px;
    border-radius: 4px;
    border: 1px solid #ccc;
    font-family: 'Cairo';
}

.btn {
    padding: 8px 20px;
    border-radius: 4px;
    border: none;
    cursor: pointer;
    font-family: 'Cairo';
    font-weight: bold;
    transition: 0.3s;
}

.add-btn { background: #34495e; color: white; margin-left: 10px; }
.print-btn { background: #27ae60; color: white; }
.btn:hover { opacity: 0.8; }

@media print {
    .no-print { display: none !important; }
    .a4-page { margin: 0; box-shadow: none; }
    body { background: none; }
}

/* تحسينات للهاتف */
@media screen and (max-width: 768px) {
    .a4-page {
        width: 100%; /* جعل العرض كامل الشاشة */
        height: auto; /* السماح للطول بالتمدد حسب المحتوى */
        min-height: 100vh;
        margin: 0;
        transform: scale(1); /* إلغاء أي تصغير */
        overflow-x: hidden;
    }

    .invoice-content {
        padding: 20mm 10px 10px 10px; /* تقليل المسافات الجانبية */
    }

    table {
        font-size: 12px; /* تصغير الخط قليلاً ليناسب العرض */
    }

    .total-box {
        padding: 10px 20px;
        font-size: 16px;
    }
    
    .admin-panel input {
        width: 90%; /* جعل مدخلات التحكم مناسبة للمس باليد */
    }
    
    .row-input {
        flex-direction: column; /* ترتيب المدخلات فوق بعضها في الهاتف */
        align-items: center;
    }
}