/* ============ الخط ============ */
@font-face { font-family: 'Plex'; font-weight: 400; font-display: swap; src: url(/vendor/fonts/ibm-plex-sans-arabic-arabic-400-normal.woff2) format('woff2'); unicode-range: U+0600-06FF, U+0750-077F, U+08A0-08FF, U+200C-200E, U+FB50-FDFF, U+FE70-FEFF; }
@font-face { font-family: 'Plex'; font-weight: 500; font-display: swap; src: url(/vendor/fonts/ibm-plex-sans-arabic-arabic-500-normal.woff2) format('woff2'); unicode-range: U+0600-06FF, U+0750-077F, U+08A0-08FF, U+200C-200E, U+FB50-FDFF, U+FE70-FEFF; }
@font-face { font-family: 'Plex'; font-weight: 600; font-display: swap; src: url(/vendor/fonts/ibm-plex-sans-arabic-arabic-600-normal.woff2) format('woff2'); unicode-range: U+0600-06FF, U+0750-077F, U+08A0-08FF, U+200C-200E, U+FB50-FDFF, U+FE70-FEFF; }
@font-face { font-family: 'Plex'; font-weight: 700; font-display: swap; src: url(/vendor/fonts/ibm-plex-sans-arabic-arabic-700-normal.woff2) format('woff2'); unicode-range: U+0600-06FF, U+0750-077F, U+08A0-08FF, U+200C-200E, U+FB50-FDFF, U+FE70-FEFF; }
@font-face { font-family: 'Plex'; font-weight: 400; font-display: swap; src: url(/vendor/fonts/ibm-plex-sans-arabic-latin-400-normal.woff2) format('woff2'); unicode-range: U+0000-00FF, U+2000-206F, U+20AC, U+2122, U+2212; }
@font-face { font-family: 'Plex'; font-weight: 600; font-display: swap; src: url(/vendor/fonts/ibm-plex-sans-arabic-latin-600-normal.woff2) format('woff2'); unicode-range: U+0000-00FF, U+2000-206F, U+20AC, U+2122, U+2212; }
@font-face { font-family: 'Plex'; font-weight: 700; font-display: swap; src: url(/vendor/fonts/ibm-plex-sans-arabic-latin-700-normal.woff2) format('woff2'); unicode-range: U+0000-00FF, U+2000-206F, U+20AC, U+2122, U+2212; }

/* ============ الهوية: أبيض، أسود، رصاصي ============ */
:root {
  --bg: #f2f2f3;
  --grid: rgba(17, 17, 19, .035);
  --surface: #ffffff;
  --surface-2: #f4f4f5;
  --surface-3: #e9e9ec;
  --ink: #111113;
  --ink-2: #3f3f46;
  --muted: #71717a;
  --faint: #a1a1aa;
  --line: #e7e7ea;
  --line-2: #d4d4d8;
  --accent: #111113;
  --on-accent: #ffffff;
  --nav-bg: #111113;
  --nav-ink: #9a9aa3;
  --nav-active-bg: #ffffff;
  --nav-active-ink: #111113;
  --danger: #b42318;
  --danger-bg: #fdecea;
  --warn: #9a5b06;
  --warn-bg: #fdf3e1;
  --ok: #1d7a46;
  --ok-bg: #e6f4ec;
  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .04), 0 10px 30px rgba(0, 0, 0, .07);
  --shadow-lg: 0 12px 40px rgba(0, 0, 0, .18);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}
