:root {
  --teal: #1a6b7c;
  --teal-dark: #145a68;
  --teal-light: #e8f4f6;
  --gold: #c9a86c;
  --gold-light: #f5edd8;
  --navy: #1a2a3a;
  --white: #ffffff;
  --gray-50: #f8f9fa;
  --gray-100: #f0f2f4;
  --gray-200: #e2e6ea;
  --gray-400: #9aa5b1;
  --gray-600: #5c6b7a;
  --success: #2d8a5e;
  --warning: #d4a017;
  --danger: #c0392b;
  --info: #5b7fa6;
  --shadow: 0 4px 20px rgba(26, 42, 58, 0.08);
  --shadow-lg: 0 8px 32px rgba(26, 42, 58, 0.12);
  --radius: 16px;
  --radius-sm: 10px;
  --font: 'Tajawal', 'Segoe UI', sans-serif;
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  scroll-behavior: smooth;
}

body {
  font-family: var(--font);
  background: var(--gray-50);
  color: var(--navy);
  line-height: 1.7;
  min-height: 100vh;
  direction: rtl;
}

/* Islamic geometric pattern background */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%231a6b7c' fill-opacity='0.03'%3E%3Cpath d='M30 0l30 30-30 30L0 30z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
  pointer-events: none;
  z-index: 0;
}

/* ── Header ── */
.header {
  background: linear-gradient(135deg, var(--teal) 0%, var(--teal-dark) 100%);
  color: var(--white);
  padding: 1rem 1.25rem;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-lg);
}

.header-inner {
  max-width: 1100px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  text-decoration: none;
  color: inherit;
  flex: 1;
  min-width: 0;
}

.header-logo {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--white);
  padding: 4px;
  object-fit: contain;
  flex-shrink: 0;
}

.header-titles h1 {
  font-size: 1.1rem;
  font-weight: 800;
  line-height: 1.3;
}

.header-titles p {
  font-size: 0.78rem;
  opacity: 0.85;
}

/* ── Nav dropdown ── */
.nav-toggle {
  background: rgba(255,255,255,0.15);
  border: 1px solid rgba(255,255,255,0.3);
  color: var(--white);
  padding: 0.5rem 0.85rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-family: var(--font);
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  transition: background 0.2s;
  flex-shrink: 0;
}

.nav-toggle:hover {
  background: rgba(255,255,255,0.25);
}

.nav-toggle svg {
  width: 18px;
  height: 18px;
}

.nav-menu {
  position: absolute;
  top: calc(100% + 8px);
  left: 1.25rem;
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  min-width: 240px;
  max-height: 70vh;
  overflow-y: auto;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-8px);
  transition: all 0.25s ease;
  z-index: 200;
}

.nav-menu.open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.nav-menu-section {
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--gray-100);
}

.nav-menu-section:last-child {
  border-bottom: none;
}

.nav-menu-label {
  padding: 0.4rem 1rem;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--gray-400);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.nav-menu a {
  display: block;
  padding: 0.6rem 1rem;
  color: var(--navy);
  text-decoration: none;
  font-size: 0.92rem;
  transition: background 0.15s, color 0.15s;
}

.nav-menu a:hover,
.nav-menu a.active {
  background: var(--teal-light);
  color: var(--teal);
}

.nav-wrapper {
  position: relative;
}

/* ── Main content ── */
.main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 3rem;
  position: relative;
  z-index: 1;
}

/* ── Hero section ── */
.hero {
  text-align: center;
  padding: 2rem 1rem;
  margin-bottom: 1.5rem;
}

.hero-badge {
  display: inline-block;
  background: var(--gold-light);
  color: var(--gold);
  border: 1px solid var(--gold);
  padding: 0.3rem 1rem;
  border-radius: 50px;
  font-size: 0.82rem;
  font-weight: 600;
  margin-bottom: 0.75rem;
}

.hero h2 {
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--teal);
  margin-bottom: 0.5rem;
}

.hero p {
  color: var(--gray-600);
  font-size: 0.95rem;
  max-width: 500px;
  margin: 0 auto;
}

/* ── Stats bar ── */
.stats-bar {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.75rem;
  margin-bottom: 2rem;
}

