:root {
  --ink: #0f172a;
  --ink-secondary: #334155;
  --muted: #64748b;
  --line: #e2e8f0;
  --line-strong: #cbd5e1;
  --brand: #2563eb;
  --brand-hover: #1d4ed8;
  --brand-dark: #1e40af;
  --brand-soft: #eff6ff;
  --paper: #ffffff;
  --bg: #f8fafc;
  --bg-subtle: #f1f5f9;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --success: #059669;
  --success-soft: #ecfdf5;
  --warning: #d97706;
  --warning-soft: #fffbeb;
  --info: #0284c7;
  --info-soft: #f0f9ff;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 18px;
  --shadow-sm: 0 1px 2px 0 rgba(15, 23, 42, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(15, 23, 42, 0.07), 0 2px 4px -2px rgba(15, 23, 42, 0.05);
  --shadow-lg: 0 10px 15px -3px rgba(15, 23, 42, 0.08), 0 4px 6px -4px rgba(15, 23, 42, 0.04);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  min-height: 100vh;
  width: 100%;
  overflow-x: hidden;
  position: relative;
}

body {
  color: var(--ink);
  background: var(--bg);
  font: 14px/1.45 'Inter', ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

/* ==========================================================================
   App Shell & Header Layout
   ========================================================================== */
.app-shell {
  max-width: 1380px;
  margin: 0 auto;
  padding: 24px 20px 40px;
}

.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.header-brand-group {
  display: flex;
  align-items: center;
  gap: 14px;
}

.header-school-logo {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-md);
  object-fit: contain;
  background: #ffffff;
  border: 1px solid var(--line);
  padding: 4px;
  box-shadow: var(--shadow-sm);
  flex-shrink: 0;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.header-school-logo:hover {
  transform: scale(1.04);
  box-shadow: var(--shadow-md);
}

.header-brand-text {
  display: flex;
  flex-direction: column;
}

.eyebrow {
  color: var(--brand);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .12em;
  text-transform: uppercase;
  display: block;
  margin-bottom: 2px;
}

h1 {
  margin: 0;
  font-size: 26px;
  font-weight: 800;
  letter-spacing: -.03em;
  color: var(--ink);
}

h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  color: var(--ink);
}

h3 {
  margin: 0 0 6px;
  font-size: 15px;
  font-weight: 700;
  color: var(--ink);
}

.header-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.header-more-btn {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  background: var(--paper);
  border: 1px solid var(--line);
  color: var(--ink);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: var(--shadow-sm);
  flex-shrink: 0;
}

.header-more-btn:hover {
  background: var(--brand-soft);
  border-color: var(--brand);
  color: var(--brand-dark);
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.12);
}

.header-more-btn:active {
  transform: scale(0.95);
}

/* Class Filter Box */
.class-filter-box {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--paper);
  border: 1px solid var(--line);
  padding: 4px 10px;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
}

.class-filter-box .filter-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.class-filter-box select {
  border: 0;
  padding: 4px 4px;
  background: transparent;
  font-weight: 700;
  font-size: 13px;
  color: var(--brand-dark);
  outline: none;
  cursor: pointer;
}

/* User Switcher Profile Button */
.user-profile-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--paper);
  border: 1px solid var(--line);
  padding: 5px 12px;
  border-radius: 99px;
  cursor: pointer;
  transition: all 0.2s ease;
  user-select: none;
  box-shadow: var(--shadow-sm);
}

.user-profile-btn:hover {
  border-color: var(--brand);
  background: var(--brand-soft);
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.12);
}

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

.user-avatar {
  font-size: 15px;
}

.user-info {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
  text-align: left;
}

.user-info strong {
  font-size: 12px;
  color: var(--ink);
  font-weight: 700;
}

.badge-role {
  font-size: 9px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 1px 6px;
  border-radius: 4px;
  display: inline-block;
  margin-top: 2px;
  width: fit-content;
}

.badge-role.admin {
  background: #eef2ff;
  color: #4338ca;
  border: 1px solid #c7d2fe;
}

.badge-role.user {
  background: #f1f5f9;
  color: #475569;
  border: 1px solid #cbd5e1;
}

.status {
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
}

/* ==========================================================================
   Navigation Tabs (Segmented Control & Mobile Horizontal Scroll)
   ========================================================================== */
.tabs {
  display: flex;
  gap: 6px;
  background: var(--bg-subtle);
  padding: 5px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--line);
  margin-bottom: 22px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.tabs::-webkit-scrollbar {
  display: none;
}

