/* ===== Base ===== */
:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --ink: #15161b;
  --ink-2: #4a4d57;
  --ink-3: #7e8290;
  --line: #e7e5dd;
  --line-2: #d8d6cd;
  --accent: oklch(0.55 0.18 265);
  --accent-soft: oklch(0.95 0.04 265);
  --accent-deep: oklch(0.42 0.18 265);
  --boy: oklch(0.62 0.13 240);
  --girl: oklch(0.66 0.14 8);
  --boy-soft: oklch(0.96 0.03 240);
  --girl-soft: oklch(0.96 0.03 8);
  --good: oklch(0.65 0.13 155);
  --warn: oklch(0.72 0.15 65);
  --bad: oklch(0.62 0.18 25);
  --radius: 16px;
  --radius-sm: 10px;
  --shadow-sm: 0 1px 2px rgba(20,22,30,.05), 0 0 0 1px rgba(20,22,30,.04);
  --shadow-md: 0 4px 16px rgba(20,22,30,.08), 0 0 0 1px rgba(20,22,30,.04);
  --shadow-lg: 0 24px 60px -16px rgba(20,22,30,.18), 0 0 0 1px rgba(20,22,30,.05);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'IBM Plex Sans Thai', 'Sarabun', system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input { font-family: inherit; }

/* ===== Admin lock button on mobile top-bar ===== */
.admin-lock {
  width: 36px; height: 36px;
  border-radius: 50%;
  display: grid; place-items: center;
  background: var(--bg);
  border: 1px solid var(--line);
  color: var(--ink-2);
  transition: all .15s ease;
  cursor: pointer;
}
.admin-lock:hover {
  background: var(--ink);
  color: white;
  border-color: var(--ink);
  transform: rotate(-6deg);
}

/* ===== Admin gate ===== */
.gate-shell {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(800px 500px at 20% 0%, oklch(0.95 0.04 265 / 0.7), transparent 60%),
    radial-gradient(700px 400px at 100% 100%, oklch(0.95 0.04 30 / 0.5), transparent 60%),
    var(--bg);
  display: grid; place-items: center;
  z-index: 50;
  padding: 20px;
}
.gate-close {
  position: absolute;
  top: 20px; right: 20px;
  width: 40px; height: 40px;
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--line);
  display: grid; place-items: center;
  transition: all .15s ease;
}
.gate-close:hover { background: var(--ink); color: white; }
.gate-card {
  background: var(--surface);
  padding: 40px 36px;
  border-radius: 24px;
  box-shadow: var(--shadow-lg);
  max-width: 380px;
  width: 100%;
  text-align: center;
  animation: pop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.gate-card.shake { animation: shake 0.4s ease; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-8px); }
  40%, 80% { transform: translateX(8px); }
}
.gate-icon {
  width: 64px; height: 64px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent-deep);
  display: grid; place-items: center;
  margin: 0 auto 20px;
}
.gate-icon svg { width: 28px; height: 28px; }
.gate-title { font-size: 22px; font-weight: 700; }
.gate-sub { font-size: 14px; color: var(--ink-2); margin: 6px 0 24px; }
.gate-input {
  width: 100%;
  padding: 14px 16px;
  border-radius: 12px;
  border: 1.5px solid var(--line);
  font-size: 18px;
  text-align: center;
  letter-spacing: 0.2em;
  background: var(--bg);
  outline: none;
  transition: border-color .15s ease;
}
.gate-input:focus { border-color: var(--accent); background: var(--surface); }
.gate-input.err { border-color: var(--bad); background: oklch(0.97 0.04 25); }
.gate-err {
  color: var(--bad);
  font-size: 12px;
  margin-top: 6px;
  text-align: left;
}
.gate-hint {
  margin-top: 16px;
  font-size: 11px;
  color: var(--ink-3);
}

/* ===== Modal (edit / class dialog) ===== */
.modal-shade {
  position: fixed; inset: 0;
  background: rgba(15,17,23,0.6);
  backdrop-filter: blur(4px);
  display: grid; place-items: center;
  z-index: 60;
  padding: 20px;
  animation: fade 0.2s ease;
}
.modal {
  background: var(--surface);
  border-radius: 20px;
  max-width: 520px;
  width: 100%;
  max-height: 90vh;
  display: flex; flex-direction: column;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  animation: pop 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.modal-header {
  padding: 18px 22px;
  border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px;
}
.modal-body {
  padding: 20px 22px;
  overflow-y: auto;
  flex: 1;
}
.modal-foot {
  padding: 14px 22px;
  border-top: 1px solid var(--line);
  display: flex; justify-content: flex-end; gap: 8px;
  background: var(--bg);
}

/* form fields inside modal */
.form-fields {
  display: flex; flex-direction: column; gap: 14px;
}
.ff-row {
  display: flex; flex-direction: column; gap: 6px;
}
.ff-row .ff-lbl {
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-2);
  letter-spacing: 0.02em;
}
.ff-input {
  padding: 10px 12px;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  font-size: 14px;
  background: var(--bg);
  outline: none;
  transition: border-color .15s ease;
  font-family: inherit;
}
.ff-input:focus { border-color: var(--accent); background: var(--surface); }
.ff-input:disabled { opacity: 0.6; cursor: not-allowed; }

