/* ============================================
   تحسين ألوان الـ Badges والتباين
   Badge Colors & Contrast Enhancement
   ============================================ */

/* ===== Badges الأساسية ===== */
.badge {
    font-weight: 500 !important;
    letter-spacing: 0.3px;
}

/* Badge أخضر - للنجاح وأوامر الشراء */
.badge.bg-success,
a.badge.bg-success {
    background-color: #198754 !important;
    color: #ffffff !important;
}
.badge.bg-success i,
a.badge.bg-success i {
    color: #ffffff !important;
}
.badge.bg-success:hover,
a.badge.bg-success:hover {
    background-color: #157347 !important;
    color: #ffffff !important;
}

/* Badge أزرق - للمعلومات والفواتير */
.badge.bg-info,
a.badge.bg-info {
    background-color: #0dcaf0 !important;
    color: #000000 !important;
}
.badge.bg-info i,
a.badge.bg-info i {
    color: #000000 !important;
}
.badge.bg-info:hover,
a.badge.bg-info:hover {
    background-color: #31d2f2 !important;
}

/* Badge أصفر/برتقالي - للتحذيرات والمردودات */
.badge.bg-warning,
a.badge.bg-warning {
    background-color: #ffc107 !important;
    color: #000000 !important;
}
.badge.bg-warning i,
a.badge.bg-warning i {
    color: #000000 !important;
}
.badge.bg-warning:hover,
a.badge.bg-warning:hover {
    background-color: #ffca2c !important;
}

/* Badge أحمر - للخطأ والرفض */
.badge.bg-danger,
a.badge.bg-danger {
    background-color: #dc3545 !important;
    color: #ffffff !important;
}
.badge.bg-danger i,
a.badge.bg-danger i {
    color: #ffffff !important;
}
.badge.bg-danger:hover,
a.badge.bg-danger:hover {
    background-color: #bb2d3b !important;
}

/* Badge رمادي - للمسودات والسندات */
.badge.bg-secondary,
a.badge.bg-secondary {
    background-color: #6c757d !important;
    color: #ffffff !important;
}
.badge.bg-secondary i,
a.badge.bg-secondary i {
    color: #ffffff !important;
}
.badge.bg-secondary:hover,
a.badge.bg-secondary:hover {
    background-color: #5c636a !important;
}

/* Badge أزرق داكن - للأساسي */
.badge.bg-primary,
a.badge.bg-primary {
    background-color: #0d6efd !important;
    color: #ffffff !important;
}
.badge.bg-primary i,
a.badge.bg-primary i {
    color: #ffffff !important;
}
.badge.bg-primary:hover,
a.badge.bg-primary:hover {
    background-color: #0b5ed7 !important;
}

/* Badge أسود/داكن - للمحول والمكتمل */
.badge.bg-dark,
a.badge.bg-dark {
    background-color: #212529 !important;
    color: #ffffff !important;
}
.badge.bg-dark i,
a.badge.bg-dark i {
    color: #ffffff !important;
}
.badge.bg-dark:hover,
a.badge.bg-dark:hover {
    background-color: #1a1e21 !important;
}

/* Badge فاتح */
.badge.bg-light,
a.badge.bg-light {
    background-color: #f8f9fa !important;
    color: #212529 !important;
    border: 1px solid #dee2e6;
}
.badge.bg-light i,
a.badge.bg-light i {
    color: #212529 !important;
}

