/* ==========================================================================
   Nội Thất Trọng Lương — Lập báo giá
   ========================================================================== */

@font-face { font-family: 'Be Vietnam Pro'; font-weight: 400; font-style: normal; font-display: swap; src: url('../fonts/BeVietnamPro-Regular.ttf') format('truetype'); }
@font-face { font-family: 'Be Vietnam Pro'; font-weight: 500; font-style: normal; font-display: swap; src: url('../fonts/BeVietnamPro-Medium.ttf') format('truetype'); }
@font-face { font-family: 'Be Vietnam Pro'; font-weight: 600; font-style: normal; font-display: swap; src: url('../fonts/BeVietnamPro-SemiBold.ttf') format('truetype'); }
@font-face { font-family: 'Be Vietnam Pro'; font-weight: 700; font-style: normal; font-display: swap; src: url('../fonts/BeVietnamPro-Bold.ttf') format('truetype'); }

:root {
  --bg: #F4F1EC;
  --surface: #FFFFFF;
  --surface-2: #FAF8F4;
  --ink: #1F1D1A;
  --ink-2: #4A453F;
  --muted: #7A7268;
  --line: #E6E0D6;
  --line-strong: #D5CDC0;
  --brass: #A8743F;
  --brass-600: #8E5F30;
  --brass-300: #C99A62;
  --brass-50: #F7EFE5;
  --dark: #26231F;
  --dark-2: #34302B;
  --cream: #F4EEE4;
  --danger: #B3402E;
  --danger-50: #FBEDEA;
  --focus: 0 0 0 3px rgba(168, 116, 63, 0.22);
  --radius: 12px;
  --radius-sm: 8px;
  --topbar-h: 60px;
  --font: 'Be Vietnam Pro', system-ui, -apple-system, 'Segoe UI', Roboto, Arial, sans-serif;
  color-scheme: light;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 14.5px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
/* Cảm ứng: bấm phản hồi ngay, không phóng to khi chạm đúp vào nút */
button, .btn, label.btn { touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

.i {
  width: 18px; height: 18px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 1.8;
  stroke-linecap: round; stroke-linejoin: round;
}

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  height: var(--topbar-h);
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 0 18px;
  background: var(--dark);
  color: var(--cream);
}
.brand { display: flex; align-items: center; gap: 11px; min-width: 0; }
.brand-mark { display: block; width: 38px; height: 38px; border-radius: 10px; box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.16); flex: none; }
.brand-mark svg { display: block; width: 100%; height: 100%; }
.brand-text { display: flex; flex-direction: column; line-height: 1.1; white-space: nowrap; }
.brand-kicker { font-size: 10.5px; font-weight: 600; letter-spacing: 0.18em; text-transform: uppercase; color: var(--brass-300); }
.brand-name { font-size: 17px; font-weight: 700; letter-spacing: 0.01em; }
.brand-divider { width: 1px; height: 26px; background: rgba(255, 255, 255, 0.18); }
.brand-app { font-size: 13.5px; color: rgba(244, 238, 228, 0.72); white-space: nowrap; }

