@font-face { font-family: 'Cairo'; font-weight: 400; font-display: swap; src: url(../fonts/cairo-arabic-400-normal.woff2) format('woff2'); unicode-range: U+0600-06FF, U+0750-077F, U+200C-200F, U+FB50-FDFF, U+FE70-FEFF; }
@font-face { font-family: 'Cairo'; font-weight: 700; font-display: swap; src: url(../fonts/cairo-arabic-700-normal.woff2) format('woff2'); unicode-range: U+0600-06FF, U+0750-077F, U+200C-200F, U+FB50-FDFF, U+FE70-FEFF; }
@font-face { font-family: 'Cairo'; font-weight: 400; font-display: swap; src: url(../fonts/cairo-latin-400-normal.woff2) format('woff2'); unicode-range: U+0000-00FF, U+2000-206F, U+20AC; }
@font-face { font-family: 'Cairo'; font-weight: 700; font-display: swap; src: url(../fonts/cairo-latin-700-normal.woff2) format('woff2'); unicode-range: U+0000-00FF, U+2000-206F, U+20AC; }

:root {
  --bg: #f4f6f6; --card: #fff; --text: #1d2b2a; --muted: #5f6f6d; --line: #dfe5e4;
  --primary: #0f766e; --primary-dark: #0b5a54; --primary-soft: #e3f4f1;
  --danger: #b42318; --danger-soft: #fdecea; --warn: #8a5300; --warn-soft: #fff4dc;
  --ok: #1f7a3a; --ok-soft: #e6f5ea; --info-soft: #eaf1fb; --info: #1d4f91;
  --radius: 12px; --nav-h: 64px;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { font-family: 'Cairo', Tahoma, 'Segoe UI', sans-serif; background: var(--bg); color: var(--text); font-size: 16px; line-height: 1.6; -webkit-text-size-adjust: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--primary); }
