:root {
  --bg: #f6f4ef;
  --card: #ffffff;
  --ink: #1f2421;
  --muted: #5f6661;
  --line: #e4e0d6;
  --brand: #2f5d50;
  --brand-ink: #ffffff;
  --soft: color-mix(in srgb, var(--brand) 10%, var(--card));
  --danger: #b3261e;
  --radius: 16px;
  --tab-h: 64px;
  --bg-dim: 40%;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141816;
    --card: #1d2320;
    --ink: #eef1ee;
    --muted: #a3aca6;
    --line: #2d3531;
    --danger: #ff8a80;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 17px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans Arabic", "Geeza Pro", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
body.large-text { font-size: 20px; }

/* Background photo with a fade so text stays readable. */
body.has-bg::before, body.has-bg::after { content: ""; position: fixed; inset: 0; pointer-events: none; }
body.has-bg::before { background: var(--bg-image) center / cover no-repeat; z-index: -2; }
body.has-bg::after { background: color-mix(in srgb, var(--bg) var(--bg-dim), transparent); z-index: -1; }
body.has-bg { background: var(--bg); }
body.has-bg #app { position: relative; z-index: 0; }

#app {
  max-width: 760px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 18px) 16px calc(var(--tab-h) + env(safe-area-inset-bottom) + 24px);
}
#app.no-tabs { padding-bottom: 32px; }

h1 { font-size: 1.65rem; line-height: 1.2; margin: 0; }
h2 { font-size: 1.05rem; margin: 0; }
h3 { font-size: 0.95rem; margin: 0 0 8px; }
p { margin: 0; }
a { color: inherit; }
.muted { color: var(--muted); }
.small { font-size: 0.875rem; }
.center { text-align: center; }
.block { display: block; }
.grow { flex: 1; min-width: 0; text-decoration: none; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.stack > * + * { margin-top: 14px; }
.row { display: flex; gap: 12px; align-items: center; }
.row.between { justify-content: space-between; }
.row.wrap { flex-wrap: wrap; }
.row.tight { gap: 4px; }
.link { color: var(--brand); background: none; border: 0; padding: 0; font: inherit; cursor: pointer; text-decoration: none; font-weight: 600; }
.back { display: inline-block; color: var(--brand); text-decoration: none; font-weight: 600; padding: 4px 0; }
.page-head { min-height: 44px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  display: block;
}
.card.soft { background: var(--soft); border-color: transparent; }
.card.row { display: flex; }
.card.off { opacity: 0.55; }
.card.tap { cursor: pointer; text-decoration: none; color: inherit; }
.card.tap:active { transform: scale(0.99); }

.list { display: grid; gap: 10px; }
.record-title { font-weight: 600; }
.record { display: grid; gap: 4px; }
.record .row.muted { gap: 8px; flex-wrap: wrap; }
.record.done { opacity: 0.6; }
.record.done .record-title { text-decoration: line-through; }
.record.overdue { border-color: color-mix(in srgb, var(--danger) 45%, var(--line)); }

.badge {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 2px 9px;
  border-radius: 999px;
  background: var(--soft);
  color: var(--brand);
  white-space: nowrap;
}
.badge.colored { background: color-mix(in srgb, var(--badge) 16%, transparent); color: var(--badge); }

.avatar {
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--brand); color: var(--brand-ink);
  display: inline-grid; place-items: center; font-weight: 700; flex: none; overflow: hidden;
}
.avatar.lg { width: 52px; height: 52px; font-size: 1.3rem; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }

/* Today */
.today-head .row { margin-bottom: 6px; }
.app-name { margin-bottom: 2px; }
.hijri { font-size: 1rem; }
.quick-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.quick {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  min-height: 76px; padding: 8px 4px; text-align: center;
  background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  text-decoration: none; color: var(--ink); font-size: 0.78rem; font-weight: 600; line-height: 1.2;
}
.quick .icon { font-size: 1.5rem; }
.quick:active { background: var(--soft); }
.widgets { display: grid; grid-template-columns: 1fr; gap: 12px; }
@media (min-width: 640px) {
  .widgets { grid-template-columns: 1fr 1fr; }
  .widget.wide { grid-column: 1 / -1; }
}
.widget-head { margin-bottom: 10px; }
.items { list-style: none; margin: 0; padding: 0; }
.items li + li { border-top: 1px solid var(--line); }
.item { display: flex; justify-content: space-between; gap: 10px; padding: 10px 0; text-decoration: none; color: inherit; align-items: center; }
.item-title { flex: 1; min-width: 0; }
.item-meta { display: flex; gap: 8px; align-items: center; color: var(--muted); font-size: 0.875rem; white-space: nowrap; }
.item.overdue .item-meta > span:first-child { color: var(--danger); font-weight: 600; }
.big-number { display: block; font-size: 2.6rem; font-weight: 800; color: var(--brand); text-decoration: none; line-height: 1.1; }

