:root {
  --navy: #17365d;
  --navy2: #24508a;
  --bg: #f3f6f9;
  --card: #ffffff;
  --ink: #1b2533;
  --muted: #5b6878;
  --line: #d9e1ea;
  --ok: #157a3c;
  --ok-bg: #e5f6ec;
  --bad: #b42318;
  --bad-bg: #fdecea;
  --warn: #8a5a00;
  --warn-bg: #fff4d6;
  --late: #9a4d00;
  --late-bg: #ffe9d1;
  --info-bg: #e8f0fb;
  --radius: 14px;
  color-scheme: light;
}
* {
  box-sizing: border-box;
}
html,
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Segoe UI', Tahoma, 'Noto Naskh Arabic', 'Noto Sans Arabic', 'Geeza Pro', Arial, sans-serif;
  font-size: 17px;
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
}
body {
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}
button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}
a {
  color: var(--navy2);
}
.hidden {
  display: none !important;
}
.app {
  max-width: 980px;
  margin: 0 auto;
  padding: 12px 16px 24px;
  outline: none;
}
.loading {
  text-align: center;
  color: var(--muted);
  padding: 40px 0;
}

/* الشريط العلوي */
.top {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  background: var(--navy);
  color: #fff;
}
.top .school {
  font-weight: 800;
  font-size: 17px;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.top .who {
  font-size: 13px;
  opacity: 0.85;
}
.top select {
  max-width: 46vw;
  background: #fff1;
  color: #fff;
  border: 1px solid #fff5;
  border-radius: 10px;
  padding: 4px 8px;
}
.top select option {
  color: var(--ink);
}
.top .icon-btn {
  background: transparent;
  border: 1px solid #fff6;
  color: #fff;
  border-radius: 10px;
  min-height: 40px;
  padding: 0 10px;
}

/* التنقل السفلي */
.nav {
  position: fixed;
  inset: auto 0 0 0;
  z-index: 10;
  display: flex;
  justify-content: space-around;
  background: #fff;
  border-top: 1px solid var(--line);
  padding: 4px 4px calc(4px + env(safe-area-inset-bottom));
}
.nav a {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  padding: 6px 2px;
  min-height: 56px;
  text-decoration: none;
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 700;
  border-radius: 12px;
}
.nav a .i {
  font-size: 22px;
  line-height: 1.2;
}
.nav a.on {
  color: var(--navy);
  background: var(--info-bg);
}

/* الشبكة */
.net {
  position: sticky;
  top: 0;
  z-index: 11;
  padding: 6px 16px;
  text-align: center;
  font-weight: 700;
  font-size: 14px;
  background: var(--warn-bg);
  color: var(--warn);
}
.net.ok {
  background: var(--ok-bg);
  color: var(--ok);
}

/* عناصر عامة */
h1 {
  font-size: 22px;
  margin: 8px 0 12px;
  color: var(--navy);
}
h2 {
  font-size: 18px;
  margin: 16px 0 8px;
  color: var(--navy);
}
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 12px;
}
.row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.grow {
  flex: 1;
  min-width: 0;
}
.muted {
  color: var(--muted);
  font-size: 14px;
}
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 48px;
  padding: 0 18px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #fff;
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
  color: var(--ink);
}
.btn.primary {
  background: var(--navy);
  border-color: var(--navy);
  color: #fff;
}
.btn.wa {
  background: #1f8f4e;
  border-color: #1f8f4e;
  color: #fff;
}
.btn.danger {
  color: var(--bad);
  border-color: #f0b3ad;
}
.btn.small {
  min-height: 38px;
  padding: 0 12px;
  font-size: 14px;
}
.btn:disabled {
  opacity: 0.5;
  cursor: default;
}
.btn:focus-visible,
.nav a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
.seg button:focus-visible {
  outline: 3px solid #f5b400;
  outline-offset: 2px;
}
label.f {
  display: block;
  font-weight: 700;
  margin: 10px 0 4px;
}
input[type='text'],
input[type='password'],
input[type='tel'],
input[type='date'],
input[type='month'],
input:not([type]),
select,
textarea {
  width: 100%;
  min-height: 48px;
  padding: 8px 12px;
  border: 1px solid #b8c4d2;
  border-radius: 12px;
  background: #fff;
}
textarea {
  min-height: 110px;
  resize: vertical;
}
.ltr {
  direction: ltr;
  unicode-bidi: isolate;
  text-align: left;
}
.err {
  color: var(--bad);
  font-weight: 700;
  margin: 8px 0;
}
.note {
  background: var(--info-bg);
  border-radius: 12px;
  padding: 10px 12px;
  margin: 8px 0;
  font-size: 15px;
}
.note.warn {
  background: var(--warn-bg);
  color: var(--warn);
}
.badge {
  display: inline-block;
  padding: 0 10px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 800;
  background: var(--info-bg);
  color: var(--navy);
  white-space: nowrap;
}
.badge.ok {
  background: var(--ok-bg);
  color: var(--ok);
}
.badge.bad {
  background: var(--bad-bg);
  color: var(--bad);
}
.badge.warn {
  background: var(--warn-bg);
  color: var(--warn);
}
.badge.late {
  background: var(--late-bg);
  color: var(--late);
}
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}
.stat {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
}
.stat b {
  display: block;
  font-size: 26px;
  color: var(--navy);
}
.list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.list > li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 4px;
  border-bottom: 1px solid var(--line);
}
.list > li:last-child {
  border-bottom: 0;
}
.list a.item {
  flex: 1;
  text-decoration: none;
  color: inherit;
  min-height: 44px;
  display: flex;
  align-items: center;
  gap: 8px;
}
table.t {
  width: 100%;
  border-collapse: collapse;
  font-size: 15px;
}
table.t th,
table.t td {
  border-bottom: 1px solid var(--line);
  padding: 8px 6px;
  text-align: start;
}
table.t th {
  background: #eef2f7;
}
.scroll {
  overflow-x: auto;
}

