/* ---------- Charts & meters ---------- */
.chart {
  width: 100%;
  height: 160px;
  display: block;
}

.chart-figure { margin: 0; }

.chart__empty { color: var(--muted); font-size: var(--text-body); margin: 0; }

.meter {
  height: 10px;
  background: var(--surface-soft);
  border-radius: var(--radius-pill);
  overflow: clip;
}

.meter__fill {
  width: 0;
  height: 100%;
  background: var(--brand);
  border-radius: var(--radius-pill);
  transition: width var(--duration) var(--ease);
}
.meter--info .meter__fill { background: var(--info); }
.meter--warning .meter__fill { background: var(--warning); }
.meter--danger .meter__fill { background: var(--danger); }
.meter--accent .meter__fill { background: var(--accent); }

/* ---------- Certificates ---------- */
.certificate-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
}

.certificate-card {
  display: flex;
  flex-direction: column;
  min-height: 270px;
  text-decoration: none;
  color: inherit;
  background:
    linear-gradient(180deg, color-mix(in srgb, var(--accent-light) 68%, transparent), color-mix(in srgb, var(--surface) 82%, transparent) 42%),
    var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem 1.25rem;
  text-align: center;
  box-shadow: var(--shadow-sm);
  transition: transform var(--duration) var(--ease), box-shadow var(--duration) var(--ease), border-color var(--duration) var(--ease);
}
.certificate-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); border-color: var(--warning-border); text-decoration: none; }
.certificate-card__seal {
  width: 58px;
  height: 58px;
  display: grid;
  place-items: center;
  align-self: center;
  color: var(--warning);
  background: var(--surface);
  border: 1px solid var(--warning-border);
  border-radius: 50%;
  box-shadow: var(--shadow-sm);
  font-size: var(--text-display);
}
.certificate-card__seal .app-icon {
  width: 1.55rem;
  height: 1.55rem;
}
.certificate-card__type { color: var(--brand); font-weight: 700; font-size: var(--text-small); margin-top: .375rem; }
.certificate-card__title { overflow-wrap: anywhere; font-weight: 800; margin-top: .25rem; }
.certificate-card__student { color: var(--ink); margin-top: .375rem; }
.certificate-card__date { color: var(--muted); font-size: var(--text-small); margin-top: .5rem; }
.certificate-card__actions {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: .5rem;
  margin-top: auto;
  padding-top: 1rem;
}

.certificate { max-width: 640px; margin: 0 auto; }
.certificate__border {
  border: 3px double var(--brand);
  border-radius: var(--radius-lg);
  padding: 2.5rem 2rem;
  text-align: center;
  background:
    radial-gradient(600px 200px at 50% -10%, color-mix(in srgb, var(--success) 8%, transparent), transparent 70%),
    var(--surface);
  box-shadow: var(--shadow);
}
.certificate__seal {
  display: inline-grid;
  place-items: center;
  color: var(--warning);
  font-size: 3rem;
}
.certificate__seal .app-icon {
  width: 2.65rem;
  height: 2.65rem;
}
.certificate__eyebrow { color: var(--brand); font-weight: 700; margin: .5rem 0 0; }
.certificate__title { font-size: 1.6rem; font-weight: 800; margin: .5rem 0 1.5rem; }
.certificate__awarded { color: var(--muted); margin: 0; }
.certificate__student { font-size: 1.4rem; font-weight: 800; color: var(--ink); margin: .25rem 0; }
.certificate__reference { color: var(--brand-dark); font-weight: 600; margin: .25rem 0; }
.certificate__desc { color: var(--ink); margin: 1rem 0 0; }
.certificate__footer {
  display: flex; justify-content: space-between; gap: 1rem;
  margin-top: 2rem; color: var(--muted); font-size: .85rem;
}

/* ---------- Leaderboard ---------- */
.leaderboard-summary {
  display: grid;
  --grid-min: 180px;
  gap: .75rem;
  margin-bottom: 1rem;
}

.leaderboard-summary__item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
  min-height: 68px;
  padding: .75rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

.leaderboard-summary__item span { color: var(--muted); font-size: var(--text-small); font-weight: 700; }
.leaderboard-summary__item strong { color: var(--ink); font-size: var(--text-subtitle); }

