/* =========================================================
   MAIN & GLOBAL STYLES
   التنسيقات العامة والريست وتأثيرات الحركة ونظام التنبيهات
   ========================================================= */

@import url('variables.css');

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body, button, input, select, textarea, optgroup, table {
  font-family: 'Tajawal', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Noto Sans Arabic', Tahoma, sans-serif;
  -webkit-font-smoothing: antialiased;
}

html {
  font-size: 14px;
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  background-color: var(--bg);
  background-image: var(--bg-gradient);
  background-repeat: no-repeat;
  background-size: cover;
  color: var(--text-body);
  direction: rtl;
  text-align: right;
  min-height: 100vh;
  line-height: 1.5;
  overflow-x: hidden;
  width: 100%;
  padding-left: env(safe-area-inset-left, 0);
  padding-right: env(safe-area-inset-right, 0);
  padding-bottom: env(safe-area-inset-bottom, 0);
  touch-action: manipulation;
}

body.mobile-drawer-open {
  overflow: hidden !important;
  touch-action: none;
}

/* منع التكبير التلقائي المزعج على متصفحات Safari في هواتف الآيفون */
@media (max-width: 768px) {
  input, select, textarea, .form-control,
  input[type="text"], input[type="search"], input[type="number"], input[type="date"] {
    font-size: 16px !important;
  }
}

/* Custom Scrollbar */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
::-webkit-scrollbar-track {
  background: #f1f5f9;
}
::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: var(--radius-full);
}
::-webkit-scrollbar-thumb:hover {
  background: #94a3b8;
}

/* Button Base Styles */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 16px;
  font-size: 0.88rem;
  font-weight: 700;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  transition: transform 0.3s cubic-bezier(0.25, 1, 0.5, 1), box-shadow 0.3s cubic-bezier(0.25, 1, 0.5, 1), background-color 0.2s ease, opacity 0.2s ease;
  user-select: none;
  text-decoration: none;
  white-space: nowrap;
  box-shadow: var(--shadow-sm);
  will-change: transform;
}
.btn:hover {
  transform: translateY(-2px);
}
.btn:active {
  transform: scale(0.96) translateY(0);
}

