/* بوصلة — تصميم هادئ، عربي، من اليمين إلى اليسار */
:root {
  --bg: #f6f3ee;
  --surface: #ffffff;
  --surface-2: #f0ece4;
  --text: #1f2a2e;
  --muted: #5e6b70;
  --line: #e2dcd1;
  --primary: #1f6f6b;
  --primary-ink: #ffffff;
  --primary-soft: #e1efed;
  --accent: #b9773a;
  --accent-soft: #f6eadc;
  --danger: #b4443a;
  --danger-soft: #f8e4e1;
  --ok: #2f7d4f;
  --t1: #3a7ca5;
  --t2: #c0713d;
  --t3: #7a6bb0;
  --t4: #2f7d4f;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(31, 42, 46, 0.05), 0 4px 16px rgba(31, 42, 46, 0.05);
  --font: "IBM Plex Sans Arabic", "Segoe UI", Tahoma, "Noto Sans Arabic", system-ui, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141a1c;
    --surface: #1c2427;
    --surface-2: #232d31;
    --text: #e6eaeb;
    --muted: #9aa7ab;
    --line: #2f3b3f;
    --primary: #4fb3aa;
    --primary-ink: #0f1a1b;
    --primary-soft: #1d3634;
    --accent: #e0a066;
    --accent-soft: #3a2c1e;
    --danger: #ec7d72;
    --danger-soft: #3b2220;
    --ok: #6cc08f;
    --t1: #6fb0d8;
    --t2: #e39a66;
    --t3: #a99ae0;
    --t4: #6cc08f;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.75;
}

h1, h2, h3 { line-height: 1.35; margin: 0 0 .5rem; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.02rem; }
p { margin: 0 0 .75rem; }
a { color: var(--primary); }

.skip {
  position: absolute; inset-inline-start: 1rem; top: -100px;
  background: var(--primary); color: var(--primary-ink); padding: .5rem 1rem; z-index: 100;
}
.skip:focus { top: .5rem; }

.container { max-width: 1080px; margin: 0 auto; padding: 0 16px; }

/* ---------- الشريط العلوي ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.topbar-inner { max-width: 1080px; margin: 0 auto; padding: 10px 16px 4px; }
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; }
.brand-mark { width: 34px; height: 34px; color: var(--primary); }
.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-text strong { font-size: 1.15rem; }
.brand-text small { color: var(--muted); font-size: .78rem; }

.nav {
  max-width: 1080px; margin: 0 auto; padding: 4px 12px 8px;
  display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none;
}
.nav::-webkit-scrollbar { display: none; }
.nav a {
  flex: none; padding: 6px 14px; border-radius: 999px;
  color: var(--muted); text-decoration: none; font-weight: 500; font-size: .93rem; white-space: nowrap;
}
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a[aria-current="page"] { background: var(--primary); color: var(--primary-ink); }

/* ---------- عناصر عامة ---------- */
main { padding-top: 20px; padding-bottom: 24px; outline: none; }
.page-head { margin-bottom: 16px; }
.page-head p { color: var(--muted); max-width: 70ch; }

.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }

.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow);
  min-width: 0;
}
.card + .card { margin-top: 16px; }
.grid > .card + .card { margin-top: 0; }
.card-label { color: var(--muted); font-size: .85rem; font-weight: 500; margin-bottom: 4px; display: block; }
.card-title { font-size: 1.25rem; font-weight: 700; margin-bottom: 4px; overflow-wrap: anywhere; }
.card.highlight { border-color: color-mix(in srgb, var(--primary) 45%, var(--line)); background: linear-gradient(180deg, var(--primary-soft), var(--surface) 70%); }

