/* ============================================================
   Al Irshaad Academy SMS — Frontend Design System
   ============================================================ */

:root {
  --green:      #1B4332;
  --green-mid:  #2D6A4F;
  --green-lt:   #4A7C59;
  --green-pale: #D8F3DC;
  --green-xpale:#EBF5EE;
  --gold:       #C9972C;
  --gold-lt:    #F0D080;
  --gold-dark:  #A97820;
  --ivory:      #F9F5EE;
  --ivory-dark: #F0EAD6;
  --slate:      #334155;
  --slate-lt:   #64748B;
  --soft-grey:  #6B7280;
  --line-grey:  #E2E8F0;
  --white:      #FFFFFF;
  --danger:     #DC2626;
  --warning:    #F59E0B;
  --info:       #0D7377;
  --sidebar-w:  260px;
  --header-h:   64px;
  --radius:     8px;
  --shadow-sm:  0 1px 3px rgba(0,0,0,.1);
  --shadow-md:  0 4px 12px rgba(0,0,0,.12);
  --shadow-lg:  0 8px 24px rgba(0,0,0,.14);
  --transition: 0.2s ease;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 14px; scroll-behavior: smooth; }

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--ivory);
  color: var(--slate);
  line-height: 1.6;
  min-height: 100vh;
}

