:root {
  --bg: #f3f5f8; --panel: #ffffff; --ink: #1c1f24; --muted: #667085; --line: #e2e6ec; --line2: #cfd5dd;
  --brand: #1f4e78; --brand2: #2d6aa3; --accent: #c00000; --ok: #1a7f37; --warn: #9a6700; --err: #c62828;
  --warnbg: #fff8e1; --errbg: #fdecea; --okbg: #e8f5e9; --sel: #eaf2fb;
  --radius: 8px; --shadow: 0 1px 3px rgba(16, 24, 40, .08);
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.45 "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--brand2); }
.topbar { position: sticky; top: 0; z-index: 20; background: var(--brand); color: #fff; display: flex; align-items: center; gap: 4px;
  padding: 0 16px; height: 50px; box-shadow: var(--shadow); overflow-x: auto; }
.topbar .logo { font-weight: 800; margin-right: 14px; white-space: nowrap; }
.topbar button { background: transparent; border: 0; color: #dfe9f5; padding: 8px 12px; border-radius: 6px; cursor: pointer; white-space: nowrap; }
.topbar button.on, .topbar button:hover { background: rgba(255,255,255,.15); color: #fff; }
.topbar .sp { flex: 1; }
.wrap { max-width: 1500px; margin: 0 auto; padding: 16px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; margin-bottom: 14px; }
.panel h2 { font-size: 15px; margin: 0 0 10px; display: flex; align-items: center; gap: 8px; }
.grid { display: grid; gap: 10px 14px; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); }
.grid.wide { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
label.f { display: flex; flex-direction: column; gap: 3px; font-size: 12.5px; color: var(--muted); }
label.f > span { font-weight: 600; }
input[type=text], input[type=number], input[type=password], input[type=search], select, textarea {
  border: 1px solid var(--line2); border-radius: 6px; padding: 7px 9px; background: #fff; min-width: 0; width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid #9cc3ea; border-color: var(--brand2); }
textarea { resize: vertical; }
.checks { display: flex; flex-wrap: wrap; gap: 6px 14px; padding-top: 4px; }
.checks label { display: flex; align-items: center; gap: 5px; color: var(--ink); font-size: 13.5px; cursor: pointer; }
.btn { background: var(--brand); color: #fff; border: 0; border-radius: 6px; padding: 8px 14px; cursor: pointer; font-weight: 600; white-space: nowrap; }
.btn:hover { background: var(--brand2); }
.btn.sec { background: #fff; color: var(--brand); border: 1px solid var(--line2); }
.btn.sec:hover { background: var(--sel); }
.btn.red { background: var(--err); }
.btn.sm { padding: 4px 9px; font-size: 12.5px; font-weight: 500; }
.btn:disabled { opacity: .5; cursor: default; }
.sp { flex: 1; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.tbl-wrap { overflow-x: auto; }
table.t { width: 100%; border-collapse: collapse; }
table.t th { background: #f0f3f7; text-align: left; font-size: 12px; color: #475467; padding: 7px 6px; border-bottom: 1px solid var(--line2); white-space: nowrap; position: sticky; top: 0; }
table.t td { border-bottom: 1px solid var(--line); padding: 6px; vertical-align: middle; }
table.t td.n, table.t th.n { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
table.t tr.grp td { background: #f8fafc; font-weight: 700; color: var(--brand); font-size: 12.5px; }
table.t tr.bad td { background: var(--errbg); }
table.t input[type=number] { width: 72px; padding: 5px 6px; text-align: right; }
table.t input.price { width: 112px; }
table.t select { min-width: 260px; max-width: 520px; }
.pick { position: relative; flex: 1; min-width: 260px; max-width: 520px; }
.pick-btn { width: 100%; display: flex; align-items: center; gap: 6px; border: 1px solid var(--line2); border-radius: 6px; padding: 7px 9px;
  background: #fff; cursor: pointer; text-align: left; }
.pick-btn > span:first-child { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pick-btn .caret { color: var(--muted); font-size: 11px; }
.pick-btn:focus { outline: 2px solid #9cc3ea; border-color: var(--brand2); }
.pick-pop { position: fixed; z-index: 40; background: #fff; border: 1px solid var(--line2); border-radius: 8px; box-shadow: 0 8px 24px rgba(16,24,40,.18);
  display: flex; flex-direction: column; padding: 6px; }
.pick-top { display: flex; gap: 6px; margin-bottom: 6px; }
.pick-top input { flex: 1; }
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--brand2); text-decoration: underline; }
.pick-list { overflow-y: auto; flex: 1; position: relative; }
.pick-it { padding: 5px 6px; border-radius: 5px; cursor: pointer; font-size: 13px; }
.pick-row { display: flex; align-items: center; gap: 8px; }
.pick-lb { flex: 1; }
.pick-it .pinfo { margin: 6px 0 4px; cursor: default; }
.pick-it img, .pick-it .noimg { width: 32px; height: 32px; object-fit: contain; flex: none; }
.pick-it.hi { background: var(--sel); }
.pick-it.on { font-weight: 700; }
.pick-empty { padding: 10px; color: var(--muted); }
.ibtn { flex: none; width: 22px; height: 22px; border-radius: 50%; border: 1px solid var(--brand2); background: #fff; color: var(--brand2);
  font: italic 700 13px/1 Georgia, serif; cursor: pointer; padding: 0; }
.ibtn:hover, .ibtn.on { background: var(--brand2); color: #fff; }
a > .thumb { display: block; }
tr.info-row td { background: #f8fafc; }
.pinfo { display: flex; gap: 14px; align-items: flex-start; background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; }
.pinfo img { width: 110px; height: 110px; object-fit: contain; flex: none; }
.pinfo-txt { flex: 1; min-width: 0; }
.pinfo-txt a { margin-left: 8px; }
.pinfo-spec { white-space: pre-line; font-size: 12.5px; color: #344054; margin: 6px 0; max-height: 260px; overflow: auto; }
.qbar { position: sticky; top: 50px; z-index: 15; padding: 8px 16px; background: #fff8e1; border-color: #f5d77a; }
input.otp { font-size: 22px; letter-spacing: 8px; text-align: center; font-variant-numeric: tabular-nums; }
.modebar { display: flex; gap: 8px; margin-bottom: 12px; }
.modebar .mode { flex: 0 1 auto; border: 2px solid var(--line2); background: #fff; color: var(--ink); border-radius: 10px; padding: 9px 18px;
  font-weight: 700; font-size: 15px; cursor: pointer; }
.modebar .mode.on { border-color: var(--brand); background: var(--brand); color: #fff; }
.pills { display: inline-flex; gap: 6px; margin-left: 10px; font-weight: 400; }
.pills .pill { font-size: 12.5px; padding: 3px 10px; }
.int { background: #fffdf2; }
th.int { background: #fff4c7 !important; }
.badge { display: inline-block; padding: 1px 7px; border-radius: 10px; font-size: 11.5px; background: #eef2f6; color: #344054; margin: 1px 2px 1px 0; white-space: nowrap; }
.badge.y { background: #fff59d; color: #5c4b00; }
.badge.b { background: #e3eefb; color: #1f4e78; }
.badge.g { background: var(--okbg); color: var(--ok); }
.badge.r { background: var(--errbg); color: var(--err); }
.msgs { display: flex; flex-direction: column; gap: 6px; }
.msg { border-radius: 6px; padding: 7px 10px; font-size: 13px; }
.msg.err { background: var(--errbg); color: var(--err); }
.msg.warn { background: var(--warnbg); color: var(--warn); }
.msg.ok { background: var(--okbg); color: var(--ok); }
.totals { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px; }
.totals .k { background: #f8fafc; border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; }
.totals .k b { display: block; font-size: 19px; margin-top: 2px; font-variant-numeric: tabular-nums; }
.totals .k.big { background: #fff3cd; border-color: #f5d77a; }
.totals .k.int { background: #fffdf2; }
.login { max-width: 360px; margin: 12vh auto; }
.modal-bg { position: fixed; inset: 0; background: rgba(15, 23, 42, .45); z-index: 50; display: flex; align-items: flex-start; justify-content: center; padding: 6vh 12px; overflow-y: auto; }
.modal { background: #fff; border-radius: 10px; width: min(760px, 100%); padding: 18px; box-shadow: 0 10px 30px rgba(0,0,0,.2); }
.toast { position: fixed; bottom: 18px; right: 18px; background: #1c1f24; color: #fff; padding: 10px 14px; border-radius: 8px; z-index: 60; box-shadow: var(--shadow); max-width: 420px; }
.spec { white-space: pre-line; font-size: 12px; color: #475467; max-height: 120px; overflow: auto; }
.thumb { width: 38px; height: 38px; object-fit: contain; background: #fff; border: 1px solid var(--line); border-radius: 4px; }
.stepnum { background: var(--brand); color: #fff; border-radius: 50%; width: 22px; height: 22px; display: inline-flex; align-items: center; justify-content: center; font-size: 12px; }
.pill { cursor: pointer; border: 1px solid var(--line2); background: #fff; border-radius: 16px; padding: 5px 12px; }
.pill.on { background: var(--brand); color: #fff; border-color: var(--brand); }
.nav { display: contents; }
.menu-btn, .cur-view, .filter-btn { display: none; }

/* ---------------------------------------------------------------- điện thoại */
@media (max-width: 700px) {
  html, body { font-size: 15px; }
  .wrap { padding: 8px; }
  .panel { padding: 12px; margin-bottom: 10px; }
  .panel h2 { flex-wrap: wrap; }
  input[type=text], input[type=number], input[type=password], input[type=search], select, textarea { font-size: 16px; padding: 8px 9px; } /* iPhone không tự phóng to */

  /* thanh trên: tên mục đang xem + nút ☰ mở menu dọc */
  .topbar { padding: 0 6px 0 12px; overflow: visible; gap: 8px; }
  .topbar .logo { margin-right: 0; font-size: 13px; opacity: .8; }
  .cur-view { display: block; flex: 1; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .menu-btn { display: block; font-size: 22px !important; padding: 4px 12px !important; color: #fff !important; }
  .nav { display: none; position: absolute; top: 50px; left: 0; right: 0; background: var(--brand); flex-direction: column;
    padding: 6px; box-shadow: 0 8px 20px rgba(0,0,0,.25); max-height: calc(100vh - 50px); overflow-y: auto; }
  .nav.open { display: flex; }
  .nav button { text-align: left; padding: 12px 14px; font-size: 16px; }
  .nav .sp { display: none; }
  .modebar .mode { flex: 1; padding: 10px 8px; font-size: 14px; }
  .qbar { top: 50px; padding: 6px 10px; font-size: 13px; }
  .qbar .row { flex-wrap: nowrap; }
  .qbar .row > span:first-child { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px 10px; }
  .grid.wide { grid-template-columns: minmax(0, 1fr); }
  .checks { gap: 8px 14px; }
  .checks label { font-size: 15px; }
  .row.end { justify-content: stretch; }
  .row.end > .btn, .row.end > a.btn { flex: 1 1 auto; text-align: center; }
  .totals { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .totals .k { padding: 8px 10px; }
  .totals .k b { font-size: 17px; }
  .toast { left: 12px; right: 12px; bottom: 12px; max-width: none; }

  /* bảng dòng báo giá -> thẻ: thiết bị / SL – CK – Đơn giá – Thành tiền / giá nội bộ / ghi chú */
  table.lines, table.lines tbody { display: block; }
  table.lines thead { display: none; }
  table.lines tr { display: grid; grid-template-columns: 54px 62px minmax(0, 1fr) minmax(0, 1fr); gap: 6px 8px; padding: 10px 0; border-bottom: 1px solid var(--line2); }
  table.lines td[data-l="Niêm yết"] { grid-column: 1 / span 2; }
  table.lines tr.grp { display: block; padding: 10px 0 2px; border: 0; }
  table.lines tr.grp td { background: none; padding: 0; }
  table.lines tr.info-row { display: block; padding: 0 0 10px; }
  table.lines tr.bad { background: var(--errbg); }
  table.lines td { display: block; border: 0; padding: 0; min-width: 0; }
  table.lines td.c-dev { grid-column: 1 / -1; }
  table.lines td.c-note { grid-column: 1 / span 3; }
  table.lines td.c-del { align-self: end; text-align: right; }
  table.lines td.int { background: none; }
  table.lines td[data-l]::before { content: attr(data-l); display: block; font-size: 11.5px; color: var(--muted); text-align: left; }
  table.lines td.n { text-align: left; }
  table.lines input[type=number], table.lines input.price { width: 100%; text-align: left; }
  table.lines td.c-note input { min-width: 0 !important; }
  .pick { min-width: 0; max-width: none; }

  /* tìm sản phẩm: bộ lọc gập lại, kết quả dạng thẻ */
  .filter-btn { display: block; grid-column: 1 / -1; }
  .filters:not(.open) { display: none; }
  table.plist, table.plist tbody { display: block; }
  table.plist thead { display: none; }
  table.plist tr { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 4px 8px; padding: 10px 0; border-bottom: 1px solid var(--line2); }
  table.plist tr.info-row { display: block; padding: 0 0 10px; }
  table.plist td { display: block; border: 0; padding: 0; min-width: 0; }
  table.plist td.c-img { grid-row: span 2; }
  table.plist td.c-img .thumb { width: 64px; height: 64px; }
  table.plist td.c-name, table.plist td.c-attr { grid-column: 2 / -1; }
  table.plist td.c-act { grid-column: 1 / -1; display: flex; gap: 8px; }
  table.plist td.c-act .btn { flex: 1; padding: 9px; }
  table.plist td.int { background: none; }
  table.plist td.n { text-align: left; }
  table.plist td[data-l]::before { content: attr(data-l); display: block; font-size: 11.5px; color: var(--muted); }

  /* bảng danh sách khác -> thẻ "nhãn: giá trị" */
  table.cards, table.cards tbody { display: block; }
  table.cards thead { display: none; }
  table.cards tr { display: block; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; margin-bottom: 8px; }
  table.cards td { display: flex; align-items: center; gap: 8px; border: 0; padding: 3px 0; text-align: left !important; white-space: normal; }
  table.cards td[data-l]::before { content: attr(data-l); flex: 0 0 100px; color: var(--muted); font-size: 12.5px; }
  table.cards td.c-head { display: block; font-size: 15px; padding-bottom: 6px; }
  table.cards td.row { flex-wrap: wrap !important; padding-top: 8px; }

  .pinfo { flex-direction: column; gap: 8px; }
  .pinfo img { width: 90px; height: 90px; }
  .pinfo-txt a { margin-left: 0; display: inline-block; }
  .modal { padding: 14px; }
  .login { margin: 6vh 12px; }
}
@media print { .topbar, .noprint { display: none !important; } }
