/* ============================================================
   نَبْض — نظام التصميم الطبي الاحترافي
   RTL-first • Mobile-first • Medical Color System
   ============================================================ */

/* --- متغيرات CSS (Design Tokens) --- */
:root {
  /* ألوان النظام */
  --primary:       #0d6efd;
  --primary-dark:  #0a58ca;
  --primary-light: #cfe2ff;
  --success:       #198754;
  --success-light: #d1e7dd;
  --danger:        #dc3545;
  --danger-light:  #f8d7da;
  --warning:       #ffc107;
  --warning-light: #fff3cd;
  --info:          #0dcaf0;
  --info-light:    #cff4fc;
  --whatsapp:      #25D366;
  --whatsapp-dark: #1ebe57;

  /* ألوان الخلفيات والنصوص */
  --bg-body:       #f0f4f8;
  --bg-card:       #ffffff;
  --bg-sidebar:    #1a2332;
  --text-dark:     #1a2332;
  --text-medium:   #495057;
  --text-light:    #6c757d;
  --text-sidebar:  #c8d6e5;
  --border:        #dee2e6;
  --border-light:  #e9ecef;

  /* طبقات الظل */
  --shadow-sm:   0 1px 3px rgba(0,0,0,.08);
  --shadow-md:   0 4px 12px rgba(0,0,0,.10);
  --shadow-lg:   0 8px 24px rgba(0,0,0,.14);

  /* أبعاد التخطيط */
  --sidebar-width:   240px;
  --topbar-height:   56px;
  --bottom-nav-h:    64px;
  --border-radius:   10px;
  --border-radius-sm:6px;
  --transition:      0.2s ease;
}

/* --- إعادة الضبط والأساسيات --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  direction: rtl;
  scroll-behavior: smooth;
}

body {
  font-family: 'Cairo', 'Segoe UI', Tahoma, sans-serif;
  font-size: 15px;
  line-height: 1.6;
  color: var(--text-dark);
  background: var(--bg-body);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* ============================================================
   شاشة التحميل
   ============================================================ */
.loading-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 60vh;
  gap: 1rem;
  color: var(--text-light);
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}

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

/* ============================================================
   شاشة المصادقة
   ============================================================ */
.auth-screen {
  min-height: 100vh;
  background: linear-gradient(135deg, #0d6efd 0%, #0a58ca 50%, #1a2332 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.auth-container {
  width: 100%;
  max-width: 420px;
}

.auth-logo {
  text-align: center;
  margin-bottom: 2rem;
  color: #fff;
}

.auth-logo .logo-icon { font-size: 3rem; display: block; margin-bottom: .5rem; }
.auth-logo .logo-text { font-size: 2.5rem; font-weight: 800; }
.auth-logo .logo-sub  { font-size: .95rem; opacity: .8; }

.auth-card {
  background: var(--bg-card);
  border-radius: 16px;
  padding: 2rem;
  box-shadow: var(--shadow-lg);
}

.auth-panel { display: none; }
.auth-panel.active { display: block; }

.auth-title {
  font-size: 1.4rem;
  font-weight: 700;
  margin-bottom: 1.5rem;
  color: var(--text-dark);
}

.auth-desc {
  color: var(--text-medium);
  margin-bottom: 1.5rem;
  font-size: .9rem;
}

.auth-links {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: .5rem;
  margin-top: 1rem;
}

.link-btn {
  background: none;
  border: none;
  color: var(--primary);
  cursor: pointer;
  font-family: inherit;
  font-size: .9rem;
  padding: 0;
  text-decoration: underline;
  transition: color var(--transition);
}
.link-btn:hover { color: var(--primary-dark); }

/* ============================================================
   تخطيط التطبيق الرئيسي
   ============================================================ */
.app-screen {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* --- الشريط الجانبي (Sidebar) --- */
.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-sidebar);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 1000;
  transition: transform var(--transition);
  overflow-y: auto;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.2rem 1rem;
  border-bottom: 1px solid rgba(255,255,255,.1);
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: .5rem;
  color: #fff;
}
.logo-icon-sm  { font-size: 1.5rem; }
.logo-text-sm  { font-size: 1.3rem; font-weight: 800; }

.sidebar-close {
  display: none;
  background: none;
  border: none;
  color: var(--text-sidebar);
  font-size: 1.2rem;
  cursor: pointer;
  padding: .25rem .5rem;
}

.sidebar-nav {
  flex: 1;
  padding: 1rem 0;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .75rem 1.25rem;
  color: var(--text-sidebar);
  text-decoration: none;
  font-size: .95rem;
  font-weight: 500;
  transition: background var(--transition), color var(--transition);
  border-right: 3px solid transparent;
}

.nav-item:hover {
  background: rgba(255,255,255,.08);
  color: #fff;
}

.nav-item.active {
  background: rgba(13,110,253,.25);
  color: #fff;
  border-right-color: var(--primary);
}

