/* ============================================
   HLS-Edu Stylesheet - Horizons Language School
   Color Scheme: Navy Blue (#1B3A6B) + Red (#D4213D)
   ============================================ */

@import url('https://fonts.googleapis.com/css2?family=Cairo:wght@300;400;500;600;700;800&family=Inter:wght@300;400;500;600;700;800&display=swap');

/* ============ CSS Variables - Dark Navy/Gold/Red Theme ============ */
:root {
  --primary: #0f2042;
  --primary-dark: #0a1628;
  --primary-light: #1a3060;
  --accent: #c62828;
  --accent-dark: #b71c1c;
  --accent-light: #e53935;
  --gold: #f9a825;
  --gold-dark: #e69100;
  --white: #FFFFFF;
  --bg-light: rgba(255,255,255,0.04);
  --bg-page: #0a1628;
  --card-bg: rgba(255,255,255,0.04);
  --text-primary: #e8e8e8;
  --text-secondary: rgba(255,255,255,0.7);
  --text-muted: rgba(255,255,255,0.4);
  --border: rgba(255,255,255,0.08);
  --success: #4caf50;
  --success-bg: rgba(76,175,80,0.12);
  --warning: #f9a825;
  --warning-bg: rgba(249,168,37,0.12);
  --danger: #e53935;
  --danger-bg: rgba(229,57,53,0.12);
  --info: #42a5f5;
  --info-bg: rgba(66,165,245,0.12);
  --purple: #ab47bc;
  --purple-bg: rgba(171,71,188,0.12);
  --teal: #26a69a;
  --teal-bg: rgba(38,166,154,0.12);
  --shadow: 0 2px 10px rgba(0,0,0,0.3);
  --shadow-lg: 0 10px 40px rgba(0,0,0,0.4);
  --radius: 8px;
  --radius-lg: 16px;
  --transition: all 0.3s cubic-bezier(.4,0,.2,1);
  --header-height: 60px;
  --nav-height: 50px;
  --font-main: 'Inter', 'Cairo', sans-serif;
  --font-ar: 'Cairo', sans-serif;
  --glass: rgba(255,255,255,0.04);
  --glass-border: rgba(255,255,255,0.08);
}

/* ============ Reset & Base ============ */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

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

/* Scale the dashboard for large desktop and installed-PWA windows. */
@media (min-width: 1200px) {
  html { font-size: 15px; }
}

@media (min-width: 1600px) {
  html { font-size: 16px; }
}

body {
  font-family: var(--font-main);
  background: var(--bg-page);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: hidden;
  max-width: 100vw;
}

::selection { background: var(--gold); color: #000; }

a { color: var(--gold); text-decoration: none; transition: var(--transition); }
a:hover { color: #fff; }

img { max-width: 100%; height: auto; }

/* ============ Login Page ============ */
.login-wrapper {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary) 50%, var(--primary-light) 100%);
  position: relative;
  overflow: hidden;
}

.login-wrapper::before {
  content: '';
  position: absolute;
  top: -50%;
  right: -50%;
  width: 100%;
  height: 100%;
  background: radial-gradient(circle, rgba(212,33,61,0.15) 0%, transparent 70%);
  animation: floatBg 20s ease-in-out infinite;
}

.login-wrapper::after {
  content: '';
  position: absolute;
  bottom: -30%;
  left: -30%;
  width: 80%;
  height: 80%;
  background: radial-gradient(circle, rgba(255,255,255,0.05) 0%, transparent 70%);
  animation: floatBg 15s ease-in-out infinite reverse;
}

@keyframes floatBg {
  0%, 100% { transform: translate(0, 0) rotate(0deg); }
  33% { transform: translate(30px, -30px) rotate(5deg); }
  66% { transform: translate(-20px, 20px) rotate(-3deg); }
}

.login-card {
  background: rgba(15,32,66,0.9);
  backdrop-filter: blur(20px);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  padding: 40px;
  width: 420px;
  max-width: 90%;
  box-shadow: var(--shadow-lg);
  position: relative;
  z-index: 1;
  animation: slideUp 0.6s ease-out;
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(40px); }
  to { opacity: 1; transform: translateY(0); }
}

.login-logo {
  text-align: center;
  margin-bottom: 24px;
}

.login-logo img {
  width: 100px;
  height: 100px;
  border-radius: 50%;
  object-fit: contain;
  border: 3px solid var(--border);
  padding: 5px;
  background: white;
}

.login-logo h1 {
  font-size: 1.4rem;
  color: #fff;
  margin-top: 12px;
  font-weight: 700;
}

.login-logo p {
  color: var(--text-secondary);
  font-size: 0.85rem;
}

.form-group {
  margin-bottom: 18px;
}

.form-group label {
  display: block;
  margin-bottom: 6px;
  font-weight: 600;
  color: var(--text-primary);
  font-size: 0.9rem;
}

.form-control {
  width: 100%;
  padding: 12px 16px;
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  font-family: var(--font-main);
  font-size: 0.95rem;
  transition: var(--transition);
  background: rgba(255,255,255,0.06);
  color: var(--text-primary);
}

.form-control:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(249,168,37,0.15);
  background: rgba(255,255,255,0.08);
}

.form-control::placeholder {
  color: var(--text-muted);
}