.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.muted { color: var(--muted); }
.small { font-size: .88rem; }
.pre { white-space: pre-wrap; overflow-wrap: anywhere; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-weight: 600; font-size: .95rem;
  padding: 9px 18px; border-radius: 999px; border: 1px solid transparent; cursor: pointer;
  background: var(--primary); color: var(--primary-ink); text-decoration: none;
}
.btn:hover { filter: brightness(1.06); }
.btn.secondary { background: var(--surface); color: var(--text); border-color: var(--line); }
.btn.secondary:hover { background: var(--surface-2); }
.btn.ghost { background: transparent; color: var(--muted); padding: 4px 10px; }
.btn.ghost:hover { color: var(--text); background: var(--surface-2); }
.btn.danger { background: var(--danger); color: #fff; }
.btn.small { padding: 5px 12px; font-size: .85rem; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }

:focus-visible { outline: 3px solid color-mix(in srgb, var(--primary) 55%, transparent); outline-offset: 2px; }

/* ---------- النماذج ---------- */
.form { display: grid; gap: 14px; }
.field { display: grid; gap: 4px; }
.field > span, .field > label { font-weight: 600; font-size: .95rem; }
.field .hint { color: var(--muted); font-size: .85rem; font-weight: 400; }
.form-row { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
input[type="text"], input[type="date"], textarea, select {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 9px 12px; width: 100%;
}
textarea { min-height: 84px; resize: vertical; }
input:focus, textarea:focus, select:focus { border-color: var(--primary); outline: none; box-shadow: 0 0 0 3px var(--primary-soft); }

/* شرائح التقييم */
.slider-block { background: var(--surface-2); border-radius: var(--radius); padding: 16px; }
.slider-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.slider-head label { font-weight: 700; font-size: 1.05rem; }
.slider-value { font-size: 1.8rem; font-weight: 700; color: var(--primary); font-variant-numeric: tabular-nums; }
.slider-value small { font-size: .9rem; color: var(--muted); font-weight: 500; }
input[type="range"] { width: 100%; accent-color: var(--primary); height: 28px; cursor: pointer; }
.scale { display: flex; justify-content: space-between; color: var(--muted); font-size: .8rem; gap: 8px; }
details { margin-top: 8px; }
summary { cursor: pointer; color: var(--primary); font-size: .9rem; font-weight: 500; }
details ul { margin: 6px 0 0; padding-inline-start: 1.2rem; color: var(--muted); font-size: .9rem; }

/* ---------- المراحل ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 2px 10px; border-radius: 999px; font-weight: 700; font-size: .85rem;
  background: var(--surface-2); color: var(--text); direction: ltr; unicode-bidi: isolate;
}
.badge.T1 { background: color-mix(in srgb, var(--t1) 16%, transparent); color: var(--t1); }
.badge.T2 { background: color-mix(in srgb, var(--t2) 16%, transparent); color: var(--t2); }
.badge.T3 { background: color-mix(in srgb, var(--t3) 16%, transparent); color: var(--t3); }
.badge.T4 { background: color-mix(in srgb, var(--t4) 16%, transparent); color: var(--t4); }
.stage-card { border-top: 4px solid var(--line); }
.stage-card.T1 { border-top-color: var(--t1); }
.stage-card.T2 { border-top-color: var(--t2); }
.stage-card.T3 { border-top-color: var(--t3); }
.stage-card.T4 { border-top-color: var(--t4); }
.stage-card.is-current { box-shadow: 0 0 0 2px var(--primary), var(--shadow); }
.stage-card ul { padding-inline-start: 1.2rem; margin: 6px 0 10px; }
.stage-card li { margin-bottom: 2px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 2px 12px; font-size: .92rem; margin: 10px 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 600; }
.pill { display: inline-block; padding: 1px 10px; border-radius: 999px; background: var(--primary-soft); color: var(--primary); font-size: .8rem; font-weight: 600; }

.preview { border: 1px dashed color-mix(in srgb, var(--primary) 50%, var(--line)); border-radius: var(--radius); padding: 16px; background: var(--primary-soft); }
.preview .stage-line { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 6px; }
.note {
  border-inline-start: 4px solid var(--accent); background: var(--accent-soft);
  padding: 10px 14px; border-radius: var(--radius-sm); font-size: .9rem; margin: 12px 0 0;
}

/* مقاييس صغيرة */
.meter { height: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.meter > span { display: block; height: 100%; background: var(--primary); border-radius: 999px; }
.meter.accent > span { background: var(--accent); }
.meter-row { display: grid; grid-template-columns: 70px 1fr 40px; align-items: center; gap: 8px; font-size: .88rem; }
.meter-row b { text-align: end; font-variant-numeric: tabular-nums; }
.delta { font-size: .8rem; font-weight: 600; direction: ltr; unicode-bidi: isolate; }
.delta.up { color: var(--ok); }
.delta.down { color: var(--danger); }

/* ---------- خريطة الطريق ---------- */
.timeline { list-style: none; margin: 0; padding: 0; position: relative; }
.timeline::before {
  content: ""; position: absolute; top: 12px; bottom: 12px; inset-inline-start: 19px;
  width: 2px; background: var(--line);
}
.tl-stage { position: relative; padding-inline-start: 56px; margin-bottom: 18px; }
.tl-dot {
  position: absolute; inset-inline-start: 0; top: 14px; width: 40px; height: 40px; border-radius: 50%;
  display: grid; place-items: center; font-weight: 700; font-size: .8rem;
  background: var(--surface); border: 2px solid var(--line); color: var(--muted);
}
.tl-stage.done .tl-dot { background: var(--ok); border-color: var(--ok); color: #fff; }
.tl-stage.current .tl-dot { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); box-shadow: 0 0 0 5px var(--primary-soft); }
.tl-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; justify-content: space-between; }
.steps { list-style: none; margin: 10px 0 0; padding: 0; display: grid; gap: 6px; }
.step {
  display: flex; align-items: flex-start; gap: 10px; padding: 8px 10px;
  border-radius: var(--radius-sm); background: var(--surface-2);
}
.step input[type="checkbox"] { width: 20px; height: 20px; margin-top: 4px; accent-color: var(--ok); flex: none; cursor: pointer; }
.step label { flex: 1; cursor: pointer; overflow-wrap: anywhere; }
.step.done label { color: var(--muted); text-decoration: line-through; }
.step.next { background: var(--accent-soft); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 50%, transparent); }
.step .next-tag { font-size: .75rem; font-weight: 700; color: var(--accent); white-space: nowrap; margin-top: 3px; }
.add-step { display: flex; gap: 8px; margin-top: 10px; }
.add-step input { flex: 1; min-width: 0; }

/* ---------- السجل ---------- */
.entries { display: grid; gap: 12px; }
.entry-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.entry dl { display: grid; gap: 6px; margin: 0; }
.entry dt { color: var(--muted); font-size: .82rem; font-weight: 600; }
.entry dd { margin: 0 0 4px; white-space: pre-wrap; overflow-wrap: anywhere; }
.check { display: flex; align-items: center; gap: 8px; font-size: .92rem; }
.check input { width: 18px; height: 18px; accent-color: var(--primary); }

/* ---------- جداول ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { text-align: start; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: .82rem; }
td.num { font-variant-numeric: tabular-nums; font-weight: 600; }

/* ---------- البداية ---------- */
.hero { text-align: center; padding: 32px 20px; }
.hero h1 { font-size: 1.8rem; }
.hero p { color: var(--muted); max-width: 56ch; margin-inline: auto; }
.onboard { list-style: none; padding: 0; margin: 20px auto 0; max-width: 520px; display: grid; gap: 10px; text-align: start; counter-reset: s; }
.onboard li { counter-increment: s; display: flex; gap: 12px; align-items: center; background: var(--surface-2); padding: 10px 14px; border-radius: var(--radius-sm); }
.onboard li::before { content: counter(s); flex: none; width: 28px; height: 28px; border-radius: 50%; background: var(--primary); color: var(--primary-ink); display: grid; place-items: center; font-weight: 700; font-size: .85rem; }
.empty { text-align: center; color: var(--muted); padding: 24px 12px; }

/* ---------- تنبيهات ---------- */
.banner { padding: 10px 16px; text-align: center; font-size: .92rem; }
.banner.warn { background: var(--accent-soft); color: var(--text); }
.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translate(-50%, 20px);
  background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 999px;
  font-size: .92rem; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
  max-width: calc(100% - 32px); text-align: center; z-index: 50;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: var(--danger); color: #fff; }

.footer { color: var(--muted); font-size: .82rem; padding-top: 16px; padding-bottom: 32px; border-top: 1px solid var(--line); margin-top: 16px; }
.footer p { margin: 0 0 4px; }

@media (max-width: 560px) {
  h1 { font-size: 1.35rem; }
  .card { padding: 16px; }
  .hero { padding: 20px 4px; }
  .actions .btn { flex: 1 1 auto; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

@media print {
  .topbar, .nav, .toast, .actions, .footer { display: none !important; }
  body { background: #fff; }
}