.tab {
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 8px 14px;
  border-radius: var(--radius-md);
  font-weight: 600;
  font-size: 13px;
  white-space: nowrap;
  transition: all 0.18s ease;
  user-select: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.tab svg {
  flex-shrink: 0;
}

.tab:hover {
  color: var(--ink);
  background: rgba(255, 255, 255, 0.6);
}

.tab.active {
  background: var(--paper);
  color: var(--brand-dark);
  font-weight: 700;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--line);
}

.tab[style*="display: none"] {
  display: none !important;
}

/* Views */
.view {
  display: none;
}

.view.active {
  display: block;
  animation: fadeIn 0.2s ease;
}

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

/* ==========================================================================
   Cards, Grid & Layout Components
   ========================================================================== */
.card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow-sm);
}

.grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
}

.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.stack, .toolbar {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.toolbar {
  justify-content: space-between;
  margin-bottom: 16px;
}

.label {
  display: block;
  color: var(--muted);
  margin-bottom: 4px;
  font-weight: 600;
  font-size: 12px;
}

.metric {
  font-size: 28px;
  font-weight: 800;
  letter-spacing: -.04em;
  color: var(--brand);
}

/* ==========================================================================
   Quick Actions Grid
   ========================================================================== */
.quick-actions-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}

.action-card {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 16px 18px;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: var(--shadow-sm);
}

.action-card:hover {
  transform: translateY(-2px);
  border-color: #93c5fd;
  box-shadow: 0 6px 16px rgba(37, 99, 235, 0.08);
  background: #fbfdff;
}

.action-card:active {
  transform: scale(0.98);
}

.action-icon {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-md);
  background: var(--brand-soft);
  color: var(--brand);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}

.action-title {
  margin: 0;
  font-size: 14px;
  font-weight: 750;
  color: var(--ink);
}

.action-desc {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--muted);
}

/* ==========================================================================
   Detailed Metrics Grid & Stat Boxes
   ========================================================================== */
.detailed-metrics-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}

.stat-box {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 18px;
  box-shadow: var(--shadow-sm);
  position: relative;
  overflow: hidden;
}

.stat-box::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 4px;
  height: 100%;
  background: var(--brand);
}

.stat-box.info::before { background: var(--info); }
.stat-box.success::before { background: var(--success); }
.stat-box.warning::before { background: var(--warning); }

.stat-val {
  font-size: 26px;
  font-weight: 800;
  letter-spacing: -.03em;
  color: var(--ink);
  margin: 4px 0 2px;
}

.stat-sub {
  font-size: 12px;
  color: var(--muted);
  font-weight: 500;
}

/* ==========================================================================
   Division Chips & Leaderboard
   ========================================================================== */
.division-chips {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin: 14px 0;
}