.btn svg.svg-inline--fa, .btn i {
  font-size: 1.05rem;
  flex-shrink: 0;
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary-light), var(--primary));
  color: white;
  box-shadow: 0 4px 12px var(--primary-glow);
}
.btn-primary:hover {
  background: linear-gradient(135deg, #2563eb, var(--primary-hover));
  box-shadow: 0 6px 16px var(--primary-glow);
  transform: translateY(-2px);
}
.btn-primary svg.svg-inline--fa, .btn-primary i {
  color: #bfdbfe;
}

.btn-success {
  background: linear-gradient(135deg, #10b981, #059669);
  color: white;
  box-shadow: 0 4px 12px rgba(16, 185, 129, 0.25);
}
.btn-success:hover {
  background: linear-gradient(135deg, #059669, #047857);
  transform: translateY(-2px);
}
.btn-success svg.svg-inline--fa, .btn-success i {
  color: #a7f3d0;
}

.btn-excel {
  background: linear-gradient(135deg, #16a34a, #15803d);
  color: white;
  box-shadow: 0 4px 12px rgba(22, 163, 74, 0.25);
}
.btn-excel:hover {
  background: linear-gradient(135deg, #15803d, #166534);
  transform: translateY(-2px);
}
.btn-excel svg.svg-inline--fa, .btn-excel i {
  color: #bbf7d0;
}

.btn-pdf {
  background: linear-gradient(135deg, #ef4444, #dc2626);
  color: white;
  box-shadow: 0 4px 12px rgba(239, 68, 68, 0.25);
}
.btn-pdf:hover {
  background: linear-gradient(135deg, #dc2626, #b91c1c);
  transform: translateY(-2px);
}
.btn-pdf svg.svg-inline--fa, .btn-pdf i {
  color: #fecaca;
}

.btn-print {
  background: linear-gradient(135deg, #0284c7, #0369a1);
  color: white;
  box-shadow: 0 4px 12px rgba(2, 132, 199, 0.25);
}
.btn-print:hover {
  background: linear-gradient(135deg, #0369a1, #075985);
  transform: translateY(-2px);
}
.btn-print svg.svg-inline--fa, .btn-print i {
  color: #bae6fd;
}

.btn-import {
  background: linear-gradient(135deg, #8b5cf6, #7c3aed);
  color: white;
  box-shadow: 0 4px 12px rgba(139, 92, 246, 0.25);
}
.btn-import:hover {
  background: linear-gradient(135deg, #7c3aed, #6d28d9);
  transform: translateY(-2px);
}
.btn-import svg.svg-inline--fa, .btn-import i {
  color: #ddd6fe;
}

.btn-danger {
  background: #fee2e2;
  color: #ef4444;
  border-color: #fecaca;
}
.btn-danger:hover {
  background: #ef4444;
  color: white;
  transform: translateY(-2px);
}

.btn-secondary {
  background: #f1f5f9;
  color: var(--text-body);
  border-color: var(--border);
}
.btn-secondary:hover {
  background: #e2e8f0;
  color: var(--text-main);
  transform: translateY(-2px);
}

/* Action Icon Buttons */
.action-btns {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.icon-btn {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.3s cubic-bezier(0.25, 1, 0.5, 1), background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease;
  background: #f8fafc;
  color: var(--text-muted);
  will-change: transform;
}
.icon-btn:hover {
  transform: translateY(-2px) scale(1.05);
}
.icon-btn:active {
  transform: scale(0.92);
}
.icon-btn.edit {
  background: #eff6ff;
  color: #2563eb;
  border-color: #bfdbfe;
}
.icon-btn.edit:hover {
  background: #2563eb;
  color: white;
}
.icon-btn.delete {
  background: #fef2f2;
  color: #ef4444;
  border-color: #fecaca;
}
.icon-btn.delete:hover {
  background: #ef4444;
  color: white;
}
.icon-btn.delete-photo {
  background: #fff7ed;
  color: #ea580c;
  border-color: #fed7aa;
}
.icon-btn.delete-photo:hover {
  background: #ea580c;
  color: white;
  border-color: #c2410c;
}
[data-theme="dark"] .icon-btn.delete-photo {
  background: rgba(234, 88, 12, 0.15);
  color: #fb923c;
  border-color: rgba(234, 88, 12, 0.3);
}
[data-theme="dark"] .icon-btn.delete-photo:hover {
  background: #ea580c;
  color: white;
}

/* Section Transitions */
.section-view {
  display: none;
  opacity: 0;
  transform: translateY(12px);
  transition: opacity 0.3s cubic-bezier(0.25, 1, 0.5, 1), transform 0.3s cubic-bezier(0.25, 1, 0.5, 1);
  will-change: transform, opacity;
}
.section-view.active {
  display: block;
  opacity: 1;
  transform: translateY(0);
  animation: sectionFadeSlideIn 0.35s cubic-bezier(0.25, 1, 0.5, 1) forwards;
}

@keyframes sectionFadeSlideIn {
  from {
    opacity: 0;
    transform: translateY(14px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Toast Notifications System */
.toast-container {
  position: fixed;
  bottom: 24px;
  left: 24px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
}
.toast {
  pointer-events: all;
  min-width: 280px;
  max-width: 420px;
  background: white;
  border-radius: var(--radius-md);
  padding: 12px 18px;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: 0 12px 24px -6px rgba(15, 23, 42, 0.15), 0 0 0 1px var(--border);
  animation: toastSlideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  transition: all var(--transition-normal);
  direction: rtl;
}
.toast.toast-hiding {
  opacity: 0;
  transform: translateX(-30px);
}
.toast-icon {
  font-size: 1.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.toast-content {
  flex: 1;
}
.toast-title {
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--text-main);
  margin-bottom: 2px;
}
.toast-message {
  font-size: 0.8rem;
  color: var(--text-muted);
}
.toast-success {
  border-right: 4px solid var(--success);
}
.toast-success .toast-icon {
  color: var(--success);
}
.toast-error {
  border-right: 4px solid var(--danger);
}
.toast-error .toast-icon {
  color: var(--danger);
}
.toast-info {
  border-right: 4px solid var(--info);
}
.toast-info .toast-icon {
  color: var(--info);
}
.toast-warning {
  border-right: 4px solid var(--warning);
}
.toast-warning .toast-icon {
  color: var(--warning);
}

@keyframes toastSlideUp {
  from {
    opacity: 0;
    transform: translateY(20px) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* =========================================================
   120 FPS GPU ACCELERATION & REFLOW OPTIMIZATION
   تحسين الأداء لـ 120 فريم: عزل طبقات الرسم وتفادي Reflow
   ========================================================= */

/* تحسين استهلاك المعالج وتفادي Composite Layer Explosion */
.toast,
.modal-backdrop.active .modal {
  will-change: transform, opacity;
  transform: translateZ(0);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}

/* عزل حسابات التخطيط للعناصر الكبيرة والمحتوى خارج الشاشة */
.modal-backdrop {
  will-change: opacity;
  contain: strict;
}

.app-container {
  content-visibility: auto;
  contain-intrinsic-size: auto 800px;
}

.table-card,
.analytics-dashboard-section {
  content-visibility: auto;
  contain-intrinsic-size: auto 450px;
  contain: layout style;
}

.main-table-container,
.table-container,
.table-wrapper {
  content-visibility: auto;
  contain-intrinsic-size: 1000px;
  contain: layout style paint;
}

.chart-canvas-wrapper {
  contain: layout style paint;
}

/* طبقة الخلفية التفاعلية الثابتة المسرعة بالعتاد (Hardware-Accelerated Layer) */
.app-bg-layer {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: var(--bg-gradient);
  background-size: cover;
  pointer-events: none;
  z-index: -1;
  will-change: transform;
  transform: translateZ(0);
}

/* إيقاف الحركات والتأثيرات على العناصر غير المعروضة لتوفير دورات المعالج (CPU/GPU) */
.section-view:not(.active),
.modal-backdrop:not(.active),
[hidden] {
  animation: none !important;
  transition: none !important;
  pointer-events: none !important;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* تأثير الإبراز البصري الفوري للصف المضاف حديثاً في الجداول */
@keyframes rowHighlightPulse {
  0% { background-color: rgba(34, 197, 94, 0.4); outline: 2px solid #22c55e; }
  50% { background-color: rgba(34, 197, 94, 0.2); outline: 2px solid #22c55e; }
  100% { background-color: transparent; outline: 2px solid transparent; }
}

tr.new-row-highlight {
  animation: rowHighlightPulse 3.5s cubic-bezier(0.25, 1, 0.5, 1) forwards !important;
}
