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

body { max-width: 100%; }

:root {
  --primary: #4f46e5;
  --primary-dark: #3730a3;
  --primary-light: #818cf8;
  --table-header-bg: var(--primary-dark);
  --success: #059669;
  --danger: #dc2626;
  --warning: #d97706;
  --sidebar-bg: #1e293b;
  --sidebar-text: #cbd5e1;
  --bg: #f1f5f9;
  --card-bg: #ffffff;
  --text: #334155;
  --text-light: #64748b;
  --border: #e2e8f0;
  --shadow: 0 1px 3px rgba(0,0,0,0.1);
  --radius: 8px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  line-height: 1.6;
}

body[data-theme="emerald"] {
  --primary: #0f766e;
  --primary-dark: #115e59;
  --primary-light: #2dd4bf;
  --table-header-bg: #115e59;
  --sidebar-bg: #134e4a;
  --sidebar-text: #ccfbf1;
  --bg: #ecfdf5;
}

body[data-theme="ocean"] {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-light: #60a5fa;
  --table-header-bg: #1e40af;
  --sidebar-bg: #172554;
  --sidebar-text: #dbeafe;
  --bg: #eff6ff;
}

body[data-theme="sunset"] {
  --primary: #ea580c;
  --primary-dark: #c2410c;
  --primary-light: #fb923c;
  --table-header-bg: #9a3412;
  --sidebar-bg: #7c2d12;
  --sidebar-text: #ffedd5;
  --bg: #fff7ed;
}

/* ===== Auth Page ===== */
.auth-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.auth-page .home-landing-container {
  display: block !important;
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 100vh;
  overflow-y: auto;
  z-index: 100;
  background: white;
  flex: none;
}

.auth-page .home-landing-container.hidden {
  display: none !important;
}

.auth-page #auth-container {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 50;
  background: white;
  border-radius: 16px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.15);
  padding: 40px;
  max-width: 420px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
}

.auth-page #auth-container.hidden {
  display: none;
}

.auth-card {
  background: white;
  border-radius: 16px;
  padding: 40px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.15);
}

.auth-logo { text-align: center; margin-bottom: 30px; }
.auth-logo .logo-icon { font-size: 48px; margin-bottom: 10px; }
.auth-logo h1 { font-size: 24px; color: var(--text); }
.auth-logo p { color: var(--text-light); font-size: 14px; margin-top: 4px; }

.auth-tabs {
  display: flex;
  margin-bottom: 24px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.auth-tab {
  flex: 1;
  padding: 10px;
  border: none;
  background: white;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-light);
  transition: all 0.2s;
}

.auth-tab.active {
  background: var(--primary);
  color: white;
}

/* ===== Forms ===== */
.form-group { margin-bottom: 16px; }

.form-group label {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  color: var(--text);
  background: white;
  transition: border-color 0.2s;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.form-group textarea { resize: vertical; font-family: inherit; }

.password-field {
  position: relative;
  display: flex;
  align-items: center;
}

.password-field input {
  padding-right: 38px !important;
}

.password-toggle {
  position: absolute;
  right: 10px;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 18px;
  padding: 4px 8px;
  color: var(--text-secondary);
  transition: color 0.2s;
}

.password-toggle:hover {
  color: var(--text);
}

.password-toggle:active {
  transform: scale(0.95);
}

.native-select-hidden {
  position: absolute;
  opacity: 0;
  pointer-events: none;
  width: 1px;
  height: 1px;
}

.app-dropdown {
  position: relative;
}

.app-dropdown-block {
  width: 100%;
}

.app-dropdown-inline {
  min-width: 170px;
}

.app-dropdown-compact {
  min-width: 0;
  width: auto;
}

.app-dropdown-compact .app-dropdown-trigger {
  width: auto;
  min-width: 0;
  min-height: 28px;
  padding: 3px 8px;
  gap: 6px;
  font-size: 12px;
}

.app-dropdown-compact .app-dropdown-menu {
  left: auto;
  right: 0;
  min-width: 64px;
}

.app-dropdown-trigger {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  font-size: 14px;
  padding: 10px 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 40px;
}

.app-dropdown-trigger:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.app-dropdown-caret {
  color: var(--text-light);
  font-size: 11px;
  transition: transform 0.2s ease;
}

.app-dropdown.open .app-dropdown-caret {
  transform: rotate(180deg);
}

.app-dropdown-menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.12);
  z-index: 50;
  max-height: 230px;
  overflow-y: auto;
  display: none;
  padding: 4px;
}

.app-dropdown.open .app-dropdown-menu {
  display: block;
}

.app-dropdown-search-wrap {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: 4px;
  margin: -4px -4px 4px;
  background: #fff;
  border-bottom: 1px solid var(--border);
}

.app-dropdown-search {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 7px 9px;
  font-size: 13px;
}

.app-dropdown-search:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(79, 70, 229, 0.12);
}

.app-dropdown-empty {
  padding: 8px 10px;
  font-size: 12px;
  color: var(--text-light);
}

.app-dropdown-item {
  width: 100%;
  border: none;
  background: transparent;
  border-radius: 6px;
  padding: 8px 10px;
  text-align: left;
  cursor: pointer;
  color: var(--text);
}

.app-dropdown-item:hover,
.app-dropdown-item.selected {
  background: #eef2ff;
  color: var(--primary-dark);
}

.app-dropdown-item:focus {
  outline: none;
  background: #e0e7ff;
  color: var(--primary-dark);
}

.app-dropdown-item:disabled {
  color: #94a3b8;
  cursor: not-allowed;
}

.app-dropdown-in-row {
  width: 100%;
}

.app-dropdown-in-row .app-dropdown-trigger {
  min-height: 34px;
  padding: 6px 10px;
}

.toggle-group { margin-bottom: 12px; }

.toggle-row {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  user-select: none;
  margin-bottom: 0;
}

.toggle-switch {
  position: relative;
  width: 44px;
  height: 24px;
  display: inline-block;
  flex: 0 0 auto;
}

.toggle-switch input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  inset: 0;
  background: #cbd5e1;
  border-radius: 999px;
  transition: background 0.2s ease;
}

.toggle-slider::before {
  content: '';
  position: absolute;
  width: 18px;
  height: 18px;
  left: 3px;
  top: 3px;
  background: #fff;
  border-radius: 50%;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
  transition: transform 0.2s ease;
}

.toggle-switch input:checked + .toggle-slider { background: var(--primary); }

.toggle-switch input:checked + .toggle-slider::before {
  transform: translateX(20px);
}

.toggle-switch input:focus-visible + .toggle-slider {
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.2);
}