/* date input */
.date-input {
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 13px;
  background: var(--surface);
  font-family: inherit;
  cursor: pointer;
  color: var(--ink);
}
.date-input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

/* Date strip (history mini calendar) */
.date-strip {
  display: flex;
  gap: 8px;
  padding: 14px 20px;
  overflow-x: auto;
  border-bottom: 1px solid var(--line);
}
.date-pill {
  min-width: 60px;
  padding: 8px 4px;
  border-radius: 12px;
  background: var(--bg);
  border: 1px solid var(--line);
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  transition: all .15s ease;
  font-size: 11px;
  color: var(--ink-3);
  flex-shrink: 0;
  cursor: pointer;
}
.date-pill:hover { border-color: var(--ink-3); color: var(--ink); }
.date-pill.active {
  background: var(--ink);
  color: white;
  border-color: var(--ink);
}
.date-pill .dp-day { font-size: 20px; font-weight: 700; color: inherit; }
.date-pill .dp-wd { font-size: 10px; opacity: 0.7; }
.date-pill .dp-count { font-size: 10px; margin-top: 2px; font-weight: 600; }
.date-pill.active .dp-count { color: oklch(0.85 0.13 155); }

/* Row actions in tables */
.row-action {
  width: 30px; height: 30px;
  border-radius: 8px;
  display: inline-grid; place-items: center;
  background: transparent;
  color: var(--ink-3);
  transition: all .15s ease;
  margin-left: 4px;
}
.row-action:hover { background: var(--accent-soft); color: var(--accent-deep); }
.row-action.danger:hover { background: oklch(0.96 0.05 25); color: var(--bad); }

/* Group header inside data-table */
.group-header {
  padding: 14px 20px 6px;
  font-size: 13px;
  font-weight: 700;
  color: var(--ink);
  letter-spacing: 0.02em;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}

/* Month grid (calendar in monthly view) */
.month-grid {
  padding: 0 20px 20px;
}
.mg-row { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.mg-head { margin-bottom: 6px; }
.mg-head-cell {
  padding: 8px 0;
  font-size: 11px;
  font-weight: 600;
  color: var(--ink-3);
  text-align: center;
  letter-spacing: 0.04em;
}
.mg-body {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
}
.mg-cell {
  aspect-ratio: 1.4 / 1;
  border-radius: 10px;
  background: var(--bg);
  padding: 6px 8px;
  display: flex; flex-direction: column;
  border: 1px solid var(--line);
  position: relative;
}
.mg-cell.weekend { opacity: 0.5; }
.mg-cell.has-data {
  background: linear-gradient(180deg, oklch(0.97 0.04 155 / 0.4), transparent);
  border-color: oklch(0.65 0.13 155 / 0.3);
}
.mg-cell .mg-day {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
}
.mg-cell.has-data .mg-day { color: var(--good); }
.mg-cell .mg-count {
  font-size: 10px;
  color: var(--ink-3);
  margin-top: auto;
  font-weight: 600;
}
.mg-cell.has-data .mg-count { color: var(--good); }

/* Danger nav item in admin sidebar */
.admin-side .as-item.danger {
  color: oklch(0.72 0.15 25);
}
.admin-side .as-item.danger:hover {
  background: oklch(0.62 0.18 25 / 0.15);
  color: oklch(0.85 0.15 25);
}

/* ===== Class dropdown (mobile teacher) ===== */
.class-dropdown {
  position: relative;
}
.cd-trigger {
  width: 100%;
  background: var(--surface);
  border: 1.5px solid var(--line);
  border-radius: 16px;
  padding: 16px 18px;
  display: flex; align-items: center;
  gap: 12px;
  cursor: pointer;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.cd-trigger:hover { border-color: var(--ink-3); }
.cd-trigger.open {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft);
}
.cd-eyebrow {
  font-size: 11px;
  color: var(--ink-3);
  font-weight: 600;
  letter-spacing: 0.04em;
}
.cd-selected {
  font-size: 18px;
  font-weight: 700;
  color: var(--ink);
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.cd-placeholder {
  font-size: 15px;
  color: var(--ink-3);
  margin-top: 2px;
}
.cd-caret {
  font-size: 18px;
  color: var(--ink-3);
  transition: transform .2s ease;
}
.cd-caret.open { transform: rotate(180deg); color: var(--accent); }

.cd-menu {
  position: absolute;
  top: calc(100% + 8px);
  left: 0; right: 0;
  background: var(--surface);
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--line);
  max-height: 360px;
  overflow-y: auto;
  z-index: 20;
  padding: 6px;
  animation: cd-pop 0.18s cubic-bezier(0.34, 1.2, 0.64, 1);
}
@keyframes cd-pop {
  from { opacity: 0; transform: translateY(-6px) scale(0.98); }
  to { opacity: 1; transform: none; }
}
.cd-group {
  padding: 10px 12px 4px;
  font-size: 10px;
  font-weight: 700;
  color: var(--ink-3);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.cd-item {
  width: 100%;
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px;
  border-radius: 10px;
  text-align: left;
  transition: background .12s ease;
  cursor: pointer;
}
.cd-item:hover { background: var(--bg); }
.cd-item.active { background: var(--accent-soft); }
.cd-item-main { flex: 1; min-width: 0; }
.cd-item-level { font-size: 14px; font-weight: 600; color: var(--ink); }
.cd-item-meta { font-size: 11px; color: var(--ink-3); margin-top: 2px; }
.cd-item-tag {
  font-size: 10px;
  padding: 3px 8px;
  border-radius: 999px;
  font-weight: 600;
  background: var(--bg);
  color: var(--ink-3);
  border: 1px solid var(--line);
  white-space: nowrap;
}
.cd-item-tag.ok {
  background: var(--good);
  color: white;
  border-color: transparent;
}

/* Selected class big card under dropdown */
.selected-card {
  background: linear-gradient(180deg, var(--ink) 0%, oklch(0.22 0.04 265) 100%);
  color: white;
  border-radius: 18px;
  padding: 18px;
  position: relative;
  overflow: hidden;
}
.selected-card::before {
  content: "";
  position: absolute;
  top: -60px; right: -60px;
  width: 200px; height: 200px;
  background: radial-gradient(closest-side, var(--accent), transparent);
  opacity: 0.5;
  filter: blur(10px);
}
.sc-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
  position: relative;
}
.sc-stat {
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.14);
  border-radius: 12px;
  padding: 10px 12px;
}
.sc-lbl { font-size: 11px; opacity: 0.7; }
.sc-val { font-size: 20px; font-weight: 700; letter-spacing: -0.02em; margin-top: 2px; }
.sc-val small { font-size: 11px; font-weight: 500; opacity: 0.6; margin-left: 2px; }
.sc-note {
  margin-top: 12px;
  padding: 8px 12px;
  background: rgba(255,255,255,0.1);
  border-radius: 10px;
  font-size: 12px;
  display: flex; align-items: center; gap: 8px;
  position: relative;
}