/* الوضع الافتراضي فاتح. الداكن عند اختياره، أو "حسب الجهاز" إذا كان الهاتف داكناً */
@media (prefers-color-scheme: dark) {
  :root[data-theme="auto"] {
    --bg: #0c0c0d; --grid: rgba(255, 255, 255, .025); --surface: #17171a; --surface-2: #202024; --surface-3: #2a2a2f;
    --ink: #f4f4f5; --ink-2: #d4d4d8; --muted: #a1a1aa; --faint: #71717a; --line: #26262b; --line-2: #3a3a40;
    --accent: #f4f4f5; --on-accent: #111113; --nav-bg: #f4f4f5; --nav-ink: #6b6b73; --nav-active-bg: #111113; --nav-active-ink: #ffffff;
    --danger: #f28b82; --danger-bg: #3a1714; --warn: #f0b45a; --warn-bg: #36260b; --ok: #6fcf97; --ok-bg: #12301f;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 10px 30px rgba(0, 0, 0, .35);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0c0c0d; --grid: rgba(255, 255, 255, .025); --surface: #17171a; --surface-2: #202024; --surface-3: #2a2a2f;
  --ink: #f4f4f5; --ink-2: #d4d4d8; --muted: #a1a1aa; --faint: #71717a; --line: #26262b; --line-2: #3a3a40;
  --accent: #f4f4f5; --on-accent: #111113; --nav-bg: #f4f4f5; --nav-ink: #6b6b73; --nav-active-bg: #111113; --nav-active-ink: #ffffff;
  --danger: #f28b82; --danger-bg: #3a1714; --warn: #f0b45a; --warn-bg: #36260b; --ok: #6fcf97; --ok-bg: #12301f;
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100dvh; font-family: 'Plex', system-ui, 'Segoe UI', Tahoma, sans-serif; font-size: 15px; line-height: 1.6;
  color: var(--ink); background-color: var(--bg);
  /* ورق دفتر المدرسة */
  background-image: linear-gradient(var(--grid) 1px, transparent 1px), linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 22px 22px; background-attachment: fixed;
}
img { max-width: 100%; display: block; }
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
.ltr { direction: ltr; unicode-bidi: isolate; display: inline-block; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.xs { font-size: 12px; }
.bold { font-weight: 700; }
.center { text-align: center; }
.grow { flex: 1; min-width: 0; }
.row-flex { display: flex; align-items: center; gap: 10px; }
.wrap { flex-wrap: wrap; }
.between { justify-content: space-between; }
.stack > * + * { margin-top: 12px; }
.mt { margin-top: 16px; } .mt-s { margin-top: 8px; } .mb { margin-bottom: 16px; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pre { white-space: pre-wrap; word-break: break-word; }
.ico { width: 20px; height: 20px; flex: none; display: inline-block; vertical-align: middle; }
.flip { transform: scaleX(-1); }

/* ============ الشريط العلوي الطافي ============ */
.topbar {
  position: fixed; z-index: 30; top: calc(var(--safe-t) + 10px); inset-inline: 12px; margin: 0 auto; max-width: 760px;
  height: 62px; padding: 0 10px 0 8px; display: flex; align-items: center; gap: 10px;
  background: color-mix(in srgb, var(--surface) 88%, transparent); backdrop-filter: saturate(1.6) blur(16px); -webkit-backdrop-filter: saturate(1.6) blur(16px);
  border: 1px solid var(--line); border-radius: 20px; box-shadow: var(--shadow);
}
.tb-id { flex: 1; min-width: 0; display: flex; flex-direction: column; justify-content: center; padding-inline-start: 6px; background: none; border: 0; text-align: start; }
.tb-name { font-weight: 700; font-size: 16px; line-height: 1.3; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tb-role { font-size: 12.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tb-actions { display: flex; align-items: center; gap: 6px; }
.tb-avatar { border: 0; padding: 0; background: none; border-radius: 50%; }
/* علامة الاتصال بالخادم */
.net-pill { display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 11px; border-radius: 999px; font: inherit; font-size: 12px; font-weight: 600;
  background: var(--surface-2); color: var(--ink-2); border: 0; cursor: pointer; white-space: nowrap; }
.net-pill .ico { width: 15px; height: 15px; }
.net-pill b { min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--warn); color: #fff; font-size: 11px; line-height: 18px; text-align: center; }
.net-pill.off { background: var(--warn-bg); color: var(--warn); }
.net-pill.sync .ico { animation: spin 1.6s linear infinite; }
.led { width: 9px; height: 9px; border-radius: 50%; flex: none; background: var(--ok); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 22%, transparent); }
.net-pill.off .led, .net-state.off .led { background: var(--warn); box-shadow: 0 0 0 3px color-mix(in srgb, var(--warn) 22%, transparent); animation: blink 1.4s ease-in-out infinite; }
@keyframes blink { 50% { opacity: .35; } }
@media (max-width: 370px) { .net-pill.on span { display: none; } .net-pill.on { padding: 0 9px; } }
.net-state { display: flex; align-items: flex-start; gap: 12px; padding: 14px; border-radius: var(--radius); background: var(--ok-bg); }
.net-state.off { background: var(--warn-bg); }
.net-state .led { margin-top: 7px; width: 11px; height: 11px; }
.net-state .t { font-weight: 700; font-size: 15.5px; }
.net-state .d { font-size: 13px; color: var(--ink-2); margin-top: 2px; }
.ctx-banner { position: fixed; z-index: 29; top: calc(var(--safe-t) + 78px); inset-inline: 0; margin: 0 auto; width: max-content; max-width: calc(100% - 24px);
  background: var(--accent); color: var(--on-accent); border-radius: 999px; padding: 4px 6px 4px 14px; font-size: 12.5px; display: flex; align-items: center; gap: 8px; box-shadow: var(--shadow); }
.ctx-banner button { background: var(--on-accent); color: var(--accent); border: 0; border-radius: 999px; padding: 2px 10px; font-size: 12px; font-weight: 600; }

/* ============ الشريط السفلي الطافي ============ */
.bottombar {
  position: fixed; z-index: 30; bottom: calc(var(--safe-b) + 12px); inset-inline: 12px; margin: 0 auto; max-width: 520px;
  display: flex; gap: 2px; padding: 6px; border-radius: 26px; background: var(--nav-bg); box-shadow: var(--shadow-lg);
}
.nav-item {
  flex: 1; min-width: 0; position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  height: 56px; border: 0; border-radius: 20px; background: transparent; color: var(--nav-ink); text-decoration: none; font-size: 11.5px; font-weight: 600;
  transition: background .2s, color .2s;
}
.nav-item .ico { width: 22px; height: 22px; }
.nav-item.on { background: var(--nav-active-bg); color: var(--nav-active-ink); }
.nav-item .dot { position: absolute; top: 6px; inset-inline-end: calc(50% - 20px); min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--danger); color: #fff; font-size: 11px; line-height: 18px; text-align: center; border: 2px solid var(--nav-bg); box-sizing: content-box; }
.nav-item.on .dot { border-color: var(--nav-active-bg); }

/* ============ المحتوى ============ */
.view { max-width: 760px; margin: 0 auto; padding: calc(var(--safe-t) + 88px) 16px calc(var(--safe-b) + 112px); }
body.bare .view { padding-top: calc(var(--safe-t) + 24px); padding-bottom: 40px; }
body.has-ctx .view { padding-top: calc(var(--safe-t) + 116px); }
.splash { min-height: 70vh; display: grid; place-items: center; align-content: center; gap: 24px; }
.splash img { width: 84px; border-radius: 22px; }

.page-head { display: flex; align-items: center; gap: 10px; margin: 4px 0 16px; }
.page-head h1 { font-size: 23px; line-height: 1.3; margin: 0; font-weight: 700; }
.page-head .sub { color: var(--muted); font-size: 13.5px; margin-top: 2px; }
.page-head .grow > * { margin: 0; }
.back-btn { width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--line); background: var(--surface); display: grid; place-items: center; flex: none; }
h2.section { font-size: 15px; font-weight: 700; margin: 22px 4px 10px; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
h2.section a, h2.section button { font-size: 13px; font-weight: 600; color: var(--muted); text-decoration: none; background: none; border: 0; padding: 0; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.card + .card { margin-top: 12px; }
.card.flat { box-shadow: none; }
.card.dark { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }
.card.dark .muted { color: color-mix(in srgb, var(--on-accent) 65%, transparent); }

/* ============ الأزرار ============ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 44px; padding: 0 18px; border-radius: 14px;
  border: 1px solid transparent; background: var(--surface-2); color: var(--ink); font-weight: 600; font-size: 14.5px; text-decoration: none; white-space: nowrap;
  transition: transform .1s, opacity .2s, background .2s;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; pointer-events: none; }
.btn-primary { background: var(--accent); color: var(--on-accent); }
.btn-outline { background: transparent; border-color: var(--line-2); }
.btn-soft { background: var(--surface-2); }
.btn-ghost { background: transparent; }
.btn-danger { background: var(--danger-bg); color: var(--danger); }
.btn-sm { height: 34px; padding: 0 12px; font-size: 13px; border-radius: 10px; }
.btn-lg { height: 52px; font-size: 16px; border-radius: 16px; }
.btn-block { width: 100%; }
.btn .ico { width: 19px; height: 19px; }
.icon-btn { width: 40px; height: 40px; border-radius: 50%; border: 0; background: transparent; display: grid; place-items: center; position: relative; color: var(--ink); flex: none; }
.icon-btn:active { background: var(--surface-2); }
.icon-btn .dot { position: absolute; top: 5px; inset-inline-end: 5px; min-width: 16px; height: 16px; padding: 0 4px; border-radius: 8px; background: var(--danger); color: #fff; font-size: 10.5px; line-height: 16px; text-align: center; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.btn-row .btn { flex: 1; }
.link { background: none; border: 0; color: var(--ink-2); text-decoration: underline; text-underline-offset: 4px; padding: 6px; }
.spinner { width: 22px; height: 22px; border-radius: 50%; border: 2.5px solid currentColor; border-top-color: transparent; animation: spin .7s linear infinite; opacity: .6; }
.btn .spinner { width: 18px; height: 18px; }
@keyframes spin { to { transform: rotate(360deg); } }

.fab {
  position: fixed; z-index: 25; bottom: calc(var(--safe-b) + 92px); inset-inline-start: max(16px, calc(50% - 364px)); height: 54px; padding: 0 20px 0 22px; border-radius: 18px;
  background: var(--accent); color: var(--on-accent); border: 0; display: inline-flex; align-items: center; gap: 8px; font-weight: 700; box-shadow: var(--shadow-lg);
}
[dir="rtl"] .fab { inset-inline-start: auto; inset-inline-end: max(16px, calc(50% - 364px)); }

/* ============ الحقول ============ */
.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 13.5px; font-weight: 600; color: var(--ink-2); margin: 0 4px 6px; }
.field > small { display: block; color: var(--muted); font-size: 12px; margin: 6px 4px 0; }
.input, .field input, .field select, .field textarea {
  width: 100%; height: 48px; padding: 0 14px; border-radius: 14px; border: 1.5px solid transparent; background: var(--surface-2); color: var(--ink); font-size: 16px; outline: none;
  transition: border-color .15s, background .15s;
}
.field textarea { height: auto; min-height: 110px; padding: 12px 14px; resize: vertical; line-height: 1.7; }
.input:focus, .field input:focus, .field select:focus, .field textarea:focus { border-color: var(--ink); background: var(--surface); }
.field select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%2371717a' stroke-width='2'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: left 12px center; padding-left: 38px; }
.field input[type="date"] { direction: rtl; }
.input-icon { position: relative; }
.input-icon .ico { position: absolute; top: 50%; inset-inline-start: 14px; transform: translateY(-50%); color: var(--muted); }
.input-icon input { padding-inline-start: 42px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }

/* مجموعات الاختيار */
.seg { display: flex; padding: 4px; gap: 4px; border-radius: 14px; background: var(--surface-2); margin-bottom: 14px; overflow-x: auto; scrollbar-width: none; }
.seg::-webkit-scrollbar { display: none; }
.seg button { flex: 1; height: 38px; border: 0; border-radius: 10px; background: transparent; font-weight: 600; font-size: 14px; color: var(--muted); white-space: nowrap; padding: 0 12px; }
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(0, 0, 0, .1); }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 2px 6px; margin: 0 -2px 10px; scrollbar-width: none; }
.chips.wrap { flex-wrap: wrap; overflow: visible; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; height: 38px; padding: 0 14px; border-radius: 12px; border: 1.5px solid var(--line-2); background: var(--surface); font-weight: 600; font-size: 14px; display: inline-flex; align-items: center; gap: 6px; color: var(--ink-2); text-decoration: none; }
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.chip small { font-weight: 500; opacity: .7; font-size: 11.5px; }
.switch-row { display: flex; align-items: center; gap: 12px; padding: 12px 2px; border-bottom: 1px solid var(--line); cursor: pointer; }
.switch-row:last-child { border-bottom: 0; }
.switch-row .t { font-weight: 600; font-size: 14.5px; }
.switch-row .d { font-size: 12.5px; color: var(--muted); }
.switch { position: relative; width: 46px; height: 28px; flex: none; }
.switch input { opacity: 0; position: absolute; inset: 0; margin: 0; cursor: pointer; z-index: 1; }
.switch span { position: absolute; inset: 0; border-radius: 14px; background: var(--line-2); transition: background .2s; }
.switch span::after { content: ''; position: absolute; top: 3px; right: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; transition: transform .2s; box-shadow: 0 1px 3px rgba(0, 0, 0, .25); }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(-18px); }

/* ============ القوائم ============ */
.list { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.list-row { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border: 0; border-bottom: 1px solid var(--line); background: none; width: 100%; text-align: start; text-decoration: none; color: inherit; min-height: 64px; }
.list-row:last-child { border-bottom: 0; }
button.list-row:active, a.list-row:active { background: var(--surface-2); }
.list-row .t { font-weight: 600; font-size: 15px; line-height: 1.4; }
.list-row .d { font-size: 12.5px; color: var(--muted); line-height: 1.5; }
.list-row .chev { color: var(--faint); width: 18px; height: 18px; }
.list-row .meta { font-size: 12px; color: var(--muted); text-align: end; flex: none; }
.unread-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--danger); flex: none; }
.count { min-width: 22px; height: 22px; padding: 0 7px; border-radius: 11px; background: var(--accent); color: var(--on-accent); font-size: 12px; font-weight: 700; display: inline-grid; place-items: center; }

