/* ═══════════════════════════════════════════════
   School MIS — Thai Academic Management System
   ═══════════════════════════════════════════════ */
:root {
  --primary: #059669;
  --primary-light: #d1fae5;
  --primary-dark: #065f46;
  --danger: #dc2626;
  --danger-light: #fee2e2;
  --warning: #d97706;
  --warning-light: #fef3c7;
  --info: #2563eb;
  --info-light: #dbeafe;
  --bg: #f1f5f9;
  --card: #ffffff;
  --border: #e2e8f0;
  --text: #1e293b;
  --text-light: #64748b;
  --sidebar-w: 260px;
  --topbar-h: 56px;
}

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

body {
  font-family: 'Noto Sans Thai', 'TH Sarabun New', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
}

/* ── Login Page ── */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #059669 0%, #065f46 100%);
}
.login-box {
  background: var(--card);
  border-radius: 16px;
  padding: 40px 36px;
  width: 400px;
  max-width: 90vw;
  box-shadow: 0 20px 60px rgba(0,0,0,.15);
  text-align: center;
}
.login-box h1 { font-size: 20px; margin-bottom: 4px; color: var(--primary-dark); }
.login-box .subtitle { font-size: 14px; color: var(--text-light); margin-bottom: 24px; }

/* ── Forms ── */
.form-group { margin-bottom: 16px; text-align: left; }
.form-group label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 4px; color: var(--text-light); }
.form-control {
  width: 100%;
  padding: 10px 12px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  transition: border-color .2s;
}
.form-control:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(5,150,105,.1); }
select.form-control { appearance: auto; }
textarea.form-control { resize: vertical; min-height: 80px; }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all .2s;
  text-decoration: none;
  white-space: nowrap;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; }
