:root {
  --bg: #f5f6f8; --card: #fff; --ink: #1c2330; --muted: #6b7380; --line: #dfe3ea;
  --brand: #1f6f5c; --brand-ink: #fff; --warn: #b45309; --bad: #b42318; --ok: #1a7f37; --soft: #e8f3ef;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12161c; --card: #1a2029; --ink: #e8ecf2; --muted: #98a2b3; --line: #2b3441;
    --brand: #3aa88f; --brand-ink: #08130f; --warn: #f0a24b; --bad: #f97066; --ok: #4ac26b; --soft: #1b2b27;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--brand); }
.muted { color: var(--muted); }
.pad { padding: 24px 16px; }
.topbar { display: flex; align-items: center; gap: 16px; padding: 0 16px; height: 52px; background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.brand { font-weight: 700; font-size: 17px; text-decoration: none; color: var(--brand); }
nav { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
nav a { padding: 6px 12px; border-radius: 6px; text-decoration: none; color: var(--ink); white-space: nowrap; }
nav a.on { background: var(--soft); color: var(--brand); font-weight: 600; }
.who { color: var(--muted); font-size: 12px; white-space: nowrap; }
main { max-width: 1180px; margin: 0 auto; padding: 16px; }
h1 { font-size: 20px; margin: 4px 0 14px; }
h2 { font-size: 15px; margin: 0 0 10px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; margin-bottom: 14px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
.grow { flex: 1; min-width: 200px; }
label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 3px; }
input, select, textarea { width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 7px; background: var(--card); color: var(--ink); font: inherit; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: -1px; }
input[type=checkbox] { width: auto; }
button { padding: 8px 14px; border-radius: 7px; border: 1px solid var(--line); background: var(--card); color: var(--ink); font: inherit; cursor: pointer; }
button:hover { border-color: var(--brand); }
button.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); font-weight: 600; }
button.danger { color: var(--bad); }
button:disabled { opacity: .5; cursor: not-allowed; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; white-space: nowrap; }
td.num, th.num { text-align: right; white-space: nowrap; }
tbody tr.click { cursor: pointer; }
tbody tr.click:hover { background: var(--soft); }
.pick { border: 1px solid var(--line); border-radius: 8px; max-height: 260px; overflow: auto; margin-top: 6px; }
.pick div { padding: 7px 10px; border-bottom: 1px solid var(--line); cursor: pointer; }
.pick div:hover { background: var(--soft); }
.pick div:last-child { border-bottom: 0; }
.pill { display: inline-block; padding: 1px 8px; border-radius: 99px; font-size: 11px; background: var(--soft); color: var(--brand); }
.pill.warn { background: transparent; border: 1px solid var(--warn); color: var(--warn); }
.warn { color: var(--warn); }
.bad { color: var(--bad); }
.ok { color: var(--ok); }
.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 8px; z-index: 20; max-width: 90vw; }
.toast.err { background: var(--bad); color: #fff; }
dialog { border: 1px solid var(--line); border-radius: 12px; padding: 18px; background: var(--card); color: var(--ink); width: min(560px, 94vw); }
dialog::backdrop { background: rgba(0,0,0,.4); }
.actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; }
.lines td input, .lines td select { padding: 5px 7px; }
.lines td.price input { text-align: right; width: 112px; }
.lines td.moq input { width: 84px; }
.small { font-size: 12px; }

