/**
 * ورقة الأنماط التأسيسية لتطبيق الجوال المستقل — مركز أبكار الطبي
 * Abkar Medical Center - Dedicated Mobile App-Like Engine (v1.0)
 * صُممت بنمط Native App مع شريط ملاحة سفلي وبطاقات لمسية مستقلة تماماً عن الديسكتوب
 */

:root {
  --m-p: #0a63c9;
  --m-pd: #063973;
  --m-pl: #eff6ff;
  --m-red: #d4141c;
  --m-red-soft: #fee2e2;
  --m-green: #10b981;
  --m-green-soft: #d1fae5;
  --m-amber: #f59e0b;
  --m-amber-soft: #fef3c7;
  --m-ink: #0f172a;
  --m-ink2: #334155;
  --m-mut: #64748b;
  --m-bg: #f8fafc;
  --m-card: #ffffff;
  --m-line: #e2e8f0;
  --m-r: 16px;
  --m-sh: 0 4px 18px rgba(15, 23, 42, 0.06);
  --m-nav-h: 64px;
  --m-hdr-h: 58px;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  background-color: var(--m-bg);
  color: var(--m-ink);
  font-family: 'Tajawal', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  direction: rtl;
  text-align: right;
  -webkit-font-smoothing: antialiased;
}

body {
  padding-top: var(--m-hdr-h);
  padding-bottom: calc(var(--m-nav-h) + 16px);
  min-height: 100vh;
}

/* 1. الترويسة العلوية الثابتة (Top App Bar) */
.m-appbar {
  position: fixed;
  top: 0;
  right: 0;
  left: 0;
  height: var(--m-hdr-h);
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--m-line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  z-index: 1000;
  box-shadow: 0 2px 10px rgba(15, 23, 42, 0.03);
}

.m-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--m-pd);
}

.m-brand img {
  width: 38px;
  height: 38px;
  object-fit: contain;
}

.m-brand-info b {
  display: block;
  font-size: 1.05rem;
  font-weight: 900;
  color: var(--m-pd);
  line-height: 1.1;
}

.m-brand-info small {
  display: block;
  font-size: 0.68rem;
  color: var(--m-p);
  font-weight: 800;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

.m-appbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.m-icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  background: var(--m-pl);
  color: var(--m-p);
  border: 1px solid rgba(10, 99, 201, 0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  font-size: 1.1rem;
  cursor: pointer;
}

/* 2. شريط الملاحة السفلي الثابت (Bottom Navigation Bar) */
.m-bottom-nav {
  position: fixed;
  bottom: 0;
  right: 0;
  left: 0;
  height: var(--m-nav-h);
  background: #ffffff;
  border-top: 1px solid var(--m-line);
  display: flex;
  align-items: center;
  justify-content: space-around;
  z-index: 1000;
  padding: 0 4px;
  box-shadow: 0 -4px 20px rgba(15, 23, 42, 0.05);
}

.m-nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  color: var(--m-mut);
  padding: 6px 0;
  font-size: 0.72rem;
  font-weight: 700;
  gap: 3px;
  transition: all 0.2s ease;
  position: relative;
}

.m-nav-item .m-nav-icon {
  font-size: 1.3rem;
  line-height: 1;
  transition: transform 0.2s ease;
}

.m-nav-item.active {
  color: var(--m-p);
  font-weight: 900;
}

.m-nav-item.active .m-nav-icon {
  transform: translateY(-2px);
  color: var(--m-p);
}

.m-nav-item.active::after {
  content: '';
  position: absolute;
  top: 0;
  width: 24px;
  height: 3px;
  background: var(--m-p);
  border-radius: 0 0 3px 3px;
}

/* 3. حاوية المحتوى العام للجوال */
.m-container {
  padding: 16px;
  max-width: 600px;
  margin: 0 auto;
}

/* 4. البطاقات اللمسية (Mobile Touch Cards) */
.m-card {
  background: var(--m-card);
  border: 1px solid var(--m-line);
  border-radius: var(--m-r);
  padding: 16px;
  margin-bottom: 14px;
  box-shadow: var(--m-sh);
}

.m-card-glass {
  background: rgba(255, 255, 255, 0.94);
  border: 1.5px solid rgba(226, 232, 240, 0.9);
  border-radius: var(--m-r);
  box-shadow: 0 6px 20px rgba(15, 23, 42, 0.05);
}

.m-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid #f1f5f9;
}

