/* ================================================================
   Tính giá Inox — thành phần dùng chung + từng trang.
   Khung ứng dụng (đăng nhập, sidebar, tiêu đề trang): shell.css
   ================================================================ */
:root {
  --bg: #f3f5f6;
  --panel: #ffffff;
  --panel-2: #f6f8f9;
  --hover: #f0f4f5;
  --ink: #17252b;
  --ink-2: #4e5f66;
  --ink-3: #7d8c92;
  --line: #e1e6e8;
  --line-2: #cfd7da;
  --brand: #17323a;
  --brand-2: #24505d;
  --primary: #e8710a;          /* cam: nút chính, mục đang chọn, viền focus */
  --primary-hover: #cf6309;
  --primary-ink: #ffffff;
  --primary-soft: #fff1e3;
  --accent: var(--primary);
  --accent-ink: var(--primary-ink);
  --accent-soft: var(--primary-soft);
  --link: #0f7c99;
  --ok: #1e8a4c;
  --ok-soft: rgba(30, 138, 76, .12);
  --danger: #c0392b;
  --danger-soft: rgba(192, 57, 43, .1);
  --warn: #b35a00;
  --warn-soft: #fff3e3;
  --hl: #ff8a1f;
  --sheet: #8fa3ab;
  --profile: #0f7c99;
  --viewer-top: #fbfcfc;
  --viewer-bottom: #e4e9eb;
  --radius: 8px;
  --radius-lg: 10px;
  --shadow: 0 1px 2px rgba(16, 36, 44, .05);
  --shadow-lg: 0 12px 40px rgba(10, 25, 30, .22);
  --header-h: 64px;
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 20px; --s6: 24px; --s8: 32px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1619; --panel: #172125; --panel-2: #1d292e; --hover: #1f2d32; --ink: #e6edf0; --ink-2: #a9b8be; --ink-3: #7c8d94;
    --line: #2a383e; --line-2: #36474e; --primary-soft: #3a2614; --link: #3cb4d4;
    --warn: #ffb35c; --warn-soft: #3a2a14; --sheet: #7b8f97; --profile: #3cb4d4; --viewer-top: #2a3439; --viewer-bottom: #1a2327;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.5 "Be Vietnam Pro", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--link); }
h2 { font-size: 16px; font-weight: 600; margin: 0 0 var(--s1); }
h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-3); margin: 20px 0 8px; font-weight: 600; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--ink-2); margin: 0 0 var(--s4); }
.muted-text { color: var(--ink-3); }
.pre { white-space: pre-line; }
.error { color: var(--danger); margin: 0 0 var(--s3); }
.spacer { flex: 1; }
.code { font-variant-numeric: tabular-nums; font-size: 13px; }

/* ---------------------------------------------------------------- nút */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 36px; padding: 0 14px; border-radius: var(--radius); border: 1px solid transparent;
  font-weight: 600; font-size: 14px; cursor: pointer; white-space: nowrap; text-decoration: none;
  transition: background .12s, border-color .12s, color .12s;
}
.btn:disabled { opacity: .5; cursor: default; }
.btn-primary { background: var(--primary); color: var(--primary-ink); }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-ghost { background: var(--panel); border-color: var(--line-2); color: var(--ink); }
.btn-ghost:hover:not(:disabled) { background: var(--hover); border-color: var(--ink-3); }
.btn-danger { color: var(--danger); }
.btn-danger:hover:not(:disabled) { background: var(--danger-soft); border-color: var(--danger); color: var(--danger); }
.btn-sm { height: 30px; padding: 0 10px; font-size: 13px; }
.btn-block { width: 100%; height: 42px; }
.btn-current { background: var(--brand); color: #fff; }
.link-btn { border: 0; background: none; padding: 0; color: var(--link); cursor: pointer; text-decoration: underline; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center; flex: none;
  border: 0; background: transparent; color: var(--ink-2); width: 32px; height: 32px; border-radius: var(--radius); cursor: pointer; font-size: 15px;
}
.icon-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn:hover:not(:disabled) { background: var(--hover); color: var(--ink); }
.icon-btn:disabled { opacity: .3; cursor: default; }
.icon-btn.danger:hover:not(:disabled) { background: var(--danger-soft); color: var(--danger); }
.ghost-btn { width: 100%; border: 1px dashed var(--line-2); background: transparent; color: var(--ink-2); padding: 9px; border-radius: var(--radius); cursor: pointer; }
.ghost-btn:hover { color: var(--primary); border-color: var(--primary); }

/* ---------------------------------------------------------------- ô nhập */
.field { display: grid; gap: 4px; margin-bottom: var(--s3); min-width: 0; }
.label { display: block; font-size: 13px; color: var(--ink-2); font-weight: 500; }
.hint { font-size: 12px; color: var(--ink-3); margin: 2px 0 0; }
.text-input, select {
  width: 100%; height: 40px; padding: 0 12px; border: 1px solid var(--line-2); border-radius: var(--radius); background: var(--panel);
  transition: border-color .12s, box-shadow .12s;
}
select { padding: 0 32px 0 10px; cursor: pointer; }
textarea.text-input { height: auto; padding: 8px 12px; resize: vertical; line-height: 1.45; }
.text-input:hover, select:hover { border-color: var(--ink-3); }
.text-input:focus, select:focus, .num-input:focus-within, .unit-input:focus-within, .search-box:focus-within {
  outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 22%, transparent);
}
.text-input:disabled, select:disabled, .unit-input input:disabled, .matrix input:disabled { background: var(--panel-2); color: var(--ink-2); cursor: not-allowed; }
.form-error { color: var(--danger); background: var(--danger-soft); border-radius: var(--radius); padding: 8px 12px; margin: var(--s2) 0 var(--s3); font-weight: 500; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 var(--s4); }
.form-grid .wide { grid-column: 1 / -1; }

.switch { position: relative; display: flex; align-items: center; gap: 10px; cursor: pointer; padding: 4px 0; }
.switch input { position: absolute; left: 0; top: 0; opacity: 0; width: 1px; height: 1px; }
.switch-track { flex: none; width: 38px; height: 22px; border-radius: 11px; background: var(--line-2); position: relative; transition: background .15s; }
.switch-track::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform .15s;
}
.switch input:checked + .switch-track { background: var(--primary); }
.switch input:checked + .switch-track::after { transform: translateX(16px); }
.switch input:focus-visible + .switch-track { outline: 2px solid var(--primary); outline-offset: 2px; }
.switch input:disabled + .switch-track { opacity: .5; }
.switch-label { font-weight: 500; font-size: 14px; }
.switch-label small { display: block; font-weight: 400; font-size: 12px; color: var(--ink-3); }

.search-box {
  display: flex; align-items: center; gap: 8px; height: 40px; padding: 0 12px; flex: 1 1 260px; min-width: 0;
  border: 1px solid var(--line-2); border-radius: var(--radius); background: var(--panel); cursor: text;
}
.search-box svg { width: 18px; height: 18px; flex: none; fill: none; stroke: var(--ink-3); stroke-width: 2; stroke-linecap: round; }
.search-box input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; height: 100%; }

/* ---------------------------------------------------------------- thẻ, bảng, huy hiệu */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: var(--s5); }
.card + .card { margin-top: var(--s4); }
.card > p { color: var(--ink-2); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 4px; }
.card-head h2 { margin: 0; }
.empty-state { text-align: center; padding: 48px 24px; }
.toolbar { display: flex; flex-wrap: wrap; gap: var(--s2); align-items: center; }
.toolbar select { width: auto; flex: 0 1 230px; min-width: 0; }
.table-summary { font-size: 13px; color: var(--ink-2); margin: var(--s3) 0 var(--s2); }