.custom-date-input {
  background-image: linear-gradient(transparent, transparent),
    radial-gradient(circle at 85% 50%, rgba(79, 70, 229, 0.12) 0, rgba(79, 70, 229, 0.12) 14px, transparent 14px);
  background-repeat: no-repeat;
  background-size: 100% 100%, 34px 34px;
  background-position: 0 0, right 8px center;
  padding-right: 46px;
}

.flatpickr-calendar {
  border: 1px solid #dbe4ff;
  box-shadow: 0 16px 38px rgba(15, 23, 42, 0.18);
  border-radius: 14px;
  overflow: hidden;
}

.flatpickr-months {
  background: linear-gradient(135deg, #4f46e5 0%, #3b82f6 100%);
}

.flatpickr-current-month,
.flatpickr-monthDropdown-months,
.flatpickr-weekday,
.flatpickr-prev-month,
.flatpickr-next-month {
  color: #fff !important;
  fill: #fff !important;
}

.flatpickr-weekdays {
  background: #eef2ff;
}

.flatpickr-day {
  border-radius: 10px;
  max-width: 34px;
  line-height: 34px;
  height: 34px;
}

.flatpickr-day.today {
  border-color: #4f46e5;
}

.flatpickr-day.selected,
.flatpickr-day.startRange,
.flatpickr-day.endRange,
.flatpickr-day.selected:hover,
.flatpickr-day.startRange:hover,
.flatpickr-day.endRange:hover {
  background: #4f46e5;
  border-color: #4f46e5;
}

.error-msg {
  color: var(--danger);
  font-size: 13px;
  margin-top: 12px;
  text-align: center;
  display: none;
}

.error-msg.show {
  display: block;
  animation: slideInDown 0.3s ease-out;
}

.success-msg {
  color: #22c55e;
  font-size: 13px;
  margin-top: 12px;
  text-align: center;
  display: none;
  background: #f0fdf4;
  padding: 12px;
  border-radius: 4px;
  border-left: 4px solid #22c55e;
}

.success-msg.show {
  display: block;
  animation: slideInDown 0.3s ease-out;
}

.hidden { display: none !important; }

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: none;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  text-decoration: none;
  white-space: nowrap;
}

.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-success { background: var(--success); color: white; }
.btn-success:hover { background: #047857; }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: #b91c1c; }
.btn-warning { background: var(--warning); color: white; }
.btn-outline { 
  background: transparent !important; 
  color: var(--primary) !important; 
  border: 2px solid var(--primary) !important;
  font-weight: 600;
}
.btn-outline:hover { 
  background: rgba(79, 70, 229, 0.1) !important; 
  color: var(--primary) !important; 
}
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-block { width: 100%; justify-content: center; padding: 12px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.top-bar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-left: auto;
}

.user-profile-button {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px 8px 10px;
  border: 1px solid rgba(148, 163, 184, 0.45);
  background: rgba(255, 255, 255, 0.8);
  color: var(--text);
  border-radius: 999px;
  cursor: pointer;
  box-shadow: 0 4px 10px rgba(15, 23, 42, 0.06);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.user-profile-button:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 18px rgba(15, 23, 42, 0.1);
}

.user-profile-avatar,
.user-profile-avatar-fallback {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  object-fit: cover;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  color: white;
  font-weight: 700;
  font-size: 12px;
  overflow: hidden;
  flex-shrink: 0;
}

.user-profile-avatar.hidden {
  display: none;
}

.user-profile-avatar-fallback.hidden {
  display: none;
}

.user-profile-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  line-height: 1.15;
}

.user-profile-meta span:first-child {
  font-size: 13px;
  font-weight: 700;
}

.user-profile-role {
  font-size: 11px;
  color: var(--text-light);
  text-transform: capitalize;
}

.user-profile-caret {
  font-size: 11px;
  color: var(--text-light);
}

.profile-modal-grid {
  display: grid;
  grid-template-columns: 180px 1fr;
  gap: 20px;
  align-items: start;
}

.profile-card {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
}

.profile-avatar-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.profile-avatar-large {
  width: 110px;
  height: 110px;
  border-radius: 50%;
  object-fit: cover;
  border: 3px solid rgba(79, 70, 229, 0.2);
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
}

.profile-avatar-placeholder {
  width: 110px;
  height: 110px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 32px;
  font-weight: 700;
}

.profile-actions-list {
  display: grid;
  gap: 10px;
}

.profile-action-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: white;
}

.profile-action-copy {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.profile-action-copy strong {
  font-size: 14px;
}

.profile-action-copy span {
  font-size: 12px;
  color: var(--text-light);
}

.profile-toggle {
  position: relative;
  width: 52px;
  height: 30px;
  border-radius: 999px;
  border: none;
  background: #cbd5e1;
  cursor: pointer;
  transition: background 0.2s ease;
}

.profile-toggle::after {
  content: "";
  position: absolute;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: white;
  top: 4px;
  left: 4px;
  transition: transform 0.2s ease;
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.15);
}

.profile-toggle.enabled {
  background: var(--success);
}

.profile-toggle.enabled::after {
  transform: translateX(22px);
}

.profile-form-grid {
  display: grid;
  gap: 12px;
}

.profile-subtitle {
  font-size: 13px;
  color: var(--text-light);
  margin-bottom: 6px;
}

/* Student Portal Styles */
.student-welcome-banner {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
  color: white;
  padding: 32px;
  margin-bottom: 24px;
}

.student-welcome-banner h2 { margin-bottom: 12px; }
.student-profile-info {
  display: flex;
  gap: 24px;
  opacity: 0.9;
  font-size: 1.1rem;
}

.test-interface-container {
  max-width: 800px;
  margin: 0 auto;
}

.test-interface-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px;
  position: sticky;
  top: 0;
  z-index: 100;
  border-radius: 0 0 12px 12px;
  border-top: none;
  margin-top: -24px; /* Pull up to touch header */
}

.test-timer-display {
  background: #f1f5f9;
  padding: 12px 24px;
  border-radius: 50px;
  font-weight: 700;
  font-size: 1.2rem;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.05);
}

.test-question-card {
  margin-bottom: 24px;
  padding: 24px;
}

/* Results Styling */
.test-result-container {
  max-width: 600px;
  margin: 40px auto;
  padding: 40px;
  text-align: center;
}

.result-header {
  margin-bottom: 32px;
}

.result-icon {
  font-size: 4rem;
  margin-bottom: 16px;
}

.result-stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-bottom: 32px;
}

.result-stat-card {
  background: #f8fafc;
  padding: 16px;
  border-radius: 12px;
  display: flex;
  flex-direction: column;
}

.stat-label {
  font-size: 0.85rem;
  color: #64748b;
  margin-bottom: 4px;
}

.stat-value {
  font-size: 1.25rem;
  font-weight: 700;
  color: #1e293b;
}

.result-feedback-banner {
  padding: 16px;
  border-radius: 8px;
  margin-bottom: 32px;
  font-weight: 600;
}