select.form-control,
select {
  background-color: #131b2e;
  color: #e0e0e0;
  color-scheme: dark;
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%23888' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}

[dir="rtl"] select.form-control,
[dir="rtl"] select {
  background-position: left 12px center;
  padding-right: 16px;
  padding-left: 36px;
}

select.form-control option,
select option {
  background: #131b2e;
  color: #e0e0e0;
  padding: 8px 12px;
}

select.form-control option:checked,
select option:checked {
  background: var(--primary-light);
  color: #fff;
}

.input-icon-wrapper {
  position: relative;
}

.input-icon-wrapper .form-control {
  padding-left: 44px;
}

.input-icon-wrapper i {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: 1.1rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 24px;
  border: none;
  border-radius: var(--radius);
  font-family: var(--font-main);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  text-decoration: none;
}

.btn-primary {
  background: linear-gradient(135deg, var(--gold), var(--gold-dark));
  color: #000;
  width: auto;
  padding: 10px 20px;
  font-size: 0.92rem;
  font-weight: 700;
}

.login-card .btn-primary {
  width: 100%;
  padding: 14px;
  font-size: 1rem;
}

.btn-primary:hover {
  background: linear-gradient(135deg, #fbc02d, var(--gold));
  transform: translateY(-2px);
  box-shadow: 0 5px 20px rgba(249,168,37,0.4);
}

.btn-accent {
  background: linear-gradient(135deg, var(--accent), var(--accent-light));
  color: white;
}

.btn-accent:hover {
  background: linear-gradient(135deg, var(--accent-dark), var(--accent));
  transform: translateY(-1px);
}

.btn-success { background: var(--success); color: white; }
.btn-success:hover { background: #219a52; }

.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: #c0392b; }

.btn-outline {
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.2);
  color: var(--text-secondary);
}

.btn-outline:hover {
  background: rgba(255,255,255,0.12);
  border-color: rgba(255,255,255,0.35);
  color: #fff;
}

.btn-sm { padding: 6px 14px; font-size: 0.8rem; }
.btn-xs { padding: 4px 10px; font-size: 0.75rem; }

.alert {
  padding: 12px 16px;
  border-radius: var(--radius);
  margin-bottom: 16px;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  gap: 10px;
}

.alert-danger { background: var(--danger-bg); color: var(--danger); border-left: 4px solid var(--danger); }
.alert-success { background: var(--success-bg); color: var(--success); border-left: 4px solid var(--success); }
.alert-warning { background: var(--warning-bg); color: var(--warning); border-left: 4px solid var(--warning); }
.alert-info { background: var(--info-bg); color: var(--info); border-left: 4px solid var(--info); }

/* ============ Header ============ */
.header {
  background: linear-gradient(135deg, rgba(6,14,26,.96), rgba(10,22,40,.98));
  height: var(--header-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  color: white;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  z-index: 1000;
  box-shadow: 0 2px 15px rgba(0,0,0,0.4);
  border-bottom: 1px solid var(--glass-border);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 16px;
}

.header-logo {
  width: 45px;
  height: 45px;
  border-radius: 50%;
  object-fit: contain;
  background: white;
  padding: 3px;
}

.header-logo.brand-mark {
  border-radius: 0;
  background: transparent;
  padding: 4px;
}

.header-title {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: 0.5px;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

.header-icon {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: rgba(255,255,255,0.15);
  color: white;
  cursor: pointer;
  transition: var(--transition);
  font-size: 1.1rem;
}

.header-icon:hover {
  background: rgba(255,255,255,0.25);
}

.user-menu {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  padding: 4px 12px;
  border-radius: 20px;
  transition: var(--transition);
  position: relative;
}

.user-menu:hover { background: rgba(255,255,255,0.15); }

.user-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid rgba(255,255,255,0.5);
}

.user-name {
  font-size: 0.9rem;
  font-weight: 500;
}

.user-dropdown {
  position: absolute;
  top: 100%;
  right: 0;
  background: rgba(15,32,66,0.95);
  backdrop-filter: blur(20px);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  min-width: 200px;
  padding: 8px 0;
  display: none;
  z-index: 1001;
  margin-top: 8px;
}

.user-dropdown.show { display: block; animation: fadeIn 0.2s ease; }

.user-dropdown a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  color: var(--text-secondary);
  font-size: 0.9rem;
  transition: var(--transition);
}

.user-dropdown a:hover {
  background: rgba(249,168,37,0.1);
  color: var(--gold);
}

.user-dropdown a.active-lang {
  color: var(--gold);
  background: rgba(249,168,37,0.06);
}

.user-dropdown .divider {
  height: 1px;
  background: var(--border);
  margin: 4px 0;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(-10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ============ Navigation Bar ============ */
.main-nav {
  background: linear-gradient(90deg, rgba(10,22,40,.95), rgba(15,32,66,.9));
  position: fixed;
  top: var(--header-height);
  left: 0;
  width: 100%;
  z-index: 999;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
  border-bottom: 1px solid var(--glass-border);
  display: flex;
  align-items: center;
}

.nav-container {
  display: flex;
  align-items: center;
  padding: 0 8px;
  gap: 0;
  flex: 1;
}

.nav-item {
  position: relative;
  padding: 0;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 14px 14px;
  color: rgba(255,255,255,0.85);
  font-size: 0.88rem;
  font-weight: 500;
  white-space: nowrap;
  transition: var(--transition);
  border-bottom: 3px solid transparent;
  cursor: pointer;
}

.nav-link:hover, .nav-link.active {
  color: white;
  background: rgba(255,255,255,0.06);
  border-bottom-color: var(--gold);
}

.nav-link i { font-size: 0.95rem; }

.nav-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  background: rgba(10,22,40,0.97);
  backdrop-filter: blur(20px);
  border: 1px solid var(--glass-border);
  border-radius: 0 0 var(--radius) var(--radius);
  box-shadow: 0 10px 40px rgba(0,0,0,0.5);
  min-width: 220px;
  padding: 8px 0;
  display: none;
  z-index: 10000;
}

.nav-item:hover > .nav-dropdown,
.nav-dropdown.open {
  display: block !important;
  animation: fadeIn 0.2s ease;
}

.nav-dropdown a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 18px;
  color: var(--text-secondary);
  font-size: 0.88rem;
  transition: var(--transition);
}

.nav-dropdown a:hover {
  background: rgba(249,168,37,0.08);
  color: var(--gold);
  padding-left: 24px;
}

.nav-dropdown a i { color: var(--text-muted); width: 18px; }

/* Settings nav (gear icon) - inline with main nav */
.settings-nav {
  padding: 0 8px 0 0;
  flex-shrink: 0;
}

/* ============ Sub Navigation (Tabs) ============ */
.sub-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 12px 24px;
  background: rgba(15,32,66,0.6);
  border-bottom: 1px solid var(--glass-border);
}

.sub-nav a {
  padding: 8px 16px;
  border-radius: 6px;
  color: var(--text-secondary);
  font-size: 0.88rem;
  font-weight: 500;
  transition: var(--transition);
}

.sub-nav a:hover {
  color: #fff;
  background: rgba(255,255,255,0.06);
}

.sub-nav a.active {
  color: var(--gold);
  font-weight: 700;
  background: rgba(249,168,37,0.1);
}

/* ============ Main Content ============ */
.main-content {
  margin-top: calc(var(--header-height) + var(--nav-height) + 5px);
  padding: 16px 24px;
  min-height: calc(100vh - var(--header-height) - var(--nav-height));
  max-width: 100%;
  overflow: hidden;
}

/* ============ Dashboard Cards ============ */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 20px;
  margin-bottom: 30px;
}

.stat-card {
  background: var(--glass);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  padding: 24px;
  display: flex;
  align-items: center;
  gap: 16px;
  box-shadow: var(--shadow);
  transition: var(--transition);
  position: relative;
  overflow: hidden;
  backdrop-filter: blur(10px);
}

.stat-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-lg);
}

.stat-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 5px;
  height: 100%;
}

.stat-card.blue::before { background: var(--info); }
.stat-card.red::before { background: var(--accent); }
.stat-card.teal::before { background: var(--teal); }
.stat-card.purple::before { background: var(--purple); }

.stat-card.blue { border-left: none; }
.stat-card.red { border-left: none; }
.stat-card.teal { border-left: none; }
.stat-card.purple { border-left: none; }

