/* ألوان البوابة وخطوطها، حتى يبدو النظامان منتجًا واحدًا */
:root {
  --bg: #f6f9fa; --surface: #ffffff; --fg: #17242b; --muted: #5b6b74; --line: #dbe4e8;
  --navy: #1e5364; --teal: #1cb0c0; --tint: #e2f3f5; --soft: #eef4f6;
  --warn: #8a5a12; --warnbg: #fbf3e4; --bad: #a33a2b; --badbg: #fbe9e5; --good: #17694f; --goodbg: #e2f4ec;
  --plan: #0093a8; --actual: #4a55c8;
  --display: "Cairo", "IBM Plex Sans Arabic", Tahoma, sans-serif;
  --body: "IBM Plex Sans Arabic", "Cairo", Tahoma, sans-serif;
  --r: 14px;
  --shadow: 0 1px 2px rgba(23, 36, 43, .04), 0 8px 24px rgba(23, 36, 43, .05);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1a1f; --surface: #15242b; --fg: #e4edf0; --muted: #97aab3; --line: #26383f;
    --navy: #7cc7d6; --teal: #3fc6d4; --tint: #173a42; --soft: #1a2c33;
    --warn: #e0a84a; --warnbg: #2e2616; --bad: #f0a597; --badbg: #40201b; --good: #84d9b5; --goodbg: #15352b;
    --plan: #12a0b2; --actual: #c58bf5; --shadow: none;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--fg); font-family: var(--body); font-size: 15px; line-height: 1.7; }
a { color: var(--navy); }
h1, h2, h3 { font-family: var(--display); margin: 0; line-height: 1.4; }
h1 { font-size: 1.5rem; font-weight: 800; }
h2 { font-size: 1.05rem; font-weight: 700; }
h3 { font-size: .92rem; font-weight: 700; }
:focus-visible { outline: 2px solid var(--teal); outline-offset: 2px; border-radius: 4px; }
.muted { color: var(--muted); font-size: .84rem; }
.num { font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: isolate; }

.shell { display: grid; grid-template-columns: 250px minmax(0, 1fr); min-height: 100vh; }
.rail { position: sticky; top: 0; align-self: start; height: 100vh; padding: 22px 18px; border-inline-end: 1px solid var(--line); background: var(--surface); display: flex; flex-direction: column; gap: 16px; }
.logo { background: #fff; border-radius: 8px; padding: 8px 10px; align-self: flex-start; }
.logo img { height: 30px; display: block; }
.rail small { color: var(--muted); font-size: 12px; margin-top: -8px; }
nav { display: flex; flex-direction: column; gap: 2px; }
nav a { display: flex; align-items: center; justify-content: space-between; padding: 8px 12px; border-radius: 8px; text-decoration: none; color: var(--fg); font-weight: 500; }
nav a:hover { background: var(--soft); }
nav a[aria-current="page"] { background: var(--tint); color: var(--navy); font-weight: 600; }
nav .count { min-width: 22px; padding: 0 6px; border-radius: 999px; background: var(--warnbg); color: var(--warn); font-size: 12px; text-align: center; }
.meta { margin-top: auto; color: var(--muted); font-size: 12px; line-height: 1.9; }
.lang-toggle { display: block; min-height: 30px; margin-bottom: 8px; padding: 2px 12px; border-radius: 999px; font-size: .78rem; }
main { padding: 28px 32px 60px; max-width: 1240px; width: 100%; }

.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

button, .btn { font: inherit; font-size: .84rem; font-weight: 500; min-height: 38px; padding: 6px 14px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--fg); cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; }
button:hover { border-color: var(--teal); }
button.primary { background: var(--navy); border-color: var(--navy); color: var(--surface); font-weight: 600; }
button.mini { min-height: 30px; padding: 2px 10px; font-size: .76rem; }
button.danger { color: var(--bad); }
button:disabled { opacity: .55; cursor: default; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 20px 22px; margin-bottom: 18px; box-shadow: var(--shadow); }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.grid-2 { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: 18px; align-items: start; }
.grid-2 > .card { margin-bottom: 0; }
.stack { margin-bottom: 18px; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(135px, 1fr)); gap: 12px; margin-bottom: 18px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 16px 18px; box-shadow: var(--shadow); transition: transform .15s, border-color .15s; }
.kpi:hover { transform: translateY(-1px); border-color: var(--teal); }
.kpi b { display: block; font-family: var(--display); font-size: 1.85rem; font-weight: 700; line-height: 1.3; font-variant-numeric: tabular-nums; color: var(--navy); }
.kpi span { display: block; font-size: .8rem; font-weight: 500; }
.kpi small { display: block; color: var(--muted); font-size: .72rem; margin-top: 2px; }

