:root {
  --giay: #eeede9;
  --giay-2: #e5e3dd;
  --trang: #f8f7f4;
  --muc: #1b2536;
  --muc-2: #4a5465;
  --tem: #2d4b7e;
  --tem-d: #243d68;
  --son: #b1361f;
  --bao: #cfbc98;
  --bao-2: #e3d6bb;
  --line: rgba(27, 37, 54, 0.16);
  --line-2: rgba(27, 37, 54, 0.3);
  --ease: cubic-bezier(0.32, 0.72, 0, 1);
  --serif: 'Newsreader', 'Iowan Old Style', Georgia, serif;
  --sans: 'Be Vietnam Pro', 'Segoe UI', system-ui, sans-serif;
  --r-form: 0.5rem;
  --r-tem: 1.25rem;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--giay); color: var(--muc); font: 400 15px/1.55 var(--sans); font-variant-numeric: tabular-nums; min-width: 0; overflow-x: hidden; }
h1, h2, h3 { font-family: var(--serif); font-weight: 500; margin: 0; letter-spacing: -0.02em; line-height: 1.12; text-wrap: balance; }
p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--tem); text-underline-offset: 0.2em; }
::selection { background: var(--bao); color: var(--muc); }
:focus-visible { outline: 2px solid var(--tem); outline-offset: 2px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.mute { color: var(--muc-2); }
.n { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

.demobar { display: flex; flex-wrap: wrap; gap: 0.25rem 1.25rem; align-items: center; justify-content: space-between; padding: 0.6rem 1rem; background: var(--muc); color: var(--giay); font-size: 13px; }
.demobar nav { display: flex; flex-wrap: wrap; gap: 0.25rem 1rem; align-items: center; }
.demobar a, .demobar .linkbtn { color: var(--giay); text-decoration: none; padding: 0.15rem 0; border-bottom: 1px solid transparent; }
.demobar a[aria-current] { border-bottom-color: var(--bao); }
.demobar a:hover, .demobar .linkbtn:hover { border-bottom-color: var(--giay); }
.demobar :focus-visible { outline-color: var(--bao); }
.linkbtn { background: none; border: 0; padding: 0; cursor: pointer; font-size: inherit; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem; min-height: 40px; padding: 0.45rem 1.1rem; border-radius: 999px; border: 1px solid transparent; background: var(--giay-2); color: var(--muc); font-weight: 500; font-size: 14px; cursor: pointer; text-decoration: none; transition: transform 160ms var(--ease); white-space: nowrap; }
.btn:active { transform: scale(0.98); }
.btn.primary { background: var(--tem); color: #fff; }
.btn.primary:hover { background: var(--tem-d); }
.btn.ghost { background: transparent; border-color: var(--line-2); }
.btn.ghost:hover { background: var(--giay-2); }
.btn.danger { background: transparent; border-color: var(--son); color: var(--son); }
.btn.danger:hover { background: var(--son); color: #fff; }
.btn.sm { min-height: 38px; padding: 0.3rem 0.8rem; font-size: 13px; }
.btn[disabled], .btn[aria-disabled='true'] { background: transparent; border: 1px dashed var(--line-2); color: var(--muc-2); cursor: not-allowed; transform: none; }
.btn[disabled]:hover { background: transparent; color: var(--muc-2); }
.btn.busy::after { content: ''; width: 0.7em; height: 0.7em; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin 700ms linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.field { display: grid; gap: 0.25rem; margin-bottom: 0.9rem; min-width: 0; }
.field label { font-size: 13px; font-weight: 500; color: var(--muc-2); }
input, select, textarea { width: 100%; min-height: 40px; padding: 0.45rem 0.7rem; border: 1px solid var(--line-2); border-radius: var(--r-form); background: var(--trang); }
textarea { resize: vertical; }
input:hover, select:hover, textarea:hover { border-color: var(--muc); }
input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 2px solid var(--tem); outline-offset: 0; border-color: var(--tem); }
input[disabled], select[disabled], textarea[disabled] { border-style: dashed; background: transparent; color: var(--muc-2); cursor: not-allowed; }
[aria-invalid='true'] { border-color: var(--son); }
select { appearance: none; padding-right: 2rem; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5 6 6.5l5-5' fill='none' stroke='%231B2536' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 0.75rem center; }
input[type='checkbox'], input[type='radio'] { appearance: none; width: 18px; height: 18px; min-height: 0; padding: 0; border: 1.5px solid var(--muc); border-radius: 4px; background: var(--trang); display: inline-grid; place-content: center; cursor: pointer; vertical-align: middle; }
input[type='radio'] { border-radius: 50%; }
input[type='checkbox']:checked, input[type='radio']:checked { background: var(--tem); border-color: var(--tem); }
input[type='checkbox']:checked::after { content: ''; width: 9px; height: 5px; border: solid #fff; border-width: 0 0 2px 2px; transform: rotate(-45deg) translate(1px, -1px); }
input[type='radio']:checked::after { content: ''; width: 7px; height: 7px; border-radius: 50%; background: #fff; }
input[type='date'] { appearance: none; }
.err { color: var(--son); font-size: 13px; min-height: 0; }
.err:empty { display: none; }
.hint { font-size: 12.5px; color: var(--muc-2); }
.err-line { color: var(--son); font-size: 13px; padding: 0.35rem 0; }

.st { display: inline-block; padding: 0.2rem 0.7rem; border: 1px solid var(--line-2); border-radius: 999px; font-size: 12.5px; line-height: 1.5; white-space: nowrap; color: var(--muc); background: transparent; transition: opacity 200ms linear; }
.st.ok { border-color: var(--tem); color: var(--tem); }
.st.bad { border-color: var(--son); color: var(--son); }

.banner { padding: 0.7rem 0.9rem; border: 1px solid var(--line-2); border-radius: var(--r-form); background: var(--trang); font-size: 14px; }
.banner.bad { border-color: var(--son); color: var(--son); }
.banner strong { font-weight: 600; }
.empty { padding: 1.4rem 0.5rem; color: var(--muc-2); text-align: center; border: 1px dashed var(--line-2); border-radius: var(--r-form); }
.empty .btn { margin-top: 0.7rem; }

.tablewrap { overflow-x: auto; max-width: 100%; }
table.ledger { width: 100%; border-collapse: collapse; font-size: 14px; }
.ledger th { text-align: left; font-size: 13px; font-weight: 600; color: var(--muc-2); padding: 0.5rem 0.7rem; border-bottom: 1px solid var(--muc); white-space: nowrap; }
.ledger th.n { text-align: right; }
.ledger td:first-child { white-space: nowrap; }
.ledger td { padding: 0.55rem 0.7rem; border-bottom: 1px solid var(--line); vertical-align: top; }
.ledger tbody tr:hover { background: rgba(27, 37, 54, 0.04); }
.ledger tr[aria-selected='true'] { background: rgba(45, 75, 126, 0.1); }
.ledger tfoot td { border-top: 1px solid var(--muc); border-bottom: 0; font-weight: 600; }
.ledger tr.leave { animation: leave 180ms var(--ease) forwards; }
.ledger tr.in, .rowin { animation: rowin 180ms var(--ease) both; }
@keyframes leave { to { opacity: 0; transform: translateX(14px); } }
@keyframes rowin { from { opacity: 0; transform: translateY(4px); } }
.sk { height: 14px; border-radius: 4px; background: var(--line); animation: pulse 1.1s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.4; } }

dialog.dlg { border: 1px solid var(--line-2); border-radius: 1rem; padding: 0; background: var(--trang); color: var(--muc); width: min(30rem, calc(100vw - 2rem)); max-height: min(88dvh, 44rem); box-shadow: 0 12px 32px -16px rgba(27, 37, 54, 0.45); overflow: hidden; }
dialog.dlg.wide { width: min(46rem, calc(100vw - 2rem)); }
dialog.dlg[open] { animation: dlgin 200ms var(--ease); display: flex; flex-direction: column; }
dialog.dlg::backdrop { background: rgba(27, 37, 54, 0.45); }
dialog.dlg form { display: flex; flex-direction: column; min-height: 0; max-height: inherit; }
dialog.dlg header { padding: 1.1rem 1.25rem 0.4rem; }
dialog.dlg h2 { font-size: 1.4rem; }
.dlg-body { padding: 0.6rem 1.25rem 0.4rem; overflow-y: auto; min-height: 0; }
.dlg-body p + .field, .dlg-body p + p { margin-top: 0.7rem; }
.dlg-err { color: var(--son); font-size: 13.5px; }
.dlg-err:empty { display: none; }
dialog.dlg footer { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 0.5rem; padding: 0.8rem 1.25rem 1rem; border-top: 1px solid var(--line); }
@keyframes dlgin { from { opacity: 0; transform: scale(0.98); } }

#toasts { position: fixed; z-index: 99; left: 1rem; right: 1rem; bottom: 1rem; display: grid; gap: 0.4rem; justify-items: center; pointer-events: none; }
.toast { background: var(--muc); color: var(--giay); padding: 0.6rem 1rem; border-radius: 999px; font-size: 14px; max-width: 100%; animation: rowin 200ms var(--ease); }
.toast.err { background: var(--son); color: #fff; }
.toast.out { opacity: 0; transition: opacity 200ms linear; }

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

@media (max-width: 600px) { .demobar > span { display: none; } }

/* Bảng dòng hàng của đơn (dong-don.js) */
.ln { container-type: inline-size; display: grid; gap: 0.7rem; min-width: 0; }
.ln-add { display: flex; gap: 0.6rem; align-items: flex-end; flex-wrap: wrap; }
.ln-q { flex: 1 1 14rem; min-width: 0; }
.ln-q label { display: block; font-size: 13px; font-weight: 500; color: var(--muc-2); margin-bottom: 0.25rem; }
.ln-box { max-height: 26rem; overflow: auto; border: 1px solid var(--line-2); border-radius: var(--r-form); background: var(--trang); overscroll-behavior: contain; }
.ln-box:focus-visible { outline: 2px solid var(--tem); }
.ln-row { display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 1.35fr) 5.5rem 7rem 8rem 4.4rem; gap: 0.4rem 0.7rem; align-items: start; padding: 0.55rem 0.8rem; border-bottom: 1px solid var(--line); }
.ln-row:last-child { border-bottom: 0; }
.ln-row .c { min-width: 0; }
.ln-row .c.n { text-align: right; padding-top: 0.55rem; }
.ln-row .c.x { justify-self: end; }
.ln-row .lbl { display: none; font-size: 12px; color: var(--muc-2); }
.ln-row .sub { display: block; font-size: 12px; color: var(--muc-2); margin-top: 0.15rem; }
.ln-row input, .ln-row select { min-height: 38px; }
.ln-row .chg { display: block; font-size: 12px; color: var(--son); }
.ln-head { position: sticky; top: 0; z-index: 2; background: var(--giay); font-size: 13px; font-weight: 600; color: var(--muc-2); border-bottom: 1px solid var(--muc); align-items: center; padding-block: 0.45rem; }
.ln-head .n { text-align: right; padding-top: 0; }
.ln-err { grid-column: 1 / -1; color: var(--son); font-size: 13px; margin: 0; }
.ln-row.flash { animation: lnflash 1.4s var(--ease); }
@keyframes lnflash { from { background: var(--bao-2); } }
.ln-empty { padding: 1rem; color: var(--muc-2); font-size: 14px; }
.ln-foot { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 0.3rem 1rem; align-items: baseline; font-size: 14px; color: var(--muc-2); }
.ln-sum { font-family: var(--serif); font-size: 1.5rem; color: var(--muc); }
.ln-sum b { font-weight: 500; }
.ln-note { font-size: 13.5px; }
.ln-note .bad { color: var(--son); }
.ln-msg { margin: 0; min-height: 1.2em; font-size: 13.5px; color: var(--muc-2); }
.ln-msg.bad { color: var(--son); }
@container (max-width: 46rem) {
  .ln-head { display: none; }
  .ln-row { grid-template-columns: minmax(0, 0.8fr) minmax(0, 1.2fr); padding: 0.7rem 0.8rem 0.8rem; }
  .ln-row .lbl { display: block; }
  .ln-row .c.n { text-align: left; padding-top: 0; }
  .ln-row .c.x { grid-column: 2; grid-row: 4; align-self: end; }
  .ln-row .ct { grid-column: 1; grid-row: 4; }
  .ln-box { max-height: 30rem; }
}
@media (prefers-reduced-motion: reduce) { .ln-row.flash { animation: none; } }
.ln-msg .linkbtn { background: none; border: 0; padding: 0; color: var(--tem); text-decoration: underline; cursor: pointer; font-weight: 500; }
.field .fl { display: block; font-size: 13px; font-weight: 500; color: var(--muc-2); margin-bottom: 0.25rem; }
.dlg .ln-box { max-height: 16rem; }