/* ===== Mẫu in báo giá (A4) ===== */
.sheet { background: #fff; color: #000; width: 210mm; min-height: 297mm; margin: 0 auto 20px; padding: 12mm 12mm; font: 12px/1.4 "Times New Roman", Times, serif; box-shadow: 0 1px 8px rgba(0,0,0,.15); }
.sheet .co { text-align: center; }
.sheet .co b { font-size: 15px; }
.sheet h2.t { text-align: center; font-size: 18px; margin: 14px 0 0; }
.sheet .t2 { text-align: center; font-style: italic; margin-bottom: 4px; }
.sheet .no { text-align: center; margin-bottom: 10px; }
.sheet .meta { display: grid; grid-template-columns: 1fr 1fr; gap: 2px 18px; margin-bottom: 8px; }
.sheet table { border: 1px solid #000; margin-top: 6px; }
.sheet th, .sheet td { border: 1px solid #000; padding: 4px 5px; color: #000; font-size: 11.5px; }
.sheet th { text-align: center; background: #efefef; white-space: normal; }
.sheet td.c { text-align: center; }
.sheet td.num { text-align: right; }
.sheet .notes { margin: 8px 0 0; }
.sheet .notes b { display: block; }
.sheet .sign { display: grid; grid-template-columns: 1fr 1fr; text-align: center; margin-top: 22px; min-height: 130px; }
.sheet .sign small { font-style: italic; display: block; }
.toolbar { max-width: 210mm; margin: 0 auto 10px; display: flex; gap: 8px; align-items: center; }
@page { size: A4; margin: 8mm; }
@media print {
  body { background: #fff; }
  .no-print, .topbar { display: none !important; }
  main { padding: 0; max-width: none; }
  .sheet { box-shadow: none; margin: 0; width: auto; min-height: 0; padding: 0; }
}

/* ===== Màn hình lập báo giá ===== */
.big { font-size: 15px; padding: 11px 12px; }
.lg { font-size: 16px; }
.cols { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: 14px; align-items: start; }
@media (max-width: 900px) { .cols { grid-template-columns: 1fr; } }
.side { position: sticky; top: 64px; max-height: calc(100vh - 80px); overflow: auto; }
.banner { background: var(--soft); border: 1px solid var(--brand); border-radius: 8px; padding: 8px 12px; margin-bottom: 12px; }
.banner button { margin-left: 8px; padding: 3px 10px; }
mark { background: #ffe58a; color: inherit; border-radius: 2px; padding: 0 1px; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) mark { background: #6b5a14; } }
.brandtxt { color: var(--brand); }
.custbar { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
.star { color: #d99a00; }
.combo { position: relative; }
.combo-list { position: absolute; left: 0; right: 0; top: 100%; margin-top: 4px; background: var(--card); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 8px 28px rgba(0,0,0,.18); max-height: 420px; overflow: auto; z-index: 8; }
.combo-i { padding: 8px 12px; border-bottom: 1px solid var(--line); cursor: pointer; }
.combo-i.act, .combo-i:hover { background: var(--soft); }
.combo-h { padding: 6px 12px; font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; background: var(--bg); }
.combo-f { padding: 8px 12px; font-size: 12px; color: var(--muted); }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; border-radius: 0; padding: 8px 16px; }
.seg button.on { background: var(--brand); color: var(--brand-ink); font-weight: 600; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin: 4px 0 10px; }
.chip { padding: 4px 11px; border-radius: 99px; font-size: 13px; }
.chip.on { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.chip.used { opacity: .55; }
.hist { background: var(--soft); border-radius: 8px; padding: 10px 12px; margin-bottom: 12px; }
.plist { border: 1px solid var(--line); border-radius: 8px; max-height: 56vh; min-height: 120px; overflow: auto; margin-top: 8px; }
.pr { display: flex; justify-content: space-between; gap: 10px; padding: 8px 12px; border-bottom: 1px solid var(--line); cursor: pointer; }
.pr:last-child { border-bottom: 0; }
.pr:hover, .pr.act { background: var(--soft); }
.pr.added { opacity: .6; }
.pr-r { text-align: right; white-space: nowrap; }
.empty { padding: 28px 8px; text-align: center; color: var(--muted); }
.ln { border: 1px solid var(--line); border-radius: 8px; padding: 10px; margin-bottom: 8px; }
.ln.needs { border-color: var(--warn); }
.ln-h { display: flex; justify-content: space-between; gap: 8px; }
.ln-g { display: grid; grid-template-columns: 1.4fr 1fr; gap: 8px; margin-top: 6px; }
.ln input.num { text-align: right; }
.x { padding: 2px 8px; border: 0; background: transparent; color: var(--muted); height: fit-content; }
.x:hover { color: var(--bad); }
select.inv { border-color: var(--warn); }
.luu { margin-top: 6px; }
.sumbox { border-top: 1px solid var(--line); margin-top: 10px; padding-top: 10px; position: sticky; bottom: -14px; background: var(--card); }
.sumbox ul { margin: 4px 0 0 18px; padding: 0; }

.sheet tr.grp td { background: #f0f0f0; font-weight: 700; text-align: left; letter-spacing: .02em; }

/* ===== Làm báo giá: 3 vùng ===== */
main.wide { max-width: 1760px; }
.qgrid { display: grid; grid-template-columns: minmax(300px, 0.9fr) minmax(0, 1.25fr) minmax(0, 1fr); gap: 14px; align-items: start; }
.qgrid > .card { margin-bottom: 0; }
.qtabs { display: none; gap: 6px; margin-bottom: 10px; }
@media (max-width: 1500px) {
  .qgrid { grid-template-columns: minmax(300px, 0.8fr) minmax(0, 1.2fr); }
  .qgrid[data-tab="items"] .qpv { display: none; }
  .qgrid[data-tab="pv"] .qitems { display: none; }
  .qgrid[data-tab="pv"] .qpv { grid-column: 2; }
  .qtabs { display: flex; }
}
@media (max-width: 900px) { .qgrid { grid-template-columns: 1fr; } .qgrid[data-tab="pv"] .qpv { grid-column: 1; } }
.qcat .plist { max-height: calc(100vh - 360px); }
.qitems, .qpv { position: sticky; top: 64px; max-height: calc(100vh - 80px); overflow: auto; }
.pv-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
#pv { background: #e9ebef; padding: 8px; border-radius: 8px; overflow: hidden; }
#pv .sheet { margin: 0 auto; box-shadow: 0 1px 6px rgba(0,0,0,.2); min-height: 0; }
#pv .empty { background: var(--card); border-radius: 8px; padding: 40px 12px; }
table.items td, table.items th { padding: 6px 6px; }
table.items tr.grp td { background: var(--bg); font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
table.items tr.needs td { background: rgba(180,83,9,.07); }
table.items select { margin-top: 4px; padding: 4px 6px; }
table.items td.pc { min-width: 150px; }
.num-in { width: 112px; text-align: right; }
.num-in.sm { width: 64px; }
.moq-in { width: 72px; }
.luu { display: block; margin-top: 2px; }
.ok-pill { background: var(--soft); color: var(--ok); }
.pill.st.ok { background: var(--soft); color: var(--ok); }
.pill.st.warn { background: transparent; border: 1px solid var(--warn); color: var(--warn); }
.pill.st.bad { background: transparent; border: 1px solid var(--bad); color: var(--bad); }
.pill.st.muted { color: var(--muted); border: 1px solid var(--line); background: transparent; }
.chip.sm { padding: 2px 9px; font-size: 12px; }
.chips.sub { margin-top: -4px; padding-left: 6px; border-left: 3px solid var(--line); }

/* ===== Khách hàng / hồ sơ ===== */
.ophead { display: flex; justify-content: space-between; gap: 14px; align-items: flex-start; }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 14px; overflow-x: auto; }
.tab { border: 0; border-bottom: 3px solid transparent; border-radius: 0; background: transparent; padding: 9px 14px; white-space: nowrap; }
.tab.on { border-bottom-color: var(--brand); color: var(--brand); font-weight: 600; }
.card.narrow { max-width: 720px; }
tr.off td { opacity: .5; }
tr.off td:nth-child(2) b { text-decoration: line-through; }
.switch { border-radius: 99px; padding: 3px 12px; font-size: 12px; border-color: var(--muted); color: var(--muted); }
.switch.on { background: var(--soft); color: var(--ok); border-color: var(--ok); }
.scope { margin-top: 14px; padding: 10px 12px; background: var(--soft); border-radius: 8px; }
label.radio { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--ink); margin: 4px 0; }
label.radio input[type=radio] { width: auto; }
.inl { display: flex; align-items: center; gap: 6px; }
.prog { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; margin-top: 12px; }
.prog-h { display: flex; justify-content: space-between; gap: 10px; margin-bottom: 6px; }
dialog.wide { width: min(860px, 96vw); max-height: 92vh; overflow: auto; }
.pick div { cursor: pointer; }
label.pr { cursor: pointer; }

/* ===== Lịch sử ===== */
.tiles { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.tile { display: flex; flex-direction: column; align-items: flex-start; min-width: 118px; padding: 8px 14px; border-radius: 10px; }
.tile b { font-size: 20px; line-height: 1.1; }
.tile span { font-size: 12px; color: var(--muted); }
.tile.on { border-color: var(--brand); background: var(--soft); }
.alerts h2 { margin-bottom: 6px; }
.alert-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 14px; }
.alert-grid ul { margin: 4px 0 0 18px; padding: 0; }
.qstat { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; max-width: 210mm; margin: 0 auto 10px; padding: 8px 12px; background: var(--card); border: 1px solid var(--line); border-radius: 8px; }
@media print { .qstat { display: none; } }
.chip.on .muted { color: inherit; opacity: .8; }
.zoombar { display: flex; gap: 4px; align-items: center; margin: 6px 0; flex-wrap: wrap; }
.zoombar button { padding: 3px 10px; font-size: 13px; }
#pv { overflow: auto; max-height: calc(100vh - 190px); }
dialog.pvdlg { width: min(900px, 96vw); max-height: 94vh; overflow: auto; background: #e9ebef; }
.pvfull .sheet { margin: 0 auto 8px; }
.savep { padding: 8px 10px; background: var(--soft); border-radius: 8px; margin-bottom: 8px; }

/* ===== Tờ báo giá: đầu trang, bên gửi/nhận, số cột, ghi chú ===== */
.sheet .head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.sheet .imgs { display: flex; gap: 8px; flex: none; }
.sheet .im { width: 62px; height: 62px; display: flex; align-items: center; justify-content: center; border: 1px dashed #bbb; color: #bbb; font: 10px/1 system-ui, sans-serif; }
.sheet .im.logo { width: 110px; }
.sheet .im img { max-width: 100%; max-height: 100%; object-fit: contain; }
.sheet .co { text-align: right; flex: 1; }
.sheet h2.t { margin-top: 10px; }
.sheet .pty { font-weight: 700; text-transform: uppercase; font-size: 10.5px; letter-spacing: .04em; color: #444; border-bottom: 1px solid #999; margin-bottom: 3px; }
.sheet .bn { font-size: 13px; }
.sheet tr.cn th { background: #fff; font-weight: 400; font-style: italic; padding: 1px 4px; font-size: 10px; }
.sheet .notes .nh { font-weight: 700; margin-top: 6px; }
.sheet .notes .ng { padding-left: 14px; text-indent: -10px; padding-left: 24px; }
.sheet .notes b { display: inline; }
.pill.role { background: var(--soft); color: var(--brand); font-size: 11px; }
@media print { .sheet .im { border: 0; } .sheet .im span { visibility: hidden; } }
.roles { display: flex; flex-wrap: wrap; gap: 4px 16px; margin: 2px 0 8px; }
.star-btn { font-size: 17px; color: var(--muted); }
.star-btn.on { color: #d99a00; }
.imgbox { width: 220px; height: 110px; border: 1px dashed var(--line); border-radius: 8px; display: flex; align-items: center; justify-content: center; margin: 4px 0 8px; background: #fff; }
.imgbox img { max-width: 100%; max-height: 100%; object-fit: contain; }
.imgset { margin-bottom: 18px; }
td.nw { white-space: nowrap; }

/* ===== Giao nhận / gửi mẫu / tổng quan ===== */
a.tab { text-decoration: none; color: var(--ink); display: inline-block; }
.plan { padding: 8px 12px; background: var(--soft); border-radius: 8px; color: var(--brand); font-size: 13px; }
.plan.muted { background: transparent; color: var(--muted); }
.qa { display: flex; flex-wrap: wrap; gap: 8px; }
.qa a { text-decoration: none; }
.home-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 14px; align-items: start; }
.home-grid .card { margin-bottom: 0; }
.card.hot { border-color: var(--brand); }
ul.todo { list-style: none; margin: 8px 0 0; padding: 0; }
ul.todo li { padding: 9px 0; border-top: 1px solid var(--line); }
ul.todo li button { margin-top: 6px; padding: 4px 10px; font-size: 13px; }
.env { width: 220mm; max-width: 100%; aspect-ratio: 2 / 1; background: #fff; border: 1px solid var(--line); box-shadow: 0 1px 6px rgba(0,0,0,.12); position: relative; color: #000; }
.env-in { position: absolute; left: 90mm; top: 38mm; max-width: 120mm; font: 14px/1.45 "Times New Roman", serif; }
.env-name { font-weight: 700; font-size: 16px; } .env-ks { font-weight: 700; margin-top: 2px; }
.lbl { background: #fff; color: #000; border: 1px solid var(--line); border-radius: 6px; padding: 8mm; margin: 0 auto 14px; width: 198mm; max-width: 100%; font: 13px/1.4 Arial, sans-serif; }
.lbl-top { display: flex; justify-content: space-between; align-items: baseline; border-bottom: 2px solid #000; padding-bottom: 3px; margin-bottom: 6px; }
.lbl-brand { font-size: 20px; font-weight: 800; letter-spacing: .06em; } .lbl-no { font-size: 24px; }
.lbl-cols { display: grid; grid-template-columns: 1fr 1.4fr; gap: 14px; margin-bottom: 8px; }
.lbl .pty { font-weight: 700; text-transform: uppercase; font-size: 11px; border-bottom: 1px solid #999; margin-bottom: 3px; }
.lbl table { border: 1px solid #000; } .lbl th, .lbl td { border: 1px solid #000; padding: 6px 5px; color: #000; font-size: 12.5px; height: 26px; }
.lbl th { background: #eee; text-align: center; white-space: normal; } .lbl td.c { text-align: center; }
.lbl-f { display: grid; grid-template-columns: 1fr 1fr; gap: 3px 14px; margin-top: 8px; font-size: 13px; }
.sheet.dn .head { margin-bottom: 8px; }
@media print {
  .lbl { border: 0; border-radius: 0; margin: 0; padding: 0; width: auto; page-break-after: always; break-after: page; }
  .lbl:last-of-type { page-break-after: auto; }
  body.print-env main > *:not(.card-env) { }
  body.print-env .card { box-shadow: none; border: 0; padding: 0; }
  body.print-env #e-pick, body.print-env h1, body.print-env .tabs, body.print-env .actions, body.print-env .card:first-of-type, body.print-env h2 { display: none !important; }
  body.print-env .env { border: 0; box-shadow: none; width: 220mm; height: 110mm; }
}

[hidden] { display: none !important; }

/* ===== Soạn hợp đồng ===== */
.ed-grid { display: grid; grid-template-columns: minmax(380px, 1fr) minmax(0, 1.15fr); gap: 14px; align-items: start; }
.ed-grid > .card { margin-bottom: 0; }
@media (max-width: 1000px) { .ed-grid { grid-template-columns: 1fr; } }
.ed-grid h3 { font-size: 14px; margin: 16px 0 6px; }
.terms { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 4px 12px; }
.terms label { font-size: 11px; min-height: 28px; }
.gd { margin-bottom: 6px; } .gd label.radio { align-items: flex-start; } .gd input[type=checkbox] { margin-top: 10px; }
.pvc { position: sticky; top: 64px; max-height: calc(100vh - 80px); overflow: auto; }
.ctprev { background: #fff; color: #000; padding: 14mm 14mm; border: 1px solid var(--line); font: 13px/1.45 "Times New Roman", serif; }
.ctdoc p { margin: 3px 0; text-align: justify; }
.ctdoc .nation, .ctdoc .title { text-align: center; font-weight: 700; margin: 2px 0; }
.ctdoc .head { font-weight: 700; margin-top: 12px; }
.ctdoc .en { font-style: italic; color: #333; }
.ctdoc mark.hole { background: #fff3b0; padding: 0 2px; }
.ctdoc table.sg { width: 100%; margin-top: 18px; text-align: center; border: 0; } .ctdoc table.sg td { border: 0; padding: 2px; }

.ed-grid { grid-template-columns: minmax(360px, 0.8fr) minmax(0, 1.3fr) !important; }
.ctprev { transform-origin: top left; }
.ctdoc mark.hole.cur { background: #ffb347; outline: 2px solid #e07b00; }
.pvc .zoombar { position: sticky; top: 0; background: var(--card); z-index: 2; padding: 6px 0; }

/* Hộp chọn khách trong cửa sổ: danh sách nằm trong luồng, cao tới nửa màn hình */
dialog .combo-list { position: static; max-height: 52vh; margin-top: 6px; box-shadow: none; }
dialog.wide { min-height: 62vh; }
