/* ===== CSS Variables & Reset ===== */
:root {
  --primary: #0078D4;
  --primary-dark: #005A9E;
  --primary-light: #C7E0F4;
  --primary-bg: #E8F4FD;
  --sidebar-bg: #1B2A4A;
  --sidebar-hover: #243B6A;
  --sidebar-active: #0078D4;
  --success: #0F7B0F;
  --danger: #C42B1C;
  --warning: #9D5D00;
  --info: #0078D4;
  --bg: #F3F3F3;
  --surface: #FFFFFF;
  --surface-hover: #F9F9F9;
  --border: #E0E0E0;
  --border-focus: #0078D4;
  --text: #1A1A1A;
  --text-secondary: #616161;
  --text-light: #FFFFFF;
  --shadow: 0 2px 8px rgba(0,0,0,0.08);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.12);
  --radius: 8px;
  --radius-sm: 4px;
  --radius-lg: 12px;
  --transition: 0.2s ease;
}

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

body {
  font-family: 'Segoe UI', Tahoma, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  direction: rtl;
  line-height: 1.5;
}

/* ===== Login Screen ===== */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #0f0c29 0%, #302b63 50%, #24243e 100%);
  position: relative;
  overflow: hidden;
}

.login-screen::before {
  content: '';
  position: absolute;
  width: 600px;
  height: 600px;
  background: radial-gradient(circle, rgba(0,120,212,0.3) 0%, transparent 70%);
  top: -200px;
  left: -200px;
  animation: floatOrb 8s ease-in-out infinite;
}

.login-screen::after {
  content: '';
  position: absolute;
  width: 500px;
  height: 500px;
  background: radial-gradient(circle, rgba(120,80,212,0.25) 0%, transparent 70%);
  bottom: -150px;
  right: -150px;
  animation: floatOrb 10s ease-in-out infinite reverse;
}

@keyframes floatOrb {
  0%, 100% { transform: translate(0, 0) scale(1); }
  33% { transform: translate(30px, -40px) scale(1.05); }
  66% { transform: translate(-20px, 30px) scale(0.95); }
}

.login-container {
  display: flex;
  background: rgba(255,255,255,0.07);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 20px;
  overflow: hidden;
  max-width: 920px;
  width: 92%;
  min-height: 520px;
  box-shadow: 0 25px 60px rgba(0,0,0,0.4);
  position: relative;
  z-index: 1;
}

.login-brand {
  flex: 1.1;
  background: linear-gradient(135deg, #0078D4 0%, #5B5FC7 100%);
  color: #fff;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 48px 40px;
  text-align: center;
  position: relative;
  overflow: hidden;
}

.login-brand::before {
  content: '';
  position: absolute;
  width: 200%;
  height: 200%;
  background: repeating-linear-gradient(45deg, transparent, transparent 30px, rgba(255,255,255,0.03) 30px, rgba(255,255,255,0.03) 60px);
}

.login-brand-icon {
  width: 90px;
  height: 90px;
  background: rgba(255,255,255,0.15);
  border-radius: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 44px;
  margin-bottom: 20px;
  position: relative;
  z-index: 1;
  border: 1px solid rgba(255,255,255,0.2);
}

.login-brand h1 {
  font-size: 32px;
  font-weight: 800;
  margin-bottom: 8px;
  position: relative;
  z-index: 1;
  letter-spacing: -0.5px;
}

.login-brand .brand-subtitle {
  font-size: 15px;
  opacity: 0.85;
  position: relative;
  z-index: 1;
  line-height: 1.6;
}

.login-brand .brand-features {
  margin-top: 32px;
  position: relative;
  z-index: 1;
  text-align: right;
}

.login-brand .brand-features li {
  list-style: none;
  padding: 6px 0;
  font-size: 13px;
  opacity: 0.8;
  display: flex;
  align-items: center;
  gap: 8px;
}

.login-brand .brand-features li::before {
  content: '✓';
  width: 20px;
  height: 20px;
  background: rgba(255,255,255,0.2);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  flex-shrink: 0;
}

.login-card {
  flex: 1;
  padding: 48px 44px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  background: rgba(255,255,255,0.95);
}

.login-card h2 {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 6px;
  color: #1a1a2e;
}

.login-card .login-subtitle {
  font-size: 13px;
  color: #888;
  margin-bottom: 32px;
}

/* Floating Label Inputs */
.login-field {
  position: relative;
  margin-bottom: 22px;
}

.login-field input {
  width: 100%;
  padding: 14px 16px 14px 44px;
  border: 2px solid #E8E8E8;
  border-radius: 12px;
  font-size: 14px;
  font-family: inherit;
  background: #FAFAFA;
  color: #1a1a2e;
  transition: all 0.3s ease;
  direction: ltr;
  text-align: left;
}

.login-field input:focus {
  outline: none;
  border-color: #0078D4;
  background: #fff;
  box-shadow: 0 0 0 4px rgba(0,120,212,0.1);
}

.login-field input.error {
  border-color: #C42B1C;
  box-shadow: 0 0 0 4px rgba(196,43,28,0.1);
}

.login-field input:disabled {
  background: #F0F0F0;
  cursor: not-allowed;
}

.login-field .field-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 18px;
  opacity: 0.5;
  pointer-events: none;
  transition: opacity 0.3s;
}