/* ===== تحسينات إضافية للروابط ===== */
a.badge {
    text-decoration: none !important;
    transition: all 0.2s ease;
}
a.badge:hover {
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

/* ===== حالات الجداول ===== */
.table .badge {
    font-size: 0.75rem !important;
    padding: 0.35rem 0.6rem !important;
    border-radius: 0.375rem;
}

/* ===== Status Badges المحسنة - استثناء الجداول ===== */
/* ===== Status Badges المحسنة - لا تطبق على جداول bill-table ===== */

/* ===== ألوان الحالات المخصصة ===== */
/* مسودة */
.badge-status-draft {
    background-color: var(--theme-status-draft-bg, #6c757d) !important;
    color: var(--theme-status-draft-text, #ffffff) !important;
}

/* مقدم */
.badge-status-submitted {
    background-color: var(--theme-status-info-bg, #17a2b8) !important;
    color: var(--theme-status-info-text, #ffffff) !important;
}

/* قيد المراجعة */
.badge-status-under-review {
    background-color: var(--theme-status-warning-bg, #ffc107) !important;
    color: var(--theme-status-warning-text, #000000) !important;
}

/* مقبول/معتمد */
.badge-status-approved,
.badge-status-accepted {
    background-color: var(--theme-status-approved-bg, #28a745) !important;
    color: var(--theme-status-approved-text, #ffffff) !important;
}

/* مرفوض */
.badge-status-rejected {
    background-color: var(--theme-status-rejected-bg, #dc3545) !important;
    color: var(--theme-status-rejected-text, #ffffff) !important;
}

/* منتهي */
.badge-status-expired {
    background-color: var(--theme-status-expired-bg, #343a40) !important;
    color: var(--theme-status-expired-text, #ffffff) !important;
}

/* تم الترسية */
.badge-status-awarded {
    background-color: var(--theme-status-primary-bg, #007bff) !important;
    color: var(--theme-status-primary-text, #ffffff) !important;
}

/* محول لأمر شراء */
.badge-status-converted {
    background-color: var(--theme-status-closed-bg, #212529) !important;
    color: var(--theme-status-closed-text, #ffffff) !important;
}

/* مفتوح */
.badge-status-open {
    background-color: var(--theme-status-open-bg, #17a2b8) !important;
    color: var(--theme-status-open-text, #ffffff) !important;
}

/* مكتمل */
.badge-status-completed,
.badge-status-closed {
    background-color: var(--theme-status-success-bg, #198754) !important;
    color: var(--theme-status-success-text, #ffffff) !important;
}

/* ملغي */
.badge-status-cancelled {
    background-color: var(--theme-status-cancelled-bg, #6c757d) !important;
    color: var(--theme-status-cancelled-text, #ffffff) !important;
}

/* مرحّل */
.badge-status-posted {
    background-color: var(--theme-status-posted-bg, #0d6efd) !important;
    color: var(--theme-status-posted-text, #ffffff) !important;
}

/* ===== أنواع سندات الدفع والقبض ===== */
/* سند قبض - Receipt */
.badge-type-receipt {
    background-color: var(--theme-badge-type-receipt-bg, #198754) !important;
    color: var(--theme-badge-type-receipt-text, #ffffff) !important;
}
.badge-type-receipt:hover {
    background-color: var(--theme-badge-type-receipt-bg, #157347) !important;
    filter: brightness(0.9);
}

/* سند دفع - Payment */
.badge-type-payment {
    background-color: var(--theme-badge-type-payment-bg, #dc3545) !important;
    color: var(--theme-badge-type-payment-text, #ffffff) !important;
}
.badge-type-payment:hover {
    background-color: var(--theme-badge-type-payment-bg, #bb2d3b) !important;
    filter: brightness(0.9);
}

/* حالات سندات الدفع */
.badge-status-pending,
.status-unpaid:not(.status-badge) {
    background-color: var(--theme-status-secondary-bg, #6c757d) !important;
    color: var(--theme-status-secondary-text, #ffffff) !important;
}

.badge-status-cleared,
.status-fully_paid:not(.status-badge) {
    background-color: var(--theme-status-paid-bg, #198754) !important;
    color: var(--theme-status-paid-text, #ffffff) !important;
}

.status-partially_paid:not(.status-badge) {
    background-color: var(--theme-status-partial-bg, #ffc107) !important;
    color: var(--theme-status-partial-text, #000000) !important;
}

.status-cancelled:not(.status-badge) {
    background-color: #dc3545 !important;
    color: #ffffff !important;
}

/* ===== تحسين Select الحالة ===== */
.status-select {
    font-weight: 500 !important;
    border-radius: 0.375rem !important;
}

select.status-select[data-current="draft"] { 
    background-color: #6c757d !important; 
    color: #fff !important; 
    border-color: #6c757d !important;
}
select.status-select[data-current="submitted"] { 
    background-color: #17a2b8 !important; 
    color: #fff !important; 
    border-color: #17a2b8 !important;
}
select.status-select[data-current="under_review"] { 
    background-color: #ffc107 !important; 
    color: #000 !important; 
    border-color: #ffc107 !important;
}
select.status-select[data-current="accepted"] { 
    background-color: #28a745 !important; 
    color: #fff !important; 
    border-color: #28a745 !important;
}
select.status-select[data-current="approved"] { 
    background-color: #28a745 !important; 
    color: #fff !important; 
    border-color: #28a745 !important;
}
select.status-select[data-current="rejected"] { 
    background-color: #dc3545 !important; 
    color: #fff !important; 
    border-color: #dc3545 !important;
}
select.status-select[data-current="expired"] { 
    background-color: #343a40 !important; 
    color: #fff !important; 
    border-color: #343a40 !important;
}
select.status-select[data-current="awarded"] { 
    background-color: #007bff !important; 
    color: #fff !important; 
    border-color: #007bff !important;
}
select.status-select[data-current="converted_to_po"] { 
    background-color: #212529 !important; 
    color: #fff !important; 
    border-color: #212529 !important;
}
select.status-select[data-current="open"] { 
    background-color: #17a2b8 !important; 
    color: #fff !important; 
    border-color: #17a2b8 !important;
}
select.status-select[data-current="closed"],
select.status-select[data-current="completed"] { 
    background-color: #198754 !important; 
    color: #fff !important; 
    border-color: #198754 !important;
}
select.status-select[data-current="cancelled"] { 
    background-color: #6c757d !important; 
    color: #fff !important; 
    border-color: #6c757d !important;
}
select.status-select[data-current="posted"] { 
    background-color: #0d6efd !important; 
    color: #fff !important; 
    border-color: #0d6efd !important;
}

/* ===== تحسين الأيقونات داخل الأزرار ===== */
.btn i,
.badge i {
    vertical-align: middle;
}

/* ===== تحسين التباين في الجداول ===== */
.table-light th {
    background-color: #e9ecef !important;
    color: #212529 !important;
    font-weight: 600;
}

.table-dark th {
    background-color: #212529 !important;
    color: #ffffff !important;
}

/* ===== تحسين رؤوس البطاقات ===== */
.card-header.bg-primary {
    background-color: #0d6efd !important;
    color: #ffffff !important;
}
.card-header.bg-success {
    background-color: #198754 !important;
    color: #ffffff !important;
}
.card-header.bg-info {
    background-color: #0dcaf0 !important;
    color: #000000 !important;
}
.card-header.bg-warning {
    background-color: #ffc107 !important;
    color: #000000 !important;
}
.card-header.bg-danger {
    background-color: #dc3545 !important;
    color: #ffffff !important;
}
.card-header.bg-secondary {
    background-color: #6c757d !important;
    color: #ffffff !important;
}
.card-header.bg-dark {
    background-color: #212529 !important;
    color: #ffffff !important;
}

/* ===== تحسين التنبيهات ===== */
.alert-success {
    background-color: #d1e7dd !important;
    border-color: #badbcc !important;
    color: #0f5132 !important;
}
.alert-danger {
    background-color: #f8d7da !important;
    border-color: #f5c2c7 !important;
    color: #842029 !important;
}
.alert-warning {
    background-color: #fff3cd !important;
    border-color: #ffecb5 !important;
    color: #664d03 !important;
}
.alert-info {
    background-color: #cff4fc !important;
    border-color: #b6effb !important;
    color: #055160 !important;
}


/* ===== حالات سندات التسليم الجديدة ===== */
/* مسودة - Draft */
.badge-status-draft,
.status-draft:not(.status-badge) {
    background-color: var(--theme-status-draft-bg, #6c757d) !important;
    color: var(--theme-status-draft-text, #ffffff) !important;
}

/* في الانتظار - Waiting */
.badge-status-waiting,
.status-warning:not(.status-badge) {
    background-color: var(--theme-status-warning-bg, #ffc107) !important;
    color: var(--theme-status-warning-text, #000000) !important;
}

/* قيد التجهيز - Preparing */
.badge-status-preparing,
.status-info:not(.status-badge) {
    background-color: var(--theme-status-info-bg, #17a2b8) !important;
    color: var(--theme-status-info-text, #ffffff) !important;
}

/* جاهز للتسليم - Ready to Deliver */
.badge-status-ready-to-deliver,
.status-ready-to-deliver:not(.status-badge) {
    background-color: var(--theme-status-primary-bg, #0d6efd) !important;
    color: var(--theme-status-primary-text, #ffffff) !important;
}

/* تسليم جزئي - Partially Delivered */
.badge-status-partially-delivered,
.status-partially-delivered:not(.status-badge) {
    background-color: var(--theme-status-partially-delivered-bg, #fd7e14) !important;
    color: var(--theme-status-partially-delivered-text, #ffffff) !important;
}

/* تسليم كامل - Fully Delivered */
.badge-status-fully-delivered,
.status-fully-delivered:not(.status-badge) {
    background-color: var(--theme-status-fully-delivered-bg, #198754) !important;
    color: var(--theme-status-fully-delivered-text, #ffffff) !important;
}

/* مفتوح - Open */
.status-open:not(.status-badge) {
    background-color: var(--theme-status-open-bg, #17a2b8) !important;
    color: var(--theme-status-open-text, #ffffff) !important;
}

/* مؤكد - Confirmed */
.status-confirmed:not(.status-badge) {
    background-color: var(--theme-status-confirmed-bg, #0d6efd) !important;
    color: var(--theme-status-confirmed-text, #ffffff) !important;
}

/* مغلق - Closed */
.status-closed:not(.status-badge) {
    background-color: var(--theme-status-closed-bg, #212529) !important;
    color: var(--theme-status-closed-text, #ffffff) !important;
}

/* تم الشحن - Shipped */
.status-shipped:not(.status-badge),
.status-ready-to-deliver:not(.status-badge) {
    background-color: var(--theme-status-shipped-bg, #0d6efd) !important;
    color: var(--theme-status-shipped-text, #ffffff) !important;
}

/* ملغي - Cancelled */
.status-cancelled:not(.status-badge) {
    background-color: var(--theme-status-cancelled-bg, #dc3545) !important;
    color: var(--theme-status-cancelled-text, #ffffff) !important;
}

/* قيد المعالجة - Processing */
.status-processing:not(.status-badge) {
    background-color: var(--theme-status-processing-bg, #6610f2) !important;
    color: var(--theme-status-processing-text, #ffffff) !important;
}

/* مفوتر جزئياً - Partially Invoiced */
.status-partially-invoiced:not(.status-badge) {
    background-color: var(--theme-status-partial-bg, #e83e8c) !important;
    color: var(--theme-status-partial-text, #ffffff) !important;
}

/* مفوتر بالكامل - Fully Invoiced */
.status-fully-invoiced:not(.status-badge) {
    background-color: var(--theme-status-success-bg, #20c997) !important;
    color: var(--theme-status-success-text, #ffffff) !important;
}

/* ثانوي */
.status-secondary:not(.status-badge) {
    background-color: var(--theme-status-secondary-bg, #6c757d) !important;
    color: var(--theme-status-secondary-text, #ffffff) !important;
}

/* مقبول من العميل - Approved by Customer (Quote) */
.status-approved-customer:not(.status-badge) {
    background-color: var(--theme-status-info-bg, #17a2b8) !important;
    color: var(--theme-status-info-text, #ffffff) !important;
}

/* مرفوض من العميل - Declined by Customer (Quote) */
.status-declined:not(.status-badge),
.status-dark:not(.status-badge) {
    background-color: var(--theme-status-closed-bg, #343a40) !important;
    color: var(--theme-status-closed-text, #ffffff) !important;
}

/* Select للحالات */
select.status-select[data-current="open"] {
    background-color: #17a2b8 !important;
    color: #fff !important;
    border-color: #17a2b8 !important;
}
select.status-select[data-current="draft"] {
    background-color: #6c757d !important;
    color: #fff !important;
    border-color: #6c757d !important;
}
select.status-select[data-current="ready_to_deliver"] {
    background-color: #0d6efd !important;
    color: #fff !important;
    border-color: #0d6efd !important;
}
select.status-select[data-current="confirmed"] {
    background-color: #0d6efd !important;
    color: #fff !important;
    border-color: #0d6efd !important;
}
select.status-select[data-current="partially_delivered"] { 
    background-color: #fd7e14 !important; 
    color: #fff !important; 
    border-color: #fd7e14 !important;
}
select.status-select[data-current="fully_delivered"] { 
    background-color: #198754 !important; 
    color: #fff !important; 
    border-color: #198754 !important;
}
select.status-select[data-current="closed"] {
    background-color: #6c757d !important;
    color: #fff !important;
    border-color: #6c757d !important;
}
select.status-select[data-current="cancelled"] {
    background-color: #dc3545 !important;
    color: #fff !important;
    border-color: #dc3545 !important;
}

/* ===== حالات فاتورة المبيعات ===== */
/* مرحّلة - Posted */
.status-posted:not(.status-badge) {
    background-color: var(--theme-status-posted-bg, #0d6efd) !important;
    color: var(--theme-status-posted-text, #ffffff) !important;
}

/* مدفوعة جزئياً - Partially Paid */
.status-partially-paid:not(.status-badge) {
    background-color: var(--theme-status-partial-bg, #ffc107) !important;
    color: var(--theme-status-partial-text, #000000) !important;
}

/* مدفوعة بالكامل - Fully Paid */
.status-fully-paid:not(.status-badge) {
    background-color: var(--theme-status-paid-bg, #198754) !important;
    color: var(--theme-status-paid-text, #ffffff) !important;
}

/* متأخرة السداد - Overdue */
.status-overdue:not(.status-badge) {
    background-color: var(--theme-status-overdue-bg, #dc3545) !important;
    color: var(--theme-status-overdue-text, #ffffff) !important;
    animation: pulse-overdue 2s infinite;
}

@keyframes pulse-overdue {
    0% { opacity: 1; }
    50% { opacity: 0.8; }
    100% { opacity: 1; }
}

/* Select للحالات الجديدة */
select.status-select[data-current="posted"] {
    background-color: #0d6efd !important;
    color: #fff !important;
    border-color: #0d6efd !important;
}
select.status-select[data-current="closed"] {
    background-color: #6c757d !important;
    color: #fff !important;
    border-color: #6c757d !important;
}

/* ===== حالات طلب الشراء - Purchase Requisition Statuses ===== */

/* مقدم - Submitted */
.status-submitted:not(.status-badge) {
    background-color: var(--theme-status-info-bg, #17a2b8) !important;
    color: var(--theme-status-info-text, #ffffff) !important;
}

/* قيد المراجعة - Under Review */
.status-under-review:not(.status-badge) {
    background-color: var(--theme-status-warning-bg, #ffc107) !important;
    color: var(--theme-status-warning-text, #000000) !important;
}

/* بانتظار الاعتماد - Pending */
.status-pending:not(.status-badge) {
    background-color: #fd7e14 !important;
    color: #ffffff !important;
}

/* معتمد - Approved */
.status-approved:not(.status-badge) {
    background-color: #198754 !important;
    color: #ffffff !important;
}

/* مرفوض - Rejected */
.status-rejected:not(.status-badge) {
    background-color: #dc3545 !important;
    color: #ffffff !important;
}

/* محول لأمر شراء - Converted to PO */
.status-converted:not(.status-badge) {
    background-color: #6610f2 !important;
    color: #ffffff !important;
}

/* نجاح - Success */
.status-success:not(.status-badge) {
    background-color: #198754 !important;
    color: #ffffff !important;
}


/* ===== حالات مردودات المبيعات الإضافية ===== */
/* مرتجع جزئياً - Partially Returned */
.badge-status-partially-returned,
.status-partially-returned:not(.status-badge) {
    background-color: #fd7e14 !important;
    color: #ffffff !important;
}

/* مرتجع كلياً - Fully Returned */
.badge-status-fully-returned,
.status-fully-returned:not(.status-badge) {
    background-color: #20c997 !important;
    color: #ffffff !important;
}

/* إشعار دائن صادر - Credit Note Issued */
.badge-status-credit-note-issued,
.status-credit-note-issued:not(.status-badge) {
    background-color: #0d6efd !important;
    color: #ffffff !important;
}

select.status-select[data-current="partially_returned"] {
    background-color: #fd7e14 !important;
    color: #fff !important;
    border-color: #fd7e14 !important;
}
select.status-select[data-current="fully_returned"] {
    background-color: #20c997 !important;
    color: #fff !important;
    border-color: #20c997 !important;
}
select.status-select[data-current="credit_note_issued"] {
    background-color: #0d6efd !important;
    color: #fff !important;
    border-color: #0d6efd !important;
}
