/* ====================================================================
   UX Enhancements - تحسينات تجربة المستخدم
   نظام الطيبات | الدكتور ضياء العوضي
   ==================================================================== */

/* ===== 1. Smooth Scrolling ===== */
html {
  scroll-behavior: smooth;
  /* احترام تفضيلات المستخدم */
}

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

/* ===== 2. Focus Visible (للـ Accessibility) ===== */
:focus {
  outline: none;
}

:focus-visible {
  outline: 3px solid #c9a84c;
  outline-offset: 3px;
  border-radius: 4px;
}

/* أزرار الـ navigation */
.nav-link:focus-visible,
.btn:focus-visible,
button:focus-visible,
a:focus-visible {
  outline: 3px solid #c9a84c;
  outline-offset: 3px;
  box-shadow: 0 0 0 6px rgba(201, 168, 76, 0.2);
}

/* ===== 3. Touch Targets للموبايل (Apple/Google guidelines: 44x44px min) ===== */
@media (max-width: 768px) {
  button,
  .btn,
  a.btn,
  input[type="button"],
  input[type="submit"],
  .nav-link,
  .nav-dropdown-item,
  .ta-drawer a,
  .icon-button {
    min-height: 44px;
    min-width: 44px;
    padding: 12px 16px;
  }
  
  /* Touch feedback */
  button:active,
  .btn:active,
  a:active {
    transform: scale(0.97);
    transition: transform 0.1s;
  }
}

/* ===== 4. Toast Notifications (بديل alert/confirm) ===== */
.ta-toast-container {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 99999;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
  width: 100%;
  max-width: 400px;
  padding: 0 20px;
}

.ta-toast {
  background: white;
  border-radius: 12px;
  padding: 14px 18px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
  border-right: 4px solid #c9a84c;
  font-family: 'Tajawal', sans-serif;
  font-size: 0.95rem;
  font-weight: 500;
  color: #1a3d2b;
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 12px;
  animation: ta-toast-slide-in 0.3s ease-out;
  min-height: 50px;
  line-height: 1.5;
}

.ta-toast--success {
  border-right-color: #2d8659;
  background: linear-gradient(to left, rgba(45, 134, 89, 0.05), white 30%);
}

.ta-toast--error {
  border-right-color: #d64545;
  background: linear-gradient(to left, rgba(214, 69, 69, 0.05), white 30%);
}

.ta-toast--warning {
  border-right-color: #f59e0b;
  background: linear-gradient(to left, rgba(245, 158, 11, 0.05), white 30%);
}

.ta-toast--info {
  border-right-color: #3b82f6;
  background: linear-gradient(to left, rgba(59, 130, 246, 0.05), white 30%);
}

.ta-toast__icon {
  font-size: 1.4rem;
  flex-shrink: 0;
}

.ta-toast__message {
  flex: 1;
}

.ta-toast__close {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1.3rem;
  color: #888;
  padding: 4px 8px;
  margin: -4px;
  line-height: 1;
  flex-shrink: 0;
  border-radius: 4px;
  transition: all 0.2s;
  min-height: auto !important;
  min-width: auto !important;
}

.ta-toast__close:hover {
  background: rgba(0, 0, 0, 0.05);
  color: #333;
}

.ta-toast--leaving {
  animation: ta-toast-slide-out 0.3s ease-in forwards;
}

