/* ═══════════════════════════════════════════════════════════════════
   mobile.css — تحسينات متقدمة للموبايل والأجهزة الصغيرة
   ═══════════════════════════════════════════════════════════════════ */

/* ╔═══════════════════════════════════════════════════════════════════╗
   ║ جودة العرض على الموبايل والأجهزة الصغيرة                      ║
   ╚═══════════════════════════════════════════════════════════════════╝ */

@media (max-width: 640px) {
  /* ─── اللمسات والتفاعلات المحسّنة ─── */
  * {
    -webkit-tap-highlight-color: rgba(99, 102, 241, 0.1);
    -webkit-touch-callout: none;
  }

  a, button, .btn, input, select, textarea {
    -webkit-user-select: none;
    user-select: none;
    min-height: 44px;
    min-width: 44px;
  }

  /* ─── الخطوط محسّنة للشاشات الصغيرة ─── */
  body {
    -webkit-text-size-adjust: 100%;
    -moz-text-size-adjust: 100%;
    text-size-adjust: 100%;
  }

  h1 { font-size: 1.5rem; line-height: 1.3; }
  h2 { font-size: 1.25rem; line-height: 1.35; }
  h3 { font-size: 1.1rem; line-height: 1.4; }
  h4 { font-size: 1rem; line-height: 1.4; }
  h5, h6 { font-size: .95rem; line-height: 1.4; }

  p { font-size: .9rem; line-height: 1.6; }
  small { font-size: .8rem; }

  /* ─── القوائم المنسدلة محسّنة ─── */
  select.inp {
    padding-right: 1.8rem;
    background-size: 1rem;
    background-position: right 0.4rem center;
  }

  /* ─── النماذج محسّنة ─── */
  .form-group {
    margin-bottom: 1rem;
  }

  .form-group label {
    display: block;
    margin-bottom: 0.4rem;
    font-weight: 600;
    font-size: 0.8rem;
  }

  .form-group input,
  .form-group textarea,
  .form-group select {
    width: 100%;
  }

  textarea {
    min-height: 100px;
    resize: vertical;
    max-height: 200px;
  }

  /* ─── أزرار محسّنة للمس ─── */
  .btn {
    min-height: 44px;
    transition: all 0.15s ease;
    -webkit-user-select: none;
    user-select: none;
  }

  .btn:active {
    opacity: 0.9;
    transform: scale(0.98);
  }

  .btn-block {
    width: 100%;
    display: flex;
    justify-content: center;
  }

  /* ─── الصور محسّنة للموبايل ─── */
  img {
    max-width: 100%;
    height: auto;
    display: block;
  }

  /* ─── الجداول محسّنة للموبايل ─── */
  .tbl-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: var(--radius-sm);
    border: 1px solid var(--line);
  }

  /* ─── الهوامش والحشوات محسّنة ─── */
  .section { padding: 1rem .75rem; }
  .container { padding: 0 .75rem; margin: 0 auto; }

  /* ─── الشريط الجانبي والترويسة ─── */
  .sidebar {
    box-shadow: -4px 0 12px rgba(0, 0, 0, .15);
  }

  .app-header {
    box-shadow: 0 2px 8px rgba(0, 0, 0, .08);
  }

  /* ─── النوافذ المنبثقة محسّنة ─── */
  .modal-body {
    border-radius: .9rem .9rem 0 0;
    max-height: 90vh;
    overflow-y: auto;
  }

  .modal-wrap {
    padding: 1rem .75rem;
  }

  /* ─── رسائل البيانات الفارغة ─── */
  .empty-state {
    padding: 2rem 1rem;
    margin: 2rem 0;
  }

  /* ─── التنبيهات محسّنة ─── */
  .toast {
    max-width: 100%;
    margin: 0 .75rem;
    border-radius: var(--radius);
    font-size: .85rem;
  }

  .toasts {
    bottom: .75rem;
    left: .75rem;
    right: .75rem;
    width: auto;
  }

  /* ─── الارتفاعات المحددة ─── */
  .app-shell { min-height: 100vh; }
  .app-main { min-height: calc(100vh - 44px); }

  /* ─── تحسينات الأداء ─── */
  * {
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
  }

  .fade, .pulse, .spinner {
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
  }

  /* ─── القوائم السياقية ─── */
  .dropdown-menu {
    position: fixed;
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    max-height: 60vh;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    border: none;
    box-shadow: 0 -4px 12px rgba(0, 0, 0, .15);
  }

  .dropdown-menu-item {
    padding: 1rem;
    border-bottom: 1px solid var(--line-light);
  }

  .dropdown-menu-item:last-child {
    border-bottom: none;
  }

  /* ─── الأيقونات محسّنة ─── */
  .icon-badge {
    width: 2rem;
    height: 2rem;
    font-size: 1rem;
  }

  /* ─── التمرير الأفقي آمن ─── */
  .horizontal-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
  }

  .horizontal-scroll::-webkit-scrollbar {
    height: 3px;
  }

  .horizontal-scroll::-webkit-scrollbar-thumb {
    background: var(--brand-light);
    border-radius: 3px;
  }
}

/* ╔═══════════════════════════════════════════════════════════════════╗
   ║ الأجهزة اللوحية الصغيرة (480px - 640px)                         ║
   ╚═══════════════════════════════════════════════════════════════════╝ */