.topbar-actions { display: flex; align-items: center; gap: 8px; }
.save-status { font-size: 12.5px; color: rgba(244, 238, 228, 0.6); margin-right: 6px; white-space: nowrap; display: inline-flex; align-items: center; gap: 5px; }
.save-status .i { width: 14px; height: 14px; color: #9BC59F; }
.save-status.is-error { color: #F2A493; font-weight: 600; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 38px; padding: 0 14px;
  border: 1px solid transparent; border-radius: 9px;
  font-size: 14px; font-weight: 500; line-height: 1;
  white-space: nowrap; text-decoration: none;
  transition: background-color 0.15s, border-color 0.15s, color 0.15s;
}
.btn:focus-visible, .icon-btn:focus-visible, .mobile-tabs button:focus-visible, .qitem-main:focus-visible, .zoom-fab:focus-visible { outline: none; box-shadow: var(--focus); }
.btn-primary { background: var(--brass); color: #fff; }
.btn-primary:hover { background: var(--brass-600); }
.btn-primary:disabled { opacity: 0.75; cursor: progress; }
.btn-ghost { background: transparent; color: var(--cream); border-color: rgba(255, 255, 255, 0.16); }
.btn-ghost:hover { background: rgba(255, 255, 255, 0.08); }
.btn-soft { background: #F0EBE3; color: var(--ink); }
.btn-soft:hover { background: #E8E1D6; }
.btn-sm { height: 32px; padding: 0 11px; font-size: 13px; }
.btn-dashed {
  width: 100%; height: 46px;
  background: transparent; color: var(--ink-2);
  border: 1.5px dashed var(--line-strong);
}
.btn-dashed:hover { border-color: var(--brass); color: var(--brass-600); background: var(--brass-50); }
.badge { min-width: 20px; padding: 2px 6px; border-radius: 99px; background: rgba(255, 255, 255, 0.14); font-size: 11.5px; font-weight: 600; }
.badge:empty { display: none; }
.is-busy .i { animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.3; } }

.icon-btn {
  display: inline-grid; place-items: center;
  width: 30px; height: 30px; padding: 0;
  border: 0; border-radius: 7px;
  background: transparent; color: var(--muted);
}
.icon-btn:hover { background: #F0EBE3; color: var(--ink); }
.icon-btn.danger:hover { background: var(--danger-50); color: var(--danger); }
.icon-btn:disabled { opacity: 0.3; pointer-events: none; }
.icon-btn .i { width: 17px; height: 17px; }

/* ---------- Layout ---------- */
.mobile-tabs { display: none; }
.workspace {
  display: grid;
  grid-template-columns: minmax(400px, 620px) minmax(0, 1fr);
  align-items: start;
}
.editor { padding: 20px 20px 40px; min-width: 0; }
.preview-pane {
  position: sticky; top: var(--topbar-h);
  height: calc(100vh - var(--topbar-h));
  height: calc(100dvh - var(--topbar-h));
  overflow: auto;
  padding: 24px;
  background: #E6E1D9;
  border-left: 1px solid var(--line);
}
.preview-scale { margin: 0 auto; }

/* ---------- Cards & fields ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 20px 20px;
  margin-bottom: 14px;
}
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px 16px; flex-wrap: wrap; margin-bottom: 12px; }
.card-title { margin: 0 0 12px; font-size: 15.5px; font-weight: 600; letter-spacing: -0.005em; }
.card-head .card-title { margin: 0; }
.unit-note { margin: 0; display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--brass-600); background: var(--brass-50); padding: 4px 10px; border-radius: 99px; }
.unit-note .i { width: 15px; height: 15px; }

.grid { display: grid; gap: 0 12px; }
.g-2 { grid-template-columns: 1fr 1fr; }
.g-3 { grid-template-columns: 1.2fr 1fr 0.8fr; }
.field { display: block; margin-bottom: 12px; min-width: 0; }
.field > span { display: block; margin-bottom: 5px; font-size: 12.5px; font-weight: 500; color: var(--muted); }
.card .field:last-child, .card .grid:last-child .field { margin-bottom: 0; }

input, select, textarea {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: #fff;
  font-size: 14.5px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input::placeholder, textarea::placeholder { color: #ABA398; }
input:hover, select:hover, textarea:hover { border-color: #C3B9AA; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brass); box-shadow: var(--focus); }
textarea { resize: vertical; line-height: 1.5; }
input[type='date'] { min-height: 41px; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.input-group { display: flex; }
.input-group input { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.input-group select { width: auto; flex: none; border-left: 0; border-top-left-radius: 0; border-bottom-left-radius: 0; background: var(--surface-2); padding-right: 8px; }
.editor-foot { margin: 4px 4px 0; font-size: 12.5px; color: var(--muted); }

/* ---------- Groups & items ---------- */
.group {
  margin-bottom: 14px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--surface-2);
}
.group-head {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 8px 8px 14px;
  background: var(--brass-50);
  border-bottom: 1px solid var(--line);
  border-radius: 11px 11px 0 0;
}
.group-index { min-width: 22px; font-weight: 700; color: var(--brass); font-size: 14px; }
.group-title { flex: 1; min-width: 0; padding: 6px 9px; font-weight: 600; background: transparent; border-color: transparent; }
.group-title:hover { border-color: var(--line-strong); background: #fff; }
.group-title:focus { background: #fff; }
.row-actions { display: flex; gap: 1px; flex: none; }

.items { display: grid; gap: 10px; padding: 10px; }
.item {
  padding: 10px 10px 12px 12px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.item:focus-within { border-color: #D9C4A8; box-shadow: 0 2px 10px rgba(168, 116, 63, 0.08); }
.item-top { display: flex; align-items: center; gap: 8px; }
.item-no {
  display: grid; place-items: center; flex: none;
  width: 24px; height: 24px; border-radius: 50%;
  background: var(--dark); color: var(--cream);
  font-size: 11.5px; font-weight: 600;
}
.item-name { flex: 1; min-width: 0; font-weight: 600; }
.item-spec { display: block; margin-top: 8px; min-height: 40px; resize: none; overflow: hidden; font-size: 13.5px; color: var(--ink-2); }
.item-grid {
  display: grid;
  grid-template-columns: 1.3fr 0.75fr 0.7fr 1.15fr 1.15fr;
  grid-template-areas: 'size unit qty price total';
  gap: 8px;
  margin-top: 8px;
  align-items: start;
}
.mini { display: block; min-width: 0; }
.mini > span { display: block; margin-bottom: 4px; font-size: 11.5px; font-weight: 500; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mini > span em { font-style: normal; color: var(--brass-600); }
.mini input { padding: 7px 9px; font-size: 14px; }
.m-size { grid-area: size; } .m-unit { grid-area: unit; } .m-qty { grid-area: qty; } .m-price { grid-area: price; } .m-total { grid-area: total; }
.conv { display: block; min-height: 15px; margin-top: 3px; font-size: 11px; color: var(--brass-600); text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.m-total output {
  display: block; padding: 7px 0;
  border-top: 1px solid transparent; border-bottom: 1px solid transparent;
  text-align: right; font-weight: 600; font-size: 14px; white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.group-foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 0 10px 10px; }
.group-sum { font-size: 13px; color: var(--muted); white-space: nowrap; }
.group-sum b { color: var(--ink); font-weight: 600; font-variant-numeric: tabular-nums; }
.items-tip { margin: 10px 2px 0; font-size: 12px; color: var(--muted); }
.items-tip kbd { font: inherit; font-size: 11px; padding: 1px 5px; border: 1px solid var(--line-strong); border-bottom-width: 2px; border-radius: 4px; background: #fff; }

/* ---------- Summary ---------- */
.summary { display: grid; gap: 6px; margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line); }
.sum-row { display: flex; justify-content: space-between; gap: 12px; font-size: 14px; color: var(--ink-2); }
.sum-row b { font-weight: 500; font-variant-numeric: tabular-nums; }
.sum-grand { align-items: baseline; margin-top: 4px; color: var(--ink); font-weight: 600; font-size: 15px; }
.sum-grand b { font-size: 21px; font-weight: 700; color: var(--brass-600); }
.sum-words { margin: 0; font-size: 12.5px; font-style: italic; color: var(--muted); text-align: right; }

/* ---------- Drawer ---------- */
.drawer-backdrop { position: fixed; inset: 0; z-index: 45; background: rgba(25, 22, 19, 0.42); }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 50;
  width: min(440px, 100vw);
  display: flex; flex-direction: column;
  background: var(--surface);
  box-shadow: -12px 0 40px rgba(0, 0, 0, 0.16);
  transform: translateX(105%);
  transition: transform 0.22s ease;
}
.drawer.open { transform: none; }
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 14px 14px 18px; border-bottom: 1px solid var(--line); }
.drawer-head h2 { margin: 0; font-size: 17px; font-weight: 600; }
.drawer-search { position: relative; padding: 12px 18px 6px; }
.drawer-search .i { position: absolute; left: 30px; top: calc(50% + 3px); transform: translateY(-50%); color: var(--muted); width: 17px; height: 17px; }
.drawer-search input { padding-left: 38px; }
.quote-list { flex: 1; margin: 0; padding: 4px 12px 12px; list-style: none; overflow-y: auto; }
.qitem { display: flex; margin: 8px 0; background: #fff; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.qitem:hover { border-color: var(--line-strong); }
.qitem.current { border-color: var(--brass); box-shadow: inset 3px 0 0 var(--brass); }
.qitem-main {
  flex: 1; min-width: 0;
  display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 1px 12px;
  padding: 10px 12px; border: 0; background: none; text-align: left;
}
.qnum { font-size: 12.5px; font-weight: 600; color: var(--ink-2); }
.qnum em { margin-left: 6px; font-style: normal; font-size: 11px; font-weight: 600; color: var(--brass-600); background: var(--brass-50); padding: 1px 6px; border-radius: 99px; }
.qdate { font-size: 12px; color: var(--muted); text-align: right; }
.qcust { font-size: 14.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.qcust i { font-weight: 400; color: var(--muted); }
.qtotal { font-size: 14px; font-weight: 600; color: var(--brass-600); text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.qproj { grid-column: 1 / -1; font-size: 12.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.qitem-actions { display: flex; flex-direction: column; justify-content: center; gap: 2px; padding: 4px; border-left: 1px solid var(--line); }
.list-empty { padding: 48px 16px; text-align: center; color: var(--muted); font-size: 14px; }
.drawer-foot { padding: 14px 18px 18px; border-top: 1px solid var(--line); background: var(--surface-2); }
.drawer-foot p { margin: 0 0 10px; font-size: 12.5px; color: var(--muted); }
.drawer-foot-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 16px; right: 16px; bottom: 22px; z-index: 60;
  display: flex; align-items: center; gap: 14px;
  width: fit-content; max-width: 560px; margin: 0 auto;
  padding: 11px 14px 11px 16px;
  border-radius: 10px;
  background: var(--dark); color: var(--cream);
  font-size: 14px; overflow-wrap: anywhere;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.22);
  transform: translateY(12px); opacity: 0;
  transition: transform 0.18s ease, opacity 0.18s ease;
}
.toast.show { transform: none; opacity: 1; }
.toast { pointer-events: none; }
.toast button { pointer-events: auto; }
.toast.is-error { background: #7A2A1E; }
.toast button { flex: none; padding: 4px 6px; border: 0; background: none; color: var(--brass-300); font-weight: 600; }
.toast button:hover { text-decoration: underline; }

/* ==========================================================================
   Tờ báo giá (A4 = 794 × 1123 px ở 96 dpi) — khớp với file PDF
   ========================================================================== */
.paper {
  width: 794px; min-height: 1123px;
  padding: 45px 48px 44px;
  background: #fff;
  color: #1F1D1A;
  font-size: 12px; line-height: 1.45;
  box-shadow: 0 12px 32px rgba(38, 35, 31, 0.12), 0 1px 3px rgba(38, 35, 31, 0.1);
  transform-origin: top left;
}
.paper p { margin: 0; }
.doc-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; }
.doc-brand { display: flex; align-items: flex-start; gap: 13px; min-width: 0; }
.doc-logo { flex: none; width: 56px; height: 56px; }
.doc-logo svg { display: block; width: 100%; height: 100%; }
.doc-company-name { margin-top: 1px; font-size: 18px; font-weight: 600; letter-spacing: 0.035em; line-height: 1.25; }
.doc-contact { margin-top: 3px; font-size: 11px; }
.doc-contact span, .doc-meta span { color: #6E675E; }
.doc-meta { flex: none; text-align: right; font-size: 11.3px; line-height: 1.5; }
.doc-title { margin-bottom: 1px; font-size: 26.7px; font-weight: 600; line-height: 1.15; letter-spacing: 0.125em; color: #A8743F; margin-right: -0.125em; }
.doc-rule { margin: 13px 0; border-top: 1.6px solid #26231F; }

.doc-info { display: flex; justify-content: space-between; gap: 16px; padding: 9px 13px; background: #F6F1EA; font-size: 11.7px; }
.doc-info table { border-collapse: collapse; }
.doc-info th { width: 72px; padding: 1.8px 6px 1.8px 0; font-weight: 400; color: #6E675E; text-align: left; vertical-align: top; white-space: nowrap; }
.doc-info td { padding: 1.8px 0; vertical-align: top; }
.doc-info .strong { font-weight: 600; }
.doc-info-left { flex: 1; }
.doc-info-right { flex: none; width: 237px; }
.doc-intro { margin: 15px 0 8px !important; }

.doc-table { width: 100%; border-collapse: collapse; table-layout: fixed; font-size: 11.7px; }
.doc-table .w-no { width: 39px; } .doc-table .w-size { width: 113px; } .doc-table .w-unit { width: 52px; }
.doc-table .w-qty { width: 52px; } .doc-table .w-price { width: 95px; } .doc-table .w-total { width: 108px; }
.doc-table th {
  padding: 7px 6px; background: #26231F; color: #F4EEE4;
  font-size: 10.9px; font-weight: 600; text-align: left;
}
.doc-table td {
  padding: 5.6px 6px; vertical-align: top;
  border-bottom: 0.67px solid #E3DCD1; border-left: 0.67px solid #E3DCD1;
  overflow-wrap: anywhere;
}
.doc-table td:first-child { border-left: 0; }
.doc-table tbody tr:last-child td { border-bottom: 1.33px solid #26231F; }
.doc-table .c { text-align: center; }
.doc-table .r { text-align: right; font-variant-numeric: tabular-nums; }
.doc-table .muted { color: #6E675E; }
.doc-table .small { font-size: 10.9px; }
.doc-table .strong { font-weight: 600; }
.it-name { font-weight: 600; }
.it-name.is-empty { font-weight: 400; font-style: italic; color: #6E675E; }
.it-spec { margin-top: 2px; font-size: 10.9px; color: #6E675E; }
.row-group td { padding-top: 6px; padding-bottom: 6px; background: #F6F1EA; font-weight: 600; border-left: 0; }
.row-group .g-no { margin-right: 8px; color: #A8743F; }
.row-sum td { font-style: italic; color: #6E675E; text-align: right; font-size: 11.2px; }
.row-sum td.strong { font-style: normal; color: #1F1D1A; font-size: 11.7px; }
.row-empty td { padding: 16px; text-align: center; font-style: italic; color: #6E675E; }

.doc-totals { display: flex; justify-content: flex-end; margin-top: 11px; break-inside: avoid; }
.doc-totals table { width: 333px; border-collapse: collapse; }
.doc-totals th { padding: 2px 0; font-weight: 400; color: #6E675E; text-align: left; }
.doc-totals td { padding: 2px 0; text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.doc-totals .grand th { padding-top: 3px; color: #1F1D1A; font-weight: 600; font-size: 12.7px; }
.doc-totals .grand td { padding-top: 3px; color: #A8743F; font-weight: 600; font-size: 16.7px; }
.doc-totals tr:not(:first-child).grand > * { padding-top: 7px; border-top: 1px solid #26231F; }
.doc-totals .vat-note td { font-size: 10.4px; font-style: italic; color: #6E675E; }
.doc-words { margin-top: 11px !important; }


.doc-end { break-inside: avoid; page-break-inside: avoid; }
.doc-sign { display: grid; grid-template-columns: 1fr 1fr; margin-top: 24px; text-align: center; }
.sign-date { font-size: 11.5px; font-style: italic; }
.sign-title { margin-top: 3px !important; font-weight: 600; }
.sign-sub { font-size: 10.7px; font-style: italic; color: #6E675E; }
.sign-name { min-height: 1.45em; margin-top: 66px !important; font-weight: 600; }
.doc-foot { margin-top: 29px; text-align: center; font-size: 11.2px; font-style: italic; color: #6E675E; }

/* ==========================================================================
   Thành phần dành cho điện thoại / máy tính bảng
   ========================================================================== */
.mobile-bar, .zoom-fab { display: none; }
.group-word { display: none; }

/* Cảnh báo khi mở trong Zalo / Facebook… */
.inapp-banner {
  display: flex; align-items: flex-start; gap: 10px;
  margin-bottom: 14px; padding: 12px 6px 12px 14px;
  background: #FFF6E3; border: 1px solid #EED7A6; border-radius: var(--radius);
  color: #694C15; font-size: 13.5px; line-height: 1.45;
}
.inapp-banner > .i { margin-top: 1px; color: #B7791F; }
.inapp-banner p { flex: 1; margin: 0; }
.inapp-banner .icon-btn { margin: -6px 0 -6px auto; color: #8A6A2E; }

/* Bảng xuất PDF (trượt lên từ đáy màn hình) */
.sheet-backdrop { position: fixed; inset: 0; z-index: 55; background: rgba(25, 22, 19, 0.45); }
.sheet {
  position: fixed; left: 50%; bottom: 0; z-index: 56;
  width: min(520px, 100%);
  max-height: calc(100% - 24px); overflow-y: auto;
  padding: 10px max(18px, env(safe-area-inset-right)) calc(14px + env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left));
  background: var(--surface);
  border-radius: 18px 18px 0 0;
  box-shadow: 0 -12px 40px rgba(0, 0, 0, 0.2);
  transform: translateX(-50%);
  animation: sheet-in 0.22s ease-out;
}
@keyframes sheet-in { from { transform: translate(-50%, 100%); } to { transform: translate(-50%, 0); } }
.sheet-handle { width: 40px; height: 4px; margin: 0 auto 14px; border-radius: 4px; background: var(--line-strong); }
.sheet h2 { margin: 0 0 6px; font-size: 17px; font-weight: 600; }
.sheet-file { display: flex; align-items: center; gap: 8px; margin: 0 0 16px; font-size: 13px; color: var(--muted); }
.sheet-file .i { width: 16px; height: 16px; }
#exportName { min-width: 0; overflow-wrap: anywhere; color: var(--ink-2); }
.sheet-size { flex: none; }
.sheet-size::before { content: '·'; margin-right: 8px; }
.sheet-actions { display: grid; gap: 10px; }
.btn-block { width: 100%; height: 52px; border-radius: 12px; font-size: 15.5px; white-space: normal; text-align: center; line-height: 1.25; }
.sheet-hint { margin: 12px 2px 0; font-size: 12.5px; color: var(--muted); }
.sheet-close { margin-top: 6px; height: 46px; background: none; color: var(--ink-2); }

/* ---------- Responsive ---------- */
@media (min-width: 1500px) {
  .workspace { grid-template-columns: 660px minmax(0, 1fr); }
}

/* Màn hình cảm ứng: vùng bấm tối thiểu ~40px */
@media (pointer: coarse) {
  .icon-btn { width: 40px; height: 40px; border-radius: 9px; }
  .icon-btn .i { width: 19px; height: 19px; }
  .btn-sm { height: 42px; padding: 0 14px; font-size: 14.5px; }
  .topbar .btn { height: 42px; }
  .items-tip { display: none; }
}

@media (max-width: 960px) {
  :root { --topbar-h: 56px; --tabs-h: 48px; --bar-h: 72px; }
  html { scroll-padding-top: calc(var(--topbar-h) + var(--tabs-h) + 12px); scroll-padding-bottom: calc(var(--bar-h) + 16px); }
  body { padding-bottom: calc(var(--bar-h) + env(safe-area-inset-bottom)); }
  .topbar { padding-left: max(12px, env(safe-area-inset-left)); padding-right: max(12px, env(safe-area-inset-right)); }
  .workspace { display: block; }
  .hide-mobile, .brand-divider, .brand-app { display: none; }

  .mobile-tabs {
    position: sticky; top: var(--topbar-h); z-index: 25;
    display: grid; grid-template-columns: 1fr 1fr;
    padding: 0 env(safe-area-inset-right) 0 env(safe-area-inset-left);
    background: var(--surface); border-bottom: 1px solid var(--line);
  }
  .mobile-tabs button {
    display: flex; align-items: center; justify-content: center; gap: 7px;
    height: var(--tabs-h); border: 0; border-bottom: 2.5px solid transparent;
    background: none; color: var(--muted); font-size: 15px; font-weight: 500;
  }
  .mobile-tabs button[aria-pressed='true'] { color: var(--ink); font-weight: 600; border-bottom-color: var(--brass); }
  .mobile-tabs .i { width: 17px; height: 17px; }

  body[data-tab='edit'] .preview-pane { display: none; }
  body[data-tab='preview'] .editor { display: none; }
  .editor {
    max-width: 680px; margin: 0 auto;
    padding: 14px max(12px, env(safe-area-inset-right)) 28px max(12px, env(safe-area-inset-left));
  }
  .preview-pane {
    position: static; height: auto; border-left: 0;
    min-height: calc(100dvh - var(--topbar-h) - var(--tabs-h) - var(--bar-h));
    padding: 14px max(12px, env(safe-area-inset-right)) 24px max(12px, env(safe-area-inset-left));
  }
  .preview-pane.is-zoomed { overflow-x: auto; -webkit-overflow-scrolling: touch; }

  /* Cỡ chữ ô nhập >= 16px: iPhone không tự phóng to khi chạm vào ô */
  input, select, textarea, .mini input, .item-spec { font-size: 16px; }
  input[type='date'] { -webkit-appearance: none; appearance: none; display: block; min-width: 0; min-height: 44px; text-align: left; }
  input[type='date']::-webkit-date-and-time-value { text-align: left; }
  .card-head { align-items: center; }
  .group-title { min-height: 44px; }

  /* Thanh dưới: tổng tiền + Xuất PDF, nằm trong tầm ngón cái */
  .mobile-bar {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 35;
    display: flex; align-items: center; gap: 12px;
    min-height: var(--bar-h);
    padding: 10px max(14px, env(safe-area-inset-right)) calc(10px + env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
    background: rgba(255, 255, 255, 0.97);
    border-top: 1px solid var(--line);
    box-shadow: 0 -6px 20px rgba(38, 35, 31, 0.07);
  }
  .mobile-bar-total { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.2; }
  .mobile-bar-total span { font-size: 12px; color: var(--muted); }
  .mobile-bar-total b {
    font-size: 20px; font-weight: 700; color: var(--brass-600);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-variant-numeric: tabular-nums;
  }
  .mobile-bar .btn { flex: none; height: 50px; padding: 0 20px; border-radius: 12px; font-size: 15.5px; font-weight: 600; }
  /* Đang gõ (bàn phím mở): ẩn thanh dưới để không che ô nhập */
  body.is-typing { padding-bottom: 0; }
  body.is-typing .mobile-bar { display: none; }

  /* Nút phóng to bản xem trước */
  .zoom-fab {
    position: fixed; z-index: 34;
    right: max(14px, env(safe-area-inset-right));
    bottom: calc(var(--bar-h) + 12px + env(safe-area-inset-bottom));
    align-items: center; gap: 6px; height: 44px; padding: 0 16px;
    border: 1px solid var(--line-strong); border-radius: 99px;
    background: rgba(255, 255, 255, 0.97); color: var(--ink);
    font-size: 14px; font-weight: 600;
    box-shadow: 0 4px 16px rgba(38, 35, 31, 0.14);
  }
  body[data-tab='preview'] .zoom-fab { display: inline-flex; }

  .toast { bottom: calc(var(--bar-h) + 14px + env(safe-area-inset-bottom)); }
  body.is-typing .toast { bottom: 14px; }
  body[data-tab='preview'] .toast { bottom: calc(var(--bar-h) + 68px + env(safe-area-inset-bottom)); }
  .drawer { padding-right: env(safe-area-inset-right); }
  .drawer-foot { padding-bottom: calc(18px + env(safe-area-inset-bottom)); }
}

@media (max-width: 720px) {
  .topbar-actions { gap: 8px; }
  .topbar-actions .btn-ghost .lbl, .save-status span { display: none; }
  .topbar-actions .btn-ghost { position: relative; width: 42px; height: 42px; padding: 0; }
  .topbar-actions .btn-ghost .i { width: 20px; height: 20px; }
  .topbar-actions .btn-ghost .badge { position: absolute; top: -5px; right: -6px; background: var(--brass); color: #fff; }
  .save-status { margin-right: 2px; }
  .brand-mark { width: 36px; height: 36px; }
  .brand-name { font-size: 16px; }
  .card { padding: 16px 14px; }
  .card-title { font-size: 16px; }
  .g-2, .g-3 { grid-template-columns: 1fr 1fr; }
  .g-3 .field:first-child { grid-column: 1 / -1; }
  .unit-note { align-items: flex-start; padding: 6px 10px; border-radius: 10px; }
  .unit-note .i { margin-top: 1px; }

  /* Hạng mục: dòng 1 = "Hạng mục I" + nút; dòng 2 = ô tên hạng mục rộng hết khung */
  .group-head { flex-wrap: wrap; row-gap: 4px; padding: 6px 6px 10px 12px; }
  .group-word { display: inline; }
  .group-index { font-size: 13px; }
  .group-head .row-actions { margin-left: auto; }
  .group-title { order: 3; flex-basis: 100%; min-height: 44px; margin-right: 6px; padding: 9px 11px; background: #fff; border-color: var(--line-strong); }

  .items { gap: 8px; padding: 8px; }
  .item { padding: 6px 8px 12px 10px; }
  /* Sản phẩm: dòng 1 = số thứ tự + nút; dòng 2 = tên sản phẩm rộng hết khung */
  .item-top { flex-wrap: wrap; row-gap: 6px; }
  .item-top .row-actions { margin-left: auto; }
  .item-top .item-name { order: 3; flex-basis: 100%; }
  .item-grid {
    grid-template-columns: 1fr 1fr 1fr;
    grid-template-areas: 'size size unit' 'qty price price' 'total total total';
    gap: 8px 10px;
  }
  .mini > span { font-size: 12.5px; }
  .mini input { padding: 9px 10px; }
  .conv { font-size: 12px; }
  .m-total { display: flex; justify-content: space-between; align-items: baseline; padding-top: 6px; border-top: 1px dashed var(--line); }
  .m-total > span { margin: 0; }
  .m-total output { padding: 0; font-size: 16px; }
  /* Chân hạng mục: tổng phụ ở trên, nút "Thêm sản phẩm" rộng hết khung */
  .group-foot { flex-wrap: wrap; gap: 6px; padding: 0 8px 10px; }
  .group-foot .group-sum { flex: 1 1 100%; padding: 0 2px; text-align: right; }
  .group-foot .btn { flex: 1 1 100%; height: 44px; }
  .sum-grand b { font-size: 22px; }
}

@media (max-width: 380px) {
  .g-2 { grid-template-columns: 1fr; }
  .mobile-bar .btn { padding: 0 14px; }
  .mobile-bar-total b { font-size: 18px; }
}

@media (max-width: 340px) {
  .brand-text { display: none; }
}

/* Điện thoại xoay ngang / màn hình thấp: thanh trên cùng không dính để còn chỗ nhập liệu */
@media (max-width: 960px) and (max-height: 520px) {
  :root { --bar-h: 60px; }
  .topbar { position: static; }
  .mobile-tabs { top: 0; }
  html { scroll-padding-top: calc(var(--tabs-h) + 12px); }
  .mobile-bar { padding-top: 6px; padding-bottom: calc(6px + env(safe-area-inset-bottom)); }
  .mobile-bar .btn { height: 44px; }
  .preview-pane { min-height: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .sheet, .drawer, .toast { animation: none !important; transition: none !important; }
}

/* ---------- In ấn ---------- */
@media print {
  @page { size: A4; margin: 12mm 12mm 14mm; }
  html, body { background: #fff !important; padding: 0 !important; }
  .topbar, .mobile-tabs, .editor, .drawer, .drawer-backdrop, .toast,
  .mobile-bar, .zoom-fab, .sheet, .sheet-backdrop { display: none !important; }
  .workspace { display: block; }
  .preview-pane, body[data-tab='edit'] .preview-pane {
    display: block !important; position: static; height: auto; min-height: 0; overflow: visible;
    padding: 0; background: none; border: 0;
  }
  .preview-scale { width: auto !important; height: auto !important; }
  .paper { width: auto; min-height: 0; padding: 0; box-shadow: none; transform: none !important; }
  .doc-table thead { display: table-header-group; }
  .doc-table tr { break-inside: avoid; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
