﻿/* ===================================================
   Student Attendance System - Modern Responsive CSS
   =================================================== */

:root {
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-light: #eff6ff;
  --secondary: #64748b;
  --bg-main: #f8fafc;
  --bg-card: #ffffff;
  --text-main: #1e293b;
  --text-muted: #64748b;
  --border: #e2e8f0;

  /* Status Colors */
  --status-present: #10b981;
  --status-present-bg: #d1fae5;
  --status-present-text: #065f46;

  --status-absent: #ef4444;
  --status-absent-bg: #fee2e2;
  --status-absent-text: #991b1b;

  --status-leave: #f59e0b;
  --status-leave-bg: #fef3c7;
  --status-leave-text: #92400e;

  --status-late: #f97316;
  --status-late-bg: #ffedd5;
  --status-late-text: #9a3412;

  --status-activity: #8b5cf6;
  --status-activity-bg: #ede9fe;
  --status-activity-text: #5b21b6;

  --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: 12px;
  --radius-sm: 8px;
}

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

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

/* Navbar */
.navbar {
  background: #ffffff;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-sm);
}

.nav-container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--text-main);
}

.brand-icon {
  background: linear-gradient(135deg, var(--primary), #4f46e5);
  color: white;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
}

.brand-title {
  font-size: 1.15rem;
  font-weight: 700;
  color: #0f172a;
}

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

.nav-links {
  display: flex;
  gap: 8px;
}

.nav-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 600;
  text-decoration: none;
  color: var(--text-muted);
  transition: all 0.2s ease;
  border: 1px solid transparent;
}

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

.nav-btn.active {
  background-color: var(--primary);
  color: white;
}

/* Container */
.container {
  max-width: 1100px;
  margin: 20px auto;
  padding: 0 16px;
}

/* Cards */
.card {
  background: var(--bg-card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  padding: 18px;
  margin-bottom: 20px;
}

/* Controls Grid */
.controls-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  align-items: end;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 4px;
}

.form-control {
  width: 100%;
  padding: 10px 14px;
  font-size: 0.95rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background-color: #fff;
  color: var(--text-main);
  transition: border-color 0.2s, box-shadow 0.2s;
}

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

/* Date Stepper */
.date-input-group {
  display: flex;
  align-items: center;
  gap: 4px;
}

.btn-icon {
  background: var(--bg-main);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  font-size: 0.9rem;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-icon:hover {
  background: #e2e8f0;
}

/* Mode Banner */
.status-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  margin-top: 14px;
  font-size: 0.9rem;
  font-weight: 500;
  flex-wrap: wrap;
  gap: 10px;
}

.status-banner.saved {
  background-color: #ecfdf5;
  border: 1px solid #a7f3d0;
  color: #065f46;
}

.status-banner.unsaved {
  background-color: #fffbeb;
  border: 1px solid #fde68a;
  color: #92400e;
}

.quick-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.btn-pill {
  font-size: 0.8rem;
  font-weight: 600;
  padding: 5px 12px;
  border-radius: 9999px;
  border: 1px solid var(--border);
  background: #fff;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-pill:hover {
  background: var(--primary-light);
  color: var(--primary);
  border-color: var(--primary);
}