.pill { display: inline-block; padding: 1px 10px; border-radius: 999px; font-size: .74rem; font-weight: 600; white-space: nowrap; background: var(--soft); color: var(--muted); }
.pill.good { background: var(--goodbg); color: var(--good); }
.pill.warn { background: var(--warnbg); color: var(--warn); }
.pill.bad { background: var(--badbg); color: var(--bad); }
.pill.info { background: var(--tint); color: var(--navy); }

.alert { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; font-size: .88rem; }
.alert-bad { background: var(--badbg); color: var(--bad); }
.alert-warn { background: var(--warnbg); color: var(--warn); }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .84rem; }
th, td { padding: 10px 8px; text-align: start; border-bottom: 1px solid var(--line); white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
th { color: var(--muted); font-size: .74rem; font-weight: 500; }
td.wrap { white-space: normal; min-width: 180px; }
tr.link { cursor: pointer; }
tr.link:hover td { background: var(--soft); }
.meter { display: inline-block; width: 72px; height: 6px; border-radius: 3px; background: var(--soft); overflow: hidden; vertical-align: middle; margin-inline-start: 6px; }
.meter i { display: block; height: 100%; border-radius: 3px; background: var(--navy); }

.attention { list-style: none; margin: 0; padding: 0; }
.attention li { display: flex; gap: 10px; align-items: flex-start; padding: 9px 0; border-bottom: 1px solid var(--line); font-size: .84rem; }
.attention li:last-child { border-bottom: 0; }
.attention a { font-weight: 500; }

/* مهامي */
.page-head.tight { margin-bottom: 12px; }
.crumb { font-size: .78rem; color: var(--muted); text-decoration: none; }
.crumb:hover { color: var(--navy); }
.quick-add { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 8px 14px; margin-bottom: 20px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow); }
.quick-add:focus-within { border-color: var(--teal); }
.quick-add .plus { color: var(--teal); font-size: 1.4rem; line-height: 1; }
.quick-add input { margin: 0; border: 0; background: transparent; min-height: 40px; }
.quick-add input:focus { outline: none; }
.quick-add input[name="title"] { flex: 1 1 220px; width: auto; }
.quick-add input[type="date"] { flex: 0 0 auto; width: auto; color: var(--muted); }
label.inline { display: inline-flex; align-items: center; gap: 2px; margin: 0; font-weight: 400; font-size: .82rem; }
.group { margin-bottom: 22px; }
.group h3 { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; color: var(--muted); }
.group.accent h3 { color: var(--navy); font-size: 1.05rem; }
.group.late h3 { color: var(--bad); }
.group summary { cursor: pointer; color: var(--muted); font-size: .86rem; font-weight: 500; margin-bottom: 8px; }
.empty { padding: 14px 16px; margin: 0; background: var(--surface); border: 1px dashed var(--line); border-radius: var(--r); }
.todos { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow); overflow: hidden; }
.todo { display: flex; align-items: center; gap: 12px; padding: 8px 14px; border-bottom: 1px solid var(--line); }
.todo:last-child { border-bottom: 0; }
.todo:hover { background: var(--soft); }
.todo-body { flex: 1; min-width: 0; min-height: 0; display: block; padding: 4px 0; text-align: start; background: none; border: 0; border-radius: 4px; font-weight: 400; color: inherit; }
.todo-title { display: block; font-size: .92rem; font-weight: 500; line-height: 1.5; overflow-wrap: anywhere; }
.is-done .todo-title { text-decoration: line-through; color: var(--muted); }
.todo-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; margin-top: 2px; }
.due { font-size: .72rem; color: var(--muted); }
.due.late, .late-text { color: var(--bad); font-weight: 500; }
.due.soon { color: var(--warn); font-weight: 500; }
.check { flex: 0 0 auto; width: 22px; height: 22px; min-height: 0; padding: 0; border: 1.5px solid var(--muted); border-radius: 50%; background: transparent; position: relative; }
.check:hover:not(:disabled) { border-color: var(--teal); background: var(--tint); }
.check.done { background: var(--navy); border-color: var(--navy); }
.check.done::after { content: "✓"; position: absolute; inset: 0; display: grid; place-items: center; color: var(--surface); font-size: 13px; }
.check.review { border-color: var(--warn); background: var(--warnbg); }
.check.review::after { content: "…"; position: absolute; inset: 0; display: grid; place-items: center; color: var(--warn); font-size: 13px; }
.sun { flex: 0 0 auto; width: 34px; min-height: 34px; padding: 0; border: 0; background: none; color: var(--line); font-size: 1rem; }
.sun:hover { color: var(--warn); }
.sun.on { color: var(--warn); }
.chips { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 6px; }
.chip { display: inline-block; padding: 0 8px; border-radius: 999px; font-size: .68rem; font-weight: 600; color: #fff; background: var(--chip); }
.linkish { min-height: 0; padding: 0; border: 0; background: none; color: var(--navy); font-weight: 500; text-align: start; }
.linkish:hover { text-decoration: underline; }

/* الخطط */
.plan-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; margin-bottom: 18px; }
.plan-card { display: block; padding: 18px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow); color: inherit; text-decoration: none; transition: transform .15s, border-color .15s; }
.plan-card:hover { transform: translateY(-2px); border-color: var(--teal); }
.plan-card h3 { font-size: 1rem; margin-bottom: 4px; }
.meter.wide { display: block; width: 100%; margin: 12px 0 0; }
.tabs { display: flex; gap: 4px; margin-bottom: 16px; border-bottom: 1px solid var(--line); overflow-x: auto; }
.tabs button { background: none; border: 0; border-bottom: 2px solid transparent; border-radius: 0; color: var(--muted); }
.tabs button.active { color: var(--navy); border-bottom-color: var(--teal); font-weight: 600; }
.buckets { display: flex; gap: 12px; align-items: flex-start; overflow-x: auto; padding-bottom: 12px; }
.bucket { flex: 0 0 270px; padding: 10px; background: var(--soft); border-radius: var(--r); transition: box-shadow .15s; }
.bucket.drop { box-shadow: inset 0 0 0 2px var(--teal); }
.bucket header { display: flex; justify-content: space-between; align-items: center; gap: 6px; margin-bottom: 8px; padding: 0 4px; }
.bucket h3 { display: flex; gap: 8px; align-items: center; }
.ghost { min-height: 28px; width: 28px; padding: 0; border: 0; background: none; color: var(--muted); }
.ghost:hover { color: var(--fg); background: var(--soft); }
.card-add input { margin: 0 0 8px; min-height: 36px; background: var(--surface); }
.bucket-list { min-height: 40px; }
.card-task { padding: 10px 12px; margin-bottom: 8px; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); }
.card-task[draggable="true"] { cursor: grab; }
.card-task:hover { border-color: var(--teal); }
.card-task.dragging { opacity: .45; }
.card-task.late { border-inline-start: 3px solid var(--bad); }
.card-title { display: flex; gap: 8px; align-items: flex-start; }
.card-title .check { margin-top: 5px; width: 18px; height: 18px; }
.card-task .todo-meta { margin-top: 6px; }
.avatar { margin-inline-start: auto; width: 24px; height: 24px; display: grid; place-items: center; border-radius: 50%; background: var(--tint); color: var(--navy); font-family: var(--display); font-size: .72rem; font-weight: 700; }
.bucket-new { flex: 0 0 auto; border-style: dashed; background: transparent; color: var(--muted); }
.grid-2.even { grid-template-columns: repeat(2, minmax(0, 1fr)); }
h2.gap { margin-bottom: 12px; }
.calendar { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; }
.dow { padding: 4px; color: var(--muted); font-size: .72rem; text-align: center; }
.day { min-height: 84px; padding: 4px; border: 1px solid var(--line); border-radius: 8px; font-size: .74rem; overflow: hidden; }
.day.blank { border: 0; }
.day.today { border-color: var(--teal); background: var(--tint); }
.event { display: block; width: 100%; min-height: 0; margin-top: 3px; padding: 2px 6px; overflow: hidden; border: 0; border-radius: 4px; background: var(--navy); color: var(--surface); font-size: .7rem; text-align: start; white-space: nowrap; text-overflow: ellipsis; }
.event.is-done { background: var(--soft); color: var(--muted); text-decoration: line-through; }
.event.late { background: var(--bad); color: var(--surface); }

