/* ==========================================================================
   ธีมระบบบันทึกส่งงานนักเรียน (The Modern Educator Theme)
   ออกแบบพิเศษเพื่อความสบายตา ครูใช้งานง่ายบน iPad, มือถือ และเดสก์ท็อป
   รองรับ ม.4 (11 ห้อง) และ ม.5 (2 ห้อง) และ 5 รายวิชา
   ========================================================================== */

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

:root {
  --bg-app: #F7F7F4;
  --bg-surface: #FFFFFF;
  --bg-subtle: #F0EFEB;
  --bg-muted: #E8E7E1;
  
  --text-main: #1C1E21;
  --text-secondary: #585D65;
  --text-muted: #8E939D;
  --text-inverse: #FFFFFF;

  --border-light: #E4E3DC;
  --border-focus: #2B4C7E;

  --primary: #2B4C7E;
  --primary-hover: #1E375C;
  --primary-subtle: #EBF1F9;
  --primary-border: #C8D9EE;

  --status-submitted-bg: #EAF7EE;
  --status-submitted-text: #1B5E20;
  --status-submitted-border: #C5E7CD;
  --status-submitted-dot: #2E7D32;

  --status-pending-bg: #FDF1ED;
  --status-pending-text: #B43411;
  --status-pending-border: #F9D5CA;
  --status-pending-dot: #D9481C;

  --status-excused-bg: #F1F4F9;
  --status-excused-text: #37474F;
  --status-excused-border: #CFD8DC;

  --shadow-sm: 0 1px 2px rgba(28, 30, 33, 0.04);
  --shadow-md: 0 4px 12px rgba(28, 30, 33, 0.06);
  --shadow-lg: 0 8px 24px rgba(28, 30, 33, 0.08);

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-full: 9999px;

  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

body {
  font-family: 'Prompt', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background-color: var(--bg-app);
  color: var(--text-main);
  line-height: 1.5;
  font-feature-settings: "tnum";
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ----------------- Top Header ----------------- */
.app-header {
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-light);
  position: sticky;
  top: 0;
  z-index: 40;
  padding: 0.65rem 1.25rem;
}

.header-container {
  max-width: 1240px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.brand-badge {
  display: flex;
  align-items: center;
  gap: 0.625rem;
}

.brand-icon {
  width: 38px;
  height: 38px;
  background: var(--primary);
  color: var(--text-inverse);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  font-weight: 600;
  flex-shrink: 0;
}

.brand-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-main);
  line-height: 1.2;
}

.brand-subtitle {
  font-size: 0.75rem;
  color: var(--text-secondary);
}

/* Global Context Bar (สลับวิชาและห้องเรียน) */
.context-selector-bar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--bg-subtle);
  padding: 0.25rem 0.6rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-light);
}

.context-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.context-select {
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 500;
  padding: 0.25rem 0.5rem;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  background: var(--bg-surface);
  color: var(--primary);
  cursor: pointer;
}

.context-select:focus {
  outline: none;
  border-color: var(--primary);
}

