/* ============================================================
   MadrasaCloud — Main CSS
   Design tokens + Reset + Global styles
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&family=Noto+Nastaliq+Urdu:wght@400;700&family=Noto+Sans+Devanagari:wght@400;500&display=swap');

/* ── Tokens ── */
:root {
  /* Brand */
  --green-50:  #f0faf4;
  --green-100: #d6f1e1;
  --green-400: #34a85a;
  --green-600: #1e7a40;
  --green-800: #0f4422;

  --gold-50:  #fdfaed;
  --gold-100: #f7edbb;
  --gold-400: #d4a017;
  --gold-600: #9c7210;

  --slate-50:  #f8f8f7;
  --slate-100: #efefed;
  --slate-200: #e0dfdb;
  --slate-400: #9b9a95;
  --slate-600: #5c5b57;
  --slate-800: #2c2c2a;
  --slate-900: #1a1a18;

  --red-50:  #fff0f0;
  --red-400: #e84040;
  --red-600: #b52e2e;

  --blue-50:  #eef5ff;
  --blue-400: #3b7fe8;
  --blue-600: #1d56b8;

  /* Semantic */
  --color-bg:          #ffffff;
  --color-bg-subtle:   var(--slate-50);
  --color-bg-muted:    var(--slate-100);
  --color-surface:     #ffffff;
  --color-border:      var(--slate-200);
  --color-border-md:   #cccbc6;

  --color-text-primary:   var(--slate-900);
  --color-text-secondary: var(--slate-600);
  --color-text-muted:     var(--slate-400);

  --color-brand:        var(--green-600);
  --color-brand-light:  var(--green-50);
  --color-brand-hover:  var(--green-800);
  --color-accent:       var(--gold-400);

  --color-success:     var(--green-400);
  --color-success-bg:  var(--green-50);
  --color-danger:      var(--red-400);
  --color-danger-bg:   var(--red-50);
  --color-info:        var(--blue-400);
  --color-info-bg:     var(--blue-50);
  --color-warning:     var(--gold-400);
  --color-warning-bg:  var(--gold-50);

  /* Sidebar */
  --sidebar-w: 240px;
  --sidebar-bg: var(--slate-900);
  --sidebar-text: #c8c7c2;
  --sidebar-text-active: #ffffff;
  --sidebar-accent: var(--green-400);

  /* Spacing */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --space-10: 40px;

  /* Radius */
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --radius-full: 9999px;

  /* Typography */
  --font-sans: 'Inter', system-ui, sans-serif;
  --font-urdu: 'Noto Nastaliq Urdu', serif;
  --font-hindi: 'Noto Sans Devanagari', sans-serif;

  /* Shadows */
  --shadow-sm: 0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
  --shadow-md: 0 4px 12px rgba(0,0,0,.08), 0 2px 4px rgba(0,0,0,.04);
  --shadow-lg: 0 8px 24px rgba(0,0,0,.10), 0 4px 8px rgba(0,0,0,.06);

  /* Transitions */
  --transition: 150ms ease;
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.6;
  color: var(--color-text-primary);
  background: var(--color-bg-subtle);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; border: none; background: none; }
input, select, textarea { font-family: inherit; }
img { max-width: 100%; display: block; }
ul, ol { list-style: none; }

/* ── App Shell ── */
.app-shell {
  display: flex;
  min-height: 100vh;
}