.result-feedback-banner.pass {
  background: #f0fdf4;
  color: #166534;
}

.result-feedback-banner.retry {
  background: #fef2f2;
  color: #991b1b;
}

/* Student Portal Dashboard */
.student-welcome-banner {
  padding: 30px;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%) !important;
  color: #ffffff !important;
  margin-bottom: 30px;
  border-radius: 12px;
  box-shadow: 0 4px 15px rgba(0,0,0,0.1);
}

.student-welcome-banner h2 { 
  margin: 0 0 10px 0;
  color: #ffffff !important;
  font-size: 1.8rem;
}

.student-profile-info {
  display: flex;
  gap: 20px;
  font-size: 0.95rem;
  opacity: 0.9;
}

.test-questions-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 24px;
  margin-bottom: 40px;
}

.test-card {
  display: flex;
  flex-direction: column;
  padding: 0;
  overflow: hidden;
  transition: transform 0.2s, box-shadow 0.2s;
}

.test-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 12px 20px rgba(0,0,0,0.1);
}

.test-card.completed {
  opacity: 0.6;
  filter: grayscale(0.5);
  pointer-events: none;
  cursor: not-allowed;
}

.test-card.completed .btn {
  background: #94a3b8;
  border-color: #94a3b8;
}

.test-thumbnail {
  height: 120px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 3rem;
  color: rgba(0,0,0,0.2);
}

.test-details {
  padding: 20px;
  flex-grow: 1;
  display: flex;
  flex-direction: column;
}

.test-title {
  margin: 0 0 12px 0;
  font-size: 1.2rem;
}

.test-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}

.test-stats {
  margin-bottom: 16px;
  font-size: 0.9rem;
  color: #64748b;
  font-weight: 500;
}

.score-pill {
  display: inline-block;
  background: #f0fdf4;
  color: #166534;
  padding: 8px 16px;
  border-radius: 20px;
  font-weight: 600;
}

.count-badge {
  background: var(--danger);
  color: white;
  padding: 2px 6px;
  border-radius: 10px;
  font-size: 11px;
  margin-left: 6px;
  font-weight: 700;
  box-shadow: 0 2px 4px rgba(220, 38, 38, 0.3);
}

.uninspected-row {
  background-color: #fff9f0;
}

.status-pill {
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
}

.status-pill.pending {
  background: #fff7ed;
  color: #c2410c;
  border: 1px solid #ffedd5;
}

.status-pill.inspected {
  background: #f0fdf4;
  color: #15803d;
  border: 1px solid #dcfce7;
}

.score-badge {
  font-weight: 700;
  color: var(--primary);
}

/* Review Modal Styles */
.review-modal {
  display: flex;
  flex-direction: column;
  gap: 20px;
  max-height: 80vh;
}

.review-header-info {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 15px;
  border-bottom: 1px solid var(--border);
}

.review-total-display {
  text-align: right;
}

.review-total-display .label {
  display: block;
  font-size: 12px;
  color: var(--text-light);
  text-transform: uppercase;
}

.review-total-display .value {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--primary);
}

.review-answers-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow-y: auto;
  padding: 4px;
}

.review-answer-item {
  padding: 16px !important;
}

.review-q-row {
  display: flex;
  gap: 20px;
}

.review-q-main {
  flex: 1;
}

.review-q-text {
  font-weight: 600;
  margin-bottom: 12px;
}

.review-student-ans {
  background: #f8fafc;
  padding: 12px;
  border-radius: 8px;
  margin-bottom: 12px;
}

.ans-label {
  font-size: 11px;
  text-transform: uppercase;
  color: var(--text-light);
  margin-bottom: 4px;
}

.ans-content {
  font-style: italic;
  color: var(--text);
  white-space: pre-wrap;
}

.review-mc-key {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
}

.review-q-grading {
  width: 120px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.review-q-grading label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-light);
}

.review-q-grading input {
  padding: 8px;
  text-align: center;
  font-weight: 700;
  font-size: 1.1rem;
}

.review-footer {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  padding-top: 15px;
  border-top: 1px solid var(--border);
}

.q-header {
  display: flex;
  justify-content: space-between;
  border-bottom: 1px solid #f1f5f9;
  padding-bottom: 12px;
  margin-bottom: 16px;
}

.q-number {
  font-weight: 600;
  color: var(--primary);
}

.q-score {
  font-size: 0.9rem;
  color: var(--text-light);
}

.q-text {
  font-size: 1.1rem;
  margin-bottom: 20px;
  line-height: 1.6;
}

.q-options {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.q-option-label {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.2s;
}

.q-option-label:hover {
  background: #f8fafc;
  border-color: var(--primary-light);
}

.q-option-label input[type="radio"] {
  width: 20px;
  height: 20px;
}

.option-letter {
  font-weight: 700;
  color: var(--text-light);
  width: 24px;
}

.q-open-answer {
  width: 100%;
  padding: 16px;
  border-radius: 12px;
  border: 1px solid #e2e8f0;
  font-family: inherit;
  font-size: 1rem;
}

.test-submit-bar {
  padding: 40px 0 80px;
  text-align: center;
}

/* ===== App Layout ===== */
.app-layout {
  display: flex;
  min-height: 100vh;
  height: 100vh;
  height: 100dvh;
  width: 100%;
  max-width: 100vw;
  overflow-x: hidden;
}

.sidebar-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  z-index: 95;
}

/* ===== Sidebar ===== */
.sidebar {
  width: 250px;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  height: 100vh;
  height: 100dvh;
  min-height: 100svh;
  z-index: 100;
  transition: transform 0.3s;
  padding-bottom: env(safe-area-inset-bottom);
}

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

.sidebar-brand-mark {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: rgba(255,255,255,0.08);
}

.sidebar-school-logo {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.sidebar-header .logo-icon { font-size: 28px; }
.sidebar-header h2 { font-size: 18px; color: white; font-weight: 600; margin-bottom: 8px; }
.class-id-display {
  font-size: 12px;
  color: #a8dadc;
  background: rgba(255,255,255,0.08);
  padding: 6px 10px;
  border-radius: 4px;
  margin-top: 6px;
  font-family: 'Courier New', monospace;
  text-align: center;
  line-height: 1.4;
  min-height: 20px;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  word-break: break-all;
  box-sizing: border-box;
}

.sidebar-nav { flex: 1; padding: 12px 0; }

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 20px;
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 14px;
  transition: all 0.2s;
  border-left: 3px solid transparent;
}

.nav-link:hover {
  background: rgba(255,255,255,0.05);
  color: white;
}

.nav-link.active {
  background: rgba(79, 70, 229, 0.2);
  color: white;
  border-left-color: var(--primary-light);
}

.nav-icon { font-size: 18px; width: 24px; text-align: center; }

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