/* Navigation Tabs */
.nav-tabs {
  display: flex;
  background: var(--bg-subtle);
  padding: 0.25rem;
  border-radius: var(--radius-md);
  gap: 0.25rem;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.nav-tab-btn {
  border: none;
  background: transparent;
  padding: 0.4rem 0.75rem;
  font-size: 0.85rem;
  font-family: inherit;
  font-weight: 500;
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  cursor: pointer;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 0.35rem;
  transition: all 0.15s ease;
}

.nav-tab-btn:hover {
  color: var(--text-main);
}

.nav-tab-btn.active {
  background: var(--bg-surface);
  color: var(--primary);
  font-weight: 600;
  box-shadow: var(--shadow-sm);
}

/* Sync Indicator */
.sync-status-indicator {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  font-size: 0.75rem;
  padding: 0.25rem 0.625rem;
  border-radius: var(--radius-full);
  background: var(--bg-subtle);
  color: var(--text-secondary);
  border: 1px solid var(--border-light);
  white-space: nowrap;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #10B981;
}

.status-dot.syncing {
  background: #F59E0B;
  animation: pulse 1s infinite;
}

.status-dot.offline {
  background: #6B7280;
}

/* Main Container */
.main-content {
  flex: 1;
  max-width: 1240px;
  width: 100%;
  margin: 0 auto;
  padding: 1.25rem;
}

/* ----------------- Classrooms Pill Navigation ----------------- */
.classroom-pill-strip {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  overflow-x: auto;
  padding: 0.35rem 0.15rem;
  margin-bottom: 0.75rem;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
}

.classroom-pill-strip::-webkit-scrollbar {
  height: 5px;
}

.classroom-pill-strip::-webkit-scrollbar-track {
  background: #F1F5F9;
  border-radius: 4px;
}

.classroom-pill-strip::-webkit-scrollbar-thumb {
  background: #CBD5E1;
  border-radius: 4px;
}

.classroom-pill-strip::-webkit-scrollbar-thumb:hover {
  background: #94A3B8;
}

.class-pill {
  border: 1px solid var(--border-light);
  background: var(--bg-surface);
  padding: 0.35rem 0.75rem;
  font-size: 0.8rem;
  font-weight: 500;
  font-family: inherit;
  border-radius: var(--radius-full);
  cursor: pointer;
  white-space: nowrap;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 0.35rem;
  transition: all 0.12s ease;
}

.class-pill:hover {
  border-color: var(--primary-border);
  color: var(--primary);
}

.class-pill.active {
  background: var(--primary);
  color: var(--text-inverse);
  border-color: var(--primary);
  font-weight: 600;
}

.class-pill .badge {
  background: rgba(0, 0, 0, 0.08);
  padding: 0.1rem 0.35rem;
  border-radius: var(--radius-full);
  font-size: 0.7rem;
}

.class-pill.active .badge {
  background: rgba(255, 255, 255, 0.25);
  color: #FFFFFF;
}

/* ----------------- Cards & Stats ----------------- */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  box-shadow: var(--shadow-sm);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.card-title {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-main);
}

.stats-ribbon {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}

@media (min-width: 640px) {
  .stats-ribbon {
    grid-template-columns: repeat(4, 1fr);
  }
}

.stat-box {
  background: var(--bg-subtle);
  border-radius: var(--radius-md);
  padding: 0.875rem;
  border: 1px solid var(--border-light);
}

.stat-label {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-bottom: 0.25rem;
}

.stat-value {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-main);
  line-height: 1.1;
}

.stat-box.success .stat-value { color: var(--status-submitted-text); }
.stat-box.warning .stat-value { color: var(--status-pending-text); }

/* Quick Action Tiles */
.quick-action-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 0.75rem;
  margin-top: 1rem;
}

.action-tile-btn {
  background: var(--bg-surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: 1rem;
  text-align: left;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  transition: all 0.15s ease;
  font-family: inherit;
}

.action-tile-btn:hover {
  border-color: var(--primary-border);
  background: var(--primary-subtle);
  transform: translateY(-1px);
}

.tile-icon {
  font-size: 1.5rem;
}

.tile-title {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-main);
}

.tile-desc {
  font-size: 0.75rem;
  color: var(--text-secondary);
}

/* ----------------- Grading Layout ----------------- */
.grading-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.25rem;
}

/* รองรับ iPad แนวตั้ง (Portrait 768px+) และจอคอมพิวเตอร์ */
@media (min-width: 768px) {
  .grading-layout {
    grid-template-columns: 1fr 340px;
    align-items: start;
  }
}

/* ป้องกัน iOS / iPadOS Safari Auto-zoom เมื่อแตะช่องกรอกข้อความ */
.form-input, .select-control, .import-textarea, input, select, textarea {
  font-size: 16px;
  touch-action: manipulation;
}