.nav-icon  { font-size: 1.1rem; width: 1.5rem; text-align: center; }
.nav-label { flex: 1; }

.sidebar-footer {
  padding: 1rem;
  border-top: 1px solid rgba(255,255,255,.1);
}

.btn-logout {
  display: flex;
  align-items: center;
  gap: .5rem;
  width: 100%;
  padding: .6rem 1rem;
  background: rgba(220,53,69,.2);
  border: 1px solid rgba(220,53,69,.3);
  border-radius: var(--border-radius-sm);
  color: #ff8f9b;
  cursor: pointer;
  font-family: inherit;
  font-size: .9rem;
  font-weight: 500;
  transition: background var(--transition);
}
.btn-logout:hover { background: rgba(220,53,69,.35); }

.sidebar-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 999;
  backdrop-filter: blur(2px);
}

/* --- المنطقة الرئيسية --- */
.app-main {
  flex: 1;
  margin-right: var(--sidebar-width);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  overflow: hidden;
}

/* --- شريط العنوان العلوي (Topbar) --- */
.topbar {
  height: var(--topbar-height);
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 1.25rem;
  gap: 1rem;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-sm);
}

.btn-menu {
  display: none;
  background: none;
  border: none;
  font-size: 1.4rem;
  cursor: pointer;
  color: var(--text-dark);
  padding: .25rem;
}

.topbar-title {
  flex: 1;
  font-size: 1.1rem;
  font-weight: 700;
}

.user-name-sm {
  font-size: .85rem;
  color: var(--text-light);
}

/* --- منطقة المحتوى --- */
.main-content {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem;
  padding-bottom: 2rem;
}

/* --- شريط التنقل السفلي (Bottom Nav) --- */
.bottom-nav {
  display: none;
  height: var(--bottom-nav-h);
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 100;
  box-shadow: 0 -2px 10px rgba(0,0,0,.08);
}

.bottom-nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  padding: .5rem .25rem;
  color: var(--text-light);
  text-decoration: none;
  font-size: .7rem;
  font-weight: 500;
  transition: color var(--transition);
  gap: .15rem;
}
.bottom-nav-item.active { color: var(--primary); }
.bnav-icon  { font-size: 1.3rem; }
.bnav-label { font-size: .65rem; }

/* ============================================================
   عناصر الواجهة المشتركة
   ============================================================ */

/* --- الأزرار --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  padding: .6rem 1.25rem;
  border: none;
  border-radius: var(--border-radius-sm);
  font-family: inherit;
  font-size: .9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  text-decoration: none;
  white-space: nowrap;
}

.btn:disabled { opacity: .65; cursor: not-allowed; }

.btn-primary    { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); }

.btn-secondary  { background: var(--border-light); color: var(--text-dark); }
.btn-secondary:hover:not(:disabled) { background: var(--border); }

.btn-success    { background: var(--success); color: #fff; }
.btn-success:hover:not(:disabled) { background: #157347; }

.btn-danger     { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: #bb2d3b; }

.btn-whatsapp   { background: var(--whatsapp); color: #fff; }
.btn-whatsapp:hover:not(:disabled) { background: var(--whatsapp-dark); }

.btn-outline    { background: transparent; border: 1.5px solid var(--primary); color: var(--primary); }
.btn-outline:hover { background: var(--primary-light); }

.btn-sm         { padding: .35rem .75rem; font-size: .82rem; }
.btn-block      { width: 100%; }
.btn-icon       { padding: .5rem; border-radius: 50%; }

.btn-spinner { display: none; }
.btn.loading .btn-text    { display: none; }
.btn.loading .btn-spinner { display: inline; }

/* --- البطاقات --- */
.card {
  background: var(--bg-card);
  border-radius: var(--border-radius);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border-light);
  overflow: hidden;
}

.card-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 700;
  font-size: 1rem;
}

.card-body { padding: 1.25rem; }

/* --- شبكة البيانات الرئيسية --- */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
  gap: .75rem;
}

.page-title {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--text-dark);
}

/* --- الإحصاءات السريعة (Dashboard Stats) --- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.stat-card {
  background: var(--bg-card);
  border-radius: var(--border-radius);
  padding: 1.25rem;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border-light);
  display: flex;
  flex-direction: column;
  gap: .4rem;
  transition: box-shadow var(--transition);
}
.stat-card:hover { box-shadow: var(--shadow-md); }

.stat-icon    { font-size: 1.8rem; }
.stat-label   { font-size: .82rem; color: var(--text-light); font-weight: 500; }
.stat-value   { font-size: 1.6rem; font-weight: 800; color: var(--text-dark); line-height: 1; }
.stat-unit    { font-size: .8rem;  color: var(--text-light); }
.stat-sub     { font-size: .78rem; font-weight: 600; }

.stat-normal  { color: var(--success); }
.stat-warning { color: var(--warning); }
.stat-danger  { color: var(--danger); }

/* --- الجداول --- */
.table-wrapper {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .9rem;
}

