@font-face {
  font-family: "Noto Sans Thai";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("/fonts/noto-sans-thai/noto-sans-thai-thai-400-normal.woff2") format("woff2");
  unicode-range: U+0E00-0E7F;
}

@font-face {
  font-family: "Noto Sans Thai";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("/fonts/noto-sans-thai/noto-sans-thai-latin-400-normal.woff2") format("woff2");
  unicode-range: U+0000-00FF;
}

@font-face {
  font-family: "Noto Sans Thai";
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url("/fonts/noto-sans-thai/noto-sans-thai-thai-500-normal.woff2") format("woff2");
  unicode-range: U+0E00-0E7F;
}

@font-face {
  font-family: "Noto Sans Thai";
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url("/fonts/noto-sans-thai/noto-sans-thai-latin-500-normal.woff2") format("woff2");
  unicode-range: U+0000-00FF;
}

@font-face {
  font-family: "Noto Sans Thai";
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("/fonts/noto-sans-thai/noto-sans-thai-thai-600-normal.woff2") format("woff2");
  unicode-range: U+0E00-0E7F;
}

@font-face {
  font-family: "Noto Sans Thai";
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("/fonts/noto-sans-thai/noto-sans-thai-latin-600-normal.woff2") format("woff2");
  unicode-range: U+0000-00FF;
}

@font-face {
  font-family: "Noto Sans Thai";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("/fonts/noto-sans-thai/noto-sans-thai-thai-700-normal.woff2") format("woff2");
  unicode-range: U+0E00-0E7F;
}

@font-face {
  font-family: "Noto Sans Thai";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("/fonts/noto-sans-thai/noto-sans-thai-latin-700-normal.woff2") format("woff2");
  unicode-range: U+0000-00FF;
}

:root {
  color-scheme: light;
  --bg: #f5f7f4;
  --panel: #ffffff;
  --ink: #18221f;
  --muted: #68756f;
  --line: #d8dfda;
  --accent: #176b56;
  --accent-strong: #0f4f40;
  --danger: #b42318;
  --ok: #067647;
  --soft: #e9f2ed;
  font-family: "Noto Sans Thai", sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  font-family: "Noto Sans Thai", sans-serif;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: "Noto Sans Thai", sans-serif;
}

button,
input,
select,
table {
  font: inherit;
}

.pin-page {
  display: grid;
  place-items: center;
  padding: 24px;
}

.pin-shell {
  width: min(100%, 520px);
}

.pin-panel,
.topbar,
.summary,
.table-section {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 18px 50px rgba(24, 34, 31, 0.08);
}

.pin-panel {
  padding: 32px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  margin: 0 0 24px;
  font-size: 30px;
  line-height: 1.25;
}

.pin-form label {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

.pin-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
}

.pin-row input {
  min-width: 0;
  height: 46px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 14px;
  color: var(--ink);
  background: #fff;
}

.pin-row input:focus {
  border-color: var(--accent);
  outline: 3px solid rgba(23, 107, 86, 0.15);
}

