/* ============================================================
   منصة ثانوية البنوك التعليمية — الأنماط الرئيسية
   Phone-first, RTL Arabic. Light + dark via [data-theme].
   Role colours via body.role-admin / role-teacher / role-student / role-parent.
   No external dependencies.
   ============================================================ */

* { box-sizing: border-box; }

:root {
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 2px 10px rgba(15, 23, 42, .10);
  --shadow-lg: 0 8px 28px rgba(15, 23, 42, .16);
  --topbar-h: 60px;
  --maxw: 1080px;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --ok: #15803d;
  --ok-soft: #dcfce7;
  --warn: #b45309;
  --warn-soft: #fef3c7;
}

/* ---------- Light theme (default) ---------- */
html[data-theme="light"] {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --surface-3: #eef2ff;
  --text: #0f172a;
  --muted: #64748b;
  --border: #dbe3ee;
  --input-bg: #ffffff;
  --accent-contrast: #ffffff;
}

/* ---------- Dark theme ---------- */
html[data-theme="dark"] {
  --bg: #0b1220;
  --surface: #111c30;
  --surface-2: #16233c;
  --surface-3: #1b2a47;
  --text: #eef2f8;
  --muted: #9fb0c7;
  --border: #26374f;
  --input-bg: #0e1828;
  --accent-contrast: #ffffff;
  --shadow: 0 2px 10px rgba(0, 0, 0, .45);
  --shadow-lg: 0 8px 28px rgba(0, 0, 0, .55);
  --danger-soft: #4c1212;
  --ok-soft: #12351d;
  --warn-soft: #4a2f06;
}