.m-card-title {
  font-size: 1.05rem;
  font-weight: 900;
  color: var(--m-pd);
  margin: 0;
}

/* 5. شارات الحالة (Status Badges) */
.m-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 800;
}
.m-badge-primary { background: var(--m-pl); color: var(--m-p); }
.m-badge-success { background: var(--m-green-soft); color: var(--m-green); }
.m-badge-danger { background: var(--m-red-soft); color: var(--m-red); }
.m-badge-warning { background: var(--m-amber-soft); color: var(--m-amber); }

/* 6. الأزرار اللمسية المريحة */
.m-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  min-height: 46px;
  padding: 10px 18px;
  border-radius: 12px;
  font-size: 0.95rem;
  font-weight: 800;
  text-decoration: none;
  border: none;
  cursor: pointer;
  transition: transform 0.15s ease, opacity 0.15s ease;
}
.m-btn:active { transform: scale(0.98); }
.m-btn-primary {
  background: linear-gradient(135deg, #0a63c9 0%, #063973 100%);
  color: #ffffff;
  box-shadow: 0 4px 14px rgba(10, 99, 201, 0.28);
}
.m-btn-secondary {
  background: #f1f5f9;
  color: var(--m-ink2);
  border: 1px solid var(--m-line);
}
.m-btn-outline {
  background: transparent;
  color: var(--m-p);
  border: 1.5px solid var(--m-p);
}
.m-btn-whatsapp {
  background: #25d366;
  color: #ffffff;
  box-shadow: 0 4px 12px rgba(37, 211, 102, 0.25);
}
.m-btn-sm {
  min-height: 36px;
  font-size: 0.85rem;
  padding: 6px 12px;
  border-radius: 8px;
  width: auto;
}

/* 7. عناصر الإدخال اللمسية الصديقة للموبايل */
.m-form-group {
  margin-bottom: 14px;
}
.m-form-label {
  display: block;
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--m-ink2);
  margin-bottom: 6px;
}
.m-input, .m-select, .m-textarea {
  width: 100%;
  min-height: 46px;
  padding: 10px 14px;
  border: 1.5px solid var(--m-line);
  border-radius: 12px;
  font-size: 16px !important; /* لمنع الزووم التلقائي في آيفون */
  font-family: inherit;
  background: #ffffff;
  color: var(--m-ink);
  outline: none;
  transition: border-color 0.2s ease;
}
.m-input:focus, .m-select:focus, .m-textarea:focus {
  border-color: var(--m-p);
  box-shadow: 0 0 0 3px rgba(10, 99, 201, 0.12);
}

/* 8. بطاقات البيانات (Data Cards) لاستبدال الجداول في الجوال */
.m-data-card {
  background: #ffffff;
  border: 1px solid var(--m-line);
  border-radius: 14px;
  padding: 14px;
  margin-bottom: 12px;
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.04);
}
.m-data-card-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.m-data-card-row:last-child {
  margin-bottom: 0;
  padding-top: 8px;
  border-top: 1px dashed #f1f5f9;
}
.m-data-card-label {
  font-size: 0.82rem;
  color: var(--m-mut);
}
.m-data-card-val {
  font-size: 0.9rem;
  font-weight: 800;
  color: var(--m-ink);
}

/* 9. شبكة الأيقونات السريعة للعيادات والخدمات */
.m-quick-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}
.m-quick-card {
  background: #ffffff;
  border: 1px solid var(--m-line);
  border-radius: 16px;
  padding: 16px 12px;
  text-align: center;
  text-decoration: none;
  color: var(--m-ink);
  box-shadow: 0 2px 10px rgba(15, 23, 42, 0.03);
  transition: transform 0.15s ease;
}
.m-quick-card:active { transform: scale(0.97); }
.m-quick-icon {
  width: 48px;
  height: 48px;
  margin: 0 auto 10px;
  border-radius: 14px;
  background: var(--m-pl);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.6rem;
}
.m-quick-title {
  font-size: 0.95rem;
  font-weight: 900;
  color: var(--m-pd);
  margin-bottom: 4px;
}
.m-quick-desc {
  font-size: 0.76rem;
  color: var(--m-mut);
  line-height: 1.4;
  margin: 0;
}

/* 10. شريط التبديل إلى سطح المكتب (اختياري أسفل الصفحة) */
.m-footer-switch {
  text-align: center;
  padding: 20px 10px;
  font-size: 0.82rem;
  color: var(--m-mut);
}
.m-footer-switch a {
  color: var(--m-p);
  text-decoration: underline;
  font-weight: 700;
}