/* ===== Mobile teacher hero (logo + school) ===== */
.m-hero {
  display: flex;
  gap: 14px;
  align-items: center;
  background: var(--surface);
  padding: 16px;
  border-radius: 18px;
  border: 1px solid var(--line);
  box-shadow: var(--shadow-sm);
}
.m-hero-logo {
  width: 64px; height: 64px;
  object-fit: contain;
  flex-shrink: 0;
}
.m-hero-text { flex: 1; min-width: 0; }
.m-hero-school {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.25;
}
.m-hero-district {
  font-size: 12px;
  color: var(--ink-3);
  margin-top: 2px;
}
.m-logo {
  width: 36px; height: 36px;
  object-fit: contain;
  flex-shrink: 0;
}

/* ===== Admin sidebar logo ===== */
.admin-side .as-brand {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  font-size: 14px; font-weight: 700; line-height: 1.3;
  padding: 4px 8px 20px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
  margin-bottom: 12px;
}
.admin-side .as-logo {
  width: 38px; height: 38px;
  object-fit: contain;
  border-radius: 8px;
  background: white;
  padding: 2px;
  flex-shrink: 0;
}
.admin-side .as-brand-name { font-size: 13px; font-weight: 700; line-height: 1.25; }

/* ===== Print sheet logo row ===== */
.print-logo-row {
  display: flex;
  justify-content: center;
  margin-bottom: 4mm;
}
.print-logo {
  width: 18mm; height: 18mm;
  object-fit: contain;
}

/* ===== System Settings ===== */
.settings-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
}
@media (max-width: 1200px) { .settings-grid { grid-template-columns: 1fr; } }

.settings-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.settings-card.danger {
  border-color: oklch(0.62 0.18 25 / 0.4);
  background: oklch(0.99 0.01 25);
}
.settings-card .sc-h {
  padding: 18px 20px 12px;
  border-bottom: 1px solid var(--line);
}
.settings-card .sc-title {
  font-size: 15px;
  font-weight: 700;
}
.settings-card .sc-subtitle {
  font-size: 12px;
  color: var(--ink-3);
  margin-top: 4px;
  line-height: 1.5;
}
.settings-card .sc-body {
  padding: 18px 20px;
  display: flex; flex-direction: column;
  gap: 14px;
}

.setting-row {
  display: grid;
  grid-template-columns: 200px 1fr;
  gap: 14px;
  align-items: center;
}
.setting-lbl {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-2);
}
.setting-control input.ff-input { width: 100%; }
@media (max-width: 720px) {
  .setting-row { grid-template-columns: 1fr; gap: 6px; }
}

.duty-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}
@media (max-width: 720px) { .duty-grid { grid-template-columns: 1fr; } }
.duty-grid .setting-row {
  grid-template-columns: 110px 1fr;
}

