:root {
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-light: #eff6ff;
  --bg-main: #f8fafc;
  --bg-card: #ffffff;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 16px;
  --radius-full: 9999px;

  /* Status Colors */
  --status-present: #16a34a;       /* มา - เขียว */
  --status-present-bg: #dcfce7;
  --status-present-border: #86efac;

  --status-absent: #dc2626;        /* ขาด - แดง */
  --status-absent-bg: #fee2e2;
  --status-absent-border: #fca5a5;

  --status-leave: #d97706;         /* ลา - ส้ม/เหลือง */
  --status-leave-bg: #fef3c7;
  --status-leave-border: #fcd34d;

  --status-late: #7c3aed;          /* มาสาย - ม่วง */
  --status-late-bg: #f3e8ff;
  --status-late-border: #d8b4fe;

  --status-activity: #0284c7;      /* กิจกรรม - ฟ้า */
  --status-activity-bg: #e0f2fe;
  --status-activity-border: #7dd3fc;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: 'Sarabun', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

body {
  background-color: var(--bg-main);
  color: var(--text-main);
  line-height: 1.5;
  min-height: 100vh;
  padding-bottom: 90px;
}

/* Header & Navigation */
.header {
  background: linear-gradient(135deg, #1e3a8a 0%, #2563eb 100%);
  color: #ffffff;
  padding: 1rem 1.25rem;
  box-shadow: var(--shadow-md);
  position: sticky;
  top: 0;
  z-index: 40;
}

.header-container {
  max-width: 1100px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

@media (min-width: 768px) {
  .header-container {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
  }
}

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

.brand-icon {
  width: 42px;
  height: 42px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  flex-shrink: 0;
  backdrop-filter: blur(4px);
}

.brand-text h1 {
  font-size: 1.2rem;
  font-weight: 700;
  line-height: 1.2;
}

.brand-text p {
  font-size: 0.8rem;
  opacity: 0.85;
}

.nav-tabs {
  display: flex;
  background: rgba(0, 0, 0, 0.2);
  padding: 4px;
  border-radius: var(--radius);
  gap: 4px;
  overflow-x: auto;
}

.nav-tab {
  flex: 1;
  border: none;
  background: transparent;
  color: rgba(255, 255, 255, 0.85);
  padding: 0.5rem 0.85rem;
  font-size: 0.875rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
}

.nav-tab:hover {
  color: #ffffff;
  background: rgba(255, 255, 255, 0.1);
}

.nav-tab.active {
  background: #ffffff;
  color: #1e3a8a;
  box-shadow: var(--shadow-sm);
}

/* Main Container */
.container {
  max-width: 1100px;
  margin: 1.25rem auto;
  padding: 0 1rem;
}

/* Controls Card */
.card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  padding: 1.25rem;
  margin-bottom: 1.25rem;
}

.controls-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
}

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

@media (min-width: 1024px) {
  .controls-grid {
    grid-template-columns: 1fr 1.5fr auto;
    align-items: end;
  }
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.form-label {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.form-select,
.form-input {
  width: 100%;
  padding: 0.65rem 0.85rem;
  font-size: 0.95rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  background-color: #ffffff;
  color: var(--text-main);
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

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

.date-selector-group {
  display: flex;
  gap: 0.35rem;
}

.date-nav-btn {
  background: var(--bg-main);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 0 0.75rem;
  font-size: 0.9rem;
  cursor: pointer;
  color: var(--text-main);
  font-weight: 600;
  transition: background-color 0.15s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
}

.date-nav-btn:hover {
  background: #e2e8f0;
}

/* Status Banner */
.status-banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  margin-top: 1rem;
  font-size: 0.875rem;
  font-weight: 500;
}

.status-banner.recorded {
  background-color: var(--status-present-bg);
  border: 1px solid var(--status-present-border);
  color: #14532d;
}

.status-banner.unrecorded {
  background-color: #f1f5f9;
  border: 1px solid #cbd5e1;
  color: #475569;
}

.status-indicator-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 6px;
}

.status-banner.recorded .status-indicator-dot {
  background-color: var(--status-present);
  box-shadow: 0 0 0 3px rgba(22, 163, 74, 0.2);
}

.status-banner.unrecorded .status-indicator-dot {
  background-color: #94a3b8;
}

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

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

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

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-sm);
  position: relative;
  overflow: hidden;
  transition: transform 0.15s ease;
}