.data-table th {
  background: var(--bg-body);
  padding: .7rem 1rem;
  text-align: right;
  font-weight: 700;
  font-size: .82rem;
  color: var(--text-light);
  text-transform: uppercase;
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}

.data-table td {
  padding: .75rem 1rem;
  border-bottom: 1px solid var(--border-light);
  color: var(--text-dark);
  vertical-align: middle;
}

.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--bg-body); }

.badge {
  display: inline-block;
  padding: .2rem .6rem;
  border-radius: 20px;
  font-size: .75rem;
  font-weight: 600;
}

.badge-normal  { background: var(--success-light); color: var(--success); }
.badge-warning { background: var(--warning-light); color: #856404; }
.badge-danger  { background: var(--danger-light);  color: var(--danger); }
.badge-info    { background: var(--info-light);    color: #0a7c99; }

.value-abnormal { color: var(--danger); font-weight: 700; }

/* --- النماذج --- */
.form-group {
  margin-bottom: 1rem;
}

.form-label {
  display: block;
  font-size: .88rem;
  font-weight: 600;
  color: var(--text-medium);
  margin-bottom: .4rem;
}

.form-control {
  width: 100%;
  padding: .6rem .9rem;
  border: 1.5px solid var(--border);
  border-radius: var(--border-radius-sm);
  font-family: inherit;
  font-size: .92rem;
  color: var(--text-dark);
  background: #fff;
  transition: border-color var(--transition), box-shadow var(--transition);
  appearance: none;
  -webkit-appearance: none;
}

.form-control:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

.form-control::placeholder { color: var(--text-light); }

.form-control.is-invalid { border-color: var(--danger); }
.form-control.is-valid   { border-color: var(--success); }

textarea.form-control { resize: vertical; min-height: 70px; }

select.form-control {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath fill='%23666' d='M7.247 11.14 2.451 5.658C1.885 5.013 2.345 4 3.204 4h9.592a1 1 0 0 1 .753 1.659l-4.796 5.48a1 1 0 0 1-1.506 0z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: left .75rem center;
  background-size: 12px;
  padding-left: 2.25rem;
}

.form-row {
  display: flex;
  gap: .75rem;
  flex-wrap: wrap;
}
.form-row > .form-group { margin-bottom: 0; }

.flex-1 { flex: 1; min-width: 120px; }
.flex-2 { flex: 2; min-width: 150px; }

.form-hint {
  font-size: .82rem;
  color: var(--text-light);
  margin-bottom: 1rem;
  padding: .5rem .75rem;
  background: var(--info-light);
  border-radius: var(--border-radius-sm);
  border-right: 3px solid var(--info);
}

.section-label {
  font-size: .85rem;
  font-weight: 700;
  color: var(--text-light);
  text-transform: uppercase;
  letter-spacing: .05em;
  margin: 1rem 0 .75rem;
  padding-bottom: .4rem;
  border-bottom: 1px solid var(--border-light);
}

/* --- نتائج الحسابات الطبية الآنية --- */
.calc-result {
  background: var(--primary-light);
  border: 1px solid var(--primary);
  border-radius: var(--border-radius-sm);
  padding: .6rem .9rem;
  margin-bottom: .75rem;
  font-size: .88rem;
  display: flex;
  align-items: center;
  gap: .5rem;
  flex-wrap: wrap;
}

.calc-label { color: var(--text-medium); font-weight: 500; }
.calc-value { font-size: 1.2rem; font-weight: 800; color: var(--primary-dark); }
.calc-unit  { color: var(--text-light); font-size: .8rem; }

.calc-status {
  margin-right: auto;
  font-weight: 700;
  font-size: .82rem;
  padding: .15rem .5rem;
  border-radius: 12px;
}
.calc-status.normal  { background: var(--success-light); color: var(--success); }
.calc-status.warning { background: var(--warning-light); color: #856404; }
.calc-status.danger  { background: var(--danger-light);  color: var(--danger); }

/* --- مقياس بريستول --- */
.bristol-scale {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: .4rem;
}

.bristol-item { cursor: pointer; }
.bristol-item input[type="radio"] { display: none; }

.bristol-card {
  border: 2px solid var(--border);
  border-radius: var(--border-radius-sm);
  padding: .4rem .25rem;
  text-align: center;
  transition: all var(--transition);
  background: #fff;
}

.bristol-item input:checked + .bristol-card {
  border-color: var(--primary);
  background: var(--primary-light);
}

.bristol-num {
  font-size: 1.2rem;
  font-weight: 800;
  color: var(--primary);
}

.bristol-desc {
  font-size: .65rem;
  color: var(--text-medium);
  line-height: 1.3;
  margin-top: .2rem;
}

/* --- مربعات التحقق (Checkbox Grid) --- */
.checkbox-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: .5rem;
}

.checkbox-item {
  display: flex;
  align-items: center;
  gap: .5rem;
  cursor: pointer;
  font-size: .88rem;
  color: var(--text-medium);
  padding: .35rem .5rem;
  border: 1.5px solid var(--border);
  border-radius: var(--border-radius-sm);
  transition: all var(--transition);
}
.checkbox-item:hover { border-color: var(--primary); background: var(--primary-light); }
.checkbox-item input:checked + *,
.checkbox-item:has(input:checked) {
  border-color: var(--primary);
  background: var(--primary-light);
  color: var(--primary-dark);
}

/* ============================================================
   النوافذ المنبثقة (Modals)
   ============================================================ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10,20,40,.6);
  z-index: 2000;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 1rem;
  overflow-y: auto;
  backdrop-filter: blur(4px);
}

.modal {
  background: var(--bg-card);
  border-radius: 14px;
  width: 100%;
  max-width: 520px;
  margin: auto;
  box-shadow: var(--shadow-lg);
  animation: modal-in .2s ease;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
}

.modal-wide      { max-width: 700px; }
.modal-sm        { max-width: 380px; }
.modal-fullscreen { max-width: 900px; }

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

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border-light);
  position: sticky;
  top: 0;
  background: inherit;
  border-radius: 14px 14px 0 0;
}

.modal-title { font-size: 1.05rem; font-weight: 700; }

.modal-close {
  background: none;
  border: none;
  font-size: 1.1rem;
  cursor: pointer;
  color: var(--text-light);
  padding: .25rem .5rem;
  border-radius: 6px;
  transition: all var(--transition);
}
.modal-close:hover { background: var(--bg-body); color: var(--text-dark); }

.modal-body {
  padding: 1.25rem;
  overflow-y: auto;
  flex: 1;
}

.modal-actions {
  display: flex;
  gap: .75rem;
  justify-content: flex-end;
  padding-top: 1rem;
  border-top: 1px solid var(--border-light);
  margin-top: 1rem;
}

/* --- شريط أدوات التقرير --- */
.report-toolbar {
  display: flex;
  gap: .75rem;
  padding: .75rem 1.25rem;
  border-bottom: 1px solid var(--border-light);
  flex-wrap: wrap;
  background: var(--bg-body);
}

.report-preview-body { padding: 0; }

/* ============================================================
   محتوى التقرير (مُصمَّم للطباعة وتصدير PDF)
   ============================================================ */
.report-content {
  padding: 1.5rem;
  font-size: .9rem;
}

.report-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 2px solid var(--primary);
}

.report-logo { font-size: 1.5rem; font-weight: 800; color: var(--primary); }
.report-meta { font-size: .82rem; color: var(--text-light); text-align: left; }

.report-section-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--primary-dark);
  margin: 1.25rem 0 .75rem;
  padding-bottom: .3rem;
  border-bottom: 1px solid var(--border);
}

