/* ===== CSS RESET & VARIABLES ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary: #1a73e8;
  --primary-dark: #1557b0;
  --primary-light: #e8f0fe;
  --success: #34a853;
  --success-bg: #e6f4ea;
  --danger: #ea4335;
  --danger-bg: #fce8e6;
  --warning: #fbbc04;
  --warning-bg: #fef9e3;
  --orange: #fa7b17;
  --orange-bg: #fef0e7;
  --info: #4285f4;
  --info-bg: #e8f0fe;
  --gray: #5f6368;
  --gray-light: #f1f3f4;
  --gray-border: #dadce0;
  --white: #ffffff;
  --bg: #f8f9fa;
  --text: #202124;
  --text-secondary: #5f6368;
  --shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.1);
  --shadow-lg: 0 4px 6px rgba(0,0,0,0.1), 0 2px 4px rgba(0,0,0,0.08);
  --radius: 8px;
  --radius-lg: 12px;
  --transition: all 0.2s ease;
}

/* ===== BASE ===== */
html { font-size: 16px; scroll-behavior: smooth; }
body {
  font-family: 'Sarabun', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
}
@import url('https://fonts.googleapis.com/css2?family=Sarabun:wght@300;400;500;600;700&display=swap');

/* ===== HEADER / NAV ===== */
.header {
  background: var(--primary);
  color: white;
  padding: 0;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-lg);
}
.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  height: 60px;
}
.header-logo {
  font-size: 1.4rem;
  font-weight: 700;
  text-decoration: none;
  color: white;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.header-logo span { font-size: 1.6rem; }
.header-title {
  flex: 1;
  font-size: 1rem;
  font-weight: 500;
  opacity: 0.9;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.header-nav {
  display: flex;
  gap: 4px;
}
.nav-link {
  color: rgba(255,255,255,0.85);
  text-decoration: none;
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 0.9rem;
  font-weight: 500;
  transition: var(--transition);
}
.nav-link:hover, .nav-link.active {
  background: rgba(255,255,255,0.2);
  color: white;
}

/* ===== MAIN CONTENT ===== */
.main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px 16px;
}

/* ===== CARDS ===== */
.card {
  background: var(--white);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 16px;
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  gap: 12px;
}
.card-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ===== FORM CONTROLS ===== */
.controls {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: flex-end;
}
.form-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
  min-width: 140px;
}
.form-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.form-control {
  padding: 10px 12px;
  border: 1.5px solid var(--gray-border);
  border-radius: var(--radius);
  font-size: 0.95rem;
  color: var(--text);
  background: var(--white);
  transition: var(--transition);
  font-family: inherit;
  width: 100%;
}
.form-control:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(26,115,232,0.15);
}

/* ===== BUTTONS ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  font-family: inherit;
  white-space: nowrap;
  text-decoration: none;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); box-shadow: var(--shadow); }
.btn-success { background: var(--success); color: white; }
.btn-success:hover:not(:disabled) { background: #2d9248; box-shadow: var(--shadow); }
.btn-outline { background: transparent; color: var(--primary); border: 1.5px solid var(--primary); }
.btn-outline:hover:not(:disabled) { background: var(--primary-light); }
.btn-gray { background: var(--gray-light); color: var(--text); }
.btn-gray:hover:not(:disabled) { background: var(--gray-border); }
.btn-sm { padding: 6px 12px; font-size: 0.85rem; }
.btn-lg { padding: 12px 28px; font-size: 1rem; }
.btn-block { width: 100%; }
.btn-icon { padding: 8px; border-radius: 50%; }

/* ===== SUMMARY STATS ===== */
.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}
.stat-card {
  background: var(--gray-light);
  border-radius: var(--radius);
  padding: 12px 8px;
  text-align: center;
  transition: var(--transition);
}
.stat-card.present { background: var(--success-bg); }
.stat-card.absent { background: var(--danger-bg); }
.stat-card.leave { background: var(--warning-bg); }
.stat-card.late { background: var(--orange-bg); }
.stat-card.activity { background: var(--info-bg); }
.stat-card.unchecked { background: var(--gray-light); }
.stat-number {
  font-size: 1.8rem;
  font-weight: 700;
  line-height: 1;
  margin-bottom: 4px;
}
.stat-card.present .stat-number { color: var(--success); }
.stat-card.absent .stat-number { color: var(--danger); }
.stat-card.leave .stat-number { color: #b08000; }
.stat-card.late .stat-number { color: var(--orange); }
.stat-card.activity .stat-number { color: var(--info); }
.stat-card.unchecked .stat-number { color: var(--gray); }
.stat-label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-secondary);
}