/* ── Auth / Login ────────────────────────────────────────── */
.auth-page {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1fr 1fr;
}
.auth-brand {
  background: var(--green);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 3rem;
  gap: 1.5rem;
}
.auth-brand img { width: 100px; border-radius: 50%; }
.auth-brand h1 { color: var(--gold-lt); font-size: 1.8rem; text-align: center; }
.auth-brand p  { color: #A5C8A0; font-size: .9rem; text-align: center; line-height: 1.7; }
.auth-brand .school-meta { color: #7BAE8A; font-size: .8rem; text-align: center; }

.auth-form-area {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 3rem;
  background: var(--white);
}
.auth-card {
  width: 100%;
  max-width: 420px;
}
.auth-card h2 { color: var(--green); font-size: 1.6rem; margin-bottom: .4rem; }
.auth-card .sub { color: var(--soft-grey); font-size: .9rem; margin-bottom: 2rem; }

/* ── Layout Shell ─────────────────────────────────────────── */
.app-shell { display: none; }
.app-shell.visible { display: flex; height: 100vh; overflow: hidden; }

.sidebar {
  width: var(--sidebar-w);
  background: var(--green);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  flex-shrink: 0;
  transition: transform var(--transition);
}
.sidebar-brand {
  padding: 1.5rem 1.2rem 1rem;
  border-bottom: 1px solid rgba(255,255,255,.1);
  display: flex;
  align-items: center;
  gap: .8rem;
}
.sidebar-brand img { width: 42px; border-radius: 50%; }
.sidebar-brand .name { color: var(--gold-lt); font-weight: 700; font-size: .95rem; line-height: 1.3; }
.sidebar-brand .sub  { color: #A5C8A0; font-size: .72rem; }

.sidebar-section {
  padding: .6rem 1rem .2rem;
  font-size: .68rem;
  font-weight: 700;
  color: #7BAE8A;
  letter-spacing: .08em;
  text-transform: uppercase;
  margin-top: .5rem;
}

.sidebar-nav { padding: .4rem 0; flex: 1; }
.nav-item {
  display: flex;
  align-items: center;
  gap: .7rem;
  padding: .6rem 1.2rem;
  color: #A5C8A0;
  cursor: pointer;
  border-left: 3px solid transparent;
  transition: all var(--transition);
  font-size: .88rem;
  text-decoration: none;
}
.nav-item:hover  { color: var(--white); background: rgba(255,255,255,.06); }
.nav-item.active { color: var(--gold-lt); background: rgba(201,151,44,.1);
                   border-left-color: var(--gold); }
.nav-item .icon { font-size: 1rem; width: 20px; text-align: center; }
.nav-badge {
  margin-left: auto;
  background: var(--gold);
  color: var(--green);
  font-size: .65rem;
  font-weight: 700;
  padding: .1rem .45rem;
  border-radius: 999px;
}

.sidebar-footer {
  padding: 1rem 1.2rem;
  border-top: 1px solid rgba(255,255,255,.1);
}
.user-chip {
  display: flex;
  align-items: center;
  gap: .6rem;
  color: #A5C8A0;
  font-size: .82rem;
}
.user-chip .avatar {
  width: 32px; height: 32px;
  background: var(--green-mid);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: var(--gold-lt); font-weight: 700; font-size: .8rem;
  flex-shrink: 0;
}
.user-chip .info .name { color: var(--white); font-weight: 600; font-size: .84rem; }
.user-chip .info .role { color: var(--soft-grey); font-size: .72rem; }
.logout-btn {
  margin-left: auto;
  background: none;
  border: none;
  color: var(--soft-grey);
  cursor: pointer;
  font-size: 1rem;
  padding: .2rem;
  transition: color var(--transition);
}
.logout-btn:hover { color: var(--danger); }

/* ── Main content ─────────────────────────────────────────── */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.topbar {
  height: var(--header-h);
  background: var(--white);
  border-bottom: 1px solid var(--line-grey);
  display: flex;
  align-items: center;
  padding: 0 1.5rem;
  gap: 1rem;
  flex-shrink: 0;
}
.topbar .page-title { font-size: 1.15rem; font-weight: 700; color: var(--green); flex: 1; }
.topbar .term-badge {
  background: var(--green-xpale);
  color: var(--green-mid);
  font-size: .75rem;
  font-weight: 600;
  padding: .25rem .7rem;
  border-radius: 999px;
}

.page-body {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem;
}

/* ── Pages: sections ─────────────────────────────────────── */
.page-section { display: none; }
.page-section.active { display: block; }

/* ── Cards ───────────────────────────────────────────────── */
.card {
  background: var(--white);
  border-radius: var(--radius);
  border: 1px solid var(--line-grey);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.card-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--line-grey);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .8rem;
}
.card-header h3 { font-size: .95rem; font-weight: 700; color: var(--green); }
.card-body { padding: 1.25rem; }

/* ── Stat cards ──────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.stat-card {
  background: var(--white);
  border-radius: var(--radius);
  padding: 1.2rem 1.25rem;
  border: 1px solid var(--line-grey);
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: flex-start;
  gap: 1rem;
}
.stat-card .icon-box {
  width: 44px; height: 44px;
  border-radius: var(--radius);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.3rem;
  flex-shrink: 0;
}
.stat-card .value  { font-size: 1.6rem; font-weight: 800; color: var(--slate); line-height: 1; }
.stat-card .label  { font-size: .78rem; color: var(--soft-grey); margin-top: .25rem; }
.stat-card .change { font-size: .72rem; font-weight: 600; margin-top: .3rem; }
.stat-card .change.up   { color: var(--green-mid); }
.stat-card .change.down { color: var(--danger); }

.icon-box.green  { background: var(--green-xpale); color: var(--green); }
.icon-box.gold   { background: #FEF3C7; color: var(--gold-dark); }
.icon-box.info   { background: #E0F4F7; color: var(--info); }
.icon-box.danger { background: #FEE2E2; color: var(--danger); }

/* ── Tables ──────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table {
  width: 100%;
  border-collapse: collapse;
  font-size: .85rem;
}
thead th {
  background: var(--green);
  color: var(--gold-lt);
  font-weight: 700;
  padding: .65rem .8rem;
  text-align: left;
  font-size: .78rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  position: sticky;
  top: 0;
}
tbody tr { border-bottom: 1px solid var(--line-grey); transition: background var(--transition); }
tbody tr:hover { background: var(--green-xpale); }
tbody tr:last-child { border-bottom: none; }
td { padding: .6rem .8rem; color: var(--slate); }
td.mono { font-family: 'Courier New', monospace; font-size: .82rem; color: var(--green-mid); }

/* ── Badges / Pills ──────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: .18rem .6rem;
  border-radius: 999px;
  font-size: .7rem;
  font-weight: 700;
  letter-spacing: .02em;
}
.badge-green   { background: var(--green-xpale); color: var(--green); }
.badge-gold    { background: #FEF3C7; color: var(--gold-dark); }
.badge-blue    { background: #EFF6FF; color: #1D4ED8; }
.badge-red     { background: #FEE2E2; color: var(--danger); }
.badge-grey    { background: var(--line-grey); color: var(--soft-grey); }
.badge-teal    { background: #E0F4F7; color: var(--info); }
.badge-amber   { background: #FEF3C7; color: #B45309; }

/* ── Forms ───────────────────────────────────────────────── */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1rem;
}
.form-group { display: flex; flex-direction: column; gap: .3rem; }
.form-group label { font-size: .8rem; font-weight: 600; color: var(--green); }
.form-group input,
.form-group select,
.form-group textarea {
  border: 1.5px solid var(--line-grey);
  border-radius: var(--radius);
  padding: .55rem .75rem;
  font-size: .88rem;
  color: var(--slate);
  background: var(--white);
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
  font-family: inherit;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  border-color: var(--green-mid);
  box-shadow: 0 0 0 3px rgba(45,106,79,.12);
}
.form-group textarea { resize: vertical; min-height: 80px; }
.form-group.full { grid-column: 1 / -1; }
.form-hint { font-size: .74rem; color: var(--soft-grey); }

/* ── Buttons ─────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: .5rem 1rem;
  border-radius: var(--radius);
  font-size: .85rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all var(--transition);
  text-decoration: none;
  white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn-primary  { background: var(--green); color: var(--white); }
.btn-primary:hover  { background: var(--green-mid); }
.btn-gold     { background: var(--gold); color: var(--green); }
.btn-gold:hover { background: var(--gold-dark); }
.btn-outline  { background: transparent; border: 1.5px solid var(--green); color: var(--green); }
.btn-outline:hover { background: var(--green-xpale); }
.btn-danger   { background: var(--danger); color: var(--white); }
.btn-danger:hover { background: #B91C1C; }
.btn-ghost    { background: transparent; color: var(--slate); }
.btn-ghost:hover { background: var(--line-grey); }
.btn-sm { padding: .3rem .65rem; font-size: .78rem; }
.btn-icon { width: 34px; height: 34px; padding: 0; justify-content: center; border-radius: 50%; }

/* ── Search bar ──────────────────────────────────────────── */
.search-bar {
  position: relative;
  display: flex;
  align-items: center;
}
.search-bar input {
  padding: .45rem .75rem .45rem 2.2rem;
  border: 1.5px solid var(--line-grey);
  border-radius: var(--radius);
  font-size: .85rem;
  outline: none;
  min-width: 220px;
  background: var(--white);
  transition: border-color var(--transition);
}
.search-bar input:focus { border-color: var(--green-mid); }
.search-bar .search-icon {
  position: absolute; left: .6rem;
  color: var(--soft-grey); font-size: .9rem; pointer-events: none;
}

/* ── Modal ───────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(2px);
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--white);
  border-radius: 12px;
  padding: 1.8rem;
  width: 100%;
  max-width: 600px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  animation: modal-in .2s ease;
}
.modal.modal-lg { max-width: 860px; }
.modal.modal-sm { max-width: 420px; }
@keyframes modal-in {
  from { opacity: 0; transform: translateY(-20px); }
  to   { opacity: 1; transform: translateY(0); }
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 1.25rem; padding-bottom: .75rem;
  border-bottom: 2px solid var(--green-pale);
}
.modal-header h3 { font-size: 1.05rem; font-weight: 700; color: var(--green); }
.modal-close { background: none; border: none; font-size: 1.3rem; cursor: pointer; color: var(--soft-grey); }
.modal-footer { display: flex; gap: .75rem; justify-content: flex-end; margin-top: 1.5rem; padding-top: 1rem; border-top: 1px solid var(--line-grey); }

/* ── Alerts / Toast ──────────────────────────────────────── */
.toast-container {
  position: fixed;
  top: 1rem; right: 1rem;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: .5rem;
}
.toast {
  background: var(--white);
  border-radius: var(--radius);
  padding: .75rem 1rem;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: .6rem;
  min-width: 280px;
  max-width: 380px;
  font-size: .88rem;
  animation: toast-in .25s ease;
  border-left: 4px solid var(--green);
}
.toast.success { border-color: var(--green); }
.toast.error   { border-color: var(--danger); }
.toast.warning { border-color: var(--warning); }
@keyframes toast-in {
  from { opacity: 0; transform: translateX(20px); }
  to   { opacity: 1; transform: translateX(0); }
}

/* ── Data grids ──────────────────────────────────────────── */
.data-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 1rem;
}