.user-info {
  display: flex;
  flex-direction: column;
  margin-bottom: 10px;
}

.user-info span { font-size: 12px; }
.school-label { color: var(--primary-light); margin-top: 2px; }
.grade-label { color: rgba(255,255,255,0.75); font-size: 11px; }

/* ===== Main Content ===== */
.main-content {
  flex: 1;
  margin-left: 250px;
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

.top-bar {
  background: white;
  padding: 16px 24px;
  display: flex;
  align-items: center;
  gap: 16px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
}

.top-bar h1 { font-size: 20px; flex: 1; }

/* ===== Sidebar Theme Panel ===== */
.sidebar-theme-panel {
  padding: 14px 20px;
  border-top: 1px solid rgba(255,255,255,0.1);
}

.theme-panel-title {
  display: block;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.45);
  margin-bottom: 10px;
}

.theme-swatches {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}

.theme-swatch {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
}

.swatch-circle {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: block;
  border: 2px solid rgba(255,255,255,0.15);
  transition: border-color 0.2s, transform 0.15s, box-shadow 0.2s;
}

.theme-swatch:hover .swatch-circle {
  transform: scale(1.1);
  border-color: rgba(255,255,255,0.4);
}

.theme-swatch.active .swatch-circle {
  border: 2px solid #fff;
  box-shadow: 0 0 0 2px var(--primary-light);
  transform: scale(1.05);
}

.swatch-label {
  font-size: 10px;
  color: rgba(255,255,255,0.55);
  line-height: 1;
}

.theme-swatch.active .swatch-label {
  color: #fff;
  font-weight: 600;
}

.hamburger {
  display: none;
  background: none;
  border: none;
  font-size: 24px;
  cursor: pointer;
  padding: 4px;
}

#top-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.tab-group {
  display: flex;
  background: #f1f5f9;
  padding: 4px;
  border-radius: 10px;
  gap: 4px;
}

.tab-group .btn {
  padding: 6px 16px;
  font-size: 13px;
  border-radius: 8px;
  border: none !important;
  background: transparent;
  color: #64748b;
  box-shadow: none !important;
}

.tab-group .btn.btn-primary {
  background: white !important;
  color: var(--primary) !important;
  box-shadow: 0 2px 4px rgba(0,0,0,0.05) !important;
  font-weight: 700;
}

.content-area {
  padding: 24px;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* ===== Cards ===== */
.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
  margin-bottom: 20px;
  min-width: 0;
  max-width: 100%;
}

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

.card-header h3 { font-size: 16px; }

/* ===== Tables ===== */
.table-wrapper {
  overflow-x: auto;
  border-radius: var(--radius);
  -webkit-overflow-scrolling: touch;
  width: 100%;
  max-width: 100%;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

thead th {
  background: #f8fafc;
  padding: 12px 14px;
  text-align: left;
  font-weight: 600;
  color: var(--text);
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}

.resizable-col {
  position: relative;
}

.col-resizer {
  position: absolute;
  top: 0;
  right: -4px;
  width: 10px;
  height: 100%;
  cursor: col-resize;
  touch-action: none;
  z-index: 5;
}

.col-resizer::after {
  content: '';
  position: absolute;
  right: 4px;
  top: 20%;
  width: 2px;
  height: 60%;
  background: rgba(148, 163, 184, 0.6);
  border-radius: 2px;
  opacity: 0;
  transition: opacity 0.12s ease, background-color 0.12s ease;
}

.resizable-col:hover .col-resizer::after,
.resizable-col:focus-within .col-resizer::after,
body.col-resizing .col-resizer::after,
.col-resizer.dragging::after,
.col-resizer:hover::after {
  opacity: 1;
}

.col-resizer:hover::after,
body.col-resizing .col-resizer::after {
  background: var(--primary-dark);
}

body.col-resizing,
body.col-resizing * {
  cursor: col-resize !important;
  user-select: none !important;
}

tbody td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
}

tbody tr:hover { background: #f8fafc; }
tbody tr:last-child td { border-bottom: none; }

/* ===== Form Row ===== */
.form-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: flex-end;
  margin-bottom: 16px;
}

.form-row .form-group { margin-bottom: 0; flex: 1; min-width: 150px; }

/* ===== Score Inputs ===== */
.score-input {
  width: 80px;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 13px;
  text-align: center;
  background: white;
}

.score-input:focus {
  outline: none;
  border-color: var(--primary);
}

/* ===== Badges ===== */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 500;
}

.badge-success { background: #d1fae5; color: #065f46; }
.badge-danger { background: #fee2e2; color: #991b1b; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-info { background: #dbeafe; color: #1e40af; }

/* ===== Status Select ===== */
.status-select {
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 13px;
  min-width: 110px;
  background: white;
}

/* ===== Tags/Chips ===== */
.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: #eef2ff;
  color: var(--primary);
  border-radius: 20px;
  font-size: 13px;
}

.tag-remove {
  background: none;
  border: none;
  color: var(--danger);
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  padding: 0;
}

.tag-remove:hover { color: #991b1b; }

/* ===== Settings Grid ===== */
.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 20px;
}

.school-logo-upload-shell {
  display: grid;
  gap: 10px;
}

.school-logo-preview {
  width: 100%;
  max-width: 220px;
  aspect-ratio: 1;
  border: 1px dashed var(--border);
  border-radius: 10px;
  background: #f8fafc;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.school-logo-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #ffffff;
}

.school-logo-placeholder {
  color: var(--text-light);
  font-size: 12px;
  text-align: center;
  padding: 12px;
}

.school-logo-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.school-logo-controls input[type="file"] {
  max-width: 100%;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
}

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

.modal {
  background: white;
  border-radius: 12px;
  width: 90%;
  max-width: 600px;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,0.2);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: white;
  border-radius: 12px 12px 0 0;
}

.modal-header h3 { font-size: 18px; }

.modal-close {
  background: none;
  border: none;
  font-size: 24px;
  color: var(--text-light);
  cursor: pointer;
  padding: 0 4px;
}

.modal-close:hover { color: var(--text); }

.modal-body { padding: 24px; }

/* ===== Toast ===== */
.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  padding: 12px 20px;
  border-radius: 8px;
  color: white;
  font-size: 14px;
  animation: toastSlideIn 0.3s ease;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  max-width: 350px;
}

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

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

/* ===== Empty State ===== */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-light);
}

.empty-state .empty-icon { font-size: 48px; margin-bottom: 12px; }
.empty-state h3 { margin-bottom: 8px; color: var(--text); }

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

.filter-bar select,
.filter-bar input {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  min-width: 150px;
  background: white;
}

.filter-bar select:focus,
.filter-bar input:focus {
  outline: none;
  border-color: var(--primary);
}

.score-sheet-shell {
  padding: 20px;
  min-width: 0;
  max-width: 100%;
}