/* ============================================================
   حقول التحاليل الديناميكية
   ============================================================ */
.lab-params { margin-top: 1rem; }

.lab-param-row {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .75rem;
  border: 1px solid var(--border-light);
  border-radius: var(--border-radius-sm);
  margin-bottom: .5rem;
  background: var(--bg-body);
  transition: border-color var(--transition);
}

.lab-param-row.is-abnormal {
  border-color: var(--danger);
  background: var(--danger-light);
}

.lab-param-name {
  font-size: .88rem;
  font-weight: 600;
  min-width: 160px;
  color: var(--text-dark);
}

.lab-param-input { flex: 1; margin-bottom: 0; }
.lab-param-input .form-control { margin: 0; }

.lab-param-unit {
  font-size: .8rem;
  color: var(--text-light);
  min-width: 60px;
}

.lab-param-range {
  font-size: .75rem;
  color: var(--text-light);
  min-width: 100px;
  text-align: left;
}

.lab-param-range.out-of-range {
  color: var(--danger);
  font-weight: 700;
}

.lab-param-alert {
  font-size: .75rem;
  color: var(--danger);
  font-weight: 700;
}

/* ============================================================
   الرسوم البيانية
   ============================================================ */
.chart-container {
  position: relative;
  height: 220px;
  padding: .5rem;
}

.charts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 1rem;
  margin-top: 1.5rem;
}

/* ============================================================
   نظام الإشعارات (Toast)
   ============================================================ */
.toast-container {
  position: fixed;
  top: 1rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: .5rem;
  pointer-events: none;
  min-width: 300px;
  max-width: 480px;
}

.toast {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .85rem 1.1rem;
  border-radius: var(--border-radius-sm);
  box-shadow: var(--shadow-md);
  pointer-events: all;
  animation: toast-in .3s ease;
  font-size: .9rem;
  font-weight: 500;
  color: #fff;
}

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

.toast-out { animation: toast-out .3s ease forwards; }