.stat-icon {
  width: 60px;
  height: 60px;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  color: white;
  flex-shrink: 0;
}

.stat-card.blue .stat-icon { background: linear-gradient(135deg, #3498DB, #2980B9); }
.stat-card.red .stat-icon { background: linear-gradient(135deg, var(--accent), var(--accent-dark)); }
.stat-card.teal .stat-icon { background: linear-gradient(135deg, var(--teal), #16A085); }
.stat-card.purple .stat-icon { background: linear-gradient(135deg, var(--purple), #7D3C98); }

.stat-info { flex: 1; }

.stat-number {
  font-size: 1.8rem;
  font-weight: 800;
  line-height: 1.2;
  color: var(--text-primary);
}

.stat-number small {
  font-size: 0.9rem;
  font-weight: 400;
  color: var(--text-muted);
}

.stat-label {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-top: 2px;
}

.stat-link {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 8px;
  cursor: pointer;
  transition: var(--transition);
}

.stat-link:hover { color: var(--primary); }

/* ============ Charts Section ============ */
.charts-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 20px;
  margin-bottom: 30px;
}

.chart-card {
  background: var(--glass);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow);
}

.chart-header {
  padding: 14px 20px;
  color: white;
  font-weight: 600;
  font-size: 0.95rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.chart-header i { margin-right: 8px; }

.chart-header.blue { background: var(--info); }
.chart-header.red { background: var(--accent); }
.chart-header.teal { background: var(--teal); }
.chart-header.purple { background: var(--purple); }

.chart-body {
  padding: 20px;
  min-height: 200px;
}

.chart-toggle {
  cursor: pointer;
  font-size: 1.2rem;
  opacity: 0.8;
  transition: var(--transition);
}

.chart-toggle:hover { opacity: 1; }

/* ============ Tables ============ */
.table-container {
  background: var(--glass);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow);
}

.table-header {
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--glass-border);
}

.table-header h3 {
  font-size: 1.1rem;
  color: var(--gold);
}

table {
  width: 100%;
  border-collapse: collapse;
}

thead th {
  background: rgba(249,168,37,0.08);
  padding: 12px 16px;
  text-align: left;
  font-weight: 600;
  color: var(--gold);
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--glass-border);
}

tbody td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--glass-border);
  font-size: 0.9rem;
  color: var(--text-secondary);
}

tbody tr:hover { background: rgba(255,255,255,0.03); }

tbody tr:last-child td { border-bottom: none; }

/* ============ Student Cards ============ */
.students-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 20px;
  overflow-x: hidden;
}

.student-card {
  background: var(--glass);
  border: 1px solid var(--glass-border);
  border-radius: 18px;
  overflow: visible;
  box-shadow: var(--shadow);
  transition: transform 0.3s ease, box-shadow 0.3s ease, border-color 0.3s ease;
  position: relative;
  display: flex;
  flex-direction: column;
  height: 100%;
}

.student-card:hover {
  box-shadow: 0 0 15px rgba(249,168,37,0.15), var(--shadow-lg);
  border-color: rgba(249,168,37,0.35);
}

.student-card-header {
  background: linear-gradient(135deg, rgba(15,32,66,0.8), rgba(26,48,96,0.6));
  color: white;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border-bottom: 1px solid var(--glass-border);
  border-radius: 17px 17px 0 0;
  min-height: 72px;
  height: 72px;
}