.score-sheet-toolbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  margin-bottom: 18px;
  flex-wrap: wrap;
}

.score-sheet-heading {
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
}

.score-sheet-heading h3 {
  font-size: 20px;
}

.score-sheet-meta {
  color: var(--text-light);
  font-size: 13px;
}

.score-sheet-controls {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.score-sheet-controls select,
.score-sheet-controls input {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  min-width: 220px;
  background: white;
}

.score-sheet-controls input {
  min-width: 260px;
}

.score-grid-shell {
  display: grid;
  grid-template-columns: minmax(170px, 220px) 1fr;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: #fff;
}

.score-frozen-col {
  border-right: 1px solid var(--border);
  background: #fff;
}

.score-scroll-col.table-wrapper {
  width: 100%;
  max-width: 100%;
  overflow-x: auto !important;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-x;
  overscroll-behavior-x: contain;
  scrollbar-gutter: stable both-edges;
}

.score-sheet-table {
  border-collapse: collapse;
}

.score-frozen-table {
  width: 100%;
  min-width: 100%;
}

.score-scroll-table {
  width: 100%;
  min-width: 100%;
}

.score-sheet-table thead th {
  background: var(--table-header-bg);
  color: #fff;
  white-space: nowrap;
  border-right: 1px solid rgba(255, 255, 255, 0.2);
  padding: 12px 14px;
  text-align: left;
}

.score-sheet-table tbody td {
  white-space: nowrap;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  padding: 10px 14px;
}

.score-sheet-table tbody tr:last-child td {
  border-bottom: none;
}

.score-frozen-table th,
.score-frozen-table td {
  min-width: 170px;
}

.score-scroll-table th {
  min-width: 120px;
}

.score-scroll-table th:nth-child(1) {
  min-width: 170px;
}

.score-scroll-table th:nth-child(2),
.score-scroll-table th:nth-child(3),
.score-scroll-table th:nth-child(8) {
  min-width: 160px;
}

.score-sheet-table thead th:last-child,
.score-sheet-table tbody td:last-child {
  border-right: none;
}

.teacher-comments-grid-shell {
  display: grid;
  grid-template-columns: minmax(190px, 250px) 1fr;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: #fff;
}

.teacher-comments-frozen-col {
  border-right: 1px solid var(--border);
  background: #fff;
}

.teacher-comments-scroll-col.table-wrapper {
  width: 100%;
  max-width: 100%;
  overflow-x: auto !important;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-x;
  overscroll-behavior-x: contain;
}

.teacher-comments-frozen-table {
  width: 100%;
  min-width: 100%;
}

.teacher-comments-scroll-table {
  width: 100%;
  min-width: 100%;
}

.teacher-comments-frozen-table th,
.teacher-comments-frozen-table td {
  min-width: 190px;
}

.teacher-comments-scroll-table th:nth-child(1) { min-width: 140px; }
.teacher-comments-scroll-table th:nth-child(2) { min-width: 360px; }
.teacher-comments-scroll-table th:nth-child(3) { min-width: 180px; }
.teacher-comments-scroll-table th:nth-child(4) { min-width: 190px; }

.teacher-comment-text {
  max-width: 560px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.teacher-comments-scroll-table tbody td:last-child {
  white-space: nowrap;
}

.score-entry-card {
  margin-top: 18px;
  min-width: 0;
  max-width: 100%;
}

.score-entry-meta {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 8px;
}

.score-entry-settings {
  margin-top: 16px;
}

.report-grid-shell {
  display: grid;
  grid-template-columns: minmax(170px, 220px) 1fr;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: #fff;
}

.report-frozen-col {
  border-right: 1px solid var(--border);
  background: #fff;
}

.report-scroll-col.table-wrapper {
  width: 100%;
  max-width: 100%;
  overflow-x: auto !important;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-x;
  overscroll-behavior-x: contain;
}

.report-frozen-table {
  width: 100%;
  min-width: 100%;
}

.report-scroll-table {
  width: 100%;
  min-width: 100%;
}

.report-frozen-table th,
.report-frozen-table td {
  min-width: 170px;
}

.report-scroll-table th {
  min-width: 120px;
}

.report-scroll-table th:nth-child(1),
.report-scroll-table th:nth-child(2),
.report-scroll-table th:nth-child(6) {
  min-width: 160px;
}

.report-scroll-table th:nth-child(14),
.report-scroll-table th:nth-child(15) {
  min-width: 130px;
}

.student-toolbar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.student-pagination-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
  color: var(--text-light);
  font-size: 13px;
}

.student-pagination-controls select {
  min-width: 64px;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
}

.student-pagination-controls .btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.student-grid-shell {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: #fff;
}

.student-frozen-col {
  display: none;
}

.student-scroll-col.table-wrapper {
  width: 100%;
  max-width: 100%;
  overflow-x: auto !important;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-x;
  overscroll-behavior-x: contain;
}

.student-table {
  border-collapse: collapse;
  width: max-content;
  min-width: 100%;
}

.student-frozen-table {
  width: 100%;
  min-width: 100%;
}

.student-scroll-table {
  width: max-content;
  min-width: 100%;
}

.student-table thead th {
  background: var(--table-header-bg);
  color: #fff;
  white-space: nowrap;
  border-right: 1px solid rgba(255, 255, 255, 0.2);
  padding: 12px 14px;
  text-align: left;
}

.student-table tbody td {
  white-space: nowrap;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  padding: 10px 14px;
}

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

.student-scroll-table th:nth-child(1),
.student-scroll-table td:nth-child(1) {
  position: sticky;
  left: 0;
  z-index: 2;
  min-width: 170px;
  width: 220px;
  background: #fff;
  box-shadow: 1px 0 0 var(--border);
}

.student-scroll-table thead th:nth-child(1) {
  z-index: 3;
  background: var(--table-header-bg);
}

.student-scroll-table th:nth-child(2),
.student-scroll-table td:nth-child(2) {
  min-width: 170px;
}

.student-scroll-table th:nth-child(3),
.student-scroll-table td:nth-child(3) {
  min-width: 240px;
}

.student-scroll-table th:nth-child(4),
.student-scroll-table td:nth-child(4) {
  min-width: 120px;
}

.student-scroll-table th:nth-child(5),
.student-scroll-table td:nth-child(5) {
  min-width: 170px;
}

.student-scroll-table th:nth-child(6),
.student-scroll-table td:nth-child(6) {
  min-width: 100px;
}

.student-scroll-table th:nth-child(7),
.student-scroll-table td:nth-child(7) {
  min-width: 100px;
}

.student-scroll-table th:nth-child(8),
.student-scroll-table td:nth-child(8) {
  min-width: 300px;
}

.student-table thead th:last-child,
.student-table tbody td:last-child {
  border-right: none;
}

.student-actions-cell {
  min-width: 300px;
}

.student-actions-cell .btn {
  margin-right: 6px;
}

.student-actions-cell .btn:last-child {
  margin-right: 0;
}

.row-clickable {
  cursor: pointer;
}

.row-clickable:hover td {
  background: #eef2ff;
}

.row-details p {
  margin-bottom: 8px;
}

.row-detail-actions {
  display: flex;
  gap: 8px;
  margin-top: 14px;
}

.row-detail-actions-wrap {
  flex-wrap: wrap;
}

.attendance-shell {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.attendance-main-action {
  display: flex;
  justify-content: center;
}

.attendance-main-action .btn {
  min-width: 220px;
}

.attendance-switcher {
  display: flex;
  justify-content: center;
  gap: 8px;
}

.attendance-switch-btn {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  border-radius: 999px;
  padding: 8px 16px;
  font-weight: 600;
  cursor: pointer;
}

.attendance-switch-btn.active {
  background: var(--primary-dark);
  color: #fff;
  border-color: var(--primary-dark);
}

.attendance-current-meta {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.attendance-current-meta .form-group {
  margin-bottom: 0;
}

.attendance-current-meta .btn {
  margin-bottom: 0;
}

.att-status-pill {
  display: inline-block;
  padding: 3px 12px;
  border-radius: 12px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  user-select: none;
  border: none;
  transition: opacity 0.15s;
}
.att-status-pill:hover { opacity: 0.8; }
.att-status-pill[data-status="Present"] { background: #d1fae5; color: #065f46; }
.att-status-pill[data-status="Absent"]  { background: #fee2e2; color: #991b1b; }

.attendance-history-note {
  color: var(--text-light);
  font-size: 13px;
  margin-bottom: 10px;
}

.attendance-active-students {
  border: 1px dashed var(--border);
  border-radius: 8px;
  padding: 10px;
  margin-bottom: 14px;
  background: #f8fafc;
}

.attendance-grid-shell {
  display: grid;
  grid-template-columns: minmax(170px, 220px) 1fr;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: #fff;
}

.attendance-frozen-col {
  border-right: 1px solid var(--border);
  background: #fff;
}

.attendance-scroll-col.table-wrapper {
  width: 100%;
  max-width: 100%;
  overflow-x: auto !important;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-x;
  overscroll-behavior-x: contain;
}

.attendance-table {
  border-collapse: collapse;
}

.attendance-frozen-table {
  width: 100%;
  min-width: 100%;
}

.attendance-scroll-table {
  width: 100%;
  min-width: 100%;
}

.attendance-table thead th {
  background: var(--table-header-bg);
  color: #fff;
  white-space: nowrap;
  border-right: 1px solid rgba(255, 255, 255, 0.2);
  padding: 12px 14px;
  text-align: left;
}

.attendance-table tbody td {
  white-space: nowrap;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  padding: 10px 14px;
}

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

.attendance-frozen-table th,
.attendance-frozen-table td {
  min-width: 170px;
}

.attendance-scroll-table th:nth-child(1) {
  min-width: 170px;
}

.attendance-scroll-table th:nth-child(2) {
  min-width: 180px;
}

.attendance-scroll-table th:nth-child(3) {
  min-width: 170px;
}

.attendance-scroll-table th:nth-child(4) {
  min-width: 180px;
}

.attendance-table thead th:last-child,
.attendance-table tbody td:last-child {
  border-right: none;
}

/* ===== Summary Stats ===== */
.stats-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.grading-scale-table {
  width: max-content;
  min-width: max-content;
  border-collapse: collapse;
}

#grading-scale-card .table-wrapper {
  display: inline-block;
  max-width: 100%;
  overflow-x: auto;
  vertical-align: top;
}

#grading-scale-card .table-wrapper .grading-scale-table {
  width: max-content !important;
  min-width: max-content !important;
}

.grading-scale-table th,
.grading-scale-table td {
  padding: 4px 3px;
  min-width: 0;
}

#grading-scale-card .grading-scale-table th {
  white-space: nowrap;
  font-size: 11px;
}

.grading-scale-table .gs-input,
.grading-scale-table select {
  width: auto;
  min-width: 0;
  padding: 4px 6px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  font-size: 12px;
}

.grading-scale-table .gs-input-desc { width: 9ch; }
.grading-scale-table .gs-input-num { width: 6.5ch; }
.grading-scale-table .gs-input-lg { width: 4.5ch; }
.grading-scale-table .gs-input-ng { width: 5.5ch; }
.grading-scale-table .gs-input-rank { width: 5.5ch; }
.grading-scale-table .gs-select-pass { width: 4.5ch; }

.grading-scale-table .gs-input-num,
.grading-scale-table .gs-input-ng,
.grading-scale-table .gs-input-rank {
  appearance: textfield;
  -moz-appearance: textfield;
}

.grading-scale-table .gs-input-num::-webkit-outer-spin-button,
.grading-scale-table .gs-input-num::-webkit-inner-spin-button,
.grading-scale-table .gs-input-ng::-webkit-outer-spin-button,
.grading-scale-table .gs-input-ng::-webkit-inner-spin-button,
.grading-scale-table .gs-input-rank::-webkit-outer-spin-button,
.grading-scale-table .gs-input-rank::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.grading-scale-table .gs-remove-btn {
  min-width: 0;
  padding: 3px 5px;
}



.stat-chip {
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 500;
}

.stat-chip.present { background: #d1fae5; color: #065f46; }
.stat-chip.absent { background: #fee2e2; color: #991b1b; }
.stat-chip.late { background: #fef3c7; color: #92400e; }
.stat-chip.excused { background: #dbeafe; color: #1e40af; }

/* ===== Responsive ===== */
@media (max-width: 768px) {
  body.sidebar-open { overflow: hidden; }

  .sidebar {
    transform: translateX(-100%);
    z-index: 110;
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .main-content { margin-left: 0; }
  .hamburger { display: block; }
  .content-area { padding: 14px; }
  .form-row .form-group { min-width: 100%; }
  .settings-grid { grid-template-columns: 1fr; }
  .card { padding: 16px; }
  .top-bar { padding: 12px 14px; gap: 10px; }
  .top-bar h1 { font-size: 18px; }
  #top-actions {
    width: 100%;
    gap: 8px;
    justify-content: stretch;
  }
  #top-actions .btn {
    flex: 1 1 calc(50% - 8px);
    justify-content: center;
    padding: 10px;
    font-size: 13px;
  }
  .btn { white-space: normal; }

  .form-row {
    flex-direction: column;
    align-items: stretch;
  }

  .form-row > .btn,
  .filter-bar > .btn {
    width: 100%;
    justify-content: center;
  }

  .filter-bar {
    flex-direction: column;
    align-items: stretch;
  }

  .filter-bar select,
  .filter-bar input {
    min-width: 100%;
  }

  .score-sheet-shell {
    padding: 16px;
  }

  .score-sheet-toolbar,
  .score-sheet-controls {
    flex-direction: column;
    align-items: stretch;
  }

  .score-sheet-controls select,
  .score-sheet-controls input,
  .score-sheet-controls .btn {
    width: 100%;
    min-width: 100%;
  }

  .table-wrapper table {
    min-width: 680px;
  }

  #grading-scale-card .table-wrapper .grading-scale-table {
    min-width: max-content !important;
  }

  .grading-scale-table th,
  .grading-scale-table td {
    padding: 3px 2px;
    font-size: 11px;
  }

  .grading-scale-table .gs-input,
  .grading-scale-table .gs-select-pass {
    padding: 3px 4px;
    font-size: 11px;
  }

  .grading-scale-table .gs-input-desc { width: 8ch; }
  .grading-scale-table .gs-input-num,
  .grading-scale-table .gs-input-lg,
  .grading-scale-table .gs-input-ng,
  .grading-scale-table .gs-input-rank,
  .grading-scale-table .gs-select-pass { width: 5.5ch; }

  .grading-scale-table td:nth-child(8) .btn {
    padding: 2px 4px;
    font-size: 10px;
  }

  .modal-overlay {
    align-items: flex-end;
    padding: 0;
  }

  .modal {
    width: 100%;
    max-width: none;
    max-height: 92vh;
    border-radius: 16px 16px 0 0;
  }

  .modal-header,
  .modal-body {
    padding-left: 16px;
    padding-right: 16px;
  }

  .toast-container {
    top: auto;
    bottom: 12px;
    right: 12px;
    left: 12px;
  }

  .toast {
    max-width: none;
    width: 100%;
  }
}

@media (max-width: 480px) {
  .auth-card { padding: 24px; }
  .sidebar {
    width: min(84vw, 300px);
  }

  .card {
    padding: 14px;
  }

  #top-actions .btn {
    flex-basis: 100%;
  }

  .table-wrapper table {
    min-width: 560px;
  }

  #grading-scale-card .table-wrapper .grading-scale-table {
    min-width: max-content !important;
  }

  .grading-scale-table th,
  .grading-scale-table td {
    padding: 2px 2px;
  }

  .grading-scale-table .gs-input-desc { width: 7ch; }
  .grading-scale-table .gs-input-num,
  .grading-scale-table .gs-input-lg,
  .grading-scale-table .gs-input-ng,
  .grading-scale-table .gs-input-rank,
  .grading-scale-table .gs-select-pass { width: 5ch; }

  .score-grid-shell {
    grid-template-columns: minmax(150px, 170px) 1fr;
  }

  .score-scroll-table {
    width: 100%;
    min-width: 100%;
  }

  .report-grid-shell {
    grid-template-columns: minmax(150px, 170px) 1fr;
  }

  .report-scroll-table {
    width: 100%;
    min-width: 100%;
  }

  .student-grid-shell {
    grid-template-columns: minmax(150px, 170px) 1fr;
  }

  .student-scroll-table {
    width: 100%;
    min-width: 100%;
  }

  .attendance-grid-shell {
    grid-template-columns: minmax(150px, 170px) 1fr;
  }

  .teacher-comments-grid-shell {
    grid-template-columns: minmax(150px, 170px) 1fr;
  }

  .attendance-scroll-table {
    width: 100%;
    min-width: 100%;
  }

  .teacher-comments-scroll-table {
    width: 100%;
    min-width: 100%;
  }

  .attendance-grid-shell {
    grid-template-columns: 140px 1fr;
  }

  .attendance-scroll-table {
    width: 100%;
    min-width: 100%;
  }
}

@media (max-width: 400px) {
  .content-area {
    padding: 10px;
  }

  .card {
    padding: 12px;
    border-radius: 10px;
    margin-bottom: 12px;
  }

  .top-bar {
    padding: 10px;
  }

  .modal-header,
  .modal-body {
    padding-left: 12px;
    padding-right: 12px;
  }

  .table-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .table-wrapper table {
    min-width: 560px;
  }

  #grading-scale-card .table-wrapper .grading-scale-table {
    min-width: max-content !important;
  }

  .score-grid-shell {
    grid-template-columns: 140px 1fr;
  }

  .score-scroll-table {
    width: 100%;
    min-width: 100%;
  }

  .report-grid-shell {
    grid-template-columns: 140px 1fr;
  }

  .report-scroll-table {
    width: 100%;
    min-width: 100%;
  }

  .student-grid-shell {
    grid-template-columns: 140px 1fr;
  }

  .teacher-comments-grid-shell {
    grid-template-columns: 140px 1fr;
  }

  .student-scroll-table {
    width: 100%;
    min-width: 100%;
  }

  .teacher-comments-scroll-table {
    width: 100%;
    min-width: 100%;
  }

  .stats-row {
    gap: 8px;
  }

  .stat-chip {
    width: 100%;
    text-align: center;
  }
}

/* ===== PHOTOS SECTION ===== */

.photos-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(139px, 1fr));
  gap: 13px;
  padding: 12px 0;
}