table { width: 100%; border-collapse: collapse; }
td, th { padding: 7px 6px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { font-size: 12px; color: var(--ink-3); font-weight: 600; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.data-table { font-size: 14px; }
.data-table th {
  background: var(--panel-2); color: var(--ink-2); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .03em;
  padding: 9px 10px; border-bottom: 1px solid var(--line); white-space: nowrap;
}
.data-table td { padding: 10px; vertical-align: middle; }
.data-table tbody tr:hover > td { background: var(--hover); }
.data-table small { display: block; color: var(--ink-3); font-size: 12px; }
.data-table .c-actions { text-align: right; white-space: nowrap; width: 1%; }
.empty-cell { text-align: center !important; color: var(--ink-2); padding: 36px 12px !important; }
.row-muted td { color: var(--ink-3); }

.badge {
  display: inline-flex; align-items: center; height: 22px; padding: 0 8px; border-radius: 999px; font-size: 12px; font-weight: 600;
  background: var(--panel-2); color: var(--ink-2); white-space: nowrap; vertical-align: middle;
}
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-order { background: rgba(15, 124, 153, .12); color: var(--link); }
.badge-out { background: var(--warn-soft); color: var(--warn); }
.badge-stop { background: var(--danger-soft); color: var(--danger); }
.badge-manual { background: rgba(110, 72, 170, .12); color: #6e48aa; }
.badge-muted { background: var(--panel-2); color: var(--ink-3); }
.badge-role-admin { background: rgba(232, 113, 10, .14); color: #b55406; }
.badge-role-quan_ly { background: rgba(15, 124, 153, .12); color: var(--link); }
.badge-role-nhan_vien { background: var(--panel-2); color: var(--ink-2); }

.spec-list { margin: var(--s3) 0 0; display: grid; gap: 6px; font-size: 14px; }
.spec-list div { display: flex; gap: 12px; }
.spec-list dt { color: var(--ink-3); min-width: 140px; flex: none; }
.spec-list dd { margin: 0; font-weight: 500; min-width: 0; overflow-wrap: anywhere; }

.result-note { margin: 12px 0 0; padding: 9px 12px; border-radius: var(--radius); background: var(--panel-2); color: var(--ink-2); font-size: 13px; }
.result-warn { margin: 12px 0 0; padding: 9px 12px; border-radius: var(--radius); background: var(--warn-soft); color: var(--warn); font-size: 13px; font-weight: 500; }
.note { font-size: 12px; color: var(--ink-3); margin: 10px 0 0; }

/* ---------------------------------------------------------------- hộp thoại (modal) + ngăn bên phải (drawer) */
dialog { color: var(--ink); }
dialog::backdrop { background: rgba(10, 20, 25, .45); }
.modal, .cat-dialog {
  border: 0; padding: 0; border-radius: var(--radius-lg); width: min(640px, calc(100vw - 24px)); max-height: calc(100dvh - 24px);
  background: var(--panel); box-shadow: var(--shadow-lg);
}
.pf-dialog { width: min(760px, calc(100vw - 24px)); }
.modal-form, .cat-detail { display: flex; flex-direction: column; max-height: calc(100dvh - 24px); }
.modal-head, .modal-foot, .cat-detail header, .cat-detail footer {
  display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 14px 20px; border-bottom: 1px solid var(--line);
}
.modal-foot, .cat-detail footer { border-bottom: 0; border-top: 1px solid var(--line); justify-content: flex-end; }
.modal-head h2, .cat-detail h2 { margin: 0; font-size: 17px; }
.modal-body, .pf-body { overflow-y: auto; padding: 16px 20px; }
.pf-intro { margin: 0 0 12px; font-size: 13px; }
.pf-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 14px; }
.pf-field { display: grid; gap: 4px; min-width: 0; }
.pf-field.wide { grid-column: 1 / -1; }
.pf-dims { display: flex; align-items: center; gap: 6px; }
.pf-dims span { color: var(--ink-3); }
.pf-error { color: var(--danger); font-size: 14px; margin: 12px 0 0; font-weight: 500; }

.drawer {
  border: 0; padding: 0; margin: 0 0 0 auto; height: 100dvh; max-height: 100dvh; width: min(520px, 100vw); max-width: 100vw;
  background: var(--panel); box-shadow: var(--shadow-lg);
}
.drawer[open] { animation: drawer-in .18s ease-out; }
@keyframes drawer-in { from { transform: translateX(40px); opacity: .4; } }
.drawer-inner { display: flex; flex-direction: column; height: 100%; }
.drawer-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.drawer-head h2 { font-size: 18px; margin: 0 0 2px; line-height: 1.35; }
.drawer-head p { margin: 0; font-size: 13px; }
.drawer-body { flex: 1; overflow-y: auto; padding: 16px 20px 24px; }
.drawer-body h3 { margin-top: 18px; }
.drawer-body .pre { margin: 0; }
.drawer-img { aspect-ratio: 4 / 3; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; margin-bottom: var(--s4); }
.drawer-img img { width: 100%; height: 100%; object-fit: contain; display: block; }
.drawer-price { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin: 4px 0 4px; }
.drawer-price b { font-size: 22px; font-variant-numeric: tabular-nums; }
.drawer-price span { color: var(--ink-3); }
.drawer-foot { display: flex; gap: 8px; align-items: center; padding: 14px 20px calc(14px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); }
.ext-link { font-weight: 500; }
.noimg {
  display: flex; align-items: center; justify-content: center; width: 100%; height: 100%; color: var(--ink-3); font-size: 13px;
  background: repeating-linear-gradient(45deg, var(--panel-2), var(--panel-2) 6px, var(--bg) 6px, var(--bg) 12px);
}

/* ================================================================ Danh sách sản phẩm */
.products-card { padding: var(--s4) var(--s4) var(--s2); overflow: clip; }
.products-table { table-layout: auto; }
.products-table thead th { position: sticky; top: var(--header-h); z-index: 2; }
.products-table td { padding: 8px 10px; }
.products-table tbody tr { cursor: pointer; }
.sort-btn { border: 0; background: none; padding: 0; font: inherit; color: inherit; text-transform: inherit; letter-spacing: inherit; cursor: pointer; display: inline-flex; align-items: center; gap: 4px; }
.sort-btn i { width: 0; height: 0; border: 4px solid transparent; border-top-color: var(--line-2); margin-top: 4px; }
.sort-btn:hover { color: var(--ink); }
.sort-btn.active { color: var(--primary); }
.sort-btn.active[data-dir="asc"] i { border-top-color: transparent; border-bottom-color: var(--primary); margin: 0 0 4px; }
.sort-btn.active[data-dir="desc"] i { border-top-color: var(--primary); }
.c-price .sort-btn { flex-direction: row-reverse; }
.c-thumb { width: 56px; padding-right: 0 !important; }
.thumb, .c-thumb .noimg { width: 40px; height: 40px; border-radius: 6px; object-fit: contain; background: #fff; border: 1px solid var(--line); display: block; }
.c-code { white-space: nowrap; }
.c-code small { font-size: 11px; }
.c-name { min-width: 220px; }
.c-name .name-wrap { display: block; }
.row-parent .c-name .name-wrap { display: inline-block; vertical-align: middle; max-width: calc(100% - 30px); }
.p-name { font-weight: 600; display: block; line-height: 1.35; }
.p-sub { color: var(--ink-3); font-size: 12px; margin-top: 2px; display: block; }
.m-only { display: none; }
.c-cat { color: var(--ink-2); font-size: 13px; }
.c-unit { color: var(--ink-2); white-space: nowrap; }
.c-price { white-space: nowrap; }
.price-to { display: block; font-weight: 500; color: var(--ink-3); font-size: 12px; }
.c-source { color: var(--ink-2); font-size: 13px; }
.c-m3d { white-space: nowrap; }
.c-m3d .badge { cursor: help; }
.caret {
  display: inline-flex; vertical-align: middle; align-items: center; justify-content: center; width: 24px; height: 24px; margin: 0 4px 0 -4px;
  border: 0; border-radius: 6px; background: transparent; color: var(--ink-2); cursor: pointer; padding: 0;
}
.caret svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; transition: transform .15s; }
.caret:hover { background: var(--line); }
.row-parent.open .caret svg { transform: rotate(90deg); }
.row-parent.open > td { background: var(--panel-2); }
.row-variant > td { background: color-mix(in srgb, var(--panel-2) 50%, var(--panel)); }
.row-variant .c-name .name-wrap { padding-left: 24px; position: relative; }
.row-variant .c-name .name-wrap::before { content: ""; position: absolute; left: 6px; top: 2px; width: 10px; height: 10px; border-left: 1.5px solid var(--line-2); border-bottom: 1.5px solid var(--line-2); border-bottom-left-radius: 4px; }
.row-variant .p-name { font-weight: 500; }
.add-btn { color: var(--primary); }
.add-btn:hover:not(:disabled) { background: var(--primary-soft) !important; color: var(--primary-hover) !important; }
.pager { display: flex; gap: 6px; justify-content: center; align-items: center; flex-wrap: wrap; padding: var(--s3) 0 var(--s2); }
.pager-gap { color: var(--ink-3); padding: 0 2px; }

@container content (max-width: 820px) {
  .products-table .c-source, .products-table .c-unit { display: none; }
}
@container content (max-width: 640px) {
  .products-card { padding: var(--s3) var(--s3) var(--s2); }
  .products-table .c-code, .products-table .c-cat, .products-table .c-status, .products-table .c-m3d { display: none; }
  .products-table { table-layout: fixed; }
  .products-table th.c-thumb { width: 48px; }
  .products-table th.c-price { width: 104px; }
  .products-table th.c-actions { width: 40px; }
  .products-table .c-name { min-width: 0; overflow-wrap: anywhere; }
  .products-table .c-price { white-space: normal; }
  .products-table .c-price b { font-size: 13px; }
  .row-parent .c-name .name-wrap { max-width: calc(100% - 26px); }
  .caret { margin-right: 2px; }
  .products-table td { padding: 8px 6px; }
  .products-table .c-actions [data-edit], .products-table .c-actions [data-delete] { display: none; }
  .m-only { display: inline; }
  .toolbar select { flex: 1 1 calc(50% - 4px); }
  .search-box { flex-basis: 100%; }
  .row-variant .c-name .name-wrap { padding-left: 16px; }
}

/* ================================================================ Tính giá sản phẩm */
.calc-chips { display: none; gap: 6px; overflow-x: auto; scrollbar-width: none; margin: 0 0 var(--s3); padding-bottom: 2px; }
.calc-chips::-webkit-scrollbar { display: none; }
.calc-chips a {
  flex: none; padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line-2); background: var(--panel); color: var(--ink-2);
  text-decoration: none; font-weight: 500; font-size: 13px; white-space: nowrap;
}
.calc-chips a.active { background: var(--brand); border-color: var(--brand); color: #fff; }
.workspace {
  display: grid;
  grid-template-columns: 290px minmax(0, 1fr) 360px;
  gap: var(--s4);
  height: calc(100dvh - var(--header-h) - 40px);
  min-height: 520px;
}
.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: var(--s4); overflow-y: auto; min-height: 0; position: relative;
}
fieldset { border: 0; margin: 0 0 18px; padding: 0; min-width: 0; }
legend { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-3); font-weight: 600; margin-bottom: 10px; padding: 0; }
.workspace .field { display: block; margin-bottom: 12px; }
.workspace .label { margin-bottom: 5px; }
.workspace select { background: var(--panel-2); }
.num-input { display: flex; align-items: center; width: 100%; height: 40px; overflow: hidden; border: 1px solid var(--line-2); border-radius: var(--radius); background: var(--panel-2); }
.num-input input { flex: 1; min-width: 0; border: 0; background: transparent; height: 100%; text-align: center; font-weight: 600; font-size: 15px; outline: none; }
.num-input .unit { color: var(--ink-3); font-size: 13px; padding-right: 6px; }
.step { width: 38px; height: 100%; border: 0; background: transparent; cursor: pointer; font-size: 18px; color: var(--ink-2); flex: none; }
.step:hover { background: var(--primary-soft); color: var(--primary); }
.field-warn { font-size: 12px; color: var(--warn); margin: 5px 0 0; }
.info-value { display: flex; align-items: center; justify-content: center; height: 40px; border: 1px dashed var(--line-2); border-radius: var(--radius); color: var(--ink-2); font-weight: 600; font-size: 15px; }
.seg { display: flex; background: var(--panel-2); border: 1px solid var(--line-2); border-radius: var(--radius); padding: 3px; gap: 2px; }
.seg label, .seg button { flex: 1; position: relative; }
.seg input { position: absolute; opacity: 0; inset: 0; cursor: pointer; margin: 0; }
.seg span, .seg button {
  display: block; text-align: center; padding: 6px 4px; border-radius: 6px; border: 0; background: transparent;
  font-weight: 600; font-size: 14px; color: var(--ink-2); cursor: pointer; white-space: nowrap;
}
.seg input:checked + span, .seg button.active { background: var(--brand); color: #fff; }
.seg input:focus-visible + span { outline: 2px solid var(--primary); outline-offset: 1px; }
.seg-small span, .seg-small button { padding: 5px 10px; font-size: 13px; }

.viewer-panel {
  position: relative; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--line); box-shadow: var(--shadow);
  background: linear-gradient(180deg, var(--viewer-top), var(--viewer-bottom)); min-height: 0;
}
.viewer { position: absolute; inset: 0; touch-action: none; }
.viewer canvas { display: block; width: 100%; height: 100%; }
.viewer-labels { position: absolute; inset: 0; pointer-events: none; }
.dim-label { font-size: 12px; font-weight: 600; color: #0f6e8c; background: rgba(255,255,255,.88); padding: 2px 7px; border-radius: 6px; white-space: nowrap; box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.viewer-toolbar { position: absolute; left: 12px; right: 12px; bottom: 12px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.viewer-toolbar .seg { background: var(--panel); box-shadow: var(--shadow); }
.toggle {
  display: inline-flex; align-items: center; gap: 6px; padding: 6px 11px; border-radius: var(--radius); border: 1px solid var(--line);
  background: var(--panel); font-size: 13px; font-weight: 500; cursor: pointer; color: var(--ink-2);
}
.toggle input { accent-color: var(--primary); margin: 0; }
.product-toggles { display: contents; }
.viewer-title { position: absolute; top: 10px; left: 14px; right: 14px; font-weight: 700; font-size: 16px; pointer-events: none; }
.viewer-hint { position: absolute; top: 34px; left: 14px; right: 14px; margin: 0; font-size: 12px; color: var(--ink-3); pointer-events: none; }
.viewer-error { padding: 40px 24px; text-align: center; color: var(--ink-2); }
.t-short { display: none; }

.total { background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: #fff; border-radius: var(--radius); padding: 16px; display: grid; gap: 2px; }
.total-label { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; opacity: .75; }
.total-value { font-size: 28px; font-weight: 700; letter-spacing: -.01em; font-variant-numeric: tabular-nums; }
.total-sub { font-size: 13px; opacity: .8; }
.total-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.copy-btn { border: 1px solid rgba(255,255,255,.35); background: rgba(255,255,255,.1); color: #fff; border-radius: var(--radius); padding: 6px 12px; cursor: pointer; font-size: 13px; font-weight: 500; }
.copy-btn:hover { background: rgba(255,255,255,.2); }
.add-quote-btn { background: var(--primary); border-color: var(--primary); font-weight: 600; }
.add-quote-btn:hover { background: var(--primary-hover); }
.result-panel table { font-size: 14px; }
.cost-table small { display: block; color: var(--ink-3); font-size: 12px; }
.cost-table .sum td { font-weight: 700; border-bottom: 0; font-size: 15px; }
.parts-table { font-size: 13px !important; }
.inox-cell { white-space: nowrap; }
.inox-cell b { font-weight: 600; }
.inox-cell small { display: block; color: var(--ink-3); font-size: 11px; }
.part-group .group-head th { padding: 14px 6px 6px; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--link); border-bottom: 2px solid var(--line); font-weight: 700; text-align: left; }
.part-group .group-head th.num { text-align: right; color: var(--ink-2); }
tr.hoverable { cursor: pointer; }
tr.hoverable:hover td, tr.hoverable:hover th { background: var(--hover); }
tr.pinned td { background: color-mix(in srgb, var(--hl) 16%, transparent); }
tr.pinned td:first-child { box-shadow: inset 3px 0 0 var(--hl); }
.weight-bar { display: flex; height: 10px; border-radius: 6px; overflow: hidden; background: var(--panel-2); }
.w-sheet { background: var(--sheet); }
.w-profile { background: var(--profile); }
.weights { margin: 10px 0 0; display: grid; gap: 4px; font-size: 14px; }
.weights div { display: flex; justify-content: space-between; gap: 10px; }
.weights dt { color: var(--ink-2); display: flex; align-items: center; gap: 6px; }
.weights dd { margin: 0; font-weight: 600; font-variant-numeric: tabular-nums; }
.weights small { color: var(--ink-3); font-weight: 500; margin-left: 4px; }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.dot-sheet { background: var(--sheet); }
.dot-profile { background: var(--profile); }
.total-bar { display: none; }

/* Hai cột: thông số | 3D + kết quả */
@container content (max-width: 1080px) {
  .workspace { grid-template-columns: 280px minmax(0, 1fr); grid-template-areas: "form viewer" "form results"; grid-template-rows: 58vh auto; height: auto; }
  .form-panel { grid-area: form; align-self: start; position: sticky; top: calc(var(--header-h) + 16px); max-height: calc(100dvh - var(--header-h) - 32px); }
  .viewer-panel { grid-area: viewer; }
  .result-panel { grid-area: results; overflow: visible; }
}
/* Một cột (điện thoại) */
@container content (max-width: 680px) {
  .calc-chips { display: flex; }
  .workspace { grid-template-columns: minmax(0, 1fr); grid-template-areas: "viewer" "form" "results"; grid-template-rows: 46vh auto auto; gap: 10px; min-height: 0; }
  .form-panel { position: static; max-height: none; }
  .viewer-hint { display: none; }
  .viewer-title { font-size: 14px; }
  .viewer-toolbar { left: 8px; right: 8px; bottom: 8px; gap: 6px; flex-wrap: nowrap; overflow-x: auto; }
  .toggle { padding: 5px 8px; font-size: 12px; gap: 5px; white-space: nowrap; }
  .t-long { display: none; }
  .t-short { display: inline; }
  .seg-small span, .seg-small button { padding: 5px 7px; font-size: 12px; }
  .total-value { font-size: 24px; }
  .total-bar {
    display: flex; justify-content: space-between; align-items: center; gap: 10px;
    position: sticky; bottom: 0; z-index: 15; margin: 10px -12px 0;
    padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
    background: var(--brand); color: #fff; font-size: 13px; box-shadow: 0 -4px 16px rgba(0,0,0,.15);
  }
  .total-bar span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; opacity: .85; }
  .total-bar b { font-size: 18px; white-space: nowrap; }
  .parts-table th:nth-child(2), .parts-table td:nth-child(2) { display: none; }
}

/* ================================================================ Báo giá */
.quote-layout { display: grid; grid-template-columns: 300px minmax(0, 1fr); gap: var(--s4); align-items: start; }
.quote-layout .card + .card { margin-top: 0; }
.q-customer h3:first-child, .q-items h3:first-child { margin-top: 0; }
.q-field { display: block; margin-bottom: 10px; }
.q-field .label { margin-bottom: 4px; }
.q-staff { margin: 0; display: grid; }
.q-staff small { color: var(--ink-3); font-size: 12px; }
.q-table th { white-space: nowrap; }
.q-table td { vertical-align: top; }
.q-name small { display: block; color: var(--ink-3); font-size: 12px; margin-top: 2px; }
.q-img { width: 108px; }
.q-table th.q-img, .q-table td.q-img { padding-left: 6px; padding-right: 6px; }
.q-items .q-img { width: 100px; }
.q-thumb { display: block; width: 96px; height: 72px; padding: 0; border: 1px solid var(--line); border-radius: 6px; background: #fff; overflow: hidden; cursor: zoom-in; }
.q-items .q-thumb { width: 88px; height: 66px; } /* trình soạn: bảng chật hơn */
.q-thumb img, .q-thumb .noimg { display: block; width: 100%; height: 100%; object-fit: contain; }
.q-thumb img.loading, .q-thumb img:not([src]) { background: linear-gradient(90deg, var(--panel-2), var(--bg), var(--panel-2)); background-size: 200% 100%; animation: q-shimmer 1.2s linear infinite; }
.q-thumb-empty { display: flex; align-items: center; justify-content: center; text-align: center; cursor: default; font-size: 11px; color: var(--ink-3);
  background: repeating-linear-gradient(45deg, var(--panel-2), var(--panel-2) 6px, var(--bg) 6px, var(--bg) 12px); }
.q-img-tools { display: flex; flex-wrap: wrap; gap: 2px 10px; margin-top: 4px; font-size: 12px; }
.q-img-del { color: var(--danger); }
.q-img-busy { display: inline-flex; align-items: center; color: var(--ink-3); }
.btn-spinner { display: inline-block; width: 12px; height: 12px; margin-right: 6px; vertical-align: -2px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: q-spin .8s linear infinite; }
@keyframes q-spin { to { transform: rotate(360deg); } }
@keyframes q-shimmer { to { background-position: -200% 0; } }
.q-lightbox { border: 0; padding: 0; background: transparent; max-width: 96vw; max-height: 96vh; overflow: visible; }
.q-lightbox::backdrop { background: rgba(10, 22, 28, .78); }
.q-lightbox figure { margin: 0; padding: 10px; background: #fff; border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); cursor: zoom-out; }
.q-lightbox img { display: block; max-width: min(92vw, 1000px); max-height: 82vh; object-fit: contain; }
.q-lightbox figcaption, .q-lightbox-msg { margin: 8px 0 0; font-size: 13px; color: var(--ink-2); text-align: center; }
.q-lightbox-msg { padding: 40px 60px; }
.q-lightbox-close { position: absolute; top: -12px; right: -12px; background: var(--panel); border-radius: 50%; box-shadow: var(--shadow-lg); }
.q-stt { color: var(--ink-3); }
.q-num { min-width: 0; height: 34px; border: 1px solid var(--line-2); border-radius: 6px; background: var(--panel); text-align: right; padding: 0 8px; font-variant-numeric: tabular-nums; }
.q-num:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 22%, transparent); }
.q-qty { width: 56px; }
.q-price { width: 108px; }
.q-num.invalid, .q-missing .q-price { border-color: var(--warn); background: var(--warn-soft); }
.q-ref { display: block; font-size: 11px; color: var(--ink-3); margin-top: 2px; white-space: nowrap; }
.q-tools { white-space: nowrap; text-align: right; }
.q-tools .icon-btn { width: 28px; height: 28px; }
.q-empty { padding: 24px; text-align: center; color: var(--ink-2); border: 1px dashed var(--line-2); border-radius: var(--radius); }
.q-empty .btn { margin: 4px; }
.q-add-row { margin-top: 10px; }
.q-summary { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 16px; margin-top: 14px; }
.q-adjust { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
.q-adjust .q-field { margin: 0; }
.q-adjust .text-input { width: 120px; }
.q-inline { display: flex; gap: 6px; }
.q-inline select { width: 64px; padding-right: 8px; }
.q-totals { margin: 0; min-width: 280px; display: grid; gap: 4px; font-size: 14px; }
.q-totals div { display: flex; justify-content: space-between; gap: 16px; }
.q-totals dt { color: var(--ink-2); }
.q-totals dd { margin: 0; font-weight: 600; font-variant-numeric: tabular-nums; text-align: right; }
.q-grand { border-top: 2px solid var(--line); padding-top: 6px; margin-top: 4px; font-size: 18px; }
.q-grand dt { color: var(--ink); font-weight: 700; }
.q-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 16px; }
.q-msg { margin: 0 0 12px; padding: 10px 14px; border-radius: var(--radius); font-weight: 500; }
.q-msg.ok { background: var(--ok-soft); color: var(--ok); }
.q-msg.err { background: var(--danger-soft); color: var(--danger); }
.q-history tbody tr { cursor: pointer; }
.q-list { margin-top: var(--s2); }
.q-saved-head { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; align-items: flex-start; margin-bottom: 8px; }
.q-saved-head h2 { margin: 0 0 4px; font-size: 20px; }
.q-saved-head .q-actions { margin-top: 0; }
.q-saved-head .muted { margin: 0; }
.q-saved .q-totals { margin: 14px 0 0 auto; max-width: 360px; }
.cat-dl { margin: 10px 0 14px; display: grid; gap: 4px; font-size: 14px; }
.cat-dl div { display: flex; gap: 10px; }
.cat-dl dt { color: var(--ink-3); min-width: 120px; flex: none; }
.cat-dl dd { margin: 0; font-weight: 500; min-width: 0; overflow-wrap: anywhere; }

@container content (max-width: 760px) {
  .quote-layout { grid-template-columns: minmax(0, 1fr); }
  .q-summary { flex-direction: column; }
  .q-totals { min-width: 0; }
  .q-actions .btn { flex: 1 1 auto; }
  .q-actions .spacer { display: none; }
  /* Bảng báo giá / lịch sử thành dạng thẻ */
  .q-table thead, .q-history thead { display: none; }
  .q-table, .q-table tbody, .q-history, .q-history tbody { display: block; }
  .q-table tr, .q-history tr { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
  .q-table td, .q-history td { border: 0; padding: 0; }
  .q-table td[data-label]::before, .q-history td[data-label]::before { content: attr(data-label); display: block; font-size: 11px; color: var(--ink-3); }
  .q-table .q-name { grid-column: 1 / -1; order: -1; }
  .q-table .q-stt, .q-table .q-unit { display: none; }
  .q-table .num, .q-history .num { text-align: left; }
  .q-table .q-tools { grid-column: 1 / -1; }
  .q-qty, .q-price { width: 100%; }
  .q-table .q-img { display: none; }
  /* có ảnh (và mọi dòng trong trình soạn): ảnh nhỏ bên trái tên + số lượng / giá */
  .q-table tr.q-with-img { grid-template-columns: 88px minmax(0, 1fr) minmax(0, 1fr); }
  .q-table tr.q-with-img .q-img { display: block; grid-column: 1; grid-row: 1 / span 3; width: auto; }
  .q-table tr.q-with-img .q-img::before { display: none; }
  .q-table tr.q-with-img .q-name { grid-column: 2 / -1; grid-row: 1; }
  .q-table .q-thumb { width: 84px; height: 63px; }
  .q-table .q-img-tools { flex-direction: column; align-items: flex-start; }
  .data-table tbody tr:hover > td { background: none; }
}

/* ================================================================ Cài đặt chung */
.sheet-tabs { display: flex; gap: 4px; overflow-x: auto; margin-bottom: var(--s4); scrollbar-width: none; border-bottom: 1px solid var(--line); }
.sheet-tabs::-webkit-scrollbar { display: none; }
.sheet-tabs button {
  border: 0; border-bottom: 2px solid transparent; background: none; padding: 10px 14px; margin-bottom: -1px; cursor: pointer;
  white-space: nowrap; font-weight: 500; color: var(--ink-2);
}
.sheet-tabs button:hover { color: var(--ink); }
.sheet-tabs button.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }
.readonly-note { margin: 0 0 var(--s4); padding: 10px 14px; border-radius: var(--radius); background: var(--panel-2); border: 1px solid var(--line); color: var(--ink-2); }
.sheet { display: grid; gap: var(--s4); max-width: 1040px; }
.sheet .card + .card { margin-top: 0; }
.sheet .card > p { margin: 0 0 14px; font-size: 14px; }
.grid-fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px 18px; }
.setting { display: grid; gap: 4px; align-content: start; }
.setting small { color: var(--ink-3); font-size: 12px; }
.setting.wide { grid-column: 1 / -1; }
.unit-input { display: flex; align-items: center; border: 1px solid var(--line-2); border-radius: var(--radius); background: var(--panel); height: 40px; overflow: hidden; }
.unit-input input { flex: 1; min-width: 0; border: 0; background: transparent; height: 100%; padding: 0 12px; font-weight: 600; outline: none; text-align: right; }
.unit-input span { color: var(--ink-3); font-size: 13px; padding: 0 12px 0 4px; white-space: nowrap; }
.changed .unit-input, .changed .text-input, .matrix input.changed { border-color: var(--hl); box-shadow: inset 3px 0 0 var(--hl); }
.matrix-wrap { overflow-x: auto; }
.matrix { min-width: 640px; font-size: 13px; }
.matrix th, .matrix td { padding: 4px; text-align: center; border-bottom: 1px solid var(--line); }
.matrix th:first-child, .matrix td:first-child { text-align: left; font-weight: 600; white-space: nowrap; padding-right: 10px; }
.matrix input { width: 100%; min-width: 56px; height: 34px; text-align: center; border: 1px solid var(--line-2); border-radius: 6px; background: var(--panel); font-variant-numeric: tabular-nums; }
.matrix input:focus { outline: none; border-color: var(--primary); }
.save-bar {
  position: sticky; bottom: 0; z-index: 10; max-width: 1040px; margin-top: var(--s4);
  display: flex; justify-content: flex-end; align-items: center; gap: 10px;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 -6px 20px rgba(0,0,0,.06);
}
.save-status { flex: 1; font-size: 14px; color: var(--ink-2); }
.save-status.ok { color: var(--ok); }
.save-status.err { color: var(--danger); }
.import-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin: 14px 0 6px; }
.import-row input[type="file"] { flex: 1 1 240px; min-width: 0; font-size: 14px; }
.catalog-status p { margin: 0 0 8px; }
.catalog-log { margin: 8px 0; border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 12px; font-size: 13px; }
.catalog-log summary { cursor: pointer; font-weight: 600; }
.catalog-log.err summary { color: var(--danger); }
.catalog-log.warn summary { color: var(--warn); }
.catalog-log ul { margin: 8px 0 0; padding-left: 18px; max-height: 320px; overflow-y: auto; }
.catalog-help { margin-top: 12px; font-size: 14px; }
.catalog-help summary { cursor: pointer; color: var(--link); font-weight: 500; }
.catalog-help p { margin: 8px 0 0; }
#manual-list { overflow-x: auto; }
.manual-table { min-width: 620px; }
.manual-table small { display: block; font-size: 12px; margin: 2px 0 0; }
.manual-actions { white-space: nowrap; text-align: right; }