@keyframes toast-out {
  to { transform: translateY(-10px); opacity: 0; }
}

.toast-success { background: var(--success); }
.toast-error   { background: var(--danger); }
.toast-warning { background: var(--warning); color: var(--text-dark); }
.toast-info    { background: var(--primary); }

.toast-icon { font-size: 1.1rem; flex-shrink: 0; }
.toast-msg  { flex: 1; }

/* ============================================================
   حالة الفراغ (Empty State)
   ============================================================ */
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-light);
}
.empty-state-icon  { font-size: 3.5rem; margin-bottom: .75rem; }
.empty-state-title { font-size: 1.1rem; font-weight: 700; margin-bottom: .4rem; color: var(--text-medium); }
.empty-state-desc  { font-size: .88rem; }

/* ============================================================
   مؤشرات الصحة العامة
   ============================================================ */
.health-indicator {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  padding: .15rem .55rem;
  border-radius: 20px;
  font-size: .78rem;
  font-weight: 700;
}
.hi-normal  { background: var(--success-light); color: var(--success); }
.hi-warning { background: var(--warning-light); color: #856404; }
.hi-danger  { background: var(--danger-light);  color: var(--danger); }

/* ============================================================
   مساعدات (Utilities)
   ============================================================ */
.hidden    { display: none !important; }
.text-center { text-align: center; }
.text-left   { text-align: left; }
.text-right  { text-align: right; }
.text-danger  { color: var(--danger); }
.text-success { color: var(--success); }
.text-warning { color: var(--warning); }
.text-light   { color: var(--text-light); }
.text-muted   { color: var(--text-light); font-size: .85rem; }
.mt-1 { margin-top: .5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: .5rem; }
.mb-2 { margin-bottom: 1rem; }
.fw-bold { font-weight: 700; }

/* ============================================================
   إعدادات الطباعة (Print Media)
   ============================================================ */
@media print {
  body > *:not(.report-content) { display: none !important; }
  .report-content { padding: 0; margin: 0; }
  .report-toolbar, .modal-header { display: none !important; }
}

/* ============================================================
   الاستجابة للشاشات المحمولة (Mobile Responsive)
   ============================================================ */
@media (max-width: 992px) {
  .sidebar {
    transform: translateX(100%);
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .sidebar-close { display: block; }

  .app-main {
    margin-right: 0;
  }

  .btn-menu { display: block; }
  .bottom-nav { display: flex; }

  .main-content {
    padding: 1rem;
    padding-bottom: calc(var(--bottom-nav-h) + 1rem);
  }
}

@media (max-width: 576px) {
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .bristol-scale {
    grid-template-columns: repeat(4, 1fr);
  }

  .form-row {
    flex-direction: column;
  }
  .form-row > .form-group { min-width: 0; }

  .lab-param-row {
    flex-wrap: wrap;
  }
  .lab-param-name { min-width: 100%; }

  .charts-grid {
    grid-template-columns: 1fr;
  }

  .modal-overlay { padding: 0; align-items: flex-end; }
  .modal { border-radius: 14px 14px 0 0; max-height: 95vh; }
  .modal-fullscreen { border-radius: 0; max-height: 100vh; }

  .report-toolbar { flex-direction: column; }
  .report-toolbar .btn { width: 100%; }

  .auth-card { padding: 1.5rem 1.25rem; }
}

@media (max-width: 380px) {
  .stats-grid { grid-template-columns: 1fr; }
  .bristol-scale { grid-template-columns: repeat(4, 1fr); }
}

/* ============================================================
   المرحلة الخامسة — التوصيات الذكية + المساعد الصحي
   ============================================================ */
/* ============================================================
   phase5-style-additions.css
   أضف هذا الكود في نهاية ملف css/style.css الموجود
   المرحلة الخامسة: التوصيات الذكية + المساعد التفاعلي
   ============================================================ */

/* ════════════════════════════════════════════════════════════
   شاشة التوصيات الذكية
   ════════════════════════════════════════════════════════════ */

/* إخلاء مسؤولية طبي */
.medical-disclaimer {
  background: linear-gradient(135deg, #cfe2ff, #dbeafe);
  border: 1px solid #93c5fd;
  border-radius: var(--border-radius);
  padding: .85rem 1.1rem;
  font-size: .88rem;
  color: #1e40af;
  margin-bottom: 1.25rem;
  display: flex;
  align-items: flex-start;
  gap: .5rem;
}

/* شريط ملخص المؤشرات الصحية */
.health-summary-bar {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--border-radius);
  padding: 1.1rem 1.25rem;
  margin-bottom: 1.25rem;
  box-shadow: var(--shadow-sm);
}

.hs-title {
  font-size: .9rem;
  font-weight: 700;
  color: var(--text-medium);
  margin-bottom: .75rem;
}

.hs-items {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}

.health-summary-item {
  display: flex;
  align-items: center;
  gap: .6rem;
  background: var(--bg-body);
  border-radius: var(--border-radius-sm);
  padding: .5rem .85rem;
  border: 1px solid var(--border-light);
  min-width: 130px;
}

.hs-icon  { font-size: 1.4rem; }
.hs-label { font-size: .75rem; color: var(--text-light); font-weight: 500; }
.hs-value { font-size: .92rem; font-weight: 700; }

.hs-note {
  font-size: .78rem;
  color: var(--text-light);
  margin-top: .75rem;
  padding-top: .65rem;
  border-top: 1px solid var(--border-light);
}

/* شريط عدد التوصيات */
.rec-count-banner {
  background: linear-gradient(90deg, var(--primary), #0a58ca);
  color: #fff;
  border-radius: var(--border-radius);
  padding: .65rem 1.1rem;
  font-size: .9rem;
  font-weight: 600;
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: .5rem;
}

/* شبكة بطاقات التوصيات */
.rec-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 1rem;
}

/* بطاقة التوصية */
.rec-card {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-right: 4px solid var(--primary);
  border-radius: var(--border-radius);
  box-shadow: var(--shadow-sm);
  transition: box-shadow var(--transition);
  overflow: hidden;
}
.rec-card:hover { box-shadow: var(--shadow-md); }

.rec-card-header {
  display: flex;
  align-items: flex-start;
  gap: .75rem;
  padding: 1rem 1.1rem .65rem;
}

.rec-icon {
  font-size: 1.8rem;
  flex-shrink: 0;
  line-height: 1;
}

.rec-title-group {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: .3rem;
}

.rec-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-dark);
  margin: 0;
  line-height: 1.3;
}

