/* Modern Responsive CSS for Student Attendance System */
:root {
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-light: #eff6ff;
  --primary-border: #bfdbfe;

  --color-present: #059669;
  --bg-present: #ecfdf5;
  --border-present: #a7f3d0;
  --color-present-active: #047857;

  --color-absent: #dc2626;
  --bg-absent: #fef2f2;
  --border-absent: #fecaca;
  --color-absent-active: #b91c1c;

  --color-leave: #d97706;
  --bg-leave: #fffbeb;
  --border-leave: #fde68a;
  --color-leave-active: #b45309;

  --color-late: #0284c7;
  --bg-late: #f0f9ff;
  --border-late: #bae6fd;
  --color-late-active: #0369a1;

  --color-activity: #7c3aed;
  --bg-activity: #f5f3ff;
  --border-activity: #ddd6fe;
  --color-activity-active: #6d28d9;

  --gray-50: #f8fafc;
  --gray-100: #f1f5f9;
  --gray-200: #e2e8f0;
  --gray-300: #cbd5e1;
  --gray-400: #94a3b8;
  --gray-500: #64748b;
  --gray-600: #475569;
  --gray-700: #334155;
  --gray-800: #1e293b;
  --gray-900: #0f172a;

  --font-sans: 'Prompt', 'Kanit', 'Sarabun', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 16px;
  --radius-full: 9999px;
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.08), 0 2px 4px -2px rgb(0 0 0 / 0.05);
  --shadow-md: 0 10px 15px -3px rgb(0 0 0 / 0.08), 0 4px 6px -4px rgb(0 0 0 / 0.05);
  --shadow-lg: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.08);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-sans);
  background-color: var(--gray-50);
  color: var(--gray-800);
  line-height: 1.5;
  font-size: 15px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Header & Navbar */
.navbar {
  background: white;
  border-bottom: 1px solid var(--gray-200);
  position: sticky;
  top: 0;
  z-index: 40;
  box-shadow: var(--shadow-sm);
}

.navbar-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0.75rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  text-decoration: none;
  color: var(--gray-900);
  font-weight: 700;
  font-size: 1.15rem;
}

.brand-icon {
  width: 36px;
  height: 36px;
  background: linear-gradient(135deg, #2563eb, #4f46e5);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius);
  font-size: 1.15rem;
  box-shadow: 0 2px 4px rgba(37, 99, 235, 0.3);
}

.nav-links {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.nav-link {
  text-decoration: none;
  color: var(--gray-600);
  padding: 0.5rem 0.85rem;
  border-radius: var(--radius-sm);
  font-weight: 500;
  font-size: 0.92rem;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.nav-link:hover {
  background: var(--gray-100);
  color: var(--gray-900);
}

.nav-link.active {
  background: var(--primary-light);
  color: var(--primary);
  font-weight: 600;
}

/* Main Container */
.container {
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
  padding: 1.25rem 1rem 5rem;
  flex: 1;
}

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

.card-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--gray-900);
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

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

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

.form-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--gray-700);
}

.form-control {
  font-family: var(--font-sans);
  padding: 0.6rem 0.85rem;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius);
  font-size: 0.95rem;
  background: white;
  color: var(--gray-800);
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
  width: 100%;
}

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

/* Status Alert Banner */
.banner {
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  font-size: 0.9rem;
}

.banner-info {
  background: #f0fdf4;
  color: #166534;
  border: 1px solid #bbf7d0;
}

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

/* Summary Counters Grid */
.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}

.summary-card {
  background: white;
  border-radius: var(--radius);
  border: 1px solid var(--gray-200);
  padding: 0.85rem;
  text-align: center;
  transition: transform 0.15s ease;
}

.summary-card:hover {
  transform: translateY(-2px);
}

