/**
 * مقارنة الملفات - Compare Clients
 * تصميم نافذة المقارنة الثورية بين الملفات
 */

/* ===================================
   شريط التحديد والمقارنة
   =================================== */
.compare-toolbar {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%) translateY(100%);
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  padding: 16px 24px;
  border-radius: 16px 16px 0 0;
  box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.15);
  display: flex;
  align-items: center;
  gap: 20px;
  z-index: 9998;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  min-width: 400px;
  max-width: 600px;
}

.compare-toolbar.show {
  transform: translateX(-50%) translateY(0);
}

.compare-selection-info {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
}

.compare-selection-info i {
  font-size: 24px;
  opacity: 0.9;
}

.compare-selection-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.compare-selection-count {
  font-size: 18px;
  font-weight: 700;
}

.compare-selection-label {
  font-size: 13px;
  opacity: 0.85;
}

.compare-actions {
  display: flex;
  gap: 12px;
}

.btn-compare,
.btn-clear-selection {
  padding: 12px 24px;
  border: none;
  border-radius: 12px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-compare {
  background: white;
  color: #667eea;
}

.btn-compare:hover {
  background: #f8f9ff;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.btn-compare:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.btn-clear-selection {
  background: rgba(255, 255, 255, 0.2);
  color: white;
  border: 1px solid rgba(255, 255, 255, 0.3);
}

.btn-clear-selection:hover {
  background: rgba(255, 255, 255, 0.3);
}

/* ===================================
   Checkbox للتحديد في الجدول (داخل أول خلية)
   =================================== */

/* تنسيق عمود التحديد */
.select-column {
  text-align: center !important;
  vertical-align: middle !important;
  width: 50px !important;
  min-width: 50px !important;
  max-width: 50px !important;
  padding: 8px !important;
  overflow: hidden !important;
  font-size: 0 !important;
  line-height: 0 !important;
  white-space: nowrap !important;
}

/* إخفاء كل المحتوى النصي في عمود التحديد */
.select-column::before,
.select-column::after,
.select-column *::before,
.select-column *::after {
  content: none !important;
  display: none !important;
}

.select-column > *:not(input[type="checkbox"]) {
  display: none !important;
  visibility: hidden !important;
}

.select-column input[type="checkbox"] {
  display: inline-block !important;
  margin: 0 auto !important;
  padding: 0 !important;
  font-size: initial !important;
}

/* إخفاء أي نص داخل الخلية */
.select-column span,
.select-column div,
.select-column p,
.select-column a,
.select-column label {
  display: none !important;
  visibility: hidden !important;
  font-size: 0 !important;
}

.select-column-header {
  width: 50px !important;
  min-width: 50px !important;
  max-width: 50px !important;
  text-align: center !important;
  padding: 8px !important;
  overflow: hidden !important;
  font-size: 0 !important;
}

.select-column-header > *:not(input[type="checkbox"]) {
  display: none !important;
}

/* Checkbox في الهيدر - تحديد الكل - حجم أكبر */
#select-all-clients {
  width: 20px !important;
  height: 20px !important;
  cursor: pointer !important;
  accent-color: #667eea !important;
  margin: 0 auto !important;
  display: inline-block !important;
  transform: scale(1.3) !important;
}

/* Checkbox في الصفوف - حجم أكبر */
.client-select-checkbox {
  width: 20px !important;
  height: 20px !important;
  cursor: pointer !important;
  accent-color: #667eea !important;
  margin: 0 auto !important;
  display: inline-block !important;
  transform: scale(1.3) !important;
}

/* تمييز الصف المحدد */
tr.selected-for-compare {
  background-color: rgba(102, 126, 234, 0.08) !important;
}

tr.selected-for-compare td {
  border-color: rgba(102, 126, 234, 0.25) !important;
}

/* ===================================
   نافذة المقارنة المنبثقة
   =================================== */
.compare-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  animation: fadeIn 0.3s ease;
  padding: 20px;
}

.compare-modal.show {
  display: flex;
}

.compare-modal-backdrop {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
}

.compare-modal-content {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: white;
  border-radius: 20px;
  box-shadow: 0 25px 70px rgba(15, 23, 42, 0.3), 0 10px 30px rgba(0, 0, 0, 0.15);
  width: 96vw;
  max-width: 1600px;
  height: 92vh;
  max-height: 95vh;
  display: flex;
  flex-direction: column;
  z-index: 10000;
  opacity: 0;
  animation: slideUpCentered 0.3s ease forwards;
  border: 1px solid rgba(148, 163, 184, 0.25);
  overflow: hidden;
}

@keyframes slideUpCentered {
  from {
    transform: translate(-50%, calc(-50% + 30px));
    opacity: 0;
  }
  to {
    transform: translate(-50%, -50%);
    opacity: 1;
  }
}

/* ===================================
   رأس النافذة
   =================================== */
