:root {
  --bg: #f4f6f3;
  --surface: #ffffff;
  --surface-2: #eef2ef;
  --text: #17211f;
  --muted: #5f6d69;
  --border: #dfe5e2;
  --primary: #0f766e;
  --primary-soft: #d5efeb;
  --primary-text: #ffffff;
  --ok: #15803d;
  --ok-soft: #dcf3e3;
  --warn: #b45309;
  --warn-soft: #fdf0d9;
  --danger: #b91c1c;
  --hifz: #7c3aed;
  --reading: #0369a1;
  --review: #c2410c;
  --ibadah: #0f766e;
  --quran: #15803d;
  --book: #a16207;
  --todo: #be185d;
  --radius: 16px;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.04), 0 4px 14px rgb(0 0 0 / 0.04);
  --nav-h: 64px;
  --font: "Segoe UI", "SF Arabic", "Geeza Pro", "Noto Sans Arabic", "Noto Naskh Arabic", Tahoma, "Arial", sans-serif;
  color-scheme: light;
}

[data-theme="dark"] {
  --bg: #0b1416;
  --surface: #131f22;
  --surface-2: #1b2a2e;
  --text: #e7efed;
  --muted: #94a6a2;
  --border: #24363a;
  --primary: #2dd4bf;
  --primary-soft: #133b38;
  --primary-text: #062421;
  --ok: #4ade80;
  --ok-soft: #13301f;
  --warn: #fbbf24;
  --warn-soft: #33270e;
  --danger: #f87171;
  --hifz: #a78bfa;
  --reading: #38bdf8;
  --review: #fb923c;
  --ibadah: #2dd4bf;
  --quran: #4ade80;
  --book: #facc15;
  --todo: #f472b6;
  --shadow: none;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.6;
  background: var(--bg);
  color: var(--text);
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 16px);
  -webkit-tap-highlight-color: transparent;
}
h1, h2, h3 { margin: 0; line-height: 1.4; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1.02rem; }
p { margin: 0.35rem 0; }
a { color: var(--primary); }
button, input, select, textarea { font: inherit; color: inherit; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small, small { font-size: 0.82rem; }
.empty { color: var(--muted); text-align: center; padding: 1rem; }
.warn-text { color: var(--warn); }
.danger-text { color: var(--danger) !important; }

/* ---------- الشريط العلوي ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: calc(env(safe-area-inset-top) + 10px) 14px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand img { border-radius: 8px; }
.brand h1 { font-size: 1.15rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-actions { display: flex; align-items: center; gap: 4px; }
.icon-btn {
  display: inline-grid; place-items: center;
  width: 40px; height: 40px; border-radius: 12px;
  border: 0; background: transparent; color: var(--text); cursor: pointer; text-decoration: none;
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn:disabled { opacity: 0.35; cursor: default; }
.icon-btn.big { width: 48px; height: 48px; font-size: 1.6rem; background: var(--surface-2); }
[data-theme="dark"] .i-moon, [data-theme="light"] .i-sun { display: none; }

.sync-pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 10px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--surface); font-size: 0.78rem; cursor: pointer; white-space: nowrap;
}
.sync-pill .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.sync-pill[data-state="synced"] .dot { background: var(--ok); }
.sync-pill[data-state="syncing"] .dot, .sync-pill[data-state="pending"] .dot { background: var(--warn); animation: pulse 1s infinite alternate; }
.sync-pill[data-state="error"] .dot, .sync-pill[data-state="auth"] .dot { background: var(--danger); }
@keyframes pulse { to { opacity: 0.3; } }

/* ---------- المحتوى ---------- */
main { max-width: 720px; margin: 0 auto; padding: 14px; outline: none; display: flex; flex-direction: column; gap: 12px; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 8px;
}
.card h3 { margin-bottom: 2px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.card-head h3 { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.card-done { border-color: color-mix(in srgb, var(--ok) 45%, var(--border)); }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 4px; }
.stack { display: flex; flex-direction: column; gap: 8px; }
.row-actions { display: flex; gap: 2px; }

/* ---------- عناصر التعليم ---------- */
.check-row {
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 12px; min-height: 56px; text-align: start;
  border: 1px solid var(--border); border-radius: 14px; background: var(--surface-2); cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.check-row.flat { border: 0; background: transparent; padding: 0; min-height: 44px; }
.check-box {
  display: grid; place-items: center; width: 28px; height: 28px; flex: none;
  border-radius: 9px; border: 2px solid var(--muted); color: transparent; transition: all 0.15s;
}
.check-box svg { width: 18px; height: 18px; stroke-width: 3; }
.check-row.done .check-box { background: var(--ok); border-color: var(--ok); color: #fff; }
.check-row.done:not(.flat) { background: var(--ok-soft); border-color: color-mix(in srgb, var(--ok) 35%, transparent); }
.check-row.done b { text-decoration: line-through; text-decoration-color: color-mix(in srgb, var(--ok) 60%, transparent); }
.check-text { display: flex; flex-direction: column; min-width: 0; }
.check-text small { color: var(--muted); display: flex; flex-wrap: wrap; align-items: center; gap: 4px; }

.card-row {
  display: flex; flex-direction: column; gap: 10px; padding: 12px;
  border: 1px solid var(--border); border-radius: 14px; background: var(--surface-2);
}
.card-row.done { background: var(--ok-soft); border-color: color-mix(in srgb, var(--ok) 35%, transparent); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  min-width: 44px; height: 38px; padding: 0 14px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface); cursor: pointer; font-weight: 600;
}
.chip.on { border-color: var(--primary); color: var(--primary); background: var(--primary-soft); }
.chip.done { background: var(--ok); border-color: var(--ok); color: #fff; }
.tabs .chip { flex: 1; }

.badge {
  display: inline-flex; align-items: center; gap: 3px; padding: 1px 8px; border-radius: 999px;
  font-size: 0.75rem; font-weight: 600; background: var(--surface-2); color: var(--muted); white-space: nowrap;
}
.badge svg { width: 14px; height: 14px; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.t-hifz { --c: var(--hifz); } .t-reading { --c: var(--reading); } .t-review { --c: var(--review); }
.t-ibadah { --c: var(--ibadah); } .t-quran { --c: var(--quran); } .t-book { --c: var(--book); }
.badge[class*="t-"] { color: var(--c); background: color-mix(in srgb, var(--c) 14%, transparent); }
.dot[class*="t-"] { width: 10px; height: 10px; border-radius: 50%; background: var(--c); flex: none; display: inline-block; }

/* ---------- الأزرار ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 16px; border-radius: 12px; border: 1px solid transparent;
  font-weight: 600; cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn svg { width: 18px; height: 18px; }
.btn.primary { background: var(--primary); color: var(--primary-text); }
.btn.soft { background: var(--primary-soft); color: var(--primary); }
.btn.ghost { background: transparent; border-color: var(--border); }
.btn.danger { background: var(--danger); color: #fff; }
.btn.link { background: none; border: 0; padding: 0; min-height: 32px; justify-content: flex-start; }
.btn.block { width: 100%; }
.btn:disabled { opacity: 0.5; cursor: default; }
.small-btn { min-height: 36px; font-size: 0.85rem; align-self: flex-start; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }
.btn-row .btn { flex: 1; }
.file-btn { position: relative; }

/* ---------- التاريخ ---------- */
.date-nav { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.date-nav.compact { gap: 2px; }
.date-title { display: flex; flex-direction: column; align-items: center; text-align: center; }

/* ---------- التقدم ---------- */
.progress-card { flex-direction: row; align-items: center; gap: 16px; }
.ring { position: relative; display: grid; place-items: center; flex: none; }
.ring svg { position: absolute; inset: 0; width: 100%; height: 100%; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 8; }
.ring-bg { stroke: var(--surface-2); }
.ring-fg { stroke: var(--primary); stroke-linecap: round; transition: stroke-dashoffset 0.4s ease; }
.ring span { font-weight: 700; font-size: 1.05rem; }
.ring-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; text-align: center; }
.ring-row > div { display: flex; flex-direction: column; align-items: center; gap: 6px; }

.progress-line { position: relative; height: 10px; border-radius: 99px; background: var(--surface-2); overflow: visible; }
.progress-fill { height: 100%; border-radius: 99px; background: var(--primary); transition: width 0.3s; }
.progress-mark { position: absolute; top: -3px; width: 3px; height: 16px; border-radius: 2px; background: var(--warn); }

.quran-target { font-size: 1.05rem; }
.stepper { display: flex; align-items: center; justify-content: center; gap: 12px; }
.stepper-value { display: flex; flex-direction: column; align-items: center; }
.stepper-value input {
  width: 110px; text-align: center; font-size: 1.6rem; font-weight: 700;
  border: 1px solid var(--border); border-radius: 12px; background: var(--surface-2); padding: 4px;
}
.stepper-value span { font-size: 0.8rem; color: var(--muted); }

/* ---------- الأسبوع ---------- */
.week { display: grid; grid-template-columns: repeat(7, minmax(140px, 1fr)); gap: 8px; overflow-x: auto; padding-bottom: 6px; scroll-snap-type: x mandatory; }
.week-day {
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 10px;
  scroll-snap-align: start; min-height: 110px;
}
.week-day.is-today { border-color: var(--primary); box-shadow: 0 0 0 1px var(--primary) inset; }
.week-day.rest { background: var(--surface-2); }
.week-day-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 6px; }
.week-day ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; font-size: 0.82rem; }
.week-day li { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; line-height: 1.4; }
.week-day li small { color: var(--muted); width: 100%; padding-inline-start: 14px; }
.week-day li.done b { text-decoration: line-through; color: var(--muted); }

.goal-facts { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.goal-facts > div { background: var(--surface-2); border-radius: 10px; padding: 6px 8px; display: flex; flex-direction: column; }
.goal-facts small { color: var(--muted); font-size: 0.72rem; }
.goal-facts b { font-size: 0.9rem; }
.goal.archived { opacity: 0.6; }
.notes { white-space: pre-wrap; background: var(--surface-2); border-radius: 10px; padding: 8px 10px; font-size: 0.9rem; }

/* ---------- السجل ---------- */
.filters { gap: 10px; }
.search { display: flex; align-items: center; gap: 8px; border: 1px solid var(--border); border-radius: 12px; padding: 0 10px; background: var(--surface-2); }
.search input { border: 0; background: transparent; flex: 1; min-height: 44px; outline: none; }
.search svg { color: var(--muted); }
.timeline-day h3 { font-size: 0.9rem; color: var(--muted); margin: 6px 4px; }
.timeline { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.timeline li { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-bottom: 1px solid var(--border); }
.timeline li:last-child { border-bottom: 0; }
.timeline li > div { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.timeline li small { color: var(--muted); }

/* ---------- التقارير ---------- */
.hbar { display: flex; flex-direction: column; gap: 3px; margin: 4px 0; }
.hbar-head { display: flex; justify-content: space-between; }
.hbar-track { height: 10px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.hbar-fill { height: 100%; background: var(--primary); border-radius: 99px; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; text-align: center; }
.stats > div { background: var(--surface-2); border-radius: 12px; padding: 10px 4px; display: flex; flex-direction: column; }
.stats b { font-size: 1.35rem; color: var(--primary); }
.stats small { color: var(--muted); }
.cols { display: grid; grid-template-columns: repeat(var(--n), minmax(0, 1fr)); gap: 3px; align-items: end; height: 150px; margin-top: 6px; }
.col { display: flex; flex-direction: column; align-items: center; height: 100%; min-width: 0; }
.col-bar-wrap { flex: 1; width: 100%; display: flex; align-items: flex-end; justify-content: center; }
.col-bar { width: min(26px, 80%); background: var(--primary); border-radius: 6px 6px 2px 2px; min-height: 2px; transition: height 0.3s; }
.col-val { font-size: 0.65rem; color: var(--muted); height: 1rem; }
.col-label { font-size: 0.65rem; color: var(--muted); white-space: nowrap; overflow: hidden; max-width: 100%; }

/* ---------- النماذج ---------- */
label { display: flex; flex-direction: column; gap: 4px; font-size: 0.88rem; color: var(--muted); }
input:not([type="checkbox"]):not([type="radio"]):not([type="file"]), select, textarea {
  width: 100%; min-height: 44px; padding: 8px 12px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); font-size: 1rem;
}
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible, a:focus-visible {
  outline: 2px solid var(--primary); outline-offset: 2px;
}
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.grid2 > *, .grid3 > * { min-width: 0; }
input[type="time"], input[type="date"] { padding-inline: 6px; }
.seg { border: 1px solid var(--border); border-radius: 12px; padding: 8px 12px; margin: 0; display: flex; flex-direction: column; gap: 4px; }
.seg legend { font-size: 0.85rem; color: var(--muted); padding: 0 4px; }
.seg label, .switch { flex-direction: row; align-items: center; gap: 8px; color: var(--text); font-size: 0.95rem; }
.seg input, .switch input { width: 20px; height: 20px; accent-color: var(--primary); }
.preview { background: var(--primary-soft); border-radius: 12px; padding: 10px 12px; font-size: 0.9rem; }
.preview:empty { display: none; }
.form-error { color: var(--danger); min-height: 1.2em; font-size: 0.9rem; }

dialog {
  width: min(560px, calc(100vw - 20px)); max-height: calc(100dvh - 30px); padding: 0;
  border: 1px solid var(--border); border-radius: 20px; background: var(--surface); color: var(--text);
}
dialog::backdrop { background: rgb(0 0 0 / 0.45); }
.modal-form { display: flex; flex-direction: column; gap: 12px; padding: 18px; }
.modal-actions { display: flex; gap: 8px; position: sticky; bottom: 0; background: var(--surface); padding-top: 6px; }
.modal-actions .btn { flex: 1; }
.confirm-text { font-size: 1.05rem; }

#toast {
  position: fixed; inset-inline: 16px; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 14px);
  margin: 0 auto; max-width: 420px; padding: 12px 16px; border-radius: 14px;
  background: var(--text); color: var(--bg); text-align: center; z-index: 50;
  opacity: 0; transform: translateY(10px); pointer-events: none; transition: all 0.25s;
}
#toast.show { opacity: 1; transform: none; }

/* ---------- شريط التنقل السفلي ---------- */
.bottom-nav {
  position: fixed; inset-inline: 0; bottom: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(5, 1fr);
  height: calc(var(--nav-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface); border-top: 1px solid var(--border);
}
.bottom-nav a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); text-decoration: none; font-size: 0.75rem; font-weight: 600;
}
.bottom-nav a.active { color: var(--primary); }
.bottom-nav a.active svg { stroke-width: 2.5; }

/* ---------- الأقسام القابلة للطي ---------- */
.collapse-btn {
  display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; min-height: 36px;
  padding: 0; border: 0; background: none; cursor: pointer; text-align: start; font-weight: 700; font-size: 1.02rem;
}
.collapse-title { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; min-width: 0; }
.collapse-title svg { width: 18px; height: 18px; }
.collapse-summary { margin-inline-start: auto; font-size: 0.8rem; font-weight: 600; color: var(--muted); white-space: nowrap; }
.chev { display: grid; place-items: center; color: var(--muted); transition: transform 0.2s; }
.chev svg { width: 18px; height: 18px; }
.collapsible.collapsed .chev { transform: rotate(90deg); }
.collapsible.collapsed .card-body { display: none; }
.collapsible.collapsed { gap: 0; }
.card-body { display: flex; flex-direction: column; gap: 8px; }
.view-tools { display: flex; justify-content: flex-end; gap: 14px; margin-bottom: -6px; }
.view-tools .btn.link { min-height: 28px; font-size: 0.82rem; color: var(--muted); font-weight: 600; }
.week-card .week { margin-top: 4px; }

/* ---------- تنبيه المهام الناقصة ---------- */
.alert-card { border-color: color-mix(in srgb, var(--warn) 45%, var(--border)); background: color-mix(in srgb, var(--warn-soft) 55%, var(--surface)); }
.alert-card .collapse-title svg { color: var(--warn); }
.count-pill { background: var(--warn); color: #fff; border-radius: 999px; padding: 0 8px; font-size: 0.78rem; line-height: 1.6; }
.pending-group { display: flex; flex-direction: column; gap: 4px; }
.pending-group > small { color: var(--muted); font-weight: 600; }
.pending-list { display: flex; flex-wrap: wrap; gap: 6px; }
.pending-chip { background: var(--surface); border: 1px solid var(--border); border-radius: 999px; padding: 2px 10px; font-size: 0.85rem; }
.pending-chip em { font-style: normal; color: var(--warn); font-size: 0.78rem; }
.all-done { flex-direction: row; align-items: center; gap: 10px; color: var(--ok); background: var(--ok-soft); border-color: transparent; }

/* ---------- المهام الأخرى والقوائم ---------- */
.todo-row { display: flex; align-items: center; gap: 2px; }
.todo-row .check-row { flex: 1; min-width: 0; }
.list-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 10px; border-radius: 12px; background: var(--surface-2); }
.list-row > div:first-child { display: flex; flex-direction: column; min-width: 0; }
.stepper.small { justify-content: flex-start; gap: 8px; }
.stepper.small input[type="number"] { width: 90px; max-width: 90px; flex: none; text-align: center; font-weight: 700; }
.stepper.small .icon-btn.big { width: 42px; height: 42px; background: var(--surface); }
.small-link { font-size: 0.85rem; min-height: 28px; }
.t-todo { --c: var(--todo); }

/* ---------- الاسم وشارة الإشعارات ---------- */
.brand-text { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
.app-name { font-size: 0.72rem; font-weight: 700; color: var(--primary); letter-spacing: 0.5px; }
.nav-icon { position: relative; display: inline-grid; }
.nav-badge {
  position: absolute; top: -6px; inset-inline-end: -12px; min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 999px; background: var(--danger); color: #fff; font-size: 0.68rem; line-height: 18px; text-align: center;
}

@media (min-width: 720px) {
  main { padding: 20px; }
  .bottom-nav { max-width: 720px; margin: 0 auto; border-inline: 1px solid var(--border); border-radius: 18px 18px 0 0; }
}
@media (max-width: 380px) {
  .goal-facts { grid-template-columns: repeat(2, 1fr); }
  .grid3 { grid-template-columns: 1fr; }
  .sync-pill .label { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