/* Logo upload */
.logo-upload {
  display: flex;
  gap: 14px;
  align-items: center;
  padding: 12px;
  background: var(--bg);
  border-radius: 10px;
  border: 1px dashed var(--line-2);
}
.logo-thumb {
  width: 64px; height: 64px;
  object-fit: contain;
  background: white;
  border-radius: 8px;
  padding: 4px;
  flex-shrink: 0;
}

/* Toggle */
.toggle {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
  cursor: pointer;
}
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute; inset: 0;
  background: var(--line-2);
  border-radius: 999px;
  transition: background .2s ease;
}
.toggle-slider::before {
  content: "";
  position: absolute;
  height: 18px; width: 18px;
  left: 3px; top: 3px;
  background: white;
  border-radius: 50%;
  transition: transform .2s ease;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
.toggle input:checked + .toggle-slider { background: var(--accent); }
.toggle input:checked + .toggle-slider::before { transform: translateX(20px); }

/* Danger pill (admin nav) */
.btn-pill.danger {
  color: oklch(0.55 0.18 25);
  border-color: oklch(0.62 0.18 25 / 0.3);
}
.btn-pill.danger:hover {
  background: oklch(0.96 0.05 25);
  border-color: oklch(0.62 0.18 25 / 0.6);
  color: oklch(0.45 0.18 25);
}
.btn-pill.danger-solid {
  background: oklch(0.62 0.18 25);
  color: white;
  border-color: oklch(0.62 0.18 25);
  align-self: flex-start;
}
.btn-pill.danger-solid:hover {
  background: oklch(0.55 0.2 25);
  color: white;
  border-color: oklch(0.55 0.2 25);
}

/* ===== Role chooser (legacy — kept for safety) ===== */
.role-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 32px 20px;
  background:
    radial-gradient(900px 500px at 20% 0%, oklch(0.95 0.04 265 / 0.7), transparent 60%),
    radial-gradient(700px 400px at 100% 100%, oklch(0.95 0.04 30 / 0.5), transparent 60%),
    var(--bg);
}
.role-card {
  width: 100%;
  max-width: 880px;
  background: var(--surface);
  border-radius: 28px;
  padding: 48px 40px;
  box-shadow: var(--shadow-lg);
  position: relative;
  overflow: hidden;
}
.role-card::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, transparent, transparent 92%, var(--line) 92%);
  pointer-events: none;
}
.role-eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: var(--ink-3);
  font-weight: 500;
  letter-spacing: 0.04em;
}
.role-eyebrow .dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft);
}
.role-title {
  font-size: 36px;
  font-weight: 700;
  line-height: 1.15;
  margin: 16px 0 8px;
  letter-spacing: -0.01em;
}
.role-sub {
  font-size: 16px;
  color: var(--ink-2);
  margin-bottom: 36px;
  max-width: 540px;
}
.role-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
.role-option {
  text-align: left;
  background: var(--bg);
  border-radius: 20px;
  padding: 24px;
  border: 1.5px solid var(--line);
  transition: transform .2s ease, border-color .2s ease, box-shadow .2s ease, background .2s ease;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 200px;
}
.role-option:hover {
  transform: translateY(-2px);
  border-color: var(--accent);
  box-shadow: var(--shadow-md);
  background: var(--surface);
}
.role-option .ro-icon {
  width: 44px; height: 44px;
  border-radius: 12px;
  display: grid; place-items: center;
  background: var(--accent-soft);
  color: var(--accent-deep);
}
.role-option .ro-title { font-size: 20px; font-weight: 600; }
.role-option .ro-desc { font-size: 14px; color: var(--ink-2); line-height: 1.5; flex: 1; }
.role-option .ro-cta {
  font-size: 13px;
  font-weight: 600;
  color: var(--accent-deep);
  display: inline-flex; align-items: center; gap: 4px;
}

@media (max-width: 700px) {
  .role-grid { grid-template-columns: 1fr; }
  .role-card { padding: 32px 24px; }
  .role-title { font-size: 28px; }
}

/* ===== Mobile teacher shell ===== */
.mobile-shell {
  min-height: 100vh;
  background: var(--bg);
  max-width: 460px;
  margin: 0 auto;
  position: relative;
  display: flex;
  flex-direction: column;
  box-shadow: 0 0 0 1px var(--line);
}
@media (min-width: 720px) {
  .mobile-shell { margin-top: 24px; margin-bottom: 24px; min-height: calc(100vh - 48px); border-radius: 28px; overflow: hidden; }
}

.m-topbar {
  padding: 18px 20px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5;
}
.m-topbar .school {
  font-size: 13px; font-weight: 600; color: var(--ink);
}
.m-topbar .meta {
  font-size: 11px; color: var(--ink-3); margin-top: 2px;
}
.m-topbar .pill {
  margin-left: auto;
  font-size: 11px;
  padding: 5px 10px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-deep);
  font-weight: 600;
}
.m-back {
  width: 36px; height: 36px;
  border-radius: 50%;
  display: grid; place-items: center;
  background: var(--bg);
  border: 1px solid var(--line);
  transition: background .15s ease;
}
.m-back:hover { background: var(--accent-soft); }

