@font-face {
  font-family: "TH SarabunPSK";
  src: url("fonts/THSarabunPSK-Regular.ttf") format("truetype");
  font-style: normal; font-weight: 400; font-display: swap;
}
@font-face {
  font-family: "TH SarabunPSK";
  src: url("fonts/THSarabunPSK-Bold.ttf") format("truetype");
  font-style: normal; font-weight: 700; font-display: swap;
}

 :root {
  color-scheme: light;
  --navy: #11274e;
  --ink: #142545;
  --muted: #526782;
  --blue: #0759c6;
  --accent: #1f8ce8;
  --line: #dce6f1;
  --canvas: #f3f7fc;
  --white: #fff;
  font-family: "TH SarabunPSK", "Leelawadee UI", Tahoma, sans-serif;
  font-size: 20px;
  line-height: 1.55;
  background: var(--canvas);
  color: var(--ink);
}
* { box-sizing: border-box; }
body { margin: 0; min-width: 290px; }
[hidden] { display: none !important; }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: .55; }
input[type=checkbox], input[type=radio] { accent-color: var(--blue); width: 17px; height: 17px; margin: 0; flex: none; }
:focus-visible { outline: 2px solid #1985ee; outline-offset: 3px; }
h1, h2, h3, p { margin: 0; }
h1 { font-size: clamp(1.85rem, 3vw, 2.5rem); font-weight: 750; line-height: 1.2; letter-spacing: -.02em; }
h2 { font-size: 1.125rem; line-height: 1.35; }
h3 { font-size: 1.05rem; }
svg { flex-shrink: 0; vertical-align: middle; }
small, .muted { color: var(--muted); }

.shell { display: grid; grid-template-columns: 224px minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  display: flex; flex-direction: column; gap: 39px; position: sticky; top: 0; height: 100vh;
  background: linear-gradient(155deg, #152e59 0%, #0b1d3e 78%); color: #e6f2ff; padding: 26px 18px 18px;
  border-right: 1px solid #132a51;
}
.brand { display: flex; align-items: center; gap: 12px; padding-inline: 7px; }
.brand-logo { width: 44px; height: 44px; object-fit: contain; filter: drop-shadow(0 2px 5px #07173572); }
.brand strong { display: block; font-family: "Segoe UI", sans-serif; font-size: 1.3rem; letter-spacing: .065em; line-height: 1.15; color: white; }
.brand small { color: #b5c9e5; font-size: .78rem; white-space: nowrap; }
.sidebar nav { display: grid; gap: 5px; }
.sidebar nav a, .sidebar-bottom button {
  display: flex; width: 100%; align-items: center; gap: 12px; padding: 11px 12px; border-radius: 9px;
  border: 1px solid transparent; color: #cbd9ed; font-size: .91rem; background: transparent; text-align: left;
}
.sidebar nav a:hover, .sidebar-bottom button:hover { background: #213a62; color: white; }
.sidebar nav [aria-current=page] { background: #245099; color: white; border-color: #3663a3; box-shadow: inset 3px 0 #76cbff; }
.sidebar-bottom { margin-top: auto; border-top: 1px solid #294167; padding-top: 9px; }

.topbar { min-height: 66px; background: #fff; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px clamp(18px, 3.25vw, 46px); font-size: .89rem; font-weight: 650; color: #264367; }
.user-role { display: flex; align-items: center; gap: 7px; color: #435c7d; white-space: nowrap; font-size: .82rem; }
.user-role svg { color: #1468c2; }
.content { max-width: 1480px; margin: 0 auto; padding: clamp(22px, 3.25vw, 46px); }
.page-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 18px; margin-bottom: 24px; }
.page-heading p { margin-top: .55rem; font-size: .94rem; color: var(--muted); }
.actions { display: flex; align-items: center; flex-wrap: wrap; gap: 9px; }
.button {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 43px;
  border: 1px solid transparent; border-radius: 9px; padding: 8px 15px; font-weight: 650;
  font-size: .89rem; white-space: nowrap; transition: background .12s ease, border-color .12s ease;
}
.button.primary { background: var(--blue); color: #fff; box-shadow: 0 2px 4px #124f971d; }
.button.primary:hover { background: #064da9; }
.button.secondary { background: white; color: #1a4c85; border-color: #cddced; }
.button.secondary:hover:enabled, a.button.secondary:hover { background: #eef6ff; border-color: #9bbddd; }
.button.compact { min-height: 36px; padding: 6px 11px; font-size: .83rem; }
.text-link { display: inline-flex; align-items: center; gap: 5px; color: #0958b1; font-weight: 650; font-size: .91rem; }
.text-link:hover { text-decoration: underline; }
.back-link { margin-bottom: 16px; }
.notice { padding: 10px 14px; margin-bottom: 16px; border-radius: 8px; border: 1px solid; font-size: .9rem; overflow-wrap: anywhere; }
.notice.success { background: #eaf8f2; color: #18583c; border-color: #b7e0cc; }
.notice.error { background: #fff0f0; color: #862525; border-color: #efc8c8; }

.panel { background: white; border: 1px solid var(--line); border-radius: 15px; box-shadow: 0 2px 6px #19396507; min-width: 0; }
.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 15px; margin-bottom: 20px; }
.stat { display: flex; align-items: center; gap: 13px; padding: 15px 17px; min-height: 92px; }
.stat-icon, .empty-icon { display: grid; place-items: center; border-radius: 12px; width: 46px; height: 46px; flex: none; background: #e8f3ff; color: #135bb6; }
.stat-icon.regular { background: #e5f7f6; color: #117777; }
.stat-icon.temporary { background: #fff3db; color: #865300; }
.stat div > span { font-size: .81rem; color: var(--muted); }
.stat strong { display: block; line-height: 1.16; font-family: "Segoe UI", sans-serif; margin-top: 3px; font-size: 1.72rem; }
.dashboard-grid { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(310px, 1fr); gap: 18px; align-items: start; }
.records { overflow: hidden; }
.section-heading, .preview-heading { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.section-heading { padding: 18px 17px 12px; }
.record-count { border-radius: 7px; padding: 3px 6px; color: #285386; background: #ecf3fd; font-size: .77rem; vertical-align: middle; font-family: "Segoe UI", sans-serif; }
.filters { padding: 0 17px 15px; display: flex; flex-wrap: wrap; gap: 7px; align-items: center; }
.search-field { display: flex; align-items: center; gap: 7px; padding: 0 9px; flex: 1 1 142px; color: #5c7291; min-width: 0; border: 1px solid #d2dfed; border-radius: 8px; }
.search-field input { width: 100%; min-width: 0; height: 34px; border: 0; padding: 3px 0; background: none; }
.search-field:focus-within { outline: 2px solid #1985ee; outline-offset: 1px; }
.search-field input:focus { outline: 0; }
.filters select, .filters input { color: var(--ink); font-size: .83rem; }
.filters select { max-width: 135px; border: 1px solid #d2dfed; background: white; border-radius: 8px; height: 36px; padding: 0 7px; }
.table-wrap { overflow: auto; }
table { width: 100%; border-collapse: collapse; font-size: .86rem; }
th, td { padding: 10px; text-align: left; border-top: 1px solid #e8eef6; }
th { background: #f4f8fd; color: #45617f; font-size: .77rem; white-space: nowrap; }
th:first-child, td:first-child { padding-left: 17px; }
th:last-child, td:last-child { padding-right: 17px; }
tbody tr:hover { background: #f8fbff; }
.student-cell { display: flex; align-items: center; gap: 8px; min-width: 115px; overflow-wrap: anywhere; }
.student-cell strong, .student-cell small { display: block; }
.student-cell small { font-family: "Segoe UI", sans-serif; margin-top: 1px; }
.avatar { width: 33px; height: 33px; border-radius: 9px; overflow: hidden; background: #edf4fd; color: #4874a6; flex: none; }
.avatar svg { width: 19px; height: 19px; }
.avatar img, .card-photo img { display: block; width: 100%; height: 100%; object-fit: cover; object-position: center 35%; }
.portrait-placeholder { display: grid; place-items: center; width: 100%; height: 100%; }
.type-tag { display: inline-block; border-radius: 6px; background: #e8f5f1; color: #176049; padding: 3px 7px; font-size: .75rem; white-space: nowrap; font-weight: 650; }
.type-tag.temporary { background: #fff1d8; color: #885400; }
.row-actions { display: flex; gap: 4px; }
.icon-button { display: grid; place-items: center; width: 30px; height: 31px; color: #24558f; border-radius: 7px; }
.icon-button:hover { background: #e7f2ff; }
.empty-state { display: grid; justify-items: center; text-align: center; gap: 8px; border-top: 1px solid #e8eff8; padding: 31px 13px 36px; }
.empty-icon { margin-bottom: 4px; width: 54px; height: 54px; }
.empty-state p { color: var(--muted); font-size: .89rem; }
.pagination { display: flex; justify-content: space-between; align-items: center; gap: 10px; border-top: 1px solid #e8eff8; padding: 13px 17px; font-size: .85rem; color: var(--muted); }

.preview-panel { padding: 18px; }
.sample-tag { border: 1px solid #d7e4f1; padding: 3px 8px; border-radius: 6px; font-size: .72rem; color: #496687; white-space: nowrap; }
.card-stage {
  background: radial-gradient(ellipse at 95% -15%, #d5ebff, transparent 68%), linear-gradient(150deg, #eff6ff, #e7f2fe);
  padding: clamp(10px, 1.45vw, 21px); border: 1px solid #e4edf8; border-radius: 11px; margin: 14px 0 10px;
}
.student-card {
  position: relative; width: 100%; aspect-ratio: 85.6 / 53.98; overflow: hidden;
  container-type: inline-size; isolation: isolate;
  --card-blue: radial-gradient(ellipse at 110% -65%, #319edc, transparent 67%),
    linear-gradient(116deg, #102754 15%, #124888 70%, #1761a4);
  background: #fff; color: #172e55;
}
.card-name-label { color: #35577e; font-size: .78em; font-weight: 400; }
.card-head {
  height: 15.4cqw; display: flex; align-items: center; gap: 2.4cqw; padding: 2cqw 4.2cqw;
  background: var(--card-blue);
  color: white; border-bottom: .55cqw solid #6fc8f4;
}
.card-logo { display: block; width: 11.7cqw; height: 11.7cqw; object-fit: contain; flex: none; }
.card-title-wrap { min-width: 0; }
.card-college { font-size: 5.15cqw; font-weight: 700; line-height: .92; }
.card-title { font-size: 5.1cqw; font-weight: 700; margin-top: .7cqw; line-height: .95; }
.card-title span { font-size: 4cqw; color: #bceaff; white-space: nowrap; }
.card-fields {
  position: relative; display: grid; grid-template-columns: 22cqw minmax(0, 1fr);
  gap: 3.25cqw; align-items: center; padding: 1.25cqw 4.2cqw; height: 33.6cqw;
  background: url("card-circuit.png") center / 100% 100% no-repeat,
    linear-gradient(115deg, #f7fbff 0%, #fff 44%, #f7fbff 100%);
}
.card-photo { height: 29.4cqw; overflow: hidden; border-radius: 1.85cqw; background: #e9f3ff; border: .33cqw solid #a8c8e8; color: #5984b1; }
.card-photo .portrait-placeholder svg { width: 9cqw; height: 9cqw; }
.card-details {
  --card-text: 4.58cqw; --card-name: 5.75cqw;
  min-width: 0; height: 31.1cqw; display: flex; flex-direction: column; justify-content: safe center;
}
.card-details[data-fit=medium] { --card-text: 4.12cqw; --card-name: 5.12cqw; }
.card-details[data-fit=small] { --card-text: 3.82cqw; --card-name: 4.65cqw; }
.card-details[data-fit=compact] { --card-text: 3.55cqw; --card-name: 4.22cqw; }
.card-details[data-fit=dense] { --card-text: 3.16cqw; --card-name: 3.6cqw; }
.card-details[data-fit=mini] { --card-text: 2.75cqw; --card-name: 2.95cqw; }
.card-details[data-fit=micro] { --card-text: 2.40cqw; --card-name: 2.52cqw; }
.card-lines { display: grid; gap: .3cqw; font-size: var(--card-text); line-height: .93; }
.card-name { font-size: var(--card-name); color: #102b50; font-weight: 700; line-height: .96; overflow-wrap: anywhere; margin-bottom: .42cqw; }
.card-data { display: grid; grid-template-columns: max-content minmax(0, 1fr); align-items: baseline; gap: .8cqw; }
.card-data span { color: #35577e; font-weight: 400; }
.card-data strong { font-weight: 700; overflow-wrap: anywhere; }
.card-dates:empty, .card-dates:not(:has(.card-data:not([hidden]))) { display: none; }
.card-dates { display: flex; gap: 1.25cqw 2cqw; flex-wrap: wrap; }
.card-dates .card-data { display: inline-flex; white-space: nowrap; }
.card-band {
  position: absolute; inset: 49cqw 0 0;
  display: flex; align-items: center; justify-content: center; padding: 0 1.05cqw;
  background: var(--card-blue); border-top: .55cqw solid #6fc8f4;
}
.card-barcode {
  display: flex; align-items: center; justify-content: center; min-width: 0; max-width: 100%;
  padding: .65cqw .55cqw; border-radius: .65cqw; background: #fff;
}
.card-barcode .barcode-svg { display: block; flex: 0 1 auto; min-width: 0; max-width: 100%; height: 9.5cqw; color: #000; }
.barcode-message { padding-inline: 1.6cqw; font-size: 3.7cqw; color: #324a69; }
.optional-card-fields > small { display: block; margin-top: 7px; }


.entry-panel, .guide-panel { padding: 21px; }
.entry-panel h2, .guide-panel h2 { margin-bottom: 17px; }
.stack { display: grid; gap: 17px; }
.stack label, .stack legend { font-weight: 650; font-size: .89rem; }
.stack label > small, .stack label span > small { display: block; font-weight: 400; margin-top: 5px; font-size: .81rem; }
.stack label > input:not([type=radio]):not([type=checkbox]),
.stack label > select, .stack label > textarea {
  display: block; min-height: 43px; width: 100%; margin-top: 6px; border: 1px solid #cddced;
  border-radius: 8px; padding: 8px 10px; background: #fff; color: var(--ink); font-size: .92rem;
}
.stack input[type=file] { font-weight: 400; }
.stack textarea { resize: vertical; }
input::file-selector-button { color: #155797; background: #eaf4ff; border: 0; border-radius: 5px; padding: 5px 8px; font: inherit; margin-right: 7px; cursor: pointer; font-weight: 650; }
.field-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.name-fields { grid-template-columns: minmax(0, 1fr) minmax(0, 2fr); }
.date-parts { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.25fr) minmax(0, 1.25fr); gap: 5px; }
.date-parts select { width: 100%; min-width: 0; min-height: 43px; padding: 6px; border: 1px solid #cddced; border-radius: 8px; background: #fff; color: var(--ink); font-size: .86rem; }
.date-picker legend { margin-bottom: 6px; }
.date-picker[aria-invalid=true] .date-parts select { border-color: #bd6565; }
fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
legend { margin-bottom: 6px; padding: 0; }
.option { display: flex; align-items: center; gap: 8px; padding: 10px; min-height: 44px; border: 1px solid #d7e4f1; border-radius: 8px; }
.option:has(input:checked) { border-color: #91bce9; background: #f0f7ff; color: #194f8a; }
.checkbox-label { display: flex; align-items: flex-start; gap: 8px; }
.checkbox-label input { margin-top: 3px; }
.label-note { font-weight: 400; font-size: .8rem; color: #566d87; margin-left: 4px; }
.form-actions { padding-top: 14px; border-top: 1px solid #e4edf7; }
.guide-panel ul { padding-left: 21px; margin: 16px 0 0; color: #405974; font-size: .88rem; }
.guide-panel li { margin-bottom: 8px; }
.guide-panel li:last-child { margin-bottom: 0; }
.download-links { margin-bottom: 12px; }
.guide-panel code { color: #174979; background: #edf6ff; padding: 2px 4px; border-radius: 4px; }

.auth-page {
  min-height: 100vh; display: grid; place-items: center; padding: 20px;
  background: radial-gradient(ellipse at 25% 0%, #20558d, transparent 68%), linear-gradient(145deg, #0f254b, #0a1936);
}
.auth-panel { width: min(100%, 430px); border-radius: 19px; padding: 30px; background: #fff; box-shadow: 0 20px 65px #0005; }
.auth-logo { display: block; width: 68px; height: 68px; object-fit: contain; margin: 0 auto 10px; }
.auth-panel h1, .auth-panel p { text-align: center; }
.auth-panel h1 { font-size: 1.8rem; margin: 7px 0; }
.auth-college { color: #315780; font-weight: 650; font-size: .9rem; }
.auth-panel .stack { margin-top: 20px; }
.auth-panel .notice { margin-top: 12px; }

.print-toolbar { background: white; border-bottom: 1px solid var(--line); padding: 20px max(16px, calc((100% - 210mm) / 2)); }
.print-toolbar-inner { display: flex; align-items: flex-end; justify-content: space-between; gap: 15px; }
.print-toolbar h1 { font-size: 1.8rem; margin: 7px 0; }
.print-toolbar p { color: var(--muted); font-size: .88rem; }
.print-toolbar .print-hint { margin-top: 9px; }
.paper-stack { overflow: auto; padding: 20px 10px; }
.paper {
  display: grid; grid-template-columns: repeat(2, 85.6mm); grid-auto-rows: 53.98mm;
  gap: 3mm 6mm; justify-content: center; align-content: start;
  width: 210mm; min-height: 297mm; margin: 0 auto 18px; padding: 7.5mm 0;
  background: white; box-shadow: 0 3px 14px #192e4c26;
}
.cut-card { width: 85.6mm; height: 53.98mm; overflow: hidden; outline: .14mm solid #8e9bad; break-inside: avoid; }
.cut-card .student-card { width: 100%; height: 100%; }

@media (max-width: 1210px) {
  .shell { grid-template-columns: 195px minmax(0, 1fr); }
  .sidebar { padding-inline: 12px; }
  .content { padding-inline: 25px; }
  .dashboard-grid { grid-template-columns: minmax(0, 1.35fr) minmax(270px, 1fr); }
}
@media (max-width: 991px) {
  .dashboard-grid { grid-template-columns: minmax(0, 1fr); }
  .preview-panel, .guide-panel { max-width: 470px; }
}
@media (max-width: 710px) {
  .shell { display: block; }
  .sidebar { height: auto; position: static; gap: 9px; padding: 12px; display: grid; grid-template-columns: 1fr auto; }
  .brand { padding-inline: 2px; }
  .brand-logo { width: 38px; height: 38px; }
  .sidebar nav { grid-row: 2; grid-column: span 2; display: flex; overflow-x: auto; }
  .sidebar nav a { white-space: nowrap; width: auto; padding: 7px 9px; gap: 6px; font-size: .83rem; }
  .sidebar nav a svg { width: 17px; height: 17px; }
  .sidebar-bottom { margin-top: 0; border: 0; padding: 0; align-self: center; }
  .sidebar-bottom button { padding: 6px; gap: 5px; font-size: .78rem; }
  .topbar { min-height: 45px; font-size: .78rem; }
  .user-role span { display: none; }
  .content { padding: 19px 12px; }
  .page-heading { flex-wrap: wrap; margin-bottom: 16px; }
  .stats { gap: 6px; }
  .stat { flex-direction: column; align-items: flex-start; padding: 9px; gap: 4px; }
  .stat-icon { width: 31px; height: 31px; border-radius: 7px; }
  .stat-icon svg { width: 18px; height: 18px; }
  .stat div > span { font-size: .71rem; }
  .stat strong { font-size: 1.3rem; }
}
@media (max-width: 390px) {
  .field-row { grid-template-columns: 1fr; }
  .print-toolbar-inner { align-items: flex-start; flex-direction: column; }
}
@page { size: A4 portrait; margin: 7mm; }
@media print {
  html, body { background: white; margin: 0; min-width: 0; }
  .print-toolbar { display: none; }
  .paper-stack { padding: 0; overflow: visible; }
  .paper {
    margin: 0; padding: 0; width: auto; min-height: 0; box-shadow: none;
    break-inside: avoid; break-after: page;
  }
  .paper:last-child { break-after: auto; }
  .student-card { print-color-adjust: exact; -webkit-print-color-adjust: exact; }
}

.setup-panel { width: min(100%, 560px); }
.setup-panel .notice { margin-bottom: 0; }
