/* ─────────────────────────────────────────────────────────────────────────────
   نَسَق — نظام التصميم
   الخط: IBM Plex Sans Arabic للواجهة، Markazi Text للهوية والعناوين، IBM Plex Mono للأرقام.
   اللون: فيريديان عميق (الهوية) + زعفران (الانتباه) + مرجان (الخطر) على ورق أخضر باهت.
   ───────────────────────────────────────────────────────────────────────────── */
:root {
  --ground: #F4F6F2;
  --surface: #FFFFFF;
  --surface-2: #EBEFEA;
  --surface-3: #E1E7E1;
  --ink: #13211C;
  --ink-2: #4D5C56;
  --ink-3: #7C8983;
  --line: #D8DFDA;
  --line-strong: #BFC9C2;
  --primary: #1F5C4A;
  --primary-deep: #143F33;
  --primary-soft: #DCEBE4;
  --primary-ink: #0F2F26;
  --accent: #C98F05;
  --accent-soft: #FBF0D2;
  --accent-ink: #6E4E00;
  --danger: #C2412F;
  --danger-soft: #F9E1DC;
  --danger-ink: #6E2118;
  --ok: #2E7D5B;
  --ok-soft: #DCEFE4;
  --info: #2F6C9B;
  --info-soft: #DCE9F4;
  --shadow: 0 1px 2px rgba(19, 33, 28, .06), 0 6px 20px rgba(19, 33, 28, .06);
  --shadow-lg: 0 10px 40px rgba(19, 33, 28, .16);
  --radius: 14px;
  --radius-sm: 9px;
  --sidebar-w: 264px;
  --nav-h: 62px;
  --font-ui: 'IBM Plex Sans Arabic', 'Segoe UI', Tahoma, Arial, sans-serif;
  --font-display: 'Markazi Text', 'IBM Plex Sans Arabic', serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --ground: #0E1614;
    --surface: #16211E;
    --surface-2: #1C2925;
    --surface-3: #24332E;
    --ink: #E7EEEA;
    --ink-2: #A6B5AE;
    --ink-3: #7B8A83;
    --line: #2A3A34;
    --line-strong: #3B4E47;
    --primary: #4FA98C;
    --primary-deep: #2F7C64;
    --primary-soft: #16332A;
    --primary-ink: #BFE4D6;
    --accent: #F2B72B;
    --accent-soft: #3A2D0A;
    --accent-ink: #FFE29A;
    --danger: #F0705F;
    --danger-soft: #3F1A15;
    --danger-ink: #FFC9C0;
    --ok: #5CC495;
    --ok-soft: #14332A;
    --info: #6FAEDD;
    --info-soft: #14283A;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 6px 20px rgba(0, 0, 0, .35);
    --shadow-lg: 0 10px 40px rgba(0, 0, 0, .6);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  margin: 0; font-family: var(--font-ui); font-size: 15px; line-height: 1.6;
  background: var(--ground); color: var(--ink);
  -webkit-tap-highlight-color: transparent; overscroll-behavior-y: none;
  font-feature-settings: 'tnum' 1;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
[hidden] { display: none !important; }
h1, h2, h3, h4 { margin: 0; line-height: 1.25; font-weight: 600; }
p { margin: 0 0 .6em; }
img { max-width: 100%; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
::selection { background: var(--primary-soft); }

.muted { color: var(--ink-2); }
.faint { color: var(--ink-3); }
.small { font-size: 13px; }
.tiny { font-size: 12px; }
.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.display { font-family: var(--font-display); font-weight: 600; }
.center { text-align: center; }
.row { display: flex; gap: 10px; align-items: center; }
.row.between { justify-content: space-between; }
.row.end { justify-content: flex-end; }
.row.top { align-items: flex-start; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.mt { margin-top: 12px; }
.mt-lg { margin-top: 22px; }
.mb { margin-bottom: 12px; }
.nowrap { white-space: nowrap; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ltr { direction: ltr; unicode-bidi: isolate; }
.num { font-family: var(--font-mono); font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: isolate; }
.grid { display: grid; gap: 14px; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.grid.three { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.grid.stats { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }

/* ── الأزرار ─────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 9px 15px; border-radius: var(--radius-sm); font-weight: 600; font-size: 14px; line-height: 1.2;
  background: var(--surface); color: var(--ink); border: 1px solid var(--line-strong); min-height: 40px;
  transition: transform .05s ease, background .15s ease, border-color .15s;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--primary); color: #fff; border-color: transparent; }
.btn.primary:hover { background: var(--primary-deep); }
.btn.accent { background: var(--accent); color: #1c1400; border-color: transparent; }
.btn.danger { background: var(--danger-soft); color: var(--danger-ink); border-color: transparent; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--primary); }
.btn.ghost:hover { background: var(--primary-soft); }
.btn.block { width: 100%; }
.btn.sm { padding: 5px 10px; min-height: 32px; font-size: 13px; }
.btn.xs { padding: 3px 8px; min-height: 26px; font-size: 12px; border-radius: 7px; }
.btn.icon { padding: 6px; min-width: 36px; }
.btn:disabled { opacity: .5; cursor: default; transform: none; }
.btn .spin { width: 14px; height: 14px; border: 2px solid currentColor; border-inline-end-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── الحقول ──────────────────────────────────────────────────────────────── */
label.field { display: block; font-size: 13px; color: var(--ink-2); font-weight: 500; }
label.field > span { display: block; margin-bottom: 4px; }
.input, input[type=text], input[type=password], input[type=number], input[type=date], input[type=datetime-local], input[type=time], input[type=search], select, textarea {
  width: 100%; padding: 9px 12px; border-radius: var(--radius-sm); border: 1px solid var(--line-strong);
  background: var(--surface); color: var(--ink); font-size: 15px; min-height: 40px;
}
input[type=number], input[type=date], input[type=datetime-local], input[type=time] { direction: ltr; text-align: right; font-family: var(--font-mono); }
textarea { min-height: 88px; resize: vertical; line-height: 1.5; }
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); outline: none; }
input::placeholder, textarea::placeholder { color: var(--ink-3); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; }
.form-grid .span-2 { grid-column: span 2; }
.form-grid .span-all { grid-column: 1 / -1; }
.check { display: inline-flex; align-items: center; gap: 8px; padding: 6px 10px; border: 1px solid var(--line); border-radius: 999px; font-size: 13px; cursor: pointer; background: var(--surface); user-select: none; }
.check input { width: 16px; height: 16px; min-height: 0; margin: 0; accent-color: var(--primary); }
.check:has(input:checked) { background: var(--primary-soft); border-color: var(--primary); color: var(--primary-ink); }
.check.danger:has(input:checked) { background: var(--danger-soft); border-color: var(--danger); color: var(--danger-ink); }
.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
.switch input { appearance: none; width: 40px; height: 22px; border-radius: 999px; background: var(--line-strong); position: relative; margin: 0; min-height: 0; transition: background .15s; }
.switch input::after { content: ''; position: absolute; top: 3px; right: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .15s; }
.switch input:checked { background: var(--primary); }
.switch input:checked::after { transform: translateX(-18px); }
.error { color: var(--danger-ink); background: var(--danger-soft); padding: 8px 12px; border-radius: var(--radius-sm); font-size: 14px; }
.hint { font-size: 12px; color: var(--ink-3); margin-top: 4px; }
.seg { display: inline-flex; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); overflow: hidden; background: var(--surface); }
.seg button { padding: 7px 12px; font-size: 13px; font-weight: 600; color: var(--ink-2); border-inline-start: 1px solid var(--line); }
.seg button:first-child { border-inline-start: 0; }
.seg button.on { background: var(--primary); color: #fff; }

/* ── تسجيل الدخول ────────────────────────────────────────────────────────── */
.login { min-height: 100dvh; display: grid; grid-template-columns: 1.1fr 1fr; background: var(--ground); }
.login-art { position: relative; overflow: hidden; background: linear-gradient(160deg, #143F33, #1F5C4A 55%, #2C7A63); color: #E9F2EE; padding: 48px; display: flex; flex-direction: column; justify-content: space-between; }
.login-art svg.weave-bg { position: absolute; inset: 0; width: 100%; height: 100%; opacity: .55; }
.login-art .brand-mark { position: relative; display: flex; align-items: center; gap: 14px; }
.login-art .brand-mark img { width: 56px; height: 56px; border-radius: 16px; box-shadow: 0 6px 24px rgba(0,0,0,.25); }
.login-art .wordmark { font-family: var(--font-display); font-size: 44px; line-height: 1; font-weight: 700; letter-spacing: -.5px; }
.login-art .wordmark small { display: block; font-family: var(--font-ui); font-size: 13px; font-weight: 500; letter-spacing: .4px; opacity: .8; margin-top: 6px; }
.login-art .tagline { position: relative; font-family: var(--font-display); font-size: 40px; line-height: 1.2; max-width: 14em; }
.login-art .tagline em { font-style: normal; color: #F2B72B; }
.login-art .foot { position: relative; font-size: 13px; opacity: .75; }
.login-form-wrap { display: grid; place-items: center; padding: 32px 20px; }
.login-card { width: min(400px, 100%); background: var(--surface); border-radius: 22px; padding: 30px 28px; box-shadow: var(--shadow); border: 1px solid var(--line); }
.login-card h1 { font-family: var(--font-display); font-size: 32px; font-weight: 600; margin-bottom: 4px; }
.login-card label.field { margin-top: 14px; }
.login-card .btn { margin-top: 20px; }
@media (max-width: 860px) {
  .login { grid-template-columns: 1fr; }
  .login-art { min-height: 220px; padding: 26px 22px; }
  .login-art .tagline { font-size: 28px; margin-top: 18px; }
  .login-art .foot { display: none; }
}

/* ── الهيكل ──────────────────────────────────────────────────────────────── */
.app { min-height: 100dvh; display: grid; grid-template-columns: var(--sidebar-w) 1fr; }
.sidebar {
  position: sticky; top: 0; height: 100dvh; overflow-y: auto; background: var(--surface); border-inline-end: 1px solid var(--line);
  display: flex; flex-direction: column; padding: 18px 14px; gap: 14px;
}
.sidebar .brand { display: flex; align-items: center; gap: 10px; padding: 4px 6px; }
.sidebar .brand img { width: 40px; height: 40px; border-radius: 12px; }
.sidebar .brand .wordmark { font-family: var(--font-display); font-size: 28px; line-height: 1; font-weight: 700; color: var(--primary-ink); }
.sidebar .brand small { display: block; font-size: 11px; color: var(--ink-3); font-family: var(--font-ui); letter-spacing: .3px; margin-top: 3px; }
.patient-switch { border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; background: var(--surface-2); display: flex; gap: 10px; align-items: center; cursor: pointer; text-align: start; width: 100%; }
.patient-switch .avatar { flex: none; }
.patient-switch .name { font-weight: 600; line-height: 1.2; }
.patient-switch .sub { font-size: 12px; color: var(--ink-2); }
.avatar { width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center; color: #fff; font-weight: 700; font-family: var(--font-display); font-size: 20px; background: var(--primary); }
.avatar.lg { width: 56px; height: 56px; font-size: 28px; border-radius: 16px; }
.nav-group { display: flex; flex-direction: column; gap: 2px; }
.nav-group .label { font-size: 11px; font-weight: 600; letter-spacing: .4px; color: var(--ink-3); padding: 8px 10px 4px; text-transform: uppercase; }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 10px; color: var(--ink-2); font-weight: 500; font-size: 14px; position: relative; }
.nav-item:hover { background: var(--surface-2); text-decoration: none; color: var(--ink); }
.nav-item.on { background: var(--primary-soft); color: var(--primary-ink); font-weight: 600; }
.nav-item .ic { width: 20px; height: 20px; flex: none; display: grid; place-items: center; }
.nav-item .ic svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.nav-item .count { margin-inline-start: auto; font-size: 11px; font-weight: 700; background: var(--danger); color: #fff; border-radius: 999px; padding: 1px 7px; font-family: var(--font-mono); }
.nav-item .count.warn { background: var(--accent); color: #1c1400; }
.sidebar .me { margin-top: auto; border-top: 1px solid var(--line); padding-top: 12px; display: flex; align-items: center; gap: 10px; font-size: 13px; }
.sidebar .me .who { flex: 1; min-width: 0; }
.sidebar .me .who b { display: block; font-size: 14px; }

.main { min-width: 0; padding: 22px 28px 60px; max-width: 1280px; width: 100%; margin: 0 auto; }
.topbar { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.topbar h1 { font-family: var(--font-display); font-size: 30px; font-weight: 600; }
.topbar .crumb { font-size: 13px; color: var(--ink-3); }
.topbar .actions { margin-inline-start: auto; display: flex; gap: 8px; flex-wrap: wrap; }
.conn { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 3px var(--ok-soft); }
.conn.off { background: var(--danger); box-shadow: 0 0 0 3px var(--danger-soft); }

.mobile-nav { display: none; }
@media (max-width: 960px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .main { padding: 14px 14px calc(var(--nav-h) + 20px); }
  .topbar h1 { font-size: 24px; }
  .mobile-top { display: flex; align-items: center; gap: 10px; padding: 10px 14px; background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
  .mobile-top img { width: 32px; height: 32px; border-radius: 9px; }
  .mobile-top .wordmark { font-family: var(--font-display); font-size: 24px; font-weight: 700; color: var(--primary-ink); line-height: 1; }
  .mobile-top .patient-switch { flex: 1; padding: 6px 10px; }
  .mobile-top .patient-switch .avatar { width: 30px; height: 30px; font-size: 16px; border-radius: 9px; }
  .mobile-nav {
    display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; bottom: 0; inset-inline: 0; height: calc(var(--nav-h) + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom); background: var(--surface); border-top: 1px solid var(--line); z-index: 30;
  }
  .mobile-nav a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; font-size: 11px; color: var(--ink-2); font-weight: 500; position: relative; }
  .mobile-nav a.on { color: var(--primary); font-weight: 700; }
  .mobile-nav a svg { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
  .mobile-nav .count { position: absolute; top: 6px; inset-inline-end: calc(50% - 20px); font-size: 10px; font-weight: 700; background: var(--danger); color: #fff; border-radius: 999px; padding: 0 5px; font-family: var(--font-mono); }
}
@media (min-width: 961px) { .mobile-top { display: none; } }

/* ── الكروت ──────────────────────────────────────────────────────────────── */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); }
.card.flat { box-shadow: none; }
.card.tight { padding: 12px 14px; }
.card > h2, .card > .head h2 { font-size: 17px; font-weight: 600; }
.card .head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.card .head .actions { margin-inline-start: auto; display: flex; gap: 6px; }
.card.accent-top { border-top: 3px solid var(--primary); }
.stat { padding: 12px 14px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line); }
.stat .k { font-size: 12px; color: var(--ink-2); font-weight: 500; }
.stat .v { font-family: var(--font-mono); font-size: 24px; font-weight: 500; line-height: 1.2; margin-top: 2px; direction: ltr; text-align: right; }
.stat .v small { font-family: var(--font-ui); font-size: 12px; color: var(--ink-3); font-weight: 500; margin-inline-start: 4px; }
.stat .d { font-size: 12px; color: var(--ink-3); margin-top: 2px; }
.stat.H .v, .stat.HH .v { color: var(--danger); }
.stat.L .v, .stat.LL .v { color: var(--info); }
.stat.HH, .stat.LL { border-color: var(--danger); }
.empty { text-align: center; padding: 34px 16px; color: var(--ink-2); }
.empty .big { font-size: 40px; line-height: 1; margin-bottom: 8px; opacity: .6; }
.empty p { max-width: 36em; margin: 0 auto 10px; }
.skeleton { background: linear-gradient(90deg, var(--surface-2), var(--surface-3), var(--surface-2)); background-size: 200% 100%; animation: shimmer 1.2s infinite; border-radius: 8px; min-height: 14px; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ── الشارات ─────────────────────────────────────────────────────────────── */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; line-height: 1.5; background: var(--surface-2); color: var(--ink-2); white-space: nowrap; }
.badge.critical { background: var(--danger-soft); color: var(--danger-ink); }
.badge.warning { background: var(--accent-soft); color: var(--accent-ink); }
.badge.info { background: var(--info-soft); color: var(--info); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.primary { background: var(--primary-soft); color: var(--primary-ink); }
.badge.mono { font-family: var(--font-mono); }
.flag { display: inline-block; min-width: 22px; text-align: center; padding: 0 6px; border-radius: 6px; font-family: var(--font-mono); font-size: 12px; font-weight: 600; }
.flag.H, .flag.HH { background: var(--danger-soft); color: var(--danger-ink); }
.flag.L, .flag.LL { background: var(--info-soft); color: var(--info); }
.flag.HH, .flag.LL { outline: 1.5px solid var(--danger); }
.flag.N { background: var(--ok-soft); color: var(--ok); }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: none; }
.dot.critical { background: var(--danger); }
.dot.warning { background: var(--accent); }
.dot.info { background: var(--info); }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); font-size: 13px; }
.chip.on { background: var(--primary-soft); border-color: var(--primary); color: var(--primary-ink); font-weight: 600; }

/* ── الجداول ─────────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: var(--radius-sm); }
table.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th { text-align: start; font-size: 12px; font-weight: 600; color: var(--ink-2); padding: 8px 10px; border-bottom: 1px solid var(--line-strong); white-space: nowrap; background: var(--surface); position: sticky; top: 0; }
.tbl td { padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl tr:hover td { background: var(--surface-2); }
.tbl td.num, .tbl th.num { font-family: var(--font-mono); direction: ltr; text-align: right; white-space: nowrap; }
.tbl .actions { white-space: nowrap; text-align: end; }
.tbl tr.clickable { cursor: pointer; }
.tbl tr.dim td { color: var(--ink-3); }

/* ── القوائم ─────────────────────────────────────────────────────────────── */
.list { display: flex; flex-direction: column; }
.list-item { display: flex; gap: 12px; align-items: flex-start; padding: 12px 4px; border-bottom: 1px solid var(--line); }
.list-item:last-child { border-bottom: 0; }
.list-item.clickable { cursor: pointer; border-radius: 10px; }
.list-item.clickable:hover { background: var(--surface-2); }
.list-item .ic { width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center; background: var(--surface-2); flex: none; font-size: 18px; }
.list-item .body { flex: 1; min-width: 0; }
.list-item .title { font-weight: 600; }
.list-item .sub { font-size: 13px; color: var(--ink-2); }
.list-item .side { text-align: end; font-size: 12px; color: var(--ink-3); white-space: nowrap; }

/* ── التنبيهات ───────────────────────────────────────────────────────────── */
.alert-item { border-inline-start: 4px solid var(--info); background: var(--surface); border-radius: var(--radius-sm); padding: 10px 14px; display: flex; gap: 12px; align-items: flex-start; border: 1px solid var(--line); border-inline-start-width: 4px; }
.alert-item.critical { border-inline-start-color: var(--danger); background: color-mix(in srgb, var(--danger-soft) 45%, var(--surface)); }
.alert-item.warning { border-inline-start-color: var(--accent); background: color-mix(in srgb, var(--accent-soft) 45%, var(--surface)); }
.alert-item.acknowledged { opacity: .75; }
.alert-item.resolved { opacity: .55; border-inline-start-color: var(--line-strong); }
.alert-item .title { font-weight: 600; }
.alert-item .body { font-size: 13px; color: var(--ink-2); margin-top: 2px; }
.alert-item .meta { font-size: 12px; color: var(--ink-3); margin-top: 4px; }
.banner { padding: 10px 16px; border-radius: var(--radius-sm); font-size: 14px; display: flex; gap: 10px; align-items: center; }
.banner.warning { background: var(--accent-soft); color: var(--accent-ink); }
.banner.danger { background: var(--danger-soft); color: var(--danger-ink); }
.banner.info { background: var(--info-soft); color: var(--info); }

/* ── الرأس المتشابك (نَسَق) ──────────────────────────────────────────────── */
.weave-card { position: relative; overflow: hidden; border-radius: var(--radius); background: linear-gradient(135deg, var(--primary-deep), var(--primary) 70%, #2C7A63); color: #E9F2EE; border: 0; padding: 18px 20px 12px; box-shadow: var(--shadow); }
.weave-card .who { display: flex; align-items: center; gap: 14px; position: relative; z-index: 1; }
.weave-card .who .avatar { background: rgba(255,255,255,.14); border: 1px solid rgba(255,255,255,.25); }
.weave-card h1 { font-family: var(--font-display); font-size: 34px; font-weight: 600; line-height: 1.1; color: #fff; }
.weave-card .sub { font-size: 13px; opacity: .85; margin-top: 2px; }
.weave-card .weave { display: block; width: 100%; height: 150px; margin-top: 10px; position: relative; z-index: 1; }
.weave-card .legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 12px; opacity: .92; position: relative; z-index: 1; }
.weave-card .legend i { display: inline-block; width: 14px; height: 3px; border-radius: 2px; vertical-align: middle; margin-inline-end: 5px; }
.weave-card .legend b { font-family: var(--font-mono); font-weight: 500; }
.weave-card .ghost { position: absolute; inset: auto -40px -60px auto; width: 380px; height: 380px; border-radius: 50%; background: radial-gradient(circle, rgba(242,183,43,.18), transparent 60%); z-index: 0; }
.weave-card .empty-weave { padding: 24px 0 14px; font-size: 14px; opacity: .85; position: relative; z-index: 1; }

/* ── Markdown ────────────────────────────────────────────────────────────── */
.md { line-height: 1.8; font-size: 15px; }
.md h1 { font-family: var(--font-display); font-size: 30px; font-weight: 600; margin: 22px 0 10px; }
.md h2 { font-family: var(--font-display); font-size: 25px; font-weight: 600; margin: 26px 0 8px; padding-bottom: 6px; border-bottom: 1px solid var(--line); color: var(--primary-ink); }
.md h3 { font-size: 18px; margin: 20px 0 6px; }
.md h4 { font-size: 16px; margin: 14px 0 4px; color: var(--ink-2); }
.md p { margin: 0 0 .8em; }
.md ul, .md ol { padding-inline-start: 1.4em; margin: 0 0 .8em; }
.md li { margin-bottom: .25em; }
.md blockquote { margin: 12px 0; padding: 10px 14px; border-inline-start: 4px solid var(--accent); background: var(--accent-soft); border-radius: 8px; color: var(--accent-ink); }
.md code { font-family: var(--font-mono); font-size: 13px; background: var(--surface-2); padding: 1px 6px; border-radius: 5px; direction: ltr; unicode-bidi: isolate; }
.md pre { background: var(--surface-2); padding: 12px; border-radius: 10px; overflow-x: auto; direction: ltr; }
.md table { border-collapse: collapse; width: 100%; margin: 10px 0 16px; font-size: 14px; display: block; overflow-x: auto; }
.md th, .md td { border: 1px solid var(--line); padding: 7px 10px; text-align: start; vertical-align: top; }
.md th { background: var(--surface-2); font-weight: 600; }
.md hr { border: 0; border-top: 1px solid var(--line); margin: 20px 0; }
.md strong { color: var(--ink); }
.md img { border-radius: 8px; }

/* ── المودال والتنبيهات المنبثقة ────────────────────────────────────────── */
.modal { position: fixed; inset: 0; background: rgba(10, 20, 16, .5); display: grid; place-items: center; padding: 16px; z-index: 100; backdrop-filter: blur(3px); }
.modal .box { width: min(720px, 100%); max-height: calc(100dvh - 32px); overflow: auto; background: var(--surface); border-radius: 18px; padding: 20px 22px; box-shadow: var(--shadow-lg); border: 1px solid var(--line); animation: pop .15s ease; }
.modal .box.wide { width: min(1000px, 100%); }
.modal .box.narrow { width: min(460px, 100%); }
.modal .box h2 { font-family: var(--font-display); font-size: 26px; font-weight: 600; margin-bottom: 12px; }
.modal .foot { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; flex-wrap: wrap; }
@keyframes pop { from { transform: translateY(8px) scale(.98); opacity: 0; } }
@media (max-width: 640px) { .modal { padding: 0; align-items: end; } .modal .box { border-radius: 18px 18px 0 0; max-height: 94dvh; } }
.toasts { position: fixed; bottom: calc(var(--nav-h) + 12px); inset-inline: 0; display: flex; flex-direction: column; align-items: center; gap: 8px; z-index: 200; pointer-events: none; }
@media (min-width: 961px) { .toasts { bottom: 20px; } }
.toast { pointer-events: auto; background: var(--ink); color: var(--ground); padding: 10px 16px; border-radius: 12px; font-size: 14px; box-shadow: var(--shadow-lg); max-width: min(520px, 92vw); animation: pop .15s ease; }
.toast.ok { background: var(--ok); color: #fff; }
.toast.err { background: var(--danger); color: #fff; }
.toast.warn { background: var(--accent); color: #1c1400; }

/* ── الرفع ───────────────────────────────────────────────────────────────── */
.drop { border: 2px dashed var(--line-strong); border-radius: var(--radius); padding: 22px; text-align: center; color: var(--ink-2); background: var(--surface-2); transition: border-color .15s, background .15s; cursor: pointer; }
.drop.over { border-color: var(--primary); background: var(--primary-soft); }
.drop input { display: none; }
.file-list { display: flex; flex-direction: column; gap: 6px; margin-top: 10px; }
.file-row { display: flex; gap: 10px; align-items: center; font-size: 13px; padding: 6px 10px; border-radius: 8px; background: var(--surface); border: 1px solid var(--line); }
.file-row .bar { height: 4px; background: var(--surface-3); border-radius: 2px; overflow: hidden; flex: 1; }
.file-row .bar i { display: block; height: 100%; background: var(--primary); width: 0; transition: width .2s; }
.doc-tile { display: flex; gap: 12px; padding: 12px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); cursor: pointer; align-items: flex-start; }
.doc-tile:hover { border-color: var(--primary); }
.doc-tile .thumb { width: 64px; height: 80px; border-radius: 8px; background: var(--surface-2); display: grid; place-items: center; overflow: hidden; flex: none; font-size: 11px; font-weight: 700; color: var(--ink-3); font-family: var(--font-mono); }
.doc-tile .thumb img { width: 100%; height: 100%; object-fit: cover; }
.doc-tile .t { font-weight: 600; line-height: 1.3; }
.doc-tile .s { font-size: 12px; color: var(--ink-2); margin-top: 3px; }
.doc-tile .imp { font-size: 13px; color: var(--ink-2); margin-top: 6px; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.viewer { background: var(--surface-2); border-radius: var(--radius); overflow: hidden; min-height: 320px; display: grid; place-items: center; }
.viewer iframe { width: 100%; height: 78dvh; border: 0; background: #fff; }
.viewer img { max-height: 78dvh; object-fit: contain; }
.viewer pre { white-space: pre-wrap; padding: 16px; margin: 0; width: 100%; font-family: var(--font-ui); line-height: 1.7; }

/* ── الرسوم ──────────────────────────────────────────────────────────────── */
.chart-box { position: relative; height: 240px; }
.chart-box.tall { height: 320px; }
.spark { width: 90px; height: 28px; display: block; }
.trend-up { color: var(--danger); } .trend-down { color: var(--info); } .trend-flat { color: var(--ink-3); }

/* ── السجل الزمني ────────────────────────────────────────────────────────── */
.timeline { position: relative; padding-inline-start: 26px; }
.timeline::before { content: ''; position: absolute; inset-block: 6px; inset-inline-start: 9px; width: 2px; background: var(--line-strong); border-radius: 2px; }
.tl-day { position: relative; margin-bottom: 18px; }
.tl-day::before { content: ''; position: absolute; inset-inline-start: -22px; top: 6px; width: 12px; height: 12px; border-radius: 50%; background: var(--primary); border: 2px solid var(--surface); box-shadow: 0 0 0 2px var(--primary-soft); }
.tl-day .date { font-family: var(--font-mono); font-size: 13px; color: var(--ink-2); font-weight: 500; margin-bottom: 6px; }
.tl-item { display: flex; gap: 10px; align-items: flex-start; padding: 8px 10px; border-radius: 10px; background: var(--surface); border: 1px solid var(--line); margin-bottom: 6px; cursor: pointer; }
.tl-item:hover { border-color: var(--primary); }
.tl-item .k { font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 6px; background: var(--surface-2); color: var(--ink-2); flex: none; margin-top: 2px; }
.tl-item .k.alert { background: var(--danger-soft); color: var(--danger-ink); }
.tl-item .k.analysis { background: var(--primary-soft); color: var(--primary-ink); }
.tl-item .k.event { background: var(--accent-soft); color: var(--accent-ink); }
.tl-item .k.medication { background: var(--info-soft); color: var(--info); }

/* ── المحادثة ────────────────────────────────────────────────────────────── */
.chat { display: grid; grid-template-columns: 260px 1fr; gap: 14px; min-height: 70dvh; }
@media (max-width: 960px) { .chat { grid-template-columns: 1fr; } .chat .convs.hide-m { display: none; } }
.chat .convs { display: flex; flex-direction: column; gap: 4px; }
.conv { padding: 9px 12px; border-radius: 10px; cursor: pointer; font-size: 14px; border: 1px solid transparent; }
.conv:hover { background: var(--surface-2); }
.conv.on { background: var(--primary-soft); border-color: var(--primary); color: var(--primary-ink); font-weight: 600; }
.conv .m { font-size: 12px; color: var(--ink-3); font-weight: 400; }
.chat .pane { display: flex; flex-direction: column; min-height: 60dvh; }
.msgs { flex: 1; display: flex; flex-direction: column; gap: 12px; padding: 6px 2px 14px; overflow-y: auto; }
.msg { max-width: 92%; padding: 10px 14px; border-radius: 16px; line-height: 1.7; font-size: 15px; }
.msg.user { align-self: flex-start; background: var(--primary); color: #fff; border-end-start-radius: 4px; white-space: pre-wrap; }
.msg.assistant { align-self: flex-end; background: var(--surface); border: 1px solid var(--line); border-end-end-radius: 4px; }
.msg .meta { font-size: 11px; opacity: .7; margin-top: 4px; }
.msg .attach { font-size: 12px; opacity: .85; margin-bottom: 4px; }
.composer { display: flex; gap: 8px; align-items: flex-end; border-top: 1px solid var(--line); padding-top: 10px; }
.composer textarea { min-height: 46px; max-height: 180px; }
.typing { display: inline-flex; gap: 4px; align-items: center; height: 18px; }
.typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--ink-3); animation: blink 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: .2s; } .typing i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }

/* ── الطباعة ─────────────────────────────────────────────────────────────── */
.print-only { display: none; }
@media print {
  .sidebar, .mobile-nav, .mobile-top, .topbar .actions, .no-print, .toasts, .modal { display: none !important; }
  .app { display: block; }
  .main { padding: 0; max-width: none; }
  body { background: #fff; color: #000; font-size: 12.5pt; }
  .card { box-shadow: none; border: 0; padding: 0; }
  .md h2 { break-after: avoid; }
  .md table, .md tr { break-inside: avoid; }
  .print-only { display: block; }
  a { color: inherit; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