.m-body {
  padding: 20px;
  flex: 1;
  display: flex; flex-direction: column;
  gap: 16px;
}

.m-title { font-size: 22px; font-weight: 700; letter-spacing: -0.01em; }
.m-sub { font-size: 13px; color: var(--ink-2); margin-top: -8px; }

/* class chooser */
.group-tabs {
  display: flex;
  gap: 6px;
  background: var(--surface);
  padding: 6px;
  border-radius: 14px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 4px;
}
.group-tab {
  flex: 1;
  padding: 10px 8px;
  font-size: 13px;
  border-radius: 10px;
  font-weight: 600;
  color: var(--ink-3);
  transition: all .2s ease;
  white-space: nowrap;
}
.group-tab.active { background: var(--ink); color: var(--surface); }

.class-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.class-chip {
  background: var(--surface);
  border-radius: 14px;
  padding: 14px;
  text-align: left;
  border: 1.5px solid var(--line);
  transition: transform .15s ease, border-color .15s ease, box-shadow .15s ease;
  position: relative;
  overflow: hidden;
}
.class-chip::after {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(120px 80px at var(--mx,50%) var(--my,50%), var(--accent-soft), transparent 60%);
  opacity: 0;
  transition: opacity .2s ease;
  pointer-events: none;
}
.class-chip:hover { transform: translateY(-1px); border-color: var(--accent); box-shadow: var(--shadow-md); }
.class-chip:hover::after { opacity: 1; }
.class-chip:active { transform: scale(0.98); }
.class-chip.submitted {
  background: linear-gradient(180deg, oklch(0.97 0.03 155 / 0.5), transparent);
  border-color: oklch(0.65 0.13 155 / 0.3);
}
.class-chip .cc-level { font-size: 14px; font-weight: 600; }
.class-chip .cc-count {
  font-size: 12px; color: var(--ink-3);
  display: flex; gap: 10px; margin-top: 6px;
}
.class-chip .cc-count span b { color: var(--ink); font-weight: 600; }
.class-chip .cc-tag {
  position: absolute; top: 10px; right: 10px;
  font-size: 10px; font-weight: 600;
  padding: 2px 6px;
  border-radius: 999px;
}
.class-chip.submitted .cc-tag { background: var(--good); color: white; }
.class-chip:not(.submitted) .cc-tag { background: var(--bg); color: var(--ink-3); border: 1px solid var(--line); }

/* class summary card */
.class-summary {
  background: linear-gradient(180deg, var(--ink) 0%, oklch(0.22 0.04 265) 100%);
  color: white;
  padding: 22px;
  border-radius: 20px;
  position: relative;
  overflow: hidden;
}
.class-summary::before {
  content: "";
  position: absolute;
  top: -50px; right: -50px;
  width: 220px; height: 220px;
  background: radial-gradient(closest-side, var(--accent), transparent);
  opacity: 0.6;
  filter: blur(8px);
}
.class-summary .cs-eyebrow { font-size: 12px; opacity: 0.7; }
.class-summary .cs-title { font-size: 22px; font-weight: 700; margin-top: 4px; position: relative; }
.class-summary .cs-row { display: flex; gap: 14px; margin-top: 18px; position: relative; }
.class-summary .cs-pill {
  flex: 1;
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.14);
  backdrop-filter: blur(4px);
  border-radius: 14px;
  padding: 12px;
}
.class-summary .cs-pill .lbl { font-size: 11px; opacity: 0.7; }
.class-summary .cs-pill .num { font-size: 22px; font-weight: 700; letter-spacing: -0.02em; }
.class-summary .cs-pill .num small { font-size: 12px; font-weight: 500; opacity: 0.6; margin-left: 2px; }

/* form */
.field-group {
  background: var(--surface);
  border-radius: 18px;
  padding: 18px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.field-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 12px;
  align-items: center;
}
.field-label {
  display: flex; align-items: center; gap: 10px;
}
.field-label .icon {
  width: 36px; height: 36px;
  border-radius: 10px;
  display: grid; place-items: center;
  font-size: 18px;
}
.field-label .icon.sick { background: oklch(0.96 0.03 25); color: var(--bad); }
.field-label .icon.leave { background: oklch(0.97 0.04 65); color: var(--warn); }
.field-label .icon.absent { background: oklch(0.96 0.03 305); color: oklch(0.5 0.18 305); }
.field-label .icon.attend { background: oklch(0.95 0.05 155); color: var(--good); }
.field-label .lbl { font-size: 14px; font-weight: 600; }
.field-label .sub { font-size: 11px; color: var(--ink-3); }

