
:root{
  --blue-900:#0b2f6b;
  --blue-800:#124b9f;
  --blue-700:#155eef;
  --blue-600:#2d72f3;
  --blue-500:#4b86f7;
  --blue-100:#eaf2ff;
  --blue-50:#f5f9ff;
  --white:#ffffff;
  --text:#173055;
  --muted:#6b7c93;
  --line:#d9e6f7;
  --success:#0b8f55;
  --warning:#c76a00;
  --shadow:0 14px 36px rgba(21,94,239,.10);
}
*{box-sizing:border-box}
html{-webkit-text-size-adjust:100%;scroll-behavior:smooth}
body{
  margin:0;
  min-height:100vh;
  color:var(--text);
  font-family:"Sarabun","Noto Sans Thai",Tahoma,sans-serif;
  background:
    radial-gradient(circle at top right, rgba(75,134,247,.16), transparent 30%),
    linear-gradient(180deg,#f8fbff 0%,#eef5ff 100%);
}
button,input,select,textarea{font:inherit}
button{touch-action:manipulation}
header{
  position:relative;
  overflow:hidden;
  color:#fff;
  padding:34px 18px 38px;
  background:linear-gradient(135deg,var(--blue-900) 0%,var(--blue-700) 60%,#6fa1ff 100%);
  box-shadow:0 10px 30px rgba(18,75,159,.22);
}
header:before,header:after{
  content:"";
  position:absolute;
  border-radius:50%;
  background:rgba(255,255,255,.10);
}
header:before{width:260px;height:260px;right:-80px;top:-110px}
header:after{width:160px;height:160px;right:180px;bottom:-100px}
.wrap{max-width:1200px;margin:auto;position:relative;z-index:1}
.brand-row{display:flex;align-items:center;gap:16px}
.brand-icon{
  width:58px;height:58px;display:grid;place-items:center;
  border-radius:18px;background:rgba(255,255,255,.16);
  border:1px solid rgba(255,255,255,.35);
  box-shadow:inset 0 1px 0 rgba(255,255,255,.35);
  font-size:30px
}
h1{margin:0 0 5px;font-size:clamp(27px,4vw,42px);line-height:1.2}
.sub{opacity:.92;font-size:15px;line-height:1.7;max-width:850px}
main{max-width:1200px;margin:22px auto;padding:0 14px 56px}
.grid{display:grid;grid-template-columns:420px minmax(0,1fr);gap:20px;align-items:start}
.card{
  background:rgba(255,255,255,.95);
  border:1px solid rgba(217,230,247,.95);
  border-radius:22px;
  padding:22px;
  box-shadow:var(--shadow);
  backdrop-filter:blur(10px)
}
.left{position:sticky;top:16px}
h2{
  margin:0 0 16px;
  color:var(--blue-900);
  font-size:22px;
  display:flex;align-items:center;gap:9px
}
h2:before{
  content:"";width:6px;height:24px;border-radius:999px;
  background:linear-gradient(180deg,var(--blue-500),var(--blue-700))
}
label{display:block;font-weight:700;color:#284a76;margin:12px 0 7px}
select,input,textarea{
  width:100%;
  min-height:46px;
  color:var(--text);
  font-size:16px;
  padding:11px 12px;
  border:1px solid var(--line);
  border-radius:12px;
  background:#fff;
  outline:none;
  transition:.2s ease;
  box-shadow:0 2px 8px rgba(21,94,239,.03)
}
select:focus,input:focus,textarea:focus{
  border-color:var(--blue-500);
  box-shadow:0 0 0 4px rgba(75,134,247,.14)
}
textarea{resize:vertical}
.row{display:grid;grid-template-columns:1fr 1fr;gap:12px}
.actions{display:flex;gap:10px;flex-wrap:wrap;margin-top:16px}
button{
  border:0;border-radius:12px;padding:11px 15px;
  font-weight:800;cursor:pointer;min-height:46px;
  transition:.18s ease;box-shadow:0 6px 14px rgba(21,94,239,.08)
}
button:hover{transform:translateY(-1px)}
.p{
  color:#fff;
  background:linear-gradient(135deg,var(--blue-700),var(--blue-500));
  box-shadow:0 9px 20px rgba(21,94,239,.24)
}
.p:hover{filter:brightness(.98)}
.s{background:var(--blue-100);color:var(--blue-800)}
.g{background:#f7f9fc;color:#3c5373;border:1px solid #e5edf7}
.list{
  max-height:520px;overflow:auto;
  border:1px solid var(--line);
  border-radius:16px;
  background:linear-gradient(180deg,#fff,#fbfdff);
  scrollbar-width:thin;
  scrollbar-color:#bdd1f3 transparent
}
.list::-webkit-scrollbar{width:8px}
.list::-webkit-scrollbar-thumb{background:#bdd1f3;border-radius:999px}
.item{
  display:flex;gap:11px;padding:13px 12px;
  border-bottom:1px solid #edf3fb;
  transition:.16s ease
}
.item:hover{background:#f5f9ff}
.item:last-child{border-bottom:0}
.item input{width:21px;height:21px;flex:0 0 auto;accent-color:var(--blue-700)}
.code{font-weight:900;color:var(--blue-800)}
.badge{
  display:inline-block;
  font-size:12px;font-weight:800;padding:3px 8px;border-radius:999px;
  background:#e8f8f0;color:var(--success);margin-left:4px
}
.badge.final{background:#fff1df;color:var(--warning)}
.ksac{display:grid;grid-template-columns:1fr 1fr;gap:14px}
.box{
  border:1px solid var(--line);
  border-radius:16px;
  padding:14px;
  background:#fff;
  box-shadow:0 8px 18px rgba(23,48,85,.04)
}
.box h3{margin:0 0 10px;font-size:18px}
.k{border-top:5px solid #f7a91f}
.sk{border-top:5px solid #18b56c}
.a{border-top:5px solid #8d67eb}
.c{border-top:5px solid #2d72f3}
.preview{
  position:relative;
  margin-top:18px;
  padding:30px;
  font-family:"TH Sarabun New","Sarabun",sans-serif;
  font-size:19px;
  line-height:1.82;
  background:#fff;
  border:1px solid var(--line);
  border-radius:18px;
  box-shadow:0 10px 28px rgba(21,94,239,.06)
}
.preview:before{
  content:"";
  position:absolute;left:0;top:0;bottom:0;width:6px;
  border-radius:18px 0 0 18px;
  background:linear-gradient(180deg,var(--blue-500),var(--blue-700))
}
.center{text-align:center}
.muted{color:var(--muted);font-size:13px;line-height:1.6}
.empty{padding:22px;text-align:center;color:var(--muted)}
#result{animation:fadeUp .35s ease}
@keyframes fadeUp{from{opacity:0;transform:translateY(8px)}to{opacity:1;transform:none}}
@media(max-width:980px){
  .grid{grid-template-columns:1fr}
  .left{position:static}
  .list{max-height:390px}
}
@media(max-width:640px){
  header{padding:26px 14px 30px}
  .brand-row{align-items:flex-start}
  .brand-icon{width:48px;height:48px;border-radius:14px;font-size:24px}
  .sub{font-size:14px}
  main{padding:0 9px 90px}
  .card{padding:15px;border-radius:17px}
  .row,.ksac{grid-template-columns:1fr}
  .actions{display:grid;grid-template-columns:1fr 1fr}
  .actions button{width:100%;padding:10px 8px}
  .preview{padding:18px 15px;font-size:17px;line-height:1.7}
}
@media(max-width:420px){
  .actions{grid-template-columns:1fr}
  h1{font-size:26px}
}
@media print{
  body{background:#fff}
  header,.left,.actions,.filters{display:none!important}
  main{margin:0;padding:0;max-width:none}
  .grid{display:block}
  .card{border:0;box-shadow:none;padding:0}
  .preview{border:0;box-shadow:none;font-size:18pt;padding:0}
  .preview:before{display:none}
}