/* ==========================================================================
   11. محدد التبويب العلوي واللوح السفلي (Header Dropdown & Bottom Sheet Picker)
   ========================================================================== */
.m-subnav-bar {
  position: sticky;
  top: 56px;
  z-index: 85000;
  background: #ffffff;
  border-bottom: 1.5px solid var(--m-line);
  padding: 8px 12px;
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.04);
}

.m-subnav-picker-btn {
  width: 100%;
  background: #eff6ff;
  border: 1.5px solid #0a63c9;
  border-radius: 12px;
  padding: 8px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.2s ease;
  box-shadow: 0 2px 6px rgba(10, 99, 201, 0.08);
}
.m-subnav-picker-btn:active {
  background: #dbeafe;
  transform: scale(0.99);
}

.m-subnav-picker-info {
  display: flex;
  align-items: center;
  gap: 10px;
  text-align: right;
  overflow: hidden;
}

.m-subnav-icon {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: #ffffff;
  border: 1px solid #bfdbfe;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  flex-shrink: 0;
}

.m-subnav-text-col {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.m-subnav-mod-title {
  font-size: 0.7rem;
  color: #0a63c9;
  font-weight: 800;
  line-height: 1.1;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.m-subnav-sub-title {
  font-size: 0.92rem;
  color: #0f172a;
  font-weight: 900;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.2;
  margin-top: 2px;
}

.m-subnav-badge-pill {
  background: #0a63c9;
  color: #ffffff;
  font-size: 0.72rem;
  font-weight: 800;
  padding: 4px 10px;
  border-radius: 20px;
  white-space: nowrap;
  flex-shrink: 0;
  box-shadow: 0 2px 6px rgba(10, 99, 201, 0.2);
}

/* النافذة السفلية المنزلقة (Bottom Sheet Modal) */
.m-sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.65);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 96000;
  display: none;
  opacity: 0;
  transition: opacity 0.25s ease;
}
.m-sheet-backdrop.is-open {
  display: block;
  opacity: 1;
}

.m-bottom-sheet {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: #ffffff;
  border-radius: 22px 22px 0 0;
  z-index: 96001;
  max-height: 85vh;
  display: none;
  flex-direction: column;
  box-shadow: 0 -10px 40px rgba(15, 23, 42, 0.3);
  transform: translateY(100%);
  transition: transform 0.28s cubic-bezier(0.16, 1, 0.3, 1);
  direction: rtl;
}
.m-bottom-sheet.is-open {
  display: flex !important;
  transform: translateY(0);
}

.m-bottom-sheet-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 18px 12px;
  border-bottom: 1.5px solid var(--m-line);
  position: sticky;
  top: 0;
  background: #ffffff;
  border-radius: 22px 22px 0 0;
  z-index: 2;
}

.m-sheet-drag-handle {
  width: 40px;
  height: 4px;
  background: #cbd5e1;
  border-radius: 10px;
  margin: 0 auto 10px;
}

.m-sheet-title {
  display: flex;
  align-items: center;
  gap: 10px;
}

