:root {
  --bg: #f5f7fb;
  --panel: #ffffff;
  --text: #111827;
  --muted: #6b7280;
  --line: #dfe4ec;
  --accent: #2563eb;
  --accent-dark: #1d4ed8;
  --danger: #dc2626;
  --ok: #047857;
  --shadow: 0 16px 40px rgba(15, 23, 42, 0.08);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  padding: 14px clamp(16px, 4vw, 48px);
  background: rgba(255, 255, 255, 0.92);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(14px);
}

a { color: inherit; text-decoration: none; }
.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  min-width: 0;
  line-height: 1.15;
}
.brand img {
  width: 57px;
  height: 57px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid #fff;
  box-shadow: 0 6px 16px rgba(15, 23, 42, .12);
}
.brand-title {
  max-width: min(620px, 70vw);
}
.brand-title span {
  display: block;
}
.topbar-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
}
.header-lookup {
  display: flex;
  gap: 8px;
  align-items: center;
}
.header-lookup input {
  width: 170px;
  min-height: 38px;
  text-transform: uppercase;
}
.header-lookup button {
  min-height: 38px;
  padding: 8px 12px;
}
.topbar-actions .message {
  max-width: 220px;
  margin: 0;
  font-size: 13px;
}
.nav-form { margin: 0; }
.nav-form button {
  min-height: auto;
  padding: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
}
.nav-form button:hover { background: transparent; color: var(--text); }
main { width: min(1120px, calc(100% - 32px)); margin: 28px auto 56px; }
.site-footer {
  width: min(1120px, calc(100% - 32px));
  margin: -24px auto 32px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 14px;
  text-align: center;
}
.site-footer a {
  color: var(--accent-dark);
  font-weight: 800;
}

.admin-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 24px;
  align-items: stretch;
  margin-bottom: 24px;
}

.admin-head, .panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.panel, .admin-head { padding: 24px; }
h1, h2, h3, p { margin-top: 0; }
h1 { font-size: clamp(30px, 5vw, 52px); line-height: 1.02; margin-bottom: 14px; letter-spacing: 0; }
h2 { font-size: 22px; margin-bottom: 16px; }
h3 { font-size: 18px; margin-bottom: 6px; }
.eyebrow { color: var(--accent); font-weight: 800; text-transform: uppercase; font-size: 12px; letter-spacing: .08em; margin-bottom: 10px; }
.muted, .section-title p, .slot-admin-item p, .message { color: var(--muted); }

.form-head, .table-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  margin-bottom: 20px;
}

.grid.two, .admin-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.person-sections {
  display: grid;
  gap: 14px;
  margin-bottom: 18px;
}

.profile-choice {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 240px;
  gap: 14px;
  align-items: end;
  margin-bottom: 30px;
  padding: 18px;
  border-radius: 8px;
  border: 1px solid #bfdbfe;
  background: #eff6ff;
}

.profile-choice label {
  font-size: 16px;
}

.profile-choice select {
  min-height: 64px;
  padding: 14px 16px;
  font-size: 16px;
  font-weight: 700;
  line-height: 1.25;
  border-color: #93c5fd;
}

.person-section {
  padding: 16px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  border-radius: 8px;
  background: #fbfcff;
}

.person-section-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}

.person-section-head span {
  display: inline-grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 999px;
  background: #eff6ff;
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 900;
}

.person-section-head h3 {
  margin: 0;
}