.photo-card {
  display: flex;
  flex-direction: column;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: transform 0.2s, box-shadow 0.2s;
  cursor: pointer;
}

.photo-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 8px 16px rgba(0,0,0,0.12);
}

.photo-avatar {
  width: 100%;
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
  cursor: pointer;
}

.photo-avatar-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.avatar-initials {
  font-size: 31px;
  font-weight: 700;
  color: #ffffff;
  user-select: none;
}

.photo-info {
  padding: 10px;
}

.photo-name {
  font-size: 11px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 7px;
  word-break: break-word;
}

.photo-detail {
  font-size: 9px;
  color: var(--text-light);
  margin-bottom: 4px;
  line-height: 1.4;
}

.photo-detail strong {
  color: var(--text);
  font-weight: 500;
}

.photo-detail:last-child {
  margin-bottom: 0;
}

.photo-upload-hint {
  margin-top: 6px;
  color: var(--primary-dark);
  font-weight: 600;
}

.photo-upload-shell {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.photo-current-preview-wrap {
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: #f8fafc;
}

.photo-current-preview {
  width: 100%;
  max-height: 380px;
  object-fit: contain;
  display: block;
}

.photo-upload-note {
  color: var(--text-light);
  font-size: 13px;
}

.photo-upload-picker-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.photo-file-input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.photo-crop-stage {
  width: 100%;
  border: 1px dashed var(--border);
  border-radius: 8px;
  padding: 8px;
  background: #f8fafc;
}

#photo-crop-canvas {
  width: 100%;
  max-width: 280px;
  height: auto;
  border-radius: 6px;
  display: block;
  margin: 0 auto;
  background: #f1f5f9;
  touch-action: none;
}

