/* ChannelBook — رموز التصميم من school-comms-DESIGN.md
   لا لون مكتوب مباشرة في أي مكان آخر: كل شيء من هذه المتغيّرات،
   و`primary`/`accent` وحدهما يُستبدلان لكل مدرسة. */

:root {
  --primary: #14304F;
  --primary-hover: #1D4E77;
  --primary-subtle: #E8F0F7;
  --on-primary: #FFFFFF;
  --accent: #F0B429;
  --accent-hover: #D89E14;
  --on-accent: #3D2A00;

  --background: #FFFFFF;
  --surface: #F5F8FB;
  --surface-raised: #FFFFFF;
  --surface-sunken: #EDF2F7;
  --border: #DDE7F0;
  --border-strong: #B4C7D9;
  --text: #1F2937;
  --text-muted: #5B6B7C;
  --text-faint: #94A3B8;
  --text-inverse: #FFFFFF;

  --ledger-surface: #FBF9F4;
  --ledger-rule: #E4DED0;
  --ledger-rule-major: #C9BFA8;
  --ledger-locked: #F2EFE7;

  --success: #1B7F5A;  --success-subtle: #E6F4EE;
  --warning: #B45309;  --warning-subtle: #FDF3E3;
  --danger:  #B42318;  --danger-subtle:  #FDECEA;
  --info:    #1D4E77;  --info-subtle:    #E8F0F7;
  --neutral-state: #64748B; --neutral-state-subtle: #F1F5F9;

  --focus-ring: #1D4E77;

  --r-sm: 6px; --r-md: 10px; --r-lg: 14px; --r-pill: 999px;
  --touch: 44px; --field: 48px; --row: 48px; --nav: 60px;
  --content-max: 1160px; --reading-max: 68ch;

  --sh-card: 0 1px 2px rgba(20,48,79,.06);
  --sh-raised: 0 2px 8px rgba(20,48,79,.08);
  --sh-elevated: 0 8px 24px rgba(20,48,79,.12);
  --sh-sticky: 0 -2px 8px rgba(20,48,79,.08);

  --ease: cubic-bezier(.2,0,.2,1);
  --fast: 140ms; --normal: 200ms;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  background: var(--surface);
  color: var(--text);
  font-family: Cairo, 'Noto Naskh Arabic', 'Segoe UI', system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.75;
  font-variant-numeric: tabular-nums;
  -webkit-text-size-adjust: 100%;
}

/* أرقام الهواتف والرقم القومي سلاسل رقمية تُقرأ من اليسار لليمين */
.tel, .num-ltr { direction: ltr; unicode-bidi: isolate; display: inline-block; }

a { color: var(--primary-hover); text-underline-offset: 3px; }
:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; border-radius: var(--r-sm); }

/* ── الترويسة ─────────────────────────────────────────────── */
header.app { background: var(--primary); color: var(--on-primary); }
header.app .in {
  max-width: var(--content-max); margin-inline: auto; padding: 12px 16px;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
}
header.app a { color: var(--on-primary); text-decoration: none; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 17px; }
.brand svg { display: block; }
.vsep { width: 1px; height: 22px; background: rgba(255,255,255,.28); }
.who { font-size: 13px; opacity: .85; }
.spacer { margin-inline-start: auto; }

nav.main {
  background: var(--surface-raised); border-bottom: 1px solid var(--border);
  overflow-x: auto; -webkit-overflow-scrolling: touch;
}
nav.main .in {
  max-width: var(--content-max); margin-inline: auto; padding-inline: 8px;
  display: flex; gap: 2px; white-space: nowrap;
}
nav.main a {
  display: inline-flex; align-items: center; gap: 6px; min-height: var(--touch);
  padding: 0 12px; font-size: 14px; font-weight: 600;
  color: var(--text-muted); text-decoration: none; border-bottom: 2px solid transparent;
}
nav.main a[aria-current="page"] { color: var(--primary); border-bottom-color: var(--primary); }
.badge {
  background: var(--accent); color: var(--on-accent);
  font-size: 12px; font-weight: 700; border-radius: var(--r-pill);
  padding: 0 7px; min-width: 20px; text-align: center;
}

main { max-width: var(--content-max); margin-inline: auto; padding: 16px 16px 96px; }