.login-field input:focus ~ .field-icon {
  opacity: 0.8;
}

.login-field label {
  position: absolute;
  left: 44px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 14px;
  color: #999;
  pointer-events: none;
  transition: all 0.3s ease;
  background: transparent;
  padding: 0 4px;
}

.login-field input:focus ~ label,
.login-field input:not(:placeholder-shown) ~ label {
  top: -8px;
  left: 12px;
  font-size: 11px;
  color: #0078D4;
  background: #fff;
  font-weight: 600;
}

.login-field input.error:focus ~ label,
.login-field input.error:not(:placeholder-shown) ~ label {
  color: #C42B1C;
}

.login-field .toggle-password {
  position: absolute;
  right: 14px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  cursor: pointer;
  font-size: 18px;
  opacity: 0.4;
  padding: 4px;
  transition: opacity 0.2s;
}

.login-field .toggle-password:hover {
  opacity: 0.8;
}

.error-message {
  background: #FEF0F0;
  color: #C42B1C;
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 13px;
  margin-bottom: 16px;
  text-align: center;
  border: 1px solid #FECDD3;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.login-btn {
  width: 100%;
  padding: 14px;
  border: none;
  border-radius: 12px;
  font-size: 15px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  background: linear-gradient(135deg, #0078D4, #5B5FC7);
  color: #fff;
  transition: all 0.3s ease;
  position: relative;
  overflow: hidden;
  margin-top: 4px;
}

.login-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 24px rgba(0,120,212,0.35);
}

.login-btn:active {
  transform: translateY(0);
}

.login-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.login-btn .spinner {
  display: none;
  width: 20px;
  height: 20px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  margin: 0 auto;
}

.login-btn.loading .btn-text { display: none; }
.login-btn.loading .spinner { display: inline-block; }

@keyframes spin { to { transform: rotate(360deg); } }

.login-footer {
  margin-top: 24px;
  text-align: center;
  font-size: 11px;
  color: #aaa;
}

/* ===== Form Elements ===== */
.form-group { margin-bottom: 16px; }
.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.form-input, .form-select {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
  transition: border-color var(--transition);
  direction: rtl;
}

.form-input:focus, .form-select:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 2px rgba(0,120,212,0.15);
}