.photo-zoom-group {
  margin-bottom: 0;
}

@media (max-width: 768px) {
  .photos-grid {
    grid-template-columns: repeat(auto-fill, minmax(113px, 1fr));
    gap: 10px;
  }

  .avatar-initials {
    font-size: 23px;
  }
}

@media (max-width: 600px) {
  .photos-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 7px;
  }

  .photo-avatar {
    aspect-ratio: 6 / 3;
  }

  .photo-card {
    border-radius: 6px;
  }

  .photo-info {
    padding: 7px;
  }

  .photo-name {
    font-size: 10px;
    margin-bottom: 6px;
  }

  .photo-detail {
    font-size: 8px;
    margin-bottom: 3px;
  }

  .avatar-initials {
    font-size: 11px;
  }

  .photo-upload-picker-row .btn {
    width: 100%;
    justify-content: center;
  }
}

@media (max-width: 400px) {
  .photos-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 5px;
  }

  .photo-avatar {
    aspect-ratio: 1 / 1;
  }
}

.back-to-home {
  margin-top: 20px;
  text-align: center;
}

.btn-link {
  background: none;
  border: none;
  color: #667eea;
  cursor: pointer;
  font-size: 0.9rem;
  text-decoration: none;
  padding: 10px;
  transition: color 0.3s;
}