.avatar { flex: none; border-radius: 50%; background: var(--surface-3); color: var(--ink-2); display: grid; place-items: center; font-weight: 700; overflow: hidden; object-fit: cover; }
img.avatar { background: var(--surface-3); }

.tag { display: inline-flex; align-items: center; gap: 4px; height: 24px; padding: 0 9px; border-radius: 8px; font-size: 12px; font-weight: 600; background: var(--surface-2); color: var(--ink-2); white-space: nowrap; }
.tag.solid { background: var(--accent); color: var(--on-accent); }
.tag.outline { background: transparent; border: 1px solid var(--line-2); }
.tag.danger { background: var(--danger-bg); color: var(--danger); }
.tag.warn { background: var(--warn-bg); color: var(--warn); }
.tag.ok { background: var(--ok-bg); color: var(--ok); }
.tag .ico { width: 14px; height: 14px; }

.empty { text-align: center; padding: 40px 20px; color: var(--muted); }
.empty > .ico { width: 44px; height: 44px; margin: 0 auto 10px; display: block; opacity: .5; }
.empty .t { font-weight: 700; color: var(--ink-2); font-size: 16px; margin-bottom: 4px; }
.skeleton { border-radius: var(--radius); background: linear-gradient(90deg, var(--surface-2), var(--surface-3), var(--surface-2)); background-size: 200% 100%; animation: shimmer 1.2s infinite; height: 72px; margin-bottom: 10px; }
@keyframes shimmer { to { background-position: -200% 0; } }

