@font-face {
  font-family: 'Be Vietnam Pro';
  font-style: normal;
  font-display: swap;
  font-weight: 400;
  src: url(fonts/be-vietnam-pro-vietnamese-400-normal.woff2) format('woff2');
  unicode-range: U+0102-0103,U+0110-0111,U+0128-0129,U+0168-0169,U+01A0-01A1,U+01AF-01B0,U+0300-0301,U+0303-0304,U+0308-0309,U+0323,U+0329,U+1EA0-1EF9,U+20AB;
}
@font-face {
  font-family: 'Be Vietnam Pro';
  font-style: normal;
  font-display: swap;
  font-weight: 400;
  src: url(fonts/be-vietnam-pro-latin-ext-400-normal.woff2) format('woff2');
  unicode-range: U+0100-02BA,U+02BD-02C5,U+02C7-02CC,U+02CE-02D7,U+02DD-02FF,U+0304,U+0308,U+0329,U+1D00-1DBF,U+1E00-1E9F,U+1EF2-1EFF,U+2020,U+20A0-20AB,U+20AD-20C0,U+2113,U+2C60-2C7F,U+A720-A7FF;
}
@font-face {
  font-family: 'Be Vietnam Pro';
  font-style: normal;
  font-display: swap;
  font-weight: 400;
  src: url(fonts/be-vietnam-pro-latin-400-normal.woff2) format('woff2');
  unicode-range: U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD;
}
@font-face {
  font-family: 'Be Vietnam Pro';
  font-style: normal;
  font-display: swap;
  font-weight: 600;
  src: url(fonts/be-vietnam-pro-vietnamese-600-normal.woff2) format('woff2');
  unicode-range: U+0102-0103,U+0110-0111,U+0128-0129,U+0168-0169,U+01A0-01A1,U+01AF-01B0,U+0300-0301,U+0303-0304,U+0308-0309,U+0323,U+0329,U+1EA0-1EF9,U+20AB;
}
@font-face {
  font-family: 'Be Vietnam Pro';
  font-style: normal;
  font-display: swap;
  font-weight: 600;
  src: url(fonts/be-vietnam-pro-latin-ext-600-normal.woff2) format('woff2');
  unicode-range: U+0100-02BA,U+02BD-02C5,U+02C7-02CC,U+02CE-02D7,U+02DD-02FF,U+0304,U+0308,U+0329,U+1D00-1DBF,U+1E00-1E9F,U+1EF2-1EFF,U+2020,U+20A0-20AB,U+20AD-20C0,U+2113,U+2C60-2C7F,U+A720-A7FF;
}
@font-face {
  font-family: 'Be Vietnam Pro';
  font-style: normal;
  font-display: swap;
  font-weight: 600;
  src: url(fonts/be-vietnam-pro-latin-600-normal.woff2) format('woff2');
  unicode-range: U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD;
}
@font-face {
  font-family: 'Be Vietnam Pro';
  font-style: normal;
  font-display: swap;
  font-weight: 800;
  src: url(fonts/be-vietnam-pro-vietnamese-800-normal.woff2) format('woff2');
  unicode-range: U+0102-0103,U+0110-0111,U+0128-0129,U+0168-0169,U+01A0-01A1,U+01AF-01B0,U+0300-0301,U+0303-0304,U+0308-0309,U+0323,U+0329,U+1EA0-1EF9,U+20AB;
}
@font-face {
  font-family: 'Be Vietnam Pro';
  font-style: normal;
  font-display: swap;
  font-weight: 800;
  src: url(fonts/be-vietnam-pro-latin-ext-800-normal.woff2) format('woff2');
  unicode-range: U+0100-02BA,U+02BD-02C5,U+02C7-02CC,U+02CE-02D7,U+02DD-02FF,U+0304,U+0308,U+0329,U+1D00-1DBF,U+1E00-1E9F,U+1EF2-1EFF,U+2020,U+20A0-20AB,U+20AD-20C0,U+2113,U+2C60-2C7F,U+A720-A7FF;
}
@font-face {
  font-family: 'Be Vietnam Pro';
  font-style: normal;
  font-display: swap;
  font-weight: 800;
  src: url(fonts/be-vietnam-pro-latin-800-normal.woff2) format('woff2');
  unicode-range: U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD;
}
:root{--blue:#0B3D91;--red:#E0202A;--ink:#0E2A5C;--ink-2:#4A5B7A;--line:#DCE3EE;--bg:#F2F5FA;--tint:#E8EEF8;
  --splash:linear-gradient(90deg,#0B3D91 0 20%,#1E88D2 20% 38%,#7DB53B 38% 56%,#F2B705 56% 72%,#F28C28 72% 86%,#E0202A 86%)}
*{box-sizing:border-box}
html,body{margin:0}
body{font:16px/1.5 'Be Vietnam Pro',system-ui,sans-serif;color:var(--ink);background:var(--bg);-webkit-text-size-adjust:100%;font-variant-numeric:tabular-nums}
:focus-visible{outline:3px solid #1E88D2;outline-offset:2px}
button,input,select{font:inherit;color:inherit}
input,select{font-size:16px;font-weight:400;min-height:46px;width:100%;padding:10px 12px;border:1px solid var(--line);border-radius:10px;background:#fff}
input:focus,select:focus{border-color:var(--blue);outline:none;box-shadow:0 0 0 3px #0B3D9126}
button{min-height:44px;min-width:44px;padding:8px 16px;border:1px solid var(--line);background:#fff;color:var(--blue);border-radius:10px;font-weight:600;cursor:pointer}
button:active{transform:translateY(1px)}
button.primary{background:var(--blue);border-color:var(--blue);color:#fff}
button.danger{color:var(--red);border-color:#F3C4C6}
button:disabled{opacity:.6}

/* header: brand blue with the logo's paint-splash colours as a band */
.top{position:sticky;top:0;z-index:5;display:flex;align-items:center;gap:12px;padding:calc(10px + env(safe-area-inset-top)) 14px 15px;background:var(--blue);color:#fff}
.top::after{content:'';position:absolute;left:0;right:0;bottom:0;height:5px;background:var(--splash)}
.top h1{font-size:19px;font-weight:800;margin:0;flex:1;letter-spacing:-.01em}
.top img{height:38px;background:#fff;border-radius:10px;padding:3px}
.top button{background:#ffffff1a;color:#fff;border-color:#ffffff4d;font-size:18px}
.top .status{font-size:13px;opacity:.85;white-space:nowrap}
.top .status.err{background:var(--red);padding:3px 10px;border-radius:8px;opacity:1;white-space:normal}

main{padding:14px 14px 130px;max-width:980px;margin:0 auto}
main:has(.grid){max-width:1200px}
.h2row{display:flex;align-items:center;justify-content:space-between;gap:12px}
.h2row h2{margin:24px 0 10px}
h2{font-size:17px;font-weight:800;margin:24px 0 10px}
.muted{color:var(--ink-2);font-size:14px;overflow-wrap:anywhere}
.card{background:#fff;border:1px solid var(--line);border-radius:14px;padding:14px;margin:0 0 12px}
.card h2{margin-top:0}
label{display:block;font-size:13px;font-weight:600;color:var(--ink-2);margin:12px 0 4px}

/* list: one sheet, rows divided, each slip marked by a paint chip */
input[type=search]{padding-left:42px;background:#fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' fill='none' stroke='%234A5B7A' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='9' cy='9' r='6'/%3E%3Cpath d='m14 14 4 4'/%3E%3C/svg%3E") no-repeat 12px center;margin-bottom:12px}
.slips{background:#fff;border:1px solid var(--line);border-radius:14px;overflow:hidden}
.slip{display:flex;align-items:center;border-top:1px solid var(--line)}
.slip:first-child{border-top:0}
.slip-main{flex:1;min-width:0;display:flex;align-items:center;gap:12px;padding:12px 6px 12px 14px;border:0;border-radius:0;background:none;color:inherit;text-align:left;font-weight:400}
.chip{flex:0 0 44px;height:56px;border-radius:5px 5px 9px 9px;background:var(--c);color:#fff;font-weight:800;font-size:15px;display:flex;align-items:flex-end;justify-content:center;padding-bottom:5px;box-shadow:inset 0 -16px 0 #00000024}
.slip-info{flex:1;min-width:0;display:flex;flex-direction:column}
.slip-info>*{white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.slip-info b{font-weight:600}
.slip-info .meta{font-size:13px;color:var(--ink-2)}
.slip-right{display:flex;flex-direction:column;align-items:flex-end;gap:2px}
.slip-right .meta{font-size:13px;color:var(--ink-2)}
.slip-total{font-weight:800;color:var(--red);white-space:nowrap;font-size:15px}
.slip .more{border:0;background:none;color:var(--ink-2);font-size:22px;margin-right:2px}
.empty{text-align:center;padding:56px 24px}
.empty .chips{display:flex;justify-content:center;gap:6px;margin-bottom:18px}
.empty .chip{flex-basis:30px;height:42px}
.empty b{display:block;font-size:18px;margin-bottom:4px}
.fab{position:fixed;right:16px;bottom:calc(18px + env(safe-area-inset-bottom));z-index:6;background:var(--red);border-color:var(--red);color:#fff;border-radius:999px;padding:0 24px;min-height:54px;box-shadow:0 6px 18px #E0202A55}

/* editor */
.buyer{background:#fff;border:1px solid var(--line);border-radius:14px;margin-bottom:6px}
.buyer summary{list-style:none;cursor:pointer;padding:14px 84px 14px 14px;position:relative;display:flex;flex-direction:column}
.buyer summary::-webkit-details-marker{display:none}
.buyer summary::after{content:'Sửa';position:absolute;right:14px;top:14px;font-size:14px;font-weight:600;color:var(--blue)}
.buyer[open] summary::after{content:'Thu gọn'}
.buyer .who{font-size:18px;font-weight:800;line-height:1.3}
.buyer .fields{padding:2px 14px 14px;border-top:1px solid var(--line)}
.grid{overflow-x:auto;background:#fff;border:1px solid var(--line);border-radius:14px;margin-bottom:10px;-webkit-overflow-scrolling:touch}
.grid table{border-collapse:separate;border-spacing:0;min-width:100%}
.grid th,.grid td{border-bottom:1px solid var(--line);border-right:1px solid var(--line);padding:0;vertical-align:middle}
.grid tr>:last-child{border-right:0}
.grid tbody tr:last-child td{border-bottom:0}
.grid tbody tr:nth-child(even) td{background:#F7F9FC}
.grid th{background:var(--tint);font-size:13px;font-weight:600;padding:9px 10px;white-space:nowrap;text-align:left}
.grid th.t-number,.grid th.t-money,.grid th.t-amount{text-align:right}
.grid td input{border:0;border-radius:0;background:transparent;min-width:130px}
.grid td input:focus{box-shadow:inset 0 0 0 2px var(--blue);background:#fff}
.grid td:focus-within{background:#fff!important}
.grid td.t-number input{min-width:72px;width:72px;text-align:right}
.grid td.t-money input{min-width:120px;width:120px;text-align:right}
.grid td.t-date input{min-width:130px}
.grid tbody tr:hover td{background:#EEF3FB}
.grid .ro{min-height:46px;min-width:120px;display:flex;align-items:center;justify-content:flex-end;padding:0 10px;font-weight:700}
.grid .hint{padding:0 8px 4px;font-size:12px;max-width:150px}
.grid .stt,.grid th:first-child{position:sticky;left:0;z-index:1;background:var(--tint)}
.grid tbody tr:nth-child(even) td.stt{background:var(--tint)}
.grid .stt button{border:0;background:transparent;min-width:44px;font-weight:800;color:var(--blue)}
.addcol{min-height:36px;padding:2px 14px;white-space:nowrap;font-size:14px}
.addrow{width:100%;border:1.5px dashed #B9C6DC;background:transparent}
.imgcell{display:flex;align-items:center;justify-content:center;width:72px;height:62px;min-height:0;margin:3px auto;padding:0;border:1.5px dashed #B9C6DC;border-radius:8px;font-size:22px;cursor:pointer;background:#fff}
.imgcell:not(.empty){border:0;background:none}
.imgcell img{max-width:72px;max-height:62px;object-fit:cover;border-radius:6px}
.foot{position:fixed;left:0;right:0;bottom:0;z-index:5;display:flex;gap:12px;align-items:center;padding:10px 16px calc(10px + env(safe-area-inset-bottom));background:#fff;box-shadow:0 -6px 20px #0E2A5C17}
.foot .sum{flex:1;font-size:13px;color:var(--ink-2);font-weight:600}
.foot .sum b{display:block;font-size:22px;color:var(--red);font-weight:800;line-height:1.2}
.foot .primary{min-height:52px;padding:0 24px}
.spin{display:inline-block;width:14px;height:14px;border:2px solid #fff6;border-top-color:#fff;border-radius:50%;animation:sp .7s linear infinite;vertical-align:-2px;margin-right:8px}
@keyframes sp{to{transform:rotate(360deg)}}
.atts{display:grid;grid-template-columns:repeat(auto-fill,minmax(140px,1fr));gap:10px}
.atts div{position:relative}
.atts img{width:100%;aspect-ratio:1;object-fit:cover;border-radius:10px;display:block}
.atts button{position:absolute;top:6px;right:6px;background:#fffe;border-color:#fff;color:var(--red);min-height:36px;min-width:36px;padding:0;border-radius:50%}

/* phone: each row becomes a labelled card instead of a wide scrolling table */
@media (max-width:640px){
  main{padding:10px 10px 130px}
  .grid{border:0;background:none;overflow:visible}
  .grid table,.grid tbody{display:block}
  .grid thead{display:none}
  .grid tbody tr{display:grid;grid-template-columns:1fr 1fr;gap:2px 10px;background:#fff;border:1px solid var(--line);border-radius:14px;margin-bottom:10px;padding:4px 12px 10px}
  .grid tbody tr:hover td,.grid tbody tr:nth-child(even) td,.grid td{display:block;border:0;background:none;position:static;min-width:0}
  .grid td::before{content:attr(data-label);display:block;font-size:12px;font-weight:600;color:var(--ink-2);margin:6px 0 2px}
  .grid td.t-text,.grid td.t-image{grid-column:1/-1}
  .grid td.stt{grid-column:1/-1;background:none!important;display:flex;justify-content:space-between}
  .grid td.stt::before{display:none}
  .grid .stt button::before{content:'Dòng '}
  .grid .stt button::after{content:' ⋯';color:var(--ink-2)}
  .grid .stt button{width:100%;text-align:left;padding:0}
  .grid td input,.grid td.t-number input,.grid td.t-money input,.grid td.t-date input{width:100%;min-width:0;border:1px solid var(--line);border-radius:10px;background:#fff;text-align:left}
  .grid td.t-number input,.grid td.t-money input{text-align:right}
  .grid .ro{min-width:0;justify-content:flex-end;min-height:46px;background:var(--tint);border-radius:10px}
  .grid .hint{max-width:none;padding:2px 0}
  .imgcell{margin:0;width:96px;height:80px}
  .imgcell img{max-width:96px;max-height:80px}
}

/* sheets & dialogs */
.modal{position:fixed;inset:0;z-index:20;background:#0E2A5C8c;display:flex;align-items:flex-end;justify-content:center}
.modal .sheet{background:#fff;width:100%;max-width:560px;max-height:92vh;overflow:auto;border-radius:20px 20px 0 0;padding:18px 16px calc(16px + env(safe-area-inset-bottom));animation:up .18s ease-out}
.modal.center{align-items:center}
.modal.center .sheet{border-radius:18px;width:calc(100% - 32px);max-height:84vh;padding-bottom:16px}
.modal .sheet>p{font-size:17px;font-weight:600;margin:4px 0 12px}
.modal .sheet>.btns button{flex:1}
@keyframes up{from{transform:translateY(24px);opacity:0}}
@media (prefers-reduced-motion:reduce){.modal .sheet{animation:none}.spin{animation-duration:2s}}
/* column editor: one compact row per column */
.modal .sheet.colsheet{padding-top:0}
.sheet-head+.muted{margin:-4px 0 10px}
.sheet-head{position:sticky;top:0;z-index:1;display:flex;align-items:center;justify-content:space-between;gap:12px;background:#fff;padding:14px 0 10px}
.sheet-head h2{margin:0}
.cols{border:1px solid var(--line);border-radius:14px;overflow:hidden;margin-bottom:12px}
.colrow{display:flex;align-items:stretch;gap:8px;padding:10px 8px;border-top:1px solid var(--line)}
.colrow:first-child{border-top:0}
.colrow.off .colbody input:not([type]){color:var(--ink-2);text-decoration:line-through}
.order{display:flex;flex-direction:column;gap:4px}
.order button{flex:1;min-height:0;min-width:36px;padding:0;border:0;background:var(--tint);font-size:11px}
.order button:disabled{opacity:.3}
.colbody{flex:1;min-width:0;display:flex;flex-direction:column;gap:6px}
.colbody input{min-height:42px;font-weight:600}
.colopts{display:flex;gap:6px;align-items:center}
.colopts select{flex:1;min-width:0;min-height:40px;padding:6px 8px;font-size:15px}
.side{display:flex;flex-direction:column;align-items:center;justify-content:space-between;gap:6px}
.colrow .del{border:0;background:none;color:var(--red);font-size:18px;min-height:42px}
.side .switch{min-height:40px}
.switch{display:flex;align-items:center;gap:6px;margin:0;font-size:14px;color:var(--ink);cursor:pointer;white-space:nowrap}
.switch input{appearance:none;-webkit-appearance:none;width:40px;min-width:40px;height:24px;min-height:24px;padding:0;margin:0;border-radius:12px;background:#C5CFDF;border:0;position:relative;cursor:pointer;transition:background .15s}
.switch input::after{content:'';position:absolute;top:3px;left:3px;width:18px;height:18px;border-radius:50%;background:#fff;transition:transform .15s}
.switch input:checked{background:#7DB53B}
.switch input:checked::after{transform:translateX(16px)}
.switch input:focus{box-shadow:0 0 0 3px #0B3D9126}
.btns{display:flex;gap:8px;flex-wrap:wrap;margin:10px 0}
#toast{position:fixed;left:14px;right:14px;bottom:calc(92px + env(safe-area-inset-bottom));z-index:30;max-width:560px;margin:0 auto;background:var(--red);color:#fff;padding:12px 16px;border-radius:12px;font-weight:600;display:none;box-shadow:0 8px 24px #0E2A5C33}
#toast.ok{background:var(--ink)}
.hint{color:var(--red);font-size:13px}
input.bad{border-color:var(--red)}
.note{background:var(--tint);border-radius:10px;padding:12px;font-size:14px}
.preview{display:block;max-width:100%;max-height:60vh;margin:0 auto 4px;border-radius:10px}
label.btn{display:inline-flex;align-items:center;justify-content:center;min-height:44px;padding:8px 16px;border:1px solid var(--line);border-radius:10px;color:var(--blue);font-size:16px;font-weight:600;margin:0;cursor:pointer;background:#fff}
.modal label.btn{flex:1}