.student-card-header h4 {
  font-size: 0.94rem;
  font-weight: 700;
  line-height: 1.45;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
}
.student-name-link{
  color:#fff;
  text-decoration:none;
  display:-webkit-box;
  -webkit-line-clamp:2;
  -webkit-box-orient:vertical;
  overflow:hidden;
  line-height:1.45;
  word-break:break-word;
}
.student-name-link:hover,.student-name-link:focus-visible{color:#fff;text-decoration:underline;text-underline-offset:4px}
.student-card-menu{display:flex;align-items:center;justify-content:center;width:40px;height:40px;border:1px solid rgba(255,255,255,.3);border-radius:12px;background:rgba(255,255,255,.12);color:#fff;cursor:pointer;flex-shrink:0}
.student-card-menu:hover,.student-card-menu:focus-visible{background:rgba(255,255,255,.24);outline:2px solid var(--gold);outline-offset:2px}

.student-card-body {
  padding: 16px 18px;
  flex: 1;
  display: flex;
  flex-direction: column;
}
.student-card-badges {
  display: flex;
  flex-wrap: nowrap;
  gap: 6px;
  margin-bottom: 10px;
  min-height: 26px;
  height: 26px;
  align-items: center;
  overflow: hidden;
}
.student-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  line-height: 1.4;
  white-space: nowrap;
  flex-shrink: 0;
}
.student-pill i { font-size: 0.68rem; }
.student-pill-male { background: rgba(37, 99, 235, 0.14); color: #2563eb; border: 1px solid rgba(37, 99, 235, 0.28); }
.student-pill-female { background: rgba(219, 39, 119, 0.14); color: #db2777; border: 1px solid rgba(219, 39, 119, 0.28); }
.student-pill-muslim { background: rgba(5, 150, 105, 0.15); color: #059669; border: 1px solid rgba(5, 150, 105, 0.32); }
.student-pill-christian { background: rgba(124, 58, 237, 0.15); color: #7c3aed; border: 1px solid rgba(124, 58, 237, 0.32); }
.student-pill-neutral { background: rgba(100, 116, 139, 0.12); color: var(--text-secondary); border: 1px solid rgba(100, 116, 139, 0.24); }
.student-card-summary{display:flex;gap:12px;margin:8px 0 10px;align-items:center}
.student-card-age{min-height:22px;height:22px;font-size:.76rem;color:#d97706;font-weight:600;margin-bottom:6px;line-height:22px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.student-card-code{min-height:20px;height:20px;font-size:.75rem;color:var(--text-muted);margin-bottom:4px;line-height:20px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.student-info-row.data-missing,.student-card-code.data-missing{color:var(--text-muted);font-style:italic}
.student-card-footer{display:flex;align-items:center;justify-content:space-between;gap:10px;flex-wrap:nowrap;padding:12px 18px;margin-top:auto;border-top:1px solid var(--glass-border);border-radius:0 0 17px 17px;font-size:.8rem}
.student-card-footer a{display:inline-flex;align-items:center;gap:7px;color:var(--info);font-weight:700;text-decoration:none;min-height:36px;flex-shrink:0}.student-card-footer a:hover{text-decoration:underline}.student-card-footer span{color:var(--text-muted);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}

.student-info-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 7px;
  font-size: 0.83rem;
  color: var(--text-secondary);
  min-height: 21px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.student-info-row > span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.student-info-row i {
  width: 16px;
  flex-shrink: 0;
  text-align: center;
  color: var(--text-muted);
}

.student-photo {
  width: 58px;
  height: 58px;
  flex-shrink: 0;
  border-radius: 50%;
  object-fit: cover;
  border: 3px solid white;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

/* Student card dropdown fix */
.student-card .user-dropdown {
  right: 0;
  left: auto;
  min-width: 180px;
  z-index: 1010;
}
[dir="rtl"] .student-card .user-dropdown {
  right: auto;
  left: 0;
}
.student-card-header {
  position: relative;
  z-index: 2;
}

/* ============ Attendance Grid ============ */
.attendance-table {
  overflow-x: auto;
}

.attendance-table table {
  min-width: 800px;
}

.attendance-table th, .attendance-table td {
  text-align: center;
  padding: 8px 6px;
  font-size: 0.8rem;
}

.attendance-check { color: var(--success); font-size: 1.2rem; }
.attendance-cross { color: var(--danger); font-size: 1.2rem; }
.attendance-today { background: rgba(52,152,219,0.1); }

.attendance-status-cell {
  min-width: 94px;
}

.attendance-status-select {
  width: 100%;
  min-width: 88px;
  min-height: 38px;
  padding: 6px 8px;
  border: 1px solid var(--glass-border);
  border-radius: 8px;
  background: var(--glass);
  color: var(--text-primary);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.attendance-status-select:focus-visible {
  outline: 3px solid rgba(52, 152, 219, .28);
  outline-offset: 2px;
}

.attendance-status-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  min-width: 78px;
  padding: 5px 7px;
  border: 1px solid currentColor;
  border-radius: 999px;
  font-size: .72rem;
  font-weight: 700;
  white-space: nowrap;
}

.attendance-status-select.status-present,
.attendance-status-badge.status-present { color: var(--success); background: rgba(39, 174, 96, .12); }
.attendance-status-select.status-absent,
.attendance-status-badge.status-absent { color: var(--danger); background: rgba(231, 76, 60, .12); }
.attendance-status-select.status-late,
.attendance-status-badge.status-late { color: var(--warning); background: rgba(243, 156, 18, .13); }
.attendance-status-select.status-excused,
.attendance-status-badge.status-excused { color: var(--info); background: rgba(52, 152, 219, .12); }
.attendance-status-select.status-sick,
.attendance-status-badge.status-sick { color: var(--purple); background: var(--purple-bg); }
.attendance-sick-count { color: var(--purple); font-weight: 600; }

.promotion-lock-card {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 14px;
  align-items: start;
  padding: 18px;
  border: 1px solid rgba(243, 156, 18, .45);
  border-radius: var(--radius);
  background: rgba(243, 156, 18, .1);
  color: var(--text-primary);
}
.promotion-lock-icon {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: rgba(243, 156, 18, .18);
  color: var(--warning);
  font-size: 1.1rem;
}
.promotion-lock-card h3 { margin: 0 0 6px; font-size: 1rem; }
.promotion-lock-card p { margin: 0 0 10px; color: var(--text-secondary); line-height: 1.7; }
.promotion-lock-meta { display: flex; flex-wrap: wrap; gap: 8px 16px; margin-bottom: 12px; font-size: .82rem; }
.promotion-lock-card [disabled] { cursor: not-allowed; opacity: .58; }
@media (max-width: 600px) {
  .promotion-lock-card { grid-template-columns: 1fr; }
}

.student-card-blocked { border-color: rgba(231, 76, 60, .65) !important; }
.student-card-blocked .student-card-header { background: rgba(231, 76, 60, .13); }
.student-blocked-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-inline-start: 7px;
  padding: 3px 7px;
  border: 1px solid rgba(231, 76, 60, .55);
  border-radius: 999px;
  background: rgba(231, 76, 60, .16);
  color: var(--danger);
  font-size: .65rem;
  white-space: nowrap;
}
.student-block-reason {
  margin-bottom: 10px;
  padding: 9px 10px;
  border-inline-start: 3px solid var(--danger);
  border-radius: 7px;
  background: rgba(231, 76, 60, .1);
  color: var(--text-primary);
  font-size: .76rem;
  line-height: 1.7;
}

/* ============ Filters ============ */
.filters-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: flex-end;
  padding: 16px;
  background: var(--glass);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  box-shadow: 0 8px 24px rgba(15,32,66,.06);
  margin-bottom: 20px;
}

.filters-bar > strong {
  flex: 1 0 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 28px;
  color: var(--text-primary);
}

.filters-bar > label,
.filters-bar > .form-group {
  display: flex;
  flex: 1 1 180px;
  min-width: min(180px, 100%);
  flex-direction: column;
  gap: 7px;
  color: var(--text-secondary);
  font-size: .83rem;
  font-weight: 700;
  line-height: 1.4;
}

.filters-bar select, .filters-bar input {
  width: 100%;
  min-height: 48px;
  padding: 10px 14px;
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  font-family: var(--font-main);
  font-size: 0.95rem;
  background: rgba(255,255,255,0.06);
  color: var(--text-primary);
  transition: var(--transition);
}

.filters-bar > select {
  flex: 1 1 170px;
  width: auto;
  min-width: min(170px, 100%);
}

.filters-bar > .btn,
.filters-bar > button[type="submit"] {
  flex: 0 0 auto;
  min-height: 48px;
  min-width: 112px;
  align-self: flex-end;
  white-space: nowrap;
}

.filters-bar select:focus, .filters-bar input:focus {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
  border-color: var(--gold);
}

.academic-class-filters{display:grid;grid-template-columns:repeat(3,minmax(150px,1fr)) auto;flex:1 1 100%;width:100%;gap:12px;align-items:end;min-width:0}
.academic-class-filters .acf-field{display:flex;min-width:0;flex-direction:column;gap:7px;color:var(--text-secondary);font-size:.83rem;font-weight:700;line-height:1.4}
.academic-class-filters .acf-field select{width:100%;min-height:48px;color:var(--text-primary);font-weight:600}
.academic-class-filters .acf-field select:disabled{opacity:.55;cursor:not-allowed}
.academic-class-filters .acf-submit{width:auto;min-height:48px;min-width:112px;align-self:end;white-space:nowrap;font-weight:700}
.filters-bar .search-box input{min-height:48px}
.attendance-filter-field{display:flex;flex:1 1 170px;min-width:165px;flex-direction:column;gap:7px;color:var(--text-secondary);font-size:.83rem;font-weight:700}
.attendance-filter-field input{width:100%;min-height:48px}
.attendance-view-note{margin:14px 0;padding:12px 16px;border:1px solid var(--glass-border);border-radius:12px;background:var(--glass);color:var(--text-secondary)}
.attendance-student-cell{min-width:210px;text-align:start;white-space:normal}.attendance-student-cell a{display:block;color:var(--text-primary);font-weight:700;text-decoration:none}.attendance-student-cell a:hover{text-decoration:underline;color:var(--info)}
.attendance-placement-badge{display:inline-flex;margin-top:5px;padding:3px 9px;border-radius:999px;background:rgba(26,188,156,.14);color:var(--text-primary);border:1px solid var(--glass-border);font-size:.75rem;font-weight:600}
@media(max-width:900px){.academic-class-filters{grid-template-columns:repeat(2,minmax(0,1fr))}.academic-class-filters .acf-submit{width:100%}}
@media(max-width:520px){.academic-class-filters{grid-template-columns:1fr}.academic-class-filters .acf-submit{width:100%}}

.filters-bar select option { background: #0f2042; color: #fff; }

.search-box {
  position: relative;
  flex: 2 1 280px;
  min-width: min(240px, 100%);
}

.search-box input {
  width: 100%;
  padding: 10px 16px 10px 40px;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  font-family: var(--font-main);
  font-size: 0.9rem;
}

.search-box i {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
}

/* ============ Floating Action Button ============ */
button.fab {
  position: fixed;
  bottom: 30px;
  right: 30px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-dark));
  color: white;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  box-shadow: 0 4px 20px rgba(212,33,61,0.4);
  transition: var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

button.fab:hover {
  transform: scale(1.1) rotate(90deg);
  box-shadow: 0 6px 30px rgba(212,33,61,0.5);
}

/* ============ Modal ============ */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.7);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  backdrop-filter: blur(4px);
}

.modal-overlay.show {
  display: flex;
  animation: fadeIn 0.2s ease;
}

.modal {
  background: linear-gradient(145deg, rgba(10,22,40,0.98), rgba(8,18,35,0.99));
  border: 1px solid rgba(249,168,37,0.15);
  backdrop-filter: blur(20px);
  border-radius: 16px;
  width: 960px;
  max-width: 95%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5), 0 0 30px rgba(249,168,37,0.03);
  animation: slideUp 0.3s ease;
}

.modal-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--glass-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-header h3 {
  color: var(--gold);
  font-size: 1.1rem;
}

.modal-close {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: rgba(255,255,255,0.06);
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 1.2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}

.modal-close:hover { background: var(--danger-bg); color: var(--danger); }

.modal-body { padding: 24px; }
.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--glass-border);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* Modal form improvements */
.modal .form-control {
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.15);
  color: #fff;
}

