:root {
  --bg: #f8fafc;
  --surface: #ffffff;
  --primary: #2563eb;
  --secondary: #0f172a;
  --success: #16a34a;
  --danger: #dc2626;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #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: 1100px;
  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);
}

.optional {
  font-size: 0.85rem;
  color: var(--muted);
  font-weight: 400;
}

.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: 12px 18px;
  cursor: pointer;
  white-space: nowrap;
}

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

button.secondary {
  background: #e2e8f0;
  color: var(--secondary);
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

button.icon-button {
  width: 30px;
  height: 30px;
  min-width: 30px;
  padding: 0;
  border-radius: 8px;
  background: #f8fafc;
  color: var(--secondary);
  border: 1px solid transparent;
  transition: background 120ms ease, border-color 120ms ease;
}

button.icon-button:hover {
  background: rgba(37, 99, 235, 0.12);
  border-color: rgba(37, 99, 235, 0.22);
}

button.icon-button.danger-hover:hover {
  background: rgba(220, 38, 38, 0.1);
  border-color: rgba(220, 38, 38, 0.22);
  color: var(--danger);
}

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

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

/* ── 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;
}

.school-label-group {
  display: flex;
  flex-direction: column;
  line-height: 1.3;
}

.school-label {
  font-size: 0.78rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.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: center;
  margin-bottom: 18px;
}

.panel-header h2 {
  margin: 0;
}

/* ── Add form panel ── */
.add-form-panel {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px;
  margin-bottom: 18px;
}

.add-form-panel h3 {
  margin: 0 0 16px;
  font-size: 1rem;
}

.form-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 4px;
}

/* ── List ── */
.list {
  display: grid;
  gap: 14px;
}

/* ── Data Table ── */
.table-wrapper {
  overflow-x: auto;
}

.data-table {
  width: 100%;
  min-width: max-content;
  border-collapse: collapse;
  table-layout: auto;
}

.data-table th,
.data-table td {
  border: 1px solid var(--border);
  padding: 8px 12px;
  text-align: left;
  vertical-align: middle;
  white-space: nowrap;
}

.data-table th {
  background: #f1f5f9;
  font-size: 0.875rem;
  font-weight: 600;
}

.data-table .table-actions {
  display: flex;
  gap: 6px;
  align-items: center;
  justify-content: center;
}

.data-table td:last-child {
  text-align: center;
}

/* ── Inline edit row ── */
.inline-form-row td {
  padding: 0;
  border-top: none;
}

.inline-panel {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px 20px;
  margin: 6px 0;
}

.inline-panel h4 {
  margin: 0 0 14px;
  font-size: 0.95rem;
}

.inline-panel label {
  font-weight: 400;
}

.inline-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 12px;
}

.inline-status {
  margin-top: 10px;
  font-size: 0.9rem;
}

/* ── School picker ── */
.picker-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}

.picker-header h2 {
  margin: 0;
}

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

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

.school-pick-card h3 {
  margin: 0 0 4px;
}

.school-pick-card p {
  margin: 0;
  font-size: 0.875rem;
  color: var(--muted);
}

.school-pick-card button {
  margin-top: 12px;
  align-self: flex-start;
}

.status-badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 99px;
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.status-badge.active {
  background: #dcfce7;
  color: #15803d;
}

.status-badge.inactive {
  background: #f1f5f9;
  color: var(--muted);
}

/* ── Dashboard ── */
.dashboard-grid {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

.dashboard-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 20px;
}

.dashboard-card h3 {
  margin: 0 0 10px;
  font-size: 0.95rem;
  color: var(--muted);
  font-weight: 500;
}

.dashboard-card p {
  margin: 0;
  font-size: 2rem;
  font-weight: 700;
  color: var(--text);
}

.dashboard-card .sub {
  font-size: 0.8rem;
  font-weight: 400;
  color: var(--muted);
}

/* ── Live Presence ── */
.presence-date {
  margin: 2px 0 0;
  font-size: 0.875rem;
  color: var(--muted);
}

.presence-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}

.presence-card {
  border-radius: 14px;
  padding: 18px 20px;
  border: 1px solid transparent;
}