/* ── Hifdh Juz' grid ─────────────────────────────────────── */
.juz-grid {
  display: grid;
  grid-template-columns: repeat(15, 1fr);
  gap: 4px;
  margin: 1rem 0;
}
.juz-cell {
  aspect-ratio: 1;
  border: 1.5px solid var(--line-grey);
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .7rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  background: var(--ivory);
  color: var(--soft-grey);
  user-select: none;
}
.juz-cell:hover       { background: var(--green-xpale); border-color: var(--green-mid); }
.juz-cell.fluent      { background: var(--green-pale);  border-color: var(--green-mid); color: var(--green); }
.juz-cell.revision    { background: #FEF3C7; border-color: var(--gold); color: var(--gold-dark); }
.juz-legend { display: flex; gap: 1.5rem; font-size: .75rem; color: var(--soft-grey); margin-bottom: .5rem; }
.juz-legend span { display: flex; align-items: center; gap: .35rem; }
.dot { width: 12px; height: 12px; border-radius: 3px; border: 1.5px solid; }
.dot-fluent   { background: var(--green-pale); border-color: var(--green-mid); }
.dot-revision { background: #FEF3C7; border-color: var(--gold); }
.dot-blank    { background: var(--ivory); border-color: var(--line-grey); }

/* ── Rating rows ─────────────────────────────────────────── */
.rating-row {
  display: flex;
  align-items: center;
  padding: .45rem .6rem;
  gap: 1rem;
  border-bottom: 1px solid var(--line-grey);
  font-size: .85rem;
}
.rating-row:nth-child(even) { background: var(--green-xpale); }
.rating-row .label { flex: 1; color: var(--slate); }
.rating-row .options { display: flex; gap: .5rem; }
.radio-option {
  display: flex;
  align-items: center;
  gap: .25rem;
  font-size: .78rem;
  cursor: pointer;
  padding: .2rem .5rem;
  border-radius: 4px;
  border: 1.5px solid var(--line-grey);
  transition: all var(--transition);
  white-space: nowrap;
}
.radio-option:hover { border-color: var(--green-mid); background: var(--green-xpale); }
.radio-option.selected { border-color: var(--green); background: var(--green-xpale); color: var(--green); font-weight: 600; }
.radio-option input[type=radio] { display: none; }

/* ── Marks entry ─────────────────────────────────────────── */
.marks-input {
  width: 60px;
  text-align: center;
  border: 1.5px solid var(--line-grey);
  border-radius: 4px;
  padding: .3rem;
  font-size: .85rem;
  outline: none;
}
.marks-input:focus { border-color: var(--green-mid); }
.marks-input.error { border-color: var(--danger); }

/* ── Section bands ───────────────────────────────────────── */
.section-band {
  background: var(--green);
  color: var(--gold-lt);
  font-weight: 700;
  padding: .5rem .8rem;
  border-radius: 5px;
  font-size: .82rem;
  letter-spacing: .02em;
  margin-bottom: .75rem;
  margin-top: 1.25rem;
}

/* ── Fee progress bar ─────────────────────────────────────── */
.progress-bar { background: var(--line-grey); border-radius: 999px; height: 8px; overflow: hidden; }
.progress-fill { height: 100%; border-radius: 999px; background: var(--green-mid); transition: width .4s ease; }
.progress-fill.warning { background: var(--warning); }
.progress-fill.danger  { background: var(--danger); }

/* ── Pagination ──────────────────────────────────────────── */
.pagination {
  display: flex;
  align-items: center;
  gap: .3rem;
  padding: 1rem 0 .5rem;
}
.page-btn {
  min-width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 6px;
  border: 1.5px solid var(--line-grey);
  background: var(--white);
  cursor: pointer;
  font-size: .82rem;
  color: var(--slate);
  transition: all var(--transition);
}
.page-btn:hover { border-color: var(--green-mid); color: var(--green); }
.page-btn.active { background: var(--green); border-color: var(--green); color: var(--white); font-weight: 700; }
.page-btn:disabled { opacity: .4; cursor: default; }

/* ── Responsive (v12: full mobile support) ───────────────── */

/* Shown only on small screens (hamburger button) */
.mobile-only { display: none; }

/* Dim layer behind the mobile sidebar drawer */
.sidebar-overlay {
  display: none; position: fixed; inset: 0; z-index: 99;
  background: rgba(15, 23, 42, .55);
}
.sidebar-overlay.visible { display: block; }

/* Tables scroll sideways instead of breaking the layout */
.table-wrap, .card-body { -webkit-overflow-scrolling: touch; }

@media (max-width: 900px) {
  .stats-grid { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 768px) {
  .auth-page { grid-template-columns: 1fr; }
  .auth-brand { display: none; }

  /* Sidebar becomes a slide-in drawer */
  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0; z-index: 100;
    width: 82vw; max-width: 300px;
    transform: translateX(-100%);
    transition: transform .25s ease;
    overflow-y: auto;
  }
  .sidebar.open { transform: translateX(0); box-shadow: 0 0 40px rgba(0,0,0,.35); }
  .mobile-only { display: inline-flex; }

  .main-content { width: 100%; }

  /* Topbar: hamburger + title, badge wraps out of the way */
  .topbar { padding: .6rem .8rem; gap: .5rem; flex-wrap: wrap; }
  .topbar .page-title { font-size: 1rem; }
  .topbar .term-badge { font-size: .68rem; }

  .page-body { padding: .8rem; }

  /* One-column cards and forms */
  .stats-grid { grid-template-columns: 1fr; }
  .form-grid  { grid-template-columns: 1fr; }

  /* Collapse inline multi-column grids (modals, report cards, filters)
     — these are set as inline styles throughout, so we override hard. */
  [style*="grid-template-columns"] { grid-template-columns: 1fr !important; }

  /* Any table can scroll horizontally on its own */
  .table-wrap, .card-body, .modal-body, #modal-v2-body { overflow-x: auto; }
  table { min-width: 560px; }          /* keeps columns readable, scrolls instead of squashing */

  /* Comfortable tap targets */
  .btn { min-height: 40px; padding: .5rem .8rem; }
  .btn-sm { min-height: 34px; }
  .nav-item { padding: .8rem 1rem; }
  input, select, textarea { font-size: 16px; }   /* stops iOS zoom-on-focus */

  /* Modals fill the screen */
  .modal { width: 96vw !important; max-width: 96vw !important; margin: 2vh auto; max-height: 92vh; overflow-y: auto; }
  .modal-lg { width: 96vw !important; max-width: 96vw !important; }

  /* Action button clusters wrap rather than overflow */
  .flex-between { flex-wrap: wrap; gap: .5rem; }
}

@media (max-width: 480px) {
  .page-body { padding: .6rem; }
  .card-body { padding: .7rem; }
  .topbar .term-badge { display: none; }   /* reclaim width on very small phones */
}

/* Printing: never show app chrome */
@media print {
  .sidebar, .topbar, .sidebar-overlay, .mobile-only { display: none !important; }
}

/* ── Utilities ───────────────────────────────────────────── */
.flex { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.flex-end { display: flex; justify-content: flex-end; align-items: center; }
.gap-sm { gap: .5rem; }
.gap-md { gap: 1rem; }
.gap-lg { gap: 1.5rem; }
.mt-sm { margin-top: .5rem; }
.mt-md { margin-top: 1rem; }
.mt-lg { margin-top: 1.5rem; }
.mb-md { margin-bottom: 1rem; }
.mb-lg { margin-bottom: 1.5rem; }
.text-center { text-align: center; }
.text-right  { text-align: right; }
.text-green  { color: var(--green); }
.text-gold   { color: var(--gold); }
.text-muted  { color: var(--soft-grey); }
.text-danger { color: var(--danger); }
.text-small  { font-size: .8rem; }
.font-bold   { font-weight: 700; }
.w-full { width: 100%; }
.hidden { display: none !important; }
.loading { opacity: .5; pointer-events: none; }
.divider { height: 1px; background: var(--line-grey); margin: 1.25rem 0; }
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--soft-grey);
}
.empty-state .icon { font-size: 2.5rem; margin-bottom: .75rem; }
.empty-state p { font-size: .9rem; }