.podium {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
  margin-bottom: 1rem;
}
.podium__place {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1rem;
  text-align: center;
  box-shadow: var(--shadow-sm);
}
.podium__place--1 { border-color: var(--warning-border); background: linear-gradient(180deg,var(--accent-light),var(--surface)); transform: translateY(-6px); }
.podium__place--2 { border-color: var(--border); }
.podium__place--3 { border-color: var(--warning-border); }
.podium__medal { display: flex; justify-content: center; }
.podium__medal .rank-medal { width: 2.75rem; height: 2.75rem; font-size: var(--text-subtitle); }

/* ---------- Rank medal ---------- */
.rank-medal {
  display: inline-grid;
  place-items: center;
  width: 1.75rem;
  height: 1.75rem;
  border: 1px solid var(--border-strong);
  border-radius: 50%;
  color: var(--muted);
  background: var(--surface-soft);
  font: 700 var(--text-small)/1 var(--font-display);
  font-variant-numeric: tabular-nums;
}
.rank-medal--1 { color: var(--accent-ink); background: var(--accent-light); border-color: var(--accent); }
.rank-medal--2 { color: var(--ink); background: var(--surface); border-color: var(--muted); }
.rank-medal--3 { color: var(--warning); background: var(--warning-bg); border-color: var(--warning-border); }
.rank-medal--4 { border-color: transparent; background: transparent; }
.podium__name { display: block; font-weight: 800; margin-top: .25rem; color: var(--ink); text-decoration: none; }
.podium__name:hover { color: var(--brand); text-decoration: none; }
.podium__meta { color: var(--muted); font-size: var(--text-small); margin-top: .125rem; }
.podium__halaqah { color: var(--muted); text-decoration: none; }
.podium__halaqah:hover { color: var(--brand); text-decoration: none; }
.podium__points { color: var(--brand); font-weight: 700; font-size: var(--text-body); margin-top: .25rem; }

.leaderboard-row--1 td { background: var(--accent-light); }
.leaderboard-row--2 td { background: var(--surface-soft); }
.leaderboard-row--3 td { background: var(--warning-bg); }
.leaderboard-row__student { color: var(--ink); font-weight: 800; text-decoration: none; }
.leaderboard-row__student:hover { color: var(--brand); text-decoration: none; }
.leaderboard-row__halaqah { color: var(--ink); text-decoration: none; }
.leaderboard-row__halaqah:hover { color: var(--brand); text-decoration: none; }
.badge-icon {
  width: 1.5rem;
  height: 1.5rem;
  display: inline-grid;
  place-items: center;
  margin-inline-end: .25rem;
  color: var(--brand);
  background: var(--brand-light);
  border-radius: var(--radius-pill);
  vertical-align: middle;
}

.badge-icon .app-icon {
  width: .9rem;
  height: .9rem;
}

.badge-tile__icon {
  display: grid;
  place-items: center;
  color: var(--brand);
}

.badge-tile__icon .app-icon {
  width: 1.55rem;
  height: 1.55rem;
}

