/* สไตล์อิงเว็บงานเครื่องราชของ ตร.: โทน slate (กรมท่าอมเทา) + ทอง, ฟอนต์ Sarabun, การ์ดขาวขอบบาง */
:root {
  --bg: #f1f5f9; --panel: #fff; --soft: #f8fafc; --ink: #334155; --head: #0f172a; --muted: #64748b; --line: #e2e8f0;
  --outline: #cbd5e1; --dark1: #0f172a; --dark2: #1e293b;
  --primary: #3b82f6; --primary-d: #2563eb; --success: #10b981; --success-d: #059669; --danger: #ef4444; --danger-d: #dc2626;
  --ok: #047857; --ok-bg: #e7f6ef; --warn: #92400e; --warn-bg: #fef3c7; --bad: #b91c1c; --bad-bg: #fee2e2;
  --badge: #fef3c7; --badge-ink: #b45309; --footer: #0f172a; --gold: #d4af37;
  --radius: 12px; --shadow: 0 4px 6px rgba(0, 0, 0, .02);
}
* { box-sizing: border-box; }
html, body { min-height: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); display: flex; flex-direction: column; min-height: 100vh;
  font: 16px/1.6 "Sarabun", "Leelawadee UI", "Tahoma", system-ui, sans-serif; }
a { color: var(--primary-d); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 24px; font-weight: 600; color: var(--head); margin: 0 0 18px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
h1.center { justify-content: center; text-align: center; font-size: 26px; }
h2 { font-size: 18px; font-weight: 600; color: var(--head); margin: 0 0 12px; }
.muted { color: var(--muted); } .center { text-align: center; } .small { font-size: 13px; } .big { font-size: 20px; }

/* ---------------------------------------------------------------- แถบบน / ท้ายเว็บ */
.topbar { background: linear-gradient(180deg, #e3c35a 0%, #d4af37 55%, #c29d2c 100%); border-bottom: 1px solid #a8861f;
  box-shadow: 0 2px 6px rgba(15, 23, 42, .12); display: flex; justify-content: space-between;
  align-items: center; padding: 10px 24px; flex-wrap: wrap; gap: 10px; }
.brand { font-weight: 700; font-size: 18px; color: var(--head); } .brand span { font-weight: 500; color: #3b2f0b; }
.brand:hover { text-decoration: none; }
.topbar nav { display: flex; gap: 10px; align-items: center; font-size: 14px; flex-wrap: wrap; }
.who { color: #3b2f0b; } .who b { color: var(--head); }
.pill { padding: 7px 16px; border-radius: 8px; background: #fff; border: 1px solid var(--outline); color: var(--ink);
  font-weight: 600; }
.pill:hover { background: var(--soft); text-decoration: none; }
.pill.logout { background: var(--danger); border-color: var(--danger-d); color: #fff; }
.pill.logout:hover { background: var(--danger-d); }
footer { margin-top: auto; background: var(--footer); border-top: 3px solid var(--gold); color: #94a3b8;
  font-size: 14px; text-align: center; padding: 26px 20px; }
footer .copyright { color: #f8fafc; font-weight: 600; font-size: 15px; }
footer .contact { border-top: 1px solid var(--dark2); margin: 12px auto 0; padding-top: 12px; max-width: 720px; }

/* การ์ดต้อนรับ (หน้าหลักหน่วย / Admin) */
.welcome-card { background: linear-gradient(135deg, var(--dark1) 0%, var(--dark2) 100%); color: #fff;
  border-left: 6px solid var(--gold); border-radius: 12px; box-shadow: 0 10px 25px rgba(15, 23, 42, .15);
  padding: 22px 28px; margin-bottom: 20px; display: flex; justify-content: space-between; align-items: center;
  gap: 12px; flex-wrap: wrap; }
.welcome-card .name { margin: 0; font-size: 20px; font-weight: 600; }
.welcome-card .details { margin: 2px 0 0; color: #cbd5e1; font-size: 14px; }
.role-badge { font-size: 13px; font-weight: 600; color: #bae6fd; background: rgba(255, 255, 255, .1);
  border: 1px solid rgba(255, 255, 255, .2); border-radius: 20px; padding: 4px 12px; white-space: nowrap; }

/* ---------------------------------------------------------------- โครงหน้า */
main { width: 100%; max-width: 1260px; margin: 0 auto; padding: 28px 16px 40px; }
.sheet { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 30px 32px; }
.box { background: var(--soft); border: 1px solid var(--line); border-radius: 12px; padding: 20px 22px; margin-bottom: 18px; }
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.cols .box { margin-bottom: 18px; }
dl { display: grid; grid-template-columns: 130px 1fr; gap: 8px 14px; margin: 0; } dt { color: var(--muted); }
.back { display: inline-block; margin-bottom: 10px; font-size: 14px; }

/* ---------------------------------------------------------------- ฟอร์ม / ปุ่ม */
form label { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; font-size: 14px; color: #374151; }
input, select { font: inherit; padding: 10px 14px; border: 1px solid #d1d5db; border-radius: 8px; background: #fff;
  color: var(--ink); min-height: 44px; }
input:focus, select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(59, 130, 246, .18); }
input::placeholder { color: #9ca3af; }
button, .btn { font: inherit; font-weight: 700; background: var(--primary); color: #fff; border: 0; border-radius: 8px;
  padding: 10px 22px; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; min-height: 44px; }
button:hover, .btn:hover { background: var(--primary-d); text-decoration: none; }
button.success { background: var(--success); } button.success:hover { background: var(--success-d); }
button.secondary, .btn.secondary { background: #fff; color: var(--ink); border: 1px solid var(--outline); }
button.secondary:hover, .btn.secondary:hover { background: var(--soft); }
button.danger { background: var(--danger); color: #fff; } button.danger:hover { background: var(--danger-d); }
.btn.small, button.small { padding: 5px 12px; font-size: 13px; min-height: 0; font-weight: 600; }
.row { display: flex; gap: 16px; flex-wrap: wrap; } .row label { flex: 1; min-width: 200px; }
.row label.grow { flex: 2; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 4px; }
.actions.center { justify-content: center; }
form.sub { border-top: 1px dashed var(--line); padding-top: 14px; margin-top: 14px; }
form.sub:first-of-type { border-top: 0; padding-top: 0; margin-top: 0; }
form.inline { display: inline-flex; gap: 6px; }
form.inline button { padding: 5px 12px; min-height: 0; font-size: 13px; }
details summary { cursor: pointer; color: var(--primary-d); font-weight: 600; margin: 8px 0; }
details[open] summary { margin-bottom: 14px; }
a.card { color: var(--ink); } a.card:hover { text-decoration: none; border-color: var(--primary); }
.btn.danger-link { background: var(--bad-bg); color: var(--bad); } .btn.danger-link:hover { background: #fcd4d4; }
form.review input { min-height: 36px; padding: 6px 10px; font-size: 13px; width: 100%; margin-bottom: 6px; }
.grid tr.inactive td { color: var(--muted); background: #fafafa; }
form.inline-edit { display: flex; gap: 6px; }
form.inline-edit input { min-height: 36px; padding: 6px 10px; font-size: 13px; width: 100%; }
.pw-code { font-size: 20px; font-weight: 700; letter-spacing: 1px; background: #fff; padding: 2px 10px; border-radius: 6px; }
.alert { background: var(--bad-bg); color: var(--bad); padding: 10px 14px; border-radius: 8px; }

/* ---------------------------------------------------------------- หน้าเข้าสู่ระบบ */
body.auth { background: radial-gradient(1200px 600px at 10% 0%, #e8eefc 0%, transparent 60%),
  radial-gradient(900px 500px at 100% 100%, #fdf3d7 0%, transparent 55%), var(--bg); }
body.auth main { flex: 1; display: flex; align-items: center; justify-content: center; padding-top: 32px; }
.auth-wrap { display: grid; grid-template-columns: 1.1fr 1fr; width: 100%; max-width: 940px; background: var(--panel);
  border-radius: 18px; overflow: hidden; box-shadow: 0 20px 45px rgba(15, 23, 42, .12), 0 2px 6px rgba(15, 23, 42, .06); }
.auth-hero { position: relative; background: linear-gradient(135deg, var(--dark1) 0%, var(--dark2) 100%); color: #e2e8f0;
  padding: 44px 40px; border-right: 4px solid var(--gold); }
.auth-hero::after { content: ""; position: absolute; inset: auto -60px -60px auto; width: 220px; height: 220px; border-radius: 50%;
  background: radial-gradient(circle, rgba(212, 160, 23, .25), transparent 70%); pointer-events: none; }
.auth-hero .medal { width: 58px; height: 72px; margin-bottom: 18px; filter: drop-shadow(0 4px 8px rgba(0, 0, 0, .3)); }
.auth-hero .eyebrow { margin: 0 0 6px; font-size: 14px; letter-spacing: .3px; color: #c7d2fe; }
.auth-hero h1 { display: block; color: #fff; font-size: 28px; line-height: 1.35; margin: 0 0 14px; }
.year-badge { display: inline-block; margin: 0 0 26px; padding: 4px 14px; border-radius: 999px; background: var(--gold);
  color: #1f2937; font-weight: 700; font-size: 14px; }
.auth-points { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; font-size: 15px; }
.auth-points li { padding-left: 26px; position: relative; }
.auth-points li::before { content: "✓"; position: absolute; left: 0; top: 0; width: 18px; height: 18px; border-radius: 50%;
  background: rgba(212, 160, 23, .25); color: #fcd34d; font-size: 12px; font-weight: 700; display: grid; place-items: center;
  margin-top: 3px; }
.auth-card { padding: 44px 40px; display: flex; flex-direction: column; justify-content: center; }
.auth-card h2 { font-size: 24px; margin: 0 0 4px; }
.auth-card > .muted { margin: 0 0 22px; }
.auth-card form label > span:first-child { font-weight: 600; }
.pw { position: relative; display: block; }
.pw input { width: 100%; padding-right: 72px; }
.pw-toggle { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); min-height: 0; padding: 6px 12px;
  font-size: 13px; background: #eef0f3; color: var(--ink); }
.pw-toggle:hover { background: #e3e6ea; }
.auth-submit { width: 100%; margin: 6px 0 16px; font-size: 16px; min-height: 48px; }

/* ---------------------------------------------------------------- ตาราง / ป้าย */
.table-wrap { border: 1px solid var(--line); border-radius: 12px; overflow-x: auto; background: var(--panel); }
.grid { width: 100%; border-collapse: collapse; background: var(--panel); }
.grid th, .grid td { padding: 14px 16px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.grid thead th { background: var(--soft); font-weight: 700; color: var(--ink); border-bottom: 2px solid var(--line);
  white-space: nowrap; }
.grid tbody tr:last-child td { border-bottom: 0; }
.grid tbody tr:hover td { background: #fafbfc; }
.grid td.num, .grid th.num { text-align: right; }
.grid tr.issue td { background: #fff5f5; }
.box .table-wrap { margin-top: 6px; }

.badge { display: inline-block; background: var(--badge); color: var(--badge-ink); font-weight: 700; border-radius: 6px;
  padding: 3px 9px; white-space: nowrap; }
.badge.big { font-size: 18px; padding: 4px 12px; }
.tag { display: inline-block; background: #eef0f3; color: var(--ink); border-radius: 999px; padding: 1px 9px; font-size: 12px; }
.tag.warn { background: var(--warn-bg); color: var(--warn); } .tag.bad { background: var(--bad-bg); color: var(--bad); }
.st { font-size: 12px; font-weight: 600; border-radius: 999px; padding: 2px 10px; background: #eef0f3; white-space: nowrap; }
.st.rejected { background: var(--bad-bg); color: var(--bad); }
.st.confirmed { background: var(--ok-bg); color: var(--ok); } .st.filled { background: #e0ecff; color: var(--primary-d); }
.bar { display: inline-block; width: 110px; height: 8px; background: #eef0f3; border-radius: 99px; overflow: hidden;
  vertical-align: middle; margin-right: 6px; } .bar i { display: block; height: 100%; background: var(--success); }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 22px; }
.card { background: var(--bg); border: 1px solid var(--line); border-top: 4px solid var(--gold); border-radius: 10px;
  padding: 16px 18px; box-shadow: 0 2px 4px rgba(0, 0, 0, .02); }
.card b { display: block; font-size: 26px; } .card span { color: var(--muted); font-size: 13px; }
.card.warn { border-top-color: #f59e0b; } .card.warn b { color: var(--warn); }
.card.bad { border-top-color: var(--danger); } .card.bad b { color: var(--bad); }
.card.ok { border-top-color: var(--success); }

.tabs { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 16px; }
.tabs a { padding: 7px 14px; border-radius: 8px; background: #eef0f3; color: var(--ink); font-weight: 600; font-size: 14px; }
.tabs a:hover { background: #e3e6ea; text-decoration: none; }
.tabs a.on { background: var(--primary); color: #fff; }
.tabs a span { opacity: .75; font-weight: 400; margin-left: 3px; }
.search { margin-left: auto; } .search input { width: 260px; }

.note { padding: 10px 14px; border-radius: 8px; background: #eef0f3; margin: 0 0 14px; }
.note.warn { background: var(--warn-bg); color: var(--warn); } .note.ok { background: var(--ok-bg); color: var(--ok); }

/* กรอบแบบฟอร์ม — เรียงช่องตามฟอร์ม Access (สิ่งที่จะส่ง ตร.) */
.form-card { background: var(--panel); border: 1px solid #c7d2fe; }
.form-title { text-align: center; color: #9f1239; font-size: 18px; border: 1px solid #fecdd3; background: #fff7f8;
  border-radius: 8px; padding: 8px 12px; margin: 0 auto 18px; width: fit-content; max-width: 100%; }
.sub-title { font-size: 14px; font-weight: 700; margin: 18px 0 10px; padding-top: 14px; border-top: 1px dashed var(--line);
  text-decoration: underline; text-underline-offset: 3px; }
.formgrid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px 14px; }
.formgrid .f { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.formgrid .f.w2 { grid-column: span 2; }
.formgrid .f > span { font-size: 13px; font-weight: 700; color: #1d4ed8; }
.formgrid .v { border: 1px solid #d1d5db; border-radius: 8px; background: #fff; padding: 9px 12px; min-height: 44px;
  overflow-wrap: anywhere; }
.formgrid .v i { color: #9ca3af; font-style: normal; }

@media (max-width: 760px) {
  .auth-wrap { grid-template-columns: 1fr; } .auth-hero { border-right: 0; border-bottom: 4px solid var(--gold); padding: 28px 22px; }
  .auth-hero h1 { font-size: 22px; } .auth-points { display: none; } .auth-card { padding: 28px 22px; }
  body.auth main { padding-top: 16px; }
  .formgrid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .topbar { padding: 10px 16px; }
  main { padding: 16px 12px 28px; }
  .sheet { padding: 20px 16px; }
  h1.center { font-size: 22px; }
  .cols { grid-template-columns: 1fr; } .search { margin-left: 0; width: 100%; } .search input { width: 100%; }
  .grid th, .grid td { padding: 10px; font-size: 13px; }
  .grid.hide2 th:nth-child(2), .grid.hide2 td:nth-child(2) { display: none; }
  dl { grid-template-columns: 110px 1fr; }
}

/* ไม่ประสงค์ขอรับพระราชทาน */
.st.declined { background: #f1e8ff; color: #6b21a8; }
.note.declined { background: #f5efff; color: #5b1a91; }
details.decline { margin-top: 14px; border-top: 1px dashed var(--line); padding-top: 12px; }
details.decline summary { cursor: pointer; color: #6b21a8; font-weight: 600; }
details.decline[open] summary { margin-bottom: 8px; }
/* หน้าวิธีใช้ */
.help .toc { text-align: center; margin: 0 0 18px; line-height: 2; }
.help section.box ul { margin: 6px 0; padding-left: 22px; } .help section.box li { margin: 4px 0; }
.help .grid td:first-child { white-space: nowrap; width: 1%; }
.help dl.faq dt { font-weight: 600; margin-top: 10px; } .help dl.faq dd { margin: 2px 0 0 18px; color: var(--muted); }
.help section.box { scroll-margin-top: 80px; }
