:root {
  --navy: #0b3c73;
  --red: #c8342a;
  --blue: #2b7bb9;
  --bg: #f4f6f9;
  --card: #ffffff;
  --border: #d9dee5;
  --text: #1f2a37;
  --muted: #6b7684;
  --ok: #1a7f4b;
  --warn: #b4790a;
  --danger: #c8342a;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Sarabun", "TH Sarabun New", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
}

header.site {
  background: linear-gradient(135deg, var(--navy), var(--blue));
  color: #fff;
  padding: 28px 20px;
  text-align: center;
  position: relative;
}

.form-code {
  position: absolute;
  top: 14px;
  right: 18px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.5px;
  background: rgba(255, 255, 255, 0.18);
  border: 1px solid rgba(255, 255, 255, 0.4);
  border-radius: 6px;
  padding: 4px 10px;
}

header.site .site-logo {
  width: 64px;
  height: 64px;
  object-fit: contain;
  margin-bottom: 10px;
  border-radius: 50%;
  background: #fff;
  padding: 4px;
}

header.site h1 {
  margin: 0 0 4px;
  font-size: 22px;
}

header.site p {
  margin: 0;
  font-size: 15px;
  opacity: 0.9;
}

main {
  max-width: 760px;
  margin: 24px auto 40px;
  padding: 0 16px;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 28px;
  box-shadow: 0 6px 20px rgba(11, 60, 115, 0.08);
  margin-bottom: 20px;
}

.card h2 {
  margin-top: 0;
  font-size: 18px;
  color: var(--navy);
  border-bottom: 2px solid var(--border);
  padding-bottom: 10px;
}

.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px 16px;
}

.grid .full { grid-column: 1 / -1; }

@media (max-width: 560px) {
  .grid { grid-template-columns: 1fr; }
}

label {
  display: block;
  font-size: 14px;
  margin-bottom: 5px;
  color: var(--muted);
}

label .req { color: var(--red); }

input[type="text"],
input[type="tel"],
input[type="email"],
input[type="date"],
input[type="number"],
input[type="password"],
select,
textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: inherit;
  font-size: 15px;
  background: #fff;
  color: var(--text);
}

textarea { resize: vertical; min-height: 70px; }

.field { margin-bottom: 4px; }

.date-be-group {
  display: flex;
  gap: 8px;
}

.date-be-group select {
  flex: 1;
  min-width: 0;
}

.checkline {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 14px;
  margin-top: 6px;
}

.checkline input { margin-top: 4px; }

button {
  font-family: inherit;
  font-size: 15px;
  border: none;
  border-radius: 8px;
  padding: 12px 22px;
  cursor: pointer;
  font-weight: 600;
}

.btn-primary {
  background: var(--navy);
  color: #fff;
}