/* الحضور */
.att li {
  flex-wrap: wrap;
}
.att .name {
  flex: 1 1 160px;
  font-weight: 700;
}
.seg {
  display: inline-flex;
  border: 1px solid #b8c4d2;
  border-radius: 12px;
  overflow: hidden;
}
.seg button {
  border: 0;
  border-inline-start: 1px solid #b8c4d2;
  background: #fff;
  min-height: 44px;
  min-width: 58px;
  padding: 0 8px;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
}
.seg button:first-child {
  border-inline-start: 0;
}
.seg button[aria-pressed='true'][data-s='present'] {
  background: var(--ok);
  color: #fff;
}
.seg button[aria-pressed='true'][data-s='absent'] {
  background: var(--bad);
  color: #fff;
}
.seg button[aria-pressed='true'][data-s='late'] {
  background: #c25e00;
  color: #fff;
}
.seg button[aria-pressed='true'][data-s='excused'] {
  background: var(--navy2);
  color: #fff;
}
.sticky-actions {
  position: sticky;
  bottom: calc(72px + env(safe-area-inset-bottom));
  background: linear-gradient(#f3f6f900, var(--bg) 30%);
  padding: 14px 0 6px;
  display: flex;
  gap: 8px;
}
.sticky-actions .btn {
  flex: 1;
}

/* البطاقات المطبوعة */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 10px;
}
.lcard {
  border: 2px dashed #8aa0b8;
  border-radius: 12px;
  padding: 10px 12px;
  background: #fff;
  display: flex;
  gap: 10px;
  break-inside: avoid;
}
.lcard .qr {
  width: 96px;
  flex: none;
}
.lcard .qr svg {
  width: 96px;
  height: 96px;
}
.lcard .kv {
  font-size: 14px;
}
.lcard .kv b {
  font-size: 17px;
  letter-spacing: 1px;
}
.creds {
  font-size: 18px;
}
.creds b {
  direction: ltr;
  unicode-bidi: isolate;
  letter-spacing: 1px;
}
.qr-box svg {
  width: 180px;
  height: 180px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(84px + env(safe-area-inset-bottom));
  transform: translate(-50%, 20px);
  background: #1b2533;
  color: #fff;
  padding: 10px 18px;
  border-radius: 12px;
  font-weight: 700;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  max-width: calc(100vw - 32px);
  z-index: 20;
}
.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.login {
  max-width: 420px;
  margin: 6vh auto 0;
}
.login .logo {
  text-align: center;
  font-size: 46px;
}
.login h1 {
  text-align: center;
}
.month {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  font-size: 13px;
  text-align: center;
}
.month div {
  padding: 6px 0;
  border-radius: 8px;
  background: #fff;
  border: 1px solid var(--line);
}
.month .absent {
  background: var(--bad-bg);
  color: var(--bad);
  font-weight: 800;
}
.month .late {
  background: var(--late-bg);
  color: var(--late);
  font-weight: 800;
}
.month .present {
  background: var(--ok-bg);
  color: var(--ok);
}
.month .excused {
  background: var(--info-bg);
  color: var(--navy);
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
    animation: none !important;
  }
}
@media print {
  .top,
  .nav,
  .net,
  .noprint,
  .toast {
    display: none !important;
  }
  body {
    background: #fff;
    padding: 0;
  }
  .app {
    max-width: none;
    padding: 0;
  }
  .cards {
    grid-template-columns: 1fr 1fr;
  }
  .card {
    border: 0;
    padding: 0;
  }
}