.btn-warning { background: var(--warning); color: #fff; }
.btn-info { background: var(--info); color: #fff; }
.btn-ghost { background: transparent; color: var(--text-light); border: 1.5px solid var(--border); }
.btn-ghost:hover { background: var(--bg); }
.btn-sm { padding: 5px 10px; font-size: 12px; border-radius: 6px; }
.btn-block { width: 100%; }

/* ── Layout ── */
.sidebar {
  position: fixed;
  left: 0; top: 0; bottom: 0;
  width: var(--sidebar-w);
  background: #fff;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 100;
  overflow-y: auto;
}
.sidebar-header {
  padding: 20px 16px 12px;
  border-bottom: 1px solid var(--border);
}
.sidebar-header h2 { font-size: 15px; color: var(--primary-dark); }
.sidebar-header p { font-size: 12px; color: var(--text-light); }

.sidebar-nav { flex: 1; padding: 8px 0; }
.nav-section { padding: 8px 16px 4px; font-size: 11px; font-weight: 700; color: var(--text-light); text-transform: uppercase; letter-spacing: .5px; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 16px;
  font-size: 13px;
  color: var(--text);
  text-decoration: none;
  cursor: pointer;
  transition: all .15s;
  border-left: 3px solid transparent;
}
.nav-item:hover { background: var(--bg); }
.nav-item.active { background: var(--primary-light); color: var(--primary-dark); border-left-color: var(--primary); font-weight: 600; }
.nav-item .icon { font-size: 16px; width: 20px; text-align: center; }

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  font-size: 12px;
}
.sidebar-footer .user-info { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.sidebar-footer .user-avatar { width: 32px; height: 32px; background: var(--primary-light); color: var(--primary-dark); border-radius: 50%; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 14px; }

.main { margin-left: var(--sidebar-w); min-height: 100vh; }
.topbar {
  height: var(--topbar-h);
  background: #fff;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 50;
}
.topbar h1 { font-size: 16px; font-weight: 700; }
.topbar .date { font-size: 13px; color: var(--text-light); }

.content { padding: 24px; max-width: 1200px; }

/* ── Cards ── */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  margin-bottom: 16px;
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  flex-wrap: wrap;
  gap: 8px;
}
.card-header h3 { font-size: 16px; font-weight: 700; }

/* ── Stats Cards ── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px 20px;
}
.stat-card .label { font-size: 12px; color: var(--text-light); font-weight: 600; }
.stat-card .value { font-size: 28px; font-weight: 800; color: var(--primary-dark); margin: 4px 0 2px; }
.stat-card .sub { font-size: 12px; color: var(--text-light); }

/* ── Tables ── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); }
th { background: var(--bg); font-weight: 700; font-size: 12px; color: var(--text-light); white-space: nowrap; }
tr:hover td { background: #f8fafc; }
td.actions { white-space: nowrap; }

/* ── Badges ── */
.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 700;
}
.badge-success { background: #d1fae5; color: #065f46; }
.badge-danger { background: #fee2e2; color: #991b1b; }
.badge-warning { background: #fef3c7; color: #854d0e; }
.badge-info { background: #dbeafe; color: #1e40af; }
.badge-purple { background: #ede9fe; color: #5b21b6; }

/* ── Alerts ── */
.alert {
  padding: 12px 16px;
  border-radius: 8px;
  margin-bottom: 16px;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.alert-success { background: #d1fae5; color: #065f46; border: 1px solid #a7f3d0; }
.alert-danger { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }
.alert-info { background: #dbeafe; color: #1e40af; border: 1px solid #bfdbfe; }
.alert-warning { background: #fef3c7; color: #854d0e; border: 1px solid #fde68a; }

/* ── Toolbar ── */
.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.toolbar .form-control { width: auto; min-width: 140px; }

/* ── Modal ── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.modal {
  background: var(--card);
  border-radius: 12px;
  padding: 24px;
  width: 500px;
  max-width: 90vw;
  max-height: 85vh;
  overflow-y: auto;
}
.modal h3 { margin-bottom: 16px; font-size: 16px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 20px; }

/* ── Hamburger Button ── */
.hamburger {
  display: none;
  background: none;
  border: none;
  font-size: 24px;
  cursor: pointer;
  padding: 4px 8px;
  color: var(--text);
  line-height: 1;
}

/* ── Sidebar Overlay (mobile backdrop) ── */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 90;
  opacity: 0;
  transition: opacity .25s;
}
.sidebar-overlay.open { display: block; opacity: 1; }

/* ── Responsive ── */
@media (max-width: 768px) {
  /* Sidebar becomes slide-in drawer */
  .sidebar {
    transform: translateX(-100%);
    transition: transform .25s ease;
    box-shadow: none;
  }
  .sidebar.open {
    transform: translateX(0);
    box-shadow: 4px 0 24px rgba(0,0,0,.15);
  }

  /* Show hamburger */
  .hamburger { display: block; }

  /* No margin offset */
  .main { margin-left: 0; }
  body.sidebar-open { overflow: hidden; }

  /* Topbar */
  .topbar {
    padding: 0 12px;
    gap: 8px;
  }
  .topbar h1 { font-size: 14px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .topbar .date { font-size: 11px; display: none; }

  /* Content */
  .content { padding: 12px; }

  /* Stats grid */
  .stats-grid {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-bottom: 16px;
  }
  .stat-card { padding: 12px 14px; }
  .stat-card .value { font-size: 22px; }
  .stat-card .label { font-size: 11px; }

  /* Cards */
  .card { padding: 14px; border-radius: 10px; }
  .card-header { margin-bottom: 12px; }
  .card-header h3 { font-size: 14px; }

  /* Tables — make scrollable + compact */
  .table-wrap { margin: 0 -12px; padding: 0; }
  table { font-size: 12px; min-width: 500px; }
  th, td { padding: 8px 10px; }

  /* Forms — full width, larger touch targets */
  .form-control { padding: 12px 14px; font-size: 16px; /* prevent iOS zoom */ }
  .form-group label { font-size: 12px; }

  /* Buttons — larger tap targets */
  .btn { padding: 10px 16px; font-size: 14px; }
  .btn-sm { padding: 8px 12px; font-size: 13px; }

  /* Toolbar — stack vertically */
  .toolbar { flex-direction: column; align-items: stretch; gap: 8px; }
  .toolbar .form-control { width: 100%; min-width: 0; }

  /* Modal — full screen on small phones */
  .modal { width: 100%; max-width: 100%; border-radius: 0; max-height: 100vh; padding: 16px; }
  .modal-overlay { align-items: flex-end; }
  .modal { border-radius: 16px 16px 0 0; max-height: 90vh; }

  /* Login box */
  .login-box { padding: 28px 20px; width: 100%; max-width: 100%; border-radius: 0; min-height: 100vh; display: flex; flex-direction: column; justify-content: center; }

  /* Sidebar nav — slightly larger tap targets */
  .nav-item { padding: 11px 16px; font-size: 14px; }
  .nav-section { font-size: 10px; padding-top: 12px; }
}

@media (max-width: 400px) {
  .stats-grid { grid-template-columns: 1fr; }
  .stat-card { padding: 10px 12px; }
  .stat-card .value { font-size: 20px; }
}

/* ── Print ── */
@media print {
  .sidebar, .topbar, .no-print { display: none !important; }
  .main { margin-left: 0 !important; }
  .content { padding: 0 !important; }
  body { background: #fff; }
  .card { border: none; box-shadow: none; }
}

/* ── Misc ── */
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-muted { color: var(--text-light); }
.text-danger { color: var(--danger); }
.text-success { color: var(--primary-dark); }
.mt-2 { margin-top: 8px; }
.mt-4 { margin-top: 16px; }
.mb-2 { margin-bottom: 8px; }
.mb-4 { margin-bottom: 16px; }
.gap-2 { gap: 8px; }
.flex { display: flex; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.hidden { display: none; }

/* ═══════════════════════════════════════════════
   Attendance — Mobile-first Check-in UI
   ═══════════════════════════════════════════════ */

/* ── Selector (class + date picker) ── */
.att-selector { display: flex; flex-direction: column; gap: 12px; }
.att-selector-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

/* ── Summary bar ── */
.att-subject-header {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff;
  border-radius: 12px;
  padding: 16px 20px;
  margin-bottom: 12px;
}
.att-subject-name {
  font-size: 20px;
  font-weight: 800;
  margin-bottom: 4px;
}
.att-subject-meta {
  font-size: 13px;
  opacity: 0.85;
}
.att-summary {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 16px;
  margin-bottom: 12px;
}
.att-summary-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.att-checked {
  font-size: 12px;
  font-weight: 600;
  color: var(--primary);
  background: var(--primary-light);
  padding: 2px 8px;
  border-radius: 99px;
}
.att-summary-pills {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.att-pill {
  font-size: 12px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 99px;
  white-space: nowrap;
}
.att-pill-present { background: #d1fae5; color: #065f46; }
.att-pill-absent  { background: #fee2e2; color: #991b1b; }
.att-pill-leave   { background: #dbeafe; color: #1e40af; }
.att-pill-sick    { background: #fef3c7; color: #854d0e; }
.att-pill-late    { background: #ede9fe; color: #5b21b6; }

/* ── Quick action bar ── */
.att-quick-actions {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
  align-items: center;
}
.att-quick-actions .btn-primary { margin-left: auto; }

/* ── Attendance Table ── */
.att-table-wrap {
  overflow-x: auto;
  margin-bottom: 80px; /* space for sticky save bar */
  -webkit-overflow-scrolling: touch;
}
.att-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 14px;
}
.att-table thead th {
  background: var(--bg);
  padding: 10px 12px;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-light);
  text-align: left;
  border-bottom: 2px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 2;
}
.att-th-no { width: 50px; text-align: center !important; }
.att-th-name { min-width: 120px; }
.att-th-btns { min-width: 260px; }

.att-table tbody tr {
  border-bottom: 1px solid var(--border);
}
.att-table tbody tr:last-child { border-bottom: none; }
.att-table td {
  padding: 10px 8px;
  vertical-align: middle;
  border-bottom: 1px solid var(--border);
}
.att-td-no {
  text-align: center;
  font-weight: 800;
  font-size: 15px;
  color: var(--text-light);
}
.att-td-name {
  font-weight: 600;
  font-size: 14px;
  white-space: nowrap;
}
.att-td-btns { padding: 8px 4px; }

/* ── Status button row inside table ── */
.att-btns {
  display: flex;
  gap: 4px;
}
.att-btn {
  border: 2px solid transparent;
  border-radius: 8px;
  padding: 8px 6px;
  font-size: 12px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  text-align: center;
  transition: all .15s;
  background: var(--bg);
  color: var(--text-light);
  min-width: 44px; /* Apple touch target guideline */
  flex: 1;
}
.att-btn:active { transform: scale(.93); }

/* Default state (unselected) */
.att-btn-present { border-color: #a7f3d0; color: #065f46; }
.att-btn-absent  { border-color: #fecaca; color: #991b1b; }
.att-btn-leave   { border-color: #bfdbfe; color: #1e40af; }
.att-btn-sick    { border-color: #fde68a; color: #854d0e; }
.att-btn-late    { border-color: #c4b5fd; color: #5b21b6; }

/* Active (selected) state */
.att-btn-present.active { background: #059669; color: #fff; border-color: #059669; }
.att-btn-absent.active  { background: #dc2626; color: #fff; border-color: #dc2626; }
.att-btn-leave.active   { background: #2563eb; color: #fff; border-color: #2563eb; }
.att-btn-sick.active    { background: #d97706; color: #fff; border-color: #d97706; }
.att-btn-late.active    { background: #7c3aed; color: #fff; border-color: #7c3aed; }

/* ── Sticky save bar ── */
.att-save-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: #fff;
  border-top: 1px solid var(--border);
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  z-index: 80;
  box-shadow: 0 -2px 12px rgba(0,0,0,.08);
}
.att-save-count { font-size: 13px; color: var(--text-light); font-weight: 600; }
.att-save-btn { padding: 12px 24px; font-size: 15px; font-weight: 700; }

/* ── Desktop: wider buttons, offset for sidebar ── */
@media (min-width: 769px) {
  .att-btn { padding: 8px 12px; min-width: 56px; }
  .att-table td { padding: 10px 12px; }
  .att-save-bar { left: var(--sidebar-w); }
}

/* ── Mobile tweaks ── */
@media (max-width: 768px) {
  .att-btn { font-size: 13px; padding: 10px 6px; min-width: 50px; min-height: 44px; }
  .att-btns { gap: 5px; }
  .att-td-name { font-size: 14px; white-space: normal; }
  .att-td-no { font-size: 15px; width: 40px; }
  .att-table { min-width: 0; width: 100%; }
  .att-table thead th { font-size: 11px; padding: 8px 6px; }
  .att-table td { padding: 6px 4px; }
  .att-td-btns { padding: 6px 2px; }
  .att-th-name { min-width: 80px; }
  .att-th-btns { min-width: auto; }
  .att-save-bar { padding: 8px 12px; }
  .att-save-btn { padding: 12px 20px; font-size: 15px; width: 100%; }
  .att-save-count { font-size: 12px; }
}
