@import url('https://fonts.googleapis.com/css2?family=Prompt:wght@300;400;500;600;700&display=swap');

:root {
  --navy: #0b2e5b;
  --blue: #1d4ed8;
  --blue-600: #2563eb;
  --blue-50: #eff5ff;
  --blue-100: #dbe7fe;
  --ink: #14213a;
  --muted: #5b6b87;
  --line: #dce4f0;
  --bg: #f4f7fc;
  --white: #fff;
  --ok: #0e9f6e;
  --warn: #d97706;
  --danger: #dc2626;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(11, 46, 91, .06), 0 8px 24px rgba(11, 46, 91, .07);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Prompt', system-ui, sans-serif;
  font-weight: 300;
  color: var(--ink);
  background: var(--bg);
  line-height: 1.65;
  -webkit-text-size-adjust: 100%;
}

a { color: var(--blue); }

/* ---------- หัวเว็บฟอร์ม ---------- */
.masthead {
  position: relative;
  background: linear-gradient(160deg, var(--navy) 0%, #123f7d 100%);
  color: #fff;
  padding: 34px 20px 68px;
  text-align: center;
}
.masthead-admin-link {
  position: absolute; top: 16px; right: 16px; z-index: 1;
  width: 40px; height: 40px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  background: rgba(255, 255, 255, .1); border: 1px solid rgba(255, 255, 255, .3);
  color: #fff; text-decoration: none; transition: .15s;
}
.masthead-admin-link:hover { background: rgba(255, 255, 255, .22); border-color: rgba(255, 255, 255, .5); }
.masthead-admin-link:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
.masthead-admin-link svg { width: 19px; height: 19px; }
@media (max-width: 640px) {
  .masthead-admin-link { top: 10px; right: 10px; width: 34px; height: 34px; }
  .masthead-admin-link svg { width: 16px; height: 16px; }
}
.masthead .eyebrow {
  font-size: 13px; letter-spacing: .16em; text-transform: uppercase;
  color: var(--blue-100); font-weight: 500; margin: 0 0 10px;
}
.masthead-logos { display: flex; align-items: center; justify-content: center; gap: 22px; margin: 0 0 18px; }
.masthead-logos .logo-chip {
  background: #fff; border-radius: 50%; width: 104px; height: 104px; flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
  box-shadow: var(--shadow); overflow: hidden;
}
.masthead-logos .logo { max-height: 94px; max-width: 94px; width: auto; height: auto; object-fit: contain; display: block; }
@media (max-width: 640px) {
  .masthead-logos { gap: 14px; }
  .masthead-logos .logo-chip { width: 76px; height: 76px; }
  .masthead-logos .logo { max-height: 68px; max-width: 68px; }
}
.masthead h1 { font-size: clamp(20px, 4.4vw, 28px); font-weight: 600; margin: 0 0 8px; line-height: 1.35; }
.masthead p { margin: 0; color: #c9dcfa; font-size: 15px; }

.wrap { max-width: 820px; margin: -46px auto 60px; padding: 0 16px; position: relative; z-index: 1; }
.wrap-wide { max-width: 1240px; }

/* ---------- การ์ด / ส่วนของฟอร์ม ---------- */
.card {
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 26px;
  margin-bottom: 18px;
}
.section-head { display: flex; align-items: baseline; gap: 12px; margin: 0 0 18px; padding-bottom: 14px; border-bottom: 2px solid var(--blue-50); }
.section-head .no {
  font-size: 13px; font-weight: 600; color: var(--blue);
  background: var(--blue-50); border-radius: 999px; padding: 3px 12px; white-space: nowrap;
}
.section-head h2 { font-size: 17px; font-weight: 600; margin: 0; }

.grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px 16px; }
.col-span { grid-column: 1 / -1; }
@media (max-width: 640px) {
  .grid, .grid-3 { grid-template-columns: 1fr; }
  .card { padding: 18px; }
}

label.field { display: block; }
label.field > span {
  display: block; font-size: 14px; font-weight: 500; margin-bottom: 6px; color: var(--ink);
}
.req { color: var(--danger); }
.hint { font-size: 12.5px; color: var(--muted); font-weight: 300; }

/* ช่องที่ยังไม่ได้ตอบตอนกดส่งฟอร์ม (เติมด้วย JS) */
.field-error { outline: 2px solid var(--danger); outline-offset: 4px; border-radius: 10px; }
.field-error > span { color: var(--danger); }

input[type=text], input[type=tel], input[type=email], input[type=number],
input[type=date], input[type=password], select, textarea {
  width: 100%; font-family: inherit; font-size: 15px; font-weight: 300; color: var(--ink);
  background: #fff; border: 1.5px solid var(--line); border-radius: 10px;
  padding: 10px 12px; transition: border-color .15s, box-shadow .15s;
}
textarea { min-height: 96px; resize: vertical; }
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--blue-600); box-shadow: 0 0 0 3px rgba(37, 99, 235, .15);
}
input:focus-visible, button:focus-visible, a:focus-visible { outline: 2px solid var(--blue-600); outline-offset: 2px; }