.division-chip {
  background: var(--bg-subtle);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 12px 10px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.division-chip strong {
  font-size: 20px;
  font-weight: 800;
  color: var(--ink);
}

.division-chip span {
  font-size: 11px;
  color: var(--muted);
  font-weight: 700;
  text-transform: uppercase;
}

/* ==========================================================================
   Search Bar Component
   ========================================================================== */
.search-box {
  position: relative;
  display: inline-flex;
  align-items: center;
  width: 100%;
  max-width: 320px;
}

.search-box input {
  padding-left: 36px !important;
  padding-right: 32px !important;
  height: 38px;
  border-radius: var(--radius-md);
  border: 1px solid var(--line-strong);
  background: var(--paper);
  font-size: 13px;
  color: var(--ink);
  transition: all 0.2s ease;
}

.search-box input:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.search-icon {
  position: absolute;
  left: 12px;
  color: var(--muted);
  font-size: 14px;
  pointer-events: none;
}

.search-clear {
  position: absolute;
  right: 8px;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 99px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.search-clear:hover {
  color: var(--ink);
  background: var(--bg-subtle);
}

/* ==========================================================================
   Buttons, Forms & Inputs
   ========================================================================== */
input, select, textarea {
  width: 100%;
  border: 1px solid var(--line-strong);
  background: var(--paper);
  padding: 10px 12px;
  border-radius: var(--radius-md);
  color: var(--ink);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  font-size: 14px;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.input-with-icon {
  position: relative;
  display: flex;
  align-items: center;
  width: 100%;
}

.input-with-icon input {
  padding-right: 40px;
}

.toggle-password-btn {
  position: absolute;
  right: 10px;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--muted);
  font-size: 15px;
  padding: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
}

.toggle-password-btn:hover {
  color: var(--ink);
  background: var(--bg-subtle);
}

.form-group-title {
  font-size: 13px;
  font-weight: 750;
  color: var(--ink);
  margin: 16px 0 8px;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--line);
}

.field {
  margin-bottom: 14px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0 14px;
}

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

.primary, .secondary, .danger {
  border: 0;
  border-radius: var(--radius-md);
  padding: 9px 15px;
  font-weight: 700;
  font-size: 13px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  transition: all 0.15s ease;
  user-select: none;
}

.primary {
  color: #ffffff;
  background: var(--brand);
}

.primary:hover {
  background: var(--brand-hover);
}

.primary:active {
  transform: scale(0.98);
}

.secondary {
  color: var(--brand-dark);
  background: var(--brand-soft);
  border: 1px solid #bfdbfe;
}

.secondary:hover {
  background: #dbeafe;
}

.secondary:active {
  transform: scale(0.98);
}

.danger {
  color: var(--danger);
  background: var(--danger-soft);
  border: 1px solid #fecaca;
}

.danger:hover {
  background: #fee2e2;
}

.icon {
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 6px;
  font-size: 16px;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
}

.icon:hover {
  background: var(--bg-subtle);
  color: var(--ink);
}

button:disabled, button[disabled] {
  opacity: 0.55 !important;
  cursor: not-allowed !important;
  pointer-events: none !important;
}

/* Button Loading Spinner */
button.is-loading {
  position: relative;
  pointer-events: none !important;
  opacity: 0.85 !important;
  cursor: not-allowed !important;
  padding-right: 36px !important;
}

button.is-loading::after {
  content: '';
  position: absolute;
  right: 12px;
  top: 50%;
  width: 14px;
  height: 14px;
  margin-top: -7px;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: #ffffff;
  border-radius: 50%;
  animation: btn-spin 0.6s linear infinite;
}

button.secondary.is-loading::after {
  border: 2px solid rgba(37, 99, 235, 0.25);
  border-top-color: var(--brand);
}

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

/* Global Top Progress Bar */
#progressBar {
  position: fixed;
  top: 0;
  left: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--brand), #06b6d4, var(--brand-dark));
  background-size: 200% 100%;
  width: 0%;
  z-index: 9999;
  opacity: 0;
  transition: width 0.3s ease, opacity 0.3s ease;
  animation: progress-slide 1.5s linear infinite;
}

@keyframes progress-slide {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ==========================================================================
   Tables & Data Lists (Responsive Scroll)
   ========================================================================== */
.table-wrap,
.data-table {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  margin-top: 12px;
  background: var(--paper);
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
}

.table-wrap::-webkit-scrollbar,
.data-table::-webkit-scrollbar {
  height: 5px;
}

.table-wrap::-webkit-scrollbar-thumb,
.data-table::-webkit-scrollbar-thumb {
  background: var(--line-strong);
  border-radius: 99px;
}

.table-wrap table,
.data-table table {
  min-width: 520px;
  width: 100%;
}

table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
}

th, td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}

th {
  background: var(--bg-subtle);
  color: var(--muted);
  font-weight: 700;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

tr:last-child td {
  border-bottom: 0;
}

tbody tr:hover {
  background: #fafcff;
}

.table-input {
  width: 72px;
  padding: 5px 8px;
  text-align: center;
  font-weight: 700;
  border-radius: var(--radius-sm);
}

/* Subject & Order Badges */
.subject-pill {
  display: inline-flex;
  align-items: center;
  padding: 3px 8px;
  border-radius: 99px;
  background: var(--bg-subtle);
  border: 1px solid var(--line);
  font-size: 11px;
  font-weight: 700;
  color: var(--ink-secondary);
}

.order-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 2px 7px;
  border-radius: var(--radius-sm);
  background: var(--brand-soft);
  color: var(--brand-dark);
  font-weight: 750;
  font-size: 11px;
}

/* Drag-and-drop Subject Rows */
.draggable-row {
  cursor: grab;
  transition: background-color 0.15s ease, opacity 0.15s ease;
}

.draggable-row:active {
  cursor: grabbing;
}

.drag-handle {
  cursor: grab;
  color: var(--muted);
  font-size: 16px;
  padding-right: 6px;
  user-select: none;
}

.draggable-row.dragging {
  opacity: 0.4;
  background: var(--brand-soft) !important;
}

.draggable-row.drag-over {
  border-top: 2px solid var(--brand);
  background: #f0f7ff !important;
}

