/* حلقة نور — styles. Mobile first; works on phones, iPad and computers, in both directions. */
:root {
  --bg: #f6f3ec;
  --surface: #ffffff;
  --surface-2: #f0ebe1;
  --text: #1d2827;
  --muted: #687270;
  --border: #e3ddd0;
  --accent: #0f6b5c;
  --accent-ink: #ffffff;
  --accent-soft: #dcefe9;
  --gold: #b8892d;
  --ok: #1f8a4c;
  --warn: #b7791f;
  --danger: #b4382c;
  --info: #2f6fb0;
  --radius: 16px;
  --tabbar: 64px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101615;
    --surface: #18201f;
    --surface-2: #212b29;
    --text: #e7eeec;
    --muted: #94a3a0;
    --border: #2c3836;
    --accent: #4fb9a3;
    --accent-ink: #0b1513;
    --accent-soft: #1b3832;
    --gold: #d8ad55;
    --ok: #4cc47e;
    --warn: #e0a64a;
    --danger: #e3786c;
    --info: #74a8e0;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.6 "Noto Sans Arabic", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
:root[dir="ltr"] body { font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans Arabic", sans-serif; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
h1, h2, h3 { line-height: 1.3; }
.muted { color: var(--muted); }
.small { font-size: 0.86rem; }
.pre { white-space: pre-wrap; overflow-wrap: anywhere; }
.ok { color: var(--ok); font-weight: 600; }
bdi.url { overflow-wrap: anywhere; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: calc(10px + env(safe-area-inset-top, 0px)) max(16px, env(safe-area-inset-right)) 10px max(16px, env(safe-area-inset-left));
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: saturate(1.4) blur(12px);
  -webkit-backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 1.2rem; white-space: nowrap; }
.brand-mark { color: var(--gold); }
.topbar-end { display: flex; align-items: center; gap: 8px; min-width: 0; }
.lang {
  max-width: 190px; padding: 7px 10px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--bg); cursor: pointer;
}
.account {
  display: flex; align-items: center; gap: 8px; min-width: 0;
  padding: 3px 12px 3px 3px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--bg); cursor: pointer;
}
:root[dir="rtl"] .account { padding: 3px 3px 3px 12px; }
.account-text { display: flex; flex-direction: column; line-height: 1.15; text-align: start; min-width: 0; }
@media (max-width: 420px) { .lang { max-width: 128px; } .account-text { display: none; } .account { padding: 3px !important; } }
.account-text bdi { font-weight: 600; font-size: 0.9rem; max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-text small { color: var(--muted); font-size: 0.72rem; }
.avatar {
  display: inline-grid; place-items: center; flex: none;
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--accent); color: var(--accent-ink); font-weight: 700;
}
.avatar.small { width: 32px; height: 32px; font-size: 0.9rem; background: var(--surface-2); color: var(--text); }