.stale-note { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--warn); background: var(--warn-bg); border-radius: 12px; padding: 8px 12px; margin-bottom: 12px; }
.stale-note .ico { width: 16px; height: 16px; }
.banner { display: flex; align-items: center; gap: 12px; padding: 14px; border-radius: var(--radius); background: var(--surface); border: 1px dashed var(--line-2); margin-bottom: 12px; }
.banner .t { font-weight: 700; font-size: 14.5px; }
.banner .d { font-size: 12.5px; color: var(--muted); }
.banner .x { color: var(--faint); }

/* ============ البطاقات الإحصائية ============ */
.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
@media (min-width: 620px) { .tiles.four { grid-template-columns: repeat(4, 1fr); } }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; text-decoration: none; color: inherit; display: block; }
.tile .num { font-size: 28px; font-weight: 700; line-height: 1.2; font-variant-numeric: tabular-nums; }
.tile .num small { font-size: 14px; color: var(--muted); font-weight: 600; }
.tile .lbl { font-size: 13px; color: var(--muted); font-weight: 600; }
.tile .hint { font-size: 12px; color: var(--muted); margin-top: 4px; }
.tile.dark { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }
.tile.dark .lbl, .tile.dark .hint, .tile.dark .num small { color: color-mix(in srgb, var(--on-accent) 62%, transparent); }
.meter { height: 6px; border-radius: 3px; background: var(--surface-3); overflow: hidden; margin-top: 10px; }
.meter > i { display: block; height: 100%; border-radius: 3px; background: var(--ink); }
.tile.dark .meter { background: color-mix(in srgb, var(--on-accent) 20%, transparent); }
.tile.dark .meter > i { background: var(--on-accent); }