.btn-primary:hover { background: #0a2f5a; }

.btn-secondary {
  background: #eef1f5;
  color: var(--navy);
  border: 1px solid var(--border);
}

.btn-small {
  padding: 7px 14px;
  font-size: 13px;
}

.actions { margin-top: 20px; display: flex; gap: 10px; }

.msg {
  padding: 12px 14px;
  border-radius: 8px;
  font-size: 14px;
  margin-top: 16px;
  display: none;
}

.msg.show { display: block; }
.msg.ok { background: #e6f4ea; color: var(--ok); border: 1px solid #b7dfc4; }
.msg.err { background: #fdecea; color: var(--danger); border: 1px solid #f3c2bd; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

th, td {
  border: 1px solid var(--border);
  padding: 8px 10px;
  text-align: left;
  vertical-align: top;
}

th {
  background: #eef2f7;
  color: var(--navy);
  font-weight: 600;
}

tr.clickable { cursor: pointer; }
tr.clickable:hover { background: #f7f9fc; }

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}

.badge.pending { background: #fdf3dc; color: var(--warn); }
.badge.approved { background: #e6f4ea; color: var(--ok); }
.badge.rejected { background: #fdecea; color: var(--danger); }

.hidden { display: none !important; }

.detail-panel {
  border-top: 2px solid var(--border);
  margin-top: 14px;
  padding-top: 14px;
}

.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid #ccc;
  border-top-color: var(--navy);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  vertical-align: -3px;
  margin-right: 6px;
}

@keyframes spin { to { transform: rotate(360deg); } }

.footer-note {
  text-align: center;
  font-size: 12px;
  color: var(--muted);
  margin: 24px 0 8px;
}

.req-id {
  font-family: monospace;
  background: #eef2f7;
  padding: 2px 8px;
  border-radius: 6px;
}

/* ---------- แผงยืนยันการยื่นคำร้องสำเร็จ ---------- */
.success-panel {
  display: none;
  text-align: center;
  padding: 8px 4px 4px;
}

.success-panel.show { display: block; }

.success-panel .success-icon {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--ok);
  color: #fff;
  font-size: 30px;
  line-height: 56px;
  margin: 0 auto 14px;
}

.success-panel h3 {
  margin: 0 0 6px;
  color: var(--ok);
  font-size: 19px;
}

.success-panel p {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 14px;
}

.success-panel .success-id-box {
  display: inline-block;
  background: #eef2f7;
  border: 1px dashed var(--navy);
  border-radius: 10px;
  padding: 10px 22px;
  margin-bottom: 18px;
}

.success-panel .success-id-box span {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 2px;
}

.success-panel .success-id-box strong {
  font-family: monospace;
  font-size: 22px;
  color: var(--navy);
  letter-spacing: 0.5px;
}

.success-panel .actions {
  justify-content: center;
}

/* ---------- ใบยืนยันคำร้องแบบพิมพ์ / บันทึก PDF ---------- */
#printReceipt { display: none; }

.receipt-page {
  max-width: 720px;
  margin: 0 auto;
  padding: 20px;
  position: relative;
  color: #000;
}

.receipt-page .form-code {
  position: absolute;
  top: 0;
  right: 0;
  background: none;
  border: 1px solid #000;
  color: #000;
}

.receipt-header {
  text-align: center;
  margin-bottom: 6px;
  border-bottom: 2px solid #000;
  padding-bottom: 16px;
}

.receipt-header img {
  width: 60px;
  height: 60px;
  object-fit: contain;
  margin-bottom: 8px;
}

.receipt-header h2 {
  margin: 0 0 4px;
  font-size: 19px;
  letter-spacing: 0.3px;
}

.receipt-header p {
  margin: 0;
  font-size: 13px;
  color: #333;
}

.receipt-id-box {
  text-align: center;
  border: 1px solid #000;
  border-radius: 4px;
  padding: 10px 16px;
  margin: 22px auto 26px;
  max-width: 340px;
}

.receipt-id-box span {
  display: block;
  font-size: 12px;
  letter-spacing: 0.5px;
}

.receipt-id-box strong {
  font-family: "Sarabun", sans-serif;
  font-size: 21px;
  letter-spacing: 1px;
}

.receipt-fields {
  margin-top: 12px;
}

.receipt-row {
  display: flex;
  gap: 18px;
  padding: 9px 2px;
  border-bottom: 1px solid #ccc;
  font-size: 14px;
}

.receipt-row:last-child {
  border-bottom: none;
}

.receipt-row .rlabel {
  flex: 0 0 40%;
  color: #444;
}

.receipt-row .rvalue {
  flex: 1;
  font-weight: 600;
}

.receipt-note {
  font-size: 12px;
  color: #444;
  margin-top: 20px;
  font-style: italic;
}

.receipt-sign {
  margin-top: 56px;
  text-align: right;
  font-size: 14px;
}

.receipt-sign .line {
  margin-bottom: 8px;
}

body.printing > *:not(#printReceipt) {
  display: none !important;
}

body.printing #printReceipt {
  display: block !important;
}

@media print {
  @page { margin: 14mm; }
}