@media (min-width: 480px) and (max-width: 640px) {
  .tbl-responsive tbody tr {
    padding: 1rem;
  }

  .form-row.cols-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: .75rem;
  }

  .btn-group {
    display: flex;
    gap: .5rem;
  }

  .btn-group .btn {
    flex: 1;
  }
}

/* ╔═══════════════════════════════════════════════════════════════════╗
   ║ الأجهزة اللوحية المتوسطة (641px - 1023px)                       ║
   ╚═══════════════════════════════════════════════════════════════════╝ */

@media (min-width: 641px) and (max-width: 1023px) {
  body {
    font-size: .95rem;
  }

  .app-content {
    padding: 1.5rem;
  }

  .tbl th,
  .tbl td {
    padding: .7rem .6rem;
  }

  .btn {
    min-height: 40px;
  }

  .modal-body {
    max-height: 85vh;
  }

  .toast {
    max-width: 320px;
  }

  .toasts {
    bottom: 1rem;
    left: 1rem;
  }
}

/* ╔═══════════════════════════════════════════════════════════════════╗
   ║ المعالجات الخاصة للاتجاهات (Orientation)                       ║
   ╚═══════════════════════════════════════════════════════════════════╝ */

@media (orientation: portrait) and (max-width: 640px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .landscape-hide {
    display: block;
  }

  .landscape-show {
    display: none;
  }

  .app-header {
    gap: .5rem;
  }
}

@media (orientation: landscape) and (max-height: 500px) {
  .app-header {
    padding: .4rem .75rem;
  }

  .app-content {
    padding: .75rem;
  }

  .landscape-hide {
    display: none;
  }

  .landscape-show {
    display: block;
  }

  h1 { font-size: 1.25rem; }
  h2 { font-size: 1.1rem; }
  h3 { font-size: 1rem; }

  .page-title {
    margin-bottom: .5rem;
  }

  .form-group {
    margin-bottom: .5rem;
  }

  .tbl th,
  .tbl td {
    padding: .35rem .25rem;
    font-size: .75rem;
  }

  .btn {
    min-height: 36px;
    padding: .4rem .75rem;
  }
}

/* ╔═══════════════════════════════════════════════════════════════════╗
   ║ الشاشات الكبيرة جداً (> 1920px)                                 ║
   ╚═══════════════════════════════════════════════════════════════════╝ */

@media (min-width: 1920px) {
  .app-content {
    max-width: 1880px;
    margin: 0 auto;
  }

  .sidebar {
    width: 20rem;
  }

  .page-title {
    font-size: 2.5rem;
  }

  .btn {
    padding: .75rem 1.5rem;
    font-size: .95rem;
  }
}

/* ╔═══════════════════════════════════════════════════════════════════╗
   ║ فئات مساعدة لـ Responsive Design                                 ║
   ╚═══════════════════════════════════════════════════════════════════╝ */

/* إخفاء/إظهار العناصر حسب حجم الشاشة */
.d-none { display: none !important; }
.d-block { display: block !important; }
.d-inline { display: inline !important; }
.d-flex { display: flex !important; }
.d-grid { display: grid !important; }

.d-mobile-only { display: none !important; }
@media (max-width: 640px) {
  .d-mobile-only { display: block !important; }
}

.d-tablet-only { display: none !important; }
@media (min-width: 641px) and (max-width: 1023px) {
  .d-tablet-only { display: block !important; }
}

.d-desktop-only { display: none !important; }
@media (min-width: 1024px) {
  .d-desktop-only { display: block !important; }
}

/* الفراغات المحسّنة */
.mt-mobile { margin-top: .5rem; }
.mb-mobile { margin-bottom: .5rem; }
.px-mobile { padding-left: .75rem; padding-right: .75rem; }

@media (min-width: 641px) {
  .mt-mobile { margin-top: 1rem; }
  .mb-mobile { margin-bottom: 1rem; }
  .px-mobile { padding-left: 1.5rem; padding-right: 1.5rem; }
}

/* الشبكات المحسّنة */
.grid-mobile { display: grid; grid-template-columns: 1fr; gap: .75rem; }
@media (min-width: 640px) {
  .grid-mobile { grid-template-columns: 1fr 1fr; gap: 1rem; }
}

.grid-cols-2 { grid-template-columns: 1fr; }
@media (min-width: 480px) {
  .grid-cols-2 { grid-template-columns: 1fr 1fr; }
}

.grid-cols-3 { grid-template-columns: 1fr; }
@media (min-width: 768px) {
  .grid-cols-3 { grid-template-columns: repeat(3, 1fr); }
}

.grid-cols-4 { grid-template-columns: 1fr; }
@media (min-width: 1024px) {
  .grid-cols-4 { grid-template-columns: repeat(4, 1fr); }
}

/* الأعمدة المحسّنة */
.col-full { flex: 0 0 100%; }
.col-half { flex: 0 0 50%; }
.col-third { flex: 0 0 33.333%; }
.col-quarter { flex: 0 0 25%; }

@media (max-width: 640px) {
  .col-half,
  .col-third,
  .col-quarter {
    flex: 0 0 100%;
  }
}