/* แถบสลับหน้าชุดงานในหน้ารายงาน */
.report-page-tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.report-page-btn {
  font-family: inherit;
  font-size: 0.85rem;
  padding: 0.4rem 0.85rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-light);
  background: var(--bg-surface);
  color: var(--text-secondary);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  transition: all 0.15s ease;
  user-select: none;
}

.report-page-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.report-page-btn.active {
  background: var(--primary);
  color: #FFFFFF;
  border-color: var(--primary);
  font-weight: 600;
}

.assignment-bar {
  background: var(--bg-surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  padding: 1rem 1.25rem;
  margin-bottom: 1rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.875rem;
}

.select-control {
  font-family: inherit;
  font-size: 0.95rem;
  padding: 0.5rem 0.85rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-light);
  background-color: var(--bg-surface);
  color: var(--text-main);
  min-width: 220px;
  cursor: pointer;
}

.btn-group {
  display: inline-flex;
  gap: 0.375rem;
}

.btn {
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 500;
  padding: 0.5rem 0.875rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-light);
  background: var(--bg-surface);
  color: var(--text-main);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
  transition: all 0.15s ease;
  user-select: none;
}

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

.btn-primary {
  background: var(--primary);
  color: var(--text-inverse);
  border-color: var(--primary);
}

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

.btn-success {
  background: #2E7D32;
  color: #FFFFFF;
  border-color: #2E7D32;
}

.btn-success:hover {
  background: #1B5E20;
}

.btn-secondary {
  background: var(--bg-subtle);
  border-color: var(--border-light);
}

.btn-danger {
  background: #DC2626;
  color: #FFFFFF;
  border-color: #DC2626;
}

.btn-danger:hover {
  background: #B91C1C;
}

.btn-danger-soft {
  color: #DC2626 !important;
  background-color: #FEF2F2 !important;
  border-color: #FECACA !important;
}

.btn-danger-soft:hover {
  background-color: #FEE2E2 !important;
  border-color: #FCA5A5 !important;
  color: #B91C1C !important;
}

.btn-sm {
  padding: 0.35rem 0.625rem;
  font-size: 0.8rem;
}

/* Roster Table Styles */
.roster-table {
  width: 100%;
  border-collapse: collapse;
}

.roster-row {
  transition: background-color 0.12s ease;
}

.roster-row:nth-child(even) {
  background-color: #F8FAFC;
}

.roster-row:hover {
  background-color: #EEF2F6 !important;
}

.roster-actions {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.35rem;
  white-space: nowrap;
}

.roster-actions .btn-sm {
  padding: 0.25rem 0.55rem;
  font-size: 0.8rem;
  line-height: 1.25;
  white-space: nowrap;
}