h1 { font-size: 22px; font-weight: 700; line-height: 1.5; margin: 8px 0 4px; }
h2 { font-size: 18px; font-weight: 700; line-height: 1.55; margin: 24px 0 8px; }
h3 { font-size: 16px; font-weight: 600; margin: 16px 0 8px; }
p.sub { color: var(--text-muted); font-size: 13px; margin: 0 0 16px; max-width: var(--reading-max); }
.prose { max-width: var(--reading-max); }

/* ── البطاقات ─────────────────────────────────────────────── */
.card {
  background: var(--surface-raised); border: 1px solid var(--border);
  border-radius: var(--r-lg); box-shadow: var(--sh-card); margin-bottom: 16px; overflow: hidden;
}
.card > .head {
  padding: 12px 16px; border-bottom: 1px solid var(--border);
  display: flex; gap: 12px; align-items: flex-start; flex-wrap: wrap;
}
.card > .body { padding: 16px; }
.card.due { border-inline-end: 2px solid var(--accent); }
.muted { color: var(--text-muted); font-size: 13px; }
.faint { color: var(--text-faint); font-size: 12px; }

/* ── الأزرار والحقول ─────────────────────────────────────── */
.btn {
  font: inherit; font-weight: 600; font-size: 14px; cursor: pointer;
  min-height: var(--touch); padding: 0 16px; border-radius: var(--r-md);
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--primary); color: var(--on-primary); border: 1px solid var(--primary);
  text-decoration: none; transition: background var(--fast) var(--ease);
}
.btn:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn.ghost { background: transparent; color: var(--primary); }
.btn.ghost:hover { background: var(--primary-subtle); }
.btn.danger { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn.block { width: 100%; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.btn-row .btn { flex: 1 1 140px; }

label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 4px; }
input[type=text], input[type=password], input[type=search], input[type=number],
input[type=date], input[type=file], select, textarea {
  font: inherit; font-size: 15px; width: 100%;
  min-height: var(--field); padding: 8px 12px;
  border: 1px solid var(--border-strong); border-radius: var(--r-md);
  background: var(--surface-raised); color: var(--text);
}
textarea { min-height: 120px; line-height: 1.75; resize: vertical; }
.field { margin-bottom: 16px; }
.hint { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.err-text { font-size: 13px; color: var(--danger); margin-top: 4px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px,1fr)); gap: 12px; }

/* ── الشارات ──────────────────────────────────────────────── */
.pill {
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
  font-size: 13px; font-weight: 600; border-radius: var(--r-pill); padding: 4px 12px;
}
.pill.ok { background: var(--success-subtle); color: var(--success); }
.pill.warn { background: var(--warning-subtle); color: var(--warning); }
.pill.bad { background: var(--danger-subtle); color: var(--danger); }
.pill.info { background: var(--info-subtle); color: var(--info); }
.pill.calm { background: var(--neutral-state-subtle); color: var(--neutral-state); }
.ic { font-size: 12px; line-height: 1; }

.alert {
  display: flex; gap: 12px; align-items: flex-start; border-radius: var(--r-md);
  padding: 12px 16px; margin-bottom: 16px; font-size: 14px;
}
.alert.warn { background: var(--warning-subtle); color: var(--warning); border-inline-start: 2px solid var(--warning); }
.alert.bad  { background: var(--danger-subtle);  color: var(--danger);  border-inline-start: 2px solid var(--danger); }
.alert.ok   { background: var(--success-subtle); color: var(--success); border-inline-start: 2px solid var(--success); }
.alert.info { background: var(--info-subtle);    color: var(--info);    border-inline-start: 2px solid var(--info); }
.alert b { font-weight: 700; }
.alert .body { color: var(--text); }

/* ── الجداول: لوحة الدفتر ─────────────────────────────────── */
.scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; background: var(--ledger-surface); }
thead th {
  text-align: start; font-size: 13px; font-weight: 600; color: var(--text-muted);
  padding: 8px 12px; border-bottom: 1px solid var(--ledger-rule-major); white-space: nowrap;
}
thead th .max { display: block; font-size: 12px; font-weight: 400; color: var(--text-muted); }
tbody td { padding: 8px 12px; border-bottom: 1px solid var(--ledger-rule); font-size: 14px; }
tbody tr:last-child td { border-bottom: none; }
td.name, th.name {
  font-weight: 600; white-space: nowrap;
  border-inline-end: 1px solid var(--ledger-rule-major);
  position: sticky; inset-inline-start: 0; background: var(--ledger-surface);
}
tr.locked td { background: var(--ledger-locked); color: var(--text-muted); }
tr.dim td { background: var(--ledger-locked); color: var(--text-muted); }