.stat-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
}

.stat-card.total::before { background: #3b82f6; }
.stat-card.present::before { background: var(--status-present); }
.stat-card.absent::before { background: var(--status-absent); }
.stat-card.leave::before { background: var(--status-leave); }
.stat-card.late::before { background: var(--status-late); }
.stat-card.activity::before { background: var(--status-activity); }

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

.stat-value {
  font-size: 1.5rem;
  font-weight: 700;
  line-height: 1.2;
  margin-top: 0.2rem;
}

.stat-card.total .stat-value { color: #1d4ed8; }
.stat-card.present .stat-value { color: var(--status-present); }
.stat-card.absent .stat-value { color: var(--status-absent); }
.stat-card.leave .stat-value { color: var(--status-leave); }
.stat-card.late .stat-value { color: var(--status-late); }
.stat-card.activity .stat-value { color: var(--status-activity); }

/* Quick Actions Toolbar */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.toolbar-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.6rem 1rem;
  font-size: 0.875rem;
  font-weight: 600;
  border-radius: var(--radius);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}

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

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

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

.btn-success {
  background: #16a34a;
  color: #ffffff;
}

.btn-success:hover {
  background: #15803d;
}

.btn-outline {
  background: #ffffff;
  border-color: var(--border);
  color: var(--text-main);
}

.btn-outline:hover {
  background: #f1f5f9;
}

.btn-sm {
  padding: 0.4rem 0.65rem;
  font-size: 0.8rem;
}

/* Student Cards / List */
.student-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.student-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  padding: 0.9rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

@media (min-width: 768px) {
  .student-card {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1.25rem;
  }
}

.student-card:hover {
  border-color: #cbd5e1;
  box-shadow: var(--shadow-md);
}

.student-card.status-present-active { border-left: 4px solid var(--status-present); }
.student-card.status-absent-active { border-left: 4px solid var(--status-absent); }
.student-card.status-leave-active { border-left: 4px solid var(--status-leave); }
.student-card.status-late-active { border-left: 4px solid var(--status-late); }
.student-card.status-activity-active { border-left: 4px solid var(--status-activity); }

.student-info {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 250px;
}

.student-no-badge {
  width: 34px;
  height: 34px;
  background: #f1f5f9;
  color: #334155;
  font-weight: 700;
  font-size: 0.9rem;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.student-details {
  display: flex;
  flex-direction: column;
}

.student-name {
  font-weight: 600;
  font-size: 1rem;
  color: var(--text-main);
  line-height: 1.3;
}

.student-meta {
  font-size: 0.8rem;
  color: var(--text-muted);
  display: flex;
  gap: 0.5rem;
}

/* Status Selector Buttons Group */
.status-buttons-group {
  display: flex;
  gap: 4px;
  background: #f8fafc;
  padding: 4px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  overflow-x: auto;
}

.status-btn {
  flex: 1;
  min-width: 52px;
  padding: 0.45rem 0.5rem;
  border: 1.5px solid transparent;
  background: transparent;
  color: #64748b;
  font-weight: 600;
  font-size: 0.85rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-align: center;
  transition: all 0.15s ease;
  user-select: none;
}

.status-btn:hover {
  background: #f1f5f9;
}

/* Active Status Buttons */
.status-btn.active.present {
  background: var(--status-present-bg);
  border-color: var(--status-present-border);
  color: #15803d;
  font-weight: 700;
}

.status-btn.active.absent {
  background: var(--status-absent-bg);
  border-color: var(--status-absent-border);
  color: #b91c1c;
  font-weight: 700;
}

.status-btn.active.leave {
  background: var(--status-leave-bg);
  border-color: var(--status-leave-border);
  color: #b45309;
  font-weight: 700;
}

.status-btn.active.late {
  background: var(--status-late-bg);
  border-color: var(--status-late-border);
  color: #6d28d9;
  font-weight: 700;
}

.status-btn.active.activity {
  background: var(--status-activity-bg);
  border-color: var(--status-activity-border);
  color: #0369a1;
  font-weight: 700;
}

/* Student Note */
.student-note-wrapper {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

@media (min-width: 768px) {
  .student-note-wrapper {
    max-width: 200px;
  }
}

.student-note-input {
  width: 100%;
  padding: 0.4rem 0.6rem;
  font-size: 0.825rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #ffffff;
  outline: none;
}

.student-note-input:focus {
  border-color: var(--primary);
}

/* Floating Save Bar */
.floating-save-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: #ffffff;
  border-top: 1px solid var(--border);
  padding: 0.85rem 1.25rem;
  box-shadow: 0 -4px 10px rgba(0, 0, 0, 0.06);
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.floating-save-content {
  max-width: 1100px;
  margin: 0 auto;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.save-summary-text {
  font-size: 0.875rem;
  color: var(--text-muted);
}

.save-summary-text strong {
  color: var(--text-main);
  font-size: 1rem;
}

.btn-save-large {
  padding: 0.75rem 1.75rem;
  font-size: 1rem;
  border-radius: var(--radius);
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
  color: #ffffff;
  border: none;
  font-weight: 700;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  transition: all 0.15s ease;
}

.btn-save-large:hover {
  background: linear-gradient(135deg, #1d4ed8, #1e40af);
  box-shadow: 0 6px 16px rgba(37, 99, 235, 0.4);
}

.btn-save-large:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* History & Report View Table */
.history-filters {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.75rem;
}

@media (min-width: 640px) {
  .history-filters {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (min-width: 1024px) {
  .history-filters {
    grid-template-columns: 1.2fr 1.2fr 1fr 1fr 1.5fr auto;
    align-items: end;
  }
}

.table-responsive {
  width: 100%;
  overflow-x: auto;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: #ffffff;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 0.875rem;
}

.data-table th {
  background: #f8fafc;
  padding: 0.75rem 1rem;
  font-weight: 600;
  color: #475569;
  border-bottom: 1.5px solid var(--border);
  white-space: nowrap;
}

.data-table td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  color: var(--text-main);
  vertical-align: middle;
}

.data-table tr:hover {
  background: #f8fafc;
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.25rem 0.65rem;
  border-radius: var(--radius-full);
  font-size: 0.8rem;
  font-weight: 600;
  white-space: nowrap;
}

.badge-present { background: var(--status-present-bg); color: #15803d; border: 1px solid var(--status-present-border); }
.badge-absent { background: var(--status-absent-bg); color: #b91c1c; border: 1px solid var(--status-absent-border); }
.badge-leave { background: var(--status-leave-bg); color: #b45309; border: 1px solid var(--status-leave-border); }
.badge-late { background: var(--status-late-bg); color: #6d28d9; border: 1px solid var(--status-late-border); }
.badge-activity { background: var(--status-activity-bg); color: #0369a1; border: 1px solid var(--status-activity-border); }

/* Toast Notifications */
.toast-container {
  position: fixed;
  top: 1.25rem;
  right: 1.25rem;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  pointer-events: none;
}

.toast {
  background: #1e293b;
  color: #ffffff;
  padding: 0.85rem 1.25rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  pointer-events: auto;
  animation: slideIn 0.25s ease forwards;
  max-width: 360px;
}

.toast.success { background: #166534; }
.toast.error { background: #991b1b; }
.toast.info { background: #1e40af; }

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

/* Empty State & Loading State */
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-muted);
}

.empty-icon {
  font-size: 3rem;
  margin-bottom: 0.75rem;
}

.loading-spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 3px solid rgba(255, 255, 255, 0.3);
  border-radius: 50%;
  border-top-color: #ffffff;
  animation: spin 0.8s linear infinite;
}

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

/* Print Styles */
@media print {
  .header, .floating-save-bar, .toolbar, .history-filters, .nav-tabs {
    display: none !important;
  }
  body {
    background: #ffffff !important;
    padding-bottom: 0 !important;
  }
  .card {
    box-shadow: none !important;
    border: none !important;
    padding: 0 !important;
  }
}
