/* ═══════════ نظام تقارير قسم المراقبة — تصميم مودرن ═══════════ */
* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --bg: #f4f5fa;
  --card: #ffffff;
  --line: #e8eaf2;
  --primary: #4f46e5;
  --primary-2: #6d28d9;
  --primary-soft: #eef2ff;
  --accent: #10b981;
  --danger: #f43f5e;
  --warn: #f59e0b;
  --text: #0f172a;
  --muted: #64748b;
  --side-w: 248px;
  --radius: 16px;
  --shadow: 0 1px 3px rgba(15,23,42,.05), 0 8px 24px -12px rgba(15,23,42,.10);
  --shadow-lg: 0 12px 40px -12px rgba(79,70,229,.35);
}
html { scroll-behavior: smooth; }
body {
  font-family: "Tajawal", "Segoe UI", Tahoma, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* ═══════════ الهيكل: قائمة جانبية + محتوى ═══════════ */
.app { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--side-w);
  flex-shrink: 0;
  background: linear-gradient(180deg, #111033 0%, #1e1b4b 55%, #312e81 130%);
  color: #e0e7ff;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 22px 14px 16px;
  z-index: 50;
}
.side-brand { display: flex; align-items: center; gap: 12px; padding: 0 8px 20px; }
.side-brand .logo {
  width: 44px; height: 44px; border-radius: 14px; flex-shrink: 0;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  display: flex; align-items: center; justify-content: center;
  font-size: 21px; box-shadow: 0 6px 18px -4px rgba(99,102,241,.55);
}
.side-brand .btxt { font-weight: 800; font-size: 16px; line-height: 1.25; }
.side-brand .btxt small { display: block; font-weight: 500; font-size: 11px; color: #a5b4fc; }

.side-nav { flex: 1; display: flex; flex-direction: column; gap: 3px; overflow-y: auto; scrollbar-width: thin; }
.side-nav a {
  display: flex; align-items: center; gap: 12px;
  color: #c7d2fe; text-decoration: none;
  padding: 10.5px 13px; border-radius: 12px;
  font-size: 14px; font-weight: 500;
  transition: background .18s, color .18s, transform .18s;
}
.side-nav a .ic { font-size: 17px; width: 24px; text-align: center; filter: grayscale(35%); transition: filter .18s, transform .18s; }
.side-nav a:hover { background: rgba(255,255,255,.07); color: #fff; }
.side-nav a:hover .ic { filter: none; transform: scale(1.12); }
.side-nav a.active {
  background: linear-gradient(90deg, rgba(99,102,241,.95), rgba(139,92,246,.85));
  color: #fff; font-weight: 700;
  box-shadow: 0 6px 16px -6px rgba(99,102,241,.6);
}
.side-nav a.active .ic { filter: none; }

.side-user {
  display: flex; align-items: center; gap: 10px;
  background: rgba(255,255,255,.06);
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 14px; padding: 10px 12px; margin-top: 14px;
}
.side-user .avatar {
  width: 36px; height: 36px; border-radius: 50%; flex-shrink: 0;
  background: linear-gradient(135deg, #f59e0b, #f43f5e);
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 15px; color: #fff;
}
.side-user .uinfo { flex: 1; min-width: 0; line-height: 1.3; }
.side-user .uinfo b { display: block; font-size: 13px; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.side-user .uinfo small { font-size: 11px; color: #a5b4fc; }
.side-user .logout { color: #fda4af; text-decoration: none; font-size: 18px; padding: 4px; border-radius: 8px; transition: background .15s; }
.side-user .logout:hover { background: rgba(244,63,94,.18); }

.main-area { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.pagehead {
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  padding: 22px 30px 0;
}
.pagehead h1 { font-size: 22px; font-weight: 800; letter-spacing: -.3px; }
.pagehead .pdate {
  font-size: 12.5px; color: var(--muted); background: var(--card);
  border: 1px solid var(--line); padding: 7px 14px; border-radius: 999px; font-weight: 500;
}
.container { max-width: 1250px; width: 100%; margin: 0 auto; padding: 20px 30px 10px; animation: fadeUp .35s ease both; }
@keyframes fadeUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.foot { text-align: center; color: var(--muted); font-size: 12px; padding: 22px; }

/* ═══════════ البطاقات ═══════════ */
.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 24px; margin-bottom: 20px;
  box-shadow: var(--shadow);
}
.card h2 { font-size: 17px; font-weight: 800; margin-bottom: 16px; display: flex; align-items: center; gap: 9px; }
.card h3 { font-size: 14px; font-weight: 700; margin: 16px 0 10px; color: var(--primary); }

/* ═══════════ النماذج ═══════════ */
.grid { display: grid; gap: 14px; }
.g2 { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.g3 { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.g4 { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
label.fld { display: flex; flex-direction: column; gap: 6px; font-size: 12.5px; font-weight: 700; color: #475569; }
input[type=text], input[type=date], input[type=time], input[type=number], input[type=password], select, textarea {
  padding: 10px 13px; border: 1.5px solid var(--line); border-radius: 11px;
  font-size: 14px; font-family: inherit; background: #fbfcfe; width: 100%;
  transition: border-color .15s, box-shadow .15s, background .15s;
}
input:hover, select:hover, textarea:hover { border-color: #c7d2fe; }
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--primary); background: #fff;
  box-shadow: 0 0 0 4px rgba(99,102,241,.13);
}
textarea { min-height: 66px; resize: vertical; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  background: linear-gradient(135deg, #6366f1, #7c3aed);
  color: #fff; border: 0; padding: 10.5px 24px; border-radius: 11px;
  font-size: 14px; font-weight: 700; cursor: pointer; text-decoration: none; font-family: inherit;
  box-shadow: 0 4px 14px -4px rgba(99,102,241,.5);
  transition: transform .15s, box-shadow .15s, filter .15s;
}
.btn:hover { transform: translateY(-1.5px); filter: brightness(1.07); box-shadow: 0 8px 20px -6px rgba(99,102,241,.55); }
.btn:active { transform: translateY(0); }
.btn.green { background: linear-gradient(135deg, #10b981, #059669); box-shadow: 0 4px 14px -4px rgba(16,185,129,.5); }
.btn.green:hover { box-shadow: 0 8px 20px -6px rgba(16,185,129,.55); }
.btn.red { background: linear-gradient(135deg, #f43f5e, #e11d48); box-shadow: 0 4px 14px -4px rgba(244,63,94,.45); }
.btn.gray { background: linear-gradient(135deg, #64748b, #475569); box-shadow: 0 4px 14px -4px rgba(71,85,105,.4); }
.btn.sm { padding: 6px 14px; font-size: 12.5px; border-radius: 9px; }

/* ═══════════ الرسائل ═══════════ */
.flash { padding: 13px 18px; border-radius: 13px; margin-bottom: 18px; font-weight: 700; font-size: 13.5px; display: flex; align-items: center; gap: 8px; animation: fadeUp .3s ease both; }
.flash.ok { background: #ecfdf5; color: #047857; border: 1px solid #a7f3d0; }
.flash.ok::before { content: "✓"; width: 22px; height: 22px; border-radius: 50%; background: #10b981; color: #fff; display: inline-flex; align-items: center; justify-content: center; font-size: 12px; flex-shrink: 0; }
.flash.err { background: #fff1f2; color: #be123c; border: 1px solid #fecdd3; }
.flash.err::before { content: "!"; width: 22px; height: 22px; border-radius: 50%; background: #f43f5e; color: #fff; display: inline-flex; align-items: center; justify-content: center; font-size: 13px; flex-shrink: 0; }

/* ═══════════ الجداول ═══════════ */
.tbl-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 13px; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.tbl th {
  background: #f8fafc; color: #475569; padding: 11px 13px; text-align: right;
  border-bottom: 1px solid var(--line); white-space: nowrap;
  font-size: 12px; font-weight: 800; letter-spacing: .2px;
}
.tbl td { padding: 10px 13px; border-bottom: 1px solid #f1f3f9; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl tbody tr, .tbl tr { transition: background .12s; }
.tbl tr:hover td { background: #f7f8ff; }
.tbl .num { text-align: center; }

/* ═══════════ الشارات ═══════════ */
.badge { display: inline-flex; align-items: center; padding: 4px 11px; border-radius: 999px; font-size: 11.5px; font-weight: 800; letter-spacing: .2px; }
.badge.ok { background: #ecfdf5; color: #047857; box-shadow: inset 0 0 0 1px #a7f3d0; }
.badge.bad { background: #fff1f2; color: #be123c; box-shadow: inset 0 0 0 1px #fecdd3; }
.badge.warn { background: #fffbeb; color: #b45309; box-shadow: inset 0 0 0 1px #fde68a; }
.badge.info { background: #eef2ff; color: #4338ca; box-shadow: inset 0 0 0 1px #c7d2fe; }

/* ═══════════ اختيارات الراديو ═══════════ */
.radio-row { display: flex; gap: 9px; flex-wrap: wrap; align-items: center; }
.radio-row label {
  display: flex; align-items: center; gap: 7px;
  background: #fbfcfe; border: 1.5px solid var(--line); border-radius: 11px;
  padding: 8px 15px; cursor: pointer; font-size: 13px; font-weight: 600;
  transition: all .15s;
}
.radio-row label:hover { border-color: #c7d2fe; background: #f5f7ff; }
.radio-row label:has(input:checked) {
  background: var(--primary-soft); border-color: var(--primary);
  color: var(--primary); font-weight: 800;
  box-shadow: 0 2px 8px -2px rgba(99,102,241,.25);
}
.radio-row input { accent-color: var(--primary); width: 15px; height: 15px; }
input[type=checkbox] { accent-color: var(--primary); width: 16px; height: 16px; cursor: pointer; }

/* ═══════════ خطوات SOP ═══════════ */
.sop-step {
  border: 1px solid var(--line); border-radius: 14px;
  padding: 16px 18px; margin-bottom: 12px; background: #fbfcff;
  transition: border-color .15s, box-shadow .15s;
  position: relative; overflow: hidden;
}
.sop-step::before {
  content: ""; position: absolute; right: 0; top: 0; bottom: 0; width: 4px;
  background: linear-gradient(180deg, #6366f1, #8b5cf6); opacity: .55;
}
.sop-step:hover { border-color: #c7d2fe; box-shadow: var(--shadow); }
.sop-step .step-title { font-weight: 800; font-size: 13.5px; margin-bottom: 11px; }
.sop-step .step-body { display: flex; gap: 14px; flex-wrap: wrap; align-items: center; }
.sop-step .mini { font-size: 11.5px; color: var(--muted); background: #f1f5f9; padding: 4px 10px; border-radius: 999px; font-weight: 600; }
.calc-out {
  font-weight: 800; font-size: 13px; padding: 8px 14px; border-radius: 10px;
  background: #f1f5f9; color: #64748b; min-width: 110px; text-align: center;
  transition: all .2s;
}
.calc-out.pass { background: #ecfdf5; color: #047857; box-shadow: inset 0 0 0 1.5px #6ee7b7; }
.calc-out.fail { background: #fff1f2; color: #be123c; box-shadow: inset 0 0 0 1.5px #fda4af; }

.sop-tabs { display: flex; gap: 9px; flex-wrap: wrap; margin-bottom: 18px; }
.sop-tabs a {
  text-decoration: none; padding: 10px 20px; border-radius: 12px;
  border: 1.5px solid var(--line); background: var(--card); color: var(--text);
  font-weight: 700; font-size: 13.5px; transition: all .15s;
}
.sop-tabs a:hover { border-color: #c7d2fe; transform: translateY(-1px); box-shadow: var(--shadow); }
.sop-tabs a.active {
  background: linear-gradient(135deg, #6366f1, #7c3aed); color: #fff; border-color: transparent;
  box-shadow: 0 6px 16px -5px rgba(99,102,241,.55);
}

/* ═══════════ بطاقات الإحصاء ═══════════ */
.stat-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(165px, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat-card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px 16px; text-align: center; box-shadow: var(--shadow);
  position: relative; overflow: hidden; transition: transform .18s, box-shadow .18s;
}
.stat-card:hover { transform: translateY(-3px); box-shadow: 0 14px 34px -14px rgba(15,23,42,.18); }
.stat-card::after {
  content: ""; position: absolute; inset: 0 0 auto 0; height: 3.5px;
  background: linear-gradient(90deg, #6366f1, #8b5cf6);
}
.stat-card.green::after { background: linear-gradient(90deg, #10b981, #34d399); }
.stat-card.red::after { background: linear-gradient(90deg, #f43f5e, #fb7185); }
.stat-card .val { font-size: 30px; font-weight: 900; letter-spacing: -1px; color: var(--primary); }
.stat-card.green .val { color: #059669; }
.stat-card.red .val { color: #e11d48; }
.stat-card .lbl { font-size: 12px; color: var(--muted); margin-top: 5px; font-weight: 600; }

/* ═══════════ روابط سريعة ═══════════ */
.quick-links { display: grid; grid-template-columns: repeat(auto-fit, minmax(185px, 1fr)); gap: 14px; }
.quick-links a {
  display: block; background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 22px 16px; text-decoration: none;
  color: var(--text); font-weight: 800; text-align: center; font-size: 14px;
  transition: all .18s; position: relative;
}
.quick-links a:hover {
  border-color: #c7d2fe; transform: translateY(-4px);
  box-shadow: 0 16px 34px -14px rgba(99,102,241,.35);
}
.quick-links .ico {
  font-size: 24px; width: 54px; height: 54px; margin: 0 auto 10px;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #eef2ff, #f5f3ff);
  border-radius: 16px;
}

/* ═══════════ الرسوم البيانية ═══════════ */
.charts-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 18px; }
.chart-box { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.chart-box h3 { margin: 0 0 12px; font-size: 14px; font-weight: 800; }
canvas.chart { width: 100%; height: 240px; }

/* ═══════════ تسجيل الدخول ═══════════ */
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(1100px 550px at 85% -10%, #4338ca55, transparent),
              radial-gradient(900px 500px at 0% 110%, #7c3aed44, transparent),
              linear-gradient(160deg, #0b0a24, #1e1b4b 60%, #312e81);
  padding: 20px;
}
.login-card {
  background: rgba(255,255,255,.97); backdrop-filter: blur(14px);
  border-radius: 24px; padding: 42px 36px; width: 400px; max-width: 94vw;
  box-shadow: 0 30px 80px -18px rgba(0,0,0,.55);
  animation: fadeUp .45s ease both;
}
.login-card .login-logo {
  width: 66px; height: 66px; margin: 0 auto 16px; font-size: 30px;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  border-radius: 20px; box-shadow: 0 12px 28px -8px rgba(99,102,241,.6);
}
.login-card h1 { font-size: 20px; font-weight: 900; text-align: center; margin-bottom: 6px; }
.login-card .sub { text-align: center; color: var(--muted); font-size: 13px; margin-bottom: 26px; font-weight: 500; }
.login-card .fld { margin-bottom: 15px; }
.login-card .btn { width: 100%; padding: 13px; font-size: 15px; margin-top: 6px; }

/* ═══════════ منتقي الوقت العربي (ص / م) ═══════════ */
.tp { display: flex; align-items: center; gap: 5px; }
.tp select {
  width: auto; min-width: 58px; padding: 9px 8px; text-align: center;
  font-weight: 700; font-size: 13.5px; cursor: pointer;
}
.tp .tp-ap { min-width: 56px; background: var(--primary-soft); border-color: #c7d2fe; color: var(--primary); }
.tp .tp-sep { font-weight: 900; color: var(--muted); }
.tp.tp-err select { border-color: var(--danger); box-shadow: 0 0 0 3px rgba(244,63,94,.15); }

/* ═══════════ كروت الفروع القابلة للنقر ═══════════ */
.branch-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; }
.bcard {
  display: block; text-decoration: none; color: inherit;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow); position: relative; overflow: hidden;
  transition: transform .18s, box-shadow .18s, border-color .18s;
}
.bcard::after { content: ""; position: absolute; inset: 0 0 auto 0; height: 4px; background: var(--accent); }
.bcard.bad::after { background: var(--danger); }
.bcard.mid::after { background: var(--warn); }
.bcard:hover { transform: translateY(-4px); border-color: #c7d2fe; box-shadow: 0 16px 34px -14px rgba(99,102,241,.35); }
.bcard .bname { font-weight: 800; font-size: 15px; margin-bottom: 12px; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.bcard .bscore { font-size: 30px; font-weight: 900; letter-spacing: -1px; line-height: 1; }
.bcard .bmeta { display: flex; gap: 14px; margin-top: 10px; font-size: 11.5px; color: var(--muted); font-weight: 600; flex-wrap: wrap; }
.bcard .bmeta b { color: var(--text); }
.bcard .bopen { font-size: 11.5px; color: var(--primary); font-weight: 700; margin-top: 12px; display: block; }

/* ═══════════ شريط النقاط ═══════════ */
.scorebar { background: #eef0f7; border-radius: 999px; height: 11px; overflow: hidden; min-width: 90px; }
.scorebar > span { display: block; height: 100%; border-radius: 999px; transition: width .6s ease; }

/* ═══════════ استجابة الموبايل ═══════════ */
@media (max-width: 900px) {
  .app { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; padding: 14px; flex-direction: column; }
  .side-brand { padding-bottom: 12px; }
  .side-nav { flex-direction: row; overflow-x: auto; padding-bottom: 6px; }
  .side-nav a { flex-direction: column; gap: 5px; padding: 9px 13px; font-size: 11.5px; white-space: nowrap; }
  .side-user { margin-top: 8px; }
  .pagehead, .container { padding-left: 14px; padding-right: 14px; }
}

/* ═══════════ الطباعة ═══════════ */
@media print {
  .no-print, .sidebar { display: none !important; }
  body, .app { background: #fff; display: block; }
  .card, .chart-box { box-shadow: none; border-color: #bbb; break-inside: avoid; }
  .container { max-width: 100%; padding: 0; animation: none; }
}
