/* ============ Polish layer: typography · motion · popups · toasts ============ */
:root {
  --font: 'Noto Sans Thai', 'Leelawadee UI', Tahoma, sans-serif;
  --font-h: 'Prompt', 'Noto Sans Thai', sans-serif;
  --ease: cubic-bezier(.2, .8, .2, 1);
  --spring: cubic-bezier(.34, 1.56, .64, 1);
}
body { font-family: var(--font); font-size: 15px; letter-spacing: .005em; }
h1, h2, h3, .brand b, .cta, .btn.primary, .kpi .v, .ms .v, .totals .g, .qno, .auth-hero h2, .auth h1, .modal-box h3, .toast-t, .cel h3 {
  font-family: var(--font-h); letter-spacing: 0;
}
.page h2 { font-size: 27px; font-weight: 600; line-height: 1.3; }
.card h3 { font-weight: 600; }
.kpi .v, .ms .v { font-weight: 600; }
.qno { font-weight: 600 !important; }
.btn { font-weight: 500; }
.btn.primary, .cta { font-weight: 600; }
::selection { background: var(--red-m); }

/* ---- page enter: staggered fade-up ---- */
@keyframes up { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
.page { animation: none; }
.page > *, .editor > div > .card, .editor > div > #check, .editor > div > .savebar { animation: up .5s var(--ease) both; }
.page > *:nth-child(2) { animation-delay: .05s; } .page > *:nth-child(3) { animation-delay: .1s; }
.page > *:nth-child(4) { animation-delay: .15s; } .page > *:nth-child(5) { animation-delay: .2s; }
.editor > div > .card:nth-child(2) { animation-delay: .08s; } .editor > div > .card:nth-child(3) { animation-delay: .14s; } .editor > div > .card:nth-child(4) { animation-delay: .2s; }
.mini-stats > *, .kpis > * { animation: up .55s var(--ease) both; }
.mini-stats > *:nth-child(2), .kpis > *:nth-child(2) { animation-delay: .06s; }
.mini-stats > *:nth-child(3), .kpis > *:nth-child(3) { animation-delay: .12s; }
.mini-stats > *:nth-child(4), .kpis > *:nth-child(4) { animation-delay: .18s; }
#tb tr { animation: up .4s var(--ease) both; }
#tb tr:nth-child(2) { animation-delay: .03s; } #tb tr:nth-child(3) { animation-delay: .06s; } #tb tr:nth-child(4) { animation-delay: .09s; }
#tb tr:nth-child(5) { animation-delay: .12s; } #tb tr:nth-child(n+6) { animation-delay: .15s; }

/* ---- skeleton loading ---- */
@keyframes shimmer { from { background-position: -600px 0; } to { background-position: 600px 0; } }
.sk { border-radius: 12px; background: linear-gradient(90deg, #efe9e5 0%, #f8f4f1 40%, #efe9e5 80%); background-size: 1200px 100%; animation: shimmer 1.3s linear infinite; }
.sk-wrap { display: grid; gap: 14px; }
.sk-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
@media (max-width: 900px) { .sk-row { grid-template-columns: 1fr 1fr; } }

/* ---- hover / press micro-interactions ---- */
.btn { position: relative; overflow: hidden; transition: background .18s, border-color .18s, transform .18s var(--spring), box-shadow .2s; }
.btn:active { transform: scale(.97); }
.btn.primary:hover { transform: translateY(-1px); box-shadow: 0 8px 20px rgba(208,17,43,.32); }
.btn .rip { position: absolute; border-radius: 50%; transform: scale(0); background: currentColor; opacity: .18; pointer-events: none; animation: rip .55s var(--ease) forwards; }
@keyframes rip { to { transform: scale(2.6); opacity: 0; } }
.kpi, .ms, .card.share { transition: transform .25s var(--ease), box-shadow .25s; }
.kpi:hover, .ms:hover { transform: translateY(-3px); box-shadow: var(--sh-2); }
.snav a { transition: background .2s, color .2s, transform .2s var(--ease); }
.snav a:not(.on):hover { transform: translateX(3px); }
.snav a.on { animation: navin .35s var(--spring); }
@keyframes navin { from { transform: scale(.94); opacity: .6; } }
.cta { transition: transform .2s var(--spring), box-shadow .2s; }
.cta:active { transform: scale(.97); }
table.list tr.click td { transition: background .15s; }
table.list tr.flash td { animation: flash 1s ease; }
@keyframes flash { 0% { background: #fff4c2; } 100% { background: transparent; } }
select.st { transition: background .25s, color .25s; }
input, select, textarea { transition: border-color .18s, box-shadow .18s, background .18s; }
.toggle button { transition: background .2s, color .2s, box-shadow .2s; }
.items tbody tr { animation: up .3s var(--ease) both; }
.totals .g span:last-child { display: inline-block; transition: color .2s; }
.bump { animation: bump .45s var(--spring); }
@keyframes bump { 40% { transform: scale(1.12); } }

/* chart grow */
.bars .b { transform-origin: bottom; animation: grow .8s var(--ease) both; animation-delay: calc(var(--i, 0) * .045s + .15s); }
@keyframes grow { from { transform: scaleY(0); } }

/* ---- auth ---- */
.auth-hero img { animation: float 5s ease-in-out infinite; }
@keyframes float { 50% { transform: translateY(-8px) rotate(-2deg); } }
.auth-hero .blob { position: absolute; border-radius: 50%; filter: blur(50px); opacity: .5; pointer-events: none; animation: drift 14s ease-in-out infinite alternate; }
.auth-hero .blob.b1 { width: 340px; height: 340px; background: #ffc531; left: -80px; bottom: -60px; }
.auth-hero .blob.b2 { width: 280px; height: 280px; background: #ff5a6e; right: -60px; top: 30%; animation-duration: 18s; }
@keyframes drift { to { transform: translate(40px, -50px) scale(1.15); } }
.auth-hero > div { position: relative; z-index: 1; }
.auth-hero h2 { font-weight: 700; font-size: 42px; }
.auth-hero li { animation: up .6s var(--ease) both; }
.auth-hero li:nth-child(2) { animation-delay: .1s; } .auth-hero li:nth-child(3) { animation-delay: .2s; }
.auth h1 { font-weight: 600; font-size: 30px; }
.auth { display: flex; flex-direction: column; }
.auth .err { order: 5; text-align: center; margin: 12px 0 0; min-height: 0; } .auth .err:empty { display: none; }
.auth .after { order: 6; }
.auth .err:not(:empty) { background: var(--bad-l); border-radius: 10px; padding: 9px 12px; }
.auth .field { position: relative; }
.auth .field .ic { position: absolute; left: 13px; top: 12px; color: var(--faint); transition: color .2s; }
.auth .field input { padding-left: 40px; min-height: 46px; }
.auth .field:focus-within .ic { color: var(--red); }
.auth .btn.primary { min-height: 48px; font-size: 16px; }
.auth .shake { animation: shake .4s; }
@keyframes shake { 20%, 60% { transform: translateX(-7px); } 40%, 80% { transform: translateX(7px); } }

/* ---- modal: spring in, slide out, bottom sheet on phones ---- */
.modal { animation: fade .2s ease; }
.modal-box { animation: modalin .38s var(--spring); }
@keyframes modalin { from { opacity: 0; transform: translateY(18px) scale(.94); } }
.modal.closing { animation: fadeout .18s ease forwards; }
.modal.closing .modal-box { animation: modalout .18s ease forwards; }
@keyframes fadeout { to { opacity: 0; } }
@keyframes modalout { to { opacity: 0; transform: translateY(10px) scale(.97); } }
.modal-box .x { position: absolute; right: 14px; top: 14px; width: 34px; height: 34px; border-radius: 50%; border: 0; background: var(--line-2); cursor: pointer; font-size: 16px; color: var(--muted); }
.modal-box .x:hover { background: var(--line); color: var(--ink); }
.modal-box { position: relative; }
@media (max-width: 700px) {
  .modal { place-items: end center; padding: 0; }
  .modal-box { border-radius: 22px 22px 0 0; max-height: 90vh; padding: 26px 18px calc(18px + env(safe-area-inset-bottom)); animation: sheetin .42s var(--ease); }
  .modal-box::before { content: ''; position: absolute; top: 8px; left: 50%; width: 40px; height: 5px; margin-left: -20px; border-radius: 9px; background: #ddd5d0; }
  .modal.closing .modal-box { animation: sheetout .22s ease forwards; }
  @keyframes sheetin { from { transform: translateY(100%); } }
  @keyframes sheetout { to { transform: translateY(100%); } }
}

/* confirm dialog */
.dlg { text-align: center; max-width: 420px; }
.dlg .dico { width: 60px; height: 60px; margin: 4px auto 12px; border-radius: 50%; display: grid; place-items: center; font-size: 28px; background: var(--warn-l); }
.dlg.danger .dico { background: var(--bad-l); }
.dlg h3 { margin-bottom: 6px !important; }
.dlg p { color: var(--muted); margin: 0 0 18px; }
.dlg .modal-actions { justify-content: center; border: 0; padding-top: 0; }
.dlg .modal-actions .btn { min-width: 120px; }
.btn.danger-fill { background: var(--bad); border-color: var(--bad); color: #fff; font-weight: 600; }

/* ---- toasts: stacked, top-right, with progress ---- */
.toast { display: none !important; }
.toasts { position: fixed; top: 18px; right: 18px; z-index: 70; display: flex; flex-direction: column; gap: 10px; pointer-events: none; width: min(380px, calc(100vw - 24px)); }
.tst { pointer-events: auto; position: relative; overflow: hidden; display: flex; gap: 12px; align-items: flex-start; background: rgba(255,255,255,.97); backdrop-filter: blur(12px);
  border: 1px solid var(--line); border-radius: 14px; padding: 13px 14px 15px; box-shadow: 0 14px 40px rgba(28,25,23,.16); animation: tin .45s var(--spring); }
.tst.out { animation: tout .3s var(--ease) forwards; }
@keyframes tin { from { opacity: 0; transform: translateX(40px) scale(.95); } }
@keyframes tout { to { opacity: 0; transform: translateX(40px); height: 0; padding: 0; margin-top: -10px; } }
.tst .ti { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; flex: none; color: #fff; font-weight: 700; font-size: 15px; background: #22c55e; box-shadow: 0 4px 10px rgba(34,197,94,.35); }
.tst.bad .ti { background: #ef4444; box-shadow: 0 4px 10px rgba(239,68,68,.35); }
.tst.info .ti { background: #3b82f6; box-shadow: 0 4px 10px rgba(59,130,246,.35); }
.tst .toast-t { font-weight: 600; font-size: 14.5px; line-height: 1.35; }
.tst .tm { font-size: 13.5px; color: var(--muted); margin-top: 1px; }
.tst .tx { margin-left: auto; border: 0; background: none; color: var(--faint); cursor: pointer; font-size: 16px; padding: 0 2px; }
.tst .tp { position: absolute; left: 0; bottom: 0; height: 3px; background: #22c55e; animation: tp linear forwards; transform-origin: left; width: 100%; }
.tst.bad .tp { background: #ef4444; } .tst.info .tp { background: #3b82f6; }
@keyframes tp { to { transform: scaleX(0); } }
@media (max-width: 900px) {
  .toasts { top: 66px; right: 50%; transform: translateX(50%); }
  @keyframes tin { from { opacity: 0; transform: translateY(-20px) scale(.95); } }
  @keyframes tout { to { opacity: 0; transform: translateY(-20px); height: 0; padding: 0; margin-top: -10px; } }
}

/* ---- celebration after issuing a quote ---- */
.cel { text-align: center; max-width: 460px; overflow: hidden; }
.cel .badge { width: 84px; height: 84px; margin: 6px auto 14px; border-radius: 50%; display: grid; place-items: center; background: linear-gradient(135deg, #22c55e, #15803d);
  color: #fff; font-size: 40px; box-shadow: 0 12px 30px rgba(21,128,61,.35); animation: badge .7s var(--spring) .1s both; }
@keyframes badge { from { transform: scale(0) rotate(-40deg); } }
.cel h3 { font-size: 22px !important; margin-bottom: 4px !important; }
.cel .qn { font-family: var(--font-h); font-size: 26px; font-weight: 700; color: var(--red); letter-spacing: .02em; margin: 2px 0 2px; }
.cel p { color: var(--muted); margin: 0 0 18px; }
.cel .acts { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.cel .acts .btn { min-height: 46px; }
.cel .acts .full { grid-column: 1 / -1; }
.confetti { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.confetti i { position: absolute; top: -12px; width: 8px; height: 14px; border-radius: 2px; opacity: 0; animation: fall 1.6s var(--ease) forwards; }
@keyframes fall { 0% { opacity: 1; transform: translate(0, 0) rotate(0); } 100% { opacity: 0; transform: translate(var(--dx), 360px) rotate(var(--r)); } }

/* ---- small polish ---- */
.empty .big { animation: float 4s ease-in-out infinite; display: inline-block; }
.eye { animation: up .4s var(--ease) both; }
.avatar { font-family: var(--font-h); background: linear-gradient(135deg, #ffd45e, #ffb800); }
.me { transition: background .2s; }
.share .qr { animation: float 5s ease-in-out infinite; }
.savebar { transition: box-shadow .3s; }
.preview .qdoc { transition: transform .3s var(--ease); }
input[type=number] { font-variant-numeric: tabular-nums; }
.page-head .sub { font-size: 14.5px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
}

/* ============ Alignment & balance ============ */
/* เนื้อหาอยู่กึ่งกลางพื้นที่ทางขวาของเมนู บนจอกว้าง */
.page { max-width: none; --gutter: max(32px, calc((100vw - var(--side) - 1360px) / 2)); padding-left: var(--gutter); padding-right: var(--gutter); }
@media (max-width: 900px) { .page { --gutter: 14px; } }

/* page head: หัวข้อกับปุ่มอยู่แนวเดียวกัน */
.page-head { align-items: center; margin-bottom: 20px; }
.page-head .btn { min-height: 42px; }
.page-head > div:first-child { min-width: 0; }

/* checkbox ทั่วไป: กล่องกับข้อความอยู่กึ่งกลางกัน */
.checkbox { align-items: center; line-height: 1.4; }
.checkbox input { margin: 0; flex: none; }
.modal-box .checkbox, .status-box .checkbox { align-items: flex-start; }
.modal-box .checkbox input, .status-box .checkbox input { margin-top: 2px; }

/* toolbar: ทุกช่องสูงเท่ากัน 40px และเรียงกึ่งกลาง */
.toolbar { align-items: center; padding: 10px; gap: 10px; }
.toolbar select, .toolbar input[type=search] { min-height: 40px; height: 40px; }
.toolbar .search .ic { top: 50%; transform: translateY(-50%); }
.toolbar .checkbox { height: 40px; padding: 0 14px; border: 1px solid #ddd6d2; border-radius: var(--r-sm); background: #fff; white-space: nowrap; gap: 8px; cursor: pointer; transition: background .18s, border-color .18s, color .18s; user-select: none; }
.toolbar .checkbox:hover { border-color: #cbc2bd; }
.toolbar .checkbox:has(input:checked) { background: var(--red-l); border-color: var(--red-m); color: var(--red); font-weight: 600; }

/* การ์ดสรุป: ความสูงเท่ากัน ตัวเลขชิดแนวเดียวกัน */
.mini-stats > .ms, .kpis > .kpi { height: 100%; }
.ms { display: flex; flex-direction: column; justify-content: center; padding: 14px 18px 14px 20px; }
.ms .l, .kpi .l { line-height: 1.3; }
.ms .v, .kpi .v { line-height: 1.35; margin: 3px 0 1px; }
.kpi { align-items: center; }

/* ตาราง: ทุกเซลล์กึ่งกลางแนวตั้ง หัวคอลัมน์ตรงกับข้อมูล */
table.list th, table.list td { vertical-align: middle; }
table.list th:first-child, table.list td:first-child { padding-left: 20px; }
table.list th:last-child, table.list td:last-child { padding-right: 20px; }
table.list td[data-k=st] select.st { display: block; }
table.list td[data-k=eye] { white-space: nowrap; }

/* ปุ่มทุกแบบ: ไอคอนกับข้อความกึ่งกลาง */
.btn { line-height: 1.2; }
.btn .ic { margin-top: -1px; }

/* ฟอร์ม: toggle สูงเท่าช่องกรอก */
.toggle { height: 42px; align-items: stretch; }
.toggle button { display: flex; align-items: center; padding: 0 20px; }
label.f > .row { flex-wrap: nowrap; }

/* แถบหัวหน้าดูใบ */
.viewbar { align-items: center; row-gap: 10px; }
.viewbar h2 { line-height: 1.2; }
.viewbar .btn { min-height: 42px; }

/* ส่วนเงื่อนไข/ยอดรวมใน editor */
.totals { margin-right: 0; }
.savebar { justify-content: space-between; }

/* เมนูซ้าย: ไอคอนกับข้อความตรงกัน */
.snav a { min-height: 42px; }
.snav a .ic { margin-top: -1px; }
.cta { min-height: 46px; }
.brand { align-items: center; }
.brand > div { line-height: 1.25; }
.items th { white-space: nowrap; }
.items th:nth-child(5) { text-align: right; }
.toggle button { min-width: 72px; justify-content: center; }

/* ============ Version + update notice ============ */
.ver { position: relative; z-index: 1; display: flex; align-items: center; justify-content: center; gap: 6px; margin-top: 8px; font-size: 12px; color: rgba(255,255,255,.7);
  background: none; border: 0; cursor: pointer; padding: 4px; border-radius: 8px; width: 100%; }
.ver:hover { color: #fff; background: rgba(255,255,255,.08); }
.ver b { font-family: var(--font-h); font-weight: 600; background: rgba(255,255,255,.14); padding: 1px 8px; border-radius: 999px; color: #fff; }
.ver .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--gold); box-shadow: 0 0 0 3px rgba(255,197,49,.3); animation: pulse 1.6s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 7px rgba(255,197,49,0); } }
.upbar { position: fixed; left: 50%; bottom: 24px; z-index: 65; transform: translateX(-50%); display: flex; align-items: center; gap: 14px;
  background: #1c1917; color: #fff; padding: 10px 10px 10px 18px; border-radius: 16px; box-shadow: 0 18px 50px rgba(0,0,0,.3); animation: upin .5s var(--spring); max-width: calc(100vw - 24px); }
@media (min-width: 901px) { .upbar { left: calc(50% + var(--side) / 2); } }
@keyframes upin { from { opacity: 0; transform: translate(-50%, 30px) scale(.95); } }
.upbar .rk { font-size: 22px; animation: float 2.4s ease-in-out infinite; }
.upbar .t { font-family: var(--font-h); font-weight: 600; font-size: 14.5px; line-height: 1.3; }
.upbar .s { font-size: 12.5px; opacity: .7; }
.upbar .btn { min-height: 38px; }
.upbar .btn.ghost { color: #fff; } .upbar .btn.ghost:hover { background: rgba(255,255,255,.1); }
.upbar .btn.primary { background: var(--gold); border-color: var(--gold); color: #3a2500; box-shadow: none; }
@media (max-width: 900px) { .upbar { bottom: 86px; flex-wrap: wrap; justify-content: center; text-align: center; padding: 12px; gap: 8px; } }
.changelog { max-height: 56vh; overflow: auto; margin: 0 -4px; padding: 0 4px; }
.cl-item { position: relative; padding: 0 0 18px 26px; }
.cl-item::before { content: ''; position: absolute; left: 6px; top: 8px; bottom: -6px; width: 2px; background: var(--line); }
.cl-item:last-child::before { display: none; }
.cl-item::after { content: ''; position: absolute; left: 0; top: 4px; width: 14px; height: 14px; border-radius: 50%; background: #fff; border: 3px solid var(--faint); }
.cl-item.cur::after { border-color: var(--red); background: var(--red-l); }
.cl-item h4 { margin: 0 0 4px; font-family: var(--font-h); font-weight: 600; font-size: 15px; display: flex; gap: 8px; align-items: center; }
.cl-item h4 small { font-family: var(--font); font-weight: 400; color: var(--muted); font-size: 12.5px; }
.cl-item ul { margin: 0; padding-left: 18px; color: var(--ink-2); font-size: 14px; }
.cl-item .now { font-size: 11.5px; background: var(--red); color: #fff; padding: 1px 8px; border-radius: 999px; font-family: var(--font); }
.auth .verline { order: 7; text-align: center; font-size: 12px; color: var(--faint); margin-top: 18px; }