/* بطاقة المهمة */
dialog.sheet { width: min(100vw, 560px); max-width: 100vw; height: 100vh; max-height: 100vh; margin: 0; margin-inline-start: auto; padding: 0; border: 0; border-radius: 0; border-inline-start: 1px solid var(--line); box-shadow: 0 0 40px rgba(15, 26, 31, .18); }
.sheet-body, .sheet-section, .sheet-foot { padding: 16px 22px; }
.sheet-body { padding-top: 20px; }
.sheet-section { border-top: 1px solid var(--line); }
.sheet-section h3 { margin-bottom: 8px; }
.sheet-top { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.title-input { flex: 1; margin: 0; min-height: 40px; padding: 4px 6px; border-color: transparent; background: transparent; font-family: var(--display); font-size: 1.1rem; font-weight: 700; }
.title-input:hover:not(:disabled), .title-input:focus { border-color: var(--line); background: var(--bg); }
.review-bar { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.actions.gap { margin-top: 2px; }
.steps { list-style: none; margin: 0 0 6px; padding: 0; }
.steps li { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 4px 0; font-size: .86rem; }
.struck { color: var(--muted); text-decoration: line-through; }
.inline-form { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.inline-form input { flex: 1 1 140px; width: auto; margin: 0; min-height: 36px; }
.ltr { direction: ltr; text-align: left; }
.comment { margin-bottom: 10px; font-size: .84rem; }
.comment p { margin: 2px 0 0; overflow-wrap: anywhere; }
.sheet-foot { border-top: 1px solid var(--line); }

/* بوابات المشروع */
.gates { display: flex; align-items: stretch; gap: 4px; overflow-x: auto; padding-bottom: 4px; }
.gate-step { flex: 1 1 0; min-width: 96px; padding: 8px 10px; border-radius: 8px; background: var(--soft); color: var(--muted); font-size: .78rem; text-align: center; }
.gate-step b { display: block; font-family: var(--display); font-size: .84rem; font-weight: 700; }
.gate-step.past { background: var(--goodbg); color: var(--good); }
.gate-step.now { background: var(--navy); color: var(--surface); }
.gate-mark { align-self: center; flex: 0 0 auto; max-width: 70px; font-size: .66rem; line-height: 1.3; text-align: center; color: var(--muted); }

/* الرسوم */
/* محاذاة النصوص داخل الرسوم تعتمد على الإحداثيات، لا على اتجاه الصفحة */
.chart svg, .gantt svg { display: block; width: 100%; height: auto; direction: ltr; }
.gantt { overflow-x: auto; }
.gantt svg { min-width: 760px; }
.legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: .76rem; color: var(--muted); margin-bottom: 8px; }
.legend i { display: inline-block; width: 14px; height: 3px; border-radius: 2px; margin-inline-end: 6px; vertical-align: middle; }
.chart { position: relative; }
.tip { position: absolute; pointer-events: none; background: var(--fg); color: var(--bg); border-radius: 6px; padding: 5px 9px; font-size: .74rem; line-height: 1.6; white-space: nowrap; z-index: 2; }
.bars { display: grid; gap: 8px; }
.bar-row { display: grid; grid-template-columns: 110px minmax(0, 1fr) 62px; gap: 8px; align-items: center; font-size: .8rem; }
.bar-track { height: 10px; }
.bar-track i { display: block; height: 100%; min-width: 2px; border-start-end-radius: 4px; border-end-end-radius: 4px; background: var(--navy); }
.bar-row.over .bar-track i { background: var(--warn); }

/* الالتزامات */
.commit { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--line); font-size: .86rem; flex-wrap: wrap; }
.commit:last-child { border-bottom: 0; }

/* النماذج */
dialog { border: 1px solid var(--line); border-radius: 14px; padding: 22px; width: min(94vw, 560px); background: var(--surface); color: var(--fg); }
dialog::backdrop { background: rgba(15, 26, 31, .5); }
label { display: block; font-size: .8rem; font-weight: 500; margin-bottom: 12px; }
input, select, textarea { display: block; width: 100%; margin-top: 4px; padding: 8px 12px; min-height: 40px; font: inherit; font-size: .88rem; color: var(--fg); background: var(--bg); border: 1px solid var(--line); border-radius: 8px; }
input[type="checkbox"] { display: inline-block; width: 18px; min-height: 18px; margin: 0; margin-inline-end: 8px; vertical-align: middle; }
select[multiple] { min-height: 96px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 12px; }
.form-grid .full { grid-column: 1 / -1; }
.hint { display: block; color: var(--muted); font-size: .72rem; font-weight: 400; margin-top: 3px; }
.dialog-actions { display: flex; gap: 8px; margin-top: 6px; }

@media (max-width: 860px) {
  .shell { display: block; }
  .rail { position: static; height: auto; padding: 12px 16px; border-inline-end: 0; border-bottom: 1px solid var(--line); flex-direction: row; flex-wrap: wrap; align-items: center; gap: 10px; }
  .rail small { display: none; }
  nav { flex-direction: row; overflow-x: auto; width: 100%; order: 3; }
  nav a { white-space: nowrap; gap: 6px; }
  .meta { margin: 0; margin-inline-start: auto; display: flex; gap: 10px; align-items: center; }
  main { padding: 18px 16px 48px; }
  .grid-2 { grid-template-columns: minmax(0, 1fr); }
  .form-grid { grid-template-columns: minmax(0, 1fr); }
}