button,
.button {
  height: 46px;
  border: 0;
  border-radius: 6px;
  padding: 0 18px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

button:hover,
.button:hover {
  background: var(--accent-strong);
}

.status {
  min-height: 24px;
  margin: 12px 0 0;
  color: var(--danger);
  font-size: 14px;
}

.report-page {
  padding: 18px;
}

.report-shell {
  width: min(100%, 1180px);
  margin: 0 auto;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 20px;
}

.topbar h1 {
  margin: 2px 0 0;
  font-size: 24px;
}

.topbar p {
  margin: 0;
  color: var(--muted);
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.book-picker {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.book-picker select {
  min-width: 260px;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 10px;
  color: var(--ink);
  background: #fff;
}

.logout {
  color: var(--accent);
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
}

.tabs {
  display: flex;
  gap: 8px;
  margin: 16px 0 0;
  overflow-x: auto;
}

.tab,
.page-button,
.ghost-button,
.filter-chip {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--accent-strong);
}

.tab.is-active,
.page-button.is-active,
.filter-chip.is-active {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.ghost-button {
  height: 38px;
  padding: 0 12px;
  color: var(--accent);
}

.view {
  display: none;
}

.view.is-active {
  display: block;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin: 16px 0;
}

.summary {
  padding: 16px;
}

.summary span {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.summary strong {
  display: block;
  margin-top: 6px;
  font-size: 24px;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}

.kpi {
  min-height: 112px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.kpi span,
.kpi small {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.kpi strong {
  display: block;
  margin: 8px 0 4px;
  font-size: 28px;
  line-height: 1.1;
}

.report-card-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  padding: 0 16px 16px;
}

.report-card {
  min-height: 86px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #fbfcfb;
}

.report-card span {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.report-card strong {
  display: block;
  margin-top: 6px;
  font-size: 22px;
}

.report-note {
  margin: 0 16px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  color: var(--muted);
  background: #fbfcfb;
}

.table-section {
  overflow: hidden;
}

.inline-head {
  margin-bottom: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

.section-head h2 {
  margin: 0;
  font-size: 18px;
}

.download-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.download-list a {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 7px 10px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
}

.chart-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}

.chart-card {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  overflow: hidden;
}

.chart-title {
  margin: 0;
  padding: 12px 14px 0;
  color: var(--ink);
  font-size: 15px;
  font-weight: 700;
  line-height: 1.35;
}

.chart-card.compact .chart {
  height: 286px;
}

.chart {
  width: 100%;
  height: 360px;
}

.report-browser {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  gap: 14px;
  margin-bottom: 16px;
}

.report-mobile-controls {
  display: none;
}

.page-list,
.report-detail {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  overflow: hidden;
}

.page-list {
  align-self: start;
  max-height: calc(100vh - 180px);
  overflow-y: auto;
  padding: 12px;
}

.page-list h2 {
  margin: 2px 4px 10px;
  font-size: 17px;
}

.page-button {
  width: 100%;
  height: auto;
  justify-content: flex-start;
  margin-bottom: 8px;
  padding: 9px 10px;
  text-align: left;
}

.report-summary {
  display: grid;
  gap: 6px;
  padding: 12px 16px;
  color: var(--muted);
}

.report-summary p {
  margin: 0;
}

.table-wrap {
  max-width: 100%;
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 820px;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 10px 12px;
  text-align: left;
  vertical-align: top;
  font-size: 14px;
}

th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--soft);
  color: var(--accent-strong);
  font-size: 13px;
  font-weight: 700;
}

th:first-child,
td:first-child {
  position: sticky;
  left: 0;
  z-index: 1;
  background: #fff;
}

th:first-child {
  z-index: 3;
  background: var(--soft);
}

tbody tr:hover {
  background: #fbfcfb;
}

.report-grid {
  min-width: 720px;
}

.student-controls {
  display: flex;
  gap: 8px;
}

.student-controls select,
.student-controls input {
  min-width: 180px;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 10px;
  background: #fff;
}

.pager {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  padding: 12px 16px;
}

.pager button {
  width: auto;
  height: 38px;
}

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

.student-card-list {
  display: none;
}

.student-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fff;
}

.student-card strong,
.student-card span,
.student-card small {
  display: block;
}

.student-card strong {
  color: var(--ink);
  font-size: 15px;
  line-height: 1.35;
}

.student-card span,
.student-card small {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.loading,
.empty {
  padding: 18px;
  color: var(--muted);
}

@media (max-width: 720px) {
  .report-page {
    padding: 12px;
  }

  .report-shell {
    width: 100%;
  }

  .pin-panel {
    padding: 22px;
  }

  .pin-row,
  .summary-grid,
  .report-card-grid,
  .chart-grid,
  .report-browser {
    grid-template-columns: 1fr;
  }

  .kpi-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    margin-bottom: 12px;
  }

  .kpi {
    min-height: 86px;
    padding: 12px;
  }

  .kpi span,
  .kpi small {
    font-size: 12px;
  }

  .kpi strong {
    font-size: 22px;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
    gap: 10px;
    padding: 14px;
  }

  .topbar h1 {
    font-size: 20px;
  }

  .topbar p {
    font-size: 12px;
    line-height: 1.4;
  }

  .top-actions {
    align-items: center;
    flex-direction: row;
    width: 100%;
  }

  .book-picker {
    align-items: stretch;
    flex: 1;
    width: 100%;
    min-width: 0;
  }

  .book-picker span {
    display: none;
  }

  .book-picker select {
    height: 38px;
    min-width: 0;
    width: 100%;
  }

  .logout {
    align-items: center;
    display: inline-flex;
    min-height: 38px;
  }

  .pin-row button,
  .button {
    width: 100%;
  }

  .tabs {
    gap: 6px;
    margin-top: 12px;
    padding-bottom: 2px;
  }

  .tab {
    flex: 0 0 auto;
    height: 40px;
    padding: 0 14px;
    white-space: nowrap;
    width: auto;
  }

  .inline-head {
    margin-bottom: 10px;
  }

  .student-controls,
  .section-head {
    align-items: stretch;
    flex-direction: column;
    padding: 12px;
  }

  .student-controls select,
  .student-controls input {
    width: 100%;
  }

  .chart-grid {
    gap: 10px;
    margin-bottom: 12px;
  }

  .chart-title {
    padding: 10px 12px 0;
    font-size: 13px;
  }

  .chart,
  .chart-card.compact .chart {
    height: 260px;
  }

  .report-mobile-controls {
    position: sticky;
    top: 0;
    z-index: 5;
    display: grid;
    gap: 10px;
    margin: 12px 0;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 10px;
    background: rgba(245, 247, 244, 0.96);
    backdrop-filter: blur(8px);
  }

  .filter-chips {
    display: flex;
    gap: 6px;
    overflow-x: auto;
  }

  .filter-chip {
    flex: 0 0 auto;
    height: 34px;
    padding: 0 12px;
    white-space: nowrap;
    width: auto;
  }

  #report-page-select {
    width: 100%;
    height: 40px;
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 0 10px;
    background: #fff;
  }

  .report-browser {
    display: block;
  }

  .page-list {
    display: none;
  }

  .report-detail,
  .table-section {
    border-radius: 8px;
  }

  .report-summary {
    padding: 10px 12px;
    font-size: 13px;
  }

  .report-card-grid {
    gap: 10px;
    padding: 0 12px 12px;
  }

  .report-card {
    min-height: 74px;
    padding: 12px;
  }

  .table-wrap {
    max-height: 62vh;
  }

  table {
    min-width: 680px;
  }

  th,
  td {
    padding: 8px 10px;
    font-size: 12px;
  }

  .student-card-list {
    display: grid;
    gap: 8px;
    padding: 12px;
  }

  #student-table {
    display: none;
  }

  .pager {
    justify-content: space-between;
    padding: 10px 12px;
  }

  .pager button {
    width: auto;
  }
}
