/* PWA Styles */

/* تحسينات عامة للـ PWA */
html {
  scroll-behavior: smooth;
}

/* تحسينات PWA للجسم - بدون تأثير على النصوص الموجودة */
.pwa-body-enhancements {
  -webkit-overflow-scrolling: touch;
  -webkit-tap-highlight-color: transparent;
}

/* تطبيق user-select فقط على العناصر التفاعلية */
.pwa-no-select {
  user-select: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
}

/* إخفاء شريط التمرير على الأجهزة المحمولة */
::-webkit-scrollbar {
  width: 0px;
  background: transparent;
}

/* تحسينات للشاشات الصغيرة */
@media (max-width: 768px) {
  body {
    font-size: 16px; /* منع تكبير الخط على iOS */
  }

  input, textarea, select {
    font-size: 16px; /* منع التكبير التلقائي */
  }
}

/* وضع PWA مثبت */
.pwa-installed {
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

/* مؤشر التحميل للـ PWA */
.pwa-loading {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, transparent, #2196F3, transparent);
  z-index: 9999;
  animation: loading 2s linear infinite;
}

@keyframes loading {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}

/* مؤشر الاتصال */
.connection-indicator {
  position: fixed;
  top: 10px;
  left: 10px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  z-index: 1000;
  transition: all 0.3s ease;
}

.connection-indicator.online {
  background: #4CAF50;
  box-shadow: 0 0 0 3px rgba(76, 175, 80, 0.3);
}

.connection-indicator.offline {
  background: #f44336;
  box-shadow: 0 0 0 3px rgba(244, 67, 54, 0.3);
  animation: pulse 2s infinite;
}

/* زر التحديث السريع */
.pwa-refresh-btn {
  position: fixed;
  bottom: 80px;
  right: 20px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: #2196F3;
  color: white;
  border: none;
  font-size: 24px;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(33, 150, 243, 0.4);
  transition: all 0.3s ease;
  z-index: 1000;
}

.pwa-refresh-btn:hover {
  background: #1976D2;
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(33, 150, 243, 0.6);
}

.pwa-refresh-btn:active {
  transform: translateY(0);
}

/* بانر التحديث */
.pwa-update-banner {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: #2196F3;
  color: white;
  padding: 15px;
  transform: translateY(100%);
  transition: transform 0.3s ease;
  z-index: 9999;
}

.pwa-update-banner.show {
  transform: translateY(0);
}

.pwa-update-banner-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 1200px;
  margin: 0 auto;
}

.pwa-update-banner button {
  background: rgba(255, 255, 255, 0.2);
  color: white;
  border: none;
  padding: 8px 16px;
  border-radius: 4px;
  cursor: pointer;
  margin-left: 10px;
}

.pwa-update-banner button:hover {
  background: rgba(255, 255, 255, 0.3);
}

/* شاشة البداية */
.pwa-splash-screen {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: white;
  z-index: 10000;
  opacity: 1;
  transition: opacity 0.5s ease;
}

.pwa-splash-screen.hide {
  opacity: 0;
  pointer-events: none;
}

.pwa-splash-logo {
  width: 120px;
  height: 120px;
  margin-bottom: 30px;
  animation: logoSpin 2s ease-in-out;
}

@keyframes logoSpin {
  0% { transform: scale(0) rotate(0deg); }
  50% { transform: scale(1.1) rotate(180deg); }
  100% { transform: scale(1) rotate(360deg); }
}

.pwa-splash-title {
  font-size: 24px;
  font-weight: bold;
  margin-bottom: 10px;
}

.pwa-splash-subtitle {
  font-size: 16px;
  opacity: 0.8;
  margin-bottom: 30px;
}