/* ---------- main area ---------- */
.app {
  max-width: 1040px; margin: 0 auto;
  padding: 16px max(16px, env(safe-area-inset-right)) calc(var(--tabbar) + var(--safe-bottom) + 24px) max(16px, env(safe-area-inset-left));
}
.page-head { display: flex; align-items: flex-start; gap: 10px; margin: 4px 0 16px; }
.page-title { flex: 1; min-width: 0; }
.page-title h1 { margin: 0; font-size: 1.6rem; overflow-wrap: anywhere; }
.page-title p { margin: 2px 0 0; }
.page-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.section-title { font-size: 1.05rem; margin: 26px 0 10px; color: var(--muted); }
.section { margin-top: 14px; display: flex; flex-direction: column; gap: 12px; }
.section-actions { display: flex; justify-content: flex-end; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; display: flex; flex-direction: column; gap: 8px;
}
.card h3 { margin: 0; font-size: 1.08rem; }
.card p { margin: 0; }
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.grid { display: grid; gap: 12px; grid-template-columns: 1fr; }
@media (min-width: 640px) { .grid { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 1000px) { .grid { grid-template-columns: repeat(3, 1fr); } }
a.card { color: inherit; text-decoration: none; transition: transform 0.1s, border-color 0.1s; }
a.card:hover { border-color: var(--accent); }
a.card:active { transform: scale(0.99); }
.halaqah-card h3 { color: var(--accent); }
.clamp { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.folder-card { flex-direction: row; align-items: center; gap: 14px; }
.folder-card .icon { width: 40px; height: 40px; color: var(--gold); flex: none; }

.empty { text-align: center; padding: 40px 16px; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 14px; }
.empty p { margin: 0; max-width: 460px; }
.notice { background: var(--accent-soft); color: var(--text); border-radius: 12px; padding: 12px 14px; margin: 0; }
.notice.error { background: color-mix(in srgb, var(--danger) 14%, transparent); }

/* ---------- lists ---------- */
.list { display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.list > .card { border-radius: 0; border: 0; border-bottom: 1px solid var(--border); }
.list > :last-child { border-bottom: 0 !important; }
.row {
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 12px 16px; min-height: 56px;
  border: 0; border-bottom: 1px solid var(--border); background: none; text-align: start; color: inherit;
}
button.row, label.row { cursor: pointer; }
button.row:hover, label.row:hover { background: var(--surface-2); }
.row-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.row-main strong { overflow-wrap: anywhere; }
.row-end { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; flex: none; }
.row-end .progress { width: 90px; }
.batch { padding: 0; gap: 0; }
.batch > .row { border-bottom: 0; }
.batch-detail { padding: 0 16px 14px; display: flex; flex-direction: column; gap: 10px; }
.who { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 4px 16px; }
.who li { color: var(--muted); }
.who li.done { color: var(--ok); font-weight: 600; }

.homework-row.done strong { text-decoration: line-through; color: var(--muted); }
.tick { width: 26px; height: 26px; flex: none; accent-color: var(--ok); cursor: pointer; }

.date-box {
  flex: none; width: 54px; padding: 6px 0; border-radius: 12px; text-align: center;
  background: var(--accent-soft); color: var(--accent); display: flex; flex-direction: column; line-height: 1.2;
}
.date-box strong { font-size: 1.3rem; }
.date-box small { font-size: 0.68rem; }

/* ---------- badges, chips, progress ---------- */
.badge {
  display: inline-block; padding: 1px 10px; border-radius: 999px; font-size: 0.76rem; font-weight: 600;
  background: var(--surface-2); color: var(--muted); white-space: nowrap; vertical-align: middle;
}
.badge.late { background: color-mix(in srgb, var(--danger) 15%, transparent); color: var(--danger); }
.badge.soon { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }
.badge.ok { background: color-mix(in srgb, var(--ok) 15%, transparent); color: var(--ok); }
.badge.type-memorization { background: color-mix(in srgb, var(--accent) 15%, transparent); color: var(--accent); }
.badge.type-revision { background: color-mix(in srgb, var(--info) 15%, transparent); color: var(--info); }
.badge.type-reading { background: color-mix(in srgb, var(--gold) 18%, transparent); color: var(--gold); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  min-height: 40px; padding: 6px 14px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--border); background: var(--bg); font-size: 0.9rem; font-weight: 600; color: var(--muted);
}
.chip.on { color: #fff; border-color: transparent; }
.chip.status-present.on { background: var(--ok); }
.chip.status-late.on { background: var(--warn); }
.chip.status-absent.on { background: var(--danger); }
.chip.status-excused.on { background: var(--info); }
span.chip { min-height: 0; padding: 2px 12px; cursor: default; }
.attendance-row { flex-wrap: wrap; }
@media (max-width: 560px) { .attendance-row .chips { width: 100%; } .attendance-row .chip { flex: 1; padding: 6px 4px; } }

.progress { height: 8px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.progress-fill { height: 100%; border-radius: inherit; background: var(--accent); transition: width 0.3s; }
.plan {
  display: flex; flex-direction: column; gap: 6px; width: 100%;
  padding: 10px 0; border: 0; border-top: 1px solid var(--border); background: none; text-align: start; color: inherit;
}
button.plan { cursor: pointer; }
button.plan:hover strong { color: var(--accent); }
.plan-top { display: flex; justify-content: space-between; gap: 8px; }
.pct { font-weight: 700; color: var(--accent); }
.card > .plan:first-of-type { border-top: 0; }

.stat { flex-direction: row; align-items: center; gap: 14px; }
.stat .big { font-size: 2rem; color: var(--accent); }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 8px 18px; border-radius: 12px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); font-weight: 600;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--danger); border-color: currentColor; background: none; }
.btn.wide { width: 100%; }
.btn:disabled, .icon-btn:disabled { opacity: 0.5; cursor: default; }
.btn .icon { width: 20px; height: 20px; }
.icon-btn {
  display: inline-grid; place-items: center; flex: none;
  width: 44px; height: 44px; border-radius: 12px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
}
.icon-btn .icon { width: 22px; height: 22px; }
:root[dir="rtl"] .back .icon { transform: scaleX(-1); }
.link { background: none; border: 0; color: var(--accent); cursor: pointer; padding: 6px; font-weight: 600; }
.icon { display: inline-flex; width: 24px; height: 24px; }
.icon svg { width: 100%; height: 100%; }
.row > .icon { color: var(--accent); flex: none; }
.item-link { font-weight: 700; text-decoration: none; overflow-wrap: anywhere; }
.item-link:hover { text-decoration: underline; }

.segmented {
  display: flex; gap: 4px; padding: 4px; border-radius: 14px;
  background: var(--surface-2); overflow-x: auto; scrollbar-width: none;
}
.segmented::-webkit-scrollbar { display: none; }
.segmented button {
  flex: 1 0 auto; min-height: 40px; padding: 6px 14px; border: 0; border-radius: 10px;
  background: none; cursor: pointer; font-weight: 600; color: var(--muted); white-space: nowrap;
}
.segmented button.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgb(0 0 0 / 0.12); }

