/* ============ نظام تصميم منصة مراقبة العدوى ============ */
:root {
  --primary: #0d5c63;
  --primary-dark: #094448;
  --primary-light: #1a7a82;
  --accent: #14b8a6;
  --accent-2: #0ea5e9;
  --sidebar-bg: #0a3d42;
  --sidebar-active: #14b8a6;
  --bg: #f1f5f6;
  --surface: #ffffff;
  --text: #1e293b;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --green: #16a34a;
  --yellow: #eab308;
  --orange: #f97316;
  --red: #dc2626;
  --shadow-sm: 0 1px 3px rgba(0,0,0,.06);
  --shadow: 0 4px 20px rgba(13,92,99,.08);
  --shadow-lg: 0 12px 40px rgba(13,92,99,.14);
  --radius: 16px;
  --radius-sm: 10px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }
body {
  font-family: 'IBM Plex Sans Arabic', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
}
a { text-decoration: none; color: inherit; }

/* ============ التخطيط العام ============ */
#app-root { display: flex; min-height: 100vh; }

/* الشريط الجانبي */
#sidebar {
  width: 270px;
  background: linear-gradient(180deg, var(--sidebar-bg) 0%, #072e32 100%);
  color: #e2f5f3;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; right: 0; bottom: 0;
  z-index: 100;
  transition: transform .3s ease;
}
.brand {
  display: flex; align-items: center; gap: 14px;
  padding: 24px 22px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.brand-logo {
  width: 46px; height: 46px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border-radius: 13px;
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; color: #fff;
  box-shadow: 0 6px 18px rgba(20,184,166,.35);
}
.brand-text h1 { font-size: 18px; font-weight: 700; color: #fff; }
.brand-text p { font-size: 11px; color: #7dd3cf; letter-spacing: .5px; }

.nav-menu { padding: 18px 14px; display: flex; flex-direction: column; gap: 6px; flex: 1; }
.nav-link {
  display: flex; align-items: center; gap: 13px;
  padding: 12px 16px;
  border-radius: 12px;
  color: #b6dbd8;
  font-weight: 500;
  transition: all .2s;
  position: relative;
}
.nav-link i { width: 20px; text-align: center; font-size: 16px; }
.nav-link:hover { background: rgba(255,255,255,.07); color: #fff; }
.nav-link.active {
  background: linear-gradient(135deg, var(--accent), var(--primary-light));
  color: #fff;
  box-shadow: 0 6px 16px rgba(20,184,166,.3);
}
.nav-link.active::before {
  content: ''; position: absolute; right: -14px; top: 50%; transform: translateY(-50%);
  width: 4px; height: 26px; background: var(--accent); border-radius: 4px;
}

.sidebar-footer { padding: 16px; border-top: 1px solid rgba(255,255,255,.08); }
.region-badge {
  display: flex; align-items: center; gap: 12px;
  background: rgba(255,255,255,.06); padding: 12px 14px; border-radius: 12px;
}
.region-badge i { color: var(--accent); font-size: 18px; }
.region-badge > div { display: flex; flex-direction: column; }
.region-label { font-size: 13px; font-weight: 600; color: #fff; }
.region-sub { font-size: 11px; color: #7dd3cf; }

/* المحتوى الرئيسي */
#main { flex: 1; margin-right: 270px; min-width: 0; display: flex; flex-direction: column; }

#topbar {
  height: 70px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 16px;
  padding: 0 26px;
  position: sticky; top: 0; z-index: 50;
  box-shadow: var(--shadow-sm);
}
.menu-toggle { display: none; background: none; border: none; font-size: 20px; color: var(--text); cursor: pointer; }
.topbar-title h2 { font-size: 19px; font-weight: 700; color: var(--primary-dark); }
.page-subtitle { font-size: 12px; color: var(--text-muted); }
.topbar-right { margin-right: auto; display: flex; align-items: center; gap: 14px; }
.report-period, .user-chip {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 14px; border-radius: 20px; font-size: 12.5px; font-weight: 500;
}
.report-period { background: #e0f2f1; color: var(--primary); }
.user-chip { background: #f1f5f9; color: var(--text-muted); }
.user-chip i { color: var(--primary); }

#content { padding: 26px; flex: 1; }

/* ============ شاشة التحميل ============ */
.loading-screen { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 80px; color: var(--text-muted); gap: 16px; }
.spinner {
  width: 44px; height: 44px; border: 4px solid var(--border);
  border-top-color: var(--accent); border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ============ البطاقات الإحصائية ============ */
.page-head { margin-bottom: 22px; }
.page-head h3 { font-size: 22px; font-weight: 700; color: var(--primary-dark); }
.page-head p { color: var(--text-muted); font-size: 13.5px; margin-top: 4px; }

.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 18px; margin-bottom: 24px; }
.stat-card {
  background: var(--surface); border-radius: var(--radius); padding: 22px;
  box-shadow: var(--shadow); position: relative; overflow: hidden;
  border: 1px solid var(--border);
  transition: transform .25s, box-shadow .25s;
}
.stat-card:hover { transform: translateY(-4px); box-shadow: var(--shadow-lg); }
.stat-card::after {
  content: ''; position: absolute; left: -20px; bottom: -20px;
  width: 90px; height: 90px; border-radius: 50%; opacity: .08;
  background: var(--card-color, var(--primary));
}
.stat-icon {
  width: 52px; height: 52px; border-radius: 14px;
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; color: #fff; margin-bottom: 14px;
  background: var(--card-color, var(--primary));
  box-shadow: 0 8px 20px color-mix(in srgb, var(--card-color, var(--primary)) 35%, transparent);
}
.stat-value { font-size: 30px; font-weight: 700; color: var(--text); line-height: 1; }
.stat-label { color: var(--text-muted); font-size: 13px; margin-top: 6px; }
.stat-trend { font-size: 11.5px; margin-top: 8px; display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: 12px; font-weight: 600; }

/* ============ الشبكة والبطاقات العامة ============ */
.card {
  background: var(--surface); border-radius: var(--radius); padding: 22px;
  box-shadow: var(--shadow); border: 1px solid var(--border); margin-bottom: 20px;
}
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; flex-wrap: wrap; gap: 12px; }
.card-head h4 { font-size: 16px; font-weight: 700; color: var(--primary-dark); display: flex; align-items: center; gap: 10px; }
.card-head h4 i { color: var(--accent); }
.grid-2 { display: grid; grid-template-columns: 1.4fr 1fr; gap: 20px; }
.grid-2-eq { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
@media (max-width: 1100px) { .grid-2, .grid-2-eq { grid-template-columns: 1fr; } }

.chart-box { position: relative; height: 300px; }
.chart-box.tall { height: 340px; }

/* ============ الجداول ============ */
.table-wrap { overflow-x: auto; border-radius: var(--radius-sm); border: 1px solid var(--border); }
table.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data-table thead th {
  background: linear-gradient(180deg, #eef6f6, #e3eff0);
  color: var(--primary-dark); font-weight: 600; padding: 13px 12px;
  text-align: center; white-space: nowrap; border-bottom: 2px solid var(--border);
  position: sticky; top: 0;
}
table.data-table tbody td { padding: 11px 12px; text-align: center; border-bottom: 1px solid #f1f5f9; }
table.data-table tbody tr:hover { background: #f8fafc; }
table.data-table tbody tr:nth-child(even) { background: #fbfdfd; }
.hospital-cell { text-align: right !important; font-weight: 600; color: var(--text); }
.code-badge { display: inline-block; background: #e0f2f1; color: var(--primary); padding: 2px 8px; border-radius: 6px; font-size: 11px; font-weight: 600; }

/* خلايا المناطق (Zones) */
.zone-cell { font-weight: 700; border-radius: 6px; padding: 4px 8px; min-width: 48px; display: inline-block; }
.zone-green { background: #dcfce7; color: #15803d; }
.zone-yellow { background: #fef9c3; color: #a16207; }
.zone-orange { background: #ffedd5; color: #c2410c; }
.zone-red { background: #fee2e2; color: #b91c1c; }
.zone-dot { width: 11px; height: 11px; border-radius: 50%; display: inline-block; }

/* ============ الأزرار ============ */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 18px; border-radius: 10px; font-family: inherit;
  font-size: 13.5px; font-weight: 600; cursor: pointer; border: none;
  transition: all .2s;
}
.btn-primary { background: linear-gradient(135deg, var(--primary), var(--primary-light)); color: #fff; box-shadow: 0 6px 16px rgba(13,92,99,.25); }
.btn-primary:hover { transform: translateY(-2px); box-shadow: 0 8px 22px rgba(13,92,99,.35); }
.btn-accent { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; box-shadow: 0 6px 16px rgba(20,184,166,.28); }
.btn-accent:hover { transform: translateY(-2px); }
.btn-outline { background: var(--surface); color: var(--primary); border: 1.5px solid var(--primary); }
.btn-outline:hover { background: var(--primary); color: #fff; }
.btn-ghost { background: #f1f5f9; color: var(--text); }
.btn-ghost:hover { background: #e2e8f0; }
.btn-sm { padding: 7px 13px; font-size: 12px; }
.btn-danger { background: #fef2f2; color: var(--red); }
.btn-danger:hover { background: var(--red); color: #fff; }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none !important; }

/* ============ النماذج ============ */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px; }
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group label { font-size: 13px; font-weight: 600; color: var(--text); }
.form-group label .req { color: var(--red); }
.form-control {
  padding: 11px 13px; border: 1.5px solid var(--border); border-radius: 10px;
  font-family: inherit; font-size: 13.5px; background: #fff; transition: all .2s; color: var(--text);
}
.form-control:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(20,184,166,.12); }
select.form-control { cursor: pointer; }

/* ============ قائمة الأحداث (كما في الصورة) ============ */
.events-toolbar { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-bottom: 18px; }
.search-box { position: relative; flex: 1; min-width: 220px; }
.search-box i { position: absolute; right: 14px; top: 50%; transform: translateY(-50%); color: var(--text-muted); }
.search-box input { width: 100%; padding: 11px 42px 11px 14px; border: 1.5px solid var(--border); border-radius: 10px; font-family: inherit; font-size: 13.5px; }
.search-box input:focus { outline: none; border-color: var(--accent); }

.type-badge { display: inline-block; padding: 4px 12px; border-radius: 20px; font-size: 11.5px; font-weight: 600; white-space: nowrap; }
.type-clabsi { background: #fee2e2; color: #b91c1c; }
.type-vae { background: #dbeafe; color: #1d4ed8; }
.type-cauti { background: #fef3c7; color: #b45309; }
.type-ssi { background: #f3e8ff; color: #7e22ce; }
.type-dialysis { background: #ccfbf1; color: #0f766e; }
.type-none { background: #f1f5f9; color: #64748b; }
.patient-link { color: var(--accent-2); font-weight: 600; cursor: pointer; }
.patient-link:hover { text-decoration: underline; }

/* ============ النوافذ المنبثقة ============ */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(15,23,42,.5); backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center; z-index: 200; padding: 20px;
  animation: fadeIn .2s;
}
.modal {
  background: #fff; border-radius: 20px; width: 100%; max-width: 720px;
  max-height: 90vh; overflow-y: auto; box-shadow: var(--shadow-lg);
  animation: slideUp .3s;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 22px 26px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: #fff; z-index: 2; }
.modal-head h3 { font-size: 18px; color: var(--primary-dark); font-weight: 700; }
.modal-close { background: #f1f5f9; border: none; width: 36px; height: 36px; border-radius: 10px; cursor: pointer; font-size: 16px; color: var(--text-muted); }
.modal-close:hover { background: #fee2e2; color: var(--red); }
.modal-body { padding: 26px; }
.modal-foot { padding: 18px 26px; border-top: 1px solid var(--border); display: flex; gap: 12px; justify-content: flex-start; position: sticky; bottom: 0; background: #fff; }
@keyframes fadeIn { from { opacity: 0; } }
@keyframes slideUp { from { transform: translateY(30px); opacity: 0; } }

/* ============ إشعارات Toast ============ */
#toast-root { position: fixed; bottom: 24px; left: 24px; z-index: 300; display: flex; flex-direction: column; gap: 10px; }
.toast {
  background: #fff; padding: 14px 20px; border-radius: 12px; box-shadow: var(--shadow-lg);
  display: flex; align-items: center; gap: 12px; font-weight: 500; min-width: 260px;
  border-right: 4px solid var(--accent); animation: slideIn .3s;
}
.toast.success { border-right-color: var(--green); }
.toast.success i { color: var(--green); }
.toast.error { border-right-color: var(--red); }
.toast.error i { color: var(--red); }
.toast.info i { color: var(--accent-2); }
@keyframes slideIn { from { transform: translateX(-40px); opacity: 0; } }

/* ============ تبويبات التقرير ============ */
.module-tabs { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 6px; margin-bottom: 18px; }
.module-tab {
  padding: 10px 18px; border-radius: 12px; background: var(--surface); border: 1.5px solid var(--border);
  cursor: pointer; font-weight: 600; font-size: 13px; white-space: nowrap; color: var(--text-muted);
  transition: all .2s; display: flex; align-items: center; gap: 8px;
}
.module-tab:hover { border-color: var(--accent); color: var(--primary); }
.module-tab.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.module-tab .tab-count { background: rgba(255,255,255,.25); padding: 1px 8px; border-radius: 10px; font-size: 11px; }
.module-tab:not(.active) .tab-count { background: #e0f2f1; color: var(--primary); }

/* شريط أسطورة المناطق */
.zone-legend { display: flex; gap: 14px; flex-wrap: wrap; align-items: center; font-size: 12px; }
.zone-legend .lg { display: flex; align-items: center; gap: 6px; }

/* جدول التقرير المخصص */
.report-title-bar {
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  color: #fff; padding: 14px 20px; border-radius: 12px 12px 0 0;
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px;
}
.report-title-bar h4 { color: #fff; font-size: 16px; }
.report-title-bar .zone-scale { display: flex; gap: 0; border-radius: 8px; overflow: hidden; font-size: 11px; }
.report-title-bar .zone-scale span { padding: 4px 10px; color: #fff; font-weight: 600; }

/* منطقة الرفع */
.dropzone {
  border: 2.5px dashed var(--border); border-radius: 16px; padding: 46px 20px;
  text-align: center; cursor: pointer; transition: all .25s; background: #fafcfc;
}
.dropzone:hover, .dropzone.dragover { border-color: var(--accent); background: #f0fdfa; }
.dropzone i { font-size: 46px; color: var(--accent); margin-bottom: 14px; }
.dropzone h4 { font-size: 17px; color: var(--text); margin-bottom: 6px; }
.dropzone p { color: var(--text-muted); font-size: 13px; }
.import-result { margin-top: 20px; }

.mini-badge { font-size: 11px; padding: 2px 8px; border-radius: 8px; background: #f1f5f9; color: var(--text-muted); }
.pill-num { font-weight: 700; }
.empty-state { text-align: center; padding: 50px; color: var(--text-muted); }
.empty-state i { font-size: 48px; color: var(--border); margin-bottom: 14px; }

.editable-cell { cursor: pointer; border-radius: 6px; }
.editable-cell:hover { background: #e0f2f1 !important; outline: 1.5px solid var(--accent); }
.cell-input { width: 56px; text-align: center; padding: 6px; border: 1.5px solid var(--accent); border-radius: 6px; font-family: inherit; }

/* ============ التجاوب ============ */
@media (max-width: 900px) {
  #sidebar { transform: translateX(100%); box-shadow: var(--shadow-lg); }
  #sidebar.open { transform: translateX(0); }
  #main { margin-right: 0; }
  .menu-toggle { display: block; }
  .topbar-right .user-chip span { display: none; }
  .grid-2, .grid-2-eq { grid-template-columns: 1fr; }
}

/* أنماط الطباعة / PDF */
.print-report { background: #fff; padding: 20px; }
.print-report table { font-size: 10px; }

/* ===== رسوم التقرير البيانية (Report Charts) ===== */
.report-charts { margin-top: 18px; display: flex; flex-direction: column; gap: 16px; }
.chart-card {
  background: #fff; border: 1px solid var(--line);
  border-radius: 14px; padding: 16px 18px 18px;
  box-shadow: 0 2px 10px rgba(13,92,99,.05);
}
.chart-card.wide { width: 100%; }
.charts-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 900px) { .charts-row { grid-template-columns: 1fr; } }
.chart-card-head {
  display: flex; justify-content: space-between; align-items: center;
  flex-wrap: wrap; gap: 10px; margin-bottom: 14px;
  padding-bottom: 10px; border-bottom: 1px dashed var(--line);
}
.chart-card-head h5 { font-size: 14px; color: var(--primary); font-weight: 700; margin: 0; }
.zone-legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 11px; color: #475569; }
.zone-legend span { display: inline-flex; align-items: center; gap: 5px; }
.zone-legend i { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