/* Locked Settings Banner */
.locked-settings-banner {
  background: #fffbeb;
  border: 1px solid #fde68a;
  border-radius: var(--radius-md);
  padding: 14px 16px;
  margin-bottom: 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.locked-settings-banner .banner-text {
  font-size: 13px;
  color: #92400e;
  line-height: 1.4;
}

/* ==========================================================================
   Modals & Bottom-Sheet Design
   ========================================================================== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 1000;
  animation: fadeIn 0.15s ease;
}

.modal {
  background: var(--paper);
  border-radius: var(--radius-xl);
  width: 100%;
  max-width: 580px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--line);
  overflow: hidden;
  animation: modalPop 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

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

.modal-header,
.modal-head {
  padding: 18px 22px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.modal-header h2,
.modal-header h3,
.modal-head h2,
.modal-head h3 {
  margin: 0;
  font-size: 17px;
  font-weight: 800;
  color: var(--ink);
}

.modal-body,
.modal > form,
.modal > div:not(.modal-head):not(.modal-header):not(.modal-body):not(.modal-footer) {
  padding: 22px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.modal-footer {
  padding: 14px 22px;
  border-top: 1px solid var(--line);
  background: var(--bg-subtle);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.component-row {
  display: grid;
  grid-template-columns: 1fr 100px auto;
  gap: 10px;
  align-items: center;
  margin-bottom: 10px;
}

.marks-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 10px;
  margin-top: 8px;
}

.mark-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.mark-field label {
  font-size: 11px;
  font-weight: 700;
  color: var(--ink);
  line-height: 1.2;
}

.mark-field label small {
  display: block;
  color: var(--muted);
  font-weight: 500;
  font-size: 10px;
}

.mark-field input {
  padding: 8px 10px;
  font-size: 14px;
  font-weight: 600;
  border-radius: var(--radius-sm);
}

@media (max-width: 640px) {
  .marks-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }
}

/* Toast Notifications */
#toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: #1e293b;
  color: #ffffff;
  padding: 11px 18px;
  border-radius: var(--radius-md);
  font-weight: 600;
  font-size: 13px;
  box-shadow: var(--shadow-lg);
  z-index: 2000;
  display: none;
  align-items: center;
  gap: 8px;
  animation: toastIn 0.2s ease;
}

#toast.show-toast {
  display: flex !important;
}

.hidden-tab {
  display: none !important;
}

.hidden {
  display: none !important;
}

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

/* ==========================================================================
   Icon Utilities & Leading Icons
   ========================================================================== */
.inline-icon {
  display: inline-block;
  vertical-align: middle;
}

.heart-icon {
  color: #ef4444;
  fill: #ef4444;
  vertical-align: -2px;
}

.btn-with-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.input-with-leading-icon {
  position: relative;
  display: flex;
  align-items: center;
  width: 100%;
}

.input-leading-icon {
  position: absolute;
  left: 12px;
  color: var(--muted);
  pointer-events: none;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
}

.input-with-leading-icon input {
  padding-left: 38px !important;
}

.input-with-leading-icon.input-with-icon input {
  padding-right: 40px !important;
}

.toggle-password-btn svg {
  display: block;
}

/* Rank Badge Replacements for Emojis */
.rank-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-width: 38px;
  height: 24px;
  padding: 0 6px;
  border-radius: var(--radius-sm);
  font-size: 11px;
  font-weight: 800;
}