.summary-card.present {
  border-color: var(--border-present);
  background: linear-gradient(to bottom, #ffffff, var(--bg-present));
}
.summary-card.absent {
  border-color: var(--border-absent);
  background: linear-gradient(to bottom, #ffffff, var(--bg-absent));
}
.summary-card.leave {
  border-color: var(--border-leave);
  background: linear-gradient(to bottom, #ffffff, var(--bg-leave));
}
.summary-card.late {
  border-color: var(--border-late);
  background: linear-gradient(to bottom, #ffffff, var(--bg-late));
}
.summary-card.activity {
  border-color: var(--border-activity);
  background: linear-gradient(to bottom, #ffffff, var(--bg-activity));
}
.summary-card.total {
  border-color: var(--primary-border);
  background: linear-gradient(to bottom, #ffffff, var(--primary-light));
}

.summary-title {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--gray-600);
  margin-bottom: 0.25rem;
}

.summary-value {
  font-size: 1.5rem;
  font-weight: 700;
  line-height: 1.2;
}

.summary-card.present .summary-value { color: var(--color-present); }
.summary-card.absent .summary-value { color: var(--color-absent); }
.summary-card.leave .summary-value { color: var(--color-leave); }
.summary-card.late .summary-value { color: var(--color-late); }
.summary-card.activity .summary-value { color: var(--color-activity); }
.summary-card.total .summary-value { color: var(--primary); }

/* Quick Action Buttons */
.quick-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.btn-group {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.btn {
  font-family: var(--font-sans);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.55rem 1rem;
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.2s;
  text-decoration: none;
}

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

.btn-secondary {
  background: white;
  border-color: var(--gray-300);
  color: var(--gray-700);
}
.btn-secondary:hover {
  background: var(--gray-100);
  color: var(--gray-900);
}

.btn-success {
  background: var(--color-present);
  color: white;
}
.btn-success:hover {
  background: var(--color-present-active);
}

.btn-sm {
  padding: 0.35rem 0.65rem;
  font-size: 0.82rem;
  border-radius: var(--radius-sm);
}

/* Student Attendance List Table & Cards */
.table-container {
  overflow-x: auto;
  border-radius: var(--radius);
  border: 1px solid var(--gray-200);
  background: white;
}

.attendance-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
}

.attendance-table th {
  background: var(--gray-100);
  color: var(--gray-700);
  font-size: 0.85rem;
  font-weight: 700;
  padding: 0.75rem 0.85rem;
  border-bottom: 1px solid var(--gray-200);
  white-space: nowrap;
}

.attendance-table td {
  padding: 0.75rem 0.85rem;
  border-bottom: 1px solid var(--gray-200);
  vertical-align: middle;
  font-size: 0.92rem;
}

.attendance-table tbody tr:hover {
  background-color: var(--gray-50);
}

.student-roll {
  font-weight: 700;
  color: var(--gray-600);
  width: 50px;
  text-align: center;
}

.student-code {
  font-family: monospace;
  color: var(--gray-500);
  font-size: 0.85rem;
  background: var(--gray-100);
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
}

.student-name {
  font-weight: 600;
  color: var(--gray-900);
}

/* Segmented Status Selector */
.status-selector {
  display: inline-flex;
  background: var(--gray-100);
  padding: 3px;
  border-radius: var(--radius);
  gap: 3px;
  user-select: none;
}

.status-btn {
  padding: 0.4rem 0.75rem;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 600;
  border: none;
  background: transparent;
  color: var(--gray-600);
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.status-btn:hover {
  background: rgba(255, 255, 255, 0.7);
  color: var(--gray-900);
}

.status-btn.selected.present {
  background: var(--color-present);
  color: white;
  box-shadow: 0 2px 4px rgba(5, 150, 105, 0.3);
}

.status-btn.selected.absent {
  background: var(--color-absent);
  color: white;
  box-shadow: 0 2px 4px rgba(220, 38, 38, 0.3);
}

.status-btn.selected.leave {
  background: var(--color-leave);
  color: white;
  box-shadow: 0 2px 4px rgba(217, 119, 6, 0.3);
}

.status-btn.selected.late {
  background: var(--color-late);
  color: white;
  box-shadow: 0 2px 4px rgba(2, 132, 199, 0.3);
}

.status-btn.selected.activity {
  background: var(--color-activity);
  color: white;
  box-shadow: 0 2px 4px rgba(124, 58, 237, 0.3);
}

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

.badge-present {
  background: var(--bg-present);
  color: var(--color-present);
  border: 1px solid var(--border-present);
}
.badge-absent {
  background: var(--bg-absent);
  color: var(--color-absent);
  border: 1px solid var(--border-absent);
}
.badge-leave {
  background: var(--bg-leave);
  color: var(--color-leave);
  border: 1px solid var(--border-leave);
}
.badge-late {
  background: var(--bg-late);
  color: var(--color-late);
  border: 1px solid var(--border-late);
}
.badge-activity {
  background: var(--bg-activity);
  color: var(--color-activity);
  border: 1px solid var(--border-activity);
}
.badge-secondary {
  background: var(--gray-100);
  color: var(--gray-600);
  border: 1px solid var(--gray-200);
}

/* Remarks Input */
.remark-input {
  font-family: var(--font-sans);
  border: 1px solid var(--gray-300);
  border-radius: var(--radius-sm);
  padding: 0.35rem 0.5rem;
  font-size: 0.82rem;
  width: 100%;
  min-width: 120px;
  outline: none;
}
.remark-input:focus {
  border-color: var(--primary);
}

/* Sticky Bottom Action Bar */
.sticky-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(8px);
  border-top: 1px solid var(--gray-200);
  padding: 0.75rem 1rem;
  box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.08);
  z-index: 30;
}

.sticky-bar-inner {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.sticky-stats {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  font-size: 0.88rem;
  font-weight: 600;
}

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

.toast {
  background: white;
  color: var(--gray-900);
  padding: 0.85rem 1.25rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  border-left: 4px solid var(--primary);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-weight: 500;
  font-size: 0.92rem;
  animation: slideIn 0.25s ease-out;
}
.toast.success { border-left-color: var(--color-present); }
.toast.error { border-left-color: var(--color-absent); }

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

/* Drag & Drop Upload Zone */
.upload-zone {
  border: 2px dashed var(--primary-border);
  background: var(--primary-light);
  border-radius: var(--radius-lg);
  padding: 2.5rem 1.5rem;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s ease;
}
.upload-zone:hover, .upload-zone.dragover {
  border-color: var(--primary);
  background: #e0e7ff;
}

.upload-icon {
  font-size: 2.5rem;
  color: var(--primary);
  margin-bottom: 0.5rem;
}

/* Responsive Mobile Cards */
@media (max-width: 768px) {
  .attendance-table, .attendance-table thead, .attendance-table tbody, .attendance-table th, .attendance-table td, .attendance-table tr {
    display: block;
  }
  .attendance-table thead tr {
    position: absolute;
    top: -9999px;
    left: -9999px;
  }
  .attendance-table tr {
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    padding: 0.85rem;
    margin-bottom: 0.85rem;
    background: white;
    box-shadow: var(--shadow-sm);
  }
  .attendance-table td {
    border: none;
    padding: 0.35rem 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
  }
  .attendance-table td::before {
    content: attr(data-label);
    font-weight: 600;
    font-size: 0.8rem;
    color: var(--gray-500);
    margin-right: 0.5rem;
  }
  .status-selector {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(5, 1fr);
  }
  .status-btn {
    padding: 0.4rem 0.2rem;
    font-size: 0.75rem;
    text-align: center;
  }
  .sticky-bar-inner {
    flex-direction: column;
    align-items: stretch;
  }
  .sticky-stats {
    justify-content: space-between;
    font-size: 0.8rem;
  }
  .sticky-bar .btn-primary {
    width: 100%;
  }
}

/* Print Stylesheet for Reports */
@media print {
  .navbar, .sticky-bar, .quick-actions, .filter-controls, .btn, .no-print {
    display: none !important;
  }
  body {
    background: white;
    color: black;
  }
  .container {
    max-width: 100%;
    padding: 0;
  }
  .card {
    border: none;
    box-shadow: none;
    padding: 0;
  }
  .attendance-table th, .attendance-table td {
    border: 1px solid #ddd !important;
    color: black;
  }
}