/* Student List Table */
.student-table-container {
  background: var(--bg-surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.table-action-bar {
  padding: 0.75rem 1rem;
  background: var(--bg-subtle);
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.filter-pills {
  display: flex;
  gap: 0.25rem;
}

.pill-btn {
  border: none;
  background: transparent;
  padding: 0.25rem 0.625rem;
  font-size: 0.8rem;
  font-family: inherit;
  border-radius: var(--radius-full);
  cursor: pointer;
  color: var(--text-secondary);
}

.pill-btn.active {
  background: var(--primary);
  color: var(--text-inverse);
  font-weight: 500;
}

.student-list {
  max-height: 580px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.student-row {
  display: grid;
  grid-template-columns: 50px 85px 1fr 100px 70px;
  align-items: center;
  padding: 0.625rem 1rem;
  border-bottom: 1px solid var(--border-light);
  cursor: pointer;
  transition: background 0.12s ease;
  user-select: none;
}

@media (max-width: 600px) {
  .student-row {
    grid-template-columns: 40px 1fr 90px 60px;
  }
  .student-row .col-code {
    display: none;
  }
}

.student-row:hover {
  background: var(--bg-subtle);
}

.student-row.selected {
  background: #E8F0FE;
  outline: 2px solid var(--primary);
  outline-offset: -2px;
}

.student-no {
  font-weight: 600;
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.student-code {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.student-name {
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.2rem 0.5rem;
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  font-weight: 500;
  text-align: center;
  cursor: pointer;
  border: 1px solid transparent;
}

.status-badge.submitted {
  background: var(--status-submitted-bg);
  color: var(--status-submitted-text);
  border-color: var(--status-submitted-border);
}

.status-badge.pending {
  background: var(--status-pending-bg);
  color: var(--status-pending-text);
  border-color: var(--status-pending-border);
}

.score-display {
  font-size: 1.05rem;
  font-weight: 700;
  text-align: right;
  padding-right: 0.5rem;
}

.score-display.empty {
  color: var(--text-muted);
  font-weight: 400;
}

/* ----------------- In-App Scoring Numpad (iPad & Mobile) ----------------- */
.keypad-panel {
  background: var(--bg-surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  box-shadow: var(--shadow-md);
  position: sticky;
  top: 5rem;
}

.active-student-card {
  background: var(--bg-subtle);
  border-radius: var(--radius-md);
  padding: 0.875rem;
  margin-bottom: 1rem;
  border: 1px solid var(--border-light);
}

.active-student-no {
  font-size: 0.75rem;
  text-transform: uppercase;
  color: var(--text-secondary);
  font-weight: 600;
}

.active-student-title {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-main);
}

.quick-score-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.numpad-btn {
  font-family: inherit;
  font-size: 1.15rem;
  font-weight: 600;
  height: 48px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-light);
  background: var(--bg-surface);
  color: var(--text-main);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.1s ease;
}

.numpad-btn:hover {
  background: var(--bg-subtle);
  border-color: var(--border-focus);
}

.numpad-btn:active {
  background: var(--primary-subtle);
  transform: scale(0.96);
}

.numpad-btn.full-score {
  background: var(--primary-subtle);
  color: var(--primary);
  border-color: var(--primary-border);
  grid-column: span 3;
  font-size: 1rem;
  height: 42px;
}

.status-toggle-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.toggle-opt-btn {
  font-family: inherit;
  padding: 0.5rem;
  font-size: 0.85rem;
  font-weight: 500;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-light);
  background: var(--bg-surface);
  cursor: pointer;
  text-align: center;
}

.toggle-opt-btn.active-submitted {
  background: var(--status-submitted-bg);
  color: var(--status-submitted-text);
  border-color: var(--status-submitted-border);
  font-weight: 600;
}

.toggle-opt-btn.active-pending {
  background: var(--status-pending-bg);
  color: var(--status-pending-text);
  border-color: var(--status-pending-border);
  font-weight: 600;
}

.advance-toggle-container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0.25rem;
  font-size: 0.8rem;
  color: var(--text-secondary);
  border-top: 1px solid var(--border-light);
  margin-top: 0.5rem;
}

/* ----------------- Report & Print Sheet (A4 Landscape) ----------------- */
.report-view-container {
  background: var(--bg-surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  box-shadow: var(--shadow-sm);
}

.report-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.printable-sheet {
  background: #FFFFFF;
  border: 1px solid #E2E8F0;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 26px 22px;
  margin: 0 auto;
  overflow-x: auto;
}

.sheet-header-text {
  text-align: center;
  margin-bottom: 18px;
}

.sheet-header-text h2 {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--text-main);
  letter-spacing: -0.01em;
  margin-bottom: 4px;
}

.sheet-header-text p {
  font-size: 0.82rem;
  color: #64748B;
  margin: 2px 0;
}

.matrix-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.78rem;
  text-align: center;
}

.matrix-table th, 
.matrix-table td {
  border: 1px solid #E2E8F0;
  padding: 5px 6px;
  vertical-align: middle;
}

.matrix-table th {
  background: #F8FAFC;
  font-weight: 600;
  color: #334155;
}

.matrix-table tbody tr:hover {
  background-color: #F8FAFC;
}

.matrix-table th.task-header {
  font-size: 0.72rem;
  min-width: 52px;
  max-width: 80px;
  padding: 6px 4px;
}

.matrix-table td.col-name {
  text-align: left;
  white-space: nowrap;
  padding-left: 10px;
}

.matrix-table .tag-done {
  color: #15803D;
  font-weight: 600;
}

.matrix-table .tag-missing {
  color: #DC2626;
  font-weight: 600;
  font-size: 0.8rem;
}

.matrix-table .cell-score {
  font-weight: 600;
  font-size: 0.88rem;
  color: #1E293B;
}

.matrix-table .cell-missing {
  color: #DC2626;
  font-weight: 600;
  font-size: 0.8rem;
  background: #FEF2F2;
}

.sheet-signature-box {
  margin-top: 2rem;
  display: flex;
  justify-content: flex-end;
  text-align: center;
  font-size: 0.85rem;
}

.signature-line {
  display: inline-block;
  min-width: 220px;
  border-bottom: 1px dotted #64748B;
  margin-bottom: 0.5rem;
}

/* ----------------- Smart Import Modal ----------------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(4px);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal-content {
  background: var(--bg-surface);
  border-radius: var(--radius-lg);
  max-width: 720px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border-light);
  display: flex;
  flex-direction: column;
}

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

.modal-body {
  padding: 1.25rem;
  flex: 1;
}

.modal-footer {
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--border-light);
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  background: var(--bg-subtle);
}

.import-textarea {
  width: 100%;
  height: 180px;
  font-family: monospace;
  font-size: 0.85rem;
  padding: 0.75rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-light);
  resize: vertical;
  line-height: 1.4;
}

.import-preview-box {
  margin-top: 1rem;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  max-height: 200px;
  overflow-y: auto;
}

/* ----------------- Form Controls ----------------- */
.form-group {
  margin-bottom: 1rem;
}

.form-label {
  display: block;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 0.375rem;
}

.form-input {
  width: 100%;
  padding: 0.55rem 0.75rem;
  font-family: inherit;
  font-size: 0.9rem;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  background: var(--bg-surface);
  color: var(--text-main);
}

.form-input:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(43, 76, 126, 0.1);
}

/* Toast */
#toast-container {
  position: fixed;
  bottom: calc(1.5rem + var(--safe-bottom));
  right: 1.5rem;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  pointer-events: none;
}

