/* =====================================================================
   المنصة الوطنية لزراعة الكلى — الهوية البصرية لوزارة الصحة
   اللون الأساسي مأخوذ من الشعار: #033c59
   ===================================================================== */

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

:root {
  /* الهوية */
  --navy-950: #021f30;
  --navy-900: #022c42;
  --navy-800: #033c59;   /* لون الشعار */
  --navy-700: #0a4d70;
  --navy-600: #145f87;
  --navy-100: #dceaf3;
  --navy-50:  #eef5fa;
  --teal-600: #0b8299;
  --teal-500: #12a0b8;
  --teal-50:  #e6f6f9;

  /* المحايدات */
  --bg:      #f3f6f9;
  --surface: #ffffff;
  --ink:     #0f2433;
  --ink-2:   #3c5566;
  --muted:   #6b8191;
  --line:    #e1e9ef;
  --line-2:  #cfdbe4;

  /* الحالات */
  --ok: #138a5b;   --ok-bg: #e6f5ee;
  --warn: #b26a00; --warn-bg: #fdf3e1;
  --err: #c0362c;  --err-bg: #fcecea;
  --info: #145f87; --info-bg: #e8f1f8;

  /* المراحل */
  --st-waiting: #2563b8;      --st-waiting-bg: #e7effb;
  --st-contacted: #6d4fc2;    --st-contacted-bg: #efeafb;
  --st-processing: #b26a00;   --st-processing-bg: #fdf3e1;
  --st-transplanted: #138a5b; --st-transplanted-bg: #e6f5ee;
  --st-cannot: #c0362c;       --st-cannot-bg: #fcecea;

  --r-sm: 8px; --r: 12px; --r-lg: 16px;
  --sh-1: 0 1px 2px rgba(3, 40, 60, .06), 0 1px 1px rgba(3, 40, 60, .04);
  --sh-2: 0 6px 20px rgba(3, 40, 60, .08);
  --sidebar-w: 272px;
  --font: "Tajawal", system-ui, "Segoe UI", Tahoma, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font-family: var(--font); font-size: 15px; line-height: 1.6; color: var(--ink); background: var(--bg); }
img { max-width: 100%; display: block; }
a { color: var(--navy-700); text-decoration: none; }
a:hover { color: var(--teal-600); }
h1, h2, h3, h4 { margin: 0; line-height: 1.3; font-weight: 800; }
p { margin: 0; }
.ic { flex: none; }
.muted { color: var(--muted); }
.num { font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: isolate; }
.ltr { direction: ltr; unicode-bidi: isolate; text-align: right; }
.kv dd { text-align: right; }
.skip { position: absolute; inset-inline-start: -999px; top: 8px; background: var(--navy-800); color: #fff; padding: 8px 14px; border-radius: 8px; z-index: 100; }
.skip:focus { inset-inline-start: 8px; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--teal-500) 55%, transparent); outline-offset: 2px; }

