/* ส่วนประกอบกลางของ UI v2: ปุ่ม ช่องกรอก แผงด้านข้าง กล่องยืนยัน toast — ใช้ทุกหน้า (โหลดหลัง ui-v2.css) */

/* ปุ่มและช่องกรอกของเบราว์เซอร์ไม่สืบทอดฟอนต์ ทำให้ภาษาไทยกลายเป็นกล่องสี่เหลี่ยม */
:where(.ui2) :where(button, input, select, textarea) { font-family: inherit; }
.modal-head > .modal-icon { flex: 0 0 auto; }

/* ให้ attribute hidden ชนะ display ที่กำหนดใน class เสมอ */
.ui2 [hidden] { display: none !important; }

/* ---------- ปุ่ม ---------- */
.btn-main, .btn-ghost {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 44px; padding: 0 18px;
    border-radius: 13px; font: 600 14.5px var(--font-body); cursor: pointer; white-space: nowrap;
    transition: transform .12s, box-shadow .15s, background .15s, border-color .15s;
}
.btn-main { border: 0; color: #fff; background: linear-gradient(135deg, var(--brand), var(--brand-2)); box-shadow: 0 10px 20px -10px rgba(91, 76, 255, .8); }
.btn-main:hover { transform: translateY(-1px); box-shadow: 0 14px 24px -12px rgba(91, 76, 255, .9); }
.btn-main:active { transform: none; }
.btn-main kbd { font: 600 11px var(--font-num); padding: 2px 6px; border-radius: 6px; background: rgba(255, 255, 255, .18); }
.btn-ghost { border: 1px solid var(--line-strong); color: var(--ink-2); background: var(--surface); }
.btn-ghost:hover { border-color: var(--ink-2); color: var(--ink); }
.btn-main:disabled, .btn-ghost:disabled { opacity: .55; cursor: progress; transform: none; }
.btn-good { background: linear-gradient(135deg, #0FB57E, #0A9C88); box-shadow: 0 10px 20px -10px rgba(15, 181, 126, .8); }
.btn-bad  { background: linear-gradient(135deg, #F03E5E, #E0245E); box-shadow: 0 10px 20px -10px rgba(240, 62, 94, .8); }
.linkish { justify-self: start; border: 0; background: none; padding: 0; margin-top: 2px; font: 500 13px var(--font-body); color: var(--brand); cursor: pointer; }
.linkish:hover { text-decoration: underline; }

.mini-select select {
    height: 42px; padding: 0 34px 0 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface-2);
    font: 500 14px var(--font-body); color: var(--ink); cursor: pointer; appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 16 16'%3E%3Cpath fill='%237C819A' d='M1.6 4.6a.6.6 0 0 1 .85 0L8 10.15l5.55-5.55a.6.6 0 1 1 .85.85l-6 6a.6.6 0 0 1-.85 0l-6-6a.6.6 0 0 1 0-.85z'/%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: right 12px center;
}
.mini-select select:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 4px var(--brand-soft); }

.acts { display: inline-flex; gap: 4px; justify-content: flex-end; }
.act {
    height: 34px; min-width: 34px; padding: 0 9px; border-radius: 10px; border: 1px solid transparent; background: none;
    color: var(--muted); cursor: pointer; display: inline-flex; align-items: center; gap: 6px; font: 600 13px var(--font-body); white-space: nowrap;
}
.act:hover { background: var(--surface-2); border-color: var(--line); color: var(--ink); }
.act--good { color: var(--good); background: var(--good-soft); }
.act--good:hover { color: #fff; background: var(--good); border-color: var(--good); }
.act--bad:hover { color: var(--bad); background: var(--bad-soft); border-color: transparent; }
.more-wrap { display: flex; justify-content: center; padding: 18px; border-top: 1px solid var(--line); }

/* ---------- แผงบันทึก (drawer ด้านขวา) ---------- */
dialog.drawer {
    margin: 0 0 0 auto; height: 100dvh; max-height: 100dvh; width: min(580px, 100vw); max-width: 100vw;
    padding: 0; border: 0; border-radius: 26px 0 0 26px; background: var(--surface); color: var(--ink); box-shadow: var(--shadow-lg);
}
dialog.drawer[open] { display: flex; animation: drawer-in .26s cubic-bezier(.2, .8, .2, 1); }
dialog.drawer::backdrop { background: rgba(16, 19, 37, .42); backdrop-filter: blur(2px); }
@keyframes drawer-in { from { transform: translateX(40px); opacity: 0; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) { dialog.drawer[open], dialog.modal[open] { animation: none; } }
.drawer-form { display: flex; flex-direction: column; width: 100%; min-height: 0; }
.drawer-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; padding: 24px 28px 18px; border-bottom: 1px solid var(--line); }
.drawer-head h2 { font-size: 20px; font-weight: 700; }
.drawer-head p { font-size: 13.5px; color: var(--muted); margin-top: 2px !important; }
.drawer-body { flex: 1; overflow-y: auto; padding: 22px 28px 28px; display: grid; gap: 20px; align-content: start; overscroll-behavior: contain; }
.drawer-foot { border-top: 1px solid var(--line); padding: 14px 28px 18px; background: var(--surface); }
.drawer-actions { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; }
.drawer-actions [data-close] { margin-right: auto; }
.form-msg { color: var(--bad); font-size: 13.5px; font-weight: 500; }
.form-msg:empty { display: none; }
.drawer-foot .form-msg { margin-bottom: 10px !important; }
.is-saving .drawer-body { opacity: .7; pointer-events: none; }

/* ช่องกรอก */
.field { display: grid; gap: 6px; min-width: 0; align-content: start; }
.frow { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.flabel { display: flex; align-items: baseline; gap: 6px; font-size: 14px; font-weight: 600; color: var(--ink-2); }
.flabel em { color: var(--bad); font-style: normal; }
.flabel .opt { font-size: 12px; font-weight: 500; color: var(--muted); }
.fcount { margin-left: auto; font: 500 12px var(--font-num); color: var(--muted); }
.finput {
    width: 100%; min-height: 46px; padding: 10px 14px; border-radius: 13px; border: 1px solid var(--line-strong);
    background: var(--surface); font: 400 15px var(--font-body); color: var(--ink); transition: border-color .15s, box-shadow .15s;
}
textarea.finput { resize: vertical; line-height: 1.5; }
.finput:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 4px var(--brand-soft); }
.has-err .finput, .has-err .combo input { border-color: var(--bad); }
.has-err .finput:focus, .has-err .combo input:focus { box-shadow: 0 0 0 4px var(--bad-soft); }
.ferr { color: var(--bad); font-size: 13px; font-weight: 500; }
.ferr:empty { display: none; }
.fwarn { display: flex; gap: 6px; align-items: flex-start; padding: 8px 10px; border-radius: 10px; font-size: 13px; color: #9A5B00; background: var(--warn-soft); line-height: 1.45; }
.amount { position: relative; }
.amount input { padding-right: 38px; text-align: right; font-size: 20px; font-weight: 700; letter-spacing: -0.01em; }
.amount span { position: absolute; right: 14px; top: 50%; transform: translateY(-50%); color: var(--muted); font-weight: 600; }
.date-quick { display: flex; gap: 6px; }
.date-quick button { border: 0; background: var(--surface-2); border-radius: 8px; padding: 3px 10px; font: 500 12.5px var(--font-body); color: var(--ink-2); cursor: pointer; }
.date-quick button:hover { background: var(--brand-soft); color: var(--brand); }
.check { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; color: var(--ink-2); cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--brand); }

/* ---------- กล่องกลางจอ ---------- */
dialog.modal {
    width: min(560px, calc(100vw - 32px)); padding: 0; border: 0; border-radius: var(--r-xl);
    background: var(--surface); color: var(--ink); box-shadow: var(--shadow-lg);
}
dialog.modal--sm { width: min(420px, calc(100vw - 32px)); }
dialog.modal[open] { animation: sheet-in .22s cubic-bezier(.2, .8, .2, 1); }
dialog.modal::backdrop { background: rgba(16, 19, 37, .45); backdrop-filter: blur(3px); }
.modal-head { display: flex; align-items: flex-start; gap: 14px; padding: 22px 24px 18px; border-bottom: 1px solid var(--line); }
.modal-head > div { flex: 1; min-width: 0; }
.modal-head h2 { font-size: 18px; font-weight: 700; }
.modal-head p { font-size: 13.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.modal-icon { width: 44px; height: 44px; border-radius: 14px; display: grid; place-items: center; font-size: 21px; color: var(--c); background: var(--c-soft); flex-shrink: 0; }
.modal-body { padding: 20px 24px; display: grid; gap: 16px; }
.modal-foot { display: flex; justify-content: flex-end; align-items: center; gap: 10px; padding: 14px 24px 20px; flex-wrap: wrap; }
.modal-foot .form-msg { flex-basis: 100%; }
.confirm-body { padding: 28px 24px 8px; display: grid; justify-items: center; text-align: center; gap: 8px; }
.confirm-body h2 { font-size: 18px; font-weight: 700; margin-top: 6px; }
.confirm-body p { color: var(--ink-2); font-size: 14.5px; overflow-wrap: anywhere; }
#confirmDlg .modal-foot { justify-content: center; }
#confirmDlg .modal-foot button { min-width: 120px; }

/* ---------- Toast ---------- */
.toasts { position: fixed; z-index: 100; left: 50%; bottom: 24px; transform: translateX(-50%); display: grid; gap: 8px; justify-items: center; width: max-content; max-width: calc(100vw - 32px); pointer-events: none; }
.toast {
    display: flex; align-items: center; gap: 10px; padding: 12px 18px; border-radius: 14px; font-size: 14.5px; font-weight: 500;
    color: #fff; background: #13162B; box-shadow: var(--shadow-lg); animation: toast-in .25s cubic-bezier(.2, .8, .2, 1); pointer-events: auto;
}
.toast--good i { color: #34D399; }
.toast--warn i { color: #FBBF24; }
.toast--bad i  { color: #FB7185; }
.toast.is-out { opacity: 0; transform: translateY(8px); transition: opacity .25s, transform .25s; }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } }
/* อยู่ในแผงบันทึก: แสดงเหนือแถบปุ่มด้านล่างของแผง */
dialog .toasts { position: absolute; bottom: 104px; }
.toast > span > small { display: block; font-size: 12.5px; font-weight: 400; opacity: .8; }

/* ---------- สรุปย่อ ---------- */
.dstats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-bottom: 20px; }
.dstat {
    display: flex; align-items: center; gap: 14px; padding: 18px 20px; text-align: left; cursor: pointer;
    background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow);
    font: inherit; color: inherit; transition: border-color .15s, transform .12s, box-shadow .15s;
}
.dstat:hover { border-color: var(--line-strong); transform: translateY(-1px); }
.dstat.is-on { border-color: var(--c); box-shadow: 0 0 0 3px var(--c-soft), var(--shadow); }
.dstat-icon { width: 46px; height: 46px; border-radius: 14px; display: grid; place-items: center; font-size: 20px; flex-shrink: 0; color: var(--c); background: var(--c-soft); }
.dstat-text { display: grid; min-width: 0; }
.dstat-text > span { font-size: 13.5px; color: var(--ink-2); }
.dstat-text strong { font-size: 24px; font-weight: 700; line-height: 1.2; letter-spacing: -0.02em; }
.dstat-text small { font: 500 12.5px var(--font-num); color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dstat.is-alert .dstat-icon { animation: pulse 2s ease-in-out infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 6px var(--bad-soft); } }
@media (prefers-reduced-motion: reduce) { .dstat.is-alert .dstat-icon { animation: none; } }

@media (max-width: 1200px) {
    .dstats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 760px) {
    .dstats { gap: 10px; }
    .dstat { padding: 14px; gap: 10px; }
    .dstat-icon { width: 38px; height: 38px; font-size: 17px; border-radius: 12px; }
    .dstat-text strong { font-size: 20px; }
    .page-tools .btn-main, .page-tools .btn-ghost { flex: 1; }
    .btn-main kbd { display: none; }
    .mini-select { flex: 1; }
    .mini-select select { width: 100%; }
    .acts { width: 100%; justify-content: flex-start; flex-wrap: wrap; }
    dialog.drawer { width: 100vw; border-radius: 0; }
    .drawer-head { padding: 18px 18px 14px; }
    .drawer-body { padding: 18px; gap: 18px; }
    .drawer-foot { padding: 12px 18px calc(14px + env(safe-area-inset-bottom)); }
    .drawer-actions { display: grid; grid-template-columns: 1fr 1fr; }
    .drawer-actions .btn-main { grid-column: 1 / -1; order: -1; }
    .drawer-actions [data-close] { margin-right: 0; }
    .frow { grid-template-columns: minmax(0, 1fr); gap: 18px; }
}

/* =====================================================================
   ส่วนประกอบเพิ่มเติมสำหรับหน้าจัดการต่าง ๆ
   ===================================================================== */
.drawer-actions [data-ui-close] { margin-right: auto; }

/* ปุ่มเลือกสองทาง (radio) */
.typeseg { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; padding: 5px; margin: 0; border: 0; border-radius: 16px; background: var(--surface-2); box-shadow: inset 0 0 0 1px var(--line); }
.typeseg label { cursor: pointer; }
.typeseg input { position: absolute; opacity: 0; pointer-events: none; }
.typeseg span { display: flex; align-items: center; justify-content: center; gap: 8px; height: 44px; border-radius: 12px; font-weight: 600; color: var(--muted); transition: background .15s, color .15s, box-shadow .15s; }
.typeseg input:checked + span { background: var(--surface); color: var(--brand); box-shadow: var(--shadow-sm), 0 0 0 1px var(--line); }
.typeseg input[value="borrow"]:checked + span { color: #C46A00; }
.typeseg input:focus-visible + span { outline: 2px solid var(--brand); outline-offset: 2px; }

.btn-warn { background: linear-gradient(135deg, #F59E0B, #E58A00); box-shadow: 0 10px 20px -10px rgba(229, 138, 0, .8); }
.btn-sm { height: 38px; padding: 0 14px; border-radius: 11px; font-size: 13.5px; }
.spin { display: inline-block; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
form.inline { display: inline; margin: 0; }
.dhead { row-gap: 14px; }
.dhead .chips { width: 100%; }

.page--narrow { max-width: 1040px; }
.page--slim   { max-width: 760px; }

/* เมื่อ dstats อยู่ในการ์ดเดียวกัน (ไม่กดได้) */
.dstat.is-static { cursor: default; }
.dstat.is-static:hover { transform: none; border-color: var(--line); }
.dstats--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }

/* ป้ายเล็ก */
.badge { display: inline-flex; align-items: center; gap: 5px; height: 26px; padding: 0 10px; border-radius: 999px; font-size: 12.5px; font-weight: 600; white-space: nowrap; color: var(--ink-2); background: var(--surface-2); border: 1px solid var(--line); }
.badge--brand { color: var(--brand); background: var(--brand-soft); border-color: transparent; }
.badge--good  { color: #087A55; background: var(--good-soft); border-color: transparent; }
.badge--warn  { color: #9A5B00; background: var(--warn-soft); border-color: transparent; }
.badge--bad   { color: #B4233F; background: var(--bad-soft); border-color: transparent; }
.badge--debt  { color: #B45F00; background: var(--debt-soft); border-color: transparent; }
.badge--ink   { color: #fff; background: var(--ink); border-color: transparent; }
.mono { font-family: ui-monospace, 'SFMono-Regular', Menlo, Consolas, monospace; font-size: .92em; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* ตัวอักษรย่อของผู้ใช้ */
.avatar { width: 40px; height: 40px; border-radius: 50%; flex-shrink: 0; display: grid; place-items: center; font-weight: 700; color: var(--brand); background: var(--brand-soft); }
.avatar--lg { width: 64px; height: 64px; font-size: 26px; }
.who { display: flex; align-items: center; gap: 12px; min-width: 0; }
.who > div { min-width: 0; display: grid; line-height: 1.35; }
.who strong { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who small { font-size: 12.5px; color: var(--muted); }

/* ช่องรหัสผ่าน + ปุ่มแสดง */
.pw-wrap { position: relative; }
.pw-wrap .finput { padding-right: 48px; }
.pw-wrap button { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); width: 36px; height: 36px; border: 0; border-radius: 10px; background: none; color: var(--muted); cursor: pointer; font-size: 17px; }
.pw-wrap button:hover { color: var(--ink); background: var(--surface-2); }
.pwrules { list-style: none; margin: 0; padding: 10px 12px; display: grid; grid-template-columns: 1fr 1fr; gap: 4px 14px; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--line); font-size: 12.5px; color: var(--muted); }
.pwrules li { display: flex; align-items: center; gap: 7px; transition: color .15s; }
.pwrules li i::before { content: "\F28A"; font-size: 9px; }           /* bi-circle */
.pwrules li.is-ok { color: #087A55; font-weight: 600; }
.pwrules li.is-ok i::before { content: "\F26A"; font-size: 13px; color: var(--good); }  /* bi-check-circle-fill */
.pwrules li.is-bad { color: var(--bad); }
.pwrules li.is-bad i::before { content: "\F622"; font-size: 13px; }   /* bi-x-circle-fill */

/* กล่องข้อความแนะนำ */
.note { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: 14px; font-size: 13.5px; line-height: 1.5; color: var(--ink-2); background: var(--surface-2); border: 1px solid var(--line); }
.note > i { font-size: 17px; color: var(--brand); flex-shrink: 0; margin-top: 1px; }
.note--warn { background: var(--warn-soft); border-color: #F8E2B5; color: #7A4A00; }
.note--warn > i { color: var(--warn); }
.note--bad { background: var(--bad-soft); border-color: #F9CAD3; color: #8A1F35; }
.note--bad > i { color: var(--bad); }
.note--good { background: var(--good-soft); border-color: #BFEBD8; color: #065F43; }
.note--good > i { color: var(--good); }

/* ปุ่มเลือกไฟล์แบบลากวาง */
.dropzone { position: relative; display: grid; justify-items: center; gap: 6px; padding: 26px 18px; text-align: center; border-radius: 16px; border: 2px dashed var(--line-strong); background: var(--surface-2); cursor: pointer; transition: border-color .15s, background .15s; }
.dropzone:hover, .dropzone.is-over { border-color: var(--brand); background: var(--brand-soft); }
.dropzone input[type=file] { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.dropzone > i { font-size: 30px; color: var(--brand); }
.dropzone strong { font-weight: 600; }
.dropzone small { color: var(--muted); font-size: 12.5px; }
.dropzone.has-file { border-style: solid; border-color: var(--good); background: var(--good-soft); }
.dropzone.has-file > i { color: var(--good); }

/* อันดับ */
.rank { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 10px; }
.rank li { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 16px; border: 1px solid var(--line); background: var(--surface); }
.rank-no { width: 34px; height: 34px; border-radius: 11px; flex-shrink: 0; display: grid; place-items: center; font: 700 14px var(--font-num); color: var(--muted); background: var(--surface-2); }
.rank li:nth-child(1) .rank-no { color: #fff; background: linear-gradient(135deg, #FBBF24, #F59E0B); }
.rank li:nth-child(2) .rank-no { color: #fff; background: linear-gradient(135deg, #CBD5E1, #94A3B8); }
.rank li:nth-child(3) .rank-no { color: #fff; background: linear-gradient(135deg, #FDBA74, #F97316); }
.rank-text { flex: 1; min-width: 0; display: grid; gap: 4px; }
.rank-text strong { font-size: 14px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-text small { font-size: 12.5px; color: var(--muted); }
.rank-pct { font: 700 16px var(--font-num); color: var(--brand); }
.rank-pct.is-full { color: var(--good); }

/* ช่องรหัส 6 หลัก */
.otp { width: 100%; height: 64px; text-align: center; font: 700 30px var(--font-num); letter-spacing: .5em; padding-left: .5em; border-radius: 16px; border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink); }
.otp:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 4px var(--brand-soft); }
.qr-box { display: grid; place-items: center; padding: 14px; border-radius: 18px; background: #fff; border: 1px solid var(--line); width: max-content; margin: 0 auto; }
.secret { display: inline-block; padding: 6px 12px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--line); font: 600 15px ui-monospace, Menlo, Consolas, monospace; letter-spacing: .08em; user-select: all; overflow-wrap: anywhere; }
.steps { list-style: none; margin: 0; padding: 0; display: grid; gap: 14px; counter-reset: step; }
.steps > li { display: grid; grid-template-columns: 32px minmax(0, 1fr); gap: 12px; align-items: start; }
.steps > li::before { counter-increment: step; content: counter(step); width: 32px; height: 32px; border-radius: 10px; display: grid; place-items: center; font: 700 14px var(--font-num); color: var(--brand); background: var(--brand-soft); }
.steps > li > div { display: grid; gap: 8px; padding-top: 4px; }

/* หน้าเข้าสู่ระบบ */
body.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; background:
    radial-gradient(800px 400px at 100% 0%, rgba(139, 92, 246, .16), transparent 60%),
    radial-gradient(700px 380px at 0% 100%, rgba(56, 189, 248, .14), transparent 60%), var(--bg); }
.auth-card { width: min(420px, 100%); padding: 34px 30px 28px; border-radius: 28px; background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow-lg); display: grid; gap: 22px; }
.auth-brand { display: grid; justify-items: center; gap: 10px; text-align: center; }
.auth-brand .sb-logo { width: 56px; height: 56px; font-size: 26px; border-radius: 18px; }
.auth-brand h1 { font-family: var(--font-display); font-size: 24px; font-weight: 700; }
.auth-brand p { color: var(--muted); font-size: 14px; }
.auth-form { display: grid; gap: 16px; }
.auth-form .btn-main { width: 100%; height: 48px; }
.input-ic { position: relative; }
.input-ic > i { position: absolute; left: 15px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.input-ic .finput { padding-left: 42px; }
.auth-foot { text-align: center; font-size: 12.5px; color: var(--muted); }
.auth-foot a { color: var(--brand) !important; font-weight: 500; }

@media (max-width: 760px) {
    .dstats--3 { grid-template-columns: minmax(0, 1fr); }
    .pwrules { grid-template-columns: minmax(0, 1fr); }
    .rank { grid-template-columns: minmax(0, 1fr); }
    .auth-card { padding: 28px 20px 22px; }
    .dhead .chips { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 2px; }
    .dhead .chip { flex-shrink: 0; }
}
.typeseg input:disabled + span { opacity: .45; cursor: not-allowed; }
.dtable tr.is-new { animation: row-flash 2s ease-out; }
@keyframes row-flash { from { background: var(--brand-soft); } }

/* =====================================================================
   แถบนำทางด้านบน (navbar) — แทนเมนูด้านข้างเดิม
   ===================================================================== */
.app--nav { display: block; }
.skip-link { position: absolute; left: 12px; top: -60px; z-index: 200; padding: 10px 16px; border-radius: 12px; background: var(--ink); color: #fff !important; font-weight: 600; }
.skip-link:focus { top: 10px; }

/* เบลอพื้นหลังไว้ที่ ::before — ถ้าใส่ backdrop-filter ที่ .nav เอง เมนูมือถือ (position: fixed) จะถูกจำกัดอยู่ในแถบ */
.nav { position: sticky; top: 0; z-index: 60; border-bottom: 1px solid var(--line); transition: box-shadow .2s; }
.nav::before { content: ""; position: absolute; inset: 0; z-index: -1; background: rgba(255, 255, 255, .86); backdrop-filter: saturate(180%) blur(16px); -webkit-backdrop-filter: saturate(180%) blur(16px); }
.nav.is-scrolled { box-shadow: 0 8px 24px -18px rgba(16, 19, 37, .35); }
.nav-inner { max-width: 1840px; margin: 0 auto; height: 68px; padding: 0 28px; display: flex; align-items: center; gap: 24px; }

.brand { display: flex; align-items: center; gap: 11px; flex-shrink: 0; }
.brand img { width: 40px; height: 40px; display: block; filter: drop-shadow(0 6px 12px rgba(91, 76, 255, .35)); transition: transform .25s cubic-bezier(.2, .8, .2, 1); }
.brand:hover img { transform: rotate(-6deg) scale(1.04); }
.brand-text { display: grid; line-height: 1.1; }
.brand-text strong { font: 800 18px var(--font-num); letter-spacing: -0.03em; color: var(--ink); }
.brand-text strong b { font-weight: 800; margin-left: 3px; background: linear-gradient(135deg, var(--brand), var(--brand-2)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.brand-text small { font-size: 11.5px; color: var(--muted); letter-spacing: .02em; margin-top: 2px; }

.nav-links { display: flex; align-items: center; gap: 2px; flex: 1; min-width: 0; }
.nav-link { position: relative; display: inline-flex; align-items: center; gap: 8px; height: 40px; padding: 0 13px; border-radius: 11px; border: 0; background: none; cursor: pointer;
    font: 500 14.5px var(--font-body); color: var(--ink-2); white-space: nowrap; transition: background .15s, color .15s; }
.nav-link > .bi:first-child { font-size: 16px; color: var(--muted); transition: color .15s; }
.nav-link:hover { background: var(--surface-2); color: var(--ink); }
.nav-link:hover > .bi:first-child { color: var(--ink-2); }
.nav-link[aria-current="page"], .nav-link.is-current { color: var(--brand); background: var(--brand-soft); font-weight: 600; }
.nav-link[aria-current="page"] > .bi:first-child, .nav-link.is-current > .bi:first-child { color: var(--brand); }
.nav-caret { font-size: 11px !important; color: var(--muted); transition: transform .2s; }
[aria-expanded="true"] > .nav-caret { transform: rotate(180deg); }

.nav-dd { position: relative; }
.nav-menu { position: absolute; top: calc(100% + 10px); left: 0; z-index: 70; min-width: 250px; padding: 8px; border-radius: 18px; background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow-lg); animation: menu-in .16s cubic-bezier(.2, .8, .2, 1); }
.nav-menu[hidden] { display: none; }
.nav-menu--end { left: auto; right: 0; }
.nav-menu--grid { display: grid; grid-template-columns: 1fr 1fr; gap: 2px; width: 540px; }
@keyframes menu-in { from { opacity: 0; transform: translateY(-6px); } }
.nav-item { display: flex; align-items: center; gap: 12px; padding: 10px; border-radius: 12px; color: var(--ink-2); transition: background .12s; }
.nav-item:hover { background: var(--surface-2); color: var(--ink); }
.nav-item[aria-current="page"] { background: var(--brand-soft); }
.nav-item-ic { width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center; flex-shrink: 0; font-size: 17px; color: var(--brand); background: var(--brand-soft); }
.nav-item[aria-current="page"] .nav-item-ic { color: #fff; background: var(--brand); }
.nav-item strong { display: block; font-size: 14px; font-weight: 600; color: var(--ink); }
.nav-item small { display: block; font-size: 12px; color: var(--muted); }
.nav-item--row { gap: 10px; padding: 10px 12px; font-size: 14px; font-weight: 500; }
.nav-item--row i { font-size: 16px; color: var(--muted); width: 20px; text-align: center; }
.nav-item--bad { color: var(--bad) !important; }
.nav-item--bad i { color: var(--bad); }
.nav-item--bad:hover { background: var(--bad-soft); }
.nav-menu-head { display: flex; align-items: center; gap: 10px; padding: 8px 10px 12px; margin-bottom: 6px; border-bottom: 1px solid var(--line); }
.nav-menu-head > span:last-child { display: grid; line-height: 1.35; min-width: 0; }
.nav-menu-head strong { font-size: 14px; }
.nav-menu-head small { font-size: 12px; color: var(--muted); }

.nav-right { display: flex; align-items: center; gap: 10px; margin-left: auto; flex-shrink: 0; }
.nav-cta { display: inline-flex; align-items: center; gap: 8px; height: 40px; padding: 0 16px; border-radius: 12px; font: 600 14px var(--font-body); color: #fff !important;
    background: linear-gradient(135deg, var(--brand), var(--brand-2)); box-shadow: 0 8px 18px -10px rgba(91, 76, 255, .85); transition: transform .12s, box-shadow .15s; white-space: nowrap; }
.nav-cta, .nav-user, .nav-burger { flex-shrink: 0; }
.nav-cta:hover { transform: translateY(-1px); box-shadow: 0 12px 22px -12px rgba(91, 76, 255, .9); }
.nav-user { display: flex; align-items: center; gap: 10px; height: 46px; padding: 0 10px 0 4px; border-radius: 14px; border: 1px solid transparent; background: none; cursor: pointer; font: inherit; color: inherit; }
.nav-user:hover, .nav-user[aria-expanded="true"] { background: var(--surface-2); border-color: var(--line); }
.nav-user .avatar { width: 36px; height: 36px; font-size: 14px; }
.nav-user-text { display: grid; text-align: left; line-height: 1.25; max-width: 160px; }
.nav-user-text strong { font-size: 13.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-user-text small { font-size: 11.5px; color: var(--muted); }
.nav-burger { display: none; width: 42px; height: 42px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); font-size: 20px; cursor: pointer; place-items: center; }

/* จอขนาดกลาง: ซ่อนข้อความรอง */
@media (max-width: 1380px) {
    .nav-user-text { display: none; }
    .nav-inner { gap: 16px; padding: 0 20px; }
}
@media (max-width: 1180px) {
    .nav-link { padding: 0 10px; }
    .nav-link > .bi:first-child { display: none; }
    .nav-link > .nav-caret { display: inline; }
}
/* แท็บเล็ต/มือถือ: เมนูเลื่อนลงจากแถบด้านบน */
@media (max-width: 1023px) {
    .nav-inner { height: 62px; padding: 0 16px; }
    .brand img { width: 36px; height: 36px; }
    .nav-burger { display: grid; }
    .nav-links { position: fixed; left: 0; right: 0; top: 62px; bottom: 0; z-index: 65; flex-direction: column; align-items: stretch; gap: 4px; padding: 14px 16px 28px;
        background: var(--surface); overflow-y: auto; overscroll-behavior: contain; transform: translateY(-8px); opacity: 0; visibility: hidden; transition: opacity .18s, transform .18s, visibility .18s; }
    .nav.is-open .nav-links { transform: none; opacity: 1; visibility: visible; }
    .nav-link { height: 50px; padding: 0 14px; font-size: 15.5px; width: 100%; }
    .nav-link > .bi:first-child { display: inline; font-size: 18px; }
    .nav-link > .nav-caret { margin-left: auto; }
    .nav-dd { width: 100%; }
    .nav-links .nav-menu { position: static; width: auto; min-width: 0; box-shadow: none; border: 0; padding: 4px 0 8px 12px; animation: none; }
    .nav-menu--grid { grid-template-columns: minmax(0, 1fr); }
    body.nav-locked { overflow: hidden; }
}
@media (max-width: 560px) {
    .nav-cta span { display: none; }
    .nav-cta { width: 42px; padding: 0; justify-content: center; }
    .brand-text small { display: none; }
    .nav-user { padding: 0 4px; }
    .nav-user .nav-caret { display: none; }
}
@media (prefers-reduced-motion: reduce) { .nav-menu, .nav-links { animation: none; transition: none; } }

/* โลโก้ในหน้าเข้าสู่ระบบ */
.auth-logo { width: 64px; height: 64px; display: block; filter: drop-shadow(0 10px 20px rgba(91, 76, 255, .35)); }

/* =====================================================================
   แบนเนอร์หน้าแรก
   ===================================================================== */
.banner { position: relative; overflow: hidden; display: grid; grid-template-columns: minmax(0, 1fr) minmax(280px, 380px); gap: 28px; align-items: center;
    margin-bottom: 26px; padding: 28px 32px; border-radius: var(--r-xl); border: 1px solid #E4E0FF;
    background:
        radial-gradient(520px 260px at 92% -20%, rgba(139, 92, 246, .20), transparent 65%),
        radial-gradient(420px 240px at 0% 120%, rgba(56, 189, 248, .14), transparent 60%),
        linear-gradient(120deg, #FFFFFF 0%, #F7F5FF 60%, #F1EEFF 100%);
    box-shadow: var(--shadow); }
.banner::before { content: ""; position: absolute; inset: 0; pointer-events: none; opacity: .55;
    background-image: radial-gradient(rgba(91, 76, 255, .13) 1px, transparent 1px); background-size: 16px 16px;
    mask-image: linear-gradient(100deg, transparent 35%, #000 85%); -webkit-mask-image: linear-gradient(100deg, transparent 35%, #000 85%); }
.banner > * { position: relative; z-index: 1; }
.banner-art { position: absolute !important; z-index: 0 !important; right: 360px; top: 50%; transform: translateY(-50%) rotate(-12deg); opacity: .07; pointer-events: none; }
.banner-art img { width: 220px; height: 220px; display: block; filter: grayscale(.2); }
.banner-date { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 600; color: var(--brand); padding: 4px 12px; border-radius: 999px; background: rgba(91, 76, 255, .08); }
.banner-title { font-family: var(--font-display); font-weight: 700; font-size: clamp(22px, 2.4vw, 30px); line-height: 1.3; margin-top: 12px !important; letter-spacing: -0.01em; }
.banner-sub { color: var(--ink-2); margin-top: 4px !important; font-size: 14.5px; }
.banner-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 18px; }
.banner-btn { display: inline-flex; align-items: center; gap: 8px; height: 42px; padding: 0 16px; border-radius: 12px; font-weight: 600; font-size: 14px;
    color: var(--ink-2); background: rgba(255, 255, 255, .85); border: 1px solid var(--line-strong); transition: border-color .15s, color .15s, transform .12s; }
.banner-btn:hover { color: var(--brand); border-color: var(--brand); transform: translateY(-1px); }
.banner-btn--main { color: #fff !important; border: 0; background: linear-gradient(135deg, var(--brand), var(--brand-2)); box-shadow: 0 10px 20px -10px rgba(91, 76, 255, .8); }
.banner-pace { display: grid; gap: 10px; padding: 18px 20px; border-radius: 20px; background: rgba(255, 255, 255, .78); border: 1px solid rgba(255, 255, 255, .9);
    box-shadow: 0 1px 2px rgba(16, 19, 37, .04), 0 14px 30px -20px rgba(91, 76, 255, .45); backdrop-filter: blur(6px); }
.banner-pace-label { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; font-weight: 600; font-size: 14px; }
.banner-pace-label span { font-weight: 500; font-size: 12.5px; color: var(--muted); }
.pace-row { display: grid; grid-template-columns: 58px minmax(0, 1fr) 44px; align-items: center; gap: 10px; font-size: 13px; color: var(--ink-2); }
.pace-row b { text-align: right; font-size: 14px; }
.pace-bar { height: 10px; border-radius: 999px; background: var(--track); overflow: hidden; }
.pace-bar i { display: block; height: 100%; border-radius: inherit; background: repeating-linear-gradient(-45deg, #A5A9BE 0 6px, #B8BBCC 6px 12px); }
.pace-bar--spend i { background: linear-gradient(90deg, #6D5DFF, var(--brand-2)); }
.banner-pace-note { display: flex; align-items: center; gap: 7px; font-size: 13px; font-weight: 600; padding-top: 2px; }
.banner-pace-note.is-good { color: #087A55; }
.banner-pace-note.is-good i { color: var(--good); }
.banner-pace-note.is-warn { color: #9A5B00; }
.banner-pace-note.is-warn i { color: var(--warn); }
@media (max-width: 1023px) {
    .banner { grid-template-columns: minmax(0, 1fr); padding: 24px 22px; gap: 20px; }
    .banner-art { right: -30px; top: 30px; transform: rotate(-12deg); }
}
@media (max-width: 560px) {
    .banner { padding: 20px 16px; margin-bottom: 20px; }
    .banner-btn { flex: 1 1 auto; justify-content: center; }
    .banner-art img { width: 160px; height: 160px; }
}

/* =====================================================================
   ช่องเลือกแบบใหม่: ช่องค้นหา (combo) · การ์ด (pick) · ปุ่มแถบ (seg)
   ===================================================================== */
/* combobox (ใช้ทั้งช่องโครงการในหน้าเบิกจ่าย และ select ที่มี data-combo) */
.combo { position: relative; }
.combo > .bi-search { position: absolute; left: 15px; top: 23px; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.combo input { width: 100%; height: 48px; padding: 0 40px 0 42px; border-radius: 13px; border: 1px solid var(--line-strong); background: var(--surface); font: 500 15px var(--font-body); color: var(--ink); text-overflow: ellipsis; }
.combo input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 4px var(--brand-soft); }
.combo.has-value input { background: var(--surface-2); }
.combo-clear { position: absolute; right: 8px; top: 24px; transform: translateY(-50%); width: 32px; height: 32px; border: 0; background: none; color: var(--line-strong); cursor: pointer; border-radius: 8px; font-size: 16px; }
.combo-clear:hover { color: var(--muted); }
.combo-list {
    position: absolute; left: 0; right: 0; top: calc(100% + 6px); z-index: 5; max-height: min(380px, 50vh); overflow-y: auto;
    margin: 0; padding: 6px; list-style: none; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow-lg);
    overscroll-behavior: contain;
}
.combo-group { position: sticky; top: -6px; z-index: 1; padding: 8px 10px 4px; font-size: 12px; font-weight: 600; color: var(--muted); background: var(--surface); }
.combo-list [role="option"] { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 9px 10px; border-radius: 10px; cursor: pointer; }
.combo-list [role="option"].is-active { background: var(--brand-soft); }
.combo-list [role="option"][aria-selected="true"] .opt-code::after { content: "✓"; margin-left: 6px; color: var(--brand); }
.opt-main { display: grid; min-width: 0; }
.opt-code { font-size: 13px; font-weight: 700; color: var(--ink); }
.opt-name { font-size: 13.5px; color: var(--ink-2); line-height: 1.4; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.opt-side { display: grid; justify-items: end; flex-shrink: 0; text-align: right; }
.opt-bt { font-size: 11.5px; color: var(--muted); max-width: 140px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.opt-remain { font-size: 12.5px; font-weight: 600; color: var(--good); white-space: nowrap; }
.opt-remain.is-neg { color: var(--bad); }
.combo-list mark { background: #FFE7A3; color: inherit; border-radius: 3px; padding: 0 1px; }
.combo-empty { padding: 18px; text-align: center; color: var(--muted); font-size: 14px; }

.combo-list mark { background: #FFE7A3; }
.combo-list [role="option"] .opt-recent { font-size: 11px; font-weight: 600; color: var(--brand); background: var(--brand-soft); padding: 1px 7px; border-radius: 999px; white-space: nowrap; }
.combo-list [role="option"][aria-selected="true"] { background: var(--surface-2); }
.combo-list [role="option"][aria-selected="true"].is-active { background: var(--brand-soft); }
.combo-list [role="option"] .opt-check { color: var(--brand); font-size: 15px; visibility: hidden; }
.combo-list [role="option"][aria-selected="true"] .opt-check { visibility: visible; }
.combo-list .opt-meta { font-size: 12px; color: var(--muted); white-space: nowrap; }
.combo-list .opt-sub { display: inline-block; margin-right: 6px; padding: 0 6px; border-radius: 6px; font: 600 11.5px var(--font-num); color: var(--ink-2); background: var(--surface-2); border: 1px solid var(--line); vertical-align: 1px; }
/* combo ขนาดเล็กสำหรับแถบตัวกรอง */
.combo--sm { min-width: 230px; }
.combo--sm > .bi-search { top: 21px; font-size: 13px; }
.combo--sm input { height: 42px; border-radius: 12px; border-color: var(--line); background: var(--surface-2); font-size: 14px; padding-left: 36px; }
.combo--sm.has-value input { background: var(--brand-soft); border-color: #D9D3FF; color: var(--brand); font-weight: 600; }
.combo--sm .combo-clear { top: 21px; }
.combo--sm .combo-list { min-width: 300px; }

/* การ์ดให้กดเลือก (เช่น ประเภทงบ) */
.pick { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.pick-card { position: relative; display: grid; gap: 3px; align-content: start; min-height: 64px; padding: 10px 12px 10px 38px; text-align: left; cursor: pointer;
    border-radius: 14px; border: 1px solid var(--line-strong); background: var(--surface); font: inherit; color: var(--ink-2); transition: border-color .12s, background .12s, box-shadow .12s; }
.pick-card::before { content: ""; position: absolute; left: 12px; top: 13px; width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--line-strong); background: var(--surface); transition: border-color .12s, box-shadow .12s; }
.pick-card:hover { border-color: var(--brand); }
.pick-card[aria-checked="true"] { border-color: var(--brand); background: var(--brand-soft); box-shadow: 0 0 0 1px var(--brand) inset; color: var(--ink); }
.pick-card[aria-checked="true"]::before { border-color: var(--brand); box-shadow: inset 0 0 0 3px var(--surface); background: var(--brand); }
.pick-card:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.pick-card strong { font-size: 13.5px; font-weight: 600; line-height: 1.35; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.pick-card small { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; font-size: 12px; color: var(--muted); }
.pick-card .pick-sub { padding: 0 6px; border-radius: 6px; font: 600 11.5px var(--font-num); color: var(--brand); background: var(--surface); border: 1px solid #DCD6FF; }
.pick-card .pick-recent { color: var(--brand); font-weight: 600; }
.pick-card--none { min-height: 0; grid-column: 1 / -1; padding-top: 9px; padding-bottom: 9px; }
.pick-card--none::before { top: 50%; transform: translateY(-50%); }
.pick-card--none strong { font-weight: 500; color: var(--muted); }
.pick-empty { grid-column: 1 / -1; padding: 14px; text-align: center; color: var(--muted); font-size: 13.5px; border: 1px dashed var(--line-strong); border-radius: 14px; }

/* ปุ่มแถบ (เช่น ปีงบประมาณ) */
.seg { display: inline-flex; flex-wrap: wrap; gap: 4px; padding: 4px; border-radius: 13px; background: var(--surface-2); box-shadow: inset 0 0 0 1px var(--line); max-width: 100%; }
.seg button { height: 38px; padding: 0 14px; border: 0; border-radius: 10px; background: none; cursor: pointer; font: 600 14px var(--font-num); color: var(--muted); white-space: nowrap; transition: background .12s, color .12s; }
.seg button:hover { color: var(--ink); }
.seg button[aria-checked="true"] { background: var(--surface); color: var(--brand); box-shadow: var(--shadow-sm), 0 0 0 1px var(--line); }
.seg--block { display: flex; }
.seg--block button { flex: 1; }
.seg--sm button { height: 34px; padding: 0 12px; font-size: 13.5px; }
@media (max-width: 760px) {
    .pick { grid-template-columns: minmax(0, 1fr); }
    .combo--sm, .combo--sm .combo-list { min-width: 0; width: 100%; }
    .filters .seg { width: 100%; }
    .filters .seg button { flex: 1; }
}

/* ประวัติการแก้ไข */
.modal-head .sheet-close { margin-left: auto; }
.hist { list-style: none; margin: 0; padding: 0 0 0 18px; border-left: 2px solid var(--line); display: grid; gap: 16px; }
.hist-item { position: relative; }
.hist-item::before { content: ""; position: absolute; left: -25px; top: 5px; width: 12px; height: 12px; border-radius: 50%; background: var(--surface); border: 3px solid var(--brand); }
.hist--delete::before, .hist--convert::before, .hist--detach::before { border-color: var(--bad); }
.hist--add::before, .hist--restore::before { border-color: var(--good); }
.hist-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; }
.hist-head strong { font-size: 14px; }
.hist-head span { font-size: 12.5px; color: var(--muted); }
.hist-changes { list-style: none; margin: 6px 0 0; padding: 8px 12px; border-radius: 12px; background: var(--surface-2); display: grid; gap: 4px; font-size: 13px; }
.hist-changes li { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.hist-f { color: var(--muted); min-width: 110px; }
.hist-changes del { color: var(--bad); text-decoration: line-through; opacity: .8; }
.hist-changes ins { color: #087A55; text-decoration: none; font-weight: 600; }
.hist-changes i { color: var(--muted); font-size: 11px; }

/* ไฟล์แนบ */
.att-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.att-list li { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 12px; border: 1px solid var(--line); }
.att-list li > i { font-size: 20px; color: var(--brand); }
.att-list a { flex: 1; min-width: 0; display: grid; }
.att-list a b { font-weight: 500; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att-list a:hover b { color: var(--brand); }
.att-list small { font-size: 12px; color: var(--muted); }
.att-list .att-empty { justify-content: center; color: var(--muted); border-style: dashed; font-size: 13.5px; }
.act--on { color: var(--brand); background: var(--brand-soft); }
.act span { font: 600 12px var(--font-num); }
