*{box-sizing:border-box}
body{margin:0;background:#f6f6f4;color:#1f2937;font-family:'Battambang',sans-serif;font-size:14px}
a{color:#1f2937}
h1{margin:0;font-size:22px}
.wrap{max-width:1280px;margin:0 auto;padding:20px 20px 60px;display:flex;flex-direction:column;gap:16px}
.row{display:flex;flex-wrap:wrap;gap:16px;align-items:flex-start}
.grow{flex:999 1 560px;min-width:0}
.side{flex:1 1 320px;min-width:0}
.card{background:#fff;border:1px solid #e4e4e0;border-radius:12px;padding:16px}
.stack{display:flex;flex-direction:column;gap:12px}
.grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(190px,1fr));gap:12px}
.between{display:flex;justify-content:space-between;align-items:center;gap:10px;flex-wrap:wrap}
.muted{color:#6b6b6b}.small{font-size:12px}.center{text-align:center}.r{text-align:right}.b{font-weight:700}
.btn{font:inherit;font-size:14px;font-weight:700;background:#1f2937;color:#fff;border:0;border-radius:10px;min-height:44px;padding:0 18px;cursor:pointer}
.btn:disabled{opacity:.5;cursor:wait}
.btn2{font:inherit;font-size:14px;background:#fff;color:#1f2937;border:1px solid #d6d6d2;border-radius:10px;min-height:42px;padding:0 14px;cursor:pointer;text-decoration:none;display:inline-flex;align-items:center;gap:6px}
.btn2.sm,.btn.sm{min-height:34px;font-size:12px;padding:0 10px}
.danger{color:#b42318;border-color:#f1c4bf}
.inp{font:inherit;font-size:14px;padding:9px 11px;border:1px solid #d6d6d2;border-radius:9px;min-height:42px;width:100%;background:#fff;color:#1f2937}
.inp:focus{outline:2px solid #1f2937;outline-offset:-1px}
.lbl{display:flex;flex-direction:column;gap:5px;font-size:12px;color:#555}
.t{border-collapse:collapse;width:100%;font-size:13px}
.t th{font-size:12px;color:#555;background:#fafaf8;text-align:left;padding:9px 10px;border-bottom:1px solid #ecece8;white-space:nowrap}
.t td{padding:8px 10px;border-bottom:1px solid #f0f0ec;white-space:nowrap}
.t tr.click{cursor:pointer}.t tr.click:hover td{background:#fafaf8}
.t .r{text-align:right}
.scroll{overflow-x:auto}
.paid td{color:#2563eb;text-decoration:line-through}
.tag{display:inline-block;font-size:11px;border-radius:999px;padding:2px 9px;border:1px solid #d6d6d2;color:#555;background:#fff;white-space:nowrap}
.seg{display:inline-flex;gap:4px;background:#ebebe7;padding:4px;border-radius:999px;flex-wrap:wrap}
.seg button{font:inherit;font-size:13px;padding:6px 14px;border-radius:999px;color:#444;background:none;border:0;cursor:pointer;min-height:34px}
.seg button.on{background:#1f2937;color:#fff}
.chip{font:inherit;font-size:14px;font-weight:700;background:#fff;color:#0e7490;border:2px solid #06b6d4;border-radius:10px;min-height:42px;padding:0 14px;cursor:pointer}
.chip.on{background:#ecfeff}
.stat .v{font-size:22px;font-weight:700;margin-top:4px}
/* top bar */
.topbar{background:#fff;border-bottom:1px solid #e4e4e0}
.topbar .in{max-width:1280px;margin:0 auto;padding:10px 20px;display:flex;flex-wrap:wrap;align-items:center;justify-content:space-between;gap:10px}
.brand{font-family:'Moul',serif;font-size:15px;color:#b91c1c;text-decoration:none}
.nav{display:flex;flex-wrap:wrap;gap:6px}
.nav a{text-decoration:none;display:flex;flex-direction:column;align-items:center;gap:3px;min-width:86px;padding:8px 6px;border:1px solid #e4e4e0;border-radius:12px;font-size:12px;background:#fff;color:#1f2937}
.nav a.on{background:#1f2937;color:#fff;border-color:#1f2937}
.nav svg{width:22px;height:22px}
/* toast & modal */
#toast{position:fixed;left:50%;bottom:24px;transform:translateX(-50%);display:flex;flex-direction:column;gap:8px;z-index:99}
#toast div{background:#1f2937;color:#fff;border-radius:10px;padding:10px 16px;font-size:14px;box-shadow:0 6px 20px rgba(0,0,0,.18)}
#toast div.err{background:#b42318}
.modal-bg{position:fixed;inset:0;background:rgba(0,0,0,.35);display:flex;align-items:center;justify-content:center;padding:16px;z-index:50}
.modal{background:#fff;border-radius:14px;padding:20px;width:100%;max-width:520px;max-height:90vh;overflow:auto;display:flex;flex-direction:column;gap:12px}
/* freezer boxes */
.fgrid{display:grid;grid-template-columns:repeat(auto-fill,minmax(150px,1fr));gap:14px}
.fbox{all:unset;cursor:pointer;display:flex;flex-direction:column;align-items:center;gap:8px;padding:14px 8px 12px;border-radius:14px;background:#fff;border:1px solid #e4e4e0}
.fbox.on{border:2px solid #1f2937}
.cooler{position:relative;width:112px;height:92px}
.cooler .slot{position:absolute;left:6px;right:6px;top:18px;height:10px;background:#3b0a0a;border-radius:3px}
.cooler .lid{position:absolute;left:0;right:0;top:4px;height:20px;border-radius:6px 6px 3px 3px;box-shadow:inset 0 -3px 0 rgba(0,0,0,.18);transition:transform .45s cubic-bezier(.3,1.4,.5,1);transform-origin:12% 100%}
.fbox.on .lid{transform:translateY(-30px) rotate(-14deg)}
.cooler .body{position:absolute;left:4px;right:4px;top:26px;bottom:0;border-radius:4px 4px 10px 10px;box-shadow:inset 0 -6px 0 rgba(0,0,0,.12);display:flex;align-items:center;justify-content:center}
.cooler .no{background:#fff;font-weight:700;font-size:22px;border-radius:6px;min-width:44px;padding:0 8px;text-align:center;line-height:34px}
.sw{width:24px;height:24px;border-radius:999px;cursor:pointer;padding:0}
/* paper */
.paper{background:#fff;margin:0 auto;color:#111;box-shadow:0 2px 14px rgba(0,0,0,.08)}
.a5{width:148mm;min-height:210mm;padding:9mm 8mm 7mm;font-size:9.5pt;display:flex;flex-direction:column}
.a4{width:210mm;min-height:297mm;padding:14mm 14mm 12mm;font-size:10.5pt;display:flex;flex-direction:column;gap:10px}
.moul{font-family:'Moul',serif}
.inv th,.inv td{border-left:1px solid #111;border-right:1px solid #111;padding:5px 5px}
.inv thead th{border-top:2px solid #111;border-bottom:2px solid #111;font-size:8pt}
.inv .fz{border-left:1px solid #e6e6e6;border-right:1px solid #e6e6e6;color:#c4c4c4;text-align:center;font-size:8pt}
.inv .dsc{border-right:1px solid #e6e6e6}
.inv tbody tr.fill td{height:100%;border-bottom:2px solid #111}
.toolbar{display:flex;gap:8px;justify-content:center;flex-wrap:wrap;margin:0 0 14px}
@media print{
  #top,.toolbar,.noprint,#toast{display:none!important}
  body{background:#fff}
  .wrap{padding:0;max-width:none}
  .paper{box-shadow:none;margin:0}
}
@media (max-width:640px){.nav a{min-width:64px;font-size:11px}.wrap{padding:14px 12px 50px}}

/* ===================== ទម្រង់ដូចកម្មវិធីចាស់ (Classic) ===================== */
body.classic{background:#dbe5f1}
.cl-head{background:linear-gradient(#f7f9fc,#e3ebf5);border-bottom:1px solid #a9bcd6}
.cl-menu{display:flex;align-items:flex-end;gap:18px;padding:8px 14px 0;flex-wrap:wrap}
.cl-logo{width:34px;height:34px;display:grid;grid-template-columns:repeat(3,1fr);gap:2px;padding:2px}
.cl-logo i{background:#c8102e;border-radius:1px}.cl-logo i:nth-child(2n){background:#7a8aa6}
.cl-menu .mi{font:inherit;font-size:18px;color:#1e3f73;background:none;border:0;padding:4px 2px;cursor:pointer;position:relative}
.cl-menu .mi.sm{font-size:13px;color:#4a5f80}
.cl-menu .title{font-size:24px;color:#1e3f73;margin-left:10px}
.cl-drop{position:absolute;top:100%;left:0;background:#fff;border:1px solid #a9bcd6;box-shadow:0 6px 18px rgba(0,0,0,.15);z-index:40;min-width:200px;display:none;flex-direction:column}
.cl-drop a{padding:10px 14px;text-decoration:none;color:#1e3f73;font-size:14px;white-space:nowrap}
.cl-drop a:hover{background:#e8f0fa}
.mi.open .cl-drop{display:flex}
.cl-ribbon{display:flex;gap:2px;padding:6px 10px 8px;flex-wrap:wrap;align-items:stretch}
.cl-ribbon a{display:flex;flex-direction:column;align-items:center;justify-content:flex-end;gap:2px;text-decoration:none;color:#1e3f73;font-size:17px;padding:4px 14px;border-radius:4px;border:1px solid transparent;min-width:110px}
.cl-ribbon a:hover{background:#eef4fc;border-color:#c5d5ea}
.cl-ribbon a.on{background:#dfe9f7;border-color:#9fb6d6}
.cl-ribbon svg{width:56px;height:56px;color:#d6263b}
.cl-ribbon .sep{width:1px;background:#c5d5ea;margin:4px 6px}
.cl-body{display:flex;gap:6px;padding:6px;height:calc(100vh - 190px);min-height:520px}
.cl-left{width:270px;flex:0 0 270px;display:flex;flex-direction:column;background:#e8eff8;border:1px solid #9fb6d6}
.cl-bar{background:linear-gradient(#2f64b4,#1d4c95);color:#fff;font-weight:700;font-size:15px;padding:5px 10px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.cl-pane{flex:1;overflow:auto;padding:10px;display:flex;flex-direction:column;gap:10px;font-size:13px;color:#1e3f73}
.cl-pane .sub{background:linear-gradient(#f2f6fb,#dbe6f3);border:1px solid #b9cbe2;text-align:center;padding:4px;font-weight:700;color:#1e3f73}
.cl-pane label.f{display:flex;align-items:center;gap:6px}
.cl-pane .inp{min-height:34px;font-size:13px;padding:5px 8px;border-radius:3px;border-color:#9fb6d6}
.cl-pane .btn2{min-height:34px;border-radius:4px;border-color:#9fb6d6;background:linear-gradient(#fff,#eef2f7);font-size:13px;justify-content:center}
.cl-tabs{border-top:3px double #6f8fbf}
.cl-tabs button{all:unset;cursor:pointer;display:flex;align-items:center;gap:8px;width:100%;box-sizing:border-box;padding:7px 10px;font-size:14px;color:#1e3f73;background:linear-gradient(#f4f7fb,#dfe8f4);border-bottom:1px solid #b9cbe2}
.cl-tabs button.on{background:linear-gradient(#ffd98a,#f5b54a)}
.cl-tabs svg{width:18px;height:18px;color:#c8102e}
.cl-main{flex:1;min-width:0;display:flex;flex-direction:column;gap:6px}
.cl-grid{background:#fff;border:1px solid #9fb6d6;display:flex;flex-direction:column;min-height:0}
.cl-grid .scr{overflow:auto;flex:1}
.cl-grid table{border-collapse:collapse;width:100%;font-size:13px}
.cl-grid th{position:sticky;top:0;background:linear-gradient(#fbfcfe,#e7edf5);color:#1e3f73;font-weight:400;text-align:left;padding:6px 8px;border-right:1px solid #d3deec;border-bottom:1px solid #b9cbe2;white-space:nowrap}
.cl-grid td{padding:5px 8px;border-right:1px solid #e3eaf3;border-bottom:1px solid #e3eaf3;white-space:nowrap;color:#1f2937}
.cl-grid tr:nth-child(even) td{background:#f6f9fd}
.cl-grid tr.sel td{background:#1f5fbf!important;color:#fff!important}
.cl-grid tr.paid td{color:#2a52be;text-decoration:line-through}
.cl-grid tbody tr{cursor:default}
.cl-grid .r{text-align:right}
.cl-grid .ind{width:14px;color:#1e3f73;border-right:1px solid #d3deec}
.cl-status{display:flex;gap:24px;align-items:center;padding:6px 14px;background:linear-gradient(#f4f7fb,#dfe8f4);border-top:1px solid #a9bcd6;font-size:13px;color:#1e3f73;flex-wrap:wrap}
.cl-status svg{width:16px;height:16px;color:#c8102e;vertical-align:-3px;margin-right:4px}
/* dialog ដូចកម្មវិធីចាស់ */
.cl-dlg-bg{position:fixed;inset:0;background:rgba(30,50,80,.25);display:flex;align-items:flex-start;justify-content:center;padding:30px 12px;z-index:60;overflow:auto}
.cl-dlg{background:#eef3f9;border:1px solid #7f9cc4;box-shadow:0 12px 40px rgba(0,0,0,.3);width:100%;max-width:1100px;display:flex;flex-direction:column}
.cl-dlg .hd{display:flex;align-items:center;justify-content:space-between;padding:8px 12px;background:linear-gradient(#fdfefe,#e3ebf5);border-bottom:1px solid #a9bcd6}
.cl-dlg .hd .t{display:flex;align-items:center;gap:8px;font-size:22px;color:#1e3f73}
.cl-dlg .hd .ic{all:unset;cursor:pointer;width:34px;height:34px;display:flex;align-items:center;justify-content:center;border-radius:6px;color:#c8102e}
.cl-dlg .hd .ic:hover{background:#dfe9f7}
.cl-dlg .hd .ic svg{width:26px;height:26px}
.cl-dlg .bd{padding:12px;display:flex;flex-direction:column;gap:10px}
.cl-dlg .f{display:flex;align-items:center;gap:8px;font-size:13px;color:#1e3f73}
.cl-dlg .f > span:first-child{min-width:92px;text-align:right}
.cl-dlg .inp{min-height:32px;font-size:13px;padding:4px 8px;border-radius:2px;border-color:#9fb6d6}
.cl-dlg .yel{background:#fcf3b6}
.cl-dlg .sale{width:62px;height:62px;border-radius:50%;background:#c8102e;color:#fff;font-weight:700;display:flex;align-items:center;justify-content:center;font-size:15px;flex:0 0 auto;clip-path:polygon(50% 0,61% 9%,75% 5%,79% 19%,93% 22%,90% 36%,100% 46%,91% 57%,96% 71%,82% 76%,79% 91%,64% 89%,53% 100%,42% 90%,27% 95%,22% 81%,8% 77%,11% 63%,0 53%,9% 42%,5% 28%,19% 24%,22% 10%,36% 12%)}
.cl-tool{display:flex;gap:4px;flex-wrap:wrap;padding:4px;background:linear-gradient(#f7f9fc,#e3ebf5);border:1px solid #b9cbe2}
.cl-tool button{font:inherit;font-size:13px;display:flex;align-items:center;gap:4px;background:none;border:1px solid transparent;border-radius:3px;padding:4px 8px;cursor:pointer;color:#1e3f73;min-height:32px}
.cl-tool button:hover{background:#fff;border-color:#9fb6d6}
.cl-tool svg{width:16px;height:16px;color:#c8102e}
.cl-entry{display:flex;flex-wrap:wrap;gap:12px;align-items:center;padding:8px 10px;background:linear-gradient(#cfe0f3,#b8d0ec);border:1px solid #9fb6d6}
.cl-sum{display:grid;grid-template-columns:auto 170px;gap:6px 8px;align-items:center;font-size:13px;color:#1e3f73}
.cl-sum span{text-align:right}
.cl-sum .inp{text-align:right}
@media (max-width:900px){.cl-body{flex-direction:column;height:auto}.cl-left{width:auto;flex:none}.cl-grid .scr{max-height:60vh}.cl-ribbon a{min-width:78px;font-size:13px}.cl-ribbon svg{width:38px;height:38px}}
@media print{.cl-head,.cl-status{display:none!important}}
body.classic #app{min-height:calc(100vh - 215px)}
/* វិក្កយបត្រ៖ បាតខាងក្រោម + ពិន្ទុ */
.ivf{display:flex;margin-top:8px;font-size:8.6pt;align-items:flex-start}
.ivl{flex:0 0 54%;max-width:54%;margin-right:auto;display:flex;flex-direction:column;gap:6px}
.ivr{display:flex;justify-content:space-between;align-items:center;gap:6px;min-height:24px}
.ivr>span:first-child{white-space:nowrap}
.ivm{flex:0 0 42mm;max-width:42mm;display:flex;flex-direction:column;gap:6px}
.ivm>div{display:flex;justify-content:space-between;align-items:center;gap:4px;min-height:24px;white-space:nowrap}
.ivp{display:flex;justify-content:space-between;align-items:center;gap:6px;border-radius:6px;padding:2px 6px;white-space:nowrap;min-width:26mm;box-sizing:border-box}
.ivp-r{border:1.5px solid #e11d2a;background:#fdecec}.ivp-g{border:1.5px solid #2f8f2f;background:#eef7ee}
.ivp-p{border:1.5px solid #6d28d9;background:#f2edfd}.ivp-o{border:1.5px solid #f97316;background:#fff4ea}
@media print{.ivp{-webkit-print-color-adjust:exact;print-color-adjust:exact}}