.m-sheet-close {
  background: #f1f5f9;
  border: 1px solid var(--m-line);
  color: #64748b;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  font-size: 18px;
  font-weight: 800;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.m-sheet-close:active { background: #e2e8f0; }

.m-bottom-sheet-body {
  padding: 12px 14px 28px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.m-sheet-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 14px;
  background: #f8fafc;
  border: 1.5px solid #e2e8f0;
  text-decoration: none;
  color: var(--m-ink);
  transition: all 0.15s ease;
}
.m-sheet-item:active {
  background: #f1f5f9;
  transform: scale(0.99);
}

.m-sheet-item.is-active {
  background: #eff6ff;
  border-color: #0a63c9;
  box-shadow: 0 2px 10px rgba(10, 99, 201, 0.12);
}

.m-sheet-item-icon {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: #ffffff;
  border: 1px solid #cbd5e1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.35rem;
  flex-shrink: 0;
}
.m-sheet-item.is-active .m-sheet-item-icon {
  background: #0a63c9;
  color: #ffffff;
  border-color: #0a63c9;
}

.m-sheet-item-content {
  flex: 1;
  text-align: right;
  min-width: 0;
}

.m-sheet-item-title {
  display: block;
  font-size: 0.95rem;
  font-weight: 900;
  color: #0f172a;
  line-height: 1.2;
}
.m-sheet-item.is-active .m-sheet-item-title {
  color: #0a63c9;
}

.m-sheet-item-desc {
  display: block;
  font-size: 0.76rem;
  color: #64748b;
  margin-top: 3px;
  line-height: 1.3;
}

.m-sheet-item-check {
  font-size: 0.75rem;
  font-weight: 800;
  background: #0a63c9;
  color: #ffffff;
  padding: 4px 8px;
  border-radius: 12px;
  white-space: nowrap;
}

.m-sheet-item-arrow {
  color: #94a3b8;
  font-size: 1.1rem;
  font-weight: 800;
}

/* ==========================================================================
   12. محرك تحويل شاشات الديسك توب إلى النمط اللمسي (Full-Fidelity Touch Transform)
   ========================================================================== */
@media (max-width: 768px) {
  /* تعديل حشو جسم الصفحة لاستيعاب الأشرطة الثابتة */
  body {
    padding-top: 116px !important;
    padding-bottom: 78px !important;
  }

  /* البطاقات والحاويات الرئيسية */
  .wrap, main, .card, .content-box {
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
  }
  .card {
    border-radius: 14px !important;
    padding: 14px 12px !important;
    margin-bottom: 12px !important;
    box-shadow: 0 2px 8px rgba(15, 23, 42, 0.05) !important;
  }

  /* تحويل الشبكات متعددة الأعمدة إلى عمود واحد لمسي */
  .grid, .grid-2, .grid-3, .grid-4, .k2, .k3, .k4, .k6, .dash-charts-grid {
    display: flex !important;
    flex-direction: column !important;
    gap: 12px !important;
  }

  /* تحسين الجداول العريضة دون حذف أي عمود */
  .table-wrap:not(.table-responsive-cards), .table-responsive:not(.table-responsive-cards) {
    display: block !important;
    width: 100% !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch !important;
    border-radius: 10px !important;
  }
  table:not(.table-responsive-cards table) {
    border-collapse: collapse !important;
    min-width: 650px !important;
  }
  .table-responsive-cards, .table-responsive-cards table {
    width: 100% !important;
    min-width: 0 !important;
    max-width: 100% !important;
    overflow-x: hidden !important;
  }
  table th, table td {
    padding: 10px 10px !important;
    font-size: 0.86rem !important;
    white-space: nowrap !important;
    vertical-align: middle !important;
  }
  table th {
    background: #f1f5f9 !important;
    color: #334155 !important;
    font-weight: 800 !important;
  }
  table tr:nth-child(even) td {
    background: #f8fafc !important;
  }

  /* النماذج وحقول الإدخال لتجربة لمس ممتازة ومنع التكبير التلقائي */
  .f, .form-group {
    width: 100% !important;
    margin-bottom: 12px !important;
  }
  input[type="text"],
  input[type="number"],
  input[type="tel"],
  input[type="password"],
  input[type="email"],
  input[type="date"],
  select,
  textarea {
    width: 100% !important;
    min-height: 48px !important;
    font-size: 16px !important; /* يمنع zoom الآيفون المزعج */
    padding: 10px 14px !important;
    border-radius: 10px !important;
    border: 1.5px solid #cbd5e1 !important;
    box-sizing: border-box !important;
  }
  input:focus, select:focus, textarea:focus {
    border-color: #0a63c9 !important;
    outline: none !important;
    box-shadow: 0 0 0 3px rgba(10, 99, 201, 0.15) !important;
  }

  /* الأزرار اللمسية */
  .btn, button.btn, a.btn {
    min-height: 44px !important;
    padding: 10px 16px !important;
    font-size: 0.92rem !important;
    font-weight: 800 !important;
    border-radius: 10px !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 6px !important;
    touch-action: manipulation !important;
  }

  /* أزرار العمليات داخل خلايا الجدول */
  table td .btn, table td a.btn, table td button {
    min-height: 34px !important;
    padding: 6px 10px !important;
    font-size: 0.78rem !important;
    border-radius: 6px !important;
  }

  /* تحويل النوافذ المنبثقة إلى ألواح سفلية باللمس */
  .modal-box, .box-modal, #patientModal > div {
    position: fixed !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    top: auto !important;
    width: 100% !important;
    max-width: 100% !important;
    border-radius: 20px 20px 0 0 !important;
    max-height: 90vh !important;
    overflow-y: auto !important;
    box-shadow: 0 -10px 40px rgba(0,0,0,0.35) !important;
  }
}