.gender-input {
  display: flex; align-items: center;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  transition: border-color .15s ease;
}
.gender-input:focus-within { border-color: var(--accent); }
.gender-input .gi-label {
  padding: 8px 10px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
  background: var(--bg);
  color: var(--ink-3);
}
.gender-input.boy .gi-label { background: var(--boy-soft); color: var(--boy); }
.gender-input.girl .gi-label { background: var(--girl-soft); color: var(--girl); }
.gender-input button {
  width: 32px; height: 38px;
  font-size: 18px; font-weight: 600; color: var(--ink-2);
  transition: background .12s ease;
}
.gender-input button:hover:not(:disabled) { background: var(--bg); }
.gender-input button:disabled { opacity: 0.3; cursor: not-allowed; }
.gender-input input {
  width: 38px;
  text-align: center;
  border: none;
  background: transparent;
  font-size: 17px;
  font-weight: 600;
  padding: 8px 0;
  color: var(--ink);
  outline: none;
  appearance: textfield;
  -moz-appearance: textfield;
}
.gender-input input::-webkit-outer-spin-button,
.gender-input input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

.attend-display {
  background: oklch(0.97 0.04 155);
  border: 1.5px solid oklch(0.65 0.13 155 / 0.25);
  border-radius: 14px;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.attend-display .ad-lbl { flex: 1; font-size: 13px; color: var(--ink-2); font-weight: 600; }
.attend-display .ad-num {
  display: flex; gap: 10px;
  font-size: 16px; font-weight: 700;
}
.attend-display .ad-num .b { color: var(--boy); }
.attend-display .ad-num .g { color: var(--girl); }
.attend-display .ad-num .t {
  padding-left: 10px;
  border-left: 1px solid oklch(0.65 0.13 155 / 0.3);
  color: var(--good);
}

/* submit */
.m-bottombar {
  position: sticky; bottom: 0;
  background: linear-gradient(180deg, transparent, var(--bg) 30%);
  padding: 16px 20px 20px;
  display: flex; gap: 10px;
  z-index: 5;
}
.btn-primary {
  flex: 1;
  background: var(--ink);
  color: var(--surface);
  border-radius: 14px;
  padding: 16px;
  font-size: 15px;
  font-weight: 600;
  transition: transform .12s ease, background .15s ease;
  display: inline-flex; justify-content: center; align-items: center; gap: 8px;
  white-space: nowrap;
}
.btn-primary:hover { background: oklch(0.25 0.06 265); }
.btn-primary:active { transform: scale(0.98); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-ghost {
  background: var(--surface);
  border: 1px solid var(--line);
  padding: 16px 18px;
  border-radius: 14px;
  font-size: 14px;
  font-weight: 600;
  color: var(--ink-2);
}

/* success */
.success-shell {
  flex: 1;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 40px 24px;
  text-align: center;
}
.success-check {
  width: 88px; height: 88px;
  border-radius: 50%;
  background: var(--good);
  display: grid; place-items: center;
  position: relative;
  color: white;
  margin-bottom: 24px;
  animation: pop 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.success-check::after {
  content: "";
  position: absolute;
  inset: -10px;
  border-radius: 50%;
  border: 2px solid var(--good);
  opacity: 0;
  animation: ring 1.2s ease-out infinite;
}
@keyframes pop { from { transform: scale(0); } to { transform: scale(1); } }
@keyframes ring { 0% { transform: scale(0.9); opacity: 0.6; } 100% { transform: scale(1.4); opacity: 0; } }
.success-title { font-size: 24px; font-weight: 700; margin-bottom: 8px; }
.success-sub { font-size: 14px; color: var(--ink-2); max-width: 320px; margin-bottom: 28px; line-height: 1.5; }

.success-summary {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px;
  width: 100%;
  max-width: 380px;
  margin-bottom: 24px;
  text-align: left;
}
.success-summary .ss-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 0;
  font-size: 13px;
}
.success-summary .ss-row + .ss-row { border-top: 1px dashed var(--line); }
.success-summary .ss-row .k { color: var(--ink-2); }
.success-summary .ss-row .v { font-weight: 600; }

/* ===== Admin dashboard ===== */
.admin-shell {
  min-height: 100vh;
  background: var(--bg);
  display: grid;
  grid-template-columns: 240px 1fr;
}
@media (max-width: 900px) { .admin-shell { grid-template-columns: 1fr; } .admin-side { display: none; } }

.admin-side {
  background: var(--ink);
  color: white;
  padding: 24px 20px;
  display: flex; flex-direction: column;
  gap: 8px;
  position: sticky; top: 0; height: 100vh;
}
.admin-side .as-brand {
  font-size: 16px; font-weight: 700; line-height: 1.3;
  padding: 4px 8px 20px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
  margin-bottom: 12px;
}
.admin-side .as-brand small { display: block; font-size: 11px; font-weight: 400; opacity: 0.6; margin-top: 4px; }
.admin-side .as-item {
  text-align: left;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 14px;
  color: rgba(255,255,255,0.7);
  display: flex; align-items: center; gap: 10px;
  transition: background .15s ease, color .15s ease;
  white-space: nowrap;
}
.admin-side .as-item:hover { background: rgba(255,255,255,0.06); color: white; }
.admin-side .as-item.active { background: rgba(255,255,255,0.12); color: white; }
.admin-side .as-bottom {
  margin-top: auto;
  padding: 12px;
  font-size: 11px;
  color: rgba(255,255,255,0.5);
  line-height: 1.5;
}

.admin-main { padding: 32px 36px 80px; }
@media (max-width: 900px) { .admin-main { padding: 20px; } }

.admin-header {
  display: flex; align-items: flex-end; justify-content: space-between;
  margin-bottom: 24px;
  gap: 20px;
  flex-wrap: wrap;
}
.admin-header .ah-title { font-size: 28px; font-weight: 700; letter-spacing: -0.01em; }
.admin-header .ah-sub { font-size: 14px; color: var(--ink-2); margin-top: 6px; }

.kpi-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 24px;
}
@media (max-width: 1100px) { .kpi-row { grid-template-columns: repeat(2, 1fr); } }
.kpi {
  background: var(--surface);
  border-radius: 16px;
  padding: 18px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--line);
  position: relative;
  overflow: hidden;
}
.kpi .lbl { font-size: 12px; color: var(--ink-3); display: flex; align-items: center; gap: 6px; }
.kpi .val { font-size: 32px; font-weight: 700; margin: 6px 0 2px; letter-spacing: -0.02em; }
.kpi .delta { font-size: 12px; color: var(--ink-2); }
.kpi .delta b { color: var(--ink); font-weight: 600; }
.kpi.attend .val { color: var(--good); }
.kpi.sick .val { color: var(--bad); }
.kpi.leave .val { color: var(--warn); }
.kpi.absent .val { color: oklch(0.5 0.18 305); }