label, .stack { display: grid; gap: 8px; }
label { font-weight: 700; font-size: 14px; }
.health-group-field { margin-top: 14px; }
.profile-choice .health-group-field { margin-top: 0; }
.health-group-field[hidden] { display: none !important; }
input, select {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  font: inherit;
  background: #fff;
}
input:focus, select:focus { outline: 3px solid rgba(37, 99, 235, .15); border-color: var(--accent); }
input[type="number"] {
  appearance: textfield;
  -moz-appearance: textfield;
}
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
.invalid { border-color: var(--danger) !important; background: #fff7f7; }

button, .button {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  padding: 10px 16px;
  background: var(--accent);
  color: #fff;
  font-weight: 800;
  cursor: pointer;
}
button:hover, .button:hover { background: var(--accent-dark); }
.ghost { background: #eef2ff; color: var(--accent-dark); }
.ghost:hover { background: #dbe4ff; }
.danger { background: var(--danger); }
.danger-text { color: var(--danger); background: #fee2e2; }

.inline-form { display: flex; gap: 10px; }
.section-title { margin: 26px 0 12px; }
.subjects { display: grid; gap: 10px; }
.subject-row {
  display: grid;
  grid-template-columns: minmax(130px, 1fr) minmax(120px, 160px) minmax(110px, 130px);
  gap: 10px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcff;
}
.extra-subjects { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 14px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  font-weight: 700;
}
.chip input { width: auto; min-height: auto; }
.chip.selected { border-color: var(--accent); background: #eff6ff; color: var(--accent-dark); }

.slot-picker {
  display: grid;
  gap: 16px;
}
.slot-day h4 { margin: 0 0 10px; }
.slot-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(118px, 1fr));
  gap: 10px;
}
.slot-button {
  background: #fff;
  color: var(--text);
  border: 1px solid var(--line);
  font-weight: 800;
}
.slot-button.selected { border-color: var(--accent); background: #eff6ff; color: var(--accent-dark); }
.slot-button.busy { color: #9ca3af; background: #f3f4f6; cursor: not-allowed; }

.actions { display: flex; gap: 14px; align-items: center; margin-top: 24px; }
.field-error { min-height: 18px; color: var(--danger); font-size: 13px; margin: 6px 0 0; }
.message.ok { color: var(--ok); }
.message.error { color: var(--danger); }

.modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(17, 24, 39, .45);
  z-index: 20;
}
.modal[hidden] { display: none; }
.modal-card {
  width: min(420px, 100%);
  border-radius: 8px;
  background: #fff;
  padding: 26px;
  box-shadow: var(--shadow);
  text-align: center;
}
.code {
  margin: 14px 0 20px;
  padding: 14px;
  border-radius: 8px;
  background: #f3f6fb;
  font-size: 34px;
  font-weight: 900;
  letter-spacing: .12em;
}
.success-note {
  margin: -4px 0 20px;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.55;
}

.admin-head { grid-template-columns: 1fr auto; align-items: center; }
.admin-grid { margin-bottom: 24px; }
.login-shell {
  min-height: calc(100vh - 150px);
  display: grid;
  place-items: center;
}
.login-card {
  width: min(440px, 100%);
}
.login-logo {
  width: 86px;
  height: 86px;
  border-radius: 22px;
  object-fit: cover;
  margin-bottom: 16px;
  border: 1px solid var(--line);
}
.login-card h1 {
  font-size: 34px;
}
.checkline { display: flex; align-items: center; }
.checkline input { width: auto; min-height: auto; }
.slot-admin-list { display: grid; gap: 10px; max-height: 460px; overflow: auto; }
.slot-admin-item {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}
.slot-admin-item.busy { background: #f8fafc; }
.profile-pill {
  display: inline-flex;
  margin-left: 8px;
  padding: 3px 8px;
  border-radius: 999px;
  background: #eef2ff;
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 800;
}
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 860px; }
th, td { padding: 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { font-size: 13px; color: var(--muted); }
td span { color: var(--muted); font-size: 13px; }
.mini { display: block; }

@media (max-width: 760px) {
  .topbar { align-items: flex-start; flex-direction: column; }
  .brand-title { max-width: calc(100vw - 100px); }
  .topbar-actions, .header-lookup { width: 100%; }
  .topbar-actions { align-items: stretch; flex-direction: column; }
  .header-lookup input { width: 100%; }
  main { width: min(100% - 20px, 1120px); margin-top: 14px; }
  .admin-head, .admin-grid, .grid.two { grid-template-columns: 1fr; }
  .profile-choice { grid-template-columns: 1fr; padding: 14px; }
  .panel, .admin-head { padding: 18px; }
  .inline-form, .actions, .form-head, .slot-admin-item { flex-direction: column; align-items: stretch; }
  .subject-row { grid-template-columns: 1fr; }
  .slot-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