.modal .form-control:focus {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(249,168,37,0.15);
  background: rgba(255,255,255,0.1);
}

.modal .form-group label {
  color: var(--gold);
  font-weight: 600;
  font-size: 0.85rem;
  margin-bottom: 8px;
}

/* ============ Modal Tabs ============ */
.modal-tabs {
  display: flex;
  border-bottom: 1px solid var(--glass-border);
  background: rgba(255,255,255,0.03);
  padding: 0;
  overflow-x: auto;
}

.modal-tab {
  padding: 12px 22px;
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-secondary);
  border-bottom: 3px solid transparent;
  transition: var(--transition);
  white-space: nowrap;
  position: relative;
  font-family: var(--font-main);
}

.modal-tab:hover {
  color: var(--gold);
  background: rgba(249,168,37,0.04);
}

.modal-tab.active {
  color: var(--gold);
  font-weight: 600;
  border-bottom-color: var(--gold);
  background: rgba(249,168,37,0.06);
}

.tab-content {
  display: none;
}
.tab-content.active {
  display: block;
}

/* ============ Compact Form for Modals ============ */
.modal .form-group {
  margin-bottom: 10px;
}

.modal .form-group label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 3px;
  display: block;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.modal .form-control {
  padding: 8px 12px;
  font-size: 0.85rem;
  border: 1px solid var(--glass-border);
  border-radius: 6px;
  width: 100%;
  transition: var(--transition);
  background: rgba(255,255,255,0.06);
  color: var(--text-primary);
}

.modal .form-control:focus {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(249,168,37,0.1);
  outline: none;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 14px;
}

.form-grid .full-width {
  grid-column: 1 / -1;
}

/* ============ Section Header in Forms ============ */
.form-section-title {
  font-size: 0.9rem;
  font-weight: 700;
  margin: 14px 0 8px;
  padding: 8px 12px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.form-section-title.father {
  color: var(--primary);
  background: rgba(27,58,107,0.06);
}

.form-section-title.mother {
  color: var(--accent);
  background: rgba(212,33,61,0.06);
}

.form-section-title.general {
  color: var(--success);
  background: var(--success-bg);
}

/* ============ Import Bar ============ */
.import-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--glass);
  border: 1px solid var(--glass-border);
  padding: 10px 16px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-top: 12px;
}

.import-bar .import-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.btn-import {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  font-size: 0.83rem;
  font-weight: 600;
  border-radius: 6px;
  border: 1px solid;
  cursor: pointer;
  transition: var(--transition);
}

.btn-import-excel {
  background: #fff;
  color: #217346;
  border-color: #217346;
}
.btn-import-excel:hover {
  background: #217346;
  color: #fff;
}

.btn-import-download {
  background: #fff;
  color: var(--info);
  border-color: var(--info);
}
.btn-import-download:hover {
  background: var(--info);
  color: #fff;
}

/* ============ Dashboard Tabs ============ */
.dash-tabs {
  display: flex;
  justify-content: flex-end;
  gap: 4px;
  margin-bottom: 20px;
}

.dash-tab {
  padding: 8px 18px;
  border-radius: 20px;
  font-size: 0.88rem;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  color: var(--text-secondary);
  background: var(--glass);
  border: 1px solid var(--glass-border);
}

.dash-tab:hover { color: var(--gold); border-color: var(--gold); }

.dash-tab.active {
  background: linear-gradient(135deg, var(--gold), var(--gold-dark));
  color: #000;
  border-color: var(--gold);
  font-weight: 700;
}

/* ============ No Data Message ============ */
.no-data {
  padding: 30px;
  text-align: center;
  color: var(--text-muted);
  font-style: italic;
  background: rgba(249,168,37,0.06);
  border: 1px solid rgba(249,168,37,0.1);
  border-radius: var(--radius);
}

/* ============ Badges ============ */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
}

.badge-success { background: var(--success-bg); color: var(--success); }
.badge-danger { background: var(--danger-bg); color: var(--danger); }
.badge-warning { background: var(--warning-bg); color: var(--warning); }
.badge-info { background: var(--info-bg); color: var(--info); }
.badge-primary { background: rgba(27,58,107,0.1); color: var(--primary); }
.badge-beta { background: var(--accent); color: white; font-size: 0.65rem; padding: 2px 6px; }

/* ============ Utility ============ */
.text-center { text-align: center; }
.text-right { text-align: right; }
.mt-1 { margin-top: 8px; } .mt-2 { margin-top: 16px; } .mt-3 { margin-top: 24px; }
.mb-1 { margin-bottom: 8px; } .mb-2 { margin-bottom: 16px; } .mb-3 { margin-bottom: 24px; }
.flex { display: flex; } .flex-center { display: flex; align-items: center; justify-content: center; }
.gap-1 { gap: 8px; } .gap-2 { gap: 16px; }