/* ---------- forms ---------- */
.stack { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-weight: 600; font-size: 0.92rem; }
input:not([type="checkbox"]):not([type="radio"]):not([type="range"]), select, textarea {
  width: 100%; min-height: 46px; padding: 10px 12px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--bg);
  font-size: 16px; /* stops iPhone zooming in on focus */
}
textarea { resize: vertical; }
input:focus, select, textarea:focus { outline-color: var(--accent); }
input[type="range"] { width: 100%; accent-color: var(--accent); height: 32px; }
input[type="date"] { min-width: 0; }
input[dir="ltr"] { text-align: left; }
:root[dir="rtl"] input[dir="ltr"] { text-align: right; }
:root[dir="rtl"] input[type="date"] { direction: rtl; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 420px) { .two { grid-template-columns: 1fr; } }
.form-error { color: var(--danger); font-weight: 600; margin: 0; }
.form-error:empty { display: none; }
.form-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.toolbar { flex-direction: row; align-items: flex-end; justify-content: space-between; flex-wrap: wrap; gap: 12px; }
.toolbar .field { flex: 1 1 180px; }
fieldset { border: 0; padding: 0; margin: 0; }
legend { font-weight: 600; font-size: 0.92rem; margin-bottom: 6px; padding: 0; }
.roles { display: flex; flex-direction: column; gap: 8px; }
.role-option {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px; cursor: pointer;
  border: 1px solid var(--border); border-radius: 12px; background: var(--bg);
}
.role-option:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.role-option input { width: 20px; height: 20px; accent-color: var(--accent); margin: 0; flex: none; }
.role-text { display: flex; flex-direction: column; }
.pick-list { display: flex; flex-direction: column; gap: 2px; max-height: 260px; overflow-y: auto; border: 1px solid var(--border); border-radius: 12px; padding: 6px; }
.pick-list legend { padding: 0 4px; }
.check { display: flex; align-items: center; gap: 10px; padding: 8px 6px; border-radius: 8px; cursor: pointer; }
.check:hover { background: var(--surface-2); }
.check input { width: 20px; height: 20px; accent-color: var(--accent); margin: 0; }
.check.all { font-weight: 700; border-bottom: 1px solid var(--border); border-radius: 0; }
.add-students .form-row .form-error { flex: 1; }