.btn-link:hover {
  color: #764ba2;
}

@media (max-width: 768px) {
  .auth-page #auth-container {
    max-width: 90vw;
    padding: 30px;
  }
}
/* ===== ONBOARDING FLOW ===== */
.onboarding-container {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  z-index: 1000;
  overflow: hidden;
}

.onboarding-modal {
  position: relative;
  background: white;
  border-radius: 16px;
  width: 90%;
  max-width: 600px;
  max-height: 88vh;
  box-shadow: 0 25px 50px rgba(0, 0, 0, 0.25);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: obSlideIn 0.3s ease-out;
}

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

.onboarding-header {
  background: linear-gradient(135deg, #4f46e5 0%, #3730a3 100%);
  color: white;
  padding: 24px 24px 18px;
  text-align: center;
  flex-shrink: 0;
}

.onboarding-header h1 {
  margin: 0 0 6px;
  font-size: 24px;
  font-weight: 700;
}

.onboarding-header p {
  margin: 0;
  font-size: 13px;
  opacity: 0.9;
}

.onboarding-progress-bar {
  display: flex;
  justify-content: center;
  gap: 4px;
  padding: 14px 16px;
  background: #f8f9fa;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  overflow-x: auto;
}

.onboarding-progress-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  flex: 1;
  min-width: 0;
  opacity: 0.45;
  transition: opacity 0.2s;
}

.onboarding-progress-item.completed,
.onboarding-progress-item.current {
  opacity: 1;
}

.onboarding-progress-circle {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--border);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 13px;
  flex-shrink: 0;
}

.onboarding-progress-item.current .onboarding-progress-circle {
  background: var(--primary);
  color: white;
}

.onboarding-progress-item.completed .onboarding-progress-circle {
  background: var(--success);
  color: white;
}

.onboarding-progress-label {
  font-size: 10px;
  text-align: center;
  color: var(--text-light);
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.onboarding-content {
  padding: 24px;
  flex: 1 1 auto;
  overflow-y: auto;
  min-height: 0;
}

.onboarding-card {
  animation: obFadeIn 0.25s ease-out;
}

@keyframes obFadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.onboarding-card h2 {
  margin: 0 0 6px;
  font-size: 18px;
  color: var(--text);
}

.onboarding-card > p {
  margin: 0 0 16px;
  color: var(--text-light);
  font-size: 13px;
}

.onboarding-card .form-group {
  margin-bottom: 14px;
}

.onboarding-card .form-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  margin-bottom: 14px;
}

.onboarding-card .form-row .btn {
  flex-shrink: 0;
  white-space: nowrap;
}

.onboarding-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 12px;
  max-height: 180px;
  overflow-y: auto;
  padding: 10px;
  background: #f8f9fa;
  border-radius: 8px;
  border: 1px solid var(--border);
}

.onboarding-list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  background: white;
  border-radius: 6px;
  border: 1px solid var(--border);
  font-size: 13px;
}

.onboarding-list-item span {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.onboarding-list-item .tag {
  font-size: 11px;
  background: #eef2ff;
  color: var(--primary-dark);
  padding: 2px 6px;
  border-radius: 4px;
}

.onboarding-footer {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  background: #f8f9fa;
  flex-shrink: 0;
}

.onboarding-footer .btn {
  flex: 1;
  min-width: 80px;
  min-height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  white-space: normal;
  text-align: center;
  z-index: 10;
  position: relative;
}

.onboarding-footer .btn:disabled {
  opacity: 0.5;
  pointer-events: none;
}

.onboarding-tip {
  padding: 10px 24px;
  font-size: 11px;
  color: var(--text-light);
  background: #f8f9fa;
  text-align: center;
}
@media (max-width: 768px) {
  .top-bar {
    padding: 12px 16px;
    flex-wrap: wrap;
    gap: 12px;
  }
  
  .top-bar h2 {
    font-size: 18px;
    margin: 0;
  }

  #top-actions {
    width: 100%;
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  .tab-group {
    margin-right: 0 !important;
    width: 100%;
    overflow-x: auto;
  }

  .tab-group .btn {
    flex: 1;
    white-space: nowrap;
  }

  .top-bar .btn-primary {
    margin-top: 0;
    justify-content: center;
  }

  /* Toolbar/Filters */
  .toolbar-card .filter-row {
    flex-direction: column;
    gap: 16px;
  }
  
  .toolbar-card .form-group {
    width: 100%;
  }

  /* Grid */
  .test-questions-grid {
    grid-template-columns: 1fr;
    gap: 16px;
  }

  .onboarding-modal {
    width: 96%;
    max-height: 94vh;
    border-radius: 12px;
  }

  .onboarding-header {
    padding: 18px 16px 14px;
  }

  .onboarding-header h1 {
    font-size: 18px;
  }

  .onboarding-header p {
    font-size: 12px;
  }

  .onboarding-content {
    padding: 18px 16px;
  }

  .onboarding-footer {
    padding: 12px 16px;
  }

  .onboarding-progress-bar {
    padding: 10px 8px;
    gap: 2px;
  }

  .onboarding-progress-circle {
    width: 28px;
    height: 28px;
    font-size: 11px;
  }

  .onboarding-progress-label {
    font-size: 9px;
  }

  .onboarding-list {
    max-height: 140px;
  }
}

.student-search-input {
  min-width: 220px;
  flex: 1 1 240px;
  max-width: 360px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  background: #fff;
}