:root {
  --navy: #1f3864; --navy2: #2f5597; --ink: #1d2433; --muted: #6b7486; --line: #dfe4ee; --line2: #c7d0e0;
  --bg: #f4f6fa; --card: #fff; --soft: #eef3fb; --input: #fffbea; --ok: #1e7b34; --warn: #b45309; --danger: #c0392b;
  --radius: 10px; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
  font-family: Arial, "Helvetica Neue", Helvetica, sans-serif;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font-size: 14px; }
a { color: var(--navy2); text-decoration: none; }
h1 { font-size: 22px; margin: 4px 0; color: var(--navy); }
h2 { font-size: 15px; margin: 0; color: var(--navy); }
h3 { font-size: 14px; margin: 0; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.sm { font-size: 12px; }
.strong, .b { font-weight: 700; }
.err { color: var(--danger); }
.nowrap { white-space: nowrap; }
input, select, button { font: inherit; color: inherit; }
input, select {
  border: 1px solid var(--line2); border-radius: 7px; padding: 7px 9px; background: #fff; min-width: 0;
}
input:focus, select:focus { outline: 2px solid #9cb6e6; outline-offset: 0; border-color: var(--navy2); }

.btn {
  display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line2); background: #fff;
  border-radius: 8px; padding: 8px 14px; cursor: pointer; font-weight: 600; white-space: nowrap; color: var(--ink);
}
.btn:hover { background: var(--soft); }
.btn.primary { background: var(--navy); border-color: var(--navy); color: #fff; }
.btn.primary:hover { background: var(--navy2); }
.btn.ghost { background: transparent; }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn.danger, .ib.danger { color: var(--danger); }
.ib { border: 0; background: transparent; cursor: pointer; padding: 3px 6px; border-radius: 5px; color: var(--muted); }
.ib:hover { background: var(--soft); color: var(--ink); }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { background: #fff; padding: 32px 28px; border-radius: 14px; box-shadow: var(--shadow); width: 100%; max-width: 360px; display: grid; gap: 12px; text-align: center; }
.login-card h1 { margin: 6px 0 0; }
.login-card p { margin: 0; }
.brand-mark { width: 52px; height: 52px; border-radius: 12px; background: var(--navy); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 20px; margin: 0 auto; }
.brand-mark.sm { width: 30px; height: 30px; font-size: 13px; border-radius: 8px; margin: 0; }

/* topbar */
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 18px; padding: 10px 20px; background: #fff; border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; color: var(--navy); }
.topbar nav { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
.topbar nav a { padding: 7px 12px; border-radius: 8px; color: var(--muted); font-weight: 600; white-space: nowrap; }
.topbar nav a.active, .topbar nav a:hover { background: var(--soft); color: var(--navy); }

.page { max-width: 1180px; margin: 0 auto; padding: 20px; }
.page.wide { max-width: 1500px; }
.page.narrow { max-width: 760px; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 16px; flex-wrap: wrap; }
.page-head p { margin: 2px 0 0; }
.head-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.back { font-size: 13px; color: var(--muted); }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.toolbar { display: flex; gap: 10px; margin-bottom: 12px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; min-width: 200px; }
.check { display: inline-flex; gap: 6px; align-items: center; white-space: nowrap; cursor: pointer; }
.empty { padding: 28px; text-align: center; color: var(--muted); }
.empty.sm { padding: 14px; font-size: 13px; }

.table-wrap { overflow-x: auto; }
table.grid { width: 100%; border-collapse: collapse; }
.grid th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .02em; color: var(--muted); padding: 9px 10px; border-bottom: 1px solid var(--line); background: #fafbfd; white-space: nowrap; }
.grid td { padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.grid tr:last-child td { border-bottom: 0; }
.grid .num { text-align: right; }
.grid .actions { text-align: right; white-space: nowrap; }
.grid .actions .btn { margin-left: 4px; }

/* editor */
.info { padding: 14px 16px; margin-bottom: 14px; }
.info-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px 14px; }
.fld { display: grid; gap: 4px; }
.fld > span { font-size: 12px; color: var(--muted); font-weight: 600; }
.fld input, .fld select { width: 100%; }
.info .fld input { background: var(--input); }
.save-state { font-size: 13px; color: var(--muted); min-width: 90px; text-align: right; }
.save-state.ok { color: var(--ok); }
.save-state.warn { color: var(--warn); }

.editor > * { min-width: 0; }
.editor { display: grid; grid-template-columns: minmax(330px, 420px) 1fr; gap: 14px; align-items: start; }
.picker { position: sticky; top: 64px; display: flex; flex-direction: column; max-height: calc(100vh - 80px); overflow: hidden; }
.picker-head { padding: 12px; border-bottom: 1px solid var(--line); display: grid; gap: 10px; }
.picker-head input { width: 100%; }
.chips { display: flex; flex-wrap: wrap; gap: 5px; }
.chip { border: 1px solid var(--line2); background: #fff; border-radius: 99px; padding: 4px 10px; font-size: 12px; cursor: pointer; font-weight: 600; color: var(--muted); }
.chip:hover { border-color: var(--navy2); color: var(--navy); }
.chip.on { background: var(--navy); border-color: var(--navy); color: #fff; }
.picker-list { overflow-y: auto; padding: 4px 6px 10px; }
.pgroup { position: sticky; top: 0; background: #fff; font-size: 11px; font-weight: 700; text-transform: uppercase; color: var(--navy2); padding: 10px 8px 4px; letter-spacing: .02em; }
.pitem { display: grid; grid-template-columns: 58px 1fr auto 26px; gap: 8px; align-items: center; width: 100%; text-align: left; border: 0; background: transparent; padding: 7px 8px; border-radius: 7px; cursor: pointer; }
.pitem:hover { background: var(--soft); }
.pitem.added { background: #edf7ef; }
.pitem.blank { opacity: .45; cursor: default; }
.pma { font-weight: 700; font-size: 12px; color: var(--navy); }
.pdg { font-size: 13px; line-height: 1.3; }
.pdg small { display: block; color: var(--warn); font-size: 11px; }
.pgia { font-variant-numeric: tabular-nums; font-size: 13px; font-weight: 600; }
.pgia em { font-style: normal; font-size: 11px; color: var(--warn); font-weight: 400; }
.padd { width: 24px; height: 24px; border-radius: 6px; display: grid; place-items: center; background: var(--soft); color: var(--navy); font-weight: 700; }
.pitem.added .padd { background: var(--ok); color: #fff; font-size: 11px; }

.summary { display: grid; grid-template-columns: auto 1fr; gap: 20px; padding: 14px 18px; margin-bottom: 14px; }
.sum-main { display: grid; gap: 2px; }
.sum-main span { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; }
.sum-main b { font-size: 26px; color: var(--navy); font-variant-numeric: tabular-nums; }
.sum-main small { color: var(--muted); }
.sum-parts { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; align-self: center; }
.sum-parts div { display: grid; gap: 2px; position: relative; padding-bottom: 6px; }
.sum-parts span { font-size: 12px; color: var(--muted); }
.sum-parts b { font-variant-numeric: tabular-nums; }
.sum-parts i { position: absolute; left: 0; bottom: 0; height: 3px; width: var(--w); background: var(--navy2); border-radius: 3px; }
.sum-parts div::after { content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 3px; background: var(--line); border-radius: 3px; z-index: -1; }

.phieu-head { display: flex; justify-content: space-between; align-items: center; margin: 18px 2px 8px; }
.phieu-head:first-child { margin-top: 0; }
.hs { display: inline-flex; gap: 6px; align-items: center; font-size: 13px; color: var(--muted); font-weight: 600; }
.hs input { width: 72px; background: var(--input); text-align: center; }
.sec { margin-bottom: 10px; overflow: hidden; }
.sec-head { display: flex; align-items: center; gap: 10px; padding: 10px 14px; background: #fafbfd; border-bottom: 1px solid var(--line); }
.sec-head h3 { color: var(--navy); }
.sec-total { margin-left: auto; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--navy); font-size: 15px; }
.lines td { padding: 4px 6px; }
.lines th { padding: 7px 6px; }
.lines input { width: 100%; padding: 5px 6px; border-color: transparent; background: transparent; }
.lines input:hover { border-color: var(--line2); }
.lines input[type=number] { text-align: right; background: var(--input); border-color: #f0e6bf; }
.lines input.need { background: #fde8d7; border-color: #f2b88a; }
.lines input:disabled { background: transparent; border-color: transparent; }
.lines .c-stt { width: 32px; color: var(--muted); text-align: center; }
.lines .c-ma { width: 70px; color: var(--navy); }
.lines .c-num { width: 96px; text-align: right; position: relative; font-variant-numeric: tabular-nums; }
.lines .c-lt { width: 64px; text-align: center; }
.lines .c-lt input { width: auto; }
.lines .c-act { width: 86px; text-align: right; white-space: nowrap; }
.lines .dot { position: absolute; top: 6px; right: 4px; width: 7px; height: 7px; border-radius: 50%; background: var(--warn); }
tr.flash td { animation: flash 1.4s ease; }
@keyframes flash { from { background: #fff4c2; } to { background: transparent; } }

/* bank */
.bank { table-layout: fixed; min-width: 1100px; }
.bank td { padding: 3px 6px; }
.bank input { width: 100%; border-color: transparent; background: transparent; padding: 5px 6px; }
.bank input:hover { border-color: var(--line2); }
.bank input:focus { background: #fff; }
.bank .w-gia { width: 92px; text-align: right; background: var(--input); border-color: #f0e6bf; }
.bank .w-dvt { width: 70px; }
.bank input.saved { background: #dff3e4 !important; transition: background .3s; }
.more { padding: 12px; text-align: center; }

.form { padding: 18px; display: grid; gap: 14px; }
.row2, .row3, .row5 { display: grid; gap: 12px; }
.row2 { grid-template-columns: 1fr 1fr; } .row3 { grid-template-columns: repeat(3, 1fr); } .row5 { grid-template-columns: repeat(5, 1fr); }
.dlg { border: 0; border-radius: 14px; padding: 0; width: min(520px, calc(100vw - 32px)); box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.dlg::backdrop { background: rgba(20,30,50,.4); }
.dlg-body { padding: 20px; display: grid; gap: 12px; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 9px; opacity: 0; transition: .2s; pointer-events: none; z-index: 100; max-width: calc(100vw - 32px); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.warn { background: var(--warn); }

@media (max-width: 1000px) {
  .editor { grid-template-columns: 1fr; }
  .picker { position: static; max-height: 60vh; }
  .summary { grid-template-columns: 1fr; }
  .info-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 640px) {
  .page { padding: 14px 12px; }
  .topbar { padding: 8px 12px; gap: 8px; }
  .brand span:last-child { display: none; }
  .sum-parts { grid-template-columns: repeat(2, 1fr); }
  .row3, .row5 { grid-template-columns: 1fr 1fr; }
}

/* ================= TRANG IN ================= */
.print-mode { background: #e9ecf2; }
.print-mode .topbar { display: none; }
.print-bar { position: sticky; top: 0; z-index: 10; display: flex; gap: 14px; align-items: center; padding: 10px 20px; background: #fff; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.print-bar .pick { display: flex; gap: 14px; flex: 1; flex-wrap: wrap; }
.print-area { padding: 20px 0 40px; display: grid; gap: 20px; justify-content: center; }
.print-area .off { display: none; }
.sheet {
  width: 297mm; min-height: 210mm; padding: 9mm 10mm; background: #fff; box-shadow: 0 2px 10px rgba(0,0,0,.12);
  font-family: Arial, sans-serif; color: #000; font-size: 10.5px; position: relative;
}
.p-top { display: flex; justify-content: space-between; font-size: 11px; }
.p-company { font-weight: 700; color: var(--navy); }
.p-title { text-align: center; font-size: 17px; font-weight: 700; margin: 4px 0 6px; color: var(--navy); letter-spacing: .01em; }
.p-meta { display: flex; gap: 28px; flex-wrap: wrap; margin: 2px 0; }
.p-meta.big { font-size: 11.5px; margin-bottom: 6px; justify-content: space-between; }
.p-hs { position: absolute; top: 9mm; right: 10mm; margin-top: 16px; border: 1px solid var(--navy); padding: 1px 6px; font-weight: 700; color: var(--navy); }
table.p-grid { width: 100%; border-collapse: collapse; table-layout: fixed; }
.p-grid th, .p-grid td { border: 1px solid #6f86b3; padding: 2px 4px; height: 18px; overflow: hidden; }
.p-grid td { white-space: nowrap; text-overflow: ellipsis; }
.p-grid thead th { background: var(--navy); color: #fff; font-size: 10px; text-align: center; line-height: 1.15; }
.p-grid thead th.w { background: #fff7d6; color: var(--navy); }
.p-grid thead th.ws, .p-grid thead th.wt { background: var(--navy2); font-size: 9px; }
.p-grid col.cs { width: 3.9%; } .p-grid col.ct { width: 5.6%; }
.p-grid .c { text-align: center; } .p-grid .r { text-align: right; font-variant-numeric: tabular-nums; }
.p-grid tr.sec td { background: #dce6f2; font-weight: 700; color: var(--navy); }
.p-grid tr.tot td { background: #e2efda; font-weight: 700; }
.p-grid tr.tot.strong td { background: var(--navy); color: #fff; font-size: 11.5px; }
.p-grid tr.blank td { color: #888; }
.p-grid tr.blank td:first-child { color: #999; text-align: center; }
.p-foot { display: flex; flex-direction: column; gap: 3px; margin-top: 8px; font-size: 11.5px; }
.p-foot.two { flex-direction: row; justify-content: space-between; align-items: flex-start; gap: 20px; }
.p-foot.two > div { display: grid; gap: 3px; }
table.p-mini { border-collapse: collapse; font-size: 10px; min-width: 42%; }
.p-mini th, .p-mini td { border: 1px solid #6f86b3; padding: 2px 6px; }
.p-mini th { background: var(--soft); color: var(--navy); }
.p-mini .tot td { background: #e2efda; font-weight: 700; }
.p-sign { display: flex; justify-content: space-around; margin-top: 12px; text-align: center; }
.p-sign div { display: grid; grid-template-rows: auto auto 13mm auto; min-width: 110px; }
.p-sign b { font-size: 11.5px; } .p-sign i { font-size: 9px; color: #666; }
.p-sign span { grid-row: 4; font-weight: 700; font-size: 11.5px; }
table.p-info { width: 100%; border-collapse: collapse; margin: 10px 0 14px; font-size: 12px; }
.p-info th, .p-info td { border: 1px solid #6f86b3; padding: 6px 8px; text-align: left; }
.p-info th { background: var(--soft); width: 16%; color: var(--navy); }
.p-grid.sumt { table-layout: auto; }
.sumt td, .sumt th { height: 26px; font-size: 12px; white-space: normal; }
.p-mini .r { text-align: right; } .p-mini .b { font-weight: 700; }

@page { size: A4 landscape; margin: 8mm 9mm; }
@media print {
  html, body, .print-mode { background: #fff; }
  .no-print, .topbar, .toast { display: none !important; }
  .print-area { padding: 0; gap: 0; display: block; }
  .sheet { box-shadow: none; break-after: page; width: auto; min-height: 0; padding: 0; zoom: var(--fit, 1); }
  .p-hs { top: 0; right: 0; }
  .p-grid tr, .p-sign { break-inside: avoid; }
  .print-area > .last .sheet { break-after: auto; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