.stat-card {
  background: var(--white);
  border-radius: var(--radius);
  padding: 1rem;
  text-align: center;
  box-shadow: var(--shadow);
  border-top: 3px solid var(--gold);
}

.stat-card .stat-num {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--teal);
}

.stat-card .stat-label {
  font-size: 0.78rem;
  color: var(--gray-600);
  margin-top: 0.2rem;
}

/* ── Student cards grid ── */
.students-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
}

.student-card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
  text-decoration: none;
  color: inherit;
  display: block;
  border: 1px solid transparent;
}

.student-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-lg);
  border-color: var(--teal-light);
}

.student-card-header {
  background: linear-gradient(135deg, var(--teal) 0%, var(--teal-dark) 100%);
  padding: 1.25rem;
  position: relative;
  overflow: hidden;
}

.student-card-header::after {
  content: '';
  position: absolute;
  bottom: -20px;
  left: -20px;
  width: 80px;
  height: 80px;
  border: 2px solid rgba(201, 168, 108, 0.3);
  border-radius: 50%;
}

.student-card-header::before {
  content: '﷽';
  position: absolute;
  top: 8px;
  left: 12px;
  font-size: 0.7rem;
  opacity: 0.4;
  color: var(--gold);
}

.student-avatar {
  width: 52px;
  height: 52px;
  background: var(--gold);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3rem;
  font-weight: 800;
  color: var(--white);
  margin-bottom: 0.6rem;
  border: 2px solid rgba(255,255,255,0.4);
}

.student-card-name {
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--white);
}

.student-card-meta {
  font-size: 0.78rem;
  color: rgba(255,255,255,0.8);
  margin-top: 0.2rem;
}

.student-card-body {
  padding: 1rem 1.25rem;
}

.student-card-stats {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.mini-stat {
  flex: 1;
  min-width: 70px;
  text-align: center;
  background: var(--gray-50);
  border-radius: var(--radius-sm);
  padding: 0.5rem;
}

.mini-stat .num {
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--teal);
}

.mini-stat .lbl {
  font-size: 0.68rem;
  color: var(--gray-600);
}

.progress-bar-wrap {
  margin-top: 0.75rem;
}

.progress-label {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--gray-600);
  margin-bottom: 0.3rem;
}

.progress-bar {
  height: 6px;
  background: var(--gray-100);
  border-radius: 50px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--teal), var(--gold));
  border-radius: 50px;
  transition: width 0.5s ease;
}

/* ── Student page ── */
.back-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  color: var(--teal);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 600;
  margin-bottom: 1.25rem;
  padding: 0.4rem 0.8rem;
  border-radius: var(--radius-sm);
  transition: background 0.15s;
}

.back-btn:hover {
  background: var(--teal-light);
}

.student-profile {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  margin-bottom: 1.5rem;
}

.profile-banner {
  background: linear-gradient(135deg, var(--teal) 0%, var(--teal-dark) 60%, #0d3d47 100%);
  padding: 2rem 1.5rem;
  position: relative;
}

.profile-banner::before {
  content: '';
  position: absolute;
  inset: 0;
  background: url("data:image/svg+xml,%3Csvg width='40' height='40' viewBox='0 0 40 40' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='%23c9a86c' fill-opacity='0.08'%3E%3Cpath d='M20 0l20 20-20 20L0 20z'/%3E%3C/g%3E%3C/svg%3E");
}

.profile-content {
  position: relative;
  display: flex;
  align-items: center;
  gap: 1.25rem;
  flex-wrap: wrap;
}

.profile-avatar {
  width: 72px;
  height: 72px;
  background: var(--gold);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.8rem;
  font-weight: 800;
  color: var(--white);
  border: 3px solid rgba(255,255,255,0.5);
  flex-shrink: 0;
}

.profile-info h2 {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--white);
}

.profile-info .profile-meta {
  color: rgba(255,255,255,0.85);
  font-size: 0.88rem;
  margin-top: 0.3rem;
}

.profile-info .profile-meta span {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  margin-left: 1rem;
}

.profile-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
  gap: 0;
  border-top: 1px solid var(--gray-100);
}