@keyframes ta-toast-slide-in {
  from {
    opacity: 0;
    transform: translateY(-20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes ta-toast-slide-out {
  from {
    opacity: 1;
    transform: translateY(0);
  }
  to {
    opacity: 0;
    transform: translateY(-20px);
  }
}

/* Dark mode للـ toast */
[data-theme="dark"] .ta-toast,
[data-theme="awadi"] .ta-toast {
  background: #1a3d2b;
  color: #f5f5dc;
}

[data-theme="dark"] .ta-toast__close,
[data-theme="awadi"] .ta-toast__close {
  color: #ccc;
}

/* ===== 5. Confirm Dialog (بديل confirm) ===== */
.ta-confirm-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  z-index: 99998;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: ta-fade-in 0.2s ease-out;
}

.ta-confirm-dialog {
  background: white;
  border-radius: 16px;
  padding: 28px;
  max-width: 420px;
  width: 100%;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  font-family: 'Tajawal', sans-serif;
  text-align: center;
  animation: ta-zoom-in 0.25s ease-out;
}

.ta-confirm-dialog__icon {
  font-size: 3rem;
  margin-bottom: 12px;
}

.ta-confirm-dialog__title {
  font-size: 1.3rem;
  font-weight: 700;
  color: #1a3d2b;
  margin: 0 0 12px 0;
}

.ta-confirm-dialog__message {
  font-size: 1rem;
  color: #555;
  margin: 0 0 24px 0;
  line-height: 1.6;
}

.ta-confirm-dialog__actions {
  display: flex;
  gap: 10px;
  justify-content: center;
}

.ta-confirm-dialog__btn {
  padding: 10px 24px;
  border-radius: 10px;
  font-family: 'Tajawal', sans-serif;
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  border: none;
  transition: all 0.2s;
  min-width: 100px;
}

.ta-confirm-dialog__btn--confirm {
  background: #c9a84c;
  color: white;
}

.ta-confirm-dialog__btn--confirm:hover {
  background: #b08a32;
  transform: translateY(-1px);
}

.ta-confirm-dialog__btn--cancel {
  background: #f0f0f0;
  color: #333;
}

.ta-confirm-dialog__btn--cancel:hover {
  background: #e0e0e0;
}

@keyframes ta-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes ta-zoom-in {
  from {
    opacity: 0;
    transform: scale(0.9);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

/* Dark mode للـ confirm */
[data-theme="dark"] .ta-confirm-dialog,
[data-theme="awadi"] .ta-confirm-dialog {
  background: #2d5f4f;
  color: #f5f5dc;
}

[data-theme="dark"] .ta-confirm-dialog__title,
[data-theme="awadi"] .ta-confirm-dialog__title {
  color: #e8c96a;
}

[data-theme="dark"] .ta-confirm-dialog__message,
[data-theme="awadi"] .ta-confirm-dialog__message {
  color: #ccc;
}

[data-theme="dark"] .ta-confirm-dialog__btn--cancel,
[data-theme="awadi"] .ta-confirm-dialog__btn--cancel {
  background: #1a3d2b;
  color: #f5f5dc;
}

/* ===== 6. Image Loading Animation ===== */
img {
  /* تجنب layout shift */
  height: auto;
}

img[loading="lazy"] {
  background: linear-gradient(90deg, #f5f5f5 25%, #e8e8e8 50%, #f5f5f5 75%);
  background-size: 200% 100%;
  animation: ta-skeleton 1.5s infinite;
}

img[loading="lazy"][src] {
  animation: none;
  background: none;
}

@keyframes ta-skeleton {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ===== 7. Skip Link Improved ===== */
.skip-link {
  position: absolute;
  top: -100px;
  right: 0;
  background: #1a3d2b;
  color: white;
  padding: 12px 20px;
  text-decoration: none;
  font-weight: 600;
  border-radius: 0 0 0 8px;
  z-index: 999999;
  transition: top 0.2s;
  font-family: 'Tajawal', sans-serif;
}

.skip-link:focus {
  top: 0;
}

/* ===== 8. Selection Color (تحسين بسيط) ===== */
::selection {
  background-color: rgba(201, 168, 76, 0.3);
  color: #1a3d2b;
}

[data-theme="dark"] ::selection,
[data-theme="awadi"] ::selection {
  background-color: rgba(201, 168, 76, 0.4);
  color: #f5f5dc;
}

/* ===== 9. Scrollbar Styling ===== */
@media (min-width: 769px) {
  ::-webkit-scrollbar {
    width: 10px;
    height: 10px;
  }
  
  ::-webkit-scrollbar-track {
    background: #f5f5f0;
  }
  
  ::-webkit-scrollbar-thumb {
    background: #c9a84c;
    border-radius: 5px;
  }
  
  ::-webkit-scrollbar-thumb:hover {
    background: #b08a32;
  }
  
  /* Firefox */
  * {
    scrollbar-width: thin;
    scrollbar-color: #c9a84c #f5f5f0;
  }
  
  [data-theme="dark"] ::-webkit-scrollbar-track,
  [data-theme="awadi"] ::-webkit-scrollbar-track {
    background: #1a3d2b;
  }
}

/* ===== 10. Loading State Buttons ===== */
button[disabled],
button.is-loading {
  opacity: 0.7;
  cursor: not-allowed;
  position: relative;
}

button.is-loading::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 12px;
  width: 16px;
  height: 16px;
  margin-top: -8px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: ta-spin 0.8s linear infinite;
}

@keyframes ta-spin {
  to { transform: rotate(360deg); }
}

/* ===== 11. Better Form Inputs Focus ===== */
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
  outline: 2px solid #c9a84c;
  outline-offset: 2px;
  border-color: #c9a84c;
}

/* ===== 12. Print Styles (تحسين الطباعة) ===== */
@media print {
  .site-header,
  .site-footer,
  .telegram-banner,
  .pwa-install-button,
  .ta-toast-container,
  .nav-dropdown,
  button,
  .splash-screen {
    display: none !important;
  }
  
  body {
    background: white !important;
    color: black !important;
  }
  
  a {
    color: black !important;
    text-decoration: underline;
  }
  
  a[href]:after {
    content: " (" attr(href) ")";
    font-size: 0.85em;
    color: #666;
  }
}