/* Charts */
.chart-wrap { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
.donut { width: 150px; height: 150px; flex: none; }
.donut-total { font-size: 20px; font-weight: 700; fill: var(--ink); }
.line { width: 100%; height: auto; }
.line .axis { font-size: 10px; fill: var(--muted); }
.legend { list-style: none; margin: 0; padding: 0; flex: 1; min-width: 160px; display: grid; gap: 6px; }
.legend li { display: flex; gap: 8px; align-items: center; }
.legend li strong { margin-inline-start: auto; }
.dot { width: 12px; height: 12px; border-radius: 50%; background: var(--dot); flex: none; }
.bars { display: grid; gap: 8px; }
.bar-row { display: grid; grid-template-columns: minmax(70px, 30%) 1fr auto; gap: 10px; align-items: center; font-size: 0.9rem; }
.bar-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { background: var(--line); border-radius: 6px; height: 12px; overflow: hidden; }
.bar-fill { display: block; height: 100%; width: var(--w); background: var(--c); border-radius: 6px; }
.bar-value { font-weight: 600; }

/* Lists of modules */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.tile {
  display: flex; flex-direction: column; gap: 6px; padding: 16px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  text-decoration: none; color: var(--ink); min-height: 96px;
}
.tile-icon { font-size: 1.7rem; }
.tile-name { font-weight: 600; }
.board { display: flex; gap: 12px; overflow-x: auto; padding-bottom: 8px; scroll-snap-type: x mandatory; }
.board-col { flex: 0 0 min(80vw, 280px); scroll-snap-align: start; display: grid; gap: 8px; align-content: start; }
.segmented { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.segmented button { border: 0; background: var(--card); color: var(--ink); padding: 8px 16px; font-weight: 600; min-height: 40px; }
.segmented button.on { background: var(--brand); color: var(--brand-ink); }

/* Forms */
label { display: block; font-weight: 600; margin-bottom: 6px; }
label.check { display: flex; gap: 10px; align-items: center; font-weight: 500; margin: 0; min-height: 40px; }
label.check input { width: 22px; height: 22px; min-height: 0; }
.hint { font-weight: 400; color: var(--muted); font-size: 0.875rem; }
.field-error { color: var(--danger); font-size: 0.875rem; font-weight: 600; margin-top: 4px; }
.has-error input, .has-error select, .has-error textarea { border-color: var(--danger); }
.field.computed div { padding: 4px 0; }
input, select, textarea {
  width: 100%;
  font: inherit;
  color: inherit;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  min-height: 50px;
}
input[type="checkbox"], input[type="range"], input[type="color"] { width: auto; min-height: 0; padding: 0; }
input[type="range"] { width: 100%; accent-color: var(--brand); }
input[type="checkbox"] { accent-color: var(--brand); }
input.switch { width: 28px; height: 28px; }
textarea { min-height: 96px; resize: vertical; }
input:focus, select:focus, textarea:focus, button:focus-visible, a:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--brand) 45%, transparent);
  outline-offset: 1px;
}
.emoji-input { width: 90px; font-size: 1.4rem; text-align: center; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.chip {
  background: var(--soft); color: var(--ink); border: 1px solid transparent;
  border-radius: 999px; padding: 7px 14px; font: inherit; font-size: 0.95rem; text-decoration: none;
}
.chip.toggle { background: var(--card); border-color: var(--line); cursor: pointer; min-height: 40px; }
.chip.toggle.on { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }

.image-picker { display: grid; gap: 10px; }
.image-preview {
  width: 100%; max-width: 280px; aspect-ratio: 16 / 10; border-radius: 12px; overflow: hidden;
  background: var(--soft); display: grid; place-items: center;
}
.image-preview.round { width: 96px; height: 96px; aspect-ratio: 1; border-radius: 50%; }
.image-preview img { width: 100%; height: 100%; object-fit: cover; }

.swatches { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.swatch { width: 40px; height: 40px; border-radius: 50%; border: 3px solid var(--card); background: var(--sw);
  box-shadow: 0 0 0 1px var(--line); cursor: pointer; }
.swatch.on { box-shadow: 0 0 0 3px var(--ink); }
.swatches input[type="color"] { width: 44px; height: 40px; border-radius: 10px; border: 1px solid var(--line); background: none; }

button { font: inherit; cursor: pointer; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 50px; padding: 0 20px; border-radius: 12px; border: 1px solid transparent;
  font-weight: 600; background: var(--brand); color: var(--brand-ink); text-decoration: none; margin: 0;
}
.btn.block { display: flex; width: 100%; }
.btn.secondary { background: var(--card); color: var(--ink); border-color: var(--line); }
.btn.danger { background: transparent; color: var(--danger); border-color: var(--line); }
.btn.small { min-height: 40px; padding: 0 14px; font-size: 0.95rem; }
.btn[disabled] { opacity: 0.55; }
.icon-btn { width: 40px; height: 40px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); color: var(--ink); }
.icon-btn[disabled] { opacity: 0.35; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 18px; }

.error {
  background: color-mix(in srgb, var(--danger) 12%, transparent);
  color: var(--danger); border-radius: 12px; padding: 10px 14px; font-weight: 600;
}
.secret {
  font: 600 1.4rem/1.3 ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: 0.04em; text-align: center; padding: 14px; border-radius: 12px;
  background: var(--soft); user-select: all; -webkit-user-select: all;
}

/* More menu */
.menu-item { display: flex; gap: 14px; align-items: center; }
.menu-icon { font-size: 1.5rem; width: 36px; text-align: center; flex: none; }
.chev { margin-inline-start: auto; color: var(--muted); font-size: 1.5rem; }
.person-card { display: flex; gap: 14px; align-items: center; }
.field-row { padding: 6px 0; border-bottom: 1px solid var(--line); }
.field-row:last-child { border-bottom: 0; }

/* Import preview */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.stat { background: var(--soft); border-radius: 12px; padding: 10px; text-align: center; display: grid; }
.stat strong { font-size: 1.4rem; }
details > summary { cursor: pointer; list-style: none; display: flex; flex-wrap: wrap; gap: 6px; align-items: baseline; }
details > summary::-webkit-details-marker { display: none; }
.issues { list-style: none; margin: 10px 0 0; padding: 0; display: grid; gap: 6px; font-size: 0.9rem; }
.issue { display: flex; gap: 8px; align-items: baseline; }
.issue-tag { font-size: 0.7rem; font-weight: 700; text-transform: uppercase; padding: 2px 6px; border-radius: 6px; flex: none; }
.issue.error .issue-tag { background: color-mix(in srgb, var(--danger) 15%, transparent); color: var(--danger); }
.issue.warning .issue-tag { background: color-mix(in srgb, #c99a06 18%, transparent); color: #9a7604; }
.issue.info .issue-tag { background: var(--soft); color: var(--brand); }

.login-wrap { min-height: 80vh; display: grid; align-content: center; }
.brand { font-size: 2.2rem; text-align: center; }

#tabbar {
  position: fixed; inset: auto 0 0 0; display: flex; z-index: 5;
  background: color-mix(in srgb, var(--card) 92%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
}
#tabbar[hidden] { display: none; }
#tabbar a {
  flex: 1; height: var(--tab-h); display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; text-decoration: none; color: var(--muted); font-size: 0.75rem; font-weight: 600;
}
#tabbar a .icon { font-size: 1.4rem; line-height: 1; }
#tabbar a[aria-current="page"] { color: var(--brand); }

#toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--tab-h) + env(safe-area-inset-bottom) + 16px);
  background: var(--ink); color: var(--bg); padding: 12px 18px; border-radius: 12px;
  font-weight: 600; max-width: calc(100% - 32px); z-index: 10; display: flex; gap: 14px; align-items: center;
}
#toast[hidden] { display: none; }
.toast-action { background: none; border: 0; color: var(--bg); font-weight: 800; text-decoration: underline; padding: 4px; }

.audit-item { font-size: 0.9rem; padding: 8px 0; border-bottom: 1px solid var(--line); }
.audit-item:last-child { border-bottom: 0; }

@media (max-width: 380px) {
  .quick-grid { grid-template-columns: repeat(3, 1fr); }
  .stats { grid-template-columns: repeat(2, 1fr); }
}

/* ---------------------------------------------------------------- step 3: bell, lessons, reports */
.today-head > .row:first-child { align-items: flex-start; }
.today-head > .row:first-child > div:nth-child(2) { flex: 1; }
.bell { position: relative; display: inline-grid; place-items: center; width: 44px; height: 44px; border-radius: 50%;
  background: var(--card); border: 1px solid var(--line); text-decoration: none; font-size: 1.3rem; flex: none; }
.bell-count { position: absolute; top: -4px; right: -4px; min-width: 20px; height: 20px; padding: 0 5px; border-radius: 10px;
  background: var(--danger); color: #fff; font-size: .72rem; font-weight: 700; display: grid; place-items: center; }
.bell-count[hidden] { display: none; }
.record.unread { border-left: 4px solid var(--brand); }

.ball { display: inline-block; width: 14px; height: 14px; border-radius: 50%; flex: none;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.12); vertical-align: middle; }
.ball.green { background: #2e9e5b; }
.ball.amber { background: #e3a008; }
.ball.red { background: #d0382b; }
.ball.blue { background: #2f6fbf; }
.ball.grey { background: #9aa1a6; }
.ball-strip { display: flex; flex-wrap: wrap; gap: 6px; }
.ball-strip .ball { width: 22px; height: 22px; }
.legend-balls { gap: 12px; }
.row.tight { gap: 4px; }
.stack.tight { gap: 6px; }
.lesson-row { display: grid; grid-template-columns: 18px 1fr auto; align-items: center; gap: 10px; padding: 10px 12px;
  border-radius: 12px; background: var(--soft); color: inherit; text-decoration: none; min-height: 44px; }
.actions.wrap, .row.wrap { flex-wrap: wrap; }
.btn.ok { background: #2e9e5b; border-color: #2e9e5b; color: #fff; }
.btn[disabled] { opacity: .45; }
.note { white-space: pre-wrap; background: var(--soft); padding: 8px 10px; border-radius: 10px; margin: 0; font-family: inherit; }
.cal-buttons { gap: 8px; }
details.history summary { cursor: pointer; font-weight: 600; min-height: 32px; }
details.history ul { margin: 4px 0 0; padding-left: 18px; }
table.report { width: 100%; border-collapse: collapse; font-size: .92rem; }
table.report th, table.report td { padding: 6px 4px; text-align: center; border-bottom: 1px solid var(--line); }
table.report th:first-child, table.report td:first-child { text-align: left; }
@media (max-width: 380px) { .stats { grid-template-columns: repeat(2, 1fr); } }

/* ---------------------------------------------------------------- lessons page (balls) */
.month-nav { align-items: center; }
.month-nav strong { font-size: 1.05rem; }
.lesson-head { color: inherit; text-decoration: none; min-width: 0; }
.lesson-balls { display: grid; grid-template-columns: repeat(auto-fill, minmax(52px, 1fr)); gap: 12px 6px; }
.lesson-ball { display: flex; flex-direction: column; align-items: center; gap: 4px; background: none; border: 0; padding: 2px;
  cursor: pointer; -webkit-touch-callout: none; user-select: none; -webkit-user-select: none; touch-action: manipulation; }
.lball { width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: .95rem;
  border: 2px dashed #b9bfc4; color: var(--muted, #6b7378); background: transparent; transition: transform .12s, background .12s; }
.lesson-ball:active .lball { transform: scale(.9); }
.lball.green { background: #2e9e5b; border: 2px solid #2e9e5b; color: #fff; }
.lball.amber { background: #f0b429; border: 2px solid #f0b429; color: #3d2a00; }
.lball.red { background: #d0382b; border: 2px solid #d0382b; color: #fff; }
.lball.purple { background: #7b5cc7; border: 2px solid #7b5cc7; color: #fff; }
.lball.overdue { border-color: #d0382b; color: #d0382b; }
.lball.today { box-shadow: 0 0 0 3px var(--card, #fff), 0 0 0 5px var(--brand); }
.lball.mini { width: 14px; height: 14px; font-size: 0; border-width: 2px; }
.lball-label { font-size: .72rem; color: var(--muted, #6b7378); }
.lesson-ball.extra .lball-label::after { content: " +"; }
.lesson-legend .row { gap: 10px 14px; }
.sheet-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: var(--card, #fff); width: 100%; max-width: 560px; border-radius: 18px 18px 0 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
  max-height: 90vh; overflow: auto; }
.sheet h2 { font-size: 1.05rem; margin: 0; }
.sheet-status { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.sheet-pick { display: flex; align-items: center; gap: 8px; min-height: 44px; padding: 8px 10px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--card, #fff); font: inherit; text-align: left; color: inherit; }
.sheet-pick.on { border: 2px solid var(--brand); font-weight: 600; }
.ball.purple { background: #7b5cc7; }
.ball.amber { background: #f0b429; }
.ball.empty { background: transparent; box-shadow: inset 0 0 0 2px #b9bfc4; }
.ball.overdue { background: transparent; box-shadow: inset 0 0 0 2px #d0382b; }
.code-input { font-size: 1.4rem; letter-spacing: .3em; text-align: center; font-variant-numeric: tabular-nums; }
img.qr { width: 220px; height: 220px; margin: 0 auto; display: block; background: #fff; padding: 6px; border-radius: 12px; }
code.secret { display: block; margin-top: 6px; padding: 8px 10px; line-height: 1.5; word-break: break-all; font-size: .95rem; user-select: all; -webkit-user-select: all; }