/* ================================================================ Tài khoản nhân viên */
.users-table tbody tr { cursor: pointer; }
.role-help h2 { margin-bottom: 0; }
.role-help .spec-list dt { min-width: 110px; font-weight: 600; color: var(--ink); }
.role-help .spec-list dd { font-weight: 400; color: var(--ink-2); }

@container content (max-width: 640px) {
  .form-grid, .pf-grid { grid-template-columns: minmax(0, 1fr); }
  .users-table thead { display: none; }
  .users-table, .users-table tbody { display: block; }
  .users-table tr { display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
  .users-table td { border: 0; padding: 0; }
  .users-table td[data-label="Ngày tạo"] { display: none; }
  .users-table .c-actions { grid-row: 1 / span 2; grid-column: 2; align-self: center; }
  .role-help .spec-list div { flex-direction: column; gap: 0; }
  .spec-list dt { min-width: 110px; }
  .save-bar { flex-wrap: wrap; }
  .save-status { flex-basis: 100%; }
}
@media (max-width: 640px) {
  .pf-grid, .form-grid { grid-template-columns: minmax(0, 1fr); }
  .drawer { width: 100vw; }
}
.q-banner { margin: 0 0 12px; padding: 10px 14px; border-radius: var(--radius); background: var(--warn-soft); color: var(--ink); }
.q-banner a { font-weight: 700; margin-left: 4px; }
.q-history td small { display: block; color: var(--ink-3); font-size: 12px; }

/* ================================================================ Chọn báo giá nhận "Thêm vào báo giá" (core/quoteTarget.js) */
.qt-picker { display: inline-flex; gap: 6px; align-items: center; min-width: 0; flex-wrap: wrap; }
.qt-picker .qt-filter { width: 120px; height: 34px; padding: 0 10px; border: 1px solid var(--line-2); border-radius: var(--radius); background: var(--panel); min-width: 0; }
.qt-picker .qt-select { width: 0; max-width: 340px; height: 34px; flex: 1 1 200px; min-width: 0; } /* rộng theo khung, không theo dòng dài nhất */
.qt-picker .qt-select.qt-empty { border-color: var(--primary); }
.toolbar .qt-inline { display: flex; align-items: center; justify-content: flex-end; gap: 8px; flex: 1 1 100%; min-width: 0; }
.toolbar .qt-inline > .label { white-space: nowrap; }
.toolbar .qt-inline .qt-picker { flex: 0 1 520px; flex-wrap: nowrap; }
.toolbar .qt-inline .qt-select { flex: 1 1 300px; max-width: none; }
/* trên khung giá (nền tối) của công cụ tính giá */
.total-quote { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 8px; min-width: 0; }
.total-quote .qt-picker { flex: 1 1 100%; }
.total-quote .qt-filter { flex: 0 1 110px; }
.total-quote .qt-select { max-width: none; flex-basis: 150px; }
.qt-dark .qt-filter, .qt-dark .qt-select { background: rgba(255,255,255,.95); color: #17252b; border-color: rgba(255,255,255,.4); }
.qt-dark .qt-select.qt-empty { border-color: var(--primary); box-shadow: 0 0 0 2px color-mix(in srgb, var(--primary) 45%, transparent); }
.copy-btn:disabled { opacity: .5; cursor: not-allowed; }
.add-quote-btn:disabled:hover { background: var(--primary); }
/* hộp nhỏ hỏi báo giá khi chưa chọn */
.qt-pop {
  position: fixed; inset: auto; margin: 0; z-index: 80; width: min(380px, calc(100vw - 16px)); padding: 12px;
  background: var(--panel); color: var(--ink); border: 1px solid var(--line-2); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
}
.qt-pop-title { margin: 0 0 8px; font-weight: 600; }
.qt-pop .qt-picker { display: flex; }
.qt-pop .qt-filter { flex: 1 1 100%; width: auto; }
.qt-pop .qt-select { max-width: none; flex: 1 1 100%; }
.qt-pop-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 10px; }
.toast.toast-err { background: var(--danger); }
.toast.toast-warn { background: var(--warn); }

/* ================================================================ Sửa sản phẩm trong ngăn chi tiết */
.badge-edited { background: rgba(15, 124, 153, .12); color: var(--link); }
.ov-note { margin: 8px 0; padding: 8px 12px; border-radius: var(--radius); background: rgba(15, 124, 153, .08); color: var(--ink-2); font-size: 13px; }
.drawer-form .pf-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.drawer-foot { flex-wrap: wrap; }
.pf-image { display: grid; grid-template-columns: minmax(0, 1fr) 72px; gap: 10px; align-items: end; }
.pf-preview { width: 72px; height: 72px; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; overflow: hidden; }
.pf-preview img { width: 100%; height: 100%; object-fit: contain; display: block; }
.pf-preview .noimg { font-size: 11px; text-align: center; }
.pf-label-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.pf-field .hint { margin: 0; }
textarea[name="quote_specs"] { font-variant-numeric: tabular-nums; }

/* ================================================================ Trình soạn báo giá: "+ Thêm sản phẩm" */
.q-add-row { position: relative; display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-start; }
.q-finder {
  position: absolute; top: calc(100% + 6px); left: 0; z-index: 30; width: min(620px, 100%);
  background: var(--panel); border: 1px solid var(--line-2); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); padding: 10px;
}
.q-finder-head { display: flex; gap: 8px; align-items: center; }
.q-finder-head .search-box { flex: 1 1 auto; }
.q-finder-title { flex: 1; }
.q-finder-body { max-height: min(420px, 55vh); overflow-y: auto; margin-top: 8px; }
.q-finder-hint { margin: 6px 4px; font-size: 13px; color: var(--ink-3); }
.q-finder-flash { margin: 6px 4px 0; font-size: 13px; color: var(--ok); min-height: 0; }
.q-finder-flash:empty { display: none; }
.q-find-list { list-style: none; margin: 0; padding: 0; }
.q-find-list li { display: flex; align-items: center; gap: 10px; padding: 6px 8px; border-radius: var(--radius); cursor: pointer; }
.q-find-list li:hover { background: var(--hover); }
.q-find-list li.active { background: var(--primary-soft); box-shadow: inset 3px 0 0 var(--primary); }
.q-find-thumb { width: 40px; height: 40px; flex: none; border-radius: 6px; overflow: hidden; background: var(--panel-2); display: flex; }
.q-find-thumb img { width: 100%; height: 100%; object-fit: cover; }
.q-find-main { flex: 1; min-width: 0; display: grid; }
.q-find-main b { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.q-find-main small { color: var(--ink-3); font-size: 12px; }
.q-find-price { white-space: nowrap; font-weight: 600; font-variant-numeric: tabular-nums; }
.q-calc-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 8px; }
.q-calc-btn { border: 1px solid var(--line-2); background: var(--panel); border-radius: var(--radius); padding: 10px 12px; text-align: left; cursor: pointer; font-weight: 500; }
.q-calc-btn:hover, .q-calc-btn:focus-visible { border-color: var(--primary); color: var(--primary); }
.q-act { width: 40px; text-align: right; }
@media (max-width: 640px) {
  .q-finder { position: static; width: 100%; }
  .drawer-form .pf-grid { grid-template-columns: minmax(0, 1fr); }
  .toolbar .qt-inline { justify-content: flex-start; }
  .toolbar .qt-inline .qt-filter { width: 90px; }
}