.actions-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.action { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 14px 4px 12px; border-radius: 16px; background: var(--surface); border: 1px solid var(--line); text-decoration: none; color: inherit; font-size: 12.5px; font-weight: 600; text-align: center; line-height: 1.3; }
.action .ic { width: 42px; height: 42px; border-radius: 14px; background: var(--surface-2); display: grid; place-items: center; }
.action.primary .ic { background: var(--accent); color: var(--on-accent); }

.hub { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
@media (min-width: 620px) { .hub { grid-template-columns: repeat(3, 1fr); } }
.hub a { display: flex; flex-direction: column; gap: 10px; padding: 16px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line); text-decoration: none; color: inherit; min-height: 118px; }
.hub a .ic { width: 44px; height: 44px; border-radius: 14px; background: var(--accent); color: var(--on-accent); display: grid; place-items: center; }
.hub a .t { font-weight: 700; font-size: 15px; }
.hub a .d { font-size: 12px; color: var(--muted); line-height: 1.5; }

/* ============ الرسم البياني ============ */
.chart { position: relative; }
.chart svg { width: 100%; height: auto; max-height: 240px; display: block; overflow: visible; }
.chart .bar { fill: var(--ink); }
.chart .bar.none { fill: var(--surface-3); }
.chart .hit { fill: transparent; cursor: pointer; }
.chart .hit:hover + .bar, .chart .bar.hover { opacity: .75; }
.chart .grid-l { stroke: var(--line); stroke-width: 1; }
.chart .axis-t { fill: var(--muted); font-size: 11px; font-family: inherit; }
.chart .val-t { fill: var(--ink-2); font-size: 11px; font-weight: 700; font-family: inherit; }
.chart-tip { position: absolute; pointer-events: none; background: var(--accent); color: var(--on-accent); font-size: 12px; padding: 6px 10px; border-radius: 10px; white-space: nowrap; transform: translate(50%, -110%); box-shadow: var(--shadow); }