/* ── Sidebar ── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  transition: transform var(--transition);
}
.sidebar-logo {
  padding: var(--space-6) var(--space-5);
  border-bottom: 1px solid rgba(255,255,255,.08);
  display: flex;
  align-items: center;
  gap: var(--space-3);
}
.sidebar-logo-icon {
  width: 32px; height: 32px;
  background: var(--green-600);
  border-radius: var(--radius-md);
  display: flex; align-items: center; justify-content: center;
  color: #fff;
  font-size: 16px;
  flex-shrink: 0;
}
.sidebar-logo-text {
  font-size: 15px;
  font-weight: 600;
  color: #fff;
  letter-spacing: -.01em;
}
.sidebar-logo-text span {
  color: var(--green-400);
}
.sidebar-nav {
  flex: 1;
  padding: var(--space-4) 0;
  overflow-y: auto;
}
.nav-section-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: rgba(255,255,255,.3);
  padding: var(--space-4) var(--space-5) var(--space-2);
}
.nav-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-5);
  color: var(--sidebar-text);
  font-size: 13.5px;
  font-weight: 400;
  border-radius: 0;
  transition: background var(--transition), color var(--transition);
  cursor: pointer;
  width: 100%;
  text-align: left;
  border-left: 3px solid transparent;
}
.nav-item:hover {
  background: rgba(255,255,255,.06);
  color: #fff;
}
.nav-item.active {
  background: rgba(52,168,90,.15);
  color: var(--sidebar-text-active);
  border-left-color: var(--sidebar-accent);
  font-weight: 500;
}
.nav-item i { font-size: 16px; flex-shrink: 0; opacity: .8; }
.nav-item.active i { opacity: 1; color: var(--sidebar-accent); }
.sidebar-footer {
  padding: var(--space-4) var(--space-5);
  border-top: 1px solid rgba(255,255,255,.08);
}
.sidebar-user {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}
.sidebar-avatar {
  width: 32px; height: 32px;
  border-radius: var(--radius-full);
  background: var(--green-600);
  display: flex; align-items: center; justify-content: center;
  font-size: 12px;
  font-weight: 600;
  color: #fff;
  flex-shrink: 0;
}
.sidebar-user-info { flex: 1; min-width: 0; }
.sidebar-user-name {
  font-size: 13px;
  font-weight: 500;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar-user-role {
  font-size: 11px;
  color: var(--sidebar-text);
}
.btn-logout {
  color: var(--slate-400);
  font-size: 16px;
  padding: var(--space-1);
  border-radius: var(--radius-sm);
  transition: color var(--transition);
}
.btn-logout:hover { color: var(--red-400); }

/* ── Main Content ── */
.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ── Top Bar ── */
.topbar {
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  padding: 0 var(--space-6);
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 50;
}
.topbar-left { display: flex; align-items: center; gap: var(--space-4); }
.page-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--color-text-primary);
}
.topbar-right { display: flex; align-items: center; gap: var(--space-3); }

/* ── Page Content ── */
.page-content {
  padding: var(--space-6);
  flex: 1;
  max-width: 1200px;
  width: 100%;
}

/* ── Cards ── */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}
.card-header {
  padding: var(--space-4) var(--space-6);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
}
.card-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--color-text-primary);
}
.card-body { padding: var(--space-6); }

/* ── Stat Cards ── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: var(--space-4);
  margin-bottom: var(--space-6);
}
.stat-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  box-shadow: var(--shadow-sm);
}
.stat-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: .05em;
  margin-bottom: var(--space-2);
}
.stat-value {
  font-size: 28px;
  font-weight: 600;
  color: var(--color-text-primary);
  line-height: 1.1;
  margin-bottom: var(--space-1);
}
.stat-sub {
  font-size: 12px;
  color: var(--color-text-muted);
}
.stat-icon {
  width: 36px; height: 36px;
  border-radius: var(--radius-md);
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
  margin-bottom: var(--space-3);
}
.stat-icon.green  { background: var(--green-50);  color: var(--green-600); }
.stat-icon.gold   { background: var(--gold-50);   color: var(--gold-600); }
.stat-icon.blue   { background: var(--blue-50);   color: var(--blue-600); }
.stat-icon.red    { background: var(--red-50);    color: var(--red-600); }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: 8px 16px;
  border-radius: var(--radius-md);
  font-size: 13.5px;
  font-weight: 500;
  transition: all var(--transition);
  cursor: pointer;
  border: 1px solid transparent;
  line-height: 1;
  white-space: nowrap;
}
.btn-primary {
  background: var(--color-brand);
  color: #fff;
  border-color: var(--color-brand);
}
.btn-primary:hover { background: var(--color-brand-hover); border-color: var(--color-brand-hover); }
.btn-secondary {
  background: var(--color-surface);
  color: var(--color-text-primary);
  border-color: var(--color-border-md);
}
.btn-secondary:hover { background: var(--color-bg-muted); }
.btn-danger {
  background: var(--red-50);
  color: var(--red-600);
  border-color: #fca5a5;
}
.btn-danger:hover { background: var(--red-400); color: #fff; border-color: var(--red-400); }
.btn-ghost {
  background: transparent;
  color: var(--color-text-secondary);
}
.btn-ghost:hover { background: var(--color-bg-muted); color: var(--color-text-primary); }
.btn-sm { padding: 6px 12px; font-size: 12.5px; }
.btn-icon {
  width: 32px; height: 32px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
}

/* ── Forms ── */
.form-group { margin-bottom: var(--space-5); }
.form-label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--color-text-secondary);
  margin-bottom: var(--space-2);
}
.form-control {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--color-border-md);
  border-radius: var(--radius-md);
  font-size: 14px;
  font-family: inherit;
  color: var(--color-text-primary);
  background: var(--color-surface);
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
}
.form-control:focus {
  border-color: var(--color-brand);
  box-shadow: 0 0 0 3px rgba(30,122,64,.12);
}
.form-control::placeholder { color: var(--color-text-muted); }
select.form-control { cursor: pointer; }
.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-4);
}
.form-hint {
  font-size: 12px;
  color: var(--color-text-muted);
  margin-top: var(--space-1);
}