/* ---------- Role accent colours (contract §6) ---------- */
body.role-admin, body.role-unlinked, body:not([class*="role-"]) {
  --accent: #1e40af; --accent-dark: #1e3a8a; --accent-soft: #dbeafe;
}
body.role-teacher { --accent: #059669; --accent-dark: #047857; --accent-soft: #d1fae5; }
body.role-student { --accent: #d97706; --accent-dark: #b45309; --accent-soft: #fef3c7; }
body.role-parent  { --accent: #7c3aed; --accent-dark: #6d28d9; --accent-soft: #ede9fe; }
html[data-theme="dark"] body.role-admin,
html[data-theme="dark"] body.role-unlinked { --accent-soft: #1e2a52; }
html[data-theme="dark"] body.role-teacher { --accent-soft: #123b2c; }
html[data-theme="dark"] body.role-student { --accent-soft: #45300c; }
html[data-theme="dark"] body.role-parent  { --accent-soft: #2c1d56; }

html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: "Segoe UI", Tahoma, "Noto Kufi Arabic", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.7;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
img { max-width: 100%; }
a { color: var(--accent); }
h1, h2, h3 { line-height: 1.35; margin: .2em 0 .5em; }
h1 { font-size: 1.45rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.05rem; }
p { margin: .4em 0 .8em; }
small, .muted { color: var(--muted); }
strong { font-weight: 700; }

.skip-link {
  position: absolute; inset-inline-start: 8px; top: -48px; z-index: 200;
  background: var(--accent); color: #fff; padding: 8px 14px; border-radius: 8px;
}
.skip-link:focus { top: 8px; }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 90;
  height: var(--topbar-h);
  display: flex; align-items: center; gap: 8px;
  padding: 0 10px;
  background: linear-gradient(135deg, var(--accent), var(--accent-dark));
  color: #fff; box-shadow: var(--shadow);
}
.brand { display: flex; align-items: center; gap: 10px; color: #fff; text-decoration: none; min-width: 0; flex: 1; }
.brand-logo {
  background: #fff; border-radius: 50%; width: 44px; height: 44px; flex: none;
  display: flex; align-items: center; justify-content: center; overflow: hidden;
  box-shadow: 0 1px 6px rgba(0,0,0,.25);
}
.brand-logo img { width: 40px; height: 40px; object-fit: contain; }
.brand-text { display: flex; flex-direction: column; min-width: 0; }
.brand-text strong { font-size: .98rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-text small { color: #e0e7ff; font-size: .74rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-actions { display: flex; align-items: center; gap: 4px; }
.icon-btn {
  position: relative; width: 44px; height: 44px; flex: none;
  display: inline-flex; align-items: center; justify-content: center;
  background: rgba(255,255,255,.14); color: #fff; border: 0; border-radius: 12px;
  font-size: 1.25rem; cursor: pointer; text-decoration: none;
}
.icon-btn:hover, .icon-btn:focus-visible { background: rgba(255,255,255,.28); outline: 2px solid #fff; outline-offset: 1px; }
.badge {
  position: absolute; top: 2px; inset-inline-start: 2px;
  min-width: 20px; height: 20px; padding: 0 5px; border-radius: 999px;
  background: var(--danger); color: #fff; font-size: .72rem; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center;
  border: 2px solid #fff;
}
.badge-inline { position: static; border: 0; }
.badge-accent { background: var(--accent); }

/* Hide header actions before sign-in (auth views) */
body.auth-view #drawer-btn, body.auth-view #bell-link { display: none; }

/* ---------- Drawer ---------- */
.drawer-scrim {
  position: fixed; inset: 0; z-index: 95; background: rgba(2, 6, 23, .5);
}
.drawer {
  position: fixed; top: 0; bottom: 0; inset-inline-start: 0; z-index: 100;
  width: min(320px, 86vw); background: var(--surface); color: var(--text);
  box-shadow: var(--shadow-lg); display: flex; flex-direction: column;
  transform: translateX(105%); transition: transform .22s ease;
}
html[dir="rtl"] .drawer { transform: translateX(-105%); }
.drawer.open { transform: translateX(0); }
.drawer-header {
  display: flex; align-items: center; gap: 12px; padding: 16px 14px;
  background: linear-gradient(135deg, var(--accent), var(--accent-dark)); color: #fff;
}
.drawer-logo { background: #fff; border-radius: 50%; width: 52px; height: 52px; flex: none; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.drawer-logo img { width: 48px; height: 48px; object-fit: contain; }
.drawer-profile { min-width: 0; display: flex; flex-direction: column; }
.drawer-profile strong { font-size: 1rem; overflow: hidden; text-overflow: ellipsis; }
.drawer-profile small { color: #e0e7ff; }
.drawer-profile .avatar {
  width: 52px; height: 52px; border-radius: 50%; object-fit: cover; border: 2px solid #fff;
}
.drawer-nav { flex: 1; overflow-y: auto; padding: 10px; display: flex; flex-direction: column; gap: 2px; }
.drawer-nav a {
  display: flex; align-items: center; gap: 10px; padding: 11px 12px; border-radius: 10px;
  color: var(--text); text-decoration: none; font-weight: 600; min-height: 48px;
}
.drawer-nav a:hover { background: var(--surface-2); }
.drawer-nav a.active { background: var(--accent-soft); color: var(--accent-dark); }
html[data-theme="dark"] .drawer-nav a.active { color: #fff; }
.drawer-nav a .nav-icon { font-size: 1.2rem; width: 26px; text-align: center; flex: none; }
.drawer-nav a .nav-label { flex: 1; }
.drawer-nav .nav-section {
  margin: 12px 6px 4px; font-size: .78rem; font-weight: 700; color: var(--muted); letter-spacing: .02em;
}
.drawer-footer { padding: 12px; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 8px; }

/* ---------- Layout / cards ---------- */
.app { flex: 1; width: 100%; max-width: var(--maxw); margin: 0 auto; padding: 16px 12px 28px; }
.page-head { margin-bottom: 14px; }
.page-head p { color: var(--muted); margin-top: 0; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px; margin-bottom: 14px;
}
.card-flat { box-shadow: none; }
.grid { display: grid; gap: 12px; }
.grid-2 { grid-template-columns: 1fr; }
@media (min-width: 640px) { .grid-2 { grid-template-columns: 1fr 1fr; } }
.grid-3 { grid-template-columns: 1fr; }
@media (min-width: 640px) { .grid-3 { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 900px) { .grid-3 { grid-template-columns: repeat(3, 1fr); } }

.footer {
  text-align: center; padding: 18px 12px 26px; color: var(--muted); font-size: .85rem;
  border-top: 1px solid var(--border); background: var(--surface);
}
.footer .credit { font-weight: 700; color: var(--text); margin-bottom: 2px; }
.footer-links a { color: var(--muted); text-decoration: none; }
.footer-links a:hover { color: var(--accent); text-decoration: underline; }

/* ---------- Buttons / forms ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 10px 18px; border-radius: 12px; border: 1px solid transparent;
  font: inherit; font-weight: 700; font-size: .98rem; cursor: pointer; text-decoration: none;
  transition: filter .15s ease, background .15s ease;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: var(--accent-contrast); }
.btn-primary:hover:not(:disabled) { filter: brightness(1.12); }
.btn-secondary { background: var(--surface-3); color: var(--text); border-color: var(--border); }
.btn-ghost { background: transparent; color: var(--accent); border-color: var(--border); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-ok { background: var(--ok); color: #fff; }
.btn-sm { min-height: 40px; padding: 6px 12px; font-size: .88rem; border-radius: 10px; }
.btn-block { width: 100%; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.btn-google {
  background: #fff; color: #1f2937; border: 1px solid #d1d5db; box-shadow: var(--shadow);
  font-size: 1.05rem; width: 100%;
}
.btn-google:hover { background: #f9fafb; }
html[data-theme="dark"] .btn-google { background: #fff; color: #1f2937; }

label { display: block; font-weight: 700; margin: 10px 0 4px; font-size: .95rem; }
input, select, textarea {
  width: 100%; min-height: 48px; padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--input-bg); color: var(--text);
  font: inherit; font-size: 1rem;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: var(--accent); }
textarea { min-height: 110px; resize: vertical; }
input[type="checkbox"], input[type="radio"] { width: 20px; height: 20px; min-height: 0; accent-color: var(--accent); }
.check-row { display: flex; align-items: center; gap: 10px; min-height: 48px; font-weight: 600; cursor: pointer; }
.check-row input { flex: none; }
.field-hint { font-size: .85rem; color: var(--muted); margin-top: 2px; }
.field-error { font-size: .88rem; color: var(--danger); font-weight: 600; margin-top: 4px; }
.form-grid { display: grid; gap: 0 14px; grid-template-columns: 1fr; }
@media (min-width: 640px) { .form-grid.cols-2 { grid-template-columns: 1fr 1fr; } .form-grid.cols-3 { grid-template-columns: repeat(3, 1fr); } }
.code-input {
  font-size: 1.5rem; font-weight: 800; letter-spacing: .35em; text-align: center;
  font-variant-numeric: tabular-nums; direction: ltr;
}

/* ---------- Alerts / states ---------- */
.alert { border-radius: 12px; padding: 12px 14px; margin-bottom: 14px; border: 1px solid var(--border); background: var(--surface-2); }
.alert-info { background: var(--accent-soft); border-color: var(--accent); }
.alert-success { background: var(--ok-soft); border-color: var(--ok); }
.alert-warning { background: var(--warn-soft); border-color: var(--warn); }
.alert-error { background: var(--danger-soft); border-color: var(--danger); }
.alert strong { display: block; margin-bottom: 2px; }
.loading { text-align: center; padding: 48px 12px; color: var(--muted); }
.spinner {
  width: 40px; height: 40px; margin: 0 auto 12px; border-radius: 50%;
  border: 4px solid var(--border); border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.empty { text-align: center; padding: 34px 14px; color: var(--muted); }
.empty .empty-icon { font-size: 2.6rem; display: block; margin-bottom: 8px; }
.empty strong { color: var(--text); display: block; font-size: 1.05rem; margin-bottom: 4px; }

/* ---------- Toasts / modal ---------- */
.toast-root { position: fixed; bottom: 18px; inset-inline: 12px; z-index: 300; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast {
  background: #0f172a; color: #fff; padding: 12px 18px; border-radius: 12px; box-shadow: var(--shadow-lg);
  font-weight: 600; max-width: min(480px, 92vw); text-align: center; pointer-events: auto;
}
.toast-error { background: var(--danger); }
.toast-success { background: var(--ok); }
.modal-scrim { position: fixed; inset: 0; z-index: 250; background: rgba(2,6,23,.55); display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal { background: var(--surface); color: var(--text); border-radius: var(--radius); box-shadow: var(--shadow-lg); width: min(520px, 94vw); max-height: 88vh; overflow-y: auto; padding: 20px; }
.modal h2 { margin-top: 0; }

/* ---------- Auth / login / link ---------- */
.auth-wrap { max-width: 480px; margin: 18px auto; }
.auth-card { text-align: center; padding: 28px 20px; }
.auth-logo { background: #fff; border-radius: 24px; display: inline-flex; padding: 10px; box-shadow: var(--shadow); margin-bottom: 12px; }
.auth-logo img { width: 120px; height: 120px; object-fit: contain; }
.auth-card h1 { font-size: 1.5rem; margin-bottom: 2px; }
.auth-directorate { color: var(--warn); font-weight: 700; }
.auth-divider { display: flex; align-items: center; gap: 10px; color: var(--muted); margin: 18px 0 6px; font-size: .85rem; }
.auth-divider::before, .auth-divider::after { content: ""; flex: 1; border-top: 1px solid var(--border); }
.link-choice { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 10px 0; }
.choice-card {
  border: 2px solid var(--border); border-radius: var(--radius); padding: 16px 8px; cursor: pointer;
  background: var(--surface-2); text-align: center; font-weight: 700;
}
.choice-card .choice-icon { font-size: 1.8rem; display: block; margin-bottom: 6px; }
.choice-card.selected { border-color: var(--accent); background: var(--accent-soft); }
.qr-box { border: 2px dashed var(--border); border-radius: var(--radius); padding: 12px; text-align: center; }
.qr-box video { width: 100%; max-height: 300px; border-radius: 10px; background: #000; }
.qr-box video[hidden] { display: none; }

/* ---------- Home ---------- */
.profile-head { display: flex; align-items: center; gap: 14px; }
.profile-head .avatar, .profile-head .avatar-fallback {
  width: 64px; height: 64px; border-radius: 50%; flex: none; object-fit: cover;
  background: var(--accent-soft); color: var(--accent-dark); display: flex; align-items: center; justify-content: center;
  font-size: 1.6rem; font-weight: 800; border: 2px solid var(--accent);
}
.wisdom-card { background: linear-gradient(135deg, var(--accent-soft), var(--surface)); border-inline-start: 5px solid var(--accent); }
.wisdom-card blockquote { margin: 6px 0 0; font-size: 1.12rem; font-weight: 600; }
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (min-width: 720px) { .tiles { grid-template-columns: repeat(4, 1fr); } }
.tile {
  position: relative; display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 22px 10px 18px; border-radius: var(--radius); text-decoration: none; color: #fff;
  background: linear-gradient(150deg, var(--accent), var(--accent-dark)); box-shadow: var(--shadow);
  font-weight: 700; text-align: center; min-height: 120px; justify-content: center;
}
.tile .tile-icon { font-size: 2rem; }
.tile .badge { top: 8px; inset-inline-start: 8px; }
.tile.tile-alt { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
.tile.tile-alt .tile-icon { color: var(--accent); }
.alert-card { border-inline-start: 5px solid var(--warn); cursor: pointer; }
.alert-card:hover { filter: brightness(1.03); }
.new-tag {
  display: inline-block; background: var(--danger); color: #fff; font-size: .72rem; font-weight: 800;
  padding: 2px 8px; border-radius: 999px; margin-inline-start: 6px; vertical-align: middle;
}

/* ---------- Lists: notices / news / library / messages ---------- */
.list-item {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; margin-bottom: 10px; box-shadow: var(--shadow);
}
.list-item.unread { border-inline-start: 5px solid var(--accent); background: var(--surface-3); }
.list-item .item-meta { color: var(--muted); font-size: .83rem; display: flex; flex-wrap: wrap; gap: 4px 12px; }
.list-item .item-title { font-weight: 800; font-size: 1.05rem; }
.list-item .item-body { white-space: pre-wrap; word-break: break-word; }
.item-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.tabs { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.tab {
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  min-height: 44px; padding: 8px 16px; border-radius: 999px; font: inherit; font-weight: 700; cursor: pointer;
}
.tab.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.pill { display: inline-block; padding: 2px 10px; border-radius: 999px; background: var(--surface-3); border: 1px solid var(--border); font-size: .8rem; font-weight: 700; }
.pill-danger { background: var(--danger-soft); border-color: var(--danger); color: var(--danger); }
.pill-ok { background: var(--ok-soft); border-color: var(--ok); color: var(--ok); }
.pill-warn { background: var(--warn-soft); border-color: var(--warn); color: var(--warn); }
.file-chip { display: inline-flex; align-items: center; gap: 6px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; padding: 6px 12px; text-decoration: none; color: var(--text); font-weight: 600; font-size: .88rem; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
table { width: 100%; border-collapse: collapse; min-width: 560px; }
th, td { padding: 10px 12px; text-align: right; border-bottom: 1px solid var(--border); }
th { background: var(--surface-2); font-size: .9rem; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
td input, td select { min-height: 42px; padding: 6px 8px; }
.grade-num { font-variant-numeric: tabular-nums; font-weight: 700; }

/* ---------- Schedule grid ---------- */
.sched-grid { display: grid; gap: 10px; }
.sched-day { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); overflow: hidden; }
.sched-day h3 { margin: 0; padding: 10px 14px; background: var(--accent-soft); color: var(--accent-dark); }
html[data-theme="dark"] .sched-day h3 { color: #fff; }
.sched-period { display: flex; gap: 10px; padding: 9px 14px; border-top: 1px solid var(--border); align-items: baseline; }
.sched-period .p-num { font-weight: 800; color: var(--accent); flex: none; width: 74px; }
@media (min-width: 720px) { .sched-grid { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 1020px) { .sched-grid { grid-template-columns: repeat(3, 1fr); } }

/* ---------- Messages ---------- */
.thread-list a { text-decoration: none; color: var(--text); display: block; }
.chat { display: flex; flex-direction: column; gap: 10px; }
.bubble { max-width: 88%; padding: 10px 14px; border-radius: 16px; background: var(--surface-2); border: 1px solid var(--border); white-space: pre-wrap; word-break: break-word; align-self: flex-start; }
.bubble.mine { align-self: flex-end; background: var(--accent-soft); border-color: var(--accent); }
.bubble .bubble-meta { font-size: .75rem; color: var(--muted); margin-top: 4px; }
.chat-input { display: flex; gap: 8px; align-items: flex-end; position: sticky; bottom: 0; background: var(--bg); padding: 10px 0; }
.chat-input textarea { flex: 1; min-height: 52px; }
.chat-input .btn { flex: none; }

/* ---------- Calendar ---------- */
.cal-nav { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.cal-event { display: flex; gap: 10px; align-items: baseline; padding: 10px 4px; border-bottom: 1px solid var(--border); }
.cal-event:last-child { border-bottom: 0; }
.cal-date { font-weight: 800; color: var(--accent); white-space: nowrap; font-variant-numeric: tabular-nums; }

/* ---------- Admin ---------- */
.admin-grid { display: grid; gap: 12px; grid-template-columns: 1fr 1fr; }
@media (min-width: 720px) { .admin-grid { grid-template-columns: repeat(3, 1fr); } }
.admin-card { text-decoration: none; color: var(--text); }
.admin-card:hover { border-color: var(--accent); }
.admin-card .admin-icon { font-size: 1.7rem; }
.admin-card strong { display: block; margin: 4px 0 2px; }
.code-big { font-size: 1.4rem; font-weight: 800; letter-spacing: .18em; direction: ltr; unicode-bidi: embed; font-variant-numeric: tabular-nums; }
.mono { font-family: Consolas, "Courier New", monospace; direction: ltr; text-align: left; }
.formula-editor { min-height: 170px; }
.pager { display: flex; gap: 8px; align-items: center; justify-content: center; margin: 16px 0 4px; flex-wrap: wrap; }

/* ---------- Misc ---------- */
.hidden { display: none !important; }
.text-center { text-align: center; }
.mt-0 { margin-top: 0; }
.mb-0 { margin-bottom: 0; }
#print-area { display: none; }
@media (max-width: 480px) {
  .brand-text small { display: none; }
  .brand-text strong { font-size: .88rem; }
  h1 { font-size: 1.3rem; }
  .app { padding: 12px 8px 24px; }
}
