/* ── Design tokens ──────────────────────────────────────────────────────────── */
:root {
  --red:          #C62828;
  --red-dark:     #8E0000;
  --blue:         #1565C0;
  --blue-light:   #E3F2FD;
  --green:        #2E7D32;
  --green-light:  #E8F5E9;
  --orange:       #E65100;
  --orange-light: #FFF3E0;
  --gray-50:  #FAFAFA;
  --gray-100: #F5F5F5;
  --gray-200: #EEEEEE;
  --gray-400: #BDBDBD;
  --gray-600: #757575;
  --gray-800: #424242;
  --gray-900: #212121;
  --white:    #FFFFFF;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.10);
  --shadow:    0 2px 6px rgba(0,0,0,0.12);
  --radius:    8px;
  --tap:       52px; /* min tap-target height */
}

/* ── Reset ──────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--gray-100);
  color: var(--gray-900);
  min-height: 100dvh;
  font-size: 16px;
  line-height: 1.5;
}
.hidden { display: none !important; }

/* ── Header ─────────────────────────────────────────────────────────────────── */
#app-header {
  background: var(--red);
  color: #fff;
  height: 56px;
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 6px rgba(0,0,0,0.25);
}
.header-left  { display: flex; align-items: center; gap: 14px; }
.header-title { font-size: 1.1rem; font-weight: 700; letter-spacing: 0.01em; }
.offline-badge {
  font-size: 0.78rem;
  padding: 3px 10px;
  border-radius: 100px;
  background: rgba(255,255,255,0.22);
  border: 1px solid rgba(255,255,255,0.45);
}
.header-right { display: flex; align-items: center; gap: 12px; }
#user-display { font-size: 0.9rem; opacity: 0.88; max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#btn-logout {
  background: rgba(255,255,255,0.18);
  color: #fff;
  border: 1px solid rgba(255,255,255,0.45);
  padding: 6px 14px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.875rem;
  white-space: nowrap;
}
#btn-logout:hover { background: rgba(255,255,255,0.30); }

/* ── Admin nav tabs ─────────────────────────────────────────────────────────── */
#admin-nav {
  background: var(--white);
  display: flex;
  border-bottom: 2px solid var(--gray-200);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.tab-btn {
  padding: 14px 22px;
  border: none;
  background: none;
  cursor: pointer;
  font-size: 0.95rem;
  color: var(--gray-600);
  border-bottom: 3px solid transparent;
  margin-bottom: -2px;
  white-space: nowrap;
  transition: color 0.15s;
  min-height: var(--tap);
}
.tab-btn:hover  { color: var(--red); }
.tab-btn.active { color: var(--red); border-bottom-color: var(--red); font-weight: 600; }

/* ── Screens ─────────────────────────────────────────────────────────────────── */
.screen { min-height: calc(100dvh - 56px); }

/* ── Login ───────────────────────────────────────────────────────────────────── */
#screen-login {
  display: flex; align-items: center; justify-content: center;
  min-height: 100dvh;
}
.login-card {
  background: var(--white);
  border-radius: var(--radius);
  padding: 40px 32px;
  width: 100%; max-width: 380px;
  box-shadow: var(--shadow);
  text-align: center;
}
.login-logo {
  font-size: 0.8rem; font-weight: 700;
  letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--red); margin-bottom: 6px;
}
.login-card h1 { font-size: 1.75rem; margin-bottom: 28px; color: var(--gray-900); }
.login-card input {
  display: block; width: 100%;
  padding: 13px 14px;
  border: 1.5px solid var(--gray-200);
  border-radius: var(--radius);
  font-size: 1rem; margin-bottom: 12px;
}
.login-card input:focus { outline: none; border-color: var(--red); }
.error { color: var(--red); font-size: 0.875rem; min-height: 20px; margin-top: 8px; }

/* ── Buttons ─────────────────────────────────────────────────────────────────── */
.btn-primary {
  display: block; width: 100%;
  padding: 14px; background: var(--red); color: #fff;
  border: none; border-radius: var(--radius);
  font-size: 1rem; font-weight: 600; cursor: pointer;
  transition: background 0.15s;
}
.btn-primary:hover    { background: var(--red-dark); }
.btn-primary:disabled { opacity: 0.55; cursor: not-allowed; }