/* خلية الرصد: حالتها مرئية دائماً */
input.cell {
  width: 72px; min-height: 40px; text-align: center; padding: 4px;
  border: 1px solid transparent; background: transparent; border-radius: var(--r-sm);
  font-weight: 600; font-size: 15px;
}
input.cell:hover { border-color: var(--border); }
input.cell:focus { border-color: var(--focus-ring); outline: 2px solid var(--focus-ring); outline-offset: 0; background: var(--surface-raised); }
input.cell.saving { border-color: var(--info); }
input.cell.error { background: var(--danger-subtle); border-color: var(--danger); }
input.cell[readonly] { color: var(--text-muted); }

/* ── الحضور ───────────────────────────────────────────────── */
.att-list { display: grid; gap: 8px; }
.att-row {
  display: flex; align-items: center; gap: 12px; min-height: 56px;
  padding: 8px 12px; background: var(--surface-raised);
  border: 1px solid var(--border); border-radius: var(--r-md);
}
.att-row .nm { font-weight: 600; }
.att-row .opts { margin-inline-start: auto; display: flex; gap: 4px; flex-wrap: wrap; }
.att-opt {
  font: inherit; font-size: 13px; font-weight: 600; cursor: pointer;
  min-height: var(--touch); min-width: var(--touch); padding: 0 12px;
  border-radius: var(--r-md); border: 1px solid var(--border-strong);
  background: var(--surface-raised); color: var(--text-muted);
}
.att-opt[aria-pressed="true"][data-status="present"] { background: var(--success-subtle); color: var(--success); border-color: var(--success); }
.att-opt[aria-pressed="true"][data-status="absent"]  { background: var(--danger-subtle);  color: var(--danger);  border-color: var(--danger); }
.att-opt[aria-pressed="true"][data-status="late"]    { background: var(--warning-subtle); color: var(--warning); border-color: var(--warning); }
.att-opt[aria-pressed="true"][data-status="excused"] { background: var(--info-subtle);    color: var(--info);    border-color: var(--info); }

.sticky-bar {
  position: sticky; bottom: 0; background: var(--surface-raised);
  border-top: 1px solid var(--border); box-shadow: var(--sh-sticky);
  padding: 12px 16px; display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  margin: 16px -16px -96px;
}
.counter { font-weight: 600; font-size: 15px; }

/* ── التبويبات ────────────────────────────────────────────── */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; }
.tabs a {
  display: inline-flex; align-items: center; gap: 8px; min-height: var(--touch);
  padding: 0 14px; font-size: 14px; font-weight: 600; white-space: nowrap;
  color: var(--text-muted); text-decoration: none; border-bottom: 2px solid transparent;
}
.tabs a[aria-current="page"] { color: var(--primary); border-bottom-color: var(--primary); }

/* ── الفراغ ───────────────────────────────────────────────── */
.empty {
  padding: 32px 16px; text-align: center; color: var(--text-muted);
  background: var(--surface-raised); border: 1px solid var(--border); border-radius: var(--r-lg);
}
.empty p { margin: 0 0 12px; }

/* ── شريط عدم الاتصال ─────────────────────────────────────── */
#offline {
  position: fixed; inset-inline: 0; bottom: 0; z-index: 50;
  background: var(--warning-subtle); color: var(--warning);
  padding: 8px 16px; font-size: 13px; font-weight: 600; text-align: center;
  display: none;
}
body.is-offline #offline { display: block; }

/* ── الطباعة: عالم منفصل بقواعده ──────────────────────────── */
@media print {
  @page { size: A4; margin: 18mm; }
  header.app, nav.main, .sticky-bar, .no-print, #offline { display: none !important; }
  body { background: #fff; font-size: 10.5pt; line-height: 1.85; }
  main { max-width: none; padding: 0; }
  .card { box-shadow: none; border: none; }
  table { background: #fff; }
  thead th { background: var(--primary); color: #fff; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  tbody td { border-bottom: 1px solid var(--ledger-rule); }
  .report-header { display: flex; align-items: center; gap: 12px; border-bottom: 2px solid var(--primary); padding-bottom: 8px; }
  .report-footer { position: fixed; bottom: 0; inset-inline: 0; font-size: 9pt; color: var(--text-muted); }
  .page-break { break-after: page; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition-duration: .01ms !important; animation-duration: .01ms !important; }
}