.toast {
  background: #1E293B;
  color: #FFFFFF;
  padding: 0.65rem 1.1rem;
  border-radius: var(--radius-md);
  font-size: 0.85rem;
  box-shadow: var(--shadow-lg);
  pointer-events: auto;
  animation: slideUp 0.2s ease-out;
}

.toast-with-action {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.toast-action-btn {
  background: #2563EB;
  color: #FFFFFF;
  border: none;
  border-radius: var(--radius-sm);
  padding: 0.25rem 0.65rem;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s ease;
}

.toast-action-btn:hover {
  background: #1D4ED8;
  transform: scale(1.03);
}

/* Grading Mode Switcher */
.mode-toggle-group {
  display: inline-flex;
  background: var(--bg-subtle);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: 3px;
  gap: 3px;
}

.mode-btn {
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 500;
  padding: 0.35rem 0.75rem;
  border-radius: var(--radius-sm);
  border: none;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  transition: all 0.15s ease;
  user-select: none;
}

.mode-btn:hover {
  color: var(--text-main);
}

.mode-btn.active {
  background: #FFFFFF;
  color: var(--primary);
  font-weight: 600;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

/* Risk Students Card */
.risk-student-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 0.85rem;
  border-radius: var(--radius-md);
  background: #F8FAFC;
  border: 1px solid #E2E8F0;
  margin-bottom: 0.5rem;
  transition: background 0.15s ease;
}

.risk-student-item:hover {
  background: #F1F5F9;
}

.risk-badge {
  background: #FEE2E2;
  color: #DC2626;
  font-size: 0.78rem;
  font-weight: 600;
  padding: 0.25rem 0.65rem;
  border-radius: var(--radius-pill);
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}

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

@keyframes pulse {
  0% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.3); opacity: 0.6; }
  100% { transform: scale(1); opacity: 1; }
}