.date-display {
  font-size: 1.2rem;
  color: var(--text-muted);
  font-style: italic;
  margin-bottom: 16px;
}

/* ============ Responsive ============ */
@media (max-width: 1024px) {
  .charts-grid { grid-template-columns: 1fr; }
  .nav-link { padding: 12px 10px; font-size: 0.82rem; }
}

@media (max-width: 768px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .charts-grid { grid-template-columns: 1fr; }
  .students-grid { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
  .main-content { padding: 12px; }
  .nav-container { overflow-x: auto; }
  .nav-link { padding: 12px 10px; font-size: 0.78rem; }
  .header-title { font-size: 1rem; }
  .sub-nav { padding: 8px 12px; }
  .form-grid { grid-template-columns: 1fr; }
  .filters-bar { flex-direction: column; align-items: stretch; }
  .filters-bar > select,
  .filters-bar > label,
  .filters-bar > .form-group,
  .filters-bar > .search-box { flex: 0 0 auto; width: 100%; min-width: 0; }
  .modal { width: 95%; max-width: 95%; }
  .footer-grid { grid-template-columns: 1fr; }
  .contact-grid { grid-template-columns: 1fr; }
}

@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; }
  .login-card { padding: 24px; width: 95%; }
  .header { padding: 0 12px; }
  .header-title { display: none; }
  .main-content { padding: 8px; }
  .stat-card { padding: 16px; }
  .nav-link span { display: none; }
  .nav-link i { font-size: 1.1rem; }
  .nav-link { padding: 12px 14px; }
}

/* ============ GLOBAL DARK THEME OVERRIDES ============ */
/* Fixes ALL settings/admin pages at once */

/* Settings cards */
.settings-card,
.page-card,
.card {
  background: var(--glass) !important;
  border-color: var(--glass-border) !important;
  color: var(--text-primary) !important;
}

/* ALL tables globally */
table {
  background: transparent !important;
  border-color: var(--glass-border) !important;
}
table thead,
table thead tr,
table thead th {
  background: rgba(249,168,37,0.08) !important;
  color: var(--gold) !important;
  border-color: var(--glass-border) !important;
}
table tbody tr {
  background: transparent !important;
  border-color: var(--glass-border) !important;
}
table tbody tr:hover {
  background: rgba(255,255,255,0.03) !important;
}
table tbody td {
  background: transparent !important;
  color: var(--text-primary) !important;
  border-color: var(--glass-border) !important;
}

/* Filter bars */
.filter-bar,
.subject-filters {
  background: rgba(255,255,255,0.03) !important;
  border-color: var(--glass-border) !important;
}
.filter-bar select,
.filter-bar input,
.subject-filters select {
  background: rgba(255,255,255,0.06) !important;
  color: var(--text-primary) !important;
  border-color: var(--glass-border) !important;
}
.filter-bar select option,
.subject-filters select option {
  background: #1a2332 !important;
  color: #e0e0e0 !important;
}

/* ALL form elements inside page containers */
.page-card input:not([type="checkbox"]):not([type="radio"]):not([type="color"]),
.page-card select,
.page-card textarea,
.settings-card input:not([type="checkbox"]):not([type="radio"]):not([type="color"]),
.settings-card select,
.settings-card textarea {
  background: rgba(255,255,255,0.06) !important;
  color: var(--text-primary) !important;
  border-color: var(--glass-border) !important;
}
.page-card select option,
.settings-card select option {
  background: #1a2332 !important;
  color: #e0e0e0 !important;
}

/* Labels */
.page-card label,
.settings-card label,
.form-label {
  color: var(--text-primary) !important;
}

/* No-data messages */
.no-data {
  color: var(--text-muted) !important;
  background: transparent !important;
  border-color: var(--glass-border) !important;
}

/* Sidebar stats */
.summary-card,
.stat-sidebar,
.info-card {
  background: var(--glass) !important;
  border-color: var(--glass-border) !important;
  color: var(--text-primary) !important;
}

/* Page titles */
.page-title {
  color: var(--text-primary) !important;
}

/* Fix white bg from inline styles */
.main-content [style*="background:white"],
.main-content [style*="background: white"],
.main-content [style*="background:#fff"],
.main-content [style*="background: #fff"],
.main-content [style*="background:#FFF"] {
  background: var(--glass) !important;
}

/* Fix light text from inline styles */
.main-content [style*="color:#333"],
.main-content [style*="color:#444"],
.main-content [style*="color:#555"],
.main-content [style*="color:#666"],
.main-content [style*="color:#000"],
.main-content [style*="color: #333"],
.main-content [style*="color: #444"],
.main-content [style*="color: #555"],
.main-content [style*="color: #666"] {
  color: var(--text-primary) !important;
}

/* Fix any remaining var(--primary) used as text color on dark bg */
.main-content label[style*="color:var(--primary)"],
.main-content span[style*="color:var(--primary)"],
.main-content div[style*="color:var(--primary)"] {
  color: var(--gold) !important;
}

/* Dark import/export buttons */
.btn-import-excel {
  background: rgba(33,115,70,0.15) !important;
  color: #4caf50 !important;
  border-color: rgba(33,115,70,0.3) !important;
}
.btn-import-excel:hover {
  background: #217346 !important;
  color: #fff !important;
}
.btn-import-download {
  background: rgba(66,165,245,0.15) !important;
  color: var(--info) !important;
  border-color: rgba(66,165,245,0.3) !important;
}
.btn-import-download:hover {
  background: var(--info) !important;
  color: #fff !important;
}

/* Date inputs */
input[type="date"],
input[type="month"],
input[type="time"],
input[type="datetime-local"] {
  background: rgba(255,255,255,0.06);
  color: var(--text-primary);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  padding: 8px 12px;
  font-family: var(--font-main);
  color-scheme: dark;
}

input[type="date"]:focus,
input[type="month"]:focus {
  border-color: var(--gold);
  outline: none;
}

/* Custom scrollbar */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--bg-page); }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.25); }

/* Checkbox/radio dark styling */
input[type="checkbox"],
input[type="radio"] {
  accent-color: var(--gold);
}

/* Textarea */
textarea {
  background: rgba(255,255,255,0.06) !important;
  color: var(--text-primary) !important;
  border-color: var(--glass-border) !important;
}
textarea:focus {
  border-color: var(--gold) !important;
  outline: none;
}

/* ============ RTL (Right-to-Left) Support ============ */
/* Only fix specific elements that need RTL adjustment */

/* RTL: Navigation dropdowns - align to RIGHT edge of nav item in Arabic */
[dir="rtl"] .nav-dropdown {
  left: auto;
  right: 0;
}