/* Live Summary Counter Bar */
.summary-bar {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.summary-card {
  background: #ffffff;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: var(--shadow-sm);
}

.summary-icon {
  width: 42px;
  height: 42px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
}

.summary-info .count {
  font-size: 1.35rem;
  font-weight: 700;
  line-height: 1.1;
}

.summary-info .label {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.stat-present .summary-icon { background: var(--status-present-bg); color: var(--status-present-text); }
.stat-present .count { color: var(--status-present-text); }

.stat-absent .summary-icon { background: var(--status-absent-bg); color: var(--status-absent-text); }
.stat-absent .count { color: var(--status-absent-text); }

.stat-leave .summary-icon { background: var(--status-leave-bg); color: var(--status-leave-text); }
.stat-leave .count { color: var(--status-leave-text); }

.stat-late .summary-icon { background: var(--status-late-bg); color: var(--status-late-text); }
.stat-late .count { color: var(--status-late-text); }

.stat-activity .summary-icon { background: var(--status-activity-bg); color: var(--status-activity-text); }
.stat-activity .count { color: var(--status-activity-text); }

.stat-total .summary-icon { background: #f1f5f9; color: #475569; }
.stat-total .count { color: #334155; }

/* Student Card List */
.student-list-container {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.student-card {
  background: #ffffff;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  box-shadow: var(--shadow-sm);
  transition: all 0.2s ease;
}

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

.student-meta {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 200px;
}

.seat-badge {
  width: 36px;
  height: 36px;
  background: #f1f5f9;
  color: #334155;
  font-weight: 700;
  font-size: 0.95rem;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

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

.student-name {
  font-size: 1rem;
  font-weight: 600;
  color: #0f172a;
}

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

/* Status Selector Buttons */
.status-buttons-group {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.status-btn {
  padding: 7px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 600;
  border: 1px solid var(--border);
  background: #f8fafc;
  color: #475569;
  cursor: pointer;
  transition: all 0.15s ease;
  user-select: none;
}

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

/* Status Selected Styles */
.status-btn[data-status="มา"].active {
  background: var(--status-present);
  border-color: var(--status-present);
  color: #ffffff;
  box-shadow: 0 2px 8px rgba(16, 185, 129, 0.35);
}

.status-btn[data-status="ขาด"].active {
  background: var(--status-absent);
  border-color: var(--status-absent);
  color: #ffffff;
  box-shadow: 0 2px 8px rgba(239, 68, 68, 0.35);
}

.status-btn[data-status="ลา"].active {
  background: var(--status-leave);
  border-color: var(--status-leave);
  color: #ffffff;
  box-shadow: 0 2px 8px rgba(245, 158, 11, 0.35);
}

.status-btn[data-status="มาสาย"].active {
  background: var(--status-late);
  border-color: var(--status-late);
  color: #ffffff;
  box-shadow: 0 2px 8px rgba(249, 115, 22, 0.35);
}

.status-btn[data-status="กิจกรรม"].active {
  background: var(--status-activity);
  border-color: var(--status-activity);
  color: #ffffff;
  box-shadow: 0 2px 8px rgba(139, 92, 246, 0.35);
}

/* Student Remark input */
.student-remark-wrap {
  width: 180px;
  flex-shrink: 0;
}

.remark-input {
  width: 100%;
  font-size: 0.8rem;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #fafafa;
}

.remark-input:focus {
  background: #fff;
  border-color: var(--primary);
  outline: none;
}

/* Sticky Bottom Save Bar */
.bottom-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: #ffffff;
  border-top: 1px solid var(--border);
  padding: 12px 20px;
  box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.08);
  z-index: 99;
}

.bottom-container {
  max-width: 1100px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}

.bottom-summary-text {
  font-size: 0.9rem;
  color: var(--text-main);
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.bottom-summary-text span {
  font-weight: 600;
}

.btn-save {
  background: linear-gradient(135deg, var(--primary), #1d4ed8);
  color: white;
  border: none;
  padding: 12px 28px;
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
  display: flex;
  align-items: center;
  gap: 8px;
  transition: all 0.2s ease;
}

.btn-save:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(37, 99, 235, 0.4);
}

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

/* History Page Styles */
.badge-status {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 9999px;
  font-size: 0.8rem;
  font-weight: 600;
}

.badge-status.มา { background: var(--status-present-bg); color: var(--status-present-text); }
.badge-status.ขาด { background: var(--status-absent-bg); color: var(--status-absent-text); }
.badge-status.ลา { background: var(--status-leave-bg); color: var(--status-leave-text); }
.badge-status.มาสาย { background: var(--status-late-bg); color: var(--status-late-text); }
.badge-status.กิจกรรม { background: var(--status-activity-bg); color: var(--status-activity-text); }

.data-table-container {
  overflow-x: auto;
  background: white;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

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

.data-table th {
  background: #f8fafc;
  padding: 12px 14px;
  font-weight: 600;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.data-table td {
  padding: 12px 14px;
  border-bottom: 1px solid #f1f5f9;
  vertical-align: middle;
}

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

.btn-action {
  padding: 6px 12px;
  font-size: 0.85rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: #fff;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.15s ease;
  text-decoration: none;
  color: var(--text-main);
}

.btn-action:hover {
  background: var(--primary-light);
  color: var(--primary);
  border-color: var(--primary);
}

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

.toast {
  background: #1e293b;
  color: white;
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  font-size: 0.9rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 10px;
  animation: slideIn 0.3s ease;
}

.toast.success { background: #065f46; border-left: 4px solid #34d399; }
.toast.error { background: #7f1d1d; border-left: 4px solid #f87171; }
.toast.info { background: #1e3a8a; border-left: 4px solid #60a5fa; }

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

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

.empty-state-icon {
  font-size: 3rem;
  margin-bottom: 12px;
}

/* Mobile Responsive */
@media (max-width: 768px) {
  .student-card {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }

  .student-meta {
    width: 100%;
  }

  .status-buttons-group {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 4px;
  }

  .status-btn {
    padding: 10px 4px;
    font-size: 0.8rem;
    text-align: center;
  }

  .student-remark-wrap {
    width: 100%;
  }

  .bottom-container {
    flex-direction: column;
    align-items: stretch;
  }

  .btn-save {
    width: 100%;
    justify-content: center;
  }

  .summary-bar {
    grid-template-columns: repeat(3, 1fr);
  }
}