.rank-badge.rank-1 {
  background: linear-gradient(135deg, #fef3c7, #fde68a);
  color: #92400e;
  border: 1px solid #fcd34d;
}

.rank-badge.rank-2 {
  background: linear-gradient(135deg, #f1f5f9, #e2e8f0);
  color: #475569;
  border: 1px solid #cbd5e1;
}

.rank-badge.rank-3 {
  background: linear-gradient(135deg, #ffedd5, #fed7aa);
  color: #9a3412;
  border: 1px solid #fdba74;
}

.rank-badge.rank-other {
  background: var(--bg-subtle);
  color: var(--muted);
  border: 1px solid var(--line);
}

/* ==========================================================================
   Full-Screen Login Portal (Dedicated & Mobile-Responsive)
   ========================================================================== */
.login-portal {
  min-height: 100vh;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
  background: linear-gradient(135deg, #f8fafc 0%, #eff6ff 50%, #f1f5f9 100%);
  position: relative;
  overflow-y: auto;
}

.login-portal.hidden {
  display: none !important;
}

.login-container {
  width: 100%;
  max-width: 440px;
  margin: auto;
  animation: loginFadeUp 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

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

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

.login-logo-badge {
  width: 72px;
  height: 72px;
  border-radius: 20px;
  background: #ffffff;
  border: 1px solid var(--line);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 10px 25px -5px rgba(37, 99, 235, 0.18), 0 4px 10px -2px rgba(15, 23, 42, 0.05);
  margin-bottom: 14px;
  overflow: hidden;
  padding: 8px;
}

.login-logo-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.login-eyebrow {
  display: block;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.12em;
  color: var(--brand);
  text-transform: uppercase;
  margin-bottom: 4px;
}

.login-title {
  font-size: 26px;
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--ink);
  margin: 0 0 6px;
}

.login-subtitle {
  font-size: 13px;
  color: var(--muted);
  margin: 0;
  line-height: 1.45;
}

.login-card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  box-shadow: 0 10px 25px -5px rgba(15, 23, 42, 0.08), 0 8px 10px -6px rgba(15, 23, 42, 0.04);
  padding: 28px 24px;
}

.login-alert {
  padding: 10px 14px;
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 16px;
  background: var(--danger-soft);
  color: var(--danger);
  border: 1px solid rgba(220, 38, 38, 0.2);
  display: flex;
  align-items: center;
  gap: 8px;
}

.login-alert.hidden {
  display: none !important;
}

.login-submit-btn {
  width: 100%;
  padding: 12px 18px;
  font-size: 15px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-radius: var(--radius-md);
  margin-top: 18px;
  box-shadow: 0 4px 10px rgba(37, 99, 235, 0.25);
}



.login-notice {
  margin-top: 16px;
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 11px;
  color: var(--muted);
  line-height: 1.45;
}

.login-notice svg {
  flex-shrink: 0;
  margin-top: 1px;
  color: var(--muted);
}

.login-footer {
  text-align: center;
  margin-top: 20px;
  font-size: 12px;
  color: var(--muted);
}

/* ==========================================================================
   Custom Confirmation Modals (High-UX Replacement for confirm())
   ========================================================================== */
.confirm-modal-box {
  text-align: center;
  padding: 10px 6px;
}

.confirm-icon-badge {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 16px;
}

.confirm-icon-badge.danger {
  background: var(--danger-soft);
  color: var(--danger);
}

.confirm-icon-badge.warning {
  background: var(--warning-soft);
  color: var(--warning);
}

.confirm-icon-badge.primary,
.confirm-icon-badge.info {
  background: var(--brand-soft);
  color: var(--brand);
}

.confirm-title {
  font-size: 19px;
  font-weight: 800;
  color: var(--ink);
  margin: 0 0 8px;
  letter-spacing: -0.02em;
}

.confirm-message {
  font-size: 14px;
  color: var(--muted);
  line-height: 1.5;
  margin: 0 0 22px;
}

.confirm-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.danger-btn {
  background: var(--danger);
  color: #ffffff;
  border: 1px solid var(--danger);
  font-weight: 700;
  padding: 10px 16px;
  border-radius: var(--radius-md);
  transition: all 0.15s ease;
  box-shadow: 0 2px 4px rgba(220, 38, 38, 0.2);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.danger-btn:hover {
  background: #b91c1c;
  border-color: #b91c1c;
}

/* ==========================================================================
   Loading Splash Screen & Skeleton Shimmer
   ========================================================================== */
.loading-screen {
  position: fixed;
  inset: 0;
  background: #ffffff;
  z-index: 9998;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.35s ease, visibility 0.35s ease;
}

.loading-screen.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.loading-card {
  text-align: center;
  max-width: 320px;
  width: 90%;
  padding: 30px 20px;
}

.loading-spinner-ring {
  width: 44px;
  height: 44px;
  border: 3px solid var(--brand-soft);
  border-top-color: var(--brand);
  border-radius: 50%;
  margin: 0 auto 16px;
  animation: spin 0.8s linear infinite;
}

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

.loading-title {
  font-size: 20px;
  font-weight: 800;
  color: var(--ink);
  letter-spacing: -.02em;
}

.loading-subtitle {
  font-size: 11px;
  color: var(--brand);
  font-weight: 800;
  letter-spacing: .08em;
  margin: 4px 0 16px;
}

.loading-bar-track {
  width: 100%;
  height: 4px;
  background: var(--bg-subtle);
  border-radius: 99px;
  overflow: hidden;
  margin-top: 8px;
  position: relative;
}

.loading-bar-fill {
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  width: 45%;
  background: linear-gradient(90deg, var(--brand), #06b6d4);
  border-radius: 99px;
  animation: indet-progress 1.4s ease-in-out infinite;
}

@keyframes indet-progress {
  0% { left: -45%; width: 30%; }
  50% { left: 35%; width: 60%; }
  100% { left: 105%; width: 40%; }
}

.loading-status {
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
  margin-top: 6px;
  display: block;
}

/* Skeleton Screens */
.skeleton {
  background: linear-gradient(90deg, #edf2f7 0%, #f8fafc 50%, #edf2f7 100%);
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.5s ease-in-out infinite;
  border-radius: 6px;
  display: inline-block;
}

@keyframes skeleton-shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.skeleton-text { height: 14px; width: 100%; margin: 4px 0; }
.skeleton-text.sm { width: 60%; }
.skeleton-text.xs { width: 35%; }
.skeleton-title { height: 22px; width: 160px; margin-bottom: 8px; }
.skeleton-metric { height: 32px; width: 70px; margin-top: 6px; border-radius: 8px; }
.skeleton-button { height: 36px; width: 130px; border-radius: 8px; }
.skeleton-pill { height: 22px; width: 80px; border-radius: 99px; margin: 2px; }
.skeleton-input { height: 38px; width: 100%; border-radius: 8px; margin-top: 4px; }
.skeleton-row td { padding: 14px 12px !important; }

.app-footer {
  margin-top: 40px;
  padding: 20px 0 10px;
  border-top: 1px solid var(--line);
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}

.app-footer p { margin: 0; }
.app-footer strong { color: var(--brand); font-weight: 700; }

/* ==========================================================================
   RESPONSIVE DESIGN (PHONES & TABLETS)
   ========================================================================== */

/* Tablets & Small Desktops */
@media (max-width: 900px) {
  .detailed-metrics-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .grid {
    grid-template-columns: 1fr;
  }
}


/* Mobile Action Sheet Modal */
.action-sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 10000;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s ease, visibility 0.25s ease;
}

.action-sheet-backdrop.active {
  opacity: 1;
  visibility: visible;
}

.action-sheet {
  background: #ffffff;
  width: 100%;
  max-width: 600px;
  border-radius: 20px 20px 0 0;
  padding: 20px 20px calc(20px + env(safe-area-inset-bottom, 0px));
  box-shadow: 0 -10px 25px -5px rgba(15, 23, 42, 0.15);
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  max-height: 90vh;
  overflow-y: auto;
}

.action-sheet-backdrop.active .action-sheet {
  transform: translateY(0);
}

.action-sheet-handle {
  width: 36px;
  height: 4px;
  background: var(--line);
  border-radius: 99px;
  margin: 0 auto 16px;
}

.action-sheet-title {
  font-size: 16px;
  font-weight: 800;
  color: var(--ink);
  margin-bottom: 14px;
  text-align: center;
}

.action-sheet-buttons {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.action-sheet-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 12px 16px;
  background: var(--bg-subtle);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
  transition: all 0.15s ease;
}

.action-sheet-btn:hover {
  background: var(--line);
}

.action-sheet-btn svg {
  width: 18px;
  height: 18px;
  color: var(--muted);
  flex-shrink: 0;
}

/* Modern Responsive Data Tables */
.table-responsive {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin-bottom: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: #ffffff;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 13px;
  white-space: nowrap;
}

.data-table th {
  background: var(--bg-subtle);
  color: var(--muted);
  font-weight: 700;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
}

.data-table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  color: var(--ink);
}

.data-table tr:last-child td {
  border-bottom: none;
}

.data-table tr:hover td {
  background: rgba(248, 250, 252, 0.6);
}

/* Mobile Phones (max-width: 640px) */
@media (max-width: 640px) {
  .app-shell {
    padding: 12px 12px 80px;
    max-width: 100vw;
    overflow-x: hidden;
  }

  .app-header {
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    margin-bottom: 14px;
    flex-wrap: nowrap;
    width: 100%;
  }

  .header-brand-group {
    min-width: 0;
    gap: 8px;
    flex: 1;
  }

  .header-brand-text {
    min-width: 0;
  }

  .header-brand-text .eyebrow {
    font-size: 9px;
    letter-spacing: 0.08em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .header-brand-text h1 {
    font-size: 17px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .header-actions {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
  }

  .header-desktop-only {
    display: none !important;
  }

  .class-filter-box {
    padding: 3px 6px;
  }

  .class-filter-box select {
    font-size: 12px;
    max-width: 90px;
  }

  .header-more-btn {
    width: 36px;
    height: 36px;
  }

  /* Fixed Native Bottom App Bar for Tabs */
  .tabs {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    margin: 0;
    border-radius: 0;
    border-left: 0;
    border-right: 0;
    border-bottom: 0;
    border-top: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.96);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    z-index: 1000;
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom, 0px));
    justify-content: space-around;
    box-shadow: 0 -4px 16px rgba(15, 23, 42, 0.06);
    overflow-x: hidden;
  }

  .tabs .tab {
    flex-direction: column;
    gap: 2px;
    padding: 4px 2px;
    font-size: 10px;
    font-weight: 700;
    border-radius: var(--radius-sm);
    min-width: 0;
    flex: 1;
    border: none;
    background: transparent;
    color: var(--muted);
    text-align: center;
  }

  .tabs .tab.active {
    background: var(--brand-soft);
    color: var(--brand);
    box-shadow: none;
    border: none;
  }

  .tabs .tab svg {
    width: 18px;
    height: 18px;
  }

  .card {
    padding: 14px;
    border-radius: var(--radius-md);
  }

  .grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .toolbar {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  .toolbar .stack {
    width: 100%;
    flex-direction: column;
    align-items: stretch;
  }

  .search-box {
    max-width: 100% !important;
    width: 100%;
  }

  /* Quick Actions Grid */
  .quick-actions-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .action-card {
    padding: 12px 10px;
    gap: 10px;
    flex-direction: column;
    text-align: center;
    align-items: center;
  }

  .action-icon {
    width: 38px;
    height: 38px;
    font-size: 18px;
  }

  .action-title {
    font-size: 12px;
  }

  .action-desc {
    font-size: 10px;
    display: none; /* Hide subtitle on tiny screens for ultra-clean minimalist look */
  }

  /* Metrics Grid */
  .detailed-metrics-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .stat-box {
    padding: 12px 14px;
  }

  .stat-val {
    font-size: 20px;
  }

  .stat-sub {
    font-size: 11px;
  }

  /* Division & 2-Col Layout */
  .two-col {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .division-chips {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
  }

  .division-chip {
    padding: 10px 6px;
  }

  .division-chip strong {
    font-size: 17px;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .component-row {
    grid-template-columns: 1fr 80px auto;
  }

  /* Mobile Bottom Sheet Modal */
  .modal-backdrop {
    align-items: flex-end;
    padding: 0;
  }

  .modal {
    max-width: 100%;
    border-radius: 20px 20px 0 0;
    max-height: 85vh;
    animation: slideUp 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  }

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

  .modal-header {
    padding: 14px 18px;
  }

  .modal-body {
    padding: 16px 18px;
    max-height: calc(85vh - 120px);
  }

  .modal-footer {
    padding: 12px 18px;
    flex-direction: column-reverse;
  }

  .modal-footer button {
    width: 100%;
  }

  /* Inputs prevent iOS auto-zoom */
  input, select, textarea {
    font-size: 16px;
  }

  #toast {
    left: 12px;
    right: 12px;
    bottom: 12px;
    text-align: center;
    justify-content: center;
  }

  .header-brand-group {
    gap: 10px;
  }

  .header-school-logo {
    width: 38px;
    height: 38px;
    padding: 2px;
    border-radius: var(--radius-sm);
  }
}

/* ==========================================================================
   Progress Bar & Loading Screen (Rich Aesthetic Micro-Animations)
   ========================================================================== */
#progressBar {
  position: fixed;
  top: 0;
  left: 0;
  height: 3px;
  width: 0%;
  background: linear-gradient(90deg, var(--brand), #60a5fa);
  z-index: 9999;
  transition: width 0.25s ease, opacity 0.25s ease;
  pointer-events: none;
}

.loading-screen {
  position: fixed;
  inset: 0;
  background: rgba(248, 250, 252, 0.96);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9998;
  transition: opacity 0.35s ease, visibility 0.35s ease;
}

.loading-screen.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.loading-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  background: #ffffff;
  padding: 32px 28px;
  border-radius: var(--radius-xl);
  border: 1px solid var(--line);
  box-shadow: 0 20px 35px -10px rgba(15, 23, 42, 0.12), 0 10px 15px -5px rgba(37, 99, 235, 0.08);
  max-width: 320px;
  width: 90%;
  animation: loginFadeUp 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.loading-logo {
  width: 68px;
  height: 68px;
  border-radius: 16px;
  object-fit: contain;
  background: #ffffff;
  border: 1px solid var(--line);
  padding: 6px;
  box-shadow: 0 6px 16px -4px rgba(37, 99, 235, 0.2);
  margin-bottom: 16px;
  animation: logoPulse 2s ease-in-out infinite;
}

@keyframes logoPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); }
}

.loading-spinner-ring {
  width: 26px;
  height: 26px;
  border: 3px solid #e2e8f0;
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-bottom: 14px;
}

.loading-title {
  font-size: 18px;
  font-weight: 800;
  color: var(--ink);
  letter-spacing: -0.02em;
  margin-bottom: 2px;
}

.loading-subtitle {
  font-size: 11px;
  font-weight: 700;
  color: var(--brand);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  margin-bottom: 16px;
}

.loading-bar-track {
  width: 100%;
  height: 4px;
  background: #e2e8f0;
  border-radius: 99px;
  overflow: hidden;
  margin-bottom: 12px;
}

.loading-bar-fill {
  height: 100%;
  width: 40%;
  background: linear-gradient(90deg, var(--brand), #60a5fa);
  border-radius: 99px;
  animation: loadingIndeterminate 1.5s ease-in-out infinite;
}

@keyframes loadingIndeterminate {
  0% { transform: translateX(-100%); width: 30%; }
  50% { transform: translateX(100%); width: 60%; }
  100% { transform: translateX(350%); width: 30%; }
}

.loading-status {
  font-size: 12px;
  color: var(--muted);
}

.report-logo {
  width: 80px;
  height: 80px;
  max-width: 80px;
  max-height: 80px;
  object-fit: contain;
  display: block;
  margin: auto;
}

/* ==========================================================================
   A3 PRINT STYLES (High Fidelity Consolidated Marksheet)
   ========================================================================== */
@media print {
  @page {
    size: A3 landscape;
    margin: 8mm;
  }

  body {
    background: white;
    print-color-adjust: exact;
    -webkit-print-color-adjust: exact;
  }

  .app-shell,
  .modal-backdrop,
  #toast,
  .loading-screen,
  #progressBar {
    display: none !important;
  }

  #printReport {
    display: block !important;
  }

  .report-page {
    width: 100%;
    break-after: page;
    page-break-after: always;
  }

  .report-page:last-child {
    break-after: auto;
    page-break-after: auto;
  }

  .report-header {
    display: grid;
    grid-template-columns: 105px 1fr 260px;
    grid-template-areas: 'logo school school' 'class exam contact';
    align-items: end;
    gap: 0 14px;
    margin-bottom: 12px;
  }

  .report-logo {
    grid-area: logo;
    width: 85px;
    height: 85px;
    max-width: 85px;
    max-height: 85px;
    object-fit: contain;
    display: block;
    margin: auto;
  }

  .report-school {
    grid-area: school;
    color: #142c85;
    font-family: Georgia, serif;
    text-align: center;
    font-weight: 900;
    font-size: 27pt;
  }

  .report-exam {
    grid-area: exam;
    color: white;
    background: #427bd2;
    text-align: center;
    padding: 7px;
    font: 700 14pt Georgia, serif;
  }

  .report-class {
    grid-area: class;
    text-align: center;
    font: bold 15pt Georgia, serif;
    background: #10dddd;
    padding: 3px;
  }

  .report-contact {
    grid-area: contact;
    background: #10dddd;
    text-align: center;
    font: bold 11pt Georgia, serif;
    padding: 2px;
  }

  .report-contact b {
    display: block;
  }

  .result-table {
    table-layout: fixed;
    font-family: Georgia, serif;
    font-size: 7.5pt;
  }

  .result-table th,
  .result-table td {
    border: 1px solid #333;
    text-align: center;
    padding: 2px;
    overflow: hidden;
  }

  .result-table thead {
    display: table-header-group;
  }

  .result-table tr {
    break-inside: avoid;
    page-break-inside: avoid;
  }

  .result-table .blue {
    color: #fff;
    background: #172b87;
    font-weight: 800;
  }

  .result-table .black {
    color: #fff;
    background: #050505;
    font-weight: 800;
  }

  .result-table .total {
    background: #a2cf84;
    font-weight: 800;
  }

  .result-table .grand {
    background: #b0dfcc;
    font-weight: 800;
  }

  .result-table .name {
    text-align: left;
    font-weight: 700;
    font-size: 9pt;
  }

  .result-table .roll {
    font-weight: 700;
  }

  .report-note {
    display: none;
  }
}