.compare-modal-header {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  padding: 24px 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.compare-modal-title-section {
  display: flex;
  align-items: center;
  gap: 16px;
}

.compare-modal-icon {
  font-size: 32px;
  opacity: 0.9;
}

.compare-modal-title {
  margin: 0;
  font-size: 26px;
  font-weight: 700;
}

.compare-modal-subtitle {
  margin: 4px 0 0 0;
  font-size: 14px;
  opacity: 0.85;
}

.compare-modal-actions {
  display: flex;
  gap: 12px;
}

.btn-export-comparison,
.btn-close-compare {
  background: rgba(255, 255, 255, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.3);
  color: white;
  padding: 10px 20px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-export-comparison:hover,
.btn-close-compare:hover {
  background: rgba(255, 255, 255, 0.3);
  transform: translateY(-2px);
}

/* ===================================
   فلاتر وبحث
   =================================== */
.compare-filters {
  padding: 16px 24px;
  background: #f8f9fa;
  border-bottom: 1px solid #e2e8f0;
  display: flex;
  gap: 16px;
  align-items: center;
  flex-shrink: 0;
}

.compare-search {
  flex: 1;
  position: relative;
}

.compare-search input {
  width: 100%;
  padding: 10px 16px 10px 40px;
  border: 1px solid #cbd5e0;
  border-radius: 10px;
  font-size: 14px;
  transition: all 0.2s ease;
}

.compare-search input:focus {
  outline: none;
  border-color: #667eea;
  box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.compare-search i {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: #64748b;
}

.compare-filter-tags {
  display: flex;
  gap: 8px;
}

.filter-tag {
  padding: 8px 16px;
  background: white;
  border: 1px solid #cbd5e0;
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.filter-tag.active {
  background: #667eea;
  color: white;
  border-color: #667eea;
}

.filter-tag:hover {
  border-color: #667eea;
}

/* ===================================
   محتوى المقارنة
   =================================== */
.compare-modal-body {
  flex: 1;
  overflow: auto;
  padding: 24px;
}

.comparison-table-wrapper {
  overflow-x: auto;
}

.comparison-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 14px;
}

.comparison-table thead {
  position: sticky;
  top: 0;
  z-index: 10;
  background: white;
}

.comparison-table th {
  background: #f8f9fa;
  padding: 16px;
  text-align: right;
  font-weight: 700;
  border-bottom: 2px solid #e2e8f0;
  white-space: nowrap;
}

.comparison-table th.field-name-col {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  width: 250px;
  position: sticky;
  right: 0;
  z-index: 11;
}

.comparison-table th.client-col {
  min-width: 200px;
}

.comparison-table tbody tr:nth-child(even) {
  background: #f8f9fa;
}

.comparison-table td {
  padding: 14px 16px;
  border-bottom: 1px solid #e2e8f0;
  vertical-align: top;
}

.comparison-table td.field-name-cell {
  background: white;
  font-weight: 600;
  color: #1e293b;
  position: sticky;
  right: 0;
  border-left: 2px solid #e2e8f0;
  display: flex;
  align-items: center;
  gap: 8px;
}

.field-category-icon {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
}

.field-category-icon.general { background: #e0f2fe; color: #0284c7; }
.field-category-icon.contact { background: #fef3c7; color: #d97706; }
.field-category-icon.business { background: #ddd6fe; color: #7c3aed; }
.field-category-icon.financial { background: #dcfce7; color: #16a34a; }
.field-category-icon.documents { background: #ffe4e6; color: #e11d48; }

.comparison-table td.client-value-cell {
  color: #475569;
}

/* تمييز الاختلافات */
.comparison-table tr.has-difference td.client-value-cell {
  background: #fef3c7;
  border-right: 3px solid #f59e0b;
}

.comparison-table tr.all-same td.client-value-cell {
  background: #dcfce7;
  border-right: 3px solid #22c55e;
}

.comparison-table tr.has-empty td.client-value-cell.empty-value {
  background: #fee2e2;
  color: #dc2626;
  font-style: italic;
}

.comparison-table td.client-value-cell.empty-value::before {
  content: 'غير محدد';
}

/* قيم خاصة */
.value-badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
}

.value-badge.status-active { background: #dcfce7; color: #16a34a; }
.value-badge.status-inactive { background: #fee2e2; color: #dc2626; }
.value-badge.status-pending { background: #fef3c7; color: #d97706; }

/* ===================================
   حالات فارغة وتحميل
   =================================== */
.compare-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  gap: 16px;
}

.compare-loading-spinner {
  width: 50px;
  height: 50px;
  border: 4px solid #e2e8f0;
  border-top-color: #667eea;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.compare-empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 60px 20px;
  gap: 16px;
  color: #64748b;
}

.compare-empty-state i {
  font-size: 64px;
  opacity: 0.3;
}

/* ===================================
   Responsive
   =================================== */
@media (max-width: 900px) {
  .compare-toolbar {
    min-width: 90%;
    flex-direction: column;
    gap: 12px;
  }
  
  .compare-actions {
    width: 100%;
  }
  
  .btn-compare,
  .btn-clear-selection {
    flex: 1;
    justify-content: center;
  }
  
  .compare-modal-content {
    width: 98vw;
    height: 95vh;
  }
  
  .compare-filters {
    flex-direction: column;
    align-items: stretch;
  }
  
  .comparison-table th.field-name-col {
    width: 180px;
  }
}

@media (max-width: 600px) {
  .compare-modal-header {
    padding: 16px 20px;
  }
  
  .compare-modal-title {
    font-size: 20px;
  }
  
  .compare-modal-icon {
    font-size: 24px;
  }
  
  .compare-modal-body {
    padding: 16px;
  }
  
  .comparison-table th,
  .comparison-table td {
    padding: 10px 12px;
    font-size: 13px;
  }
}