/* Print Styles */
@media print {
  @page {
    size: A4 landscape;
    margin: 8mm;
  }

  body {
    background: #FFFFFF !important;
    color: #000000 !important;
  }

  .app-header,
  .nav-tabs,
  .classroom-pill-strip,
  .report-controls,
  .report-page-tabs,
  .btn,
  #toast-container,
  .keypad-panel,
  .modal-overlay {
    display: none !important;
  }

  .main-content {
    max-width: 100% !important;
    padding: 0 !important;
    margin: 0 !important;
  }

  .card, .report-view-container {
    border: none !important;
    box-shadow: none !important;
    padding: 0 !important;
  }

  .printable-sheet {
    border: none !important;
    padding: 0 !important;
    width: 100% !important;
    page-break-after: always !important;
    break-after: page !important;
  }

  .printable-sheet:last-child {
    page-break-after: auto !important;
    break-after: auto !important;
  }

  .matrix-table {
    font-size: 8pt !important;
    width: 100% !important;
  }

  .matrix-table thead {
    display: table-header-group !important;
  }

  .matrix-table tr {
    page-break-inside: avoid !important;
    break-inside: avoid !important;
  }

  .matrix-table th, 
  .matrix-table td {
    padding: 2px 4px !important;
    border: 0.5pt solid #000000 !important;
  }

  .matrix-table th {
    background-color: #E2E8F0 !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .matrix-table .cell-missing {
    color: #DC2626 !important;
    font-weight: bold !important;
    background: transparent !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
}

/* ==========================================================================
   🎓 ทะเบียนคะแนน & ตัดเกรด (SGS Gradebook Styles)
   ========================================================================== */
.gradebook-container {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.gradebook-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  background: var(--bg-surface);
  padding: 0.875rem 1.25rem;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
}

.ratio-switcher {
  display: inline-flex;
  background: #F1F5F9;
  padding: 3px;
  border-radius: 9999px;
  border: 1px solid var(--border-color);
}

.ratio-btn {
  border: none;
  background: transparent;
  padding: 4px 14px;
  border-radius: 9999px;
  font-size: 0.825rem;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s;
}

.ratio-btn.active {
  background: var(--primary);
  color: #FFFFFF;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
}

.gradebook-stats-bar {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 0.75rem;
}

.gb-stat-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.625rem 0.875rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  box-shadow: var(--shadow-xs);
}