/* ---------- sign in ---------- */
.auth { display: flex; justify-content: center; padding-top: 12px; }
.auth-card { width: 100%; max-width: 440px; gap: 16px; padding: 24px; }
.auth-card h1 { margin: 0; }
.auth-card h2 { margin: 0; font-size: 1.2rem; }
.auth-brand { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.auth-brand h1 { font-size: 2rem; }
.auth-brand p { margin: 0; }
.auth-logo {
  width: 64px; height: 64px; border-radius: 20px; display: grid; place-items: center;
  font-size: 2rem; color: var(--gold); background: var(--accent-soft);
}

/* ---------- bottom tab bar ---------- */
.tabs {
  position: fixed; inset-inline: 0; bottom: 0; z-index: 10;
  display: flex; justify-content: center;
  padding: 0 env(safe-area-inset-right) var(--safe-bottom) env(safe-area-inset-left);
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  backdrop-filter: saturate(1.4) blur(12px);
  -webkit-backdrop-filter: saturate(1.4) blur(12px);
  border-top: 1px solid var(--border);
}
.tab {
  flex: 1; max-width: 160px; height: var(--tabbar);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); text-decoration: none; font-size: 0.74rem; font-weight: 600;
}
.tab .icon { width: 26px; height: 26px; }
.tab.active { color: var(--accent); }
@media (min-width: 700px) { .tab { flex-direction: row; gap: 8px; font-size: 0.9rem; } }

/* ---------- sheet (pop-up form) ---------- */
.sheet {
  border: 0; padding: 0; margin: auto auto 0; width: 100%; max-width: 560px;
  max-height: 92dvh; border-radius: 22px 22px 0 0;
  background: var(--surface); color: var(--text);
}
@media (min-width: 700px) { .sheet { margin: auto; border-radius: 22px; } }
.sheet::backdrop { background: rgb(0 0 0 / 0.45); }
.sheet-form { display: flex; flex-direction: column; max-height: 92dvh; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 16px 18px 8px; }
.sheet-head h2 { margin: 0; font-size: 1.2rem; }
.sheet-body { padding: 8px 18px; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; }
.sheet-form > .form-error { padding: 0 18px; }
.sheet-actions {
  display: flex; justify-content: space-between; gap: 10px;
  padding: 12px 18px calc(14px + var(--safe-bottom)); border-top: 1px solid var(--border);
}
.sheet-actions .primary { min-width: 120px; }

/* ---------- toast & loading ---------- */
.toast {
  position: fixed; inset-inline: 16px; bottom: calc(var(--tabbar) + var(--safe-bottom) + 14px); z-index: 30;
  max-width: 480px; margin: 0 auto; padding: 12px 16px; border-radius: 12px;
  background: var(--text); color: var(--bg); text-align: center; font-weight: 600;
  box-shadow: 0 6px 24px rgb(0 0 0 / 0.2);
}
.toast.error { background: var(--danger); color: #fff; }
.loading { display: grid; place-items: center; padding: 80px 0; }
.spinner { width: 36px; height: 36px; border-radius: 50%; border: 4px solid var(--surface-2); border-top-color: var(--accent); animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 3s; } * { transition: none !important; } }

/* ---------- sign-up links ---------- */
.invite-card { gap: 10px; border-color: color-mix(in srgb, var(--accent) 35%, var(--border)); }
.share { display: flex; flex-direction: column; gap: 8px; }
.link-input { font-family: ui-monospace, SFMono-Regular, Menlo, monospace !important; font-size: 0.85rem !important; }
.share-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.share-actions .btn { flex: 1 1 140px; }
.btn.whatsapp { background: #25d366; border-color: #25d366; color: #fff; text-decoration: none; }
.danger-link { color: var(--danger); }
.center { text-align: center; }
.notice.join { font-weight: 600; }
