:root {
    --blue: #1d5fe0; --indigo: #4a35d6; --ink: #1c2540; --muted: #7a859c;
    --line: #e6ebf3; --bg: #f5f8fd; --radius: 14px;
    --shadow: 0 2px 10px rgba(30, 60, 120, .07);
}
body { font-family: 'Sarabun', sans-serif; background: var(--bg); color: var(--ink); }

/* ---------- แถบบน ---------- */
.topbar { position: sticky; top: 0; z-index: 1030; height: 64px; display: flex; align-items: center; padding: 0 1.25rem;
    background: linear-gradient(90deg, #1b66e6 0%, #3a49de 55%, #5b35d5 100%); color: #fff; box-shadow: 0 3px 14px rgba(40, 50, 160, .3); }
.topbar .brand { color: #fff; text-decoration: none; font-weight: 700; font-size: 1.25rem; display: flex; align-items: center; gap: .6rem; margin-right: 1.5rem; }
.brand-icon { width: 40px; height: 40px; border: 2px solid rgba(255,255,255,.8); border-radius: 12px; display: grid; place-items: center; font-size: 1.3rem; }
.top-nav { gap: .35rem; }
.top-nav a { color: #fff; text-decoration: none; padding: .5rem 1rem; border-radius: 12px; font-weight: 500; opacity: .92; }
.top-nav a:hover { background: rgba(255,255,255,.12); }
.top-nav a.active { background: rgba(255,255,255,.2); opacity: 1; }
.user-chip { align-items: center; gap: .6rem; }
.user-chip small { opacity: .8; }
.avatar { width: 40px; height: 40px; border-radius: 50%; background: #fff; color: var(--blue); display: grid; place-items: center; font-size: 1.4rem; }
.btn-logout { color: #fff; border: 1.5px solid rgba(255,255,255,.7); border-radius: 10px; font-weight: 500; }
.btn-logout:hover { background: rgba(255,255,255,.15); color: #fff; }

/* ---------- เมนูข้าง ---------- */
.shell { display: flex; min-height: calc(100vh - 64px); }
.sidebar { width: 248px; flex-shrink: 0; padding: 1rem; background: linear-gradient(180deg, #fff 0%, #eef3fc 100%); border-right: 1px solid var(--line); display: flex; flex-direction: column; gap: .35rem; }
.sidebar > a { display: flex; align-items: center; gap: .75rem; padding: .7rem 1rem; border-radius: 12px; color: #4a5672; text-decoration: none; font-weight: 500; }
.sidebar > a i { font-size: 1.2rem; }
.sidebar > a:hover { background: #e9f0fc; }
.sidebar > a.active { background: #e3ecfb; color: var(--blue); font-weight: 600; }
.side-promo { margin-top: auto; padding: 1rem .5rem; display: flex; flex-direction: column; gap: .35rem; }
.side-promo b { color: var(--blue); }
.side-promo small { color: var(--muted); line-height: 1.5; }
.promo-art { height: 110px; border-radius: 16px; background: linear-gradient(135deg, #dbe7fb, #eadffc); display: flex; align-items: center; justify-content: center; gap: .8rem; font-size: 2.6rem; color: #6d86d8; }
.promo-art .bi-coin { color: #f1b73b; }
.content { flex: 1; min-width: 0; padding: 1.5rem 1.75rem; }
@media (max-width: 991px) {
    .sidebar { position: fixed; top: 64px; bottom: 0; left: 0; z-index: 1020; transform: translateX(-100%); transition: .2s; box-shadow: 4px 0 16px rgba(0,0,0,.1); }
    .sidebar.open { transform: none; }
    .content { padding: 1rem; }
}

/* ---------- หัวหน้า / การ์ด ---------- */
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; margin-bottom: 1.25rem; flex-wrap: wrap; }
.page-head h4 { font-weight: 700; font-size: 1.9rem; margin: 0; display: flex; align-items: center; gap: .6rem; }
.page-head h4 i { color: var(--blue); font-size: 2.1rem; }
.page-head .sub { color: var(--muted); margin: 0; padding-left: 3rem; }
.content > .d-flex > h4, .content > .d-flex > h4 i { color: inherit; }
.card { border: 0; border-radius: var(--radius); box-shadow: var(--shadow); }
.btn-primary { background: linear-gradient(180deg, #2a72ee, #1a58d6); border: 0; border-radius: 10px; font-weight: 600; padding: .55rem 1.2rem; box-shadow: 0 3px 10px rgba(29, 95, 224, .3); }
.btn-primary:hover { background: #1a58d6; }
.btn-light { border-radius: 10px; }
.form-control, .form-select { border-radius: 10px; border-color: #dbe2ee; }
.form-control:focus, .form-select:focus { border-color: var(--blue); box-shadow: 0 0 0 .2rem rgba(29, 95, 224, .15); }
.modal-content { border: 0; border-radius: 16px; }
.modal-header { border-bottom: 1px solid var(--line); }

/* การ์ดสถิติ */
.stat-card { border-radius: var(--radius); padding: 1rem 1.25rem; display: flex; justify-content: space-between; align-items: center; box-shadow: var(--shadow); border: 1px solid transparent; }
.stat-card .lbl { display: flex; align-items: center; gap: .6rem; font-weight: 600; }
.stat-card .dot { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-size: 1rem; }
.stat-card .val { font-size: 2.2rem; font-weight: 700; line-height: 1.2; margin-top: .25rem; }
.stat-card .val small { font-size: .9rem; font-weight: 400; color: var(--muted); }
.stat-card .ghost { font-size: 3.4rem; opacity: .25; }
.stat-blue { background: #eaf2fd; border-color: #d3e3fa; } .stat-blue .dot { background: #3b82f6; } .stat-blue .ghost { color: #3b82f6; }
.stat-green { background: #e6f7ee; border-color: #cdeedb; } .stat-green .dot { background: #22b866; } .stat-green .ghost { color: #22b866; }
.stat-orange { background: #fff2e1; border-color: #fbe0bd; } .stat-orange .dot { background: #f59e0b; } .stat-orange .ghost { color: #f59e0b; }
.stat-red { background: #fdebec; border-color: #f8d1d4; } .stat-red .dot { background: #ef4444; } .stat-red .ghost { color: #ef4444; }

/* แถบค้นหา */
.filter-bar { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); padding: 1rem 1.25rem; display: flex; flex-wrap: wrap; gap: 1rem; align-items: flex-end; margin: 1.25rem 0; }
.filter-bar .search { flex: 1 1 280px; position: relative; }
.filter-bar .search i { position: absolute; left: .9rem; top: 50%; transform: translateY(-50%); color: var(--muted); }
.filter-bar .search input { padding-left: 2.4rem; background: #f6f8fc; }
.filter-bar label { font-size: .8rem; color: var(--muted); margin-bottom: .15rem; display: block; }

/* ตาราง */
.data-card { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.data-table { margin: 0; }
.data-table thead th { background: #f1f4f9; font-weight: 600; padding: 1rem .9rem; border-bottom: 1px solid var(--line); white-space: nowrap; }
.data-table td { padding: .9rem; vertical-align: middle; border-color: var(--line); }
.data-table a { color: var(--blue); }
.chip-year { background: #e3ecfb; color: var(--blue); font-weight: 600; padding: .25rem .6rem; border-radius: 8px; }
.chip-code { background: #f3f5f9; padding: .35rem .6rem; border-radius: 8px; display: inline-block; }
.badge-type { white-space: nowrap; display: inline-block; background: #12c3d8; color: #fff; border-radius: 8px; padding: .3rem .6rem; font-weight: 600; }
.badge-st { display: inline-block; white-space: nowrap; border-radius: 8px; padding: .3rem .6rem; font-weight: 600; font-size: .8rem; }
.st-active { background: #dcf5e7; color: #12864b; } .st-pending { background: #fff0d6; color: #b9770e; } .st-closed { background: #fde0e2; color: #c0262d; }
.btn-ico { width: 38px; height: 38px; padding: 0; border-radius: 10px; display: inline-grid; place-items: center; background: #fff; border-width: 1.5px; }
.table-foot { display: flex; justify-content: space-between; align-items: center; padding: 1rem 1.25rem; border-top: 1px solid var(--line); flex-wrap: wrap; gap: .75rem; color: var(--muted); }
.pager { display: flex; gap: .4rem; align-items: center; }
.pager button { min-width: 38px; height: 38px; border: 1px solid var(--line); background: #fff; border-radius: 10px; }
.pager button.on { background: var(--blue); color: #fff; border-color: var(--blue); font-weight: 600; }
.pager button:disabled { opacity: .4; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.text-ok { color: #12864b; font-weight: 600; }

/* แดชบอร์ด */
.bar-track { height: 10px; background: #e9eef7; border-radius: 6px; overflow: hidden; }
.bar-fill { height: 100%; background: linear-gradient(90deg, #2a72ee, #5b35d5); border-radius: 6px; }

/* ---------- อื่น ๆ ---------- */
#loading { position: fixed; inset: 0; background: rgba(245,248,253,.7); backdrop-filter: blur(2px); z-index: 2000; display: flex; align-items: center; justify-content: center; }
#loading.d-none { display: none !important; }
.loading-box { background: #fff; padding: 1.5rem 2.5rem; border-radius: 16px; box-shadow: 0 8px 30px rgba(30, 60, 120, .2); text-align: center; }
.swal2-popup { font-family: 'Sarabun', sans-serif; border-radius: 18px; }

/* แผนการใช้เงิน (เลียนแบบ doc/plan-paper.PNG) */
.plan-head { text-align: center; }
.plan-head .u1 { color: #b00020; font-weight: 700; font-size: 1.25rem; }
.plan-head .u2 { color: #b00020; font-weight: 700; }
.plan-head .u3 { color: #b00020; font-size: .85rem; }
.plan-info { font-weight: 600; }
.plan-code { color: #c00; font-weight: 700; font-size: 1.1rem; }
.plan-table { border-collapse: collapse; width: 100%; background: #fff; }
.plan-table th, .plan-table td { border: 1px solid #999; padding: 3px 6px; }
.plan-table thead th { background: #384bde; color: #fff;text-align: center; font-weight: 700; }
.plan-table .budget-row td { color: #c00; font-weight: 700; text-align: right; }
.plan-table .cat { text-align: center; width: 32px; }
.plan-table .act { width: 78px; text-align: center; white-space: nowrap; }
@media print {
    body { background: #fff; }
    .d-print-none, .act { display: none !important; }
    .content { padding: 0; } .card { box-shadow: none; }
}

/* ซ่อน/แสดงเมนูข้าง (เดสก์ท็อป) */
.sidebar { transition: margin-left .2s ease, opacity .2s ease; }
@media (min-width: 992px) {
    body.side-hidden .sidebar { margin-left: -248px; opacity: 0; pointer-events: none; }
}

/* ---------- มือถือ / จอเล็ก ---------- */
.sidebar-backdrop { display: none; }
@media (max-width: 991px) {
    .sidebar-backdrop.show { display: block; position: fixed; inset: 64px 0 0 0; background: rgba(20, 30, 60, .45); z-index: 1015; }
}
@media (max-width: 767px) {
    .topbar { height: 56px; padding: 0 .75rem; }
    .topbar .brand { font-size: 1rem; margin-right: 0; gap: .4rem; white-space: nowrap; overflow: hidden; }
    .brand-icon { width: 32px; height: 32px; font-size: 1rem; border-radius: 9px; flex-shrink: 0; }
    .sidebar { top: 56px; width: 80%; max-width: 280px; }
    .sidebar-backdrop.show { inset: 56px 0 0 0; }
    .btn-logout { padding: .3rem .6rem; }
    .content { padding: .9rem .75rem; }

    .page-head { margin-bottom: .9rem; }
    .page-head h4 { font-size: 1.4rem; } .page-head h4 i { font-size: 1.5rem; }
    .page-head .sub { padding-left: 2.1rem; font-size: .9rem; }
    .page-head > .btn, .page-head > select { width: 100%; }

    .stat-card { padding: .75rem; }
    .stat-card .val { font-size: 1.6rem; }
    .stat-card .lbl { font-size: .85rem; }
    .stat-card .ghost { font-size: 2.2rem; }

    .filter-bar { padding: .85rem; gap: .6rem; margin: .9rem 0; }
    .filter-bar > div:not(.search) { flex: 1 1 45%; }
    .filter-bar > .btn { flex: 1 1 45%; }

    /* ตารางเป็นการ์ดต่อรายการ */
    .data-table.stack thead { display: none; }
    .data-table.stack, .data-table.stack tbody { display: block; }
    .data-table.stack tr { display: block; padding: .75rem 1rem; border-bottom: 8px solid var(--bg); }
    .data-table.stack td { display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding: .3rem 0; border: 0; text-align: right; }
    .data-table.stack td[data-label]::before { content: attr(data-label); color: var(--muted); font-size: .85rem; text-align: left; flex-shrink: 0; }
    .data-table.stack td.cell-title { display: block; text-align: left; font-weight: 600; padding-bottom: .4rem; }
    .data-table.stack td.cell-title::before { display: block; margin-bottom: .1rem; font-weight: 400; }
    .data-table.stack td[colspan] { display: block; text-align: center; }
    .data-table.stack td.cell-actions { justify-content: flex-end; padding-top: .6rem; }
    .data-table.stack td.cell-actions::before { content: none; }

    .table-foot { flex-direction: column; align-items: stretch; text-align: center; }
    .table-foot > div { flex-direction: column; }
    .pager { flex-wrap: wrap; justify-content: center; }

    /* แผนการใช้เงิน: เลื่อนซ้ายขวา */
    #sheet { padding: .75rem; }
    .plan-table { min-width: 860px; font-size: .85rem; }
    .plan-head .u1 { font-size: 1.05rem; }
    .btn-lg { padding: .5rem 1rem; font-size: 1rem; }
}

/* ---------- แดชบอร์ด ---------- */
.stat-lg .dot-lg { width: 44px; height: 44px; font-size: 1.4rem; }
.stat-lg .val { font-size: 2.6rem; }
.stat-lg .trend { color: #12864b; font-size: .85rem; margin-top: .15rem; }
.bar-fill.fill-active { background: #22b866; } .bar-fill.fill-pending { background: #f59e0b; } .bar-fill.fill-closed { background: #ef4444; }
.card-ttl { font-weight: 700; font-size: 1.05rem; display: flex; align-items: center; gap: .6rem; margin-bottom: 1rem; }
.ttl-ico { width: 34px; height: 34px; border-radius: 10px; background: #e3ecfb; color: var(--blue); display: grid; place-items: center; }
.donut { width: 150px; height: 150px; border-radius: 50%; display: grid; place-items: center; flex-shrink: 0; background: #e9eef7; }
.donut > div { width: 98px; height: 98px; border-radius: 50%; background: #fff; display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1.15; text-align: center; }
.donut b { font-size: 1.05rem; word-break: break-all; } .donut small { color: var(--muted); }
.donut-sm { width: 130px; height: 130px; } .donut-sm > div { width: 84px; height: 84px; } .donut-sm b { font-size: 1.6rem; }
.legend { list-style: none; padding: 0; margin: 0; min-width: 150px; }
.legend li { display: flex; align-items: center; gap: .5rem; padding: .3rem 0; }
.legend li b { margin-left: auto; font-variant-numeric: tabular-nums; }
.legend li > i { width: 12px; height: 12px; border-radius: 50%; flex-shrink: 0; }
.legend-col li { align-items: flex-start; } .legend-col li > i { margin-top: .4rem; } .legend-col li b { margin-left: 0; }

.bars { display: flex; gap: .5rem; height: 200px; }
.bars .axis { display: flex; flex-direction: column; justify-content: space-between; color: var(--muted); font-size: .75rem; text-align: right; padding-bottom: 1.5rem; }
.bar-cols { flex: 1; display: flex; gap: 4px; border-left: 1px solid var(--line); }
.col-m { flex: 1; display: flex; flex-direction: column; align-items: center; min-width: 0; }
.col-m .stick { border-bottom: 1px solid var(--line); flex: 1; width: 100%; display: flex; align-items: flex-end; justify-content: center; }
.col-m .stick div { width: 70%; max-width: 22px; background: linear-gradient(180deg, #7bb0f8, #5b9bf5); border-radius: 4px 4px 0 0; min-height: 1px; }
.col-m span { font-size: .7rem; color: var(--muted); height: 1.5rem; line-height: 1.5rem; }

.act-row { display: flex; align-items: center; gap: .75rem; padding: .6rem 0; text-decoration: none; color: inherit; border-bottom: 1px solid var(--line); }
.act-row:last-child { border-bottom: 0; }
.act-row:hover .fw-semibold { color: var(--blue); }
.min-w-0 { min-width: 0; }
.date-box { width: 44px; height: 44px; border-radius: 10px; background: #e3ecfb; color: var(--blue); display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1.1; flex-shrink: 0; }
.date-box small { font-size: .65rem; }
.act-row .amt { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }

.quick { display: flex; align-items: center; gap: .5rem; padding: .8rem; border-radius: 12px; text-decoration: none; font-weight: 600; font-size: .9rem; border: 1px solid transparent; height: 100%; }
.quick i { font-size: 1.2rem; }
.q-blue { background: #eaf2fd; color: #1d5fe0; border-color: #d3e3fa; } .q-green { background: #e6f7ee; color: #12864b; border-color: #cdeedb; }
.q-purple { background: #f1ebfd; color: #6b3fd1; border-color: #e0d3f8; } .q-orange { background: #fff2e1; color: #b9770e; border-color: #fbe0bd; }
.quick:hover { filter: brightness(.97); }
@media (max-width: 767px) { .bars { height: 170px; } .donut { width: 130px; height: 130px; } .donut > div { width: 84px; height: 84px; } .stat-lg .val { font-size: 2rem; } }

/* ย่อข้อความยาวเหลือ 1 บรรทัด (เมาส์ชี้เพื่อดูข้อความเต็ม) */
.clip { display: block; max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.clip-sm { max-width: 140px; }
@media (max-width: 767px) {
    .data-table.stack td .clip { max-width: 100%; white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
    .data-table.stack td .clip-sm { max-width: 60%; }
}

.brand-logo { width: 40px; height: 40px; flex-shrink: 0; filter: drop-shadow(0 1px 3px rgba(0,0,0,.25)); }
@media (max-width: 767px) { .brand-logo { width: 32px; height: 32px; } }

/* flatpickr: ให้ช่องวันที่เต็มความกว้างและเลเบลอยู่บนหัวเหมือนช่องอื่น */
.flatpickr-wrapper { display: block; width: 100%; }
.flatpickr-wrapper .flatpickr-calendar { max-width: 100%; }