.gb-stat-card .gb-stat-label {
  font-size: 0.75rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.gb-stat-card .gb-stat-val {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-top: 2px;
}

.gb-stat-card.highlight {
  background: #EFF6FF;
  border-color: #BFDBFE;
}

.gb-stat-card.highlight .gb-stat-val {
  color: #1D4ED8;
}

/* Panoramic Gradebook Table */
.gradebook-table-wrapper {
  background: var(--bg-surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
  overflow-x: auto;
  position: relative;
  max-width: 100%;
  -webkit-overflow-scrolling: touch;
}

.gb-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.85rem;
  text-align: center;
}

.gb-table th, 
.gb-table td {
  padding: 6px 8px;
  border-bottom: 1px solid #E2E8F0;
  border-right: 1px solid #E2E8F0;
  white-space: nowrap;
}

.gb-table thead tr:first-child th {
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 8px 6px;
  border-top: none;
}

.gb-table thead tr:last-child th {
  font-size: 0.75rem;
  font-weight: 600;
  background-color: #F8FAFC;
  color: var(--text-secondary);
  padding: 6px 4px;
}

/* Section Header Colors */
.th-sec-student { background-color: #F1F5F9; color: #334155; }
.th-sec-pre     { background-color: #ECFDF5; color: #065F46; border-left: 2px solid #10B981; }
.th-sec-mid     { background-color: #FFFBEB; color: #92400E; border-left: 2px solid #F59E0B; }
.th-sec-post    { background-color: #F0F9FF; color: #075985; border-left: 2px solid #0EA5E9; }
.th-sec-term    { background-color: #EEF2FF; color: #3730A3; border-left: 2px solid #6366F1; font-weight: 800; }
.th-sec-final   { background-color: #FAF5FF; color: #6B21A8; border-left: 2px solid #A855F7; }
.th-sec-total   { background-color: #F0FDF4; color: #166534; border-left: 2px solid #22C55E; font-weight: 800; }
.th-sec-grade   { background-color: #FEF3C7; color: #78350F; border-left: 2px solid #D97706; font-weight: 800; }

/* Sticky Columns */
.gb-sticky-no {
  position: sticky;
  left: 0;
  min-width: 40px;
  background-color: #FFFFFF;
  z-index: 2;
}

.gb-sticky-id {
  position: sticky;
  left: 40px;
  min-width: 70px;
  background-color: #FFFFFF;
  z-index: 2;
}

.gb-sticky-name {
  position: sticky;
  left: 110px;
  min-width: 170px;
  max-width: 220px;
  text-align: left;
  background-color: #FFFFFF;
  z-index: 2;
  box-shadow: 3px 0 6px -2px rgba(0, 0, 0, 0.08);
  overflow: hidden;
  text-overflow: ellipsis;
}

.gb-table thead .gb-sticky-no,
.gb-table thead .gb-sticky-id,
.gb-table thead .gb-sticky-name {
  z-index: 4;
}

/* Row Hover & Alternating */
.gb-table tbody tr:nth-child(even) td {
  background-color: #FBFDFE;
}

.gb-table tbody tr:nth-child(even) .gb-sticky-no,
.gb-table tbody tr:nth-child(even) .gb-sticky-id,
.gb-table tbody tr:nth-child(even) .gb-sticky-name {
  background-color: #F8FAFC;
}

.gb-table tbody tr:hover td {
  background-color: #F1F5F9;
}

.gb-table tbody tr:hover .gb-sticky-no,
.gb-table tbody tr:hover .gb-sticky-id,
.gb-table tbody tr:hover .gb-sticky-name {
  background-color: #E2E8F0;
}

/* Score Inputs */
.gb-score-input {
  width: 48px;
  padding: 3px 2px;
  font-size: 16px; /* iOS zoom prevention */
  text-align: center;
  border: 1px solid #CBD5E1;
  border-radius: 4px;
  background: #FFFFFF;
  transition: all 0.15s;
  font-family: inherit;
}

.gb-score-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.2);
  background: #EFF6FF;
}

.gb-score-input.mini {
  width: 40px;
  font-size: 14px;
}

/* Calculated Summary Cells */
.td-calc {
  font-weight: 600;
  background-color: rgba(241, 245, 249, 0.6);
}

.td-term-total {
  font-weight: 700;
  color: #1E3A8A;
  background-color: #EEF2FF;
}

.td-grand-total {
  font-weight: 800;
  font-size: 0.95rem;
  color: #166534;
  background-color: #DCFCE7;
}

.td-grade-val {
  font-weight: 800;
  font-size: 1rem;
}

.grade-badge-4   { color: #15803D; font-weight: 800; }
.grade-badge-3   { color: #1D4ED8; font-weight: 700; }
.grade-badge-2   { color: #D97706; font-weight: 700; }
.grade-badge-1   { color: #C2410C; font-weight: 700; }
.grade-badge-0   { color: #DC2626; font-weight: 800; }
.grade-badge-res { color: #DC2626; background: #FEE2E2; padding: 2px 6px; border-radius: 4px; font-weight: 700; }

/* Print Gradebook */
@media print {
  @page {
    size: A4 landscape;
    margin: 8mm 6mm;
  }

  body {
    background: #FFFFFF !important;
  }

  .app-header,
  .gradebook-toolbar,
  .nav-tabs,
  .sync-status-indicator,
  .btn,
  #toast-container {
    display: none !important;
  }

  .gradebook-table-wrapper {
    border: none !important;
    box-shadow: none !important;
    overflow: visible !important;
  }

  .gb-table {
    font-size: 9pt !important;
  }

  .gb-table th,
  .gb-table td {
    padding: 3px 2px !important;
    border: 0.5pt solid #000000 !important;
  }

  .gb-score-input {
    border: none !important;
    background: transparent !important;
    width: auto !important;
    font-size: 9pt !important;
  }

  .gb-sticky-no,
  .gb-sticky-id,
  .gb-sticky-name {
    position: static !important;
    box-shadow: none !important;
  }
}

/* Sleek Classroom Navigation Ribbon */
.gb-classroom-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 0.625rem 1rem;
  box-shadow: var(--shadow-xs);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.gb-classroom-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 0.25rem;
  border-bottom: 1px solid #F1F5F9;
}

.gb-classroom-title {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.gb-classroom-count-badge {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--primary);
  background: #EFF6FF;
  padding: 2px 8px;
  border-radius: 9999px;
  border: 1px solid #BFDBFE;
}

.gb-classroom-slider {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  overflow-x: auto;
  padding: 0.25rem 0.15rem 0.4rem 0.15rem;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: #CBD5E1 transparent;
}

.gb-classroom-slider::-webkit-scrollbar {
  height: 4px;
}

.gb-classroom-slider::-webkit-scrollbar-track {
  background: transparent;
}

.gb-classroom-slider::-webkit-scrollbar-thumb {
  background: #CBD5E1;
  border-radius: 9999px;
}

.gb-classroom-slider::-webkit-scrollbar-thumb:hover {
  background: #94A3B8;
}

.gb-room-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.4rem 0.85rem;
  border-radius: 9999px;
  border: 1px solid #E2E8F0;
  background: #FFFFFF;
  color: #334155;
  font-size: 0.825rem;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

.gb-room-pill:hover {
  border-color: #93C5FD;
  background: #F0F9FF;
  color: #1D4ED8;
  transform: translateY(-1px);
}

.gb-room-pill.active {
  background: linear-gradient(135deg, #2563EB 0%, #1D4ED8 100%);
  color: #FFFFFF !important;
  border-color: #1D4ED8;
  box-shadow: 0 2px 6px rgba(37, 99, 235, 0.28);
}

.gb-room-pill .pill-count {
  font-size: 0.725rem;
  font-weight: 500;
  padding: 1px 6px;
  border-radius: 9999px;
  background: #F1F5F9;
  color: #64748B;
  transition: all 0.2s;
}

.gb-room-pill.active .pill-count {
  background: rgba(255, 255, 255, 0.25);
  color: #FFFFFF;
}

/* Quick Nav Helper Banner */
.gb-quick-nav-hint {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  background: #EFF6FF;
  border: 1px solid #BFDBFE;
  border-radius: var(--radius-md);
  padding: 0.5rem 0.85rem;
  font-size: 0.8rem;
  color: #1E40AF;
  flex-wrap: wrap;
}

.gb-note-input {
  width: 110px !important;
  text-align: left !important;
  font-size: 13px !important;
  padding: 4px 6px !important;
}

.gb-note-input:focus {
  width: 140px !important;
}