.pwa-splash-loader {
  width: 40px;
  height: 40px;
  border: 3px solid rgba(255, 255, 255, 0.3);
  border-top: 3px solid white;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* تحسينات للوضع الداكن - فقط لعناصر PWA */
@media (prefers-color-scheme: dark) {
  .pwa-banner {
    background: linear-gradient(135deg, #1a1a1a 0%, #2d2d2d 100%);
  }

  .pwa-welcome-message {
    background: #2d2d2d;
    color: white;
  }
}

/* إعادة تعيين الألوان للنصوص العادية */
.normal-text-reset {
  color: inherit !important;
}

/* حماية شاملة للنصوص من تأثيرات PWA */
body:not(.pwa-splash-screen):not(.pwa-banner) p,
body:not(.pwa-splash-screen):not(.pwa-banner) span,
body:not(.pwa-splash-screen):not(.pwa-banner) div,
body:not(.pwa-splash-screen):not(.pwa-banner) h1,
body:not(.pwa-splash-screen):not(.pwa-banner) h2,
body:not(.pwa-splash-screen):not(.pwa-banner) h3,
body:not(.pwa-splash-screen):not(.pwa-banner) h4,
body:not(.pwa-splash-screen):not(.pwa-banner) h5,
body:not(.pwa-splash-screen):not(.pwa-banner) h6,
body:not(.pwa-splash-screen):not(.pwa-banner) label,
body:not(.pwa-splash-screen):not(.pwa-banner) input,
body:not(.pwa-splash-screen):not(.pwa-banner) textarea,
body:not(.pwa-splash-screen):not(.pwa-banner) select,
body:not(.pwa-splash-screen):not(.pwa-banner) table,
body:not(.pwa-splash-screen):not(.pwa-banner) td,
body:not(.pwa-splash-screen):not(.pwa-banner) th,
body:not(.pwa-splash-screen):not(.pwa-banner) li,
body:not(.pwa-splash-screen):not(.pwa-banner) a {
  color: inherit !important;
}

/* استعادة تفاعلية النصوص */
body:not(.pwa-splash-screen):not(.pwa-banner) * {
  user-select: auto !important;
  -webkit-user-select: auto !important;
  -moz-user-select: auto !important;
  -ms-user-select: auto !important;
}

/* تطبيق عدم التحديد فقط على عناصر PWA المحددة */
.pwa-banner *,
.pwa-splash-screen *,
.pwa-update-banner *,
.pwa-refresh-btn,
.pwa-install-btn,
.pwa-dismiss-btn {
  user-select: none !important;
  -webkit-user-select: none !important;
  -moz-user-select: none !important;
  -ms-user-select: none !important;
}

/* إعادة تعيين قوية لحماية النصوص الموجودة */
body:not(.pwa-page) {
  color: initial !important;
}

body:not(.pwa-page) *:not(.pwa-banner):not(.pwa-splash-screen):not(.pwa-update-banner):not(.pwa-welcome-message) {
  color: inherit !important;
}

/* تأكيد خاص للعناصر الرئيسية */
.sidebar-nav,
.sidebar-nav *,
.main-content,
.main-content *,
.data-table,
.data-table *,
.representatives-main-section,
.representatives-main-section *,
.form-container,
.form-container * {
  color: inherit !important;
}/* تحسينات للشاشات الكبيرة */
@media (min-width: 1200px) {
  .pwa-banner-content {
    padding: 0 20px;
  }
}

/* تحسينات الأداء */
* {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* حماية الصور من السحب - فقط داخل عناصر PWA */
.pwa-container img,
.pwa-banner img,
.pwa-splash-screen img {
  -webkit-user-drag: none;
  -khtml-user-drag: none;
  -moz-user-drag: none;
  -o-user-drag: none;
}

/* منع النص من الاختيار في العناصر التفاعلية */
button, .clickable {
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  -khtml-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}

/* تحسين الأزرار للمس */
button, .btn {
  min-height: 44px;
  min-width: 44px;
  touch-action: manipulation;
}

/* مؤثرات الانتقال المحسنة */
.page-transition {
  transition: transform 0.3s ease, opacity 0.3s ease;
}

.page-transition.entering {
  transform: translateX(100%);
  opacity: 0;
}

.page-transition.entered {
  transform: translateX(0);
  opacity: 1;
}

.page-transition.exiting {
  transform: translateX(-100%);
  opacity: 0;
}

/* شاشة تحميل مخصصة للصفحات */
.page-loading {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(255, 255, 255, 0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9998;
}

.page-loading-spinner {
  width: 50px;
  height: 50px;
  border: 5px solid #f3f3f3;
  border-top: 5px solid #2196F3;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

/* تحسينات خاصة بـ iOS */
@supports (-webkit-touch-callout: none) {
  .ios-safe-area {
    padding-top: constant(safe-area-inset-top);
    padding-top: env(safe-area-inset-top);
  }

  .ios-safe-area-bottom {
    padding-bottom: constant(safe-area-inset-bottom);
    padding-bottom: env(safe-area-inset-bottom);
  }
}

/* تحسينات للطباعة */
@media print {
  .pwa-banner,
  .pwa-update-banner,
  .pwa-refresh-btn,
  .connection-indicator {
    display: none !important;
  }
}