.profile-stat {
  padding: 1rem;
  text-align: center;
  border-left: 1px solid var(--gray-100);
}

.profile-stat:last-child {
  border-left: none;
}

.profile-stat .num {
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--teal);
}

.profile-stat .lbl {
  font-size: 0.75rem;
  color: var(--gray-600);
}

.progress-note {
  background: var(--gold-light);
  border-right: 4px solid var(--gold);
  padding: 0.85rem 1.25rem;
  font-size: 0.9rem;
  color: var(--navy);
}

/* ── Filter tabs ── */
.filter-tabs {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 1.25rem;
}

.filter-tab {
  padding: 0.45rem 1rem;
  border-radius: 50px;
  border: 1px solid var(--gray-200);
  background: var(--white);
  color: var(--gray-600);
  font-family: var(--font);
  font-size: 0.82rem;
  cursor: pointer;
  transition: all 0.2s;
}

.filter-tab:hover {
  border-color: var(--teal);
  color: var(--teal);
}

.filter-tab.active {
  background: var(--teal);
  color: var(--white);
  border-color: var(--teal);
}

/* ── Timeline / Records list ── */
.records-section h3 {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--teal);
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.records-section h3::before {
  content: '';
  width: 4px;
  height: 20px;
  background: var(--gold);
  border-radius: 2px;
}

.records-list {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.record-item {
  background: var(--white);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  display: flex;
  align-items: stretch;
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
  border: 1px solid transparent;
}

.record-item:hover {
  transform: translateX(-3px);
  box-shadow: var(--shadow-lg);
  border-color: var(--teal-light);
}

.record-date {
  min-width: 90px;
  padding: 0.85rem 0.75rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--gray-50);
  border-left: 3px solid var(--teal);
  flex-shrink: 0;
}

.record-date .day {
  font-size: 1.3rem;
  font-weight: 800;
  color: var(--teal);
  line-height: 1;
}

.record-date .month {
  font-size: 0.72rem;
  color: var(--gray-600);
  margin-top: 0.15rem;
}

.record-date .weekday {
  font-size: 0.68rem;
  color: var(--gray-400);
}

.record-body {
  flex: 1;
  padding: 0.85rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  min-width: 0;
}

.record-content {
  flex: 1;
  min-width: 0;
}

.record-text {
  font-size: 0.9rem;
  color: var(--navy);
  word-break: break-word;
}

.record-badges {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  flex-shrink: 0;
}

.record-badge {
  display: inline-block;
  padding: 0.2rem 0.6rem;
  border-radius: 50px;
  font-size: 0.72rem;
  font-weight: 600;
  white-space: nowrap;
  flex-shrink: 0;
}

.badge-recitation {
  background: var(--teal-light);
  color: var(--teal);
}

.badge-test {
  background: var(--gold-light);
  color: #8a6d2f;
}

.badge-absence-student {
  background: #fdecea;
  color: var(--danger);
}

.badge-absence-teacher {
  background: #eaf0f8;
  color: var(--info);
}

.record-item.type-absence-student {
  opacity: 0.75;
}

.record-item.type-absence-student .record-date {
  border-left-color: var(--danger);
}

.record-item.type-absence-teacher .record-date {
  border-left-color: var(--info);
}

.record-item.type-test .record-date {
  border-left-color: var(--gold);
}

.record-item.type-both .record-date {
  border-left: 3px solid transparent;
  border-image: linear-gradient(to bottom, var(--teal), var(--gold)) 1;
}

.legend-dot-both {
  background: linear-gradient(135deg, var(--teal) 50%, var(--gold) 50%);
}

.modal-badges {
  margin-bottom: 1rem;
}