/* ---------------- الهيكل ---------------- */
.shell { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar-w); flex: none; position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; gap: 14px; padding: 20px 16px;
  background: var(--navy-800); color: #dbe8f0;
  background-image:
    radial-gradient(circle at 110% -10%, rgba(255,255,255,.07) 0 140px, transparent 141px),
    radial-gradient(circle at 110% -10%, rgba(255,255,255,.05) 0 200px, transparent 201px);
}
.brand { display: flex; align-items: center; gap: 12px; padding: 4px 4px 14px; border-bottom: 1px solid rgba(255,255,255,.10); }
.brand img { width: 52px; height: 52px; border-radius: 50%; box-shadow: 0 0 0 3px rgba(255,255,255,.9); }
.brand-text { display: flex; flex-direction: column; min-width: 0; }
.brand-org { font-size: 11.5px; color: #9fbdd0; font-weight: 500; }
.brand-app { font-size: 15.5px; color: #fff; font-weight: 800; line-height: 1.35; }
.scope-chip { display: flex; align-items: center; gap: 8px; padding: 9px 12px; border-radius: 10px; background: rgba(255,255,255,.07); color: #fff; font-size: 13px; font-weight: 700; }
.scope-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav { display: flex; flex-direction: column; gap: 2px; margin-top: 4px; }
.nav-link { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 10px; color: #c4d8e5; font-weight: 500; transition: background .15s, color .15s; }
.nav-link:hover { background: rgba(255,255,255,.08); color: #fff; }
.nav-link.is-active { background: #fff; color: var(--navy-800); font-weight: 700; box-shadow: var(--sh-1); }
.nav-link.is-active .ic { color: var(--teal-600); }
.sidebar-foot { margin-top: auto; display: flex; align-items: center; gap: 8px; padding-top: 14px; border-top: 1px solid rgba(255,255,255,.10); }
.sidebar-foot form { margin: 0; }
.me { flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; color: #fff; padding: 6px; border-radius: 10px; }
.me:hover { background: rgba(255,255,255,.07); color: #fff; }
.avatar { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; background: var(--teal-500); color: #fff; font-weight: 800; flex: none; }
.me-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.3; }
.me-text strong { font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.me-text small { font-size: 12px; color: #9fbdd0; }

.main-col { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 14px; padding: 20px 32px 8px; }
.page-head { flex: 1; min-width: 0; }
.page-head h1 { font-size: 24px; color: var(--navy-900); }
.page-head p { color: var(--muted); font-size: 14px; margin-top: 2px; }
.top-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.content { padding: 16px 32px 32px; display: flex; flex-direction: column; gap: 20px; width: 100%; max-width: 1320px; }
.foot { margin-top: auto; padding: 16px 32px 24px; color: var(--muted); font-size: 12.5px; }
.icon-btn.menu-btn { display: none; }
.scrim { display: none; }

/* ---------------- المكونات ---------------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--sh-1); }
.card-pad { padding: 20px 22px; }
.card-head { display: flex; align-items: center; gap: 12px; justify-content: space-between; padding: 16px 22px; border-bottom: 1px solid var(--line); }
.card-head h2 { font-size: 16.5px; color: var(--navy-900); }
.card-head p { font-size: 13px; color: var(--muted); }
.card-body { padding: 20px 22px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 40px; padding: 0 16px; border-radius: 10px; border: 1px solid transparent; font: inherit; font-weight: 700; font-size: 14px; cursor: pointer; white-space: nowrap; transition: background .15s, border-color .15s, box-shadow .15s, color .15s; text-decoration: none; }
.btn-primary { background: var(--navy-800); color: #fff; }
.btn-primary:hover { background: var(--navy-700); color: #fff; }
.btn-accent { background: var(--teal-600); color: #fff; }
.btn-accent:hover { background: var(--teal-500); color: #fff; }
.btn-ghost { background: var(--surface); color: var(--navy-800); border-color: var(--line-2); }
.btn-ghost:hover { border-color: var(--navy-600); color: var(--navy-800); }
.btn-danger { background: var(--surface); color: var(--err); border-color: #f0c9c5; }
.btn-danger:hover { background: var(--err-bg); color: var(--err); }
.btn-sm { height: 32px; padding: 0 11px; font-size: 13px; border-radius: 8px; }
.btn-lg { height: 48px; font-size: 15.5px; }
.btn-block { width: 100%; }
.icon-btn { width: 38px; height: 38px; display: inline-grid; place-items: center; border-radius: 10px; border: 1px solid var(--line-2); background: var(--surface); color: var(--navy-800); cursor: pointer; }
.icon-btn:hover { border-color: var(--navy-600); }
.icon-btn.on-dark { background: rgba(255,255,255,.08); border-color: transparent; color: #dbe8f0; }
.icon-btn.on-dark:hover { background: rgba(255,255,255,.16); color: #fff; }

.alert { display: flex; align-items: flex-start; gap: 10px; padding: 12px 14px; border-radius: 12px; font-weight: 500; border: 1px solid transparent; }
.alert .ic { margin-top: 2px; }
.alert-success { background: var(--ok-bg); color: #0d6644; border-color: #bfe5d3; }
.alert-error   { background: var(--err-bg); color: #962a22; border-color: #f2c7c2; }
.alert-warning { background: var(--warn-bg); color: #8a5200; border-color: #f1d9ad; }
.alert-info    { background: var(--info-bg); color: var(--navy-700); border-color: #cde0ee; }

.badge { display: inline-flex; align-items: center; gap: 4px; padding: 3px 10px; border-radius: 999px; font-size: 12.5px; font-weight: 700; white-space: nowrap; }
.badge-ok { background: var(--ok-bg); color: var(--ok); }
.badge-off { background: #eef1f4; color: #5d707d; }
.badge-role { background: var(--navy-50); color: var(--navy-700); }
.stage-waiting      { background: var(--st-waiting-bg); color: var(--st-waiting); }
.stage-contacted    { background: var(--st-contacted-bg); color: var(--st-contacted); }
.stage-processing   { background: var(--st-processing-bg); color: var(--st-processing); }
.stage-transplanted { background: var(--st-transplanted-bg); color: var(--st-transplanted); }
.stage-cannot       { background: var(--st-cannot-bg); color: var(--st-cannot); }

/* مؤشرات */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; }
.kpi { position: relative; padding: 18px 20px; display: flex; flex-direction: column; gap: 6px; overflow: hidden; }
.kpi-top { display: flex; align-items: center; justify-content: space-between; color: var(--muted); font-size: 13.5px; font-weight: 700; }
.kpi-ic { width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center; background: var(--navy-50); color: var(--navy-700); }
.kpi-val { font-size: 32px; font-weight: 800; color: var(--navy-900); line-height: 1.1; font-variant-numeric: tabular-nums; }
.kpi-sub { font-size: 12.5px; color: var(--muted); }
.kpi.is-hero { background: var(--navy-800); border-color: var(--navy-800); color: #fff; }
.kpi.is-hero .kpi-top, .kpi.is-hero .kpi-sub { color: #a9c6d8; }
.kpi.is-hero .kpi-val { color: #fff; }
.kpi.is-hero .kpi-ic { background: rgba(255,255,255,.12); color: #fff; }

/* شريط المراحل */
.pipeline { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; }
.pipe { border-radius: 12px; padding: 14px 16px; border: 1px solid var(--line); background: var(--surface); display: flex; flex-direction: column; gap: 4px; }
.pipe-label { display: flex; align-items: center; gap: 8px; font-size: 13.5px; font-weight: 700; color: var(--ink-2); }
.pipe-dot { width: 9px; height: 9px; border-radius: 50%; }
.pipe-val { font-size: 26px; font-weight: 800; color: var(--navy-900); font-variant-numeric: tabular-nums; }
.pipe-bar { height: 5px; border-radius: 9px; background: var(--bg); overflow: hidden; }
.pipe-bar i { display: block; height: 100%; border-radius: 9px; }

/* جداول */
.table-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th { text-align: start; font-weight: 700; color: var(--muted); font-size: 12.5px; padding: 11px 16px; background: #f8fafc; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl td { padding: 13px 16px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl tbody tr:hover td { background: #fafcfd; }
.cell-main { display: flex; align-items: center; gap: 12px; min-width: 0; }
.cell-ic { width: 38px; height: 38px; flex: none; border-radius: 10px; display: grid; place-items: center; background: var(--navy-50); color: var(--navy-700); }
.cell-title { font-weight: 700; color: var(--ink); }
.cell-sub { font-size: 12.5px; color: var(--muted); }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }
.row-actions form { margin: 0; }
.empty { padding: 48px 20px; text-align: center; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 10px; }
.empty .ic { color: var(--line-2); }
.bar-inline { display: flex; height: 8px; border-radius: 9px; overflow: hidden; background: var(--bg); min-width: 120px; }
.bar-inline i { display: block; height: 100%; }

/* نماذج */
.stack { display: flex; flex-direction: column; gap: 16px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px 18px; }
.form-grid .span-2 { grid-column: 1 / -1; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: 13.5px; font-weight: 700; color: var(--ink-2); }
.field .req { color: var(--err); }
.field small { color: var(--muted); font-size: 12.5px; }
input[type=text], input[type=password], input[type=email], input[type=tel], input[type=search], input:not([type]), select, textarea {
  width: 100%; height: 44px; padding: 0 13px; font: inherit; font-size: 15px; color: var(--ink);
  background: #fff; border: 1px solid var(--line-2); border-radius: 10px; transition: border-color .15s, box-shadow .15s;
}
textarea { height: auto; min-height: 96px; padding: 10px 13px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--navy-600); box-shadow: 0 0 0 4px rgba(20, 95, 135, .12); }
.input-ic { position: relative; }
.input-ic > .ic { position: absolute; inset-inline-start: 13px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.input-ic input { padding-inline-start: 42px; }
.pw-toggle { position: absolute; inset-inline-end: 6px; top: 50%; transform: translateY(-50%); width: 34px; height: 34px; border: 0; background: none; color: var(--muted); cursor: pointer; border-radius: 8px; display: grid; place-items: center; }
.pw-toggle:hover { color: var(--navy-700); background: var(--navy-50); }
.form-section { font-size: 14px; font-weight: 800; color: var(--navy-800); display: flex; align-items: center; gap: 8px; padding-bottom: 8px; border-bottom: 1px dashed var(--line-2); grid-column: 1 / -1; margin-top: 6px; }
.form-actions { display: flex; gap: 10px; justify-content: flex-start; flex-wrap: wrap; padding-top: 4px; }
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; padding: 14px 22px; border-bottom: 1px solid var(--line); }
.toolbar .search { flex: 1; min-width: 220px; max-width: 420px; }
.toolbar select { width: auto; min-width: 150px; }

/* صندوق كلمة المرور المؤقتة */
.secret { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; padding: 16px 18px; border-radius: 14px; background: var(--teal-50); border: 1px dashed var(--teal-500); }
.secret dl { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; margin: 0; flex: 1; }
.secret dt { color: var(--muted); font-size: 13px; }
.secret dd { margin: 0; font-weight: 800; color: var(--navy-900); font-size: 16px; direction: ltr; text-align: end; font-family: ui-monospace, Consolas, monospace; }

.grid-2 { display: grid; grid-template-columns: 1.6fr 1fr; gap: 20px; align-items: start; }
.list-plain { list-style: none; margin: 0; padding: 0; }
.list-plain li { display: flex; align-items: center; gap: 12px; padding: 12px 22px; border-bottom: 1px solid var(--line); }
.list-plain li:last-child { border-bottom: 0; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--teal-500); flex: none; }
.kv { display: grid; grid-template-columns: 140px 1fr; gap: 10px 16px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 700; }

/* ---------------- صفحة الدخول ---------------- */
.login-page { background: var(--surface); }
.login { min-height: 100vh; display: grid; grid-template-columns: 1.05fr 1fr; }
.login-hero {
  position: relative; overflow: hidden; color: #fff; padding: 56px 48px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 6px;
  background: var(--navy-800);
}
.hero-rings, .hero-rings::before, .hero-rings::after { position: absolute; border-radius: 50%; border: 1px solid rgba(255,255,255,.09); }
.hero-rings { width: 620px; height: 620px; top: 50%; left: 50%; transform: translate(-50%, -55%); }
.hero-rings::before { content: ""; inset: 70px; border-style: dashed; border-color: rgba(255,255,255,.08); }
.hero-rings::after { content: ""; inset: -110px; border-color: rgba(255,255,255,.05); }
.hero-logo { position: relative; width: 148px; height: 148px; border-radius: 50%; box-shadow: 0 0 0 6px rgba(255,255,255,.95), 0 20px 40px rgba(0,0,0,.25); margin-bottom: 18px; }
.hero-org { position: relative; font-size: 15px; color: #a9c6d8; font-weight: 500; }
.hero-auth { position: relative; font-size: 34px; }
.hero-sep { position: relative; width: 56px; height: 3px; border-radius: 3px; background: var(--teal-500); margin: 14px 0 10px; }
.hero-app { position: relative; font-size: 22px; font-weight: 700; color: #e7f1f7; }
.hero-tag { position: relative; margin-top: 10px; font-size: 14px; color: #a9c6d8; max-width: 380px; }
.login-panel { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 40px 24px; gap: 18px; background: var(--bg); }
.login-card { width: 100%; max-width: 420px; background: var(--surface); border: 1px solid var(--line); border-radius: 20px; padding: 28px; box-shadow: var(--sh-2); display: flex; flex-direction: column; gap: 14px; }
.login-card h3 { font-size: 21px; color: var(--navy-900); margin-top: 6px; }
.portal-tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; border-radius: 12px; background: var(--bg); }
.portal-tabs a { display: flex; align-items: center; justify-content: center; gap: 6px; height: 38px; border-radius: 9px; font-weight: 700; font-size: 13.5px; color: var(--muted); }
.portal-tabs a.is-on { background: var(--surface); color: var(--navy-800); box-shadow: var(--sh-1); }
.login-note { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12.5px; justify-content: center; }
.login-foot { color: var(--muted); font-size: 12.5px; }

.plain { background: var(--bg); display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.error-box { padding: 36px; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 14px; max-width: 420px; color: var(--navy-800); }
.error-box h1 { font-size: 18px; color: var(--ink); }

/* ---------------- الاستجابة ---------------- */
@media (max-width: 1100px) {
  .pipeline { grid-template-columns: repeat(3, 1fr); }
  .grid-2 { grid-template-columns: 1fr; }
}
@media (max-width: 900px) {
  .sidebar { position: fixed; inset-block: 0; inset-inline-start: 0; z-index: 50; transform: translateX(100%); transition: transform .2s ease; box-shadow: var(--sh-2); }
  body.nav-open .sidebar { transform: none; }
  body.nav-open .scrim { display: block; position: fixed; inset: 0; background: rgba(2, 31, 48, .45); z-index: 40; }
  .icon-btn.menu-btn { display: inline-grid; }
  .topbar { padding: 14px 16px 4px; flex-wrap: wrap; }
  .content { padding: 12px 16px 24px; }
  .foot { padding: 12px 16px 20px; }
  .page-head h1 { font-size: 20px; }
  .login { grid-template-columns: 1fr; }
  .login-hero { padding: 36px 20px 30px; }
  .hero-logo { width: 96px; height: 96px; margin-bottom: 10px; }
  .hero-auth { font-size: 26px; }
  .hero-app { font-size: 18px; }
  .hero-tag { display: none; }
  .hero-rings { width: 420px; height: 420px; }
}
@media (max-width: 640px) {
  .form-grid { grid-template-columns: 1fr; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .kpi { padding: 14px; }
  .kpi-val { font-size: 26px; }
  .kpi-ic { width: 32px; height: 32px; }
  .kpi-sub { font-size: 11.5px; }
  .pipeline { grid-template-columns: repeat(2, 1fr); }
  .kv { grid-template-columns: 1fr; gap: 2px; }
  .kv dd { margin-bottom: 8px; }
  .top-actions { width: 100%; }
  .top-actions .btn { flex: 1; }
  .tbl.responsive thead { display: none; }
  .tbl.responsive tr { display: block; border-bottom: 1px solid var(--line); padding: 8px 0; }
  .tbl.responsive td { display: flex; justify-content: space-between; gap: 12px; border: 0; padding: 6px 16px; }
  .tbl.responsive td[data-label]::before { content: attr(data-label); color: var(--muted); font-size: 12.5px; font-weight: 700; }
  .tbl.responsive td.cell-first { display: block; }
  .row-actions { justify-content: flex-start; }
}
@media print {
  .sidebar, .topbar .top-actions, .menu-btn, .foot, .row-actions { display: none !important; }
  body { background: #fff; }
  .card { box-shadow: none; }
}
.tbl td.cell-first { min-width: 190px; }

/* =================== المرحلة 2: المرضى =================== */
.tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.tab { display: inline-flex; align-items: center; gap: 8px; height: 40px; padding: 0 14px; border-radius: 10px; background: var(--surface); border: 1px solid var(--line); color: var(--ink-2); font-weight: 700; font-size: 14px; }
.tab:hover { border-color: var(--line-2); color: var(--navy-800); }
.tab.is-on { background: var(--navy-800); border-color: var(--navy-800); color: #fff; }
.tab-n { min-width: 24px; height: 22px; padding: 0 7px; border-radius: 999px; background: var(--bg); color: var(--ink-2); font-size: 12px; display: inline-grid; place-items: center; font-variant-numeric: tabular-nums; }
.tab.is-on .tab-n { background: rgba(255,255,255,.16); color: #fff; }
.tab .pipe-dot { width: 8px; height: 8px; }
.tab-waiting .pipe-dot { background: var(--st-waiting); } .tab-contacted .pipe-dot { background: var(--st-contacted); }
.tab-processing .pipe-dot { background: var(--st-processing); } .tab-transplanted .pipe-dot { background: var(--st-transplanted); }
.tab-cannot .pipe-dot { background: var(--st-cannot); }

.avatar.sm { width: 34px; height: 34px; font-size: 14px; }
.avatar.lg { width: 64px; height: 64px; font-size: 26px; }
.avatar.g-male { background: #dbeafe; color: #1e4f9c; }
.avatar.g-female { background: #fce7f3; color: #9d2a64; }
.avatar.g-x { background: var(--navy-50); color: var(--navy-700); }
.blood { display: inline-flex; align-items: center; height: 24px; padding: 0 8px; border-radius: 7px; background: #fdecec; color: #b42318; font-weight: 800; font-size: 12.5px; direction: ltr; }
td.late { color: var(--warn); font-weight: 700; }

.top-search { width: 300px; max-width: 40vw; }
.top-search input { height: 40px; background: var(--surface); }

.patient-strip { display: flex; align-items: center; gap: 18px; padding: 18px 22px; position: sticky; top: 8px; z-index: 5; }
.ps-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.ps-name { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; font-size: 19px; font-weight: 800; color: var(--navy-900); }
.ps-facts { display: flex; flex-wrap: wrap; gap: 6px 18px; color: var(--ink-2); font-size: 13.5px; }
.ps-facts > span { display: inline-flex; align-items: center; gap: 6px; }
.ps-facts .ic { color: var(--muted); }
.ps-stage { display: flex; flex-direction: column; align-items: center; padding: 8px 18px; border-inline-start: 1px solid var(--line); min-width: 130px; }
.ps-stage small { color: var(--muted); font-size: 12px; }
.ps-stage strong { font-size: 24px; color: var(--navy-900); }

.move-row { display: flex; gap: 10px; flex-wrap: wrap; }
.move-btn { display: inline-flex; align-items: center; gap: 10px; height: 48px; padding: 0 18px; border-radius: 12px; border: 1px solid transparent; font: inherit; font-weight: 800; font-size: 14.5px; cursor: pointer; transition: transform .1s, box-shadow .15s; }
.move-btn:hover { transform: translateY(-1px); box-shadow: var(--sh-2); }
.move-btn.is-static { width: 44px; height: 44px; padding: 0; justify-content: center; cursor: default; flex: none; }
.move-btn.is-static:hover { transform: none; box-shadow: none; }
.mv-waiting { background: var(--st-waiting-bg); color: var(--st-waiting); border-color: #c9dbf5; }
.mv-contacted { background: var(--st-contacted-bg); color: var(--st-contacted); border-color: #dcd2f5; }
.mv-processing { background: var(--st-processing-bg); color: var(--st-processing); border-color: #f1d9ad; }
.mv-transplanted { background: var(--st-transplanted); color: #fff; }
.mv-cannot { background: var(--st-cannot-bg); color: var(--st-cannot); border-color: #f2c7c2; }

.dialog { border: 0; padding: 0; border-radius: 18px; width: min(520px, calc(100vw - 32px)); box-shadow: 0 24px 60px rgba(2, 31, 48, .3); color: var(--ink); }
.dialog::backdrop { background: rgba(2, 31, 48, .5); backdrop-filter: blur(2px); }
.dialog form { padding: 22px; }
.dialog-head { display: flex; gap: 14px; align-items: center; }
.dialog-head h3 { font-size: 18px; color: var(--navy-900); }

.timeline { list-style: none; margin: 0; padding: 16px 22px 18px; display: flex; flex-direction: column; gap: 0; }
.timeline li { position: relative; padding: 0 22px 18px 0; border-inline-start: 2px solid var(--line); }
.timeline li:last-child { border-inline-start-color: transparent; padding-bottom: 0; }
.timeline li::before { content: ""; position: absolute; inset-inline-start: -7px; top: 3px; width: 12px; height: 12px; border-radius: 50%; background: var(--surface); border: 2px solid var(--navy-600); }
.timeline li.tl-transplanted::before { border-color: var(--st-transplanted); background: var(--st-transplanted); }
.timeline li.tl-cannot::before { border-color: var(--st-cannot); }
.tl-top { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 2px; }
.tl-note { margin-top: 6px; padding: 8px 12px; background: var(--bg); border-radius: 9px; font-size: 13.5px; }

.pair { display: flex; align-items: center; gap: 10px; }
.seg { display: flex; gap: 6px; flex-wrap: wrap; }
.seg label { position: relative; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: inline-flex; align-items: center; justify-content: center; min-width: 56px; height: 40px; padding: 0 14px; border: 1px solid var(--line-2); border-radius: 10px; background: #fff; font-weight: 700; cursor: pointer; color: var(--ink-2); }
.seg input:checked + span { background: var(--navy-800); border-color: var(--navy-800); color: #fff; }
.seg input:focus-visible + span { outline: 3px solid rgba(18,160,184,.45); outline-offset: 2px; }
.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; height: 44px; }
.switch input { position: absolute; opacity: 0; }
.switch > span { width: 46px; height: 26px; border-radius: 99px; background: var(--line-2); position: relative; transition: background .15s; flex: none; }
.switch > span::after { content: ""; position: absolute; top: 3px; inset-inline-start: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; box-shadow: var(--sh-1); transition: inset-inline-start .15s; }
.switch input:checked + span { background: var(--teal-600); }
.switch input:checked + span::after { inset-inline-start: 23px; }
.switch input:focus-visible + span { outline: 3px solid rgba(18,160,184,.45); outline-offset: 2px; }
.donors { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.donor { border: 1px dashed var(--line-2); border-radius: 14px; padding: 14px 16px 16px; margin: 0; min-width: 0; }
.donor legend { padding: 0 8px; font-weight: 800; color: var(--navy-800); font-size: 14px; }
.donor .form-grid { gap: 12px; }
.sticky-actions { position: sticky; bottom: 0; z-index: 4; display: flex; gap: 10px; padding: 14px 0; background: linear-gradient(to top, var(--bg) 70%, transparent); }
.hint-ok { color: var(--ok) !important; font-weight: 700; }
.hint-warn { color: var(--warn) !important; font-weight: 700; }
.danger-zone { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 14px 18px; border: 1px dashed #f0c9c5; border-radius: 14px; background: #fffafa; margin: 0; }
[hidden] { display: none !important; }
.pipe-link { color: inherit; }
.pipe-link:hover .pipe { border-color: var(--navy-600); }
.card-head h2 .ic { vertical-align: -3px; color: var(--teal-600); }

@media (max-width: 900px) {
  .top-search { display: none; }
  .patient-strip { flex-wrap: wrap; position: static; }
  .ps-stage { border-inline-start: 0; border-top: 1px solid var(--line); flex-direction: row; gap: 8px; width: 100%; justify-content: flex-start; padding: 10px 0 0; }
  .donors { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .move-btn { flex: 1 1 calc(50% - 10px); justify-content: center; }
  .tabs { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 4px; }
  .tab { flex: none; }
}
@media print { .patient-strip { position: static; } .move-row, .danger-zone, .top-search { display: none !important; } }
.tbl.matrix td.heat { text-align: center; font-weight: 700; background: color-mix(in srgb, var(--navy-600) calc(var(--h, 0) * 20%), transparent); }
.tbl.matrix tfoot th { background: #f8fafc; color: var(--ink); font-size: 13.5px; }

/* =================== المرحلة 3: الملف الطبي =================== */
.ptabs { position: sticky; top: 0; z-index: 6; background: var(--bg); padding: 6px 0; }
.ptabs .tab .ic { opacity: .8; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 20px; align-items: start; }
.vitals { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0 4px; }
.vitals span { display: flex; flex-direction: column; padding: 8px 12px; border-radius: 10px; background: var(--bg); min-width: 76px; }
.vitals small { color: var(--muted); font-size: 11.5px; }
.vitals b { font-size: 17px; color: var(--navy-900); }
.next-visit { display: flex; align-items: center; gap: 6px; margin-top: 10px; color: var(--navy-700); font-size: 14px; }
.next-visit.late { color: var(--err); }
.lab-mini li { padding: 10px 22px; }
.lab-val { font-weight: 800; font-size: 16px; direction: ltr; font-variant-numeric: tabular-nums; }
.lab-val small { font-weight: 500; font-size: 11px; color: var(--muted); }
.lab-val.high, .lab-cell.high { color: var(--err); }
.lab-val.low, .lab-cell.low { color: var(--st-waiting); }
.lab-cell.high { background: var(--err-bg); }
.lab-cell.low { background: var(--st-waiting-bg); }
.trend { width: 14px; color: var(--muted); font-size: 11px; }
.lab-table td, .lab-table th { white-space: nowrap; }
.lab-table td.lab-cell { text-align: center; font-weight: 700; }
.lab-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px 14px; }
.lab-grp { grid-column: 1 / -1; font-weight: 800; color: var(--navy-800); font-size: 13.5px; padding-top: 6px; border-bottom: 1px dashed var(--line-2); padding-bottom: 4px; }
.lab-in { display: flex; align-items: center; gap: 10px; }
.lab-in > span { flex: 1; display: flex; flex-direction: column; line-height: 1.3; min-width: 0; }
.lab-in > span b { font-size: 13.5px; }
.lab-in > span small { color: var(--muted); font-size: 11.5px; }
.lab-in input { width: 108px; flex: none; height: 40px; text-align: center; font-weight: 700; }
.lab-in input.high { border-color: var(--err); background: var(--err-bg); color: var(--err); }
.lab-in input.low { border-color: var(--st-waiting); background: var(--st-waiting-bg); color: var(--st-waiting); }
.lab-in input.ok { border-color: var(--ok); }
.chart { width: 100%; height: auto; max-height: 280px; }
.ch-ref { fill: var(--ok-bg); }
.ch-grid { stroke: var(--line); stroke-width: 1; }
.ch-ax { fill: var(--muted); font-size: 11px; font-family: var(--font); }
.ch-line { fill: none; stroke: var(--navy-600); stroke-width: 2.2; stroke-linejoin: round; }
.ch-pt { fill: #fff; stroke: var(--navy-600); stroke-width: 2; }
.ch-pt.high { stroke: var(--err); fill: var(--err); }
.ch-pt.low { stroke: var(--st-waiting); fill: var(--st-waiting); }
.inline-form select { height: 38px; min-width: 220px; }
.visits { display: flex; flex-direction: column; }
.visit { padding: 16px 22px; border-bottom: 1px solid var(--line); }
.visit:last-child { border-bottom: 0; }
.visit header { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.visit header > div { display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; }
.kv-visit { margin-top: 8px; grid-template-columns: 110px 1fr; }
.vitals-form { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 12px; }
.vitals-form input { text-align: center; font-weight: 700; }
.quick-dates { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.dropzone { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; padding: 24px; border: 2px dashed var(--line-2); border-radius: 14px; background: var(--bg); cursor: pointer; color: var(--navy-700); text-align: center; position: relative; }
.dropzone:hover { border-color: var(--navy-600); }
.dropzone input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.files .file-ic { width: 42px; height: 48px; border-radius: 8px; display: grid; place-items: center; font-size: 11px; font-weight: 800; flex: none; }
.file-ic.pdf { background: #fdecec; color: #b42318; }
.file-ic.img { background: var(--teal-50); color: var(--teal-600); }
.legacy-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; align-items: start; }
.kv-legacy { grid-template-columns: minmax(120px, 40%) 1fr; font-size: 13.5px; }
.muted-row td { color: var(--muted); }
@media (max-width: 1100px) { .grid-3 { grid-template-columns: 1fr 1fr; } .vitals-form { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 900px) { .legacy-grid { grid-template-columns: 1fr; } }
@media (max-width: 640px) {
  .grid-3 { grid-template-columns: 1fr; }
  .vitals-form { grid-template-columns: repeat(2, 1fr); }
  .lab-grid { grid-template-columns: 1fr; }
  .kv-visit { grid-template-columns: 1fr; }
  .ptabs { flex-wrap: nowrap; overflow-x: auto; }
  .inline-form select { min-width: 0; width: 100%; }
  .card-head { flex-wrap: wrap; }
}
@media print { .ptabs, .lab-entry, .med-form, .dropzone { display: none !important; } }

/* =================== المرحلة 4: البوابة والمشاركة =================== */
.card.emergency { border-color: #f2c7c2; }
.card.emergency .card-head h2 { color: var(--err); }
.legacy-details > summary { cursor: pointer; list-style: none; }
.legacy-details > summary::-webkit-details-marker { display: none; }
.legacy-details:not([open]) > summary { border-bottom: 0; }

.portal { background: var(--bg); min-height: 100vh; display: flex; flex-direction: column; }
.portal-top { background: var(--navy-800); color: #fff; display: flex; align-items: center; justify-content: space-between; padding: 12px 20px; }
.portal-top form { margin: 0; }
.portal-brand { display: flex; align-items: center; gap: 10px; color: #fff; }
.portal-brand:hover { color: #fff; }
.portal-brand img { border-radius: 50%; box-shadow: 0 0 0 2px #fff; }
.portal-brand span { display: flex; flex-direction: column; line-height: 1.25; }
.portal-brand small { color: #a9c6d8; font-size: 11.5px; }
.portal-nav { display: flex; gap: 4px; background: var(--surface); border-bottom: 1px solid var(--line); padding: 0 12px; overflow-x: auto; }
.portal-nav a { display: inline-flex; align-items: center; gap: 6px; padding: 14px 14px 12px; color: var(--ink-2); font-weight: 700; border-bottom: 3px solid transparent; white-space: nowrap; }
.portal-nav a.is-on { color: var(--navy-800); border-bottom-color: var(--teal-500); }
.portal-main { max-width: 960px; margin: 0 auto; }
.portal-card { max-width: 440px; width: 100%; margin: 24px auto; padding: 28px; display: flex; flex-direction: column; gap: 14px; }
.portal-card h1 { font-size: 22px; color: var(--navy-900); text-align: center; }
.portal-card > .muted { text-align: center; }
.portal-logo { margin: 0 auto; border-radius: 50%; box-shadow: 0 0 0 4px #fff, 0 8px 20px rgba(3,40,60,.18); }
.portal-hello { display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }
.portal-hello h1 { font-size: 22px; color: var(--navy-900); }
.share-new { padding: 22px; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 12px; border: 2px solid var(--teal-500); }

.slip-page { background: #e9eef2; padding: 24px; }
.slip-tools { max-width: 720px; margin: 0 auto 16px; display: flex; gap: 10px; }
.slip { max-width: 720px; margin: 0 auto; background: #fff; padding: 36px 40px; border-radius: 4px; box-shadow: var(--sh-2); display: flex; flex-direction: column; gap: 16px; font-size: 15px; }
.slip header { display: flex; align-items: center; gap: 16px; padding-bottom: 14px; border-bottom: 3px solid var(--navy-800); }
.slip header img { border-radius: 50%; }
.slip header small { color: var(--muted); }
.slip header h1 { font-size: 20px; color: var(--navy-900); }
.slip header p { color: var(--teal-600); font-weight: 700; }
.slip ol { margin: 0; padding-inline-start: 22px; display: flex; flex-direction: column; gap: 6px; }
.slip-code { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 18px; border: 2px dashed var(--navy-600); border-radius: 14px; background: var(--navy-50); }
.slip-code b { font-size: 34px; letter-spacing: .14em; color: var(--navy-900); font-family: ui-monospace, Consolas, monospace; }
.slip-code small { color: var(--muted); }
.slip-warn { font-size: 13px; color: var(--err); font-weight: 700; }
.slip footer { display: flex; justify-content: space-between; color: var(--muted); font-size: 13px; border-top: 1px solid var(--line); padding-top: 10px; }
@media print { .slip-page { background: #fff; padding: 0; } .slip { box-shadow: none; } .no-print { display: none !important; } }

/* =================== المرحلة 5: التقارير الرسمية (A4) =================== */
.report-page { background: #e6ebef; padding: 20px; }
.report-tools { max-width: 210mm; margin: 0 auto 14px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.report { width: 210mm; max-width: 100%; min-height: 297mm; margin: 0 auto; background: #fff; padding: 14mm 14mm 12mm; box-shadow: var(--sh-2); font-size: 12.5px; color: #111; display: flex; flex-direction: column; gap: 10px; }
.rp-head { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 12px; padding-bottom: 10px; border-bottom: 3px double var(--navy-800); }
.rp-head img { border-radius: 50%; }
.rp-org { display: flex; flex-direction: column; font-size: 13px; color: var(--navy-900); }
.rp-org span { color: #444; font-size: 12px; margin-top: 2px; }
.rp-meta { display: flex; flex-direction: column; align-items: flex-end; font-size: 11.5px; color: #333; text-align: left; }
.rp-title { text-align: center; padding: 4px 0 2px; }
.rp-title h1 { font-size: 19px; color: var(--navy-900); }
.rp-title p { color: #444; font-size: 12.5px; }
.rp-box { break-inside: avoid; }
.rp-box h2 { font-size: 13.5px; color: #fff; background: var(--navy-800); padding: 4px 10px; border-radius: 4px; margin-bottom: 6px; }
.rp-box p { margin: 4px 0; }
.rp-kv, .rp-table { width: 100%; border-collapse: collapse; }
.rp-kv th, .rp-kv td, .rp-table th, .rp-table td { border: 1px solid #b9c6d0; padding: 4px 7px; text-align: right; vertical-align: top; }
.rp-kv th, .rp-table th { background: #eef3f7; font-weight: 700; white-space: nowrap; }
.rp-kv th { width: 15%; }
.rp-sum td, .rp-sum th { text-align: center; }
.rp-list td { font-size: 11.5px; }
.rp-flag { font-weight: 800; }
.rp-visit { padding: 5px 0; border-bottom: 1px dashed #c8d2da; }
.rp-visit:last-child { border-bottom: 0; }
.rp-sign { margin-top: auto; display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; padding-top: 16px; break-inside: avoid; }
.rp-sign div { display: flex; flex-direction: column; gap: 6px; text-align: center; }
.rp-sign span { font-weight: 700; color: var(--navy-900); }
.rp-sign b { min-height: 18px; }
.rp-sign i { font-style: normal; color: #555; border-bottom: 1px dotted #888; padding-bottom: 14px; text-align: right; }
.rp-foot { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; font-size: 10.5px; color: #555; border-top: 1px solid #b9c6d0; padding-top: 6px; }
@page { size: A4; margin: 0; }
@media print {
  .report-page { background: #fff; padding: 0; }
  .report { box-shadow: none; width: auto; min-height: 297mm; margin: 0; }
  .report-tools { display: none !important; }
  .rp-box h2 { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .rp-kv th, .rp-table th { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
@media screen and (max-width: 800px) { .report { padding: 16px; min-height: 0; font-size: 12px; } .rp-head { grid-template-columns: 1fr; text-align: center; } .rp-meta { align-items: center; } .rp-sign { grid-template-columns: 1fr; } }