.kpi .spark {
  position: absolute;
  right: 12px; top: 12px;
  width: 36px; height: 36px;
  border-radius: 10px;
  display: grid; place-items: center;
  background: var(--accent-soft);
  color: var(--accent-deep);
}

.progress-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 20px;
  margin-bottom: 24px;
  box-shadow: var(--shadow-sm);
}
.progress-card .pc-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.progress-card .pc-row .h { font-size: 15px; font-weight: 600; }
.progress-card .pc-row .pct { font-size: 28px; font-weight: 700; letter-spacing: -0.02em; }
.progress-track {
  height: 10px;
  background: var(--bg);
  border-radius: 999px;
  overflow: hidden;
  position: relative;
}
.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-deep));
  border-radius: 999px;
  transition: width .8s cubic-bezier(0.4, 0, 0.2, 1);
}
.progress-card .pc-foot {
  margin-top: 10px;
  font-size: 12px;
  color: var(--ink-3);
  display: flex; gap: 16px;
}

.data-table {
  background: var(--surface);
  border-radius: 16px;
  border: 1px solid var(--line);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.dt-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
  display: flex; justify-content: space-between; align-items: center;
  flex-wrap: wrap; gap: 12px;
}
.dt-header .h { font-size: 16px; font-weight: 600; }
.dt-actions { display: flex; gap: 8px; }
.btn-pill {
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--bg);
  border: 1px solid var(--line);
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-2);
  display: inline-flex; align-items: center; gap: 6px;
  transition: all .15s ease;
}
.btn-pill:hover { background: var(--surface); border-color: var(--ink-3); color: var(--ink); }
.btn-pill.primary { background: var(--accent); color: white; border-color: var(--accent); }
.btn-pill.primary:hover { background: var(--accent-deep); border-color: var(--accent-deep); }

.dt-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.dt-table th, .dt-table td {
  padding: 10px 12px;
  text-align: right;
  border-bottom: 1px solid var(--line);
}
.dt-table th:first-child, .dt-table td:first-child { text-align: left; }
.dt-table thead th {
  background: var(--bg);
  font-size: 11px;
  font-weight: 600;
  color: var(--ink-3);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.dt-table tr.totals { font-weight: 700; background: var(--bg); }
.dt-table .badge {
  display: inline-block;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  font-weight: 600;
}
.dt-table .badge.ok { background: oklch(0.96 0.05 155); color: var(--good); }
.dt-table .badge.pending { background: var(--bg); color: var(--ink-3); border: 1px dashed var(--line-2); }

.dt-table tr.unsubmitted td:first-child { color: var(--ink-3); }
.dt-table tr.unsubmitted td:not(:first-child):not(:last-child) { color: var(--ink-3); font-style: italic; }

/* ===== Print sheet ===== */
.print-shell {
  background: #d9d8d2;
  min-height: 100vh;
  padding: 24px 20px;
}
.print-toolbar {
  width: 210mm;
  max-width: 100%;
  margin: 0 auto 16px;
  background: var(--surface);
  padding: 14px 18px;
  border-radius: 14px;
  display: flex; justify-content: space-between; align-items: center;
  box-shadow: var(--shadow-md);
  gap: 12px; flex-wrap: wrap;
}
.print-toolbar .pt-title { font-size: 14px; font-weight: 600; }
.print-toolbar .pt-sub { font-size: 12px; color: var(--ink-3); }

/* A4 portrait: 210mm × 297mm. We render at on-screen scale matching that. */
.print-sheet {
  background: white;
  width: 210mm;
  min-height: 297mm;
  margin: 0 auto;
  padding: 14mm 12mm;
  box-shadow: var(--shadow-lg);
  font-family: 'Sarabun', 'TH Sarabun New', serif;
  color: black;
  box-sizing: border-box;
  font-size: 11pt;
}

.print-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 10pt;
  line-height: 1.3;
}
.print-table .pt-title-row td {
  text-align: center;
  font-weight: 700;
  font-size: 12pt;
  padding: 4px 0;
  border: 1px solid black;
  border-bottom: none;
}
.print-table .pt-school td {
  text-align: center;
  font-weight: 700;
  font-size: 11pt;
  padding: 3px 0 6px;
  border: 1px solid black;
  border-top: none;
}
.print-table th, .print-table td {
  border: 1px solid black;
  padding: 2px 4px;
  text-align: center;
  vertical-align: middle;
}
.print-table th { font-weight: 600; font-size: 10pt; }
.print-table .lvl-col { width: 22%; }
.print-table td.lvl {
  text-align: center;
  white-space: nowrap;
}
.print-table tr.totals td, .print-table tr.grand td, .print-table tr.percent td {
  font-weight: 700;
}
.print-table tr.grand td.mid { font-size: 12pt; }