/* ===== ATTENDANCE TABLE ===== */
.table-wrapper {
  overflow-x: auto;
  margin: 0 -20px;
  padding: 0 20px;
}
.attendance-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.9rem;
}
.attendance-table th {
  background: var(--gray-light);
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 10px 8px;
  text-align: left;
  border-bottom: 2px solid var(--gray-border);
  white-space: nowrap;
  position: sticky;
  top: 0;
}
.attendance-table td {
  padding: 8px 8px;
  border-bottom: 1px solid var(--gray-border);
  vertical-align: middle;
}
.attendance-table tr:last-child td { border-bottom: none; }
.attendance-table tr:hover td { background: var(--primary-light); }
.attendance-table .col-num { width: 48px; text-align: center; color: var(--text-secondary); font-size: 0.85rem; }
.attendance-table .col-id { width: 80px; color: var(--text-secondary); font-size: 0.82rem; }
.attendance-table .col-name { min-width: 160px; font-weight: 500; }
.attendance-table .col-status { min-width: 280px; }
.attendance-table .col-note { min-width: 120px; }
.student-name-prefix { font-size: 0.8rem; color: var(--text-secondary); }

/* ===== STATUS BUTTONS ===== */
.status-buttons {
  display: flex;
  gap: 4px;
  flex-wrap: nowrap;
}
.status-btn {
  padding: 5px 10px;
  border: 1.5px solid transparent;
  border-radius: 20px;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
  font-family: inherit;
  background: var(--gray-light);
  color: var(--text-secondary);
}
.status-btn:hover { transform: translateY(-1px); box-shadow: var(--shadow); }
.status-btn.active-present { background: var(--success); color: white; border-color: var(--success); }
.status-btn.active-absent { background: var(--danger); color: white; border-color: var(--danger); }
.status-btn.active-leave { background: var(--warning); color: #5a4000; border-color: var(--warning); }
.status-btn.active-late { background: var(--orange); color: white; border-color: var(--orange); }
.status-btn.active-activity { background: var(--info); color: white; border-color: var(--info); }
.status-btn[data-status="present"]:hover { background: var(--success-bg); border-color: var(--success); color: var(--success); }
.status-btn[data-status="absent"]:hover { background: var(--danger-bg); border-color: var(--danger); color: var(--danger); }
.status-btn[data-status="leave"]:hover { background: var(--warning-bg); border-color: var(--warning); color: #5a4000; }
.status-btn[data-status="late"]:hover { background: var(--orange-bg); border-color: var(--orange); color: var(--orange); }
.status-btn[data-status="activity"]:hover { background: var(--info-bg); border-color: var(--info); color: var(--info); }
.note-input {
  border: 1px solid var(--gray-border);
  border-radius: var(--radius);
  padding: 4px 8px;
  font-size: 0.82rem;
  width: 100%;
  max-width: 150px;
  font-family: inherit;
  color: var(--text);
}
.note-input:focus { outline: none; border-color: var(--primary); }

/* ===== STATUS BADGE ===== */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 0.78rem;
  font-weight: 600;
  white-space: nowrap;
}
.badge-present { background: var(--success-bg); color: var(--success); }
.badge-absent { background: var(--danger-bg); color: var(--danger); }
.badge-leave { background: var(--warning-bg); color: #7a5800; }
.badge-late { background: var(--orange-bg); color: var(--orange); }
.badge-activity { background: var(--info-bg); color: var(--info); }
.badge-unknown { background: var(--gray-light); color: var(--gray); }

/* ===== ALERTS / TOAST ===== */
.toast-container {
  position: fixed;
  top: 70px;
  right: 16px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 360px;
  width: calc(100% - 32px);
}
.toast {
  background: white;
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  display: flex;
  align-items: flex-start;
  gap: 10px;
  border-left: 4px solid var(--primary);
  animation: slideIn 0.3s ease;
}
.toast.success { border-color: var(--success); }
.toast.error { border-color: var(--danger); }
.toast.warning { border-color: var(--warning); }
.toast-icon { font-size: 1.2rem; flex-shrink: 0; line-height: 1.4; }
.toast-msg { font-size: 0.9rem; flex: 1; line-height: 1.4; }
.toast-close { background: none; border: none; cursor: pointer; font-size: 1rem; color: var(--gray); padding: 0; flex-shrink: 0; }
@keyframes slideIn { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: translateX(0); } }

/* ===== LOADING ===== */
.loading-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9998;
  backdrop-filter: blur(2px);
}
.loading-spinner {
  background: white;
  border-radius: var(--radius-lg);
  padding: 28px 36px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  box-shadow: var(--shadow-lg);
}
.spinner {
  width: 36px; height: 36px;
  border: 4px solid var(--gray-border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-text { font-size: 0.9rem; color: var(--text-secondary); font-weight: 500; }
.hidden { display: none !important; }

/* ===== EMPTY STATE ===== */
.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--text-secondary);
}
.empty-icon { font-size: 3rem; margin-bottom: 12px; opacity: 0.5; }
.empty-text { font-size: 0.95rem; }