/* RTL: User dropdown - stays on right side since user-menu is first in HTML */
[dir="rtl"] .user-dropdown {
  right: 0;
  left: auto;
}

/* RTL: Dropdown items text alignment */
[dir="rtl"] .nav-dropdown a,
[dir="rtl"] .user-dropdown a {
  text-align: right;
  direction: rtl;
}

/* RTL: Tables - text alignment */
[dir="rtl"] table th,
[dir="rtl"] table td {
  text-align: right;
}

/* RTL: Alert borders - flip from left to right */
[dir="rtl"] .alert-danger { border-left: none; border-right: 4px solid var(--danger); }
[dir="rtl"] .alert-success { border-left: none; border-right: 4px solid var(--success); }
[dir="rtl"] .alert-warning { border-left: none; border-right: 4px solid var(--warning); }
[dir="rtl"] .alert-info { border-left: none; border-right: 4px solid var(--info); }

/* RTL: Form labels alignment */
[dir="rtl"] .form-group label,
[dir="rtl"] .form-label {
  text-align: right;
}

/* RTL: Page content text direction */
[dir="rtl"] .page-title,
[dir="rtl"] .year-info,
[dir="rtl"] .no-data {
  text-align: right;
}


/* ============================================
   RTL (Arabic) Comprehensive Support
   ============================================ */

/* Base RTL */
[dir="rtl"] {
    font-family: var(--font-ar);
    text-align: right;
    direction: rtl;
}

/* Header */
[dir="rtl"] .header {
    flex-direction: row-reverse;
}

/* Nav */
[dir="rtl"] .nav-dropdown {
    left: auto;
    right: 0;
}
[dir="rtl"] .user-dropdown {
    right: 0;
    left: auto;
}
[dir="rtl"] .nav-dropdown a,
[dir="rtl"] .user-dropdown a {
    text-align: right;
}

/* Form inputs */
[dir="rtl"] .form-control {
    text-align: right;
}
[dir="rtl"] .input-icon-wrapper .form-control {
    padding-left: 16px;
    padding-right: 44px;
}
[dir="rtl"] .input-icon-wrapper i {
    left: auto;
    right: 14px;
}
[dir="rtl"] .form-group label,
[dir="rtl"] .detail-item .label {
    text-align: right;
}

/* Alerts */
[dir="rtl"] .alert { border-left: none; }
[dir="rtl"] .alert-danger { border-right: 4px solid var(--danger); }
[dir="rtl"] .alert-success { border-right: 4px solid var(--success); }
[dir="rtl"] .alert-warning { border-right: 4px solid var(--warning); }
[dir="rtl"] .alert-info { border-right: 4px solid var(--info); }

/* Stat cards */
[dir="rtl"] .stat-card::before {
    left: auto;
    right: 0;
}

/* Tables */
[dir="rtl"] th,
[dir="rtl"] td {
    text-align: right;
}

/* Modal */
[dir="rtl"] .modal-header .close {
    margin-left: 0;
    margin-right: auto;
}

/* Detail grid */
[dir="rtl"] .detail-grid {
    text-align: right;
}
[dir="rtl"] .detail-item .value {
    text-align: right;
}

/* Stat card info text alignment */
[dir="rtl"] .stat-card-info {
    text-align: right;
}
[dir="rtl"] .stat-card-info h3,
[dir="rtl"] .stat-card-info p {
    text-align: right;
}

/* Chart headers */
[dir="rtl"] .chart-header {
    text-align: right;
}
[dir="rtl"] .chart-header span,
[dir="rtl"] .chart-header h3 {
    text-align: right;
}

/* Sub navigation tabs */
[dir="rtl"] .sub-nav {
    direction: rtl;
}

/* Page title */
[dir="rtl"] .page-title {
    text-align: right;
}

/* Section titles */
[dir="rtl"] .section-title {
    text-align: right;
}

/* Login card */
[dir="rtl"] .login-card {
    text-align: right;
}

/* Date display */
[dir="rtl"] .date-display {
    text-align: right;
}

/* Empty states */
[dir="rtl"] .empty-state {
    text-align: center;
}

/* Table header */
[dir="rtl"] .table-header {
    direction: rtl;
}

/* View more links */
[dir="rtl"] .stat-card a {
    text-align: right;
}

/* ============ Mobile Menu Button ============ */
.mobile-menu-btn {
  display: none;
  background: rgba(255,255,255,0.12);
  border: none;
  color: white;
  width: 38px;
  height: 38px;
  border-radius: var(--radius);
  font-size: 1.2rem;
  cursor: pointer;
  transition: var(--transition);
  align-items: center;
  justify-content: center;
}
.mobile-menu-btn:hover { background: rgba(255,255,255,0.2); }

