/* بيتنا — الأنماط */
@font-face { font-family: "Plex Arabic"; src: url("fonts/plex-ar-400.woff2") format("woff2"); font-weight: 400; font-display: swap; unicode-range: U+0600-06FF, U+0750-077F, U+0870-088E, U+0890-0891, U+0898-08E1, U+08E3-08FF, U+200C-200E, U+2010-2011, U+204F, U+2E41, U+FB50-FDFF, U+FE70-FE74, U+FE76-FEFC; }
@font-face { font-family: "Plex Arabic"; src: url("fonts/plex-ar-500.woff2") format("woff2"); font-weight: 500; font-display: swap; unicode-range: U+0600-06FF, U+0750-077F, U+0870-088E, U+0890-0891, U+0898-08E1, U+08E3-08FF, U+200C-200E, U+2010-2011, U+204F, U+2E41, U+FB50-FDFF, U+FE70-FE74, U+FE76-FEFC; }
@font-face { font-family: "Plex Arabic"; src: url("fonts/plex-ar-700.woff2") format("woff2"); font-weight: 700; font-display: swap; unicode-range: U+0600-06FF, U+0750-077F, U+0870-088E, U+0890-0891, U+0898-08E1, U+08E3-08FF, U+200C-200E, U+2010-2011, U+204F, U+2E41, U+FB50-FDFF, U+FE70-FE74, U+FE76-FEFC; }
@font-face { font-family: "Plex Arabic"; src: url("fonts/plex-lat-400.woff2") format("woff2"); font-weight: 400; font-display: swap; unicode-range: U+0000-00FF, U+2000-206F, U+20AC; }
@font-face { font-family: "Plex Arabic"; src: url("fonts/plex-lat-500.woff2") format("woff2"); font-weight: 500; font-display: swap; unicode-range: U+0000-00FF, U+2000-206F, U+20AC; }
@font-face { font-family: "Plex Arabic"; src: url("fonts/plex-lat-700.woff2") format("woff2"); font-weight: 700; font-display: swap; unicode-range: U+0000-00FF, U+2000-206F, U+20AC; }

:root {
  --bg: #f6f2ea;
  --surface: #fffdf9;
  --surface-2: #f0ebe1;
  --line: #e2dbcd;
  --text: #2a2620;
  --muted: #6f675a;
  --primary: #1f6b5c;
  --primary-ink: #ffffff;
  --primary-soft: #dcefe9;
  --done: #2e7d4f;      --done-bg: #e1f2e7;
  --progress: #9a6a00;  --progress-bg: #fbefd2;
  --missed: #b23b3b;    --missed-bg: #f8e1df;
  --idle: #5d6670;      --idle-bg: #eceef0;
  --cancel: #8b8b8b;    --cancel-bg: #efefef;
  --review: #4b57b0;    --review-bg: #e5e7f7;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(60, 45, 20, .06), 0 4px 14px rgba(60, 45, 20, .06);
  --font: "Plex Arabic", "Segoe UI", Tahoma, "Geeza Pro", "Noto Naskh Arabic", system-ui, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171a19; --surface: #212524; --surface-2: #2a2f2d; --line: #39403d;
    --text: #ece8df; --muted: #a59f93; --primary: #4fb39c; --primary-ink: #0d1f1a; --primary-soft: #1f3a33;
    --done: #6fcf97; --done-bg: #1d3427; --progress: #e8b84a; --progress-bg: #3a3020;
    --missed: #f08a84; --missed-bg: #3d2423; --idle: #b0b8c0; --idle-bg: #2b3034;
    --cancel: #9a9a9a; --cancel-bg: #2b2b2b; --review: #9aa5ff; --review-bg: #282c4a;
    --shadow: 0 1px 2px rgba(0,0,0,.4);
    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.6; min-height: 100vh; min-height: 100dvh;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--primary); }