/* Signatures — editable */
.sig-section {
  margin-top: 14mm;
  font-size: 11pt;
}
.sig-role-line {
  font-size: 11pt;
  margin-bottom: 12mm;
}
.sig-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20mm;
  margin-bottom: 14mm;
}
.sig-block { text-align: center; }
.sig-paren {
  display: flex; align-items: center; justify-content: center;
  font-size: 11pt; font-weight: 600;
  gap: 0;
}
.sig-paren.center {
  margin-top: 0;
}
.sig-paren span { font-weight: 600; }
.sig-pos { font-size: 11pt; margin-top: 2px; }
.sig-pos.sig-pos-static { padding: 4px 0; }

/* Inline-editable input that looks like plain text */
.sig-input {
  border: none;
  background: transparent;
  font-family: inherit;
  font-size: 11pt;
  font-weight: inherit;
  text-align: center;
  color: black;
  padding: 2px 4px;
  outline: none;
  min-width: 40px;
}
.sig-input::placeholder { color: #aaa; }
/* On-screen hint that fields are editable */
@media screen {
  .sig-input {
    background: oklch(0.97 0.04 65 / 0.5);
    border-radius: 4px;
    transition: background .15s ease;
  }
  .sig-input:hover { background: oklch(0.95 0.05 65 / 0.7); }
  .sig-input:focus {
    background: white;
    box-shadow: 0 0 0 2px var(--accent);
  }
  .sig-paren .sig-input { width: 200px; }
  .sig-pos .sig-input { width: 240px; }
}

.sig-center {
  text-align: center;
}
.sig-center .sig-paren { margin-top: 14mm; margin-bottom: 0; }

@media print {
  body { background: white; }
  .print-shell { background: white; padding: 0; }
  .print-toolbar { display: none; }
  .print-sheet {
    box-shadow: none;
    width: 100%;
    min-height: 0;
    padding: 0;
    margin: 0;
  }
  @page { size: A4 portrait; margin: 10mm 8mm; }
  .sig-input {
    background: transparent !important;
    box-shadow: none !important;
    border-radius: 0 !important;
  }
  /* Hide empty placeholder cells in print */
  .sig-pos .sig-input:placeholder-shown { visibility: hidden; }
}

/* ===== Misc / animation ===== */
.fade-in { animation: fade .35s ease both; }
@keyframes fade { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.slide-in { animation: slide .4s cubic-bezier(0.4, 0, 0.2, 1) both; }
@keyframes slide { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: none; } }

.empty-hint {
  text-align: center;
  padding: 40px 20px;
  color: var(--ink-3);
  font-size: 14px;
}

.pulse-dot {
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--good);
  margin-right: 6px;
  position: relative;
  animation: pulse 2s ease-in-out infinite;
}
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 0 oklch(0.65 0.13 155 / 0.5); } 50% { box-shadow: 0 0 0 6px oklch(0.65 0.13 155 / 0); } }

.toast {
  position: fixed;
  bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--ink);
  color: white;
  padding: 12px 20px;
  border-radius: 999px;
  font-size: 13px;
  box-shadow: var(--shadow-lg);
  z-index: 100;
  animation: toast-in .3s ease both;
}
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 10px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* Top-right view switcher (demo helper) */
.demo-switcher {
  position: fixed;
  top: 14px; right: 14px;
  background: var(--ink);
  color: white;
  padding: 4px;
  border-radius: 999px;
  display: flex;
  gap: 2px;
  z-index: 50;
  box-shadow: var(--shadow-lg);
  font-size: 12px;
}
.demo-switcher button {
  padding: 8px 14px;
  border-radius: 999px;
  color: rgba(255,255,255,0.6);
  font-weight: 600;
  transition: all .15s ease;
  white-space: nowrap;
}
.demo-switcher button.active { background: white; color: var(--ink); }
.demo-switcher button:hover:not(.active) { color: white; }
@media print { .demo-switcher { display: none; } }