.form-inline {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.form-inline .form-input { flex: 1; }

/* ===== Buttons ===== */
.btn {
  padding: 10px 24px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all var(--transition);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.btn:active { transform: scale(0.97); }

.btn-primary { background: var(--primary); color: var(--text-light); }
.btn-primary:hover { background: var(--primary-dark); }

.btn-secondary { background: #E1E1E1; color: var(--text); }
.btn-secondary:hover { background: #D1D1D1; }

.btn-danger { background: var(--danger); color: var(--text-light); }
.btn-danger:hover { background: #A52019; }

.btn-outline-light {
  background: transparent;
  color: var(--text-light);
  border: 1px solid rgba(255,255,255,0.3);
}
.btn-outline-light:hover { background: rgba(255,255,255,0.1); }

.btn-sm { padding: 6px 16px; font-size: 13px; }
.btn-full { width: 100%; justify-content: center; }

.btn-group { display: flex; gap: 8px; margin: 12px 0; flex-wrap: wrap; }

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

/* Sidebar */
.sidebar {
  width: 260px;
  background: var(--sidebar-bg);
  color: var(--text-light);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 100;
}

.sidebar-brand {
  padding: 20px 24px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
}

.brand-icon { font-size: 28px; }
.brand-text { font-size: 20px; font-weight: 700; }

.sidebar-nav { flex: 1; padding: 12px; overflow-y: auto; }

.nav-btn {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border: none;
  background: transparent;
  color: rgba(255,255,255,0.75);
  font-size: 14px;
  font-family: inherit;
  border-radius: var(--radius);
  cursor: pointer;
  transition: all var(--transition);
  text-align: right;
}

.nav-btn:hover { background: var(--sidebar-hover); color: var(--text-light); }
.nav-btn.active { background: var(--sidebar-active); color: var(--text-light); }
.nav-icon { font-size: 18px; width: 24px; text-align: center; }

.sidebar-footer {
  padding: 16px;
  border-top: 1px solid rgba(255,255,255,0.1);
}

/* Main Content */
.main-content {
  flex: 1;
  margin-right: 260px;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.header {
  background: var(--surface);
  padding: 16px 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
}

.header h2 { font-size: 20px; font-weight: 600; }
.header-info { font-size: 13px; color: var(--text-secondary); }

.page-container { padding: 24px 32px; flex: 1; }

/* ===== Pages ===== */
.page { display: none; }
.page.active { display: block; animation: fadeIn 0.3s ease; }

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

/* ===== Cards ===== */
.card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 24px;
  margin-bottom: 20px;
}

.card h3 {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

/* ===== Stats Grid ===== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 16px;
}

.stat-icon { font-size: 36px; }
.stat-value { font-size: 28px; font-weight: 700; }
.stat-label { font-size: 13px; color: var(--text-secondary); }

.stat-primary { border-right: 4px solid var(--primary); }
.stat-success { border-right: 4px solid var(--success); }
.stat-info { border-right: 4px solid var(--info); }
.stat-warning { border-right: 4px solid var(--warning); }

/* ===== Quick Actions ===== */
.quick-actions { margin-bottom: 24px; }
.quick-actions h3 { font-size: 16px; margin-bottom: 12px; }

.actions-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
}

.action-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
  cursor: pointer;
  transition: all var(--transition);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  font-family: inherit;
  font-size: 13px;
}

.action-card:hover { border-color: var(--primary); background: var(--primary-bg); }
.action-icon { font-size: 28px; }

/* ===== Data Tables ===== */
.table-container { overflow-x: auto; margin-top: 12px; }

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.data-table th {
  background: #F5F5F5;
  padding: 10px 14px;
  text-align: right;
  font-weight: 600;
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}

.data-table td {
  padding: 10px 14px;
  border-bottom: 1px solid #F0F0F0;
  white-space: nowrap;
}

.data-table tr:hover td { background: #F9FBFD; }
.data-table tr.selected td { background: var(--primary-bg); }

.data-table tr.synced td { color: var(--text-secondary); }

/* ===== Layouts ===== */
.three-col-layout {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 20px;
}

.split-layout {
  display: grid;
  grid-template-columns: 340px 1fr;
  gap: 20px;
  align-items: start;
}

.form-card { position: sticky; top: 80px; }

.filter-bar {
  display: flex;
  gap: 12px;
  margin-bottom: 20px;
  flex-wrap: wrap;
  align-items: center;
}

.filter-bar .form-select,
.filter-bar .form-input { width: auto; min-width: 180px; flex: none; }

/* ===== Search ===== */
.search-bar { margin-bottom: 12px; }
.search-bar .form-input { max-width: 360px; }

/* ===== Tabs ===== */
.tab-header { display: flex; gap: 4px; margin-bottom: 20px; }

.tab-btn {
  padding: 10px 24px;
  border: none;
  background: transparent;
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  color: var(--text-secondary);
  transition: all var(--transition);
}

.tab-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
  font-weight: 600;
}

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

/* ===== Recent Activity ===== */
.recent-activity { font-size: 13px; }
.recent-activity-item {
  padding: 10px 0;
  border-bottom: 1px solid #F0F0F0;
  display: flex;
  justify-content: space-between;
}
.recent-activity-item:last-child { border-bottom: none; }

/* ===== Checkbox Group ===== */
.checkbox-group {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  cursor: pointer;
}

/* ===== Mapping ===== */
.mapping-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
  padding: 8px;
  background: #F9F9F9;
  border-radius: var(--radius-sm);
}

.mapping-row label { min-width: 120px; font-weight: 600; font-size: 13px; }
.mapping-row select { flex: 1; }

/* ===== Grade Grid (Dynamic) ===== */
.grade-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.grade-table th {
  background: #E8F4FD;
  padding: 10px 14px;
  text-align: center;
  font-weight: 600;
  border: 1px solid var(--border);
  white-space: nowrap;
}

.grade-table th.name-col {
  text-align: right;
  background: #F5F5F5;
}

.grade-table th.total-col {
  background: #FFF8E1;
}

.grade-table td {
  padding: 6px 8px;
  border: 1px solid var(--border);
  text-align: center;
}

.grade-table td.name-col {
  text-align: right;
  background: #FAFAFA;
  font-weight: 500;
  white-space: nowrap;
}

.grade-table td.total-col {
  background: #FFF8E1;
  font-weight: 700;
}

.grade-table input {
  width: 70px;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  text-align: center;
  font-size: 13px;
  font-family: inherit;
}

.grade-table input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(0,120,212,0.15);
}

/* ===== Attendance Grid ===== */
.att-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.att-table th {
  background: #F5F5F5;
  padding: 10px 14px;
  text-align: center;
  font-weight: 600;
  border: 1px solid var(--border);
}

.att-table th.name-col { text-align: right; }

.att-table td {
  padding: 8px 12px;
  border: 1px solid var(--border);
  text-align: center;
}

.att-table td.name-col {
  text-align: right;
  font-weight: 500;
}

.att-table tr.present td { background: #FFFFFF; }
.att-table tr.absent td { background: #FDE7E9; }
.att-table tr.excused td { background: #FFF3E0; }

.att-radio-group { display: flex; gap: 4px; justify-content: center; }

.att-radio {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  transition: all var(--transition);
}

.att-radio input { display: none; }
.att-radio.checked { border-color: var(--primary); background: var(--primary-bg); }
.att-radio.absent.checked { border-color: var(--danger); background: #FDE7E9; }
.att-radio.excused.checked { border-color: var(--warning); background: #FFF3E0; }

.att-notes {
  width: 120px;
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-family: inherit;
}

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: #333;
  color: var(--text-light);
  padding: 12px 24px;
  border-radius: var(--radius);
  font-size: 14px;
  z-index: 10000;
  animation: toastIn 0.3s ease;
  box-shadow: var(--shadow-lg);
}

.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }
.toast.info { background: var(--primary); }

@keyframes toastIn {
  from { opacity: 0; transform: translateX(-50%) translateY(16px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ===== Modal ===== */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}

.modal-content {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 32px;
  box-shadow: var(--shadow-lg);
  min-width: 360px;
  text-align: center;
}

.modal-sm { max-width: 400px; }
.modal-content h3 { margin-bottom: 12px; }
.modal-content p { margin-bottom: 20px; color: var(--text-secondary); }

/* ===== Sync Panel ===== */
.sync-panel {
  background: #1B2A4A;
  color: var(--text-light);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  margin: 0 -32px;
  animation: slideUp 0.3s ease;
}

.sync-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
  font-weight: 600;
}

.sync-log {
  padding: 16px 24px;
  max-height: 240px;
  overflow-y: auto;
  font-family: 'Consolas', 'Courier New', monospace;
  font-size: 13px;
  line-height: 1.8;
}

.sync-log .log-line { white-space: pre-wrap; word-break: break-all; }
.sync-log .log-line.blue { color: #5B9BD5; }
.sync-log .log-line.green { color: #6BCB77; }
.sync-log .log-line.red { color: #FF6B6B; }
.sync-log .log-line.purple { color: #C792EA; }
.sync-log .log-line.gray { color: #999; }

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

/* ===== Login Hardening ===== */
.form-input.error { border-color: var(--danger); box-shadow: 0 0 0 2px rgba(196,43,28,0.15); }
.form-input:disabled { background: #F0F0F0; cursor: not-allowed; opacity: 0.7; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.login-attempts-warning {
  background: #FFF3E0;
  color: var(--warning);
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  margin-bottom: 12px;
  text-align: center;
}

/* ===== Placeholder ===== */
.placeholder-text {
  text-align: center;
  color: var(--text-secondary);
  padding: 40px;
  font-size: 14px;
}

/* ===== Responsive ===== */
@media (max-width: 1200px) {
  .three-col-layout { grid-template-columns: 1fr; }
  .split-layout { grid-template-columns: 1fr; }
  .form-card { position: static; }
}

@media (max-width: 768px) {
  .sidebar {
    width: 60px;
    overflow: hidden;
  }
  .sidebar-brand .brand-text,
  .nav-btn span:not(.nav-icon),
  .sidebar-footer { display: none; }
  .nav-btn { justify-content: center; padding: 14px; }
  .main-content { margin-right: 60px; }
  .page-container { padding: 16px; }
  .filter-bar { flex-direction: column; }
  .filter-bar .form-select,
  .filter-bar .form-input { width: 100%; }
  .login-container { flex-direction: column; max-width: 420px; min-height: auto; }
  .login-brand { padding: 32px 24px; }
  .login-brand::before { display: none; }
  .login-brand-icon { width: 64px; height: 64px; font-size: 32px; border-radius: 16px; }
  .login-brand h1 { font-size: 24px; }
  .login-brand .brand-features { display: none; }
  .login-card { padding: 32px 24px; }
}

/* ===== Mobile Menu Button ===== */
.mobile-menu-btn { display: none; }

.sidebar-backdrop { display: none; }

/* ===== Full Mobile Support (phones & small tablets) ===== */
@media (max-width: 768px) {
  /* Hamburger button */
  .mobile-menu-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 42px; height: 42px;
    font-size: 20px;
    background: var(--bg-secondary, #f1f5f9);
    border: 1px solid var(--border-color, #e2e8f0);
    border-radius: 10px;
    cursor: pointer;
    color: inherit;
  }
  .mobile-menu-btn:active { transform: scale(0.95); }

  /* Sidebar becomes slide-in drawer */
  .app-shell { flex-direction: column; }
  .sidebar {
    position: fixed !important;
    top: 0; right: -280px;
    width: 270px !important;
    height: 100vh; height: 100dvh;
    z-index: 1000;
    overflow-y: auto;
    transition: right 0.28s ease;
    box-shadow: -4px 0 24px rgba(0,0,0,0.18);
  }
  .sidebar.open { right: 0; }
  .sidebar-brand .brand-text,
  .nav-btn span:not(.nav-icon),
  .sidebar-footer {
    display: block !important;
  }
  .nav-btn { justify-content: flex-start !important; padding: 14px 16px !important; }

  /* Backdrop */
  .sidebar-backdrop.show {
    display: block;
    position: fixed; inset: 0;
    background: rgba(15,23,42,0.5);
    z-index: 999;
    backdrop-filter: blur(2px);
  }

  /* Content takes full width */
  .main-content { margin-right: 0 !important; }
  .page-container { padding: 12px !important; }
  .header { padding: 12px 16px !important; position: sticky; top: 0; z-index: 50; }
  .header h2 { font-size: 17px !important; }

  /* Tables scroll horizontally with touch */
  .table-container {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: 8px;
  }
  .table-container table { min-width: 520px; }
  .data-table th, .data-table td { padding: 10px 12px !important; font-size: 13px !important; }

  /* Collapse layout grids to single column */
  .split-layout,
  .three-col-layout,
  .form-card { grid-template-columns: 1fr !important; }

  /* Touch-friendly controls */
  .btn { min-height: 44px; font-size: 14px; }
  .form-input, .form-select, input, select, textarea { font-size: 16px !important; min-height: 44px; }
  .nav-btn { min-height: 48px; }

  /* Cards tighter */
  .card { margin-bottom: 12px; }
  .card-header { padding: 14px 16px !important; }
  .card-body { padding: 14px 16px !important; }

  /* Filter bars stack */
  .filter-bar { gap: 10px; }

  /* Sync panel full-width */
  .sync-panel { width: calc(100% - 24px) !important; right: 12px !important; left: 12px !important; max-height: 60vh; overflow-y: auto; }

  /* Tabs scrollable if many */
  .tabs { overflow-x: auto; white-space: nowrap; -webkit-overflow-scrolling: touch; }
}

/* Very small phones */
@media (max-width: 380px) {
  .page-container { padding: 8px !important; }
  .header h2 { font-size: 15px !important; }
  .login-brand h1 { font-size: 20px; }
}

/* ============================================================
   Universal Responsive System - phones / tablets / desktops
   ============================================================ */

/* --- Large desktops & 4K: keep content readable --- */
@media (min-width: 1600px) {
  .page-container { max-width: 1480px; margin: 0 auto; }
}

/* --- Tablets (portrait & landscape) --- */
@media (min-width: 769px) and (max-width: 1100px) {
  .sidebar { width: 210px !important; }
  .main-content { margin-right: 210px !important; }
  .three-col-layout { grid-template-columns: repeat(2, 1fr); }
  .split-layout { grid-template-columns: 280px 1fr; }
  .form-card { position: static !important; }
}

/* --- Phones: modals, mapping rows, tabs, filters --- */
@media (max-width: 768px) {
  /* Modal dialogs fit screen */
  .modal-content {
    width: calc(100% - 28px) !important;
    max-width: none !important;
    max-height: 85vh;
    overflow-y: auto;
    margin: auto;
  }
  .modal-sm { width: calc(100% - 28px) !important; }

  /* CSV import mapping rows wrap nicely */
  .mapping-row { flex-wrap: wrap; gap: 8px; }
  .mapping-row > * { flex: 1 1 140px; min-width: 130px; }
  .mapping-row select { width: 100% !important; min-height: 44px; }

  /* Tab strip scrolls horizontally instead of breaking */
  .tab-header {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    white-space: nowrap;
    padding-bottom: 4px;
    scrollbar-width: thin;
  }
  .tab-btn { display: inline-block; min-height: 42px; flex: none; }

  /* Search + filter bars go full width */
  .search-bar .form-input { max-width: 100%; width: 100%; }
  .filter-bar { flex-wrap: wrap; gap: 10px; }
  .filter-bar .form-select,
  .filter-bar .form-input {
    min-width: 0 !important;
    flex: 1 1 100%;
    width: 100% !important;
  }

  /* Stat cards: 2 per row on narrow screens */
  .stats-grid { grid-template-columns: repeat(2, 1fr) !important; gap: 10px; }
  .stat-card { padding: 14px 12px !important; }
  .stat-icon { font-size: 26px !important; }
  .stat-value { font-size: 22px !important; }

  /* Action cards: comfortable touch grid */
  .actions-grid { grid-template-columns: repeat(2, 1fr) !important; gap: 10px; }
}

/* --- Landscape phones: save vertical space --- */
@media (max-height: 460px) and (orientation: landscape) {
  .header { position: static !important; padding: 8px 12px !important; }
  .page-container { padding-top: 8px !important; }
  .login-screen { align-items: flex-start; overflow-y: auto; padding: 20px 0; }
  .login-container { margin: 16px auto; }
  .login-brand { display: none; }
  .login-card { padding: 20px !important; }
}

/* --- iPad Pro / big tablets get full sidebar back --- */
@media (min-width: 1101px) {
  .mobile-menu-btn { display: none !important; }
  .sidebar-backdrop { display: none !important; }
}

/* ============================================================
   Mobile: simple record tables become tappable stacked cards
   (grades grid / attendance sheet / reports keep h-scroll)
   ============================================================ */
@media (max-width: 768px) {
  #tblUniversities, #tblColleges, #tblBatches, #tblStudents,
  #tblCourses, #tblAssessments, #tblUsers {
    display: block;
    min-width: 0 !important;
    background: transparent;
  }
  #tblUniversities thead, #tblColleges thead, #tblBatches thead,
  #tblStudents thead, #tblCourses thead, #tblAssessments thead,
  #tblUsers thead { display: none; }

  #tblUniversities tr, #tblColleges tr, #tblBatches tr,
  #tblStudents tr, #tblCourses tr, #tblAssessments tr,
  #tblUsers tr {
    display: block;
    background: var(--surface, #fff);
    border: 1px solid var(--border-color, #e2e8f0);
    border-radius: 12px;
    padding: 6px 14px;
    margin-bottom: 10px;
    cursor: pointer;
    transition: box-shadow .15s ease, transform .15s ease;
  }
  #tblUniversities tr:active, #tblColleges tr:active, #tblBatches tr:active,
  #tblStudents tr:active, #tblCourses tr:active, #tblAssessments tr:active,
  #tblUsers tr:active { transform: scale(0.99); }

  #tblUniversities tr.selected, #tblColleges tr.selected, #tblBatches tr.selected,
  #tblStudents tr.selected, #tblCourses tr.selected, #tblAssessments tr.selected,
  #tblUsers tr.selected {
    border-color: var(--primary, #0078d4) !important;
    box-shadow: 0 2px 10px rgba(0,120,212,0.18);
    background: rgba(0,120,212,0.05);
  }

  #tblUniversities td, #tblColleges td, #tblBatches td,
  #tblStudents td, #tblCourses td, #tblAssessments td,
  #tblUsers td {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 12px;
    padding: 8px 0 !important;
    border-bottom: 1px dashed rgba(148,163,184,0.35);
    text-align: left;
    word-break: break-word;
  }
  #tblUniversities td:last-child, #tblColleges td:last-child,
  #tblBatches td:last-child, #tblStudents td:last-child,
  #tblCourses td:last-child, #tblAssessments td:last-child,
  #tblUsers td:last-child { border-bottom: none; }

  #tblUniversities td::before, #tblColleges td::before,
  #tblBatches td::before, #tblStudents td::before,
  #tblCourses td::before, #tblAssessments td::before,
  #tblUsers td::before {
    content: attr(data-label);
    flex: none;
    font-weight: 600;
    font-size: 12px;
    color: var(--text-secondary, #64748b);
    white-space: nowrap;
  }
}

/* ===== My Account card (users page) ===== */
.my-account-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 4px 16px;
  align-items: end;
}
.my-account-grid .btn-group { margin-top: 8px; }
@media (max-width: 768px) {
  .my-account-grid { grid-template-columns: 1fr; }
}
