/* Home Dashboard — hand-written CSS, mobile first, RTL. Colours = assets/design/README.md (same as the email digest). */
:root {
  --bg: #f3f4f6; --card: #ffffff; --text: #111827; --muted: #6b7280; --faint: #9ca3af; --line: #e5e7eb;
  --primary: #1d4ed8; --primary-bg: #eff6ff; --urgent: #dc2626; --urgent-bg: #fef2f2; --urgent-text: #b91c1c;
  --new: #059669; --new-bg: #ecfdf5; --overdue: #b45309; --overdue-bg: #fff7ed; --grade: #6d28d9; --classroom: #0f766e;
  --review: #f59e0b; --review-bg: #fffbeb; --review-text: #92400e;
  --font: -apple-system, 'Segoe UI', Tahoma, Arial, sans-serif;
  --tap: 44px;
}
* { 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: 15px; line-height: 1.6; direction: rtl; text-align: right; }
a { color: var(--primary); text-decoration: none; }
a:hover { color: #1e40af; }
b, strong { font-weight: 700; }
small { font-size: 12px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.ic { width: 20px; height: 20px; flex: 0 0 auto; }
.ic.sm { width: 14px; height: 14px; }
code { font-size: 12px; background: #f3f4f6; padding: 0 4px; border-radius: 4px; direction: ltr; }

/* ---------- layout ---------- */
.page { max-width: 640px; margin: 0 auto; padding: 0 0 80px; min-height: 100vh; }
.topnav { display: none; }
.tabbar { position: fixed; bottom: 0; left: 0; right: 0; display: flex; background: var(--card); border-top: 1px solid var(--line); z-index: 20; padding-bottom: env(safe-area-inset-bottom); }
.tabbar a, .tabbar button { flex: 1 1 0; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 0; min-height: 56px; color: var(--muted); font-size: 11px; font-weight: 400; background: none; border: 0; font-family: inherit; cursor: pointer; }
.tabbar a.on { color: var(--primary); font-weight: 700; }
.tabbar .ic { width: 22px; height: 22px; }
.tab-form { flex: 1 1 0; display: flex; }
.tab-form button { width: 100%; }

.mhead { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 14px 16px 10px; }
.mhead-title { display: flex; align-items: center; gap: 10px; min-width: 0; }
.mhead-title > span { display: flex; flex-direction: column; min-width: 0; }
.mhead-title b { font-size: 18px; line-height: 1.3; }
.mhead-title small { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.logo { width: 44px; height: 44px; border-radius: 12px; background: var(--primary); color: #fff; display: inline-flex; align-items: center; justify-content: center; flex: 0 0 auto; }
.logo .ic { width: 22px; height: 22px; }
.logo.lg { width: 64px; height: 64px; border-radius: 18px; margin: 0 auto 12px; }
.logo.lg .ic { width: 32px; height: 32px; }
.iconbtn { position: relative; display: inline-flex; align-items: center; justify-content: center; width: 44px; height: 44px; border-radius: 12px; background: var(--card); border: 1px solid var(--line); color: var(--text); flex: 0 0 auto; }
.iconbtn .ic { color: var(--review-text); }
.mhead-title .iconbtn .ic { color: var(--text); }
.pill { display: inline-flex; align-items: center; justify-content: center; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--review); color: #fff; font-size: 11px; font-weight: 700; line-height: 1; }
.pill.abs { position: absolute; top: 6px; left: 6px; }

.sysbar { display: flex; align-items: center; gap: 8px; margin: 0 16px 10px; font-size: 12px; color: var(--muted); }
.sysbar .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--new); flex: 0 0 auto; }
.sysbar.down { background: var(--urgent-bg); color: var(--urgent-text); border-right: 4px solid var(--urgent); border-radius: 10px; padding: 8px 12px; font-weight: 700; font-size: 13px; }

.home-grid, .stack { display: flex; flex-direction: column; gap: 12px; padding: 0 16px 16px; }
.cards { display: flex; flex-direction: column; gap: 12px; }
.col-main { display: flex; flex-direction: column; gap: 12px; }
.col-main:empty { display: none; }

/* ---------- boxes / cards ---------- */
.box { display: flex; flex-direction: column; gap: 4px; padding: 12px 14px; border-radius: 12px; background: var(--card); border: 1px solid var(--line); }
.box h2 { display: flex; align-items: center; gap: 8px; margin: 0; font-size: 15px; font-weight: 700; color: var(--text); }
.box h2 .count { color: var(--muted); font-weight: 400; margin-right: auto; }
.box.urgent { background: var(--urgent-bg); border: 0; border-right: 4px solid var(--urgent); }
.box.urgent h2 { color: var(--urgent-text); }
.box.review-box { background: var(--review-bg); border: 0; border-right: 4px solid var(--review); gap: 6px; }
.box.review-box h2 { color: var(--review-text); }
.rb-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.rb-lines { font-size: 13px; color: var(--review-text); }
.box.placeholder { border: 1px dashed #7c3aed; gap: 2px; }
.box.placeholder b { font-size: 13px; color: #7c3aed; }
.box.placeholder small { color: var(--muted); }
.card { display: flex; flex-direction: column; gap: 10px; padding: 14px; border-radius: 14px; background: var(--card); border: 1px solid var(--line); border-top: 3px solid var(--c, var(--primary)); }
.child-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.who { display: flex; align-items: center; gap: 10px; color: var(--text); min-width: 0; }
.who > span:last-child { display: flex; flex-direction: column; min-width: 0; }
.who b { font-size: 17px; }
.who small { color: var(--muted); font-size: 12px; }
.avatar { display: inline-flex; align-items: center; justify-content: center; width: 32px; height: 32px; border-radius: 50%; background: var(--primary); color: #fff; font-weight: 700; }
.avatar.big { width: 40px; height: 40px; font-size: 18px; flex: 0 0 auto; }
.link-c { display: inline-flex; align-items: center; gap: 2px; color: var(--c, var(--primary)); font-size: 13px; min-height: var(--tap); padding: 0 4px; }
.link-c.inline { min-height: 32px; }
.review-box .link-c { color: var(--review-text); }
.counters { display: flex; gap: 8px; }
.counter { flex: 1 1 0; border-radius: 10px; padding: 8px 10px; display: flex; flex-direction: column; background: #f9fafb; }
.counter b { font-size: 20px; line-height: 1.3; color: var(--muted); }
.counter small { color: var(--muted); font-size: 11px; }
.counter.hot { background: var(--urgent-bg); } .counter.hot b { color: var(--urgent-text); }
.counter.late { background: var(--overdue-bg); } .counter.late b { color: var(--overdue); }
.list { display: flex; flex-direction: column; }
.childlink { flex-direction: row; align-items: center; gap: 12px; color: var(--text); }
.childlink > span:nth-child(2) { display: flex; flex-direction: column; flex: 1 1 auto; min-width: 0; }
.childlink small { color: var(--muted); }
.childlink .ic { color: var(--muted); }

/* ---------- item row ---------- */
.item { display: flex; gap: 10px; align-items: flex-start; padding: 12px 0; border-bottom: 1px solid var(--line); }
.item:last-child { border-bottom: 0; }
.ic-box { width: 36px; height: 36px; border-radius: 10px; display: flex; align-items: center; justify-content: center; flex: 0 0 auto; }
.item-body { display: flex; flex-direction: column; gap: 3px; flex: 1 1 auto; min-width: 0; }
.item-title { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; font-weight: 700; font-size: 15px; }
.item-title a { color: var(--text); }
.badge { font-size: 11px; font-weight: 400; padding: 1px 7px; border-radius: 999px; white-space: nowrap; }
.badge.new { color: var(--new); background: var(--new-bg); }
.badge.done { color: #fff; background: var(--new); }
.badge.review { color: var(--review-text); background: var(--review-bg); }
.badge.muted { color: var(--muted); background: #f3f4f6; }
.item-meta { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.chip { font-size: 12px; padding: 1px 8px; border-radius: 999px; background: #f3f4f6; color: var(--text); white-space: nowrap; }
.when { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; color: var(--primary); }
.when.late { color: var(--overdue); }
.summary { font-size: 13px; color: #374151; }
.action { font-size: 13px; color: var(--urgent-text); }
.amount { font-size: 13px; }
.grade { font-size: 15px; font-weight: 700; color: var(--grade); }
.item-foot { display: flex; gap: 12px; align-items: center; justify-content: space-between; margin-top: 4px; flex-wrap: wrap; }
.src { font-size: 11px; color: var(--faint); }
.btns { display: flex; gap: 6px; flex-wrap: wrap; }
.done-state .muted { font-weight: 400; }
.item.static .item-title a { pointer-events: none; }
.fields { display: grid; grid-template-columns: max-content 1fr; gap: 2px 12px; margin: 4px 0; font-size: 13px; }
.fields dt { color: var(--muted); } .fields dd { margin: 0; }
.fields .reason { color: var(--review-text); }
.evidence { margin: 4px 0; font-size: 12px; color: var(--muted); border-right: 2px solid var(--line); padding-right: 8px; direction: ltr; text-align: left; white-space: pre-wrap; }
.note-urgent { display: flex; align-items: center; gap: 6px; padding: 10px 4px 2px; font-size: 13px; color: var(--urgent-text); }
.empty { display: flex; align-items: center; gap: 8px; padding: 14px 4px; color: var(--new); font-weight: 700; }
details.more > summary { cursor: pointer; color: var(--primary); font-size: 13px; padding: 10px 0; min-height: var(--tap); display: flex; align-items: center; list-style: none; }
details.more > summary::-webkit-details-marker { display: none; }
details.more[open] > summary { display: none; }
/* #08 step 0: «عاجل الآن» on the phone — summary behind «المزيد»; the desktop copy (.fold-desk) is hidden here */
details.fold > summary { cursor: pointer; color: var(--primary); font-size: 13px; min-height: var(--tap); display: flex; align-items: center; list-style: none; }
details.fold > summary::-webkit-details-marker { display: none; }
details.fold[open] > summary { display: none; }
.summary.fold-desk { display: none; }

/* ---------- buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 4px; font-size: 13px; font-weight: 400; padding: 8px 12px; min-height: var(--tap); border-radius: 8px; border: 0; background: var(--primary-bg); color: var(--primary); font-family: inherit; cursor: pointer; line-height: 1.2; white-space: nowrap; }
.btn.mail { background: var(--primary-bg); color: var(--primary); }
.btn.done { background: var(--new-bg); color: var(--new); }
.btn.primary { background: var(--primary); color: #fff; font-weight: 700; }
.btn.primary-green { background: var(--new); color: #fff; font-weight: 700; flex: 1 1 0; }
.btn.outline { background: var(--card); color: var(--primary); border: 1px solid var(--primary); font-weight: 700; }
.btn.icon-only { width: var(--tap); padding: 0; background: var(--card); color: var(--muted); border: 1px solid var(--line); }
.btn.ghost { background: transparent; color: var(--muted); }
.btn.small { min-height: 32px; padding: 4px 8px; }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .6; }
.htmx-request .btn, .btn.htmx-request { opacity: .6; pointer-events: none; }

/* ---------- child page ---------- */
.tabs { display: flex; padding: 0 16px; border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.tabs a { flex: 1 1 0; text-align: center; padding: 10px 0; min-height: var(--tap); font-size: 14px; color: var(--muted); border-bottom: 2px solid transparent; }
.tabs a.on { color: var(--c, var(--primary)); font-weight: 700; border-bottom-color: var(--c, var(--primary)); }
.chips { display: flex; gap: 6px; padding: 10px 16px; flex-wrap: wrap; }
.chips .chip { font-size: 12px; padding: 6px 12px; min-height: 32px; border-radius: 999px; background: var(--card); color: var(--text); border: 1px solid var(--line); display: inline-flex; align-items: center; }
.chips .chip.on { background: var(--c, var(--primary)); color: #fff; border-color: var(--c, var(--primary)); }
.tablewrap { overflow-x: auto; }
table.grades, table.status, table.digests { width: 100%; border-collapse: collapse; font-size: 13px; }
table.grades th, table.digests th { text-align: right; color: var(--muted); font-weight: 400; padding: 6px 4px; border-bottom: 1px solid var(--line); }
table.grades td, table.digests td { padding: 8px 4px; border-bottom: 1px solid #f3f4f6; vertical-align: top; }
td.num { white-space: nowrap; }
table.status th { text-align: right; color: var(--muted); font-weight: 400; padding: 6px 4px; width: 34%; vertical-align: top; border-bottom: 1px solid #f3f4f6; }
table.status td { padding: 6px 4px; border-bottom: 1px solid #f3f4f6; word-break: break-word; }
table.status .hint { color: var(--review-text); font-size: 12px; }

/* ---------- item page ---------- */
.email-head { font-size: 13px; }
.email-body { white-space: pre-wrap; word-break: break-word; font-family: inherit; font-size: 13px; color: #374151; background: #f9fafb; border-radius: 8px; padding: 10px 12px; margin: 6px 0; max-height: 60vh; overflow: auto; direction: ltr; text-align: left; unicode-bidi: plaintext; }
.attachments ul, .siblings ul, .edits { margin: 4px 0 0; padding: 0 18px 0 0; font-size: 13px; }
.attachments li { display: flex; align-items: center; gap: 6px; }
.edits li { color: #374151; }

/* ---------- review ---------- */
.rcard { display: flex; flex-direction: column; gap: 8px; padding: 14px; border-radius: 12px; background: var(--card); border: 1px solid var(--line); border-right: 4px solid var(--review); }
.rc-title { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; font-size: 15px; }
.rc-title a { color: var(--text); }
.rcard .summary { font-size: 13px; }
.rcard .reason { font-size: 13px; color: var(--review-text); background: var(--review-bg); padding: 8px 10px; border-radius: 8px; }
.rc-actions { display: flex; gap: 8px; margin-top: 4px; flex-wrap: wrap; align-items: center; }
details.editdate { flex: 1 1 0; }
details.editdate > summary { list-style: none; width: 100%; }
details.editdate > summary::-webkit-details-marker { display: none; }
details.editdate form { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; padding: 10px; background: #f9fafb; border-radius: 8px; }
details.editdate label, .assign label { display: flex; flex-direction: column; gap: 2px; font-size: 12px; color: var(--muted); }
details.editdate input, .assign select { font-family: inherit; font-size: 14px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; min-height: var(--tap); background: var(--card); color: var(--text); }
.rcard.done-state { border-right-color: var(--new); background: var(--new-bg); }
.rcard.done-state .ic { color: var(--new); }
.unassigned { display: flex; flex-direction: column; gap: 6px; padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.unassigned:last-child { border-bottom: 0; }
.unassigned.done-state { flex-direction: row; align-items: center; gap: 8px; color: var(--new); font-weight: 700; }
.assign { display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; }
.flash { padding: 8px 12px; border-radius: 8px; font-size: 13px; }
.flash.err { background: var(--urgent-bg); color: var(--urgent-text); }
.flash.ok { background: var(--new-bg); color: var(--new); }

/* ---------- digests ---------- */
.digest-frame { width: 100%; min-height: 80vh; border: 1px solid var(--line); border-radius: 12px; background: #fff; }

/* ---------- login ---------- */
.loginpage { display: flex; align-items: center; justify-content: center; padding-bottom: 0; }
.login { width: 100%; max-width: 380px; margin: 40px auto; padding: 24px; text-align: center; background: var(--card); border: 1px solid var(--line); border-radius: 16px; }
.login h1 { font-size: 20px; margin: 4px 0; color: var(--primary); }
.loginform { display: flex; flex-direction: column; gap: 12px; text-align: right; margin-top: 12px; }
.loginform label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.loginform input { font-family: inherit; font-size: 15px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; min-height: var(--tap); }
.loginform input:focus { outline: 2px solid var(--primary); border-color: var(--primary); }

/* ---------- desktop ≥ 900px ---------- */
@media (min-width: 900px) {
  :root { --tap: 36px; }
  .page { max-width: 1200px; padding: 0 0 32px; }
  .tabbar { display: none; }
  .topnav { display: block; background: var(--card); border-bottom: 2px solid var(--primary); }
  .topnav-inner { max-width: 1200px; margin: 0 auto; display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 12px 28px; }
  .brand { display: flex; align-items: center; gap: 12px; color: var(--text); }
  .brand .logo { width: 40px; height: 40px; }
  .brand-text { display: flex; flex-direction: column; line-height: 1.3; }
  .brand-text b { color: var(--primary); font-size: 18px; }
  .brand-text small { color: var(--muted); }
  .links { display: flex; gap: 4px; }
  .links a { padding: 8px 14px; border-radius: 10px; color: var(--muted); font-size: 14px; min-height: 40px; display: inline-flex; align-items: center; gap: 6px; }
  .links a.on { background: var(--primary-bg); color: var(--c, var(--primary)); font-weight: 700; }
  .links a[style] { color: var(--c); }
  .userbox { display: flex; align-items: center; gap: 8px; margin: 0; }
  .mhead { padding: 18px 28px 8px; }
  .mhead .logo { display: none; }
  .mhead-title .iconbtn { display: none; }
  .sysbar { margin: 0 28px 12px; }
  .home-grid { padding: 0 28px 24px; }
  .stack { padding: 0 28px 24px; }
  .stack.narrow { max-width: 760px; }
  .cards { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; align-items: start; }
  .tabs, .chips { padding-left: 28px; padding-right: 28px; }
  .tabs a { flex: 0 0 auto; padding: 10px 24px; }
  .btn.mail, .btn.done { min-height: 32px; padding: 6px 10px; font-size: 12px; }
  details.fold { display: none; }            /* desktop: summary inline as before */
  .summary.fold-desk { display: block; }
  .digest-frame { min-height: 70vh; }
}
