/* ============================================================
   الأساس والمكوّنات المشتركة (مريض / طبيب / لوحة التشغيل)
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0; font-family: var(--font); font-size: var(--fs-md); line-height: var(--lh); color: var(--ink-900);
  background: var(--surface-sunken); -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale;
  font-feature-settings: "tnum" 0;
}
h1, h2, h3, h4 { margin: 0; line-height: var(--lh-tight); font-weight: 700; color: var(--ink-900); }
h1 { font-size: var(--fs-3xl); } h2 { font-size: var(--fs-2xl); } h3 { font-size: var(--fs-xl); } h4 { font-size: var(--fs-lg); }
p { margin: 0; }
a { color: var(--navy-600); text-decoration: none; }
a:hover { text-decoration: underline; }
img, svg, video { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
button:disabled { cursor: not-allowed; opacity: 0.55; }
:focus-visible { outline: none; box-shadow: var(--focus-ring); border-radius: var(--radius-xs); }
::selection { background: var(--gold-200); }
.num, .tabular { font-variant-numeric: tabular-nums; }
.muted { color: var(--ink-500); }
.small { font-size: var(--fs-sm); }
.xs { font-size: var(--fs-xs); }
.strong { font-weight: 600; }
.center { text-align: center; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.ltr { direction: ltr; unicode-bidi: isolate; }
[hidden] { display: none !important; }

/* ---------- الأيقونات ---------- */
.ic { width: 20px; height: 20px; flex: none; display: inline-block; vertical-align: middle; }
.ic-sm { width: 16px; height: 16px; } .ic-lg { width: 24px; height: 24px; } .ic-xl { width: 32px; height: 32px; }