/* ============ التبليغات ============ */
.notice { display: block; text-decoration: none; color: inherit; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 10px; position: relative; }
.notice.unread { border-color: var(--ink); box-shadow: inset -4px 0 0 var(--ink); }
.notice .top { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-bottom: 6px; }
.notice h3 { font-size: 16px; margin: 0 0 4px; line-height: 1.5; }
.notice p { margin: 0; color: var(--ink-2); font-size: 14px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.notice .foot { display: flex; align-items: center; gap: 8px; margin-top: 10px; font-size: 12.5px; color: var(--muted); }
.read-meter { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); }
.read-meter .meter { flex: 1; margin: 0; height: 5px; }
.att-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 12px; }
.att-grid a, .att-grid .thumb { aspect-ratio: 1; border-radius: 12px; overflow: hidden; background: var(--surface-2); display: block; position: relative; }
.att-grid img { width: 100%; height: 100%; object-fit: cover; }
.att-grid .rm { position: absolute; top: 4px; left: 4px; width: 26px; height: 26px; border-radius: 50%; border: 0; background: rgba(0, 0, 0, .65); color: #fff; display: grid; place-items: center; }
.att-grid .rm .ico { width: 14px; height: 14px; }
.file-chip { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 12px; background: var(--surface-2); text-decoration: none; color: inherit; font-size: 13.5px; font-weight: 600; margin-top: 8px; }
.body-text { font-size: 15.5px; line-height: 1.9; white-space: pre-wrap; word-break: break-word; }
.body-text a { color: var(--ink); text-decoration: underline; }

/* ============ الغياب ============ */
.att-summary { position: sticky; top: calc(var(--safe-t) + 80px); z-index: 5; display: flex; gap: 8px; align-items: center; padding: 10px 12px; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; margin-bottom: 10px; box-shadow: var(--shadow); }
.att-summary b { font-size: 18px; }
.att-summary .s { display: flex; flex-direction: column; align-items: center; flex: 1; font-size: 11.5px; color: var(--muted); line-height: 1.3; }
.att-row { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 16px; background: var(--surface); border: 1.5px solid var(--line); margin-bottom: 8px; width: 100%; text-align: start; transition: background .15s, border-color .15s; user-select: none; }
.att-row .num { width: 26px; text-align: center; color: var(--faint); font-size: 13px; font-weight: 600; flex: none; }
.att-row .name { flex: 1; font-weight: 600; font-size: 15px; }
.att-state { height: 32px; min-width: 70px; padding: 0 12px; border-radius: 10px; display: grid; place-items: center; font-size: 13px; font-weight: 700; background: var(--ok-bg); color: var(--ok); }
.att-row.absent { border-color: var(--danger); background: var(--danger-bg); }
.att-row.absent .att-state { background: var(--danger); color: #fff; }
.att-row.late { border-color: var(--warn); background: var(--warn-bg); }
.att-row.late .att-state { background: var(--warn); color: #fff; }
.sticky-save { position: sticky; bottom: calc(var(--safe-b) + 92px); z-index: 6; margin-top: 14px; }
.sticky-save .btn { box-shadow: var(--shadow-lg); }

/* ============ الجدول ============ */
.periods .p { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-bottom: 1px solid var(--line); min-height: 64px; width: 100%; background: none; border-inline: 0; border-top: 0; text-align: start; }
.periods .p:last-child { border-bottom: 0; }
.periods .n { width: 38px; height: 38px; border-radius: 12px; background: var(--surface-2); display: grid; place-items: center; font-weight: 700; flex: none; }
.periods .p.now .n { background: var(--accent); color: var(--on-accent); }
.periods .p .t { font-weight: 600; }
.periods .p .d { font-size: 12.5px; color: var(--muted); }
.periods .p.empty-p .t { color: var(--faint); font-weight: 500; }

/* ============ الرسائل ============ */
body.chat-mode .bottombar { display: none; }
body.chat-mode .view { padding-bottom: calc(var(--safe-b) + 90px); }
.thread-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.msgs { display: flex; flex-direction: column; gap: 6px; }
.day-sep { align-self: center; font-size: 12px; color: var(--muted); background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 2px 12px; margin: 10px 0 4px; }
.bubble { max-width: 82%; padding: 9px 13px 6px; border-radius: 18px; background: var(--surface); border: 1px solid var(--line); align-self: flex-start; font-size: 15px; line-height: 1.7; word-break: break-word; }
.bubble .txt { white-space: pre-wrap; }
.bubble.mine { align-self: flex-end; background: var(--accent); color: var(--on-accent); border-color: var(--accent); border-bottom-left-radius: 6px; }
.bubble:not(.mine) { border-bottom-right-radius: 6px; }
.bubble.mine a { color: inherit; }
.bubble .time { font-size: 11px; opacity: .6; display: flex; align-items: center; gap: 4px; justify-content: flex-end; margin-top: 2px; }
.bubble .time .ico { width: 13px; height: 13px; }
.bubble img { border-radius: 12px; margin: 2px 0 4px; max-height: 280px; }
.bubble.pending { opacity: .7; }
.composer { position: fixed; z-index: 30; bottom: calc(var(--safe-b) + 10px); inset-inline: 12px; margin: 0 auto; max-width: 760px; display: flex; align-items: flex-end; gap: 6px; padding: 6px; border-radius: 24px; background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow-lg); }
.composer textarea { flex: 1; border: 0; outline: 0; background: transparent; resize: none; max-height: 140px; min-height: 44px; padding: 10px 8px; font-size: 16px; line-height: 1.5; }
.composer .send { width: 44px; height: 44px; border-radius: 50%; background: var(--accent); color: var(--on-accent); border: 0; display: grid; place-items: center; flex: none; }

/* ============ النوافذ المنبثقة ============ */
.sheet-wrap { position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.sheet-wrap .backdrop { position: absolute; inset: 0; background: rgba(10, 10, 12, .45); opacity: 0; transition: opacity .22s; }
.sheet { position: relative; width: 100%; max-width: 560px; max-height: 92dvh; display: flex; flex-direction: column; background: var(--surface); border-radius: 26px 26px 0 0; transform: translateY(100%); transition: transform .26s cubic-bezier(.2, .8, .2, 1); padding-bottom: var(--safe-b); }
.sheet-wrap.open .backdrop { opacity: 1; }
.sheet-wrap.open .sheet { transform: none; }
@media (min-width: 620px) {
  .sheet-wrap { align-items: center; }
  .sheet { border-radius: 26px; transform: translateY(30px) scale(.98); opacity: 0; transition: transform .2s, opacity .2s; }
  .sheet-wrap.open .sheet { opacity: 1; }
}
.sheet-grip { width: 40px; height: 5px; border-radius: 3px; background: var(--line-2); margin: 8px auto 0; flex: none; }
.sheet-head { display: flex; align-items: center; gap: 8px; padding: 8px 14px 6px 10px; flex: none; }
.sheet-head h3 { flex: 1; margin: 0; font-size: 18px; padding-inline-start: 6px; }
.sheet-body { flex: 1; min-height: 0; padding: 8px 18px 20px; overflow-y: auto; overscroll-behavior: contain; }
.sheet-foot { position: sticky; bottom: -20px; background: var(--surface); padding: 12px 0 4px; margin-top: 6px; }
.cred { text-align: center; padding: 8px 0; }
.cred .big { font-size: 30px; font-weight: 700; letter-spacing: 3px; direction: ltr; margin: 6px 0; }
.pw-row { display: flex; gap: 8px; align-items: stretch; }
.pw-row input { flex: 1; min-width: 0; letter-spacing: 1px; }
.pw-row .btn { flex: none; }
.acc-note { font-size: 13px; color: var(--muted); background: var(--surface-2); border-radius: 12px; padding: 10px 12px; margin: 0 0 14px; }

/* ============ الإشعارات المؤقتة ============ */
.toasts { position: fixed; z-index: 80; top: calc(var(--safe-t) + 12px); inset-inline: 0; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; padding: 0 16px; }
.toast { pointer-events: auto; max-width: 480px; background: var(--accent); color: var(--on-accent); padding: 12px 18px; border-radius: 16px; font-size: 14px; font-weight: 600; box-shadow: var(--shadow-lg); display: flex; align-items: center; gap: 10px; animation: toastIn .25s ease-out; }
.toast.error { background: var(--danger); color: #fff; }
.toast .ico { width: 18px; height: 18px; }
.toast button { background: var(--on-accent); color: var(--accent); border: 0; border-radius: 10px; padding: 4px 12px; font-weight: 700; }
@keyframes toastIn { from { opacity: 0; transform: translateY(-10px); } }

/* ============ الدخول ============ */
.auth { max-width: 420px; margin: 0 auto; min-height: calc(100dvh - 64px); display: flex; flex-direction: column; justify-content: center; }
.auth-brand { text-align: center; margin-bottom: 22px; }
.auth-brand img { width: 84px; height: 84px; margin: 0 auto 14px; border-radius: 24px; box-shadow: var(--shadow-lg); }
.auth-brand h1 { margin: 0; font-size: clamp(22px, 6.5vw, 30px); line-height: 1.4; letter-spacing: -.3px; }
.auth-brand p { margin: 4px 0 0; color: var(--muted); }
.auth-card { padding: 22px 20px; box-shadow: var(--shadow); }
.auth-foot { text-align: center; color: var(--muted); font-size: 13px; margin: 16px 10px 4px; }
.or { display: flex; align-items: center; gap: 12px; color: var(--faint); font-size: 13px; margin: 14px 0; }
.or::before, .or::after { content: ''; flex: 1; height: 1px; background: var(--line); }

/* الماسح */
.scanner { position: relative; border-radius: 20px; overflow: hidden; background: #000; aspect-ratio: 1; }
.scanner video { width: 100%; height: 100%; object-fit: cover; }
.scanner .frame { position: absolute; inset: 18%; border: 3px solid rgba(255, 255, 255, .9); border-radius: 22px; box-shadow: 0 0 0 999px rgba(0, 0, 0, .35); }
.scanner .msg { position: absolute; bottom: 12px; inset-inline: 0; text-align: center; color: #fff; font-size: 13px; }

/* ============ الطفل (ولي الأمر) ============ */
.kid-hero { display: flex; align-items: center; gap: 16px; }
.kid-photo { position: relative; flex: none; border: 0; padding: 0; background: none; border-radius: 50%; }
.kid-photo .cam { position: absolute; bottom: 0; left: 0; width: 30px; height: 30px; border-radius: 50%; background: var(--on-accent); color: var(--accent); display: grid; place-items: center; border: 2px solid var(--accent); }
.kid-photo .cam .ico { width: 16px; height: 16px; }
.kid-hero h2 { margin: 0; font-size: 21px; line-height: 1.3; }

/* ============ الطباعة ============ */
.print-sheet { display: grid; grid-template-columns: 1fr; gap: 0; background: #fff; color: #111; border-radius: 12px; overflow: hidden; }
@media (min-width: 620px) { .print-sheet { grid-template-columns: repeat(2, 1fr); } }
@media print { .print-sheet { grid-template-columns: repeat(2, 1fr); border-radius: 0; } }
.slip { border: 1px dashed #9a9aa3; padding: 12px 14px; display: flex; flex-direction: column; gap: 6px; break-inside: avoid; height: 66mm; overflow: hidden; font-size: 12px; }
.slip .s-head { display: flex; align-items: center; gap: 8px; border-bottom: 1px solid #ddd; padding-bottom: 6px; }
.slip .s-head img { width: 24px; height: 24px; border-radius: 7px; }
.slip .s-head b { font-size: 12.5px; flex: 1; }
.slip .s-head span { font-size: 10px; color: #666; }
.slip .s-body { display: flex; gap: 12px; align-items: center; flex: 1; }
.slip .qr { width: 30mm; height: 30mm; flex: none; }
.slip .qr svg { width: 100%; height: 100%; }
.slip .nm { font-size: 15px; font-weight: 700; line-height: 1.35; }
.slip .kv { display: flex; justify-content: space-between; gap: 8px; border-bottom: 1px dotted #ccc; padding: 2px 0; }
.slip .kv b { direction: ltr; font-size: 14px; letter-spacing: .5px; }
.slip .s-foot { font-size: 10px; color: #555; text-align: center; }
.poster { background: #fff; color: #111; text-align: center; padding: 40px 20px; border-radius: 24px; border: 1px solid var(--line); }
.poster h2 { font-size: 30px; margin: 0 0 6px; }
.poster .qr { width: 300px; height: 300px; margin: 24px auto; }
.poster .qr svg { width: 100%; height: 100%; }
.poster .url { direction: ltr; font-size: 20px; font-weight: 700; }
.poster img.logo { width: 80px; height: 80px; border-radius: 22px; margin: 0 auto 12px; }

@media print {
  @page { size: A4; margin: 10mm; }
  body { background: #fff !important; }
  .topbar, .bottombar, .no-print, .toasts, .ctx-banner, .fab { display: none !important; }
  .view { padding: 0 !important; max-width: none; }
  .poster { border: 0; }
}

/* ============ واجهة ولي الأمر المبسطة ============ */
.p-hello .kid-photo { flex: none; }
.p-hello .kid-photo .cam { width: 24px; height: 24px; }
.p-hello .kid-photo .cam .ico { width: 13px; height: 13px; }
.p-name { font-size: 19px; font-weight: 700; line-height: 1.4; }
.today-status { display: flex; align-items: center; gap: 10px; margin-top: 14px; padding: 12px 14px; border-radius: 14px; background: var(--surface-2);
  color: var(--ink); text-decoration: none; font-weight: 700; font-size: 15px; }
.today-status small { font-size: 12px; font-weight: 600; color: var(--muted); }
.today-status.good { background: var(--ok-bg); color: var(--ok); }
.today-status.bad { background: var(--danger-bg); color: var(--danger); }
.today-status.warn { background: var(--warn-bg); color: var(--warn); }
.periods .p .tag { flex: none; text-decoration: none; }
.office-row { min-height: 72px; }
.office-row .t { font-weight: 700; }
.chip .avatar { margin-inline-start: -6px; }

/* ---------- محرر الصورة: تحريك وتكبير وقصّ ---------- */
.crop-wrap { display: flex; justify-content: center; }
.crop-stage { position: relative; overflow: hidden; border-radius: 16px; background: #0b0b0c; touch-action: none; direction: ltr; cursor: grab; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; width: 100%; height: 300px; }
.crop-stage.dragging { cursor: grabbing; }
.crop-stage canvas { position: absolute; left: 0; top: 0; transform-origin: 0 0; max-width: none; pointer-events: none; }
/* الإطار ثابت، وما خارجه من الصورة باهت */
.crop-frame { position: absolute; z-index: 1; pointer-events: none; border-radius: 6px; box-shadow: 0 0 0 999px rgba(0, 0, 0, .58), inset 0 0 0 2px rgba(255, 255, 255, .92); }
.crop-frame.round { border-radius: 50%; }
.crop-hint { text-align: center; font-size: 13px; color: var(--muted); margin: 10px 0 6px; }
.crop-tools { display: flex; align-items: center; gap: 6px; max-width: 380px; margin: 0 auto; direction: ltr; }
.crop-tools input[type=range] { flex: 1; min-width: 0; accent-color: var(--accent); }
.crop-ratios { justify-content: center; margin-top: 10px; }
