:root {
  --bg: #f3f5f8;
  --card: #ffffff;
  --ink: #1d2733;
  --muted: #667385;
  --line: #dde3ea;
  --primary: #1b5e7e;
  --primary-ink: #ffffff;
  --accent: #7b3f98;
  --ok: #2e8b57;
  --warn: #c98a12;
  --bad: #d64533;
  --soft-ok: #e6f4ec;
  --soft-warn: #fdf3df;
  --soft-bad: #fbe7e4;
  --soft-blue: #e5f0f6;
  --radius: 10px;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "IBM Plex Sans Arabic", "Segoe UI", Tahoma, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
}
a { color: var(--primary); }
.topbar {
  display: flex; align-items: center; gap: 20px; flex-wrap: wrap;
  background: var(--primary); color: var(--primary-ink);
  padding: 10px 24px;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand small { display: block; opacity: .8; font-size: 12px; }
.logo {
  width: 36px; height: 36px; border-radius: 8px; background: #fff; color: var(--primary);
  display: grid; place-items: center; font-weight: 700; font-size: 20px;
}
nav { display: flex; gap: 4px; flex-wrap: wrap; flex: 1; }
nav a {
  color: #fff; text-decoration: none; padding: 7px 12px; border-radius: 8px; opacity: .85;
}
nav a:hover { background: rgba(255,255,255,.12); opacity: 1; }
nav a.active { background: #fff; color: var(--primary); opacity: 1; font-weight: 600; }
.badge { font-size: 12px; padding: 4px 10px; border-radius: 99px; background: rgba(255,255,255,.15); }
.badge.on { background: #d9f2e3; color: #1b6b3f; }
.me { display: flex; align-items: center; gap: 10px; font-size: 14px; }
.me a { color: #fff; text-decoration: none; line-height: 1.2; }
.me small { display: block; opacity: .8; font-size: 11px; }
button.link { background: none; border: 1px solid rgba(255,255,255,.4); color: #fff; padding: 4px 10px; font-size: 13px; }
[hidden] { display: none !important; }

main { max-width: 1240px; margin: 0 auto; padding: 22px 20px 60px; }
h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 17px; margin: 0 0 12px; }
.sub { color: var(--muted); margin: 0 0 18px; }
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; margin-bottom: 18px;
}
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: end; }
.grid { display: grid; gap: 14px; }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 800px) { .grid.cols-2, .grid.cols-3, .grid.cols-4 { grid-template-columns: 1fr; } }
.span-2 { grid-column: span 2; }
@media (max-width: 800px) { .span-2 { grid-column: auto; } }

label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); font-weight: 500; }
input, select, textarea, button { font: inherit; }
input, select, textarea {
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; color: var(--ink); background: #fff; min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: 2px solid #b8d6e6; border-color: var(--primary); }
textarea { min-height: 70px; resize: vertical; }
.ai-filled { background: #f6effa; border-color: #c9a6dc; }
button, .btn {
  border: 1px solid var(--primary); background: var(--primary); color: #fff; padding: 8px 16px;
  border-radius: 8px; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: 6px;
}
button.secondary, .btn.secondary { background: #fff; color: var(--primary); }
button.accent { background: var(--accent); border-color: var(--accent); }
button.danger { background: #fff; color: var(--bad); border-color: var(--bad); }
button:disabled { opacity: .55; cursor: wait; }

/* المؤشرات */
.kpis { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 12px; margin-bottom: 18px; }
@media (max-width: 900px) { .kpis { grid-template-columns: repeat(2, 1fr); } }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; text-align: center; }
.kpi .t { background: var(--soft-blue); color: var(--primary); font-weight: 600; font-size: 13px; padding: 8px 6px; }
.kpi .v { font-size: 30px; font-weight: 700; padding: 12px 6px; }
.kpi.ok .v { color: var(--ok); } .kpi.warn .v { color: var(--warn); } .kpi.bad .v { color: var(--bad); }
.kpi small { display: block; font-size: 12px; color: var(--muted); font-weight: 400; margin-top: -10px; padding-bottom: 8px; }

/* الجداول */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { background: var(--primary); color: #fff; font-weight: 600; text-align: right; padding: 9px 10px; white-space: nowrap; }
td { border-bottom: 1px solid var(--line); padding: 8px 10px; vertical-align: top; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: #f7fafc; }
.empty { text-align: center; color: var(--muted); padding: 24px; }
.pill { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.pill.done { background: var(--soft-ok); color: var(--ok); }
.pill.progress { background: var(--soft-blue); color: var(--primary); }
.pill.late { background: var(--soft-bad); color: var(--bad); }
.pill.p1 { background: var(--soft-bad); color: var(--bad); }
.pill.p2 { background: var(--soft-warn); color: var(--warn); }
.pill.p3 { background: var(--soft-ok); color: var(--ok); }
.pill.c1 { background: #efe3f5; color: var(--accent); }
.pill.c2 { background: var(--soft-blue); color: var(--primary); }
.num { font-family: ui-monospace, Consolas, monospace; unicode-bidi: isolate; white-space: nowrap; }
.ltr { direction: ltr; }

/* الرسم البياني */
.chart svg { width: 100%; height: auto; display: block; }
.legend { display: flex; gap: 18px; justify-content: center; font-size: 13px; color: var(--muted); margin-top: 6px; }
.legend i { display: inline-block; width: 18px; height: 3px; vertical-align: middle; margin-inline-end: 6px; border-radius: 2px; }
.bars .bar-row { display: grid; grid-template-columns: 170px 1fr 40px; gap: 10px; align-items: center; margin-bottom: 8px; font-size: 13px; }
.bars .track { display: flex; height: 16px; background: #eef1f4; border-radius: 4px; overflow: hidden; }
.bars .track span { height: 100%; }

/* الرفع */
.drop {
  border: 2px dashed #b9c6d3; border-radius: var(--radius); padding: 26px; text-align: center; color: var(--muted);
  background: #fafcfd; cursor: pointer; transition: .15s;
}
.drop.over { border-color: var(--accent); background: #f8f1fb; }
.drop strong { color: var(--ink); display: block; margin-bottom: 4px; }
.ai-box { border-inline-start: 4px solid var(--accent); background: #faf6fc; }
.hint { font-size: 13px; color: var(--muted); }
.spinner { width: 16px; height: 16px; border: 2px solid currentColor; border-top-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

/* التفاصيل */
.facts { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px 18px; }
@media (max-width: 800px) { .facts { grid-template-columns: 1fr 1fr; } }
.facts div small { display: block; color: var(--muted); font-size: 12px; }
.notes { list-style: none; padding: 0; margin: 0; }
.notes li { border-bottom: 1px solid var(--line); padding: 8px 0; }
.notes li small { color: var(--muted); }

/* المحادثة */
.chat { display: flex; flex-direction: column; height: calc(100vh - 210px); min-height: 420px; }
.msgs { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; padding: 4px; }
.msg { max-width: 80%; padding: 10px 14px; border-radius: 12px; white-space: pre-wrap; line-height: 1.7; }
.msg.user { align-self: flex-start; background: var(--primary); color: #fff; border-end-start-radius: 4px; }
.msg.assistant { align-self: flex-end; background: #fff; border: 1px solid var(--line); border-end-end-radius: 4px; }
.chat form { display: flex; gap: 8px; margin-top: 12px; }
.chat form textarea { flex: 1; min-height: 46px; }
.suggestions { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.suggestions button { font-size: 13px; padding: 5px 12px; }

.toast {
  position: fixed; bottom: 20px; left: 20px; background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 8px;
  opacity: 0; transform: translateY(10px); transition: .2s; pointer-events: none; max-width: 420px;
}
.toast.show { opacity: 1; transform: none; }
.toast.err { background: var(--bad); }

.print-head { display: none; }
@media print {
  .no-print, .topbar { display: none !important; }
  body { background: #fff; }
  main { padding: 0; max-width: none; }
  .card { border: none; padding: 0; }
  .print-head { display: block; }
  th { background: #ddd !important; color: #000; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