/* ---------- الأزرار ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
  min-height: var(--touch); padding: 0 var(--sp-5); border-radius: var(--radius-sm);
  font-weight: 600; font-size: var(--fs-md); line-height: 1.2; white-space: nowrap;
  border: 1.5px solid transparent; transition: background var(--t-fast) var(--ease), transform var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease), border-color var(--t-fast);
  -webkit-tap-highlight-color: transparent; user-select: none;
}
.btn:active { transform: translateY(1px) scale(0.99); }
.btn-primary { background: var(--navy-700); color: #fff; }
.btn-primary:hover { background: var(--navy-600); }
.btn-gold { background: linear-gradient(180deg, var(--gold-400), var(--gold-500)); color: var(--navy-900); box-shadow: var(--shadow-gold); }
.btn-gold:hover { background: linear-gradient(180deg, var(--gold-300), var(--gold-400)); }
.btn-outline { background: var(--surface); border-color: var(--line-strong); color: var(--ink-700); }
.btn-outline:hover { border-color: var(--navy-400); color: var(--navy-700); background: var(--navy-50); }
.btn-ghost { background: transparent; color: var(--navy-700); }
.btn-ghost:hover { background: var(--navy-50); }
.btn-soft { background: var(--navy-100); color: var(--navy-800); }
.btn-soft:hover { background: var(--navy-200); }
.btn-danger { background: var(--danger-600); color: #fff; }
.btn-danger:hover { background: var(--danger-700); }
.btn-danger-soft { background: var(--danger-50); color: var(--danger-700); border-color: var(--danger-100); }
.btn-danger-soft:hover { background: var(--danger-100); }
.btn-ok { background: var(--ok-600); color: #fff; }
.btn-ok:hover { background: var(--ok-700); }
.btn-lg { min-height: 56px; font-size: var(--fs-lg); padding: 0 var(--sp-8); border-radius: var(--radius); }
.btn-sm { min-height: 36px; font-size: var(--fs-sm); padding: 0 var(--sp-3); border-radius: var(--radius-xs); }
.btn-block { width: 100%; }
.btn-icon { width: var(--touch); padding: 0; border-radius: 50%; }
.btn-icon.btn-sm { width: 36px; }
.btn .spinner { width: 18px; height: 18px; border-width: 2px; }

/* ---------- الحقول ---------- */
.field { display: flex; flex-direction: column; gap: 6px; }
.label { font-size: var(--fs-sm); font-weight: 600; color: var(--ink-700); display: flex; align-items: center; gap: 6px; }
.label .req { color: var(--danger-600); }
.input, .select, .textarea {
  width: 100%; min-height: 50px; padding: 0 var(--sp-4); border-radius: var(--radius-sm);
  border: 1.5px solid var(--line-strong); background: var(--surface); color: var(--ink-900); font-size: 16px;
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.input::placeholder, .textarea::placeholder { color: var(--ink-300); }
.input:focus, .select:focus, .textarea:focus { border-color: var(--navy-500); box-shadow: 0 0 0 4px var(--navy-100); outline: none; }
.input.is-error, .textarea.is-error { border-color: var(--danger-600); box-shadow: 0 0 0 4px var(--danger-100); }
.textarea { min-height: 96px; padding: var(--sp-3) var(--sp-4); resize: vertical; line-height: 1.55; }
.select { appearance: none; padding-inline-end: 40px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2355657A' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: left 12px center; background-size: 18px; }
[dir="ltr"] .select { background-position: right 12px center; }
.help { font-size: var(--fs-xs); color: var(--ink-500); }
.error-text { font-size: var(--fs-xs); color: var(--danger-700); font-weight: 500; }
.input-wrap { position: relative; }
.input-wrap .ic { position: absolute; top: 50%; transform: translateY(-50%); inset-inline-start: 14px; color: var(--ink-300); pointer-events: none; }
.input-wrap .input { padding-inline-start: 44px; }
.checkbox { display: flex; align-items: flex-start; gap: var(--sp-3); cursor: pointer; font-size: var(--fs-sm); color: var(--ink-700); }
.checkbox input { width: 20px; height: 20px; margin: 2px 0 0; accent-color: var(--navy-700); flex: none; }

/* ---------- الشرائح والمجموعات ---------- */
.chips { display: flex; flex-wrap: wrap; gap: var(--sp-2); }
.chip {
  display: inline-flex; align-items: center; gap: 6px; min-height: 40px; padding: 0 var(--sp-4);
  border-radius: 999px; border: 1.5px solid var(--line-strong); background: var(--surface); color: var(--ink-700);
  font-size: var(--fs-sm); font-weight: 500; transition: all var(--t-fast) var(--ease); -webkit-tap-highlight-color: transparent;
}
.chip:hover { border-color: var(--navy-400); }
.chip.on { background: var(--navy-800); border-color: var(--navy-800); color: #fff; }
.chip.on-gold { background: var(--gold-100); border-color: var(--gold-500); color: var(--gold-700); }
.chip .ic { width: 16px; height: 16px; }
.chip-sm { min-height: 30px; padding: 0 var(--sp-3); font-size: var(--fs-xs); }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; padding: 4px; border-radius: var(--radius-sm); background: var(--surface-sunken); border: 1px solid var(--line-soft); }
.seg button { min-height: 42px; border-radius: 8px; font-weight: 600; font-size: var(--fs-sm); color: var(--ink-500); transition: all var(--t-fast); }
.seg button.on { background: var(--surface); color: var(--navy-800); box-shadow: var(--shadow-sm); }

/* ---------- البطاقات ---------- */
.card { background: var(--surface); border: 1px solid var(--line-soft); border-radius: var(--radius); box-shadow: var(--shadow-sm); }
.card-pad { padding: var(--sp-5); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); margin-bottom: var(--sp-4); }
.card-head h3 { display: flex; align-items: center; gap: var(--sp-2); font-size: var(--fs-lg); }
.card-head h3 .ic { color: var(--navy-500); }

/* ---------- الشارات ---------- */
.badge { display: inline-flex; align-items: center; gap: 5px; min-height: 24px; padding: 0 10px; border-radius: 999px; font-size: var(--fs-xs); font-weight: 600; white-space: nowrap; }
.badge .ic { width: 13px; height: 13px; }
.badge-navy { background: var(--navy-100); color: var(--navy-800); }
.badge-gold { background: var(--gold-100); color: var(--gold-700); }
.badge-ok { background: var(--ok-100); color: var(--ok-700); }
.badge-warn { background: var(--warn-100); color: var(--warn-800); }
.badge-danger { background: var(--danger-100); color: var(--danger-700); }
.badge-info { background: var(--info-100); color: var(--info-700); }
.badge-muted { background: var(--surface-sunken); color: var(--ink-500); }
.badge-dot::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.dot-live { width: 9px; height: 9px; border-radius: 50%; background: var(--ok-600); box-shadow: 0 0 0 0 rgba(30, 142, 90, 0.5); animation: pulse-dot 1.8s infinite; display: inline-block; }
@keyframes pulse-dot { 0% { box-shadow: 0 0 0 0 rgba(30, 142, 90, 0.5); } 70% { box-shadow: 0 0 0 8px rgba(30, 142, 90, 0); } 100% { box-shadow: 0 0 0 0 rgba(30, 142, 90, 0); } }

/* ---------- الصور الرمزية ---------- */
.avatar { width: 40px; height: 40px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; background: var(--navy-100); color: var(--navy-800); font-weight: 700; font-size: var(--fs-md); flex: none; overflow: hidden; }
.avatar-lg { width: 64px; height: 64px; font-size: var(--fs-2xl); }
.avatar-gold { background: var(--gold-100); color: var(--gold-700); }

/* ---------- الدوران والتحميل ---------- */
.spinner { width: 28px; height: 28px; border: 3px solid rgba(11, 46, 92, 0.15); border-top-color: var(--navy-600); border-radius: 50%; animation: spin 0.8s linear infinite; }
.spinner-light { border-color: rgba(255, 255, 255, 0.25); border-top-color: #fff; }
@keyframes spin { to { transform: rotate(360deg); } }
.skeleton { background: linear-gradient(90deg, var(--surface-sunken) 25%, var(--line-soft) 50%, var(--surface-sunken) 75%); background-size: 200% 100%; animation: shimmer 1.4s infinite; border-radius: var(--radius-xs); }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ---------- التنبيهات العائمة ---------- */
.toasts { position: fixed; inset-inline: 0; bottom: calc(var(--safe-bottom) + 16px); display: flex; flex-direction: column; align-items: center; gap: 8px; z-index: 1000; pointer-events: none; padding: 0 16px; }
.toast { pointer-events: auto; display: flex; align-items: center; gap: 10px; max-width: 520px; width: 100%; padding: 12px 16px; border-radius: var(--radius-sm); background: var(--ink-900); color: #fff; font-size: var(--fs-sm); font-weight: 500; box-shadow: var(--shadow-lg); animation: toast-in var(--t-med) var(--ease-spring); }
.toast .ic { flex: none; }
.toast-ok { background: var(--ok-700); } .toast-danger { background: var(--danger-700); } .toast-warn { background: var(--warn-800); } .toast-navy { background: var(--navy-800); }
.toast button { margin-inline-start: auto; color: var(--gold-300); font-weight: 700; }
@keyframes toast-in { from { opacity: 0; transform: translateY(12px) scale(0.98); } to { opacity: 1; transform: none; } }

/* ---------- النوافذ ---------- */
.overlay { position: fixed; inset: 0; background: rgba(7, 30, 61, 0.55); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); z-index: 900; display: flex; align-items: center; justify-content: center; padding: 16px; animation: fade-in var(--t-fast); }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
.modal { background: var(--surface); border-radius: var(--radius-lg); width: 100%; max-width: 520px; max-height: min(88vh, 88dvh); display: flex; flex-direction: column; box-shadow: var(--shadow-lg); animation: modal-in var(--t-med) var(--ease-spring); overflow: hidden; }
.modal-lg { max-width: 860px; }
@keyframes modal-in { from { opacity: 0; transform: translateY(16px) scale(0.98); } to { opacity: 1; transform: none; } }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 18px 22px 12px; }
.modal-head h3 { font-size: var(--fs-xl); }
.modal-body { padding: 4px 22px 18px; overflow: auto; }
.modal-foot { display: flex; gap: 10px; justify-content: flex-end; padding: 12px 22px 18px; border-top: 1px solid var(--line-soft); flex-wrap: wrap; }
.modal-foot .btn { min-width: 110px; }
.modal-close { width: 38px; height: 38px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; color: var(--ink-500); }
.modal-close:hover { background: var(--surface-sunken); color: var(--ink-900); }

/* ---------- الورقة السفلية (جوال) ---------- */
.sheet-overlay { align-items: flex-end; padding: 0; }
.sheet { background: var(--surface); width: 100%; max-width: 560px; border-radius: var(--radius-xl) var(--radius-xl) 0 0; max-height: min(92vh, 92dvh); display: flex; flex-direction: column; box-shadow: var(--shadow-lg); animation: sheet-in var(--t-slow) var(--ease-spring); padding-bottom: var(--safe-bottom); }
@keyframes sheet-in { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
.sheet-grip { width: 44px; height: 5px; border-radius: 3px; background: var(--line-strong); margin: 10px auto 4px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 8px 20px 10px; }
.sheet-head h3 { font-size: var(--fs-xl); }
.sheet-body { padding: 4px 20px 20px; overflow: auto; -webkit-overflow-scrolling: touch; }

/* ---------- التبويبات ---------- */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab { position: relative; display: inline-flex; align-items: center; gap: 6px; min-height: 46px; padding: 0 14px; font-weight: 600; font-size: var(--fs-sm); color: var(--ink-500); white-space: nowrap; border-bottom: 2.5px solid transparent; margin-bottom: -1px; }
.tab .ic { width: 17px; height: 17px; }
.tab:hover { color: var(--navy-700); }
.tab.on { color: var(--navy-800); border-bottom-color: var(--gold-500); }
.tab .count { min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; background: var(--danger-600); color: #fff; font-size: 11px; display: inline-flex; align-items: center; justify-content: center; font-weight: 700; }

/* ---------- المفاتيح ---------- */
.switch { position: relative; width: 46px; height: 26px; border-radius: 13px; background: var(--line-strong); transition: background var(--t-fast); flex: none; }
.switch::after { content: ""; position: absolute; top: 3px; inset-inline-start: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25); transition: transform var(--t-fast) var(--ease); }
.switch.on { background: var(--ok-600); }
[dir="rtl"] .switch.on::after { transform: translateX(-20px); }
[dir="ltr"] .switch.on::after { transform: translateX(20px); }

/* ---------- النجوم ---------- */
.stars { display: inline-flex; gap: 6px; direction: ltr; }
.stars button { width: 44px; height: 44px; color: var(--line-strong); transition: transform var(--t-fast) var(--ease-spring), color var(--t-fast); }
.stars button .ic { width: 36px; height: 36px; }
.stars button.on { color: var(--gold-500); }
.stars button:hover { transform: scale(1.12); }
.stars-static button { width: 20px; height: 20px; cursor: default; }
.stars-static button .ic { width: 18px; height: 18px; }

/* ---------- الفارغ ---------- */
.empty { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; padding: 40px 20px; text-align: center; color: var(--ink-500); }
.empty .ic { width: 44px; height: 44px; color: var(--line-strong); }
.empty h4 { color: var(--ink-700); }

/* ---------- عارض الصور ---------- */
.lightbox { position: fixed; inset: 0; background: rgba(4, 14, 30, 0.94); z-index: 1100; display: flex; align-items: center; justify-content: center; flex-direction: column; gap: 12px; padding: 20px; animation: fade-in var(--t-fast); }
.lightbox img { max-width: 100%; max-height: 82vh; border-radius: var(--radius-sm); object-fit: contain; box-shadow: var(--shadow-lg); }
.lightbox .cap { color: #fff; font-size: var(--fs-sm); opacity: 0.85; text-align: center; }
.lightbox .lb-close { position: absolute; top: calc(var(--safe-top) + 14px); inset-inline-end: 14px; width: 44px; height: 44px; border-radius: 50%; background: rgba(255, 255, 255, 0.12); color: #fff; display: inline-flex; align-items: center; justify-content: center; }
.lightbox .lb-actions { display: flex; gap: 10px; }
.lightbox .lb-actions .btn { background: rgba(255, 255, 255, 0.12); color: #fff; border-color: transparent; }

/* ---------- المحادثة (مشتركة) ---------- */
.chat { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.chat-list { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 8px; -webkit-overflow-scrolling: touch; }
.msg { display: flex; flex-direction: column; max-width: 82%; gap: 3px; }
.msg-me { align-self: flex-start; align-items: flex-start; }
.msg-them { align-self: flex-end; align-items: flex-end; }
[dir="rtl"] .msg-me { align-self: flex-end; align-items: flex-end; }
[dir="rtl"] .msg-them { align-self: flex-start; align-items: flex-start; }
.msg-bubble { padding: 10px 14px; border-radius: 18px; font-size: var(--fs-md); line-height: 1.5; word-break: break-word; white-space: pre-wrap; }
.msg-me .msg-bubble { background: var(--navy-700); color: #fff; border-end-end-radius: 6px; }
.msg-them .msg-bubble { background: var(--surface); color: var(--ink-900); border: 1px solid var(--line-soft); border-end-start-radius: 6px; box-shadow: var(--shadow-sm); }
.msg-time { font-size: 11px; color: var(--ink-300); padding: 0 6px; }
.msg-img { max-width: 240px; border-radius: 14px; overflow: hidden; border: 1px solid var(--line-soft); cursor: zoom-in; }
.msg-img img { width: 100%; height: auto; display: block; }
.msg-file { display: inline-flex; align-items: center; gap: 8px; padding: 10px 14px; border-radius: 14px; background: var(--surface); border: 1px solid var(--line); color: var(--navy-700); font-size: var(--fs-sm); font-weight: 600; }
.msg-system { align-self: center; font-size: var(--fs-xs); color: var(--ink-500); background: var(--surface-sunken); padding: 4px 12px; border-radius: 999px; margin: 4px 0; }
.chat-compose { display: flex; align-items: flex-end; gap: 8px; padding: 10px 12px calc(10px + var(--safe-bottom)); border-top: 1px solid var(--line-soft); background: var(--surface); }
.chat-compose textarea { flex: 1; min-height: 44px; max-height: 120px; padding: 10px 14px; border-radius: 22px; border: 1.5px solid var(--line-strong); resize: none; font-size: 16px; line-height: 1.4; background: var(--surface-sunken); }
.chat-compose textarea:focus { border-color: var(--navy-500); outline: none; background: #fff; }
.chat-compose .btn-icon { width: 44px; height: 44px; min-height: 44px; }
.typing { font-size: var(--fs-xs); color: var(--ink-500); padding: 0 16px 6px; min-height: 18px; }
.typing i { display: inline-block; width: 5px; height: 5px; border-radius: 50%; background: var(--ink-300); margin-inline-end: 3px; animation: typing 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: 0.2s; } .typing i:nth-child(3) { animation-delay: 0.4s; }
@keyframes typing { 0%, 60%, 100% { transform: translateY(0); } 30% { transform: translateY(-4px); } }

/* ---------- شريط التمرير ---------- */
* { scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent; }
*::-webkit-scrollbar { width: 8px; height: 8px; }
*::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 4px; }
*::-webkit-scrollbar-track { background: transparent; }

/* ---------- الطباعة ---------- */
@media print {
  body { background: #fff; }
  .no-print { display: none !important; }
}
