/* ===== لوحة الألوان الطبية: الأبيض، الأزرق الفاتح، الأخضر الطبي ===== */
:root {
  --white: #ffffff;
  --bg: #f3f9fd;            /* أبيض مائل للأزرق */
  --blue-50: #eaf5fc;
  --blue-100: #d4ebf8;
  --blue-200: #a9d6f0;
  --blue-400: #4fb0e0;
  --blue-600: #0b7fb3;
  --blue-800: #0a4f70;
  --green-50: #e8f8f2;
  --green-100: #c9eedf;
  --green-400: #2fbf8a;
  --green-600: #14966a;
  --green-800: #0d5f45;
  --text: #133447;
  --muted: #557286;
  --border: #d8e8f2;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(11, 79, 112, .06), 0 6px 20px rgba(11, 79, 112, .07);
  --shadow-lg: 0 20px 60px rgba(11, 79, 112, .22);
  font-family: "IBM Plex Sans Arabic", "Segoe UI", Tahoma, sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background:
    radial-gradient(1200px 400px at 100% -10%, var(--blue-100), transparent 60%),
    radial-gradient(900px 400px at -10% 0%, var(--green-50), transparent 60%),
    var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}
h1, h2, h3 { margin: 0; line-height: 1.3; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }

.container { width: 100%; max-width: 1180px; margin: 0 auto; padding: 0 16px; }

/* ===== الشريط العلوي ===== */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: rgba(255, 255, 255, .88);
  backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-block: 12px; }
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-icon {
  width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--blue-600), var(--green-600));
  box-shadow: 0 6px 16px rgba(11, 127, 179, .3);
}
.brand-icon svg { width: 22px; height: 22px; fill: var(--white); stroke: none; }
.brand h1 { font-size: 1.15rem; color: var(--blue-800); }
.brand p { margin: 0; font-size: .82rem; color: var(--muted); }

/* ===== الأزرار ===== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font: inherit; font-weight: 600; font-size: .95rem;
  padding: 10px 18px; border-radius: 12px; border: 1px solid transparent;
  cursor: pointer; transition: background .15s, box-shadow .15s, transform .05s, border-color .15s;
  white-space: nowrap; min-height: 44px;
}
.btn:active { transform: translateY(1px); }
.btn:focus-visible, .icon-btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 3px solid var(--blue-200); outline-offset: 1px;
}
.btn-primary { background: var(--blue-600); color: var(--white); box-shadow: 0 4px 12px rgba(11, 127, 179, .25); }
.btn-primary:hover { background: var(--blue-800); }
.btn-ghost { background: var(--white); color: var(--blue-800); border-color: var(--border); }
.btn-ghost:hover { background: var(--blue-50); }
.btn-ai { background: linear-gradient(135deg, var(--green-600), var(--blue-600)); color: var(--white); width: 100%; }
.btn-ai:hover { filter: brightness(1.07); }
.btn-ai[disabled] { opacity: .7; cursor: progress; }
.btn-danger { background: var(--blue-800); color: var(--white); }
.btn-danger:hover { background: #083a52; }
.btn-danger-ghost { background: var(--white); color: var(--blue-800); border-color: var(--blue-200); }
.btn-danger-ghost:hover { background: var(--blue-50); }
.icon-btn {
  width: 40px; height: 40px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--white); color: var(--muted); cursor: pointer; font-size: 1rem;
  display: inline-grid; place-items: center;
}
.icon-btn:hover { background: var(--blue-50); color: var(--blue-800); }

/* ===== الإحصائيات ===== */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin: 20px 0 14px; }
.stat {
  background: var(--white); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; box-shadow: var(--shadow); display: flex; flex-direction: column;
  border-top: 3px solid var(--blue-400);
}
.stat:nth-child(2) { border-top-color: var(--green-400); }
.stat:nth-child(3) { border-top-color: var(--blue-600); }
.stat-num { font-size: 1.6rem; font-weight: 700; color: var(--blue-800); }
.stat-label { font-size: .82rem; color: var(--muted); }