.presence-card.in-school   { background: #dcfce7; border-color: #bbf7d0; }
.presence-card.exited      { background: #dbeafe; border-color: #bfdbfe; }
.presence-card.not-in      { background: #fef9c3; border-color: #fde68a; }
.presence-card.not-arrived { background: #f1f5f9; border-color: var(--border); }
.presence-card.total       { background: #ffffff; border-color: var(--border); }

.pc-value {
  margin: 0 0 4px;
  font-size: 2.2rem;
  font-weight: 700;
  line-height: 1;
}

.pc-label {
  margin: 0;
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.presence-card.in-school   .pc-value { color: var(--success); }
.presence-card.exited      .pc-value { color: #1d4ed8; }
.presence-card.not-in      .pc-value { color: #854d0e; }
.presence-card.not-arrived .pc-value { color: var(--muted); }

/* ── 2-column form grid ── */
.form-grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  column-gap: 20px;
}

.form-grid-2 label {
  display: flex;
  flex-direction: column;
  font-weight: 500;
  margin-bottom: 14px;
}

.form-grid-2 label input,
.form-grid-2 label select {
  margin-top: 6px;
  width: 100%;
}

@media (max-width: 600px) {
  .form-grid-2 { grid-template-columns: 1fr; }
}

/* ── Photo upload ── */
.photo-upload-row {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-top: 6px;
  flex-wrap: wrap;
}

.photo-preview {
  width: 72px;
  height: 72px;
  border-radius: 10px;
  object-fit: cover;
  border: 1px solid var(--border);
}

.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;
}

/* ── 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;
  font-weight: 500;
}

/* ── 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);
}

/* ── Attendance action buttons (used in search panel) ── */
.btn-entry {
  background: #dcfce7;
  color: #15803d;
  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: #dbeafe;
  color: #1d4ed8;
  border: 1px solid #bfdbfe;
  border-radius: 8px;
  padding: 6px 14px;
  font-size: 0.875rem;
  font-weight: 600;
}

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

.btn-not-in {
  background: #fef9c3;
  color: #854d0e;
  border: 1px solid #fde68a;
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
}
.btn-not-in:hover:not(:disabled) { background: #fde68a; }

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

/* ── Not-In reason modal ── */
.not-in-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.45);
  display: flex; align-items: center; justify-content: center;
  z-index: 9999;
}
.not-in-dialog {
  background: #fff;
  border-radius: 12px;
  padding: 24px;
  width: min(420px, 92vw);
  box-shadow: 0 8px 32px rgba(0,0,0,0.18);
  display: flex; flex-direction: column; gap: 14px;
}
.not-in-dialog h3 { margin: 0; font-size: 1rem; color: #1e293b; }
.not-in-dialog p  { margin: 0; font-size: 0.85rem; color: var(--muted); }
.not-in-dialog textarea {
  width: 100%; box-sizing: border-box;
  border: 1px solid #e2e8f0; border-radius: 8px;
  padding: 8px 10px; font-size: 0.9rem;
  resize: vertical; min-height: 80px;
  font-family: inherit;
}
.not-in-dialog textarea:focus { outline: none; border-color: #f59e0b; }
.not-in-dialog-actions { display: flex; gap: 10px; justify-content: flex-end; }

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

.chip-absent  { background: #f1f5f9; color: var(--muted); }
.chip-entry   { background: #dcfce7; color: #15803d; }
.chip-exited  { background: #dbeafe; color: #1d4ed8; }
.chip-not-in  { background: #fef9c3; color: #854d0e; }

/* ── School Pickup Subsection ── */
.school-pickup-subsection {
  margin-top: 28px;
  border-top: 2px solid #fde68a;
  padding-top: 18px;
}

.subsection-header {
  margin-bottom: 12px;
}

.subsection-title {
  margin: 0 0 4px;
  font-size: 1rem;
  font-weight: 600;
  color: #92400e;
}

.subsection-note {
  margin: 0;
  font-size: 0.85rem;
}

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

.status.error {
  color: var(--danger);
}

.status.success {
  color: var(--success);
}

.muted {
  color: var(--muted);
  font-style: italic;
}

/* ── Radio group ── */
.field-label {
  display: block;
  font-weight: 500;
  margin-bottom: 8px;
}

.radio-group {
  display: flex;
  gap: 20px;
  flex-wrap: wrap;
  margin-bottom: 4px;
}

.radio-option {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 400;
  margin-bottom: 0;
  cursor: pointer;
}

.radio-option input[type="radio"] {
  width: auto;
  margin: 0;
  padding: 0;
  cursor: pointer;
}

/* Span full width inside form-grid-2 */
.form-span-2 {
  grid-column: 1 / -1;
  margin-bottom: 14px;
}

/* ── 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; }

/* ── Inactive student row ── */
.inactive-student-row { opacity: 0.55; }

/* ── Table filter row ── */
.filter-row th {
  background: #f8fafc;
  padding: 6px 8px;
}

.filter-row input,
.filter-row select {
  width: 100%;
  padding: 5px 8px;
  margin: 0;
  font-size: 0.8rem;
  border-radius: 6px;
  border: 1px solid var(--border);
}

/* ── Student Edit Modal ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-box {
  background: var(--surface);
  border-radius: 18px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.25);
  width: 100%;
  max-width: 680px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 18px 24px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.modal-header h3 {
  margin: 0;
  font-size: 1.1rem;
}

.modal-body {
  padding: 20px 24px;
  overflow-y: auto;
  flex: 1;
}

.modal-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 16px;
}

/* ── Responsive ── */
@media (max-width: 760px) {
  .toolbar {
    flex-direction: column;
    align-items: flex-start;
  }

  .panel-header {
    flex-wrap: wrap;
    gap: 10px;
  }

  .modal-box {
    max-height: 95vh;
  }
}