/* ================================================================ Danh mục sản phẩm (quản lý) */
.cat-table .c-order { width: 64px; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.cat-table .c-cdesc { color: var(--ink-2); max-width: 420px; }
.cat-table .c-ccount a { font-weight: 600; }
.cat-table .c-actions { white-space: nowrap; }

@container content (max-width: 640px) {
  .cat-table thead { display: none; }
  .cat-table, .cat-table tbody { display: block; }
  .cat-table tr { display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
  .cat-table td { border: 0; padding: 0; text-align: left; }
  .cat-table .c-order { display: none; }
  .cat-table td[data-label="Mô tả"]:empty { display: none; }
  .cat-table td[data-label="Mã viết tắt"], .cat-table td[data-label="Số sản phẩm"] { font-size: 13px; }
  .cat-table td[data-label="Mã viết tắt"]::before { content: "Mã: "; color: var(--ink-3); }
  .cat-table td[data-label="Số sản phẩm"]::before { content: "Sản phẩm: "; color: var(--ink-3); }
  .cat-table .c-ccount small { display: inline; margin-left: 4px; }
  .cat-table .c-actions { grid-row: 1 / span 4; grid-column: 2; align-self: center; width: auto; white-space: normal; max-width: 96px; text-align: right; }
}

/* Quy cách báo giá: xem trước trong biểu mẫu sản phẩm, bảng quy tắc hiển thị độ dày */
.pf-spec-preview { margin: 0; padding: 8px 10px; border: 1px dashed var(--line); border-radius: var(--radius); background: #fafbfc; font: inherit; font-size: 13px; white-space: pre-wrap; }
.pf-spec-preview::first-line { font-weight: 700; }
.rules-table { max-width: 520px; }
.rules-table input { width: 110px; }

/* Mẫu quy cách SP tính giá (Cài đặt chung) */
.sheet:has(.spec-tpl) { max-width: 1320px; }
.spec-tpl code, .tpl-mono { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 13px; }
.spec-tpl-note { color: var(--warn); background: var(--warn-soft); border-radius: var(--radius); padding: 8px 12px; }
.spec-tpl-tabs button { white-space: nowrap; }
.spec-tpl-tabs .badge { font-size: 11px; padding: 1px 6px; }
.spec-tpl-body { display: grid; grid-template-columns: minmax(0, 2fr) minmax(260px, 1fr); gap: var(--s5); align-items: start; }
.spec-tpl-edit { display: grid; gap: var(--s3); min-width: 0; }
.spec-tpl-lines td { padding: 6px; vertical-align: top; }
.spec-tpl-lines th:nth-child(3) { width: 24%; }
.spec-tpl-lines .text-input { width: 100%; min-width: 0; }
.spec-tpl-lines textarea.text-input { resize: vertical; min-height: 40px; padding: 6px 10px; line-height: 1.4; }
.spec-tpl-lines input[type="checkbox"] { accent-color: var(--primary); width: 18px; height: 18px; margin-top: 8px; }
.tpl-move { white-space: nowrap; }
.tpl-move .btn { padding: 0 7px; }
.tpl-off .tpl-input { opacity: .55; text-decoration: line-through; }
.tpl-cond { color: var(--link) !important; }
.tpl-warn { color: var(--danger) !important; font-weight: 500; }
.tpl-warn:empty { display: none !important; }
.tpl-input.tpl-bad { border-color: var(--danger); }
.spec-tpl-actions { display: flex; gap: var(--s2); flex-wrap: wrap; }
.spec-tpl-side { display: grid; gap: var(--s2); min-width: 0; }
.spec-tpl-side h3 { margin: 6px 0 0; font-size: 15px; }
.spec-tpl-prevhead { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.spec-tpl-preview { border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel-2); padding: 10px 12px; font-size: 14px; }
.tpl-prev-name { margin: 0 0 4px; }
.tpl-prev-spec { white-space: pre-line; line-height: 1.5; }
.spec-tpl-hint { margin: 0; font-size: 12px; }
.spec-tpl-vars { display: grid; gap: 4px; max-height: 460px; overflow-y: auto; padding-right: 2px; }
.tpl-var {
  display: grid; grid-template-columns: auto 1fr; gap: 0 8px; text-align: left; border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--panel); padding: 5px 8px; cursor: pointer; color: var(--ink); font: inherit; font-size: 13px;
}
.tpl-var:hover:not(:disabled) { border-color: var(--primary); background: var(--primary-soft); }
.tpl-var:disabled { cursor: default; }
.tpl-var-group { margin: 8px 0 2px; font-size: 12px; font-weight: 700; color: var(--ink-3); text-transform: uppercase; letter-spacing: .03em; }
.tpl-var-group:first-child { margin-top: 0; }
.tpl-var code { color: var(--primary-hover); font-weight: 600; }
.tpl-var small { grid-column: 1 / -1; color: var(--ink-3); font-size: 12px; overflow-wrap: anywhere; }
@media (max-width: 1000px) {
  .spec-tpl-body { grid-template-columns: 1fr; }
}

/* Sửa / tính lại dòng sản phẩm tính giá */
.q-recalc { display: block; margin-top: 4px; font-size: 12px; }
.q-recalc:disabled { color: var(--ink-3); cursor: not-allowed; text-decoration: none; }
@keyframes q-flash { 0%, 60% { background: var(--warn-soft); } 100% { background: transparent; } }
.q-table tr.q-flash > td { animation: q-flash 2.4s ease-out; }
.edit-banner { position: sticky; top: 0; z-index: 20; display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin: 0 0 10px; padding: 10px 14px; border: 1px solid var(--warn); border-radius: 8px; background: var(--warn-soft); }
.edit-banner[hidden] { display: none; }
.edit-banner .edit-banner-text { flex: 1 1 260px; min-width: 0; }
.edit-banner.err { border-color: var(--danger, #c0392b); }

/* Ngăn chi tiết sản phẩm: thẻ Thông tin / Mô hình 3D */
.drawer-tabs { display: flex; gap: 4px; padding: 0 20px; border-bottom: 1px solid var(--line); }
.drawer-tabs button { border: 0; background: none; font: inherit; font-weight: 600; font-size: 14px; color: var(--ink-3); padding: 10px 6px; margin-bottom: -1px; border-bottom: 2px solid transparent; cursor: pointer; }
.drawer-tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--primary); }
.drawer-tabs button:hover { color: var(--ink); }
[data-tab-panel][hidden] { display: none !important; }
.m3d-stage { position: relative; height: 320px; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: linear-gradient(180deg, var(--viewer-top), var(--viewer-bottom)); }
.m3d-viewer { position: absolute; inset: 0; touch-action: none; }
.m3d-viewer canvas { display: block; width: 100%; height: 100%; }
.m3d-viewer .viewer-labels { position: absolute; inset: 0; pointer-events: none; }
.m3d-loading, .m3d-viewer .viewer-error { margin: 0; padding: 120px 20px 0; text-align: center; color: var(--ink-3); font-size: 13px; }
.m3d-badges { display: flex; flex-wrap: wrap; gap: 4px; margin: 0 0 6px; min-height: 22px; }
.m3d-toolbar { position: absolute; right: 8px; top: 8px; background: var(--panel); box-shadow: var(--shadow); }
.m3d-warn { margin: 8px 0 0; padding: 8px 12px 8px 26px; border: 1px solid var(--warn); border-radius: var(--radius); background: var(--warn-soft); font-size: 13px; }
.m3d-warn li + li { margin-top: 2px; }
.m3d-meta { font-size: 13px; }
.m3d-meta code, .mono { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 12px; overflow-wrap: anywhere; }
.m3d-edit { margin-top: 14px; padding-top: 12px; border-top: 1px dashed var(--line-2); display: grid; gap: 10px; }
.m3d-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.m3d-pf { display: grid; gap: 4px; min-width: 0; font-size: 13px; }
.m3d-pf .label { font-size: 13px; }
.m3d-pf[hidden], [data-m3d-when][hidden] { display: none; }
.m3d-check { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; cursor: pointer; }
.m3d-sub { margin: 6px 0 0; font-size: 14px; }
.m3d-params { border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel-2); padding: 8px 10px; margin-bottom: 8px; }
.m3d-params .muted { margin: 0; font-size: 13px; }
.m3d-pgrid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px 10px; align-items: end; }
.m3d-pgroup { grid-column: 1 / -1; margin: 6px 0 0; font-size: 12px; font-weight: 700; color: var(--ink-3); text-transform: uppercase; letter-spacing: .03em; }
.m3d-pgroup:first-child { margin-top: 0; }
.m3d-pgrid .text-input, .m3d-pgrid select { height: 32px; font-size: 13px; }
.m3d-msg { margin: 4px 0 0; font-size: 12px; color: var(--danger); }
.m3d-clear { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
.m3d-clear label { display: grid; gap: 2px; font-size: 12px; color: var(--ink-3); }
.m3d-conns { display: flex; flex-wrap: wrap; gap: 6px 14px; }
.m3d-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 0; }
.drawer .m3d-pf.wide { grid-column: 1 / -1; }
.m3d-file-pick { display: flex; gap: 8px; align-items: center; min-width: 0; }
.m3d-file-pick select { flex: 1; min-width: 0; }
.m3d-msg.ok { color: var(--ink-2); }
.m3d-all { align-items: flex-start; line-height: 1.4; }
.m3d-all input { margin-top: 3px; }
.m3d-file { margin: 8px 0 0; padding: 8px 12px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel-2); font-size: 13px; }
.m3d-file p { margin: 0 0 4px; }
.m3d-file-warn { color: var(--danger); }
.m3d-checklist summary { cursor: pointer; font-weight: 600; }
.m3d-checklist ul { list-style: none; margin: 6px 0 0; padding: 0; display: grid; gap: 2px; }
.m3d-checklist li span { display: inline-block; width: 1.2em; font-weight: 700; }
.m3d-checklist li.ok span { color: var(--ok, #2f8a4a); }
.m3d-checklist li.bad span { color: var(--danger); }
.m3d-checklist li.todo span { color: var(--ink-3); }
@media (max-width: 560px) {
  .m3d-row, .m3d-pgrid { grid-template-columns: minmax(0, 1fr); }
  .m3d-clear { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* Trang hướng dẫn (#/help/…) */
.help-doc { max-width: 900px; line-height: 1.6; }
.help-doc h2 { margin-top: 0; }
.help-doc h3 { margin-top: 22px; }
.help-doc li + li { margin-top: 3px; }
.help-doc code { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 13px; background: var(--panel-2); padding: 1px 4px; border-radius: 4px; }
.help-pre { background: var(--panel-2); padding: 10px 12px; border-radius: var(--radius); overflow-x: auto; white-space: pre; font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 13px; line-height: 1.45; }
.help-table { overflow-x: auto; margin: 8px 0 12px; }
.help-table .data-table td, .help-table .data-table th { font-size: 13px; vertical-align: top; }
.q-finder button.loading, [data-pick].loading { opacity: .6; cursor: progress; }

/* ---------------------------------------------------------------- Xếp mặt bằng (#/quotes/<số>/layout) */
.lay { display: flex; flex-direction: column; gap: 10px; }
.lay-bar { display: flex; align-items: center; gap: 10px 14px; flex-wrap: wrap; padding: 10px 14px; }
.lay-title { display: flex; flex-direction: column; min-width: 0; }
.lay-title small { color: var(--ink-3); font-size: 12px; }
.lay-tools { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-left: auto; }
.lay-tools .icon-btn { font-size: 18px; font-weight: 700; }
.lay-modes { padding: 2px; }
.lay-status { font-size: 12px; color: var(--ink-3); min-width: 90px; text-align: right; }
.lay-status.warn { color: var(--warn); font-weight: 600; }
.lay-notice .q-msg { margin: 0; display: flex; gap: 8px; align-items: flex-start; }
.lay-notice .q-msg.lay-info { background: rgba(15, 124, 153, .09); color: var(--ink); font-weight: 400; }
.lay-notice .q-msg.warn { background: var(--warn-soft); color: var(--warn); }
.lay-close { margin-left: auto; width: 26px; height: 26px; flex: none; }
.lay-body { display: grid; grid-template-columns: 300px minmax(0, 1fr) 290px; gap: 10px; align-items: stretch; height: calc(100vh - var(--header-h) - 140px); min-height: 520px; }
.lay-left, .lay-right { padding: 4px 14px 14px; overflow-y: auto; min-height: 0; }
.lay-left h3:first-child, .lay-right h3:first-child { margin-top: 12px; }
.lay-stage { display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); gap: 10px; min-height: 0; }
.lay-stage[data-view-mode="split"] { grid-template-rows: minmax(0, 1fr) minmax(0, 1fr); }
.lay-stage[data-view-mode="split"] .lay-hint { display: none; }
.lay-plan, .lay-3d { position: relative; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; min-height: 0; }
.lay-plan { background: #eef1f2; }
.lay-3d { background: linear-gradient(180deg, var(--viewer-top), var(--viewer-bottom)); }
.lay-svg { display: block; width: 100%; height: 100%; touch-action: none; user-select: none; cursor: grab; }
.lay-svg .lay-hit { cursor: move; }
.lay-plan-tools { position: absolute; top: 10px; right: 10px; display: flex; gap: 6px; }
.lay-plan-tools .icon-btn { background: var(--panel); border: 1px solid var(--line-2); font-size: 18px; font-weight: 700; }
.lay-hint { position: absolute; left: 10px; bottom: 6px; right: 10px; margin: 0; font-size: 11.5px; color: var(--ink-3); pointer-events: none; }
.lay-3d-view { position: absolute; inset: 0; touch-action: none; }
.lay-3d-view canvas { display: block; width: 100%; height: 100%; }
.lay-3d-tools { position: absolute; left: 10px; bottom: 10px; display: flex; gap: 6px; flex-wrap: wrap; }
.lay-3d-msg { position: absolute; top: 10px; left: 12px; margin: 0; font-size: 13px; color: var(--ink-2); background: var(--panel); padding: 4px 10px; border-radius: 6px; }
.lay-badge3d { font: 700 12px/1 "Be Vietnam Pro", system-ui, sans-serif; color: #fff; background: #17323a; padding: 4px 8px; border-radius: 999px; box-shadow: 0 1px 3px rgba(0, 0, 0, .25); }
.lay-badge3d.bad { background: var(--danger); }
.lay-badge3d.sel { background: var(--primary); }
.lay-f { display: flex; flex-direction: column; gap: 3px; margin: 0 0 8px; min-width: 0; }
.lay-f .label { font-size: 12px; color: var(--ink-2); }
.lay-f select { width: 100%; }
.lay-unit { display: flex; align-items: center; gap: 6px; }
.lay-unit input { width: 100%; min-width: 0; }
.lay-unit i { font-style: normal; font-size: 12px; color: var(--ink-3); }
.lay-row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.lay-row3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.lay-add, .lay-btns { display: flex; gap: 6px; flex-wrap: wrap; margin: 4px 0 6px; }
.lay-list-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 14px; }
.lay-list-head h3 { margin: 0; }
.lay-tip { margin: 6px 0 4px; }
.lay-lines { list-style: none; margin: 6px 0 0; padding: 0; display: grid; gap: 6px; }
.lay-line { display: flex; gap: 8px; align-items: flex-start; padding: 8px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); }
.lay-line[draggable="true"] { cursor: grab; }
.lay-line.done { background: var(--panel-2); }
.lay-line.skip { opacity: .65; }
.lay-stt { flex: none; min-width: 24px; height: 24px; border-radius: 12px; background: var(--brand); color: #fff; font-size: 12px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; }
.lay-line-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.lay-line-main b { font-size: 13px; line-height: 1.35; }
.lay-line-main small { font-size: 12px; color: var(--ink-3); }
.lay-ok { color: var(--ok); font-weight: 600; }
.lay-todo { color: var(--warn); font-weight: 600; }
.lay-chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 3px; }
.lay-chip { border: 1px dashed var(--line-2); background: var(--panel); color: var(--ink-3); border-radius: 999px; padding: 1px 8px; font-size: 12px; font-weight: 600; cursor: pointer; }
.lay-chip.on { border-style: solid; border-color: var(--brand-2); color: var(--brand); background: rgba(15, 124, 153, .08); }
.lay-chip.sel { border-color: var(--primary); background: var(--primary-soft); color: #b55406; }
.lay-clear { color: var(--danger); font-size: 13px; }
.lay-name { margin: 0 0 8px; display: flex; flex-direction: column; }
.lay-name small { color: var(--ink-3); font-size: 12px; }
.lay-dl { margin: 0 0 10px; display: grid; gap: 3px; font-size: 13px; }
.lay-dl div { display: grid; grid-template-columns: 92px minmax(0, 1fr); gap: 6px; }
.lay-dl dt { color: var(--ink-3); }
.lay-dl dd { margin: 0; }
.lay-check { display: flex; gap: 6px; align-items: center; font-size: 13px; margin: 2px 0 8px; }
.lay-empty { font-size: 13px; }
.lay-legend { display: grid; gap: 4px; font-size: 12.5px; margin: 8px 0 0; }
.lay-legend div { display: flex; gap: 8px; align-items: center; }
.lay-legend dt { margin: 0; }
.lay-legend dd { margin: 0; color: var(--ink-2); }
.lay-legend .sw { display: inline-block; width: 26px; height: 14px; border: 1.5px solid; border-radius: 2px; vertical-align: middle; }
.lay-legend .sw.dash { border-style: dashed; }
.lay-legend .sw.line { border: 0; border-bottom: 4px solid #0f6e8c; height: 8px; }
.lay-legend .sw.zone { border: 1px dashed #0f6e8c; background: rgba(15, 110, 140, .06); }
.lay-warns { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; font-size: 12.5px; }
.lay-warns li { display: flex; gap: 6px; align-items: flex-start; padding: 5px 8px; border-radius: 6px; line-height: 1.4; }
.lay-warns li[data-warn] { cursor: pointer; }
.lay-warns li span { flex: none; width: 16px; height: 16px; border-radius: 8px; font-size: 11px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; color: #fff; margin-top: 1px; }
.lay-warns .lw-err { background: var(--danger-soft); color: var(--danger); }
.lay-warns .lw-err span { background: var(--danger); }
.lay-warns .lw-warn { background: var(--warn-soft); color: var(--warn); }
.lay-warns .lw-warn span { background: var(--warn); }
.lay-warns .lw-info { background: var(--panel-2); color: var(--ink-2); }
.lay-warns .lw-info span { background: var(--ink-3); }
.lay-plan-left { position: absolute; top: 10px; left: 10px; display: flex; gap: 6px; align-items: flex-start; flex-wrap: wrap; max-width: calc(100% - 230px); }
.lay-toolbar { background: var(--panel); box-shadow: var(--shadow); }
.lay-toggle.active, .lay-toggle.active:hover:not(:disabled) { background: var(--brand); color: #fff; border-color: var(--brand); }
.lay-add .btn.active, .lay-btns .btn.active { background: var(--primary-soft); border-color: var(--primary); }
.lay-layers { position: absolute; top: 40px; left: 0; z-index: 3; padding: 8px 12px; min-width: 190px; box-shadow: var(--shadow); }
.lay-layers .lay-check { margin: 4px 0; }
.lay-layers .lay-f { margin: 6px 0 0; }
.lay-svg[data-cursor="wall"], .lay-svg[data-cursor="measure"], .lay-svg[data-cursor="door"], .lay-svg[data-cursor="window"] { cursor: crosshair; }
.lay-svg[data-cursor="note"] { cursor: text; }
.lay-svg:not([data-cursor="select"]) .lay-hit { cursor: inherit; }
.lay-svg .lay-handle { cursor: grab; }
.lay-note-editor { position: absolute; z-index: 4; width: 240px; min-height: 70px; padding: 6px 8px; font: 14px/1.35 "Segoe UI", Arial, sans-serif; border: 2px solid var(--primary); border-radius: 6px; background: #fffdf6; box-shadow: var(--shadow); resize: both; }
.lay-rect { margin: 4px 0 8px; }
.lay-rect > .label { font-size: 12px; color: var(--ink-2); display: block; margin-bottom: 3px; }
.lay-rect .lay-row3 { align-items: end; }
.lay-rect .lay-row3 .btn { margin-bottom: 8px; white-space: nowrap; }
.lay-wallmode { width: auto; max-width: 100%; height: 30px; font-size: 13px; border-radius: 6px; border: 1px solid var(--line-2); background: var(--panel); padding: 0 6px; }
.lay-check-pad { margin-top: 22px; }
.lay-hnote { margin: 22px 0 0; font-size: 12px; }
.lay-note-text { width: 100%; resize: vertical; font: inherit; }
/* Chế độ cảm ứng (máy tính bảng): nút ≥ 44 px, thanh công cụ dính trên cùng, thanh thao tác nổi, menu giữ lâu, bảng vẽ tường / đo */
/* Thanh trên cùng: hàng cuối (Hoàn tác / Làm lại / 2D · 3D / trạng thái / Lưu) luôn dính dưới tiêu đề trang, các hàng trên cuộn khuất
   dưới tiêu đề (--lay-bar-h: cao thanh, đo bằng JS) */
.lay-touch .lay-bar { position: sticky; top: calc(var(--header-h) + 55px - var(--lay-bar-h, 55px)); z-index: 25; row-gap: 6px; padding: 8px 12px; }
.lay-touch .lay-tools { display: contents; }
.lay-touch .lay-bar > [data-act="back"] { order: 1; }
.lay-touch .lay-title { order: 2; flex: 1 1 160px; }
.lay-touch .lay-total { order: 3; }
.lay-touch .lay-tools > .btn:not([data-act="save"]) { order: 5; }
.lay-touch .lay-bar::after { content: ""; order: 49; flex-basis: 100%; height: 0; }
.lay-touch .lay-tools > [data-act="undo"] { order: 50; }
.lay-touch .lay-tools > [data-act="redo"] { order: 51; }
.lay-touch .lay-modes { order: 52; }
.lay-touch .lay-status { order: 53; margin-left: auto; }
.lay-touch .lay-tools > [data-act="save"] { order: 54; }
.lay-touch .lay-body { height: calc(100dvh - var(--header-h) - 80px); }
.lay-touch .lay-plan-tools { flex-direction: column; align-items: flex-end; }
.lay-touch .lay-plan-left { max-width: calc(100% - 130px); }
.lay-touch .lay-toolbar { flex-wrap: wrap; }
.lay-touch .lay-bar .btn, .lay-touch .lay-plan .btn, .lay-touch .lay-3d-tools .btn, .lay-touch .lay-wallmode { height: auto; min-height: 44px; padding: 0 12px; }
.lay-touch .lay-bar .icon-btn, .lay-touch .lay-plan-tools .icon-btn { width: 44px; height: 44px; }
.lay-touch .lay-modes button, .lay-touch .lay-toolbar button { min-height: 38px; padding: 0 12px; display: inline-flex; align-items: center; justify-content: center; }
.lay-touch .lay-layers { top: 52px; }
.lay-touch .lay-layers .lay-check { min-height: 40px; }
.lay-touch .lay-plan { touch-action: none; }
.lay-touch button, .lay-touch .lay-chip { touch-action: manipulation; }
.lay-touch .lay-svg { -webkit-touch-callout: none; -webkit-user-select: none; }
.lay-touch input, .lay-touch select, .lay-touch textarea, .lay-touch .lay-note-editor { font-size: 16px; } /* iOS: ô nhập < 16 px tự phóng to trang */
.lay-touch .lay-right { scroll-margin-top: calc(var(--header-h) + 70px); }
.lay-fab { position: absolute; z-index: 5; display: flex; flex-wrap: wrap; align-items: center; gap: 4px; padding: 6px; max-width: min(620px, calc(100% - 12px)); box-shadow: var(--shadow-lg, var(--shadow)); border: 1px solid var(--line-2); }
.lay-fab .btn { min-width: 44px; }
.lay-fab-pad { display: inline-flex; gap: 2px; padding: 0 2px; border-left: 1px solid var(--line); border-right: 1px solid var(--line); }
.lay-fab .lay-fab-arrow { font-size: 18px; padding: 0; }
.lay-fab .lay-fab-step { min-width: 56px; padding: 0 6px; font-size: 12px; color: var(--ink-2); }
.lay-fab-len { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; color: var(--ink-2); }
.lay-fab-len input { width: 84px; height: 44px; text-align: right; }
.lay-fab-len i { font-style: normal; font-size: 12px; color: var(--ink-3); }
.lay-ctx { z-index: 6; flex-direction: column; align-items: stretch; flex-wrap: nowrap; min-width: 210px; max-height: calc(100% - 12px); overflow-y: auto; }
.lay-ctx .btn { justify-content: flex-start; }
.lay-touch .lay-ctx { touch-action: pan-y; overscroll-behavior: contain; }
.lay-ctx .lay-fab-pad { border: 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); padding: 4px 0; justify-content: space-between; }
.lay-ctx .lay-fab-pad .btn { justify-content: center; }
.lay-ctx .lay-fab-len { padding: 2px 4px; }
.lay-ctx-title { padding: 4px 8px 6px; font-size: 13px; color: var(--ink-2); border-bottom: 1px solid var(--line); }
.lay-tpanel { position: absolute; z-index: 4; left: 50%; bottom: 10px; transform: translateX(-50%); display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 6px; padding: 8px; width: max-content; max-width: calc(100% - 20px); box-shadow: var(--shadow-lg, var(--shadow)); border: 1px solid var(--line-2); }
.lay-tp-read { flex: 1 1 100%; text-align: center; font-size: 14px; color: var(--ink-2); }
.lay-tp-read b { color: var(--ink); font-size: 16px; }
.lay-tpanel .lay-tp-len { width: 104px; height: 44px; text-align: right; }
.lay-flash { animation: lay-flash 1s ease; }
@keyframes lay-flash { 0%, 60% { box-shadow: 0 0 0 3px var(--primary); } 100% { box-shadow: var(--shadow); } }
@media (max-width: 1280px) {
  .lay-body { grid-template-columns: 270px minmax(0, 1fr); height: auto; }
  .lay-stage { height: calc(100vh - var(--header-h) - 140px); min-height: 520px; }
  .lay-right { grid-column: 1 / -1; display: grid; grid-template-columns: 1fr 1fr; gap: 0 18px; }
  .lay-touch .lay-body { height: auto; }
  .lay-touch .lay-stage { height: calc(100dvh - var(--header-h) - 80px); min-height: 420px; }
}
@media (max-width: 860px) {
  .lay-body { grid-template-columns: minmax(0, 1fr); }
  .lay-stage { height: 62vh; min-height: 360px; order: -1; }
  .lay-touch .lay-stage { height: min(calc(100dvh - var(--header-h) - 80px), 82dvh); }
  .lay-right { grid-template-columns: minmax(0, 1fr); }
  .lay-tools { margin-left: 0; }
  .lay-hint { display: none; }
}

/* ---------------------------------------------------------------- Sản phẩm → Mô hình 3D (thư viện file 3D) */
.models-card { padding: var(--s4) var(--s4) var(--s2); }
.table-scroll { overflow-x: auto; }
.models-table th small { display: block; font-weight: 400; text-transform: none; letter-spacing: 0; }
.models-table tbody tr { cursor: pointer; }
.models-table td { vertical-align: top; }
.models-table b { overflow-wrap: anywhere; }
.models-table th.c-mthumb, .models-table td.c-mthumb { box-sizing: border-box; width: 76px; min-width: 76px; max-width: 76px; padding: 7px 6px !important; overflow: hidden; }
.m-thumb { box-sizing: border-box; width: 64px; height: 48px; border-radius: 6px; border: 1px solid var(--line); background: #fff; display: grid; place-items: center; overflow: hidden; color: var(--ink-3); font-size: 12px; }
.m-thumb img { width: 100%; height: 100%; max-width: 100%; max-height: 100%; object-fit: contain; display: block; }
.c-mstatus { min-width: 160px; max-width: 230px; }
.c-mwhen small { white-space: nowrap; }
.models-table { font-size: 13px; }
.models-table th, .models-table td { padding-left: 7px; padding-right: 7px; }
.c-mname { min-width: 150px; max-width: 220px; }
.c-mused { max-width: 120px; }
.c-mused small { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.m-missing { margin: 4px 0 0; padding-left: 16px; font-size: 12px; color: var(--ink-2); }
.m-missing li + li { margin-top: 1px; }
.m-bad { color: var(--danger); }
.m-ok { color: var(--ok); }
.md-head { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 10px 18px; }
.md-head h2 { margin: 0 0 2px; font-size: 18px; overflow-wrap: anywhere; }
.md-head p { margin: 0; font-size: 13px; }
.md-title { flex: 1 1 320px; min-width: 0; }
.md-status { flex: 0 1 340px; font-size: 13px; }
.md-status .m-missing { margin-top: 6px; }
.md-actions { display: flex; flex-wrap: wrap; gap: 8px; flex: 1 1 100%; }
.md-head .m3d-msg { flex: 1 1 100%; font-size: 13px; }
.md-grid { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(360px, 1fr); gap: var(--s4); margin-top: var(--s4); align-items: start; }
.md-stage-wrap { position: sticky; top: 12px; }
.md-stage-wrap .hint { margin-top: 6px; }
.md-stage { position: relative; height: min(68vh, 640px); min-height: 360px; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: linear-gradient(180deg, var(--viewer-top), var(--viewer-bottom)); }
.md-stage .m3d-loading, .md-stage .viewer-error { padding-top: 30%; }
.md-xray { position: absolute; left: 8px; top: 8px; display: inline-flex; gap: 6px; align-items: center; font-size: 13px; background: var(--panel); box-shadow: var(--shadow); border-radius: var(--radius); padding: 5px 10px; cursor: pointer; }
.md-focus { position: absolute; left: 8px; bottom: 8px; right: 8px; margin: 0; font-size: 13px; background: rgba(255, 138, 31, .14); border: 1px solid #ff8a1f; color: var(--ink); border-radius: var(--radius); padding: 5px 10px; pointer-events: none; }
.md-side { display: grid; gap: var(--s4); min-width: 0; }
.md-side .card + .card { margin-top: 0; }
.md-sec { padding: var(--s4); }
.md-sec h3 { margin: 0 0 6px; font-size: 15px; }
.md-sec-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 6px; }
.md-sec-head h3 { margin: 0; }
.md-sec .hint { margin: 0 0 8px; }
.md-dl { margin-top: 0; font-size: 13px; }
.md-dl dt { min-width: 130px; }
.md-check, .md-notes { margin: 6px 0 8px; padding: 0; list-style: none; display: grid; gap: 3px; font-size: 13px; }
.md-notes { list-style: disc; padding-left: 18px; color: var(--ink-2); }
.md-check li span { display: inline-block; width: 1.2em; font-weight: 700; }
.md-check li.ok span { color: var(--ok); }
.md-check li.bad span { color: var(--danger); }
.md-front-check { margin: 4px 0 8px; font-weight: 600; }
.md-table { font-size: 13px; }
.md-table td { padding: 5px 6px; }
.md-table select { height: 30px; font-size: 13px; max-width: 210px; }
.md-table tr[data-mat-row] { cursor: pointer; }
.md-table tr.active > td, .md-part.active { background: rgba(255, 138, 31, .14) !important; }
.md-swatch { display: inline-block; width: 18px; height: 18px; border-radius: 4px; border: 1px solid var(--line-2); vertical-align: middle; }
.md-parts { max-height: 460px; overflow-y: auto; border: 1px solid var(--line); border-radius: var(--radius); }
.md-part { display: grid; grid-template-columns: 22px minmax(0, 1fr) minmax(150px, 210px); gap: 6px; align-items: center; padding: 5px 8px 5px calc(6px + var(--lvl, 0) * 16px); border-bottom: 1px solid var(--line); cursor: pointer; font-size: 13px; }
.md-part:last-child { border-bottom: 0; }
.md-part:hover { background: var(--hover); }
.md-part.is-hidden .md-part-name { opacity: .55; text-decoration: line-through; }
.md-part-name { min-width: 0; }
.md-part-name b { display: block; font-weight: 600; overflow-wrap: anywhere; }
.md-part-name small, .md-part-role small { display: block; color: var(--ink-3); font-size: 12px; }
.md-part-role select { width: 100%; height: 30px; font-size: 13px; }
.md-tog { border: 0; background: none; padding: 0; width: 22px; height: 22px; cursor: pointer; color: var(--ink-2); font-size: 13px; }
.md-tog:disabled { cursor: default; }
.md-usage { margin: 0; padding: 0; list-style: none; display: grid; gap: 4px; font-size: 13px; }
.md-assign { display: grid; gap: 10px; }
.md-assign-list { max-height: 46vh; overflow-y: auto; border: 1px solid var(--line); border-radius: var(--radius); }
.md-assign-list > p { margin: 10px; }
.md-assign-item { display: flex; gap: 8px; align-items: flex-start; padding: 6px 10px; border-bottom: 1px solid var(--line); font-size: 13px; cursor: pointer; }
.md-assign-item:hover { background: var(--hover); }
.md-assign-item input { margin-top: 3px; }
.md-assign-item small { display: block; color: var(--ink-3); }
@media (max-width: 1100px) {
  .md-grid { grid-template-columns: minmax(0, 1fr); }
  .md-stage-wrap { position: static; }
  .md-stage { height: 420px; }
}
@media (max-width: 560px) {
  .md-part { grid-template-columns: 22px minmax(0, 1fr); }
  .md-part-role { grid-column: 2; }
}

/* ================================================================ Sao lưu dữ liệu */
.bk-status dt { min-width: 170px; }
.bk-path { font-size: 13px; overflow-wrap: anywhere; }
.bk-dir-row { display: flex; gap: 8px; align-items: center; }
.bk-dir-row .text-input { flex: 1; min-width: 0; }
.bk-save-row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.bk-name { font-size: 11.5px; }
.bk-actions { white-space: nowrap; }
.bk-warn { margin: 0 0 var(--s3); padding-left: 20px; display: grid; gap: 6px; font-size: 14px; color: var(--ink-2); }
.hint.ok-text { color: var(--ok); }
.hint.error { color: var(--danger); margin: 2px 0 0; }
@media (max-width: 640px) {
  .bk-status div { flex-direction: column; gap: 0; }
  .bk-table thead { display: none; }
  .bk-table, .bk-table tbody { display: block; }
  .bk-table tr { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
  .bk-table td { border: 0; padding: 0; text-align: left; }
  .bk-table td[data-label="Người tạo"], .bk-table td[data-label="Số file"] { display: none; }
  .bk-table .c-actions { grid-column: 1 / -1; width: auto; display: flex; flex-wrap: wrap; gap: 6px; white-space: normal; }
}

/* ---------------------------------------------------------------- Xếp mặt bằng: sản phẩm của báo giá + hộp thoại «+ Thêm sản phẩm» */
.lay-notice-text { flex: 1; min-width: 0; }
.lay-total { display: inline-flex; align-items: baseline; gap: 6px; padding: 4px 10px; border-radius: 999px; background: var(--panel-2); border: 1px solid var(--line); font-size: 13px; white-space: nowrap; }
.lay-total span { color: var(--ink-3); font-size: 12px; }
.lay-total b { font-variant-numeric: tabular-nums; }
.lay-total small { color: var(--warn); font-weight: 600; font-size: 11px; }
.lay-cust { display: grid; grid-template-columns: auto minmax(160px, 1.2fr) minmax(120px, .8fr) minmax(180px, 1.5fr) minmax(160px, 1.5fr); gap: 4px 10px; align-items: end; padding: 8px 14px; }
.lay-cust .lay-f { margin: 0; }
.lay-cust-title { align-self: center; font-size: 13px; }
.lay-addprod { width: 100%; margin: 8px 0 2px; height: 34px; }
.lay-line.sel { border-color: var(--primary); box-shadow: inset 3px 0 0 var(--primary); }
.lay-line-main[data-line-pick] { cursor: pointer; }
.lay-line-money { font-variant-numeric: tabular-nums; }
.lay-side { display: flex; flex-direction: column; gap: 4px; align-items: flex-end; flex: none; }
.lay-step { display: inline-flex; align-items: center; gap: 2px; font-size: 12px; }
.lay-step b { min-width: 20px; text-align: center; font-variant-numeric: tabular-nums; }
.lay-step .btn { padding: 0 7px; min-width: 24px; height: 24px; line-height: 1; }
.lay-step-in .text-input { width: 64px; text-align: center; }
.lay-line-empty { list-style: none; padding: 10px 4px; font-size: 13px; }
.lay-quote { margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--line); }
.lay-quote h4 { margin: 0 0 8px; font-size: 13px; color: var(--ink-2); }
.lay-amount { margin: 0 0 6px; font-size: 13px; display: flex; flex-wrap: wrap; gap: 4px 8px; align-items: baseline; }
.lay-small { font-size: 12px; margin: 0 0 6px; }
@media (max-width: 1100px) { .lay-cust { grid-template-columns: repeat(2, minmax(0, 1fr)); } .lay-cust-title { grid-column: 1 / -1; } }

.lay-pm { width: min(760px, calc(100vw - 24px)); height: min(640px, calc(100dvh - 24px)); }
.lay-pm.lay-pm-wide { width: min(1360px, calc(100vw - 24px)); height: calc(100dvh - 24px); }
.lay-pm-box { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.lay-pm .modal-head { padding: 10px 20px; }
.lay-pm .modal-head h2 { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lay-pm-tabs { display: flex; gap: 4px; padding: 0 20px; border-bottom: 1px solid var(--line); }
.lay-pm-tabs button { border: 0; background: none; padding: 9px 14px; font: inherit; font-weight: 600; font-size: 14px; color: var(--ink-2); border-bottom: 2px solid transparent; margin-bottom: -1px; cursor: pointer; }
.lay-pm-tabs button.active { color: var(--primary); border-bottom-color: var(--primary); }
.lay-pm-body { flex: 1; min-height: 0; overflow-y: auto; padding: 12px 20px; container-type: inline-size; container-name: content; }
.lay-pm-pane { min-height: 0; }
.lay-pm-pane .search-box { width: 100%; }
.lay-pm-results { margin-top: 8px; }
.lay-pm-calcpane { display: flex; flex-direction: column; gap: 8px; height: 100%; }
.lay-pm-calcbar { display: flex; align-items: center; gap: 12px; }
.lay-pm-calc { flex: 1; min-height: 0; }
@container content (min-width: 1081px) { .lay-pm-calc .workspace { height: 100%; min-height: 460px; } }
.lay-pm-calc .form-panel { top: 0; max-height: none; }
.lay-pm-msg { margin: 0; padding: 0 20px 10px; font-size: 13px; color: var(--ink-2); display: flex; gap: 6px; align-items: center; }
.lay-pm-msg:empty { display: none; }
.lay-pm-msg.err { color: var(--danger); }