/* ============ Responsive — Tablet (max 1024px) ============ */
@media (max-width: 1024px) {
  .header { padding: 0 16px; }
  .header-title { font-size: 1rem; }
  .main-content { padding: 12px 16px; }
  .stats-grid { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; }
  .charts-grid { grid-template-columns: 1fr; }
  .students-grid { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
  .sub-nav { padding: 10px 16px; gap: 2px; }
  .sub-nav a { padding: 6px 12px; font-size: .82rem; }
  .nav-link { padding: 12px 10px; font-size: .82rem; }
  .user-name { display: none; }
  table { font-size: .82rem; }
  thead th, tbody td { padding: 10px 10px; }
}

/* ============ Responsive — Mobile (max 768px) ============ */
@media (max-width: 768px) {
  :root { --header-height: 54px; --nav-height: 0px; }

  /* Header */
  .header { padding: 0 12px; }
  .header-title { font-size: .88rem; max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .header-logo { width: 36px; height: 36px; }
  .header-left { gap: 10px; }
  .header-right { gap: 8px; }
  .header-icon { width: 32px; height: 32px; font-size: .95rem; }
  .user-name { display: none; }
  .user-menu { padding: 3px 6px; }
  .user-avatar { width: 30px; height: 30px; }
  .mobile-menu-btn { display: flex; }

  /* Navigation — Hamburger */
  .main-nav {
    position: fixed;
    top: var(--header-height);
    left: 0;
    width: 280px;
    height: calc(100vh - var(--header-height));
    background: rgba(6,14,26,.98);
    transform: translateX(-100%);
    transition: transform .3s ease;
    z-index: 9999;
    overflow-y: auto;
    flex-direction: column;
    border-right: 1px solid var(--glass-border);
    display: flex;
  }
  [dir="rtl"] .main-nav {
    left: auto;
    right: 0;
    transform: translateX(100%);
    border-right: none;
    border-left: 1px solid var(--glass-border);
  }
  .main-nav.mobile-open {
    transform: translateX(0) !important;
  }
  .nav-container {
    flex-direction: column;
    padding: 8px 0;
    align-items: stretch;
  }
  .nav-item { width: 100%; }
  .nav-link {
    padding: 14px 20px;
    border-bottom: none;
    border-left: 3px solid transparent;
    font-size: .9rem;
  }
  .nav-link:hover, .nav-link.active {
    border-bottom: none;
    border-left-color: var(--gold);
    background: rgba(249,168,37,.08);
  }
  [dir="rtl"] .nav-link {
    border-left: none;
    border-right: 3px solid transparent;
  }
  [dir="rtl"] .nav-link:hover, [dir="rtl"] .nav-link.active {
    border-right-color: var(--gold);
  }
  .nav-dropdown {
    position: static;
    min-width: auto;
    box-shadow: none;
    border: none;
    border-radius: 0;
    background: rgba(255,255,255,.02);
    padding: 0;
  }
  .nav-dropdown a { padding: 12px 20px 12px 40px; font-size: .85rem; }
  [dir="rtl"] .nav-dropdown a { padding: 12px 40px 12px 20px; }
  .settings-nav { padding: 0; width: 100%; }
  .settings-nav .nav-item { width: 100%; }

  /* Content */
  .main-content { margin-top: calc(var(--header-height) + 5px); padding: 12px; }
  .sub-nav { padding: 8px 12px; gap: 4px; overflow-x: auto; flex-wrap: nowrap; }
  .sub-nav a { padding: 6px 10px; font-size: .78rem; white-space: nowrap; flex-shrink: 0; }

  /* Stats */
  .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 18px; }
  .stat-card { padding: 14px; gap: 10px; }
  .stat-icon { width: 42px; height: 42px; font-size: 1.1rem; }
  .stat-number { font-size: 1.3rem; }
  .stat-label { font-size: .78rem; }

  /* Charts */
  .charts-grid { grid-template-columns: 1fr; gap: 14px; }
  .chart-body { padding: 12px; min-height: 160px; }

  /* Tables */
  .table-container { border-radius: var(--radius); }
  .table-header { padding: 12px 14px; flex-wrap: wrap; gap: 8px; }
  .table-header h3 { font-size: .95rem; }
  table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  thead th { padding: 8px 10px; font-size: .75rem; white-space: nowrap; }
  tbody td { padding: 8px 10px; font-size: .8rem; white-space: nowrap; }

  /* Cards */
  .students-grid { grid-template-columns: 1fr; gap: 12px; }
  .student-card-header h4 { max-width: 200px; }

  /* Modals */
  .modal-content { width: 95%; max-width: 95%; margin: 10px auto; max-height: 90vh; overflow-y: auto; }
  .modal-header { padding: 14px 16px; }
  .modal-header h3 { font-size: .95rem; }
  .modal-body { padding: 16px; }
  .modal-footer { padding: 12px 16px; flex-wrap: wrap; }
  .modal-tabs { overflow-x: auto; }
  .modal-tab { padding: 10px 14px; font-size: .8rem; }

  /* Forms */
  .form-control { padding: 10px 12px; font-size: .88rem; }
  .btn { padding: 10px 18px; font-size: .88rem; }
  .filters-bar { padding: 16px; gap: 12px; }
  .filters-bar select, .filters-bar input { font-size: .9rem; padding: 10px 12px; }

  /* Messaging */
  .msg-settings { padding: 16px; }
  .msg-settings .row { gap: 10px; }
  .msg-card-top { padding: 10px 14px; flex-direction: column; align-items: flex-start; gap: 8px; }
  .msg-body { padding: 10px 14px; }
  .msg-reply { padding: 10px 14px; }
  .msg-actions { padding: 8px 14px; flex-wrap: wrap; }
  .reply-form { padding: 10px 14px; }

  /* Notifications dropdown */
  .notif-dropdown { position: fixed !important; left: 50% !important; right: auto !important; top: 60px !important; transform: translateX(-50%); width: 320px; max-width: 92vw; }
  [dir="rtl"] .notif-dropdown { left: 50% !important; right: auto !important; transform: translateX(-50%); }
  .user-dropdown { min-width: 180px; }

  /* Filter bar */
  .filter-bar { flex-direction: column; }
  .filter-bar select { width: 100%; }

  /* Child switcher */
  .child-switcher { padding: 8px 12px !important; gap: 8px !important; }
}

/* ============ Responsive — Small Mobile (max 480px) ============ */
@media (max-width: 480px) {
  .header-title { font-size: .8rem; max-width: 100px; }
  .header-logo { width: 32px; height: 32px; }
  .stats-grid { grid-template-columns: 1fr; }
  .stat-card { padding: 12px; }
  .stat-icon { width: 38px; height: 38px; font-size: 1rem; }
  .stat-number { font-size: 1.1rem; }
  .login-card { padding: 24px 20px; }
  .sub-nav a { padding: 5px 8px; font-size: .72rem; }
  .msg-stats { flex-direction: column; }
  .msg-stat { min-width: 100%; }
  .days-grid { gap: 4px; }
  .day-chip { padding: 4px 10px; font-size: .72rem; }
}

/* ============ Mobile Nav Overlay ============ */
@media (max-width: 768px) {
  .nav-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,.5);
    z-index: 9998;
  }
  .main-nav.mobile-open ~ .nav-overlay { display: block; }
}

/* ============ Print Styles ============ */
@media print {
  .header, .main-nav, .sub-nav, .mobile-menu-btn, .btn, .filter-bar, .msg-settings { display: none !important; }
  .main-content { margin-top: 0; padding: 0; }
  body { background: white; color: black; }
  .table-container { box-shadow: none; border: 1px solid #ddd; }
}

/* ============ Universal Mobile & Tablet Grid Safeguards ============ */
@media screen and (max-width: 1024px) {
  .main-content [style*="grid-column: span 2"],
  .main-content [style*="grid-column:span 2"],
  .main-content [style*="grid-column: 1/3"],
  .main-content [style*="grid-column:1/3"],
  .main-content [style*="grid-column: 1 / 3"] {
    grid-column: 1 / -1 !important;
  }
}

@media screen and (max-width: 640px) {
  .main-content form [style*="grid-template-columns:1fr 1fr"],
  .main-content form [style*="grid-template-columns: 1fr 1fr"],
  .main-content form [style*="grid-template-columns:1.5fr 1fr"],
  .main-content form [style*="grid-template-columns:repeat(3"],
  .main-content form [style*="grid-template-columns: repeat(3"],
  .modal [style*="grid-template-columns:1fr 1fr"],
  .modal [style*="grid-template-columns: 1fr 1fr"],
  .modal [style*="grid-template-columns:repeat(3"],
  .modal [style*="grid-template-columns: repeat(3"] {
    grid-template-columns: minmax(0, 1fr) !important;
  }
  .main-content .ts-engage > div[style*="grid-template-columns:repeat(4"] {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }
}