/* ===== NOTICE BOX ===== */
.notice {
  background: var(--primary-light);
  border: 1px solid #bfcfed;
  border-radius: var(--radius);
  padding: 10px 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.88rem;
  color: var(--primary-dark);
  margin-bottom: 12px;
}
.notice.warning { background: var(--warning-bg); border-color: #f8d45a; color: #7a5800; }
.notice.success { background: var(--success-bg); border-color: #a8d5b3; color: #1e6b35; }

/* ===== QUICK SELECT ===== */
.quick-select {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.quick-btn {
  padding: 6px 14px;
  border-radius: 20px;
  border: 1.5px solid var(--gray-border);
  background: white;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  font-family: inherit;
  color: var(--text-secondary);
}
.quick-btn:hover { border-color: var(--primary); color: var(--primary); }
.quick-btn.present { color: var(--success); border-color: var(--success); }
.quick-btn.present:hover { background: var(--success); color: white; }
.quick-btn.absent { color: var(--danger); border-color: var(--danger); }
.quick-btn.absent:hover { background: var(--danger); color: white; }

/* ===== PAGINATION ===== */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 20px;
  flex-wrap: wrap;
}
.page-btn {
  min-width: 36px;
  height: 36px;
  border: 1.5px solid var(--gray-border);
  background: white;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.88rem;
  font-weight: 600;
  transition: var(--transition);
  font-family: inherit;
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
}
.page-btn:hover:not(:disabled) { border-color: var(--primary); color: var(--primary); }
.page-btn.active { background: var(--primary); color: white; border-color: var(--primary); }
.page-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.page-info { font-size: 0.85rem; color: var(--text-secondary); }

/* ===== HISTORY TABLE ===== */
.history-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.88rem;
}
.history-table th {
  background: var(--gray-light);
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 10px 12px;
  text-align: left;
  border-bottom: 2px solid var(--gray-border);
  white-space: nowrap;
}
.history-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--gray-border);
  vertical-align: middle;
}
.history-table tr:hover td { background: var(--primary-light); }

/* ===== SUMMARY ROW ===== */
.summary-section { margin-top: 12px; }
.summary-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.85rem;
}
.summary-table th {
  background: var(--gray-light);
  padding: 8px 12px;
  text-align: center;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-secondary);
  border-bottom: 2px solid var(--gray-border);
  text-transform: uppercase;
}
.summary-table td {
  padding: 8px 12px;
  text-align: center;
  border-bottom: 1px solid var(--gray-border);
  font-weight: 500;
}
.summary-table td:first-child, .summary-table td:nth-child(2) { text-align: left; }

/* ===== FLOATING SAVE BUTTON ===== */
.fab-save {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: auto;
  height: auto;
  padding: 14px 24px;
  border-radius: 28px;
  font-size: 1rem;
  font-weight: 700;
  box-shadow: 0 4px 14px rgba(52,168,83,0.4);
  z-index: 200;
  border: none;
  background: var(--success);
  color: white;
  cursor: pointer;
  transition: var(--transition);
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: inherit;
}
.fab-save:hover { background: #2d9248; box-shadow: 0 6px 20px rgba(52,168,83,0.5); transform: translateY(-2px); }
.fab-save:active { transform: translateY(0); }

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
  .header-title { display: none; }
  .main { padding: 12px; }
  .card { padding: 14px; margin-bottom: 12px; }
  .controls { gap: 8px; }
  .form-group { min-width: 120px; }
  .summary-grid { grid-template-columns: repeat(3, 1fr); gap: 6px; }
  .stat-number { font-size: 1.4rem; }
  .stat-label { font-size: 0.7rem; }
  .attendance-table .col-id { display: none; }
  .status-btn { padding: 5px 7px; font-size: 0.72rem; }
  .note-input { display: none; }
  .fab-save { bottom: 16px; right: 16px; padding: 12px 20px; font-size: 0.9rem; }
}
@media (max-width: 480px) {
  .summary-grid { grid-template-columns: repeat(3, 1fr); }
  .quick-select { gap: 6px; }
  .status-btn { padding: 4px 6px; font-size: 0.68rem; }
  .status-buttons { gap: 3px; }
}
/* ===== PRINT ===== */
@media print {
  .header, .fab-save, .controls, .quick-select, .btn, .toast-container { display: none !important; }
  .card { box-shadow: none; border: 1px solid #ddd; }
  body { background: white; }
}