/* ===== التصفية ===== */
.card { background: var(--white); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.filters { padding: 14px; display: grid; gap: 12px; }
.search-wrap { position: relative; }
.search-wrap svg { position: absolute; inset-inline-start: 14px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.search-wrap input { padding-inline-start: 44px; }
.filter-row { display: grid; grid-template-columns: 2fr 1fr 1fr 1fr auto; gap: 10px; align-items: end; }
.field-sm { display: grid; gap: 4px; font-size: .8rem; color: var(--muted); font-weight: 500; }

input, select, textarea {
  font: inherit; color: var(--text); width: 100%;
  background: var(--white); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 10px 12px; min-height: 44px; transition: border-color .15s, box-shadow .15s;
}
textarea { resize: vertical; min-height: 64px; }
input:focus, select:focus, textarea:focus { border-color: var(--blue-400); outline: none; box-shadow: 0 0 0 3px var(--blue-100); }
input[type="date"] { direction: rtl; }
input.invalid, select.invalid { border-color: var(--blue-800); box-shadow: 0 0 0 3px var(--blue-100); background: var(--blue-50); }

.result-count { color: var(--muted); font-size: .88rem; margin: 16px 2px 10px; }

/* ===== بطاقات الحالات ===== */
.cases-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 14px; padding-bottom: 40px; }
.case-card {
  background: var(--white); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px; display: flex; flex-direction: column; gap: 10px;
  cursor: pointer; transition: transform .15s, box-shadow .15s, border-color .15s;
  position: relative; overflow: hidden;
}
.case-card::before {
  content: ""; position: absolute; inset-block: 0; inset-inline-start: 0; width: 4px;
  background: linear-gradient(var(--blue-400), var(--green-400));
}
.case-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); border-color: var(--blue-200); }
.case-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.patient-id { font-weight: 700; color: var(--blue-800); font-size: 1.02rem; direction: ltr; unicode-bidi: plaintext; }
.case-date { font-size: .8rem; color: var(--muted); white-space: nowrap; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font-size: .76rem; padding: 3px 10px; border-radius: 999px; background: var(--blue-50); color: var(--blue-800); border: 1px solid var(--blue-100); }
.chip-green { background: var(--green-50); color: var(--green-800); border-color: var(--green-100); }
.complaint { font-weight: 600; font-size: 1rem; }
.diagnosis { font-size: .88rem; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.diagnosis b { color: var(--green-800); font-weight: 600; }
.case-actions { display: flex; gap: 8px; margin-top: auto; padding-top: 6px; border-top: 1px dashed var(--border); }
.case-actions .btn { flex: 1; min-height: 38px; padding: 6px 10px; font-size: .86rem; }

/* ===== الحالة الفارغة ===== */
.empty { text-align: center; padding: 50px 16px 70px; color: var(--muted); }
.empty-icon { width: 72px; height: 72px; margin: 0 auto 14px; border-radius: 20px; display: grid; place-items: center; background: var(--green-50); }
.empty-icon svg { width: 34px; height: 34px; fill: var(--green-400); stroke: none; }
.empty h2 { color: var(--blue-800); font-size: 1.2rem; margin-bottom: 6px; }
.empty p { margin: 0 0 18px; }

/* ===== النوافذ ===== */
.modal {
  border: none; padding: 0; border-radius: 20px; width: min(760px, calc(100% - 24px));
  max-height: calc(100dvh - 32px); box-shadow: var(--shadow-lg); background: var(--white); color: var(--text);
}
.modal-sm { width: min(420px, calc(100% - 24px)); }
.modal::backdrop { background: rgba(10, 79, 112, .35); backdrop-filter: blur(3px); }
.modal[open] { animation: pop .18s ease-out; }
@keyframes pop { from { opacity: 0; transform: translateY(10px) scale(.98); } }
.modal-inner { display: flex; flex-direction: column; max-height: calc(100dvh - 32px); }
.modal-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
  background: linear-gradient(90deg, var(--blue-50), var(--green-50));
}
.modal-head h2 { font-size: 1.15rem; color: var(--blue-800); }
.modal-body { padding: 18px 20px; overflow-y: auto; display: grid; gap: 16px; }
.modal-body.center { text-align: center; justify-items: center; gap: 8px; }
.modal-body.center p { margin: 0; color: var(--muted); }
.modal-foot { display: flex; justify-content: flex-start; gap: 10px; padding: 14px 20px; border-top: 1px solid var(--border); background: var(--white); }
.modal-foot .btn { min-width: 110px; }
.confirm-icon { width: 56px; height: 56px; border-radius: 50%; display: grid; place-items: center; font-size: 1.6rem; font-weight: 700; background: var(--blue-50); color: var(--blue-800); border: 2px solid var(--blue-200); }

fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; margin: 0; display: grid; gap: 12px; min-width: 0; }
legend { padding: 0 8px; font-weight: 700; color: var(--blue-600); display: flex; align-items: center; gap: 6px; }
.field { display: grid; gap: 5px; font-size: .9rem; font-weight: 500; min-width: 0; }
.req { color: var(--green-600); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid-3 { display: grid; grid-template-columns: 1.4fr 1fr 1fr; gap: 12px; }

.privacy-note { background: var(--green-50); border: 1px solid var(--green-100); color: var(--green-800); border-radius: var(--radius-sm); padding: 10px 14px; font-size: .88rem; }

/* ===== الذكاء الاصطناعي ===== */
.ai-box { background: linear-gradient(180deg, var(--blue-50), var(--white)); border-color: var(--blue-200); }
.ai-badge { background: linear-gradient(135deg, var(--green-600), var(--blue-600)); color: var(--white); font-size: .72rem; padding: 2px 8px; border-radius: 6px; letter-spacing: .5px; }
.disclaimer {
  background: var(--white); border: 2px solid var(--blue-400); border-inline-start-width: 6px;
  border-radius: var(--radius-sm); padding: 12px 14px; font-size: .88rem; color: var(--blue-800);
}
.disclaimer strong { color: var(--blue-800); }
.ai-result { display: grid; gap: 12px; }
.ai-section { background: var(--white); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px 14px; }
.ai-section h3 { font-size: .95rem; color: var(--blue-600); margin-bottom: 8px; display: flex; align-items: center; gap: 8px; }
.ai-section h3 .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green-400); }
.ai-section ol, .ai-section ul { margin: 0; padding-inline-start: 22px; display: grid; gap: 6px; }
.ai-section li { font-size: .9rem; }
.ai-section li small { display: block; color: var(--muted); }
.ai-section.flags { border-color: var(--blue-400); background: var(--blue-50); }
.ai-meta { font-size: .76rem; color: var(--muted); text-align: center; }
.ai-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.ai-actions .btn { flex: 1; min-height: 38px; font-size: .86rem; }
.ai-error { background: var(--blue-50); border: 1px solid var(--blue-200); border-radius: var(--radius-sm); padding: 10px 14px; color: var(--blue-800); font-size: .9rem; }
.spinner { width: 18px; height: 18px; border: 2.5px solid rgba(255,255,255,.4); border-top-color: var(--white); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== عرض التفاصيل ===== */
.detail-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.detail-box { background: var(--blue-50); border-radius: var(--radius-sm); padding: 10px 12px; }
.detail-box span { display: block; font-size: .76rem; color: var(--muted); }
.detail-box strong { color: var(--blue-800); }
.detail-section h3 { font-size: .9rem; color: var(--blue-600); margin-bottom: 4px; }
.detail-section p { margin: 0; white-space: pre-wrap; background: var(--white); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 12px; font-size: .93rem; }
.detail-section p.empty-val { color: var(--muted); font-style: italic; }

/* ===== الإشعار ===== */
.toast {
  position: fixed; bottom: 20px; inset-inline: 0; margin: 0 auto; width: max-content; max-width: calc(100% - 32px);
  background: var(--green-800); color: var(--white); padding: 12px 20px; border-radius: 12px;
  box-shadow: var(--shadow-lg); font-weight: 500; z-index: 100;
  opacity: 0; transform: translateY(20px); pointer-events: none; transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: none; }
.toast.error { background: var(--blue-800); }

/* ===== الهاتف ===== */
@media (max-width: 820px) {
  .filter-row { grid-template-columns: 1fr 1fr; }
  .filter-row .field-sm:first-child { grid-column: 1 / -1; }
  .filter-row .btn { grid-column: 1 / -1; }
}
@media (max-width: 560px) {
  .brand p { display: none; }
  .brand h1 { font-size: 1rem; }
  #addBtn span { display: none; }
  #addBtn { padding: 10px 12px; }
  .stats { gap: 8px; }
  .stat { padding: 10px 12px; }
  .stat-num { font-size: 1.3rem; }
  .stat-label { font-size: .72rem; }
  .cases-grid { grid-template-columns: 1fr; }
  .grid-2, .grid-3, .detail-grid { grid-template-columns: 1fr 1fr; }
  .grid-3 .field:first-child { grid-column: 1 / -1; }
  .grid-2 .field:last-child { grid-column: 1 / -1; }
  .modal { width: 100%; max-width: 100%; max-height: 100dvh; height: 100dvh; border-radius: 0; margin: 0; }
  .modal-inner { max-height: 100dvh; height: 100%; }
  .modal-body { flex: 1; padding: 14px; }
  .modal-foot .btn { flex: 1; min-width: 0; }
  .modal-sm { height: auto; border-radius: 20px; width: calc(100% - 24px); margin: auto; }
}

/* ===== تسجيل الدخول ===== */
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.login-error { color: var(--blue-800); font-weight: 600; min-height: 1.4em; }
#loginDialog .modal-sm, #loginDialog { height: auto; }
@media (max-width: 560px) { #loginDialog { border-radius: 20px; width: calc(100% - 24px); margin: auto; height: auto; } }