h1 { font-size: 22px; margin: 0 0 12px; }
h2 { font-size: 19px; margin: 0 0 10px; }
h3 { font-size: 17px; margin: 0 0 8px; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.ltr { direction: ltr; unicode-bidi: embed; display: inline-block; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.stack > * + * { margin-top: 12px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; }

/* ---------- الهيكل ---------- */
.topbar { position: sticky; top: 0; z-index: 20; background: var(--primary); color: #fff; padding: 10px 16px; display: flex; align-items: center; gap: 12px; }
.topbar .brand { font-weight: 700; font-size: 18px; }
.topbar .who { margin-inline-start: auto; font-size: 14px; opacity: .9; }
.topbar .live { width: 10px; height: 10px; border-radius: 50%; background: #9be7c9; display: inline-block; }
.topbar .live.off { background: #f3b2ac; }
main { max-width: 980px; margin: 0 auto; padding: 16px 12px calc(var(--nav-h) + 24px); }
nav.tabs { position: fixed; bottom: 0; inset-inline: 0; height: var(--nav-h); background: #fff; border-top: 1px solid var(--line); display: flex; z-index: 30; padding-bottom: env(safe-area-inset-bottom); }
nav.tabs a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; text-decoration: none; color: var(--muted); font-size: 13px; gap: 2px; }
nav.tabs a .ic { font-size: 20px; line-height: 1; }
nav.tabs a.active { color: var(--primary); font-weight: 700; }
nav.tabs a .count { background: var(--danger); color: #fff; border-radius: 10px; padding: 0 6px; font-size: 11px; }
@media (min-width: 900px) {
  nav.tabs { position: sticky; top: 52px; bottom: auto; height: 52px; border-top: 0; border-bottom: 1px solid var(--line); justify-content: center; }
  nav.tabs a { flex: 0 0 auto; flex-direction: row; padding: 0 22px; font-size: 15px; gap: 8px; }
  main { padding-bottom: 32px; }
}

/* ---------- عناصر ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.card + .card { margin-top: 12px; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 8px 16px; border-radius: 10px; border: 1px solid var(--line); background: #fff; cursor: pointer; text-decoration: none; color: var(--text); white-space: nowrap; }
.btn:hover { border-color: #b9c6c4; }
.btn:disabled { opacity: .55; cursor: wait; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 700; }
.btn.primary:hover { background: var(--primary-dark); }
.btn.danger { color: var(--danger); border-color: #f0c4bf; }
.btn.big { min-height: 54px; font-size: 18px; padding: 10px 22px; }
.btn.block { width: 100%; }
.btn.sm { min-height: 36px; padding: 4px 12px; font-size: 14px; }
label.f { display: block; font-size: 14px; color: var(--muted); margin-bottom: 4px; }
label.f .req { color: var(--danger); }
input.i, select.i, textarea.i { width: 100%; min-height: 46px; padding: 8px 12px; border: 1px solid #c9d3d1; border-radius: 10px; background: #fff; }
textarea.i { min-height: 70px; resize: vertical; }
input.i:focus, select.i:focus, textarea.i:focus { outline: 2px solid var(--primary); outline-offset: 0; border-color: var(--primary); }
input.search { font-size: 18px; min-height: 54px; }
.field + .field { margin-top: 12px; }
.err { color: var(--danger); font-size: 14px; margin-top: 4px; }

.seg { display: flex; gap: 8px; flex-wrap: wrap; }
.seg button { min-height: 44px; padding: 6px 16px; border-radius: 10px; border: 1px solid #c9d3d1; background: #fff; cursor: pointer; }
.seg button.on { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 700; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { min-height: 38px; padding: 4px 12px; border-radius: 20px; border: 1px solid #c9d3d1; background: #fff; cursor: pointer; font-size: 15px; }
.chip.on { background: var(--primary-soft); border-color: var(--primary); color: var(--primary-dark); font-weight: 700; }
.chip.on::after { content: ' ✓'; }
.chip-add { display: flex; gap: 6px; margin-top: 8px; }
.chip-add input { flex: 1; }

.badge { display: inline-block; padding: 1px 10px; border-radius: 20px; font-size: 13px; background: #eef1f1; color: var(--muted); white-space: nowrap; }
.badge.waiting { background: var(--ok-soft); color: var(--ok); }
.badge.with_doctor { background: var(--info-soft); color: var(--info); }
.badge.booked { background: #eef1f1; color: var(--muted); }
.badge.done { background: #eef1f1; color: var(--muted); }
.badge.urgent, .badge.no_show, .badge.cancelled { background: var(--danger-soft); color: var(--danger); }
.badge.followup { background: var(--warn-soft); color: var(--warn); }
.badge.paper { background: var(--warn-soft); color: var(--warn); }

.alert { border-radius: 10px; padding: 8px 12px; font-size: 15px; }
.alert b { margin-inline-end: 6px; }
.alert.danger { background: var(--danger-soft); color: var(--danger); border: 1px solid #f3c3bd; }
.alert.warn { background: var(--warn-soft); color: var(--warn); border: 1px solid #f2d9a5; }
.alert.ok { background: var(--ok-soft); color: var(--ok); }
.alert.gray { background: #eef1f1; color: var(--muted); }
.alert + .alert { margin-top: 6px; }

.list { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.item { display: flex; gap: 10px; align-items: center; padding: 10px 14px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.item:first-child { border-top: 0; }
.item.click { cursor: pointer; }
.item.click:hover { background: #f8fbfa; }
.num { min-width: 38px; height: 38px; border-radius: 50%; background: var(--primary-soft); color: var(--primary-dark); display: inline-flex; align-items: center; justify-content: center; font-weight: 700; }
.item .name { font-weight: 700; }
.item .actions { margin-inline-start: auto; display: flex; gap: 6px; flex-wrap: wrap; }
.section-title { margin: 18px 4px 8px; font-weight: 700; color: var(--muted); font-size: 15px; display: flex; justify-content: space-between; align-items: center; }
.empty { padding: 18px; text-align: center; color: var(--muted); }

.next-card { border: 2px solid var(--primary); }
.next-card .pname { font-size: 22px; font-weight: 700; }
.code { font-weight: 700; letter-spacing: 1px; }
.vitals { display: grid; grid-template-columns: repeat(auto-fit, minmax(96px, 1fr)); gap: 8px; }
.bp { display: flex; gap: 4px; align-items: center; }
.rx-row { display: grid; grid-template-columns: 2fr 1fr 1fr 1fr auto; gap: 6px; align-items: center; margin-bottom: 6px; }
@media (max-width: 640px) { .rx-row { grid-template-columns: 1fr 1fr; padding: 8px; border: 1px dashed var(--line); border-radius: 10px; } .rx-row .drug { grid-column: 1 / -1; } }
.visit { border-inline-start: 4px solid var(--primary); }
.visit.paper { border-inline-start-color: #e0a63a; }
.visit .vh { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; align-items: center; }
.kv { margin: 4px 0; }
.kv b { color: var(--muted); font-weight: 400; margin-inline-end: 6px; }
.sticky-actions { position: sticky; bottom: calc(var(--nav-h) + 8px); background: rgba(244,246,246,.96); padding: 10px 0; display: flex; gap: 8px; flex-wrap: wrap; z-index: 5; }
@media (min-width: 900px) { .sticky-actions { bottom: 0; } }
details.more > summary { cursor: pointer; padding: 10px 0; font-weight: 700; color: var(--primary); }

/* ---------- نوافذ ورسائل ---------- */
dialog { border: 0; border-radius: 16px; padding: 0; width: min(560px, 94vw); max-height: 88vh; }
dialog::backdrop { background: rgba(0,0,0,.45); }
dialog .dlg { padding: 18px; overflow: auto; max-height: 88vh; }
.toast-box { position: fixed; top: 64px; inset-inline: 0; display: flex; flex-direction: column; align-items: center; gap: 8px; z-index: 100; pointer-events: none; }
.toast { background: #1d2b2a; color: #fff; padding: 10px 18px; border-radius: 10px; max-width: 92vw; pointer-events: auto; }
.toast.error { background: var(--danger); }
.toast.ok { background: var(--ok); }
.login { max-width: 400px; margin: 8vh auto; }
.login .logo { font-size: 44px; text-align: center; }
.loading { padding: 30px; text-align: center; color: var(--muted); }
table.t { width: 100%; border-collapse: collapse; font-size: 14px; }
table.t td, table.t th { border-top: 1px solid var(--line); padding: 8px; text-align: start; vertical-align: top; }
.center { text-align: center; }
@media (max-width: 640px) { .item .actions { width: 100%; margin-inline-start: 48px; } }
.alert.chronic { background: var(--danger-soft); color: var(--danger); border: 2px solid var(--danger); font-size: 17px; }
.alert.chronic .chronic-title { font-weight: 700; }
.badge.chronic { background: var(--danger); color: #fff; }