h1, h2, h3 { line-height: 1.3; margin: 0 0 .5em; }
h1 { font-size: 1.45rem; } h2 { font-size: 1.2rem; } h3 { font-size: 1.05rem; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.num { font-variant-numeric: tabular-nums; }
[hidden] { display: none !important; }
.ltr { direction: ltr; unicode-bidi: isolate; }
code { background: var(--surface-2); padding: 0 .3em; border-radius: 4px; }

/* الهيكل */
.topbar {
  position: sticky; top: 0; z-index: 20; background: var(--surface); border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 12px; padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
}
.brand { font-weight: 700; font-size: 1.15rem; display: flex; align-items: center; gap: 8px; color: var(--text); text-decoration: none; }
.brand img { width: 30px; height: 30px; border-radius: 8px; }
.topbar .spacer { flex: 1; }
.topbar .who { color: var(--muted); font-size: .9rem; }
.nav { display: flex; gap: 4px; overflow-x: auto; padding: 8px 16px; background: var(--surface); border-bottom: 1px solid var(--line); scrollbar-width: none; }
.nav::-webkit-scrollbar { display: none; }
.nav a { white-space: nowrap; padding: 8px 14px; border-radius: 999px; text-decoration: none; color: var(--muted); font-weight: 500; }
.nav a.on { background: var(--primary-soft); color: var(--primary); }
main.view { max-width: 1100px; margin: 0 auto; padding: 16px; padding-bottom: calc(40px + env(safe-area-inset-bottom)); }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.stack > * + * { margin-top: 12px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.section-title { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 22px 0 10px; flex-wrap: wrap; }
.section-title h2 { margin: 0; }

/* الأزرار */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 8px 16px;
  border-radius: 12px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; text-decoration: none;
  font-weight: 500; color: var(--text); transition: background .15s, transform .05s;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--primary); color: var(--primary-ink); border-color: transparent; }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { color: var(--missed); border-color: var(--missed); background: transparent; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.big { min-height: 54px; font-size: 1.05rem; padding: 10px 22px; }
.btn.sm { min-height: 36px; padding: 4px 12px; font-size: .9rem; }
.btn.block { width: 100%; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--primary) 60%, transparent); outline-offset: 2px; }

/* النماذج */
.form { display: grid; gap: 14px; }
.form label, .field { display: grid; gap: 6px; font-weight: 500; }
.form .hint { font-weight: 400; color: var(--muted); font-size: .85rem; }
input[type=text], input[type=password], input[type=date], input[type=time], input[type=number], input:not([type]), select, textarea {
  width: 100%; min-height: 46px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface);
}
textarea { min-height: 84px; resize: vertical; }
.form .two { display: grid; gap: 12px; grid-template-columns: 1fr 1fr; }
@media (max-width: 520px) { .form .two { grid-template-columns: 1fr; } }
.check { display: flex !important; align-items: center; gap: 10px; font-weight: 400 !important; }
.check input { width: 22px; height: 22px; accent-color: var(--primary); }
.days { display: flex; flex-wrap: wrap; gap: 6px; }
.days label { position: relative; }
.days input { position: absolute; opacity: 0; inset: 0; cursor: pointer; }
.days span { display: inline-block; padding: 8px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); min-width: 58px; text-align: center; font-weight: 500; }
.days input:checked + span { background: var(--primary); color: var(--primary-ink); border-color: transparent; }
.days input:focus-visible + span { outline: 3px solid color-mix(in srgb, var(--primary) 60%, transparent); }