/* ---------- Student progress ---------- */
.progress-summary { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 1rem; }
.progress-summary__label { color: var(--muted); font-size: var(--text-small); }
.progress-summary__points { color: var(--brand); font-size: var(--text-display); font-weight: 800; }
.progress-badges, .progress-certificates { display: flex; flex-wrap: wrap; gap: .5rem; }
.progress-badge { min-width: 80px; padding: .5rem .75rem; text-align: center; background: var(--surface-soft); border: 1px solid var(--border); border-radius: var(--radius); }
.progress-badge__name { margin-top: .25rem; font-size: var(--text-label); font-weight: 700; }
.progress-stats, .progress-chart-card, .progress-target-form { margin-top: 1rem; }
.progress-target-form .btn { min-height: 40px; }
.progress-section__title { margin: 0 0 .75rem; font-size: var(--text-lead); }
.progress-section__title--spacious { margin-bottom: 1rem; }
.progress-error-row { display: flex; align-items: center; gap: .75rem; margin-bottom: .5rem; }
.progress-error-row:last-child { margin-bottom: 0; }
.progress-error-row__label { flex: 0 0 90px; color: var(--ink); font-size: var(--text-body); }
.progress-error-row__meter { flex: 1; min-width: 0; }
.progress-error-row__count { flex: 0 0 32px; text-align: end; font-weight: 700; }
.progress-attendance { display: grid; --grid-min: 120px; gap: .5rem; }
.progress-attendance__item { display: flex; flex-direction: column; gap: .375rem; align-items: flex-start; }
.progress-attendance__count { font-size: var(--text-subtitle); font-weight: 800; }
.progress-certificate { text-decoration: none; }
.progress-certificate:hover { text-decoration: none; }
.plan-section { margin-top: 1rem; }
.plan-card { display: grid; gap: 1rem; padding: 1rem; background: var(--surface-soft); border: 1px solid var(--border); border-radius: var(--radius); }
.plan-card__head { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; }
.plan-card__head > div { display: grid; gap: .25rem; }
.plan-card__head span, .plan-card__metrics span, .plan-history__item span { color: var(--muted); font-size: var(--text-small); }
.plan-progress { width: 100%; height: .65rem; overflow: clip; appearance: none; background: var(--border); border: 0; border-radius: var(--radius-pill); }
.plan-progress::-webkit-progress-bar { background: var(--border); border-radius: var(--radius-pill); }
.plan-progress::-webkit-progress-value { background: linear-gradient(90deg, var(--brand), var(--accent)); border-radius: var(--radius-pill); }
.plan-progress::-moz-progress-bar { background: linear-gradient(90deg, var(--brand), var(--accent)); border-radius: var(--radius-pill); }
.plan-card__metrics { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: .5rem; }
.plan-card__metrics div { display: grid; padding: .75rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.plan-card__metrics strong { color: var(--brand); font-size: var(--text-heading); }
.plan-card__notes { margin: 0; white-space: pre-wrap; }
.plan-card__actions { display: flex; flex-wrap: wrap; gap: .5rem; }
.plan-form { margin-top: .75rem; padding-top: 1rem; border-top: 1px solid var(--border); }
.plan-history { margin-top: 1rem; border-top: 1px solid var(--border); padding-top: .75rem; }
.plan-history summary { cursor: pointer; color: var(--brand); font-weight: 800; }
.plan-history__list { display: grid; margin-top: .5rem; }
.plan-history__item { display: flex; align-items: center; gap: .75rem; padding: .75rem 0; border-bottom: 1px solid var(--border); }
.plan-history__item:last-child { border-bottom: 0; }
.plan-history__item > div:first-child { display: grid; flex: 1; min-width: 0; }
@media (max-width: 640px) {
  .plan-card__head, .plan-history__item { align-items: stretch; flex-direction: column; }
  .plan-card__metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .plan-card__actions .button_to, .plan-card__actions .btn { width: 100%; }
}
.progress-health { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 1rem; align-items: center; margin-top: 1rem; padding: 1rem 1.25rem; background: var(--surface); border: 1px solid var(--border); border-inline-start: 4px solid var(--brand); border-radius: var(--radius); box-shadow: var(--shadow-sm); }
.progress-health__title { margin: 0; font-size: var(--text-lead); }
.progress-health__hint, .progress-section__hint { margin: .25rem 0 0; color: var(--muted); font-size: var(--text-small); }
.progress-health__status { display: flex; align-items: center; flex-wrap: wrap; gap: .5rem; }
.progress-health__followups { min-width: 90px; text-align: center; }
.progress-health__followups strong { display: block; color: var(--brand); font-size: var(--text-title); }
.progress-health__followups span { color: var(--muted); font-size: var(--text-label); }
.intervention-list { display: grid; gap: .75rem; margin-top: 1rem; }
.intervention { display: flex; gap: .75rem; align-items: center; padding: .75rem; background: var(--surface-soft); border: 1px solid var(--border); border-radius: var(--radius); }
.intervention--resolved { opacity: .72; }
.intervention__body { flex: 1; min-width: 0; }
.intervention__body p { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.intervention__meta { margin-top: .25rem; color: var(--muted); font-size: var(--text-label); }
@media (max-width: 640px) {
  .progress-health { grid-template-columns: 1fr; align-items: start; }
  .progress-health__followups { text-align: start; }
  .progress-health__followups strong { display: inline; margin-inline-end: .25rem; }
  .intervention { align-items: stretch; flex-direction: column; }
}
.muted-text { color: var(--muted); }

/* ---------- Notifications ---------- */
.notifications-actions {
  display: inline-flex;
  align-items: center;
}
.notifications-toolbar {
  display: grid;
  grid-template-columns: minmax(220px, 2fr) repeat(2, minmax(150px, 1fr)) auto;
}
.notifications-toolbar .field,
.notifications-toolbar .field--grow {
  min-width: 0;
}
.notifications-toolbar .toolbar__input,
.notifications-toolbar .btn {
  min-height: 44px;
}
.notifications-card {
  overflow: clip;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.notif-list { list-style: none; margin: 0; padding: 0; }
.notif-list:empty { display: none; }
.notif {
  display: grid;
  grid-template-areas: "icon body action";
  grid-template-columns: 42px minmax(0, 1fr) auto;
  align-items: flex-start;
  gap: 1rem;
  padding: .75rem 1rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  transition: background var(--duration) var(--ease);
}
.notif--selectable {
  grid-template-areas: "select icon body action";
  grid-template-columns: 44px 42px minmax(0, 1fr) auto;
}
.notif:last-child { border-bottom: none; }
.notif:hover { background: var(--surface-soft); }
.notif--unread {
  background: var(--brand-light);
  border-inline-start: 4px solid var(--brand);
}
.notif__select {
  grid-area: select;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: var(--radius);
  cursor: pointer;
}
.notif__select:hover { background: color-mix(in srgb, var(--brand) 8%, transparent); }
.notif__select:has(input:focus-visible) {
  outline: 3px solid color-mix(in srgb, var(--brand) 24%, transparent);
  outline-offset: 1px;
}
.notif__select input,
.notifications-bulk__select input {
  width: 1.15rem;
  height: 1.15rem;
  accent-color: var(--brand);
}
.notif__icon {
  grid-area: icon;
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  display: grid;
  place-items: center;
  background: var(--brand-light);
  border: 1px solid var(--brand-light);
  border-radius: var(--radius);
  font-size: var(--text-subtitle);
  line-height: 1;
}
.notif__icon .app-icon {
  width: 1.18rem;
  height: 1.18rem;
}
.notif__body { grid-area: body; min-width: 0; }
.notif__meta {
  display: flex;
  align-items: center;
  gap: .5rem;
  flex-wrap: wrap;
  margin-bottom: .125rem;
}
.notif__dot {
  display: inline-flex;
  align-items: center;
  gap: .25rem;
  color: var(--brand-dark);
  font-size: var(--text-label);
  font-weight: 800;
}
.notif__dot::before {
  content: "";
  width: .42rem;
  height: .42rem;
  background: var(--brand);
  border-radius: var(--radius-pill);
}
.notif__title { overflow-wrap: anywhere; font-weight: 800; line-height: 1.35; }
.notif__text { max-width: 70ch; margin-top: .125rem; color: var(--ink); font-size: var(--text-body); overflow-wrap: anywhere; white-space: pre-wrap; }
.notif__time { margin-top: .375rem; color: var(--muted); font-size: var(--text-label); overflow-wrap: anywhere; }
.notif__action { grid-area: action; min-width: 0; }
.notif__action,
.notif__action .button_to,
.notif__action .btn,
.notif__action .btn:hover { text-decoration: none; }
.message-thread { display: flex; flex-direction: column; gap: 1rem; }
.message-thread__list {
  list-style: none;
  margin: 0;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: .75rem;
  max-height: 60vh;
  overflow-y: auto;
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.message-bubble {
  max-width: 70%;
  padding: .5rem .75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}
.message-bubble--mine {
  align-self: flex-end;
  background: var(--brand-light);
  border-color: var(--brand-light);
}
.message-bubble__meta {
  display: flex;
  align-items: baseline;
  gap: .5rem;
  margin-bottom: .25rem;
  font-size: var(--text-label);
  color: var(--muted);
}
.message-bubble__meta strong { color: var(--ink); font-weight: 750; }
.message-bubble__body { margin: 0; overflow-wrap: anywhere; }
.message-bubble__body > p { margin: 0; }
.message-bubble__body > p + p { margin-block-start: .5rem; }
.message-thread__list:has(.message-bubble) + .message-thread__empty { display: none; }
.message-thread__list:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.message-thread__composer {
  display: flex;
  gap: .5rem;
  align-items: flex-end;
}
.message-thread__composer .input { flex: 1; min-height: 44px; resize: vertical; }

.notif-live {
  margin-bottom: 1rem;
  padding: 1rem;
  background:
    linear-gradient(135deg, color-mix(in srgb, var(--brand) 10%, transparent), color-mix(in srgb, var(--accent) 10%, transparent)),
    var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.notif-live__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: .75rem;
}
.notif-live__label {
  color: var(--brand);
  font-size: var(--text-label);
  font-weight: 800;
}
.notif-live__title {
  margin-top: .125rem;
  font-weight: 800;
}
.notif-live__items {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: .75rem;
}
.notif-live__item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .5rem .75rem;
  font: inherit;
  color: var(--ink);
  text-align: start;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  box-shadow: var(--shadow-sm);
}
.notif-live__item:hover {
  border-color: var(--brand-border);
  background: var(--brand-light);
  text-decoration: none;
}
.notif-live__item .button_to,
.notif-live__item:hover .button_to { text-decoration: none; }
.notif-live__icon {
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  display: grid;
  place-items: center;
  background: var(--accent-light);
  border-radius: var(--radius);
}
.notif-live__icon .app-icon {
  width: 1.05rem;
  height: 1.05rem;
}
.notif-live__copy {
  min-width: 0;
  display: grid;
  gap: .125rem;
}
.notif-live__item-title {
  overflow: hidden;
  color: var(--ink);
  font-size: var(--text-body);
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.notif-live__time {
  color: var(--muted);
  font-size: var(--text-label);
}
.notif-live__empty {
  margin: 0;
  color: var(--muted);
}
.notifications-bulk {
  justify-content: space-between;
  margin: .75rem;
}
.notifications-bulk__select {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  gap: .5rem;
  padding-inline: .25rem;
  border-radius: var(--radius);
  cursor: pointer;
  font-weight: 700;
}
.notifications-bulk__select:has(input:focus-visible) {
  outline: 3px solid color-mix(in srgb, var(--brand) 24%, transparent);
  outline-offset: 1px;
}
.notifications-bulk__count {
  flex: 1 1 auto;
  min-width: 0;
  color: var(--brand-dark);
  font-size: var(--text-small);
  font-weight: 700;
}


/* ---------- Avatar ---------- */
.avatar {
  display: grid;
  flex: none;
  place-items: center;
  width: 36px;
  height: 36px;
  color: var(--brand-dark);
  background: var(--brand-light);
  border-radius: 50%;
  font: 700 var(--text-small)/1 var(--font-display);
}

/* ---------- Attendance bar ---------- */
.attendance-bar { display: grid; gap: .25rem; max-width: 22rem; margin-top: .5rem; }
.attendance-bar__track { display: block; width: 100%; height: 6px; overflow: clip; border-radius: var(--radius-pill); background: var(--surface-soft); }
[dir="rtl"] .attendance-bar__track { transform: scaleX(-1); }
.attendance-bar__segment--present { fill: var(--brand); }
.attendance-bar__segment--late { fill: var(--warning); }
.attendance-bar__segment--excused { fill: var(--info); }
.attendance-bar__segment--absent { fill: var(--danger); }
.attendance-bar__summary { margin: .5rem 0 0; color: var(--muted); font-size: var(--text-label); }
.attendance-bar .attendance-bar__summary { margin: 0; }

/* ---------- Juz' map (memorization coverage) ---------- */
.juz-map__grid {
  display: grid;
  grid-template-columns: repeat(10, minmax(0, 1fr));
  gap: 4px;
  max-width: 30rem;
  margin: .75rem 0 0;
  padding: 0;
  list-style: none;
}
.juz-map__cell {
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  max-width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font: 600 var(--text-label)/1 var(--font-display);
  font-variant-numeric: tabular-nums;
}
.juz-map__cell--complete { color: var(--on-brand); background: var(--brand); border-color: var(--brand); }
.juz-map__cell--in-progress { color: var(--accent-ink); background: var(--accent-light); border-color: var(--accent); }
.juz-map__cell--not-started { color: var(--muted); background: var(--surface-soft); }
.juz-map__legend { display: flex; flex-wrap: wrap; gap: .375rem 1rem; margin: .75rem 0 0; padding: 0; list-style: none; color: var(--muted); font-size: var(--text-label); }
.juz-map__legend li { display: inline-flex; align-items: center; gap: .375rem; }
.juz-map__swatch { display: inline-block; width: .75rem; height: .75rem; border: 1px solid var(--border); border-radius: calc(var(--radius-sm) / 2); }
@media (max-width: 480px) {
  .juz-map__grid { grid-template-columns: repeat(6, minmax(0, 1fr)); }
}