/* ── Table ── */
.table-wrap {
  overflow-x: auto;
  border-radius: var(--radius-lg);
  border: 1px solid var(--color-border);
  box-shadow: var(--shadow-sm);
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
  background: var(--color-surface);
}
thead {
  background: var(--color-bg-subtle);
  position: sticky;
  top: 0;
}
th {
  text-align: left;
  padding: 10px 16px;
  font-size: 12px;
  font-weight: 600;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: .04em;
  border-bottom: 1px solid var(--color-border);
  white-space: nowrap;
}
td {
  padding: 12px 16px;
  color: var(--color-text-primary);
  border-bottom: 1px solid var(--color-border);
  vertical-align: middle;
}
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--color-bg-subtle); }

/* ── Badges ── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: var(--radius-full);
  font-size: 11.5px;
  font-weight: 500;
}
.badge-green   { background: var(--green-50);  color: var(--green-600); }
.badge-red     { background: var(--red-50);    color: var(--red-600); }
.badge-gold    { background: var(--gold-50);   color: var(--gold-600); }
.badge-blue    { background: var(--blue-50);   color: var(--blue-600); }
.badge-gray    { background: var(--slate-100); color: var(--slate-600); }
.badge-dot::before {
  content: '';
  width: 6px; height: 6px;
  border-radius: 50%;
  background: currentColor;
}

/* ── Modal ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition);
}
.modal-overlay.open {
  opacity: 1;
  pointer-events: all;
}
.modal {
  background: var(--color-surface);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  transform: scale(.96) translateY(8px);
  transition: transform var(--transition);
}
.modal-overlay.open .modal { transform: scale(1) translateY(0); }
.modal-header {
  padding: var(--space-5) var(--space-6);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-title { font-size: 15px; font-weight: 600; }
.modal-body { padding: var(--space-6); }
.modal-footer {
  padding: var(--space-4) var(--space-6);
  border-top: 1px solid var(--color-border);
  display: flex;
  justify-content: flex-end;
  gap: var(--space-3);
}

/* ── Alerts ── */
.alert {
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  font-size: 13.5px;
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}
.alert i { font-size: 16px; flex-shrink: 0; margin-top: 1px; }
.alert-success { background: var(--green-50); color: var(--green-800); border: 1px solid var(--green-100); }
.alert-danger  { background: var(--red-50);   color: var(--red-600);   border: 1px solid #fecaca; }
.alert-info    { background: var(--blue-50);  color: var(--blue-600);  border: 1px solid #bfdbfe; }
.alert-warning { background: var(--gold-50);  color: var(--gold-600);  border: 1px solid var(--gold-100); }

/* ── Empty State ── */
.empty-state {
  text-align: center;
  padding: var(--space-10);
  color: var(--color-text-muted);
}
.empty-state i { font-size: 40px; margin-bottom: var(--space-4); opacity: .4; }
.empty-state p { font-size: 14px; margin-bottom: var(--space-4); }

/* ── Search Bar ── */
.search-bar {
  position: relative;
  max-width: 300px;
}
.search-bar i {
  position: absolute;
  left: 10px; top: 50%;
  transform: translateY(-50%);
  color: var(--color-text-muted);
  font-size: 16px;
  pointer-events: none;
}
.search-bar input {
  width: 100%;
  padding: 8px 12px 8px 34px;
  border: 1px solid var(--color-border-md);
  border-radius: var(--radius-md);
  font-size: 13.5px;
  outline: none;
  background: var(--color-surface);
  transition: border-color var(--transition), box-shadow var(--transition);
}
.search-bar input:focus {
  border-color: var(--color-brand);
  box-shadow: 0 0 0 3px rgba(30,122,64,.12);
}

/* ── Toast ── */
.toast-container {
  position: fixed;
  bottom: var(--space-6);
  right: var(--space-6);
  z-index: 999;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}
.toast {
  background: var(--slate-900);
  color: #fff;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  font-size: 13.5px;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-width: 240px;
  animation: toastIn .2s ease;
}
.toast.success { border-left: 3px solid var(--green-400); }
.toast.error   { border-left: 3px solid var(--red-400); }
.toast.info    { border-left: 3px solid var(--blue-400); }
@keyframes toastIn {
  from { opacity: 0; transform: translateX(20px); }
  to   { opacity: 1; transform: translateX(0); }
}

/* ── Loading Spinner ── */
.spinner {
  width: 20px; height: 20px;
  border: 2px solid var(--color-border);
  border-top-color: var(--color-brand);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-overlay {
  position: fixed; inset: 0;
  background: rgba(255,255,255,.8);
  display: flex; align-items: center; justify-content: center;
  z-index: 300;
}

/* ── Pagination ── */
.pagination {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-4) var(--space-6);
  border-top: 1px solid var(--color-border);
}
.pagination-info {
  font-size: 13px;
  color: var(--color-text-muted);
  flex: 1;
}
.page-btn {
  min-width: 32px; height: 32px;
  padding: 0 var(--space-2);
  border-radius: var(--radius-md);
  font-size: 13px;
  display: flex; align-items: center; justify-content: center;
  border: 1px solid var(--color-border-md);
  background: var(--color-surface);
  color: var(--color-text-primary);
  transition: all var(--transition);
}
.page-btn:hover { background: var(--color-bg-muted); }
.page-btn.active {
  background: var(--color-brand);
  color: #fff;
  border-color: var(--color-brand);
}
.page-btn:disabled {
  opacity: .4;
  cursor: not-allowed;
}

/* ── Language Switcher ── */
.lang-switcher {
  display: flex;
  gap: 2px;
  background: var(--color-bg-muted);
  border-radius: var(--radius-md);
  padding: 2px;
}
.lang-btn {
  padding: 4px 10px;
  border-radius: calc(var(--radius-md) - 2px);
  font-size: 12px;
  font-weight: 500;
  color: var(--color-text-muted);
  transition: all var(--transition);
}
.lang-btn.active {
  background: var(--color-surface);
  color: var(--color-text-primary);
  box-shadow: var(--shadow-sm);
}

/* ── Divider ── */
.divider {
  height: 1px;
  background: var(--color-border);
  margin: var(--space-5) 0;
}

/* ── Checkbox & Toggle ── */
.checkbox-label {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  cursor: pointer;
  font-size: 13.5px;
}
.checkbox-label input[type="checkbox"] {
  width: 16px; height: 16px;
  accent-color: var(--color-brand);
  cursor: pointer;
}
.toggle {
  position: relative;
  width: 36px; height: 20px;
  flex-shrink: 0;
}
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-track {
  position: absolute; inset: 0;
  background: var(--slate-200);
  border-radius: var(--radius-full);
  transition: background var(--transition);
  cursor: pointer;
}
.toggle input:checked ~ .toggle-track { background: var(--color-brand); }
.toggle-thumb {
  position: absolute;
  top: 2px; left: 2px;
  width: 16px; height: 16px;
  background: #fff;
  border-radius: 50%;
  transition: transform var(--transition);
  box-shadow: 0 1px 3px rgba(0,0,0,.2);
  pointer-events: none;
}
.toggle input:checked ~ .toggle-track .toggle-thumb { transform: translateX(16px); }

/* ── Responsive ── */
.sidebar-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  width: 36px; height: 36px;
  border-radius: var(--radius-md);
  color: var(--color-text-secondary);
  font-size: 20px;
}
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .main-content {
    margin-left: 0;
  }
  .sidebar-toggle { display: flex; }
  .form-row { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .page-content { padding: var(--space-4); }
}