.modal-badges .record-badges {
  flex-direction: row;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.modal-detail.is-both {
  border-right: 4px solid var(--teal);
  border-image: linear-gradient(to bottom, var(--teal), var(--gold)) 1;
  border-image-slice: 1;
}

.record-chevron {
  color: var(--gray-400);
  flex-shrink: 0;
}

/* ── Modal ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(26, 42, 58, 0.5);
  z-index: 300;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s;
  backdrop-filter: blur(4px);
}

.modal-overlay.open {
  opacity: 1;
  visibility: visible;
}

.modal {
  background: var(--white);
  border-radius: var(--radius) var(--radius) 0 0;
  width: 100%;
  max-width: 500px;
  max-height: 80vh;
  overflow-y: auto;
  transform: translateY(100%);
  transition: transform 0.3s ease;
  box-shadow: 0 -8px 40px rgba(0,0,0,0.15);
}

.modal-overlay.open .modal {
  transform: translateY(0);
}

.modal-header {
  background: linear-gradient(135deg, var(--teal), var(--teal-dark));
  color: var(--white);
  padding: 1.25rem 1.5rem;
  position: relative;
}

.modal-header h3 {
  font-size: 1.1rem;
  font-weight: 700;
}

.modal-header .modal-date {
  font-size: 0.85rem;
  opacity: 0.85;
  margin-top: 0.2rem;
}

.modal-close {
  position: absolute;
  top: 1rem;
  left: 1rem;
  background: rgba(255,255,255,0.2);
  border: none;
  color: var(--white);
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}

.modal-close:hover {
  background: rgba(255,255,255,0.35);
}

.modal-body {
  padding: 1.5rem;
}

.modal-type-badge {
  display: inline-block;
  padding: 0.3rem 0.85rem;
  border-radius: 50px;
  font-size: 0.8rem;
  font-weight: 600;
  margin-bottom: 1rem;
}

.modal-detail {
  font-size: 1rem;
  line-height: 1.8;
  color: var(--navy);
  background: var(--gray-50);
  padding: 1rem 1.25rem;
  border-radius: var(--radius-sm);
  border-right: 4px solid var(--teal);
}

.modal-detail.is-absence {
  border-right-color: var(--danger);
  color: var(--danger);
  text-align: center;
  font-weight: 600;
}

.modal-detail.is-teacher {
  border-right-color: var(--info);
  color: var(--info);
}

/* ── Legend ── */
.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
  padding: 0.85rem 1rem;
  background: var(--white);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.78rem;
  color: var(--gray-600);
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

/* ── Footer ── */
.footer {
  text-align: center;
  padding: 2rem 1rem;
  color: var(--gray-400);
  font-size: 0.82rem;
  position: relative;
  z-index: 1;
}

.footer .mosque-name {
  color: var(--gold);
  font-weight: 600;
}

/* ── Responsive ── */
@media (min-width: 640px) {
  .modal-overlay {
    align-items: center;
  }

  .modal {
    border-radius: var(--radius);
    max-height: 70vh;
    transform: translateY(20px) scale(0.95);
  }

  .modal-overlay.open .modal {
    transform: translateY(0) scale(1);
  }

  .hero h2 {
    font-size: 2rem;
  }

  .header-logo {
    width: 56px;
    height: 56px;
  }

  .header-titles h1 {
    font-size: 1.3rem;
  }
}

@media (max-width: 480px) {
  .stats-bar {
    grid-template-columns: 1fr;
  }

  .record-date {
    min-width: 72px;
    padding: 0.7rem 0.5rem;
  }

  .record-date .day {
    font-size: 1.1rem;
  }

  .profile-content {
    flex-direction: column;
    text-align: center;
  }

  .profile-info .profile-meta span {
    display: block;
    margin: 0.2rem 0;
  }
}

/* ── Animations ── */
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}

.student-card,
.record-item,
.stat-card {
  animation: fadeInUp 0.4s ease both;
}

.students-grid .student-card:nth-child(2) { animation-delay: 0.05s; }
.students-grid .student-card:nth-child(3) { animation-delay: 0.1s; }
.students-grid .student-card:nth-child(4) { animation-delay: 0.15s; }
.students-grid .student-card:nth-child(5) { animation-delay: 0.2s; }
.students-grid .student-card:nth-child(6) { animation-delay: 0.25s; }
.students-grid .student-card:nth-child(7) { animation-delay: 0.3s; }
.students-grid .student-card:nth-child(8) { animation-delay: 0.35s; }
.students-grid .student-card:nth-child(9) { animation-delay: 0.4s; }
.students-grid .student-card:nth-child(10) { animation-delay: 0.45s; }

.hidden {
  display: none !important;
}