/* ---------- การ์ดตัวเลือกสถานะ (จุดเด่นของฟอร์ม) ---------- */
.status-list { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
@media (max-width: 640px) { .status-list { grid-template-columns: 1fr; } }
.status-opt { position: relative; }
.status-opt input { position: absolute; opacity: 0; inset: 0; cursor: pointer; }
.status-opt span {
  display: block; padding: 14px 16px 14px 44px; border: 1.5px solid var(--line);
  border-radius: 12px; font-size: 15px; cursor: pointer; background: #fff; transition: .15s;
}
.status-opt span::before {
  content: ''; position: absolute; left: 16px; top: 50%; transform: translateY(-50%);
  width: 18px; height: 18px; border: 2px solid #b9c6db; border-radius: 50%; background: #fff;
}
.status-opt input:checked + span { border-color: var(--blue); background: var(--blue-50); font-weight: 500; }
.status-opt input:checked + span::before { border-color: var(--blue); border-width: 5px; }
.status-opt input:focus-visible + span { outline: 2px solid var(--blue-600); outline-offset: 2px; }

.conditional { display: none; margin-top: 18px; padding-top: 18px; border-top: 1px dashed var(--line); }
.conditional.show { display: block; animation: slide .2s ease; }
@keyframes slide { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }

/* ---------- ตารางให้คะแนน ---------- */
.rating { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.rating-row { display: grid; grid-template-columns: 1fr 260px; gap: 10px; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.rating-row:last-child { border-bottom: 0; }
.rating-row:nth-child(odd) { background: #fbfcfe; }
.scale { display: flex; gap: 6px; justify-content: space-between; }
.scale label { flex: 1; text-align: center; }
.scale input { position: absolute; opacity: 0; }
.scale em {
  display: block; font-style: normal; font-size: 14px; padding: 7px 0; cursor: pointer;
  border: 1.5px solid var(--line); border-radius: 8px; background: #fff; transition: .15s;
}
.scale input:checked + em { background: var(--blue); border-color: var(--blue); color: #fff; font-weight: 500; }
.scale-head { font-size: 12px; color: var(--muted); text-align: center; }
@media (max-width: 640px) { .rating-row { grid-template-columns: 1fr; } }

/* ---------- ปุ่ม ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 8px; justify-content: center;
  font-family: inherit; font-size: 15px; font-weight: 500; cursor: pointer;
  padding: 11px 22px; border-radius: 10px; border: 1.5px solid transparent; text-decoration: none;
  transition: .15s;
}
.btn-primary { background: var(--blue); color: #fff; }
.btn-primary:hover { background: #1a43bd; }
.btn-ghost { background: #fff; color: var(--navy); border-color: var(--line); }
.btn-ghost:hover { border-color: var(--blue); color: var(--blue); }
.btn-block { width: 100%; padding: 14px; font-size: 16px; }
.btn-sm { padding: 7px 14px; font-size: 13.5px; }

.alert { padding: 13px 16px; border-radius: 10px; font-size: 14.5px; margin-bottom: 16px; }
.alert-error { background: #fef2f2; border: 1px solid #fecaca; color: #991b1b; }
.alert-info { background: var(--blue-50); border: 1px solid var(--blue-100); color: var(--navy); }

/* ---------- หน้าขอบคุณ ---------- */
.thanks { text-align: center; padding: 46px 26px; }
.thanks .mark {
  width: 68px; height: 68px; border-radius: 50%; background: #e7f8f1; color: var(--ok);
  display: grid; place-items: center; font-size: 34px; margin: 0 auto 18px;
}

/* ---------- หลังบ้าน ---------- */
.admin-bar {
  background: var(--navy); color: #fff; padding: 12px 20px;
  display: flex; align-items: center; gap: 20px; flex-wrap: wrap;
}
.admin-bar .brand { font-weight: 600; font-size: 15px; }
.admin-bar nav { display: flex; gap: 4px; flex-wrap: wrap; margin-left: auto; }
.admin-bar nav a {
  color: #c9dcfa; text-decoration: none; font-size: 14px; padding: 6px 13px; border-radius: 8px;
}
.admin-bar nav a:hover { background: rgba(255, 255, 255, .1); color: #fff; }
.admin-bar nav a.on { background: var(--blue); color: #fff; }

.page-head { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin: 24px 0 16px; }
.page-head h1 { font-size: 21px; font-weight: 600; margin: 0; }
.page-head .spacer { margin-left: auto; }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 18px; }
@media (max-width: 900px) { .stats { grid-template-columns: repeat(2, 1fr); } }
.stat { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 18px; }
.stat .label { font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.stat .value { font-size: 27px; font-weight: 600; color: var(--navy); line-height: 1.2; }
.stat .value small { font-size: 15px; font-weight: 400; color: var(--muted); }

.charts { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 900px) { .charts { grid-template-columns: 1fr; } }
.chart-card h3 { font-size: 15px; font-weight: 600; margin: 0 0 14px; }

table.data { width: 100%; border-collapse: collapse; font-size: 14px; background: #fff; }
table.data th, table.data td { padding: 10px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
table.data th { background: var(--blue-50); font-weight: 500; font-size: 13px; color: var(--navy); white-space: nowrap; }
table.data tbody tr:hover { background: #fbfcfe; }
.table-scroll { overflow-x: auto; border: 1px solid var(--line); border-radius: 12px; }

.chip { display: inline-block; font-size: 12.5px; padding: 3px 10px; border-radius: 999px; white-space: nowrap; }
.chip-ok { background: #e7f8f1; color: #076c4b; }
.chip-study { background: var(--blue-50); color: var(--navy); }
.chip-none { background: #fef3c7; color: #92400e; }
.chip-late { background: #ffedd5; color: #9a3412; }
.chip-gray { background: #f1f4f9; color: var(--muted); }

.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 16px; }
.filters .field { min-width: 150px; }
.pager { display: flex; gap: 6px; justify-content: center; margin: 18px 0; flex-wrap: wrap; }
.pager a, .pager span { padding: 6px 12px; border: 1px solid var(--line); border-radius: 8px; background: #fff; text-decoration: none; font-size: 14px; }
.pager .on { background: var(--blue); color: #fff; border-color: var(--blue); }

.detail-grid { display: grid; grid-template-columns: 190px 1fr; gap: 0; font-size: 14.5px; }
.detail-grid dt { padding: 9px 0; color: var(--muted); border-bottom: 1px solid var(--line); }
.detail-grid dd { padding: 9px 0; margin: 0; border-bottom: 1px solid var(--line); }
@media (max-width: 640px) { .detail-grid { grid-template-columns: 1fr; } .detail-grid dt { border-bottom: 0; padding-bottom: 0; } }

.login-box { max-width: 380px; margin: 90px auto; }

/* ---------- รายงาน A4 สำหรับพิมพ์ ---------- */
.sheet {
  background: #fff; width: 210mm; min-height: 297mm; margin: 20px auto; padding: 18mm 16mm;
  box-shadow: var(--shadow); font-size: 15px;
}
.sheet h1 { text-align: center; font-size: 20px; font-weight: 600; margin: 0 0 4px; }
.sheet h2 { text-align: center; font-size: 16px; font-weight: 400; color: var(--muted); margin: 0 0 22px; }
.sheet h3 { font-size: 16px; font-weight: 600; margin: 22px 0 10px; padding-bottom: 6px; border-bottom: 2px solid var(--navy); }
.sheet table { width: 100%; border-collapse: collapse; font-size: 14px; }
.sheet table th, .sheet table td { border: 1px solid #9db0cc; padding: 6px 9px; }
.sheet table th { background: #eaf0fa; font-weight: 500; }
.sheet .num { text-align: right; }
.sheet .center { text-align: center; }
.sign { margin-top: 46px; display: flex; justify-content: flex-end; text-align: center; }
.print-bar { text-align: center; padding: 16px; }

@media print {
  body { background: #fff; }
  .no-print, .admin-bar, .print-bar { display: none !important; }
  .sheet { width: auto; min-height: 0; margin: 0; padding: 0; box-shadow: none; }
  table { page-break-inside: auto; }
  tr { page-break-inside: avoid; }
  @page { size: A4; margin: 15mm; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
