:root {
  --bg: #f8fafc;
  --surface: #ffffff;
  --primary: #2563eb;
  --secondary: #0f172a;
  --success: #16a34a;
  --danger: #dc2626;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --entry-bg: #dcfce7;
  --entry-color: #15803d;
  --exit-bg: #dbeafe;
  --exit-color: #1d4ed8;
  --absent-bg: #f1f5f9;
  --absent-color: #64748b;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: Inter, system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.page-shell {
  max-width: 960px;
  margin: 0 auto;
  padding: 24px;
}

header.header-bar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 24px;
  gap: 16px;
  flex-wrap: wrap;
}

.role-switcher {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.role-switcher label {
  font-size: 0.8rem;
  color: var(--muted);
  white-space: nowrap;
  font-weight: 400;
  margin: 0;
  display: inline;
}

.role-switcher select {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  font-size: 0.875rem;
  cursor: pointer;
  width: auto;
  margin: 0;
  font-weight: 500;
}
h1 { margin: 0; font-size: 2rem; }
.subtitle { margin: 4px 0 0; color: var(--muted); }

.card, .panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 24px;
  margin-bottom: 18px;
}

.panel { display: none; }
.panel.active { display: block; }
.hidden { display: none !important; }

button, input, select { font: inherit; }

button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 10px;
  padding: 10px 18px;
  cursor: pointer;
  white-space: nowrap;
  gap: 6px;
}

button.primary  { background: var(--primary); color: white; }
button.secondary { background: #e2e8f0; color: var(--secondary); }
button:disabled { opacity: 0.4; cursor: not-allowed; }

input, select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-top: 6px;
}

label {
  display: block;
  font-weight: 500;
  margin-bottom: 14px;
}

/* ── Toolbar ── */
.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}

.toolbar-left {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.toolbar-tabs { display: flex; gap: 6px; flex-wrap: wrap; }

.context-group {
  display: flex;
  flex-direction: column;
  line-height: 1.35;
}

.context-label {
  font-size: 0.78rem;
  color: var(--muted);
}

.tab-button {
  background: #f1f5f9;
  color: var(--secondary);
  padding: 10px 16px;
}

.tab-button.active {
  background: var(--primary);
  color: white;
}

/* ── Panel header ── */
.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 18px;
  gap: 12px;
}

.panel-header h2 { margin: 0 0 4px; }

.date-line {
  margin: 0;
  font-size: 0.9rem;
  color: var(--muted);
  font-weight: 500;
}

/* ── Class picker ── */
.picker-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 4px;
  gap: 12px;
}

.picker-header h2 { margin: 0; }

.class-picker-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 16px;
  margin-top: 20px;
}

.class-pick-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.class-pick-card h3 { margin: 0 0 6px; }
.class-pick-card p { margin: 0; font-size: 0.875rem; color: var(--muted); }
.class-pick-card button { margin-top: 14px; align-self: flex-start; }

/* ── Attendance table ── */
.attendance-table-wrapper { overflow-x: auto; }

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

.attendance-table th,
.attendance-table td {
  border: 1px solid var(--border);
  padding: 10px 14px;
  text-align: left;
  vertical-align: middle;
}

.attendance-table th {
  background: #f1f5f9;
  font-size: 0.875rem;
  font-weight: 600;
  white-space: nowrap;
}

.attendance-table td:last-child {
  white-space: nowrap;
}

.att-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.btn-entry {
  background: var(--entry-bg);
  color: var(--entry-color);
  border: 1px solid #bbf7d0;
  border-radius: 8px;
  padding: 6px 14px;
  font-size: 0.875rem;
  font-weight: 600;
}

.btn-entry:hover:not(:disabled) {
  background: #bbf7d0;
}

.btn-exit {
  background: var(--exit-bg);
  color: var(--exit-color);
  border: 1px solid #bfdbfe;
  border-radius: 8px;
  padding: 6px 14px;
  font-size: 0.875rem;
  font-weight: 600;
}

.btn-exit:hover:not(:disabled) {
  background: #bfdbfe;
}

/* ── Status badges ── */
.status-chip {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 99px;
  font-size: 0.8rem;
  font-weight: 600;
  white-space: nowrap;
}

.chip-absent  { background: var(--absent-bg);  color: var(--absent-color); }
.chip-entry   { background: var(--entry-bg);   color: var(--entry-color);  }
.chip-exited  { background: var(--exit-bg);    color: var(--exit-color);   }
.chip-not-in  { background: #fef9c3; color: #854d0e; }

/* ── Log controls ── */
.log-controls {
  display: flex;
  gap: 12px;
  align-items: flex-end;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.log-controls label {
  flex: 1;
  min-width: 160px;
  margin: 0;
}

/* ── Search bar ── */
.search-bar {
  margin-bottom: 16px;
}

.search-bar input {
  width: 100%;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  font-size: 1rem;
  margin: 0;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}

.search-bar input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

/* ── Live Summary Bar ── */
.live-summary {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.live-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 10px 18px;
  border-radius: 12px;
  border: 1px solid transparent;
  min-width: 80px;
}

.live-stat.in-class    { background: #dcfce7; border-color: #bbf7d0; }
.live-stat.exited      { background: #dbeafe; border-color: #bfdbfe; }
.live-stat.not-arrived { background: #f1f5f9; border-color: var(--border); }
.live-stat.total       { background: #ffffff; border-color: var(--border); }

.ls-value {
  font-size: 1.6rem;
  font-weight: 700;
  line-height: 1;
}

.ls-label {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted);
  margin-top: 4px;
}

.live-stat.in-class    .ls-value { color: var(--success); }
.live-stat.exited      .ls-value { color: #1d4ed8; }
.live-stat.not-arrived .ls-value { color: var(--muted); }

/* ── All Classes Overview ── */
.classes-overview {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px;
  margin-bottom: 16px;
}

.overview-grid {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.overview-card {
  background: white;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 14px;
  min-width: 180px;
}

.overview-card.is-current {
  border-color: var(--primary);
  background: #eff6ff;
}

.overview-card strong {
  display: block;
  font-size: 0.9rem;
  margin-bottom: 6px;
}

.current-tag {
  background: var(--primary);
  color: white;
  border-radius: 99px;
  padding: 1px 7px;
  font-size: 0.7rem;
  font-weight: 600;
  vertical-align: middle;
}

.overview-stats {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  font-size: 0.8rem;
  font-weight: 600;
}

.ov-stat.in-class    { color: var(--success); }
.ov-stat.exited      { color: #1d4ed8; }
.ov-stat.not-arrived { color: var(--muted); }
.ov-stat.total       { color: var(--text); font-weight: 400; }

/* ── Status messages ── */
.status {
  margin-top: 14px;
  font-size: 0.95rem;
  min-height: 1.2em;
}

.status.error   { color: var(--danger);  }
.status.success { color: var(--success); }
.muted          { color: var(--muted); font-style: italic; }

/* ── Student photo thumbnails ── */
.student-thumb {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  object-fit: cover;
  border: 1px solid var(--border);
  display: block;
}

.student-thumb-placeholder {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  background: var(--primary);
  color: white;
  font-weight: 700;
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ── Student type badges ── */
.type-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
}

.type-school         { background: #dbeafe; color: #1d4ed8; }
.type-daycare        { background: #fef9c3; color: #854d0e; }
.type-day-and-school { background: #ede9fe; color: #6d28d9; }

/* ── Responsive ── */
@media (max-width: 680px) {
  .toolbar { flex-direction: column; align-items: flex-start; }
  .panel-header { flex-direction: column; }
  .log-controls { flex-direction: column; align-items: stretch; }
}