/* رسائل */
.msg { padding: 12px 14px; border-radius: 12px; margin: 0 0 12px; }
.msg.ok { background: var(--done-bg); color: var(--done); }
.msg.err { background: var(--missed-bg); color: var(--missed); }
.msg.info { background: var(--primary-soft); color: var(--primary); }
.toast-wrap { position: fixed; inset-inline: 0; bottom: calc(16px + env(safe-area-inset-bottom)); display: grid; justify-items: center; gap: 8px; z-index: 100; pointer-events: none; padding: 0 16px; }
.toast { pointer-events: auto; background: var(--text); color: var(--bg); padding: 12px 18px; border-radius: 12px; box-shadow: var(--shadow); max-width: 520px; font-weight: 500; animation: pop .2s ease-out; }
.toast.err { background: var(--missed); color: #fff; }
.toast.ok { background: var(--done); color: #fff; }
@keyframes pop { from { transform: translateY(8px); opacity: 0; } }
.loading { display: grid; place-items: center; padding: 48px 16px; color: var(--muted); gap: 12px; }
.spinner { width: 34px; height: 34px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--primary); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.empty { text-align: center; padding: 32px 16px; color: var(--muted); }
.empty .big-emoji { font-size: 2.4rem; display: block; margin-bottom: 6px; }

/* الحالات */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 10px; border-radius: 999px; font-size: .82rem; font-weight: 500; white-space: nowrap; }
.st-not_started { background: var(--idle-bg); color: var(--idle); }
.st-in_progress { background: var(--progress-bg); color: var(--progress); }
.st-done { background: var(--done-bg); color: var(--done); }
.st-missed { background: var(--missed-bg); color: var(--missed); }
.st-cancelled { background: var(--cancel-bg); color: var(--cancel); }
.st-overdue { background: var(--missed-bg); color: var(--missed); }
.st-review { background: var(--review-bg); color: var(--review); }
.st-late { background: var(--progress-bg); color: var(--progress); }

/* بطاقة المهمة */
.task { display: grid; gap: 10px; padding: 14px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line); border-inline-start: 6px solid var(--cat, var(--line)); box-shadow: var(--shadow); }
.task.is-done { background: color-mix(in srgb, var(--done-bg) 55%, var(--surface)); }
.task.is-cancelled { opacity: .6; }
.task .head { display: flex; gap: 10px; align-items: flex-start; }
.task .icon { font-size: 1.6rem; line-height: 1; flex: none; margin-top: 2px; }
.task .title { font-weight: 700; font-size: 1.08rem; }
.task .meta { display: flex; flex-wrap: wrap; gap: 6px 12px; color: var(--muted); font-size: .88rem; }
.task .desc { color: var(--muted); font-size: .92rem; white-space: pre-line; }
.task .notes { font-size: .9rem; display: grid; gap: 4px; }
.task .notes p { margin: 0; padding: 6px 10px; border-radius: 10px; background: var(--surface-2); }
.task .actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.task .actions .btn { min-height: 56px; font-size: 1rem; flex-direction: column; gap: 0; line-height: 1.2; padding: 6px; }
.task .actions .btn .ic { font-size: 1.3rem; }
.btn.act-done.on { background: var(--done); color: #fff; border-color: transparent; }
.btn.act-progress.on { background: var(--progress); color: #fff; border-color: transparent; }
.btn.act-missed.on { background: var(--missed); color: #fff; border-color: transparent; }
.prio-3 .title::after { content: " • مهمة"; color: var(--missed); font-size: .8rem; font-weight: 500; }

/* التقدم */
.progress { height: 12px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.progress > i { display: block; height: 100%; width: var(--p, 0%); background: var(--primary); border-radius: 999px; transition: width .4s; }
.ring { --p: 0; width: 92px; height: 92px; border-radius: 50%; display: grid; place-items: center; flex: none;
  background: conic-gradient(var(--primary) calc(var(--p) * 1%), var(--surface-2) 0); }
.ring > span { width: 74px; height: 74px; border-radius: 50%; background: var(--surface); display: grid; place-items: center; font-weight: 700; font-size: 1.2rem; text-align: center; line-height: 1.1; }
.ring > span small { display: block; font-size: .7rem; color: var(--muted); font-weight: 400; }
.hero { display: flex; gap: 16px; align-items: center; }
.hero h1 { margin: 0; }

/* بطاقة الابن في لوحة الأب */
.kid { display: grid; gap: 12px; text-decoration: none; color: inherit; border-top: 5px solid var(--kid, var(--primary)); }
.kid .top { display: flex; align-items: center; gap: 12px; }
.kid .avatar { width: 46px; height: 46px; border-radius: 50%; display: grid; place-items: center; font-size: 1.5rem; background: color-mix(in srgb, var(--kid, var(--primary)) 18%, var(--surface)); flex: none; }
.kid .name { font-weight: 700; font-size: 1.15rem; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; text-align: center; }
.stats div { background: var(--surface-2); border-radius: 12px; padding: 8px 4px; }
.stats b { display: block; font-size: 1.25rem; }
.stats span { font-size: .78rem; color: var(--muted); }
.mini-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.mini-list li { display: flex; gap: 8px; align-items: center; justify-content: space-between; padding: 8px 10px; background: var(--surface-2); border-radius: 10px; font-size: .92rem; }

/* جداول */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
table { width: 100%; border-collapse: collapse; font-size: .93rem; }
th, td { padding: 10px 12px; text-align: start; border-bottom: 1px solid var(--line); vertical-align: top; }
th { background: var(--surface-2); font-weight: 700; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
.bar-row { display: grid; grid-template-columns: minmax(120px, 1.2fr) 3fr auto; gap: 10px; align-items: center; font-size: .92rem; }

/* النوافذ */
dialog { border: 0; border-radius: 20px; padding: 0; width: min(560px, calc(100vw - 24px)); max-height: calc(100dvh - 32px); background: var(--surface); color: var(--text); box-shadow: 0 20px 60px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(20, 18, 14, .45); }
dialog .dlg { padding: 18px; display: grid; gap: 14px; }
dialog .dlg-actions { display: flex; gap: 8px; justify-content: flex-start; flex-wrap: wrap; position: sticky; bottom: 0; background: var(--surface); padding-top: 8px; }
.reasons { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.reasons label { position: relative; }
.reasons input { position: absolute; opacity: 0; inset: 0; }
.reasons span { display: block; padding: 12px; border-radius: 12px; border: 1px solid var(--line); text-align: center; font-weight: 500; cursor: pointer; }
.reasons input:checked + span { background: var(--missed-bg); border-color: var(--missed); color: var(--missed); }

/* تبويبات وأدوات */
.tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.tabs button { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 6px 14px; cursor: pointer; min-height: 40px; }
.tabs button.on { background: var(--primary); color: var(--primary-ink); border-color: transparent; }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar select, .toolbar input { width: auto; min-width: 140px; }
.list { display: grid; gap: 10px; }
.item { display: flex; gap: 12px; align-items: center; justify-content: space-between; padding: 12px 14px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); flex-wrap: wrap; }
.item .grow { flex: 1; min-width: 200px; }
.item.off { opacity: .6; }
.dot { width: 12px; height: 12px; border-radius: 50%; display: inline-block; background: var(--c, var(--primary)); vertical-align: middle; }

/* شبكة الأسبوع للجدول */
.week { display: grid; grid-template-columns: repeat(7, minmax(130px, 1fr)); gap: 8px; overflow-x: auto; }
.week .day { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 10px; min-height: 120px; }
.week .day h4 { margin: 0 0 8px; font-size: .95rem; }
.week .blk { font-size: .82rem; padding: 6px 8px; border-radius: 8px; background: var(--surface-2); border-inline-start: 4px solid var(--c, var(--primary)); margin-bottom: 6px; cursor: pointer; }
.week .blk b { display: block; }
.warn { background: var(--progress-bg); color: var(--progress); padding: 10px 12px; border-radius: 12px; }

/* صفحة الدخول */
body.plain, .login-wrap { display: grid; place-items: center; min-height: 100dvh; padding: 16px; }
.login { width: min(420px, 100%); }
.login .logo { width: 84px; height: 84px; border-radius: 22px; display: block; margin: 0 auto 10px; }
.login h1 { text-align: center; margin-bottom: 2px; }
.login .sub { text-align: center; color: var(--muted); margin: 0 0 18px; }
main.setup { width: min(520px, 100%); }

@media (max-width: 640px) {
  .topbar .who { display: none; }
  .stats b { font-size: 1.1rem; }
  .ring { width: 78px; height: 78px; } .ring > span { width: 62px; height: 62px; font-size: 1.05rem; }
  .hide-sm { display: none !important; }
  .bar-row { grid-template-columns: 1fr 2fr auto; }
}

/* الطباعة: التقرير فقط */
@media print {
  :root { --bg: #fff; --surface: #fff; --shadow: none; }
  .topbar, .nav, .toolbar, .no-print, .toast-wrap { display: none !important; }
  main.view { max-width: none; padding: 0; }
  .card { break-inside: avoid; border-color: #ccc; }
  body { font-size: 12px; }
  .table-wrap { overflow: visible; }
}

.row input, .row select, .toolbar input, .toolbar select { width: auto; }
@media (max-width: 640px) {
  .week { grid-template-columns: 1fr; overflow: visible; }
  .week .day { min-height: 0; }
}