.rec-toggle-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-light);
  font-size: 1rem;
  padding: .2rem .4rem;
  border-radius: 4px;
  transition: all var(--transition);
  flex-shrink: 0;
}
.rec-toggle-btn:hover { background: var(--bg-body); color: var(--text-dark); }

.toggle-icon {
  display: inline-block;
  transition: transform var(--transition);
}
.rec-card.expanded .toggle-icon { transform: rotate(180deg); }

.rec-description {
  font-size: .88rem;
  color: var(--text-medium);
  padding: 0 1.1rem .65rem;
  margin: 0;
  line-height: 1.55;
}

/* تفاصيل البطاقة (قابلة للطي) */
.rec-details {
  max-height: 0;
  overflow: hidden;
  transition: max-height .4s ease;
  border-top: 1px solid transparent;
}
.rec-card.expanded .rec-details {
  max-height: 1200px;
  border-top-color: var(--border-light);
  padding-top: .5rem;
}

.rec-section {
  padding: .65rem 1.1rem;
  border-bottom: 1px solid var(--border-light);
}
.rec-section:last-child { border-bottom: none; }

.rec-section-title {
  font-size: .82rem;
  font-weight: 700;
  color: var(--primary-dark);
  margin-bottom: .35rem;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.rec-section-body {
  font-size: .87rem;
  color: var(--text-medium);
  line-height: 1.6;
}

/* مصدر التوصية */
.rec-source {
  display: flex;
  align-items: center;
  gap: .4rem;
  flex-wrap: wrap;
  padding: .6rem 1.1rem;
  background: var(--bg-body);
  font-size: .78rem;
  color: var(--text-light);
}
.rec-source-icon { font-size: .9rem; }
.rec-source-label { font-weight: 600; }
.rec-source-link {
  color: var(--primary);
  text-decoration: none;
  font-weight: 500;
}
.rec-source-link:hover { text-decoration: underline; }
.rec-evidence {
  margin-right: auto;
  font-weight: 500;
  color: var(--text-medium);
}

/* قسم دعوة المساعد الذكي */
.ai-cta-section { margin-top: 1.5rem; }

.ai-cta-card {
  background: linear-gradient(135deg, #1a2332, #0d6efd22);
  border: 1px solid #0d6efd44;
  border-radius: var(--border-radius);
  padding: 1.25rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.ai-cta-icon { font-size: 2.5rem; flex-shrink: 0; }

.ai-cta-text {
  flex: 1;
  color: #e2e8f0;
}
.ai-cta-text strong { color: #fff; font-size: 1rem; display: block; margin-bottom: .25rem; }
.ai-cta-text p     { font-size: .88rem; margin: 0; opacity: .8; }

/* ════════════════════════════════════════════════════════════
   زر FAB العائم للمساعد الذكي
   ════════════════════════════════════════════════════════════ */
.ai-fab {
  position: fixed;
  bottom: calc(var(--bottom-nav-h) + 1rem);
  left: 1.25rem;            /* على اليسار (في RTL يصبح RTL-aware) */
  z-index: 1500;
  display: flex;
  align-items: center;
  gap: .5rem;
  background: linear-gradient(135deg, #0d6efd, #0a58ca);
  color: #fff;
  border: none;
  border-radius: 50px;
  padding: .7rem 1.1rem .7rem .9rem;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(13,110,253,.45);
  font-family: inherit;
  font-size: .9rem;
  font-weight: 700;
  transition: all .25s ease;
  user-select: none;
}

.ai-fab:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(13,110,253,.55);
}

.ai-fab:active { transform: scale(.96); }

.ai-fab-icon  { font-size: 1.3rem; }
.ai-fab-label { white-space: nowrap; }

/* على الشاشات الكبيرة (لا يوجد bottom nav) */
@media (min-width: 993px) {
  .ai-fab { bottom: 1.5rem; }
}

/* حالة نشاط FAB */
.ai-fab.ai-fab-active {
  background: linear-gradient(135deg, #0a58ca, #07428b);
}

/* Badge للإشعارات */
.ai-fab-badge {
  position: absolute;
  top: -.3rem;
  right: -.3rem;
  background: var(--danger);
  color: #fff;
  border-radius: 50%;
  width: 18px;
  height: 18px;
  font-size: .7rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid #fff;
  animation: pulse-badge .8s ease infinite alternate;
}

@keyframes pulse-badge {
  from { transform: scale(1); }
  to   { transform: scale(1.2); }
}

/* ════════════════════════════════════════════════════════════
   نافذة المحادثة (Chat Window)
   ════════════════════════════════════════════════════════════ */
.ai-chat-window {
  position: fixed;
  bottom: calc(var(--bottom-nav-h) + 4.5rem);
  left: 1rem;
  width: 380px;
  max-width: calc(100vw - 2rem);
  max-height: 75vh;
  background: var(--bg-card);
  border-radius: 16px;
  box-shadow: 0 8px 40px rgba(0,0,0,.2);
  border: 1px solid var(--border-light);
  z-index: 1499;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: chat-slide-in .3s cubic-bezier(.34,1.56,.64,1);
  transform-origin: bottom left;
}

@keyframes chat-slide-in {
  from { transform: scale(.7) translateY(30px); opacity: 0; }
  to   { transform: scale(1) translateY(0);     opacity: 1; }
}

@media (min-width: 993px) {
  .ai-chat-window {
    bottom: 5rem;
    width: 420px;
  }
}

/* رأس نافذة المحادثة */
.ai-chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .9rem 1rem;
  background: linear-gradient(135deg, #1a2332, #0d6efd);
  color: #fff;
  border-radius: 16px 16px 0 0;
  flex-shrink: 0;
}

.ai-chat-header-info {
  display: flex;
  align-items: center;
  gap: .65rem;
}

.ai-avatar {
  font-size: 1.5rem;
  background: rgba(255,255,255,.2);
  border-radius: 50%;
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.ai-chat-title    { font-weight: 700; font-size: .95rem; }
.ai-chat-subtitle { font-size: .75rem; opacity: .8; }

.ai-chat-actions  { display: flex; gap: .25rem; }

.ai-btn-icon {
  background: rgba(255,255,255,.15);
  border: none;
  border-radius: 6px;
  color: #fff;
  cursor: pointer;
  font-size: .9rem;
  padding: .35rem .5rem;
  transition: background var(--transition);
}
.ai-btn-icon:hover { background: rgba(255,255,255,.3); }

/* إخلاء مسؤولية */
.ai-disclaimer {
  background: #fff8e1;
  border-bottom: 1px solid #ffd54f;
  padding: .85rem 1rem;
  font-size: .82rem;
  color: #5d4037;
  display: flex;
  gap: .65rem;
  align-items: flex-start;
  flex-shrink: 0;
}

.ai-disclaimer-icon { font-size: 1.2rem; flex-shrink: 0; }
.ai-disclaimer p    { margin: 0 0 .5rem; }

/* منطقة الرسائل */
.ai-messages {
  flex: 1;
  overflow-y: auto;
  padding: .85rem;
  display: flex;
  flex-direction: column;
  gap: .75rem;
  scroll-behavior: smooth;
  min-height: 180px;
  max-height: 360px;
}

/* رسالة */
.ai-message {
  display: flex;
  align-items: flex-end;
  gap: .5rem;
}

.ai-msg-user      { flex-direction: row-reverse; }
.ai-msg-assistant { flex-direction: row; }

.ai-msg-avatar {
  font-size: 1.2rem;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-body);
  border-radius: 50%;
  flex-shrink: 0;
  border: 1px solid var(--border-light);
}

.ai-user-avatar { background: var(--primary-light); }

/* فقاعة الرسالة */
.ai-msg-bubble {
  max-width: 82%;
  border-radius: 14px;
  padding: .65rem .9rem;
  font-size: .87rem;
  line-height: 1.6;
  position: relative;
}

.ai-msg-user .ai-msg-bubble {
  background: var(--primary);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.ai-msg-assistant .ai-msg-bubble {
  background: var(--bg-body);
  color: var(--text-dark);
  border: 1px solid var(--border-light);
  border-bottom-left-radius: 4px;
}

.ai-msg-error .ai-msg-bubble {
  background: var(--danger-light);
  border-color: var(--danger);
  color: var(--danger);
}

.ai-msg-bubble p { margin: 0 0 .4rem; }
.ai-msg-bubble p:last-of-type { margin-bottom: 0; }

.ai-msg-bubble ul  { margin: .3rem 0; padding-right: 1.2rem; }
.ai-msg-bubble li  { margin-bottom: .2rem; }
.ai-msg-bubble strong { color: var(--primary-dark); }
.ai-msg-user .ai-msg-bubble strong { color: #fff; }

.ai-warning-text { color: #856404; font-weight: 600; }
.ai-msg-user .ai-warning-text { color: #fef3c7; }

.ai-msg-time {
  font-size: .68rem;
  opacity: .55;
  text-align: left;
  margin-top: .3rem;
}
.ai-msg-user .ai-msg-time { text-align: right; }

/* أسئلة سريعة */
.ai-quick-questions { margin-top: .75rem; }
.ai-qb-title        { font-size: .78rem; color: var(--text-light); margin-bottom: .4rem; }

.ai-quick-btn {
  display: inline-block;
  background: #fff;
  border: 1.5px solid var(--primary);
  border-radius: 20px;
  color: var(--primary);
  font-family: inherit;
  font-size: .78rem;
  font-weight: 600;
  padding: .3rem .75rem;
  margin: .2rem;
  cursor: pointer;
  transition: all var(--transition);
}
.ai-quick-btn:hover {
  background: var(--primary);
  color: #fff;
}

/* مؤشر الكتابة (Typing Indicator) */
.ai-typing {
  display: flex;
  align-items: flex-end;
  gap: .5rem;
  padding: 0 .85rem .5rem;
}

.ai-typing-bubble {
  background: var(--bg-body);
  border: 1px solid var(--border-light);
  border-radius: 14px 14px 14px 4px;
  padding: .6rem .9rem;
  display: flex;
  gap: .3rem;
  align-items: center;
}

.ai-typing-bubble span {
  display: block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--primary);
  animation: typing-dot 1.4s ease infinite;
}

.ai-typing-bubble span:nth-child(2) { animation-delay: .2s; }
.ai-typing-bubble span:nth-child(3) { animation-delay: .4s; }

@keyframes typing-dot {
  0%, 60%, 100% { transform: translateY(0);    opacity: .4; }
  30%            { transform: translateY(-5px); opacity: 1;  }
}

/* منطقة الإدخال */
.ai-input-area {
  padding: .75rem;
  border-top: 1px solid var(--border-light);
  background: var(--bg-card);
  flex-shrink: 0;
}

.ai-input-wrapper {
  background: var(--bg-body);
  border: 1.5px solid var(--border);
  border-radius: 12px;
  transition: border-color var(--transition);
  overflow: hidden;
}
.ai-input-wrapper:focus-within { border-color: var(--primary); }

.ai-textarea {
  width: 100%;
  border: none;
  outline: none;
  background: transparent;
  font-family: inherit;
  font-size: .88rem;
  color: var(--text-dark);
  padding: .65rem .9rem .25rem;
  resize: none;
  min-height: 44px;
  max-height: 120px;
  line-height: 1.5;
  display: block;
}

.ai-textarea::placeholder { color: var(--text-light); }

.ai-input-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .25rem .65rem .5rem;
}

.ai-char-count {
  font-size: .72rem;
  color: var(--text-light);
}

.ai-send-btn {
  background: var(--primary);
  border: none;
  border-radius: 8px;
  color: #fff;
  cursor: pointer;
  padding: .35rem .65rem;
  font-size: 1rem;
  line-height: 1;
  transition: all var(--transition);
}
.ai-send-btn:hover:not(:disabled)  { background: var(--primary-dark); transform: scale(1.05); }
.ai-send-btn:disabled { opacity: .5; cursor: not-allowed; }

/* ════════════════════════════════════════════════════════════
   تكيّف مع الشاشات الصغيرة
   ════════════════════════════════════════════════════════════ */
@media (max-width: 480px) {
  .ai-chat-window {
    left: 0;
    right: 0;
    bottom: var(--bottom-nav-h);
    width: 100%;
    max-width: 100%;
    border-radius: 16px 16px 0 0;
    max-height: 80vh;
  }

  .rec-grid { grid-template-columns: 1fr; }

  .hs-items { gap: .6rem; }
  .health-summary-item { min-width: 110px; }

  .ai-fab-label { display: none; }
  .ai-fab { padding: .75rem; border-radius: 50%; width: 52px; height: 52px; justify-content: center; }
  .ai-fab-icon { font-size: 1.5rem; }
}