.btn-secondary {
  padding: 10px 16px;
  background: var(--white); color: var(--red);
  border: 2px solid var(--red); border-radius: var(--radius);
  font-size: 0.875rem; font-weight: 600; cursor: pointer;
  transition: all 0.15s;
}
.btn-secondary:hover { background: var(--red); color: #fff; }

.btn-sm {
  padding: 5px 11px; border: none; border-radius: 5px;
  cursor: pointer; font-size: 0.8rem; font-weight: 600;
}
.btn-sm.edit       { background: var(--blue-light); color: var(--blue); }
.btn-sm.deactivate { background: var(--orange-light); color: var(--orange); }
.btn-sm.reactivate { background: var(--green-light); color: var(--green); }
.btn-sm.danger     { background: #FFEBEE; color: var(--red); }

/* ── Staff board ─────────────────────────────────────────────────────────────── */
.board-page { padding: 16px; max-width: 640px; margin: 0 auto; }
.board-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px; flex-wrap: wrap; gap: 10px;
}
.board-header h2 { font-size: 1.35rem; }
.count-badge {
  background: var(--red); color: #fff;
  padding: 6px 18px; border-radius: 100px;
  font-size: 1rem; font-weight: 600;
}
.roster-list { display: flex; flex-direction: column; gap: 8px; }

.student-row {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 0 14px;
  display: flex; align-items: center;
  min-height: var(--tap); gap: 10px;
  border-left: 4px solid transparent;
}
.student-row.present { border-left-color: var(--green); }
.student-row.out     { border-left-color: var(--gray-400); opacity: 0.7; }
.student-row.absent  { border-left-color: transparent; }
.student-name { flex: 1; font-size: 1rem; font-weight: 500; }
.row-actions  { display: flex; gap: 6px; flex-shrink: 0; }

.status-badge {
  font-size: 0.78rem; padding: 3px 10px;
  border-radius: 100px; font-weight: 600; white-space: nowrap;
}
.status-badge.not-in  { background: var(--gray-200); color: var(--gray-600); }
.status-badge.present { background: var(--green-light); color: var(--green); }
.status-badge.out     { background: var(--gray-200); color: var(--gray-600); }

.btn-action {
  padding: 8px 14px; border: none; border-radius: 6px;
  font-size: 0.875rem; font-weight: 600; cursor: pointer;
  min-height: 38px; white-space: nowrap;
  transition: background 0.12s;
}
.btn-checkin  { background: var(--green);  color: #fff; }
.btn-checkin:hover  { background: #1B5E20; }
.btn-checkout { background: var(--orange); color: #fff; }
.btn-checkout:hover { background: #BF360C; }
.btn-undo     { background: var(--gray-200); color: var(--gray-800); }
.btn-undo:hover     { background: var(--gray-400); }

/* ── Admin board ─────────────────────────────────────────────────────────────── */
.admin-page { padding: 16px; max-width: 920px; margin: 0 auto; }
.admin-board-topbar {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 20px; flex-wrap: wrap; gap: 12px;
}
.global-count { font-size: 1.15rem; font-weight: 700; color: var(--red); }

.group-card {
  background: var(--white); border-radius: var(--radius);
  box-shadow: var(--shadow-sm); margin-bottom: 14px; overflow: hidden;
}
.group-card-header {
  background: var(--blue); color: #fff;
  padding: 12px 16px;
  display: flex; justify-content: space-between; align-items: center;
  font-weight: 600;
}
.group-present-count {
  background: rgba(255,255,255,0.2); padding: 2px 12px;
  border-radius: 100px; font-size: 0.875rem; font-weight: 500;
}
.group-students { padding: 4px 0; }
.group-student-row {
  padding: 9px 16px; display: flex; align-items: center; gap: 10px;
  border-bottom: 1px solid var(--gray-100);
  font-size: 0.9rem;
}
.group-student-row:last-child { border-bottom: none; }
.group-student-row.out { opacity: 0.65; }
.group-student-row.empty-row { color: var(--gray-400); font-style: italic; }
.row-time { margin-left: auto; color: var(--gray-600); font-size: 0.82rem; white-space: nowrap; }

.log-section { margin-top: 32px; }
.log-section h3 { font-size: 1.05rem; font-weight: 600; margin-bottom: 10px; color: var(--gray-800); }
.log-table { background: var(--white); border-radius: var(--radius); box-shadow: var(--shadow-sm); overflow-x: auto; }
.log-table table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
.log-table th {
  background: var(--gray-100); padding: 10px 12px;
  text-align: left; font-weight: 600; color: var(--gray-600);
  border-bottom: 1px solid var(--gray-200); white-space: nowrap;
}
.log-table td { padding: 10px 12px; border-bottom: 1px solid var(--gray-100); }
.log-table tr:last-child td { border-bottom: none; }
.by-cell  { font-size: 0.82rem; color: var(--gray-600); }
.empty-cell { text-align: center; color: var(--gray-400); padding: 24px !important; }

/* ── Admin sections (roster, staff, export) ─────────────────────────────────── */
.admin-section { padding: 16px; max-width: 900px; margin: 0 auto; }
.section-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 16px; flex-wrap: wrap; gap: 10px;
}
.section-header h2 { font-size: 1.25rem; }
.section-header-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.data-table {
  background: var(--white); border-radius: var(--radius);
  box-shadow: var(--shadow-sm); overflow-x: auto; margin-bottom: 28px;
}
.data-table table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
.data-table th {
  background: var(--gray-100); padding: 10px 12px;
  text-align: left; font-weight: 600; color: var(--gray-600);
  border-bottom: 1px solid var(--gray-200); white-space: nowrap;
}
.data-table td { padding: 10px 12px; border-bottom: 1px solid var(--gray-100); vertical-align: middle; }
.data-table td:last-child { white-space: nowrap; }
.data-table tr:last-child td { border-bottom: none; }
.row-inactive td { opacity: 0.55; }

.status-pill {
  display: inline-block; font-size: 0.78rem; font-weight: 600;
  padding: 2px 10px; border-radius: 100px;
}
.status-pill.active   { background: var(--green-light); color: var(--green); }
.status-pill.inactive { background: var(--gray-200);    color: var(--gray-600); }

.role-badge {
  display: inline-block; font-size: 0.78rem; font-weight: 600;
  padding: 2px 10px; border-radius: 100px;
}
.role-badge.admin { background: #EDE7F6; color: #4527A0; }
.role-badge.staff { background: var(--blue-light); color: var(--blue); }

/* ── Export form ─────────────────────────────────────────────────────────────── */
.export-form {
  background: var(--white); border-radius: var(--radius);
  box-shadow: var(--shadow-sm); padding: 24px; max-width: 420px;
}
.form-field { margin-bottom: 16px; }
.form-field label { display: block; font-size: 0.875rem; font-weight: 600; color: var(--gray-600); margin-bottom: 5px; }
.form-field input, .form-field select {
  width: 100%; padding: 10px 12px;
  border: 1.5px solid var(--gray-200); border-radius: 6px; font-size: 1rem;
}
.form-field input:focus, .form-field select:focus { outline: none; border-color: var(--red); }

/* ── Modal ───────────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.48);
  display: flex; align-items: center; justify-content: center;
  z-index: 200; padding: 16px;
}
.modal {
  background: var(--white); border-radius: var(--radius);
  padding: 24px; width: 100%; max-width: 440px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.22);
}
.modal h3 { font-size: 1.15rem; margin-bottom: 16px; }
.modal-hint {
  font-size: 0.875rem; color: var(--gray-600);
  background: var(--gray-100); border-radius: 6px;
  padding: 10px 12px; margin-bottom: 14px;
}
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }
.btn-cancel {
  padding: 10px 16px; background: none; border: none;
  color: var(--gray-600); cursor: pointer; font-size: 0.95rem;
}
.btn-save {
  padding: 10px 22px; background: var(--red); color: #fff;
  border: none; border-radius: 6px; font-weight: 600; cursor: pointer; font-size: 0.95rem;
}
.btn-save:hover { background: var(--red-dark); }

/* ── CSV import ──────────────────────────────────────────────────────────────── */
#import-file { margin-bottom: 12px; font-size: 0.9rem; }
.import-preview {
  background: var(--gray-100); border-radius: 6px; padding: 12px;
  font-size: 0.85rem; line-height: 1.6;
  max-height: 220px; overflow-y: auto; margin-bottom: 4px;
}
.import-preview ul { margin-top: 4px; }

/* CSV sync preview */
.sync-summary { display: flex; flex-wrap: wrap; gap: 14px; margin-bottom: 8px; font-size: 0.9rem; }
.sync-line.add b    { color: var(--green); }
.sync-line.update b { color: var(--blue); }
.sync-line.deact b  { color: var(--orange); }
.sync-line.muted    { color: var(--gray-600); }
.sync-note { font-size: 0.85rem; color: var(--gray-700); margin-bottom: 8px; }
.sync-warn {
  background: var(--orange-light); border: 1px solid var(--orange);
  border-radius: 6px; padding: 10px 12px; font-size: 0.85rem; color: var(--orange-dark, #BF360C);
  margin-bottom: 8px;
}
.sync-warn ul { margin: 6px 0 8px 18px; }
.sync-confirm { display: flex; align-items: center; gap: 6px; color: var(--gray-900); font-weight: 600; }
.sync-details { font-size: 0.85rem; margin-bottom: 6px; }
.sync-details summary { cursor: pointer; color: var(--blue); }
.sync-details ul { margin: 6px 0 0 18px; }

/* ── Empty states ────────────────────────────────────────────────────────────── */
.empty-state {
  text-align: center; padding: 60px 16px; color: var(--gray-600);
}
.empty-state h3 { font-size: 1.1rem; margin-bottom: 6px; }

/* ── Date picker (admin board) ───────────────────────────────────────────────── */
#admin-date-picker {
  padding: 7px 10px;
  border: 1.5px solid var(--gray-200); border-radius: 6px;
  font-size: 0.9rem; color: var(--gray-800);
}

/* ── Admin board v2: summary + collapsible rosters + override ────────────────── */
.topbar-controls { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.date-label { font-size: 0.9rem; color: var(--gray-700); }
#admin-override-toggle.override-active { background: var(--red); color: #fff; border-color: var(--red); }
.override-banner {
  background: var(--orange-light); color: var(--orange);
  border: 1px solid var(--orange); border-radius: var(--radius);
  padding: 10px 14px; font-size: 0.9rem; font-weight: 600; margin-bottom: 14px;
}

.admin-summary {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 8px; margin-bottom: 20px;
}
.summary-tile {
  text-align: left; background: var(--white);
  border: 1px solid var(--gray-200); border-radius: var(--radius);
  padding: 10px 12px; cursor: pointer;
  display: flex; flex-direction: column; gap: 3px;
  box-shadow: var(--shadow-sm); transition: border-color 0.12s;
}
.summary-tile:hover    { border-color: var(--blue); }
.summary-tile.expanded { border-color: var(--blue); background: var(--blue-light); }
.summary-tile-name { font-weight: 600; font-size: 0.9rem; color: var(--gray-900); }
.summary-tile-stat { font-size: 0.82rem; color: var(--gray-600); }
.summary-tile-stat b { color: var(--green); font-size: 1rem; }
.absent-num { color: var(--orange); font-weight: 600; }

.group-card-header.clickable { cursor: pointer; user-select: none; }
.group-card-header .caret { margin-right: 8px; font-size: 0.8rem; }
.group-card-header .gc-name { flex: 1; }
.group-card.collapsed .group-students { display: none; }

/* roster rows inside admin group cards */
.group-students .group-student-row .student-name { flex: 1; }
.group-students .group-student-row .row-time { margin-left: 0; }
.group-students .group-student-row .row-actions { display: flex; gap: 6px; flex-shrink: 0; }

/* ── Responsive ──────────────────────────────────────────────────────────────── */
@media (max-width: 600px) {
  .login-card  { padding: 28px 18px; }
  .board-page  { padding: 12px; }
  .admin-page  { padding: 12px; }
  .admin-section { padding: 12px; }
  .section-header  { flex-direction: column; align-items: flex-start; }
  .admin-board-topbar { flex-direction: column; align-items: flex-start; }
  .student-row { padding: 0 10px; }
  .group-card-header { flex-direction: column; align-items: flex-start; gap: 4px; }
  .log-table th, .log-table td { padding: 8px; font-size: 0.82rem; }
  .tab-btn { padding: 12px 16px; font-size: 0.875rem; }
  .modal { padding: 18px; }
}
