/* =====================================================================
   ABM Chemical — giao diện sáng, tối giản
   Một màu nhấn duy nhất (xanh ngọc bích — gợi nhựa tái sinh), phân cấp bằng
   chữ, khoảng trắng và đường kẻ mảnh; không đổ bóng thẻ.
   ===================================================================== */
:root {
  --paper: #ffffff;
  --canvas: #f6f8f7;          /* nền rất nhạt cho vùng nhấn nhẹ */
  --zebra: #f1f5f3;           /* nền dòng chẵn trong bảng (xen kẽ cho dễ đọc) — chữ mờ trên nền này vẫn 4.53:1 */
  --row-hover: #e6f1eb;       /* nền dòng khi rê chuột / chạm */
  --ink: #18201c;             /* chữ chính */
  --ink-2: #5b6660;           /* chữ phụ */
  --ink-3: #68726c;           /* chữ mờ, placeholder — 4.99:1 trên trắng (WCAG AA) */
  --line: #e4e8e5;            /* đường kẻ trang trí (phân cách) */
  --line-strong: #8a948e;     /* viền ô nhập — 3.13:1, đạt chuẩn tương phản phi văn bản 3:1 */
  --accent: #0f7b5f;          /* xanh ngọc bích */
  --accent-press: #0b5f49;
  --accent-soft: #e7f3ee;
  --danger: #b42318;
  --danger-soft: #fdecea;
  --warn: #9a5b00;
  --warn-soft: #fdf3e1;

  --font: 'Be Vietnam Pro', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --fs-xs: 12px; --fs-sm: 13px; --fs-base: 15px; --fs-md: 17px; --fs-lg: 20px; --fs-xl: 26px; --fs-hero: 40px;

  --r-sm: 8px; --r-md: 12px; --r-lg: 16px;
  --sidebar-w: 268px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; touch-action: manipulation; }
/* Ẩn khỏi màn hình nhưng trình đọc màn hình vẫn đọc được */
.visually-hidden { position: absolute !important; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.skip-link { position: absolute; left: 12px; top: -60px; z-index: 200; padding: 10px 16px; border-radius: var(--r-sm);
  background: var(--ink); color: #fff; font-weight: 600; }
.skip-link:focus { top: 12px; text-decoration: none; }
#view:focus { outline: none; }
body { margin: 0; font-family: var(--font); font-size: var(--fs-base); line-height: 1.55; color: var(--ink); background: var(--paper);
  -webkit-font-smoothing: antialiased; }
h1 { font-size: var(--fs-xl); font-weight: 700; letter-spacing: -.02em; line-height: 1.25; margin: 0 0 20px; }
h2 { font-size: var(--fs-md); font-weight: 600; letter-spacing: -.01em; margin: 0 0 12px; }
h3 { font-size: var(--fs-base); font-weight: 600; margin: 32px 0 12px; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.muted { color: var(--ink-2); }
.error { color: var(--danger); min-height: 20px; font-size: var(--fs-sm); }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* ---------- Đăng nhập ---------- */
.login-wrap { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; background: var(--canvas); }
.login-card { width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 16px; }
.login-logo { display: block; width: 180px; height: auto; margin: 0 auto 12px; }
.login-card p { margin: -10px 0 8px; }
.login-card .btn { padding: 12px; margin-top: 4px; }

/* ---------- Khung chính ---------- */
.layout { display: flex; min-height: 100vh; }
.topbar { display: none; }
.drawer-backdrop { display: none; }

.sidebar { width: var(--sidebar-w); flex-shrink: 0; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column;
  background: var(--paper); border-right: 1px solid var(--line); }
.sidebar .brand { display: block; padding: 18px 24px 14px; }
.sidebar .brand img { display: block; width: 128px; height: auto; }
.sidebar .brand:focus-visible { outline: 2px solid var(--accent); outline-offset: -4px; border-radius: var(--r-sm); }
.sidebar nav { flex: 1; overflow-y: auto; padding: 0 12px 16px; display: flex; flex-direction: column; gap: 2px; }

.nav-sec { display: flex; align-items: center; gap: 8px; width: 100%; padding: 10px 12px; margin-top: 6px; border: none; background: none;
  border-radius: var(--r-sm); font: inherit; font-size: var(--fs-sm); font-weight: 600; color: var(--ink-2); text-align: left; cursor: pointer; }
.nav-sec:hover { color: var(--ink); background: var(--canvas); }
.nav-sec .lbl { flex: 1; }
.nav-sec .chev { font-size: 16px; line-height: 1; color: var(--ink-3); transition: transform .15s; }
.nav-section.open .nav-sec .chev { transform: rotate(90deg); }
.nav-section.active .nav-sec { color: var(--ink); }
.nav-section:not(.open) .nav-sub { display: none; }
.nav-sub { display: flex; flex-direction: column; gap: 6px; padding: 2px 0 10px 6px; }
/* Mỗi mục menu là một ô bo viền, cùng màu với ô Truy cập nhanh (tone-*) */
.nav-sub a, .nav-home { display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: 12px;
  background: var(--soft, #e9f6f0); border: 1px solid color-mix(in srgb, var(--solid, #0f7b5f) 16%, transparent);
  color: var(--ink); font-size: 14.5px; text-decoration: none; transition: box-shadow .12s ease, border-color .12s ease; }
.nav-sub a:hover, .nav-home:hover { text-decoration: none; box-shadow: 0 2px 8px rgba(16, 40, 32, .08);
  border-color: color-mix(in srgb, var(--solid, #0f7b5f) 35%, transparent); }
.nav-sub a.active, .nav-home.active { border-color: var(--solid, #0f7b5f); box-shadow: inset 0 0 0 1px var(--solid, #0f7b5f); font-weight: 600; }
.nav-ico { width: 30px; height: 30px; flex-shrink: 0; display: grid; place-items: center; border-radius: 50%;
  background: var(--solid, #0f7b5f); color: #fff; }
.nav-lbl { flex: 1; min-width: 0; }
.soon { font-size: var(--fs-xs); font-weight: 500; color: var(--ink-3); white-space: nowrap; }

.user-box { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 14px 24px; border-top: 1px solid var(--line); }
.user-box .user-name { color: var(--ink); font-weight: 600; font-size: var(--fs-sm); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-box .link { font-size: var(--fs-sm); color: var(--ink-2); white-space: nowrap; }
.user-box .link:hover { color: var(--danger); }

.content { flex: 1; min-width: 0; max-width: 1360px; padding: 36px 40px 48px; }

/* ---------- Điều khiển ---------- */
input, select, textarea { width: 100%; font: inherit; color: inherit; padding: 9px 12px; background: var(--paper);
  border: 1px solid var(--line-strong); border-radius: var(--r-sm); transition: border-color .15s; }
input::placeholder, textarea::placeholder { color: var(--ink-3); }
input:hover, select:hover, textarea:hover { border-color: var(--ink-2); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--accent); }
/* Ô ngày kiểu Việt Nam (dateInputHtml): ô chữ dd/mm/yyyy + nút lịch; ô date của trình duyệt ẩn, chỉ để mở bộ chọn */
.date-box { position: relative; display: flex; align-items: stretch; width: 100%; }
.date-box .date-input { flex: 1; min-width: 0; padding-right: 40px; font-variant-numeric: tabular-nums; }
.date-box .date-pick { position: absolute; right: 1px; top: 1px; bottom: 1px; width: 38px; display: flex; align-items: center;
  justify-content: center; border: none; border-radius: 0 var(--r-sm) var(--r-sm) 0; background: transparent; color: var(--ink-2); cursor: pointer; }
.date-box .date-pick:hover { color: var(--accent); }
.date-box .date-pick:disabled { display: none; }
/* Ô date thật: trong suốt, phủ đúng vùng nút lịch → chạm vào biểu tượng là chạm vào ô date (điện thoại tự mở bộ chọn) */
.date-box .date-native { position: absolute; right: 1px; top: 1px; bottom: 1px; width: 38px; height: auto; min-width: 0; margin: 0;
  padding: 0; border: 0; opacity: 0; cursor: pointer; font-size: 16px; z-index: 1; }
.date-box .date-native:disabled { display: none; }
.date-box .date-native::-webkit-calendar-picker-indicator { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.ed-form.is-view .date-box .date-input { padding-right: 12px; }
@media (max-width: 768px) {
  .date-box .date-input { padding-right: 48px; }
  .date-box .date-pick, .date-box .date-native { width: 46px; }
}
label { display: flex; flex-direction: column; gap: 6px; font-size: var(--fs-sm); font-weight: 500; color: var(--ink-2); }
label.inline { flex-direction: row; align-items: center; gap: 10px; font-size: var(--fs-base); color: var(--ink); font-weight: 400; }

.btn { font: inherit; font-weight: 500; padding: 9px 18px; border-radius: var(--r-sm); border: 1px solid var(--line); background: var(--paper);
  color: var(--ink); cursor: pointer; white-space: nowrap; transition: background .15s, border-color .15s; }
.btn:hover { background: var(--canvas); }
.btn:disabled { opacity: .45; cursor: default; }
.btn[aria-busy="true"] { opacity: .7; cursor: progress; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.primary:hover { background: var(--accent-press); border-color: var(--accent-press); }
.btn.sm { padding: 5px 12px; font-size: var(--fs-sm); }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 35%, transparent); }
.btn.danger:hover:not(:disabled) { background: var(--danger-soft); }
.link { background: none; border: none; padding: 0; font: inherit; color: var(--accent); cursor: pointer; }
.link:hover { text-decoration: underline; }

.toolbar { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px; margin-bottom: 24px; }
.toolbar input[type=search] { width: 320px; }
.toolbar label { width: 170px; }
/* Nút Tìm: có màu (nền xanh nhạt, chữ xanh) để dễ thấy nhưng không tranh với nút chính "+ Thêm" */
.btn.search-btn { background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 35%, transparent); color: var(--accent); font-weight: 600; }
.btn.search-btn:hover { background: color-mix(in srgb, var(--accent-soft) 70%, var(--accent) 12%); }
/* Dòng vừa thêm mới trong danh sách */
tbody tr.is-new, tbody tr.is-new:nth-child(even) { background: var(--accent-soft); box-shadow: inset 3px 0 0 var(--accent); }
.new-badge { margin-right: 6px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-grid .full { grid-column: 1 / -1; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }

/* ---------- Khối & bảng ---------- */
.panel { border: 1px solid var(--line); border-radius: var(--r-md); padding: 20px; background: var(--paper); }
/* position: relative — để phần tử absolute bên trong (vd .visually-hidden ở cột cuối) bị cắt theo vùng cuộn,
   không kéo giãn cả trang thành cuộn ngang */
.table-wrap { position: relative; overflow-x: auto; border-top: 1px solid var(--line); }
.panel .table-wrap { border-top: none; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 12px 14px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--line); }
tbody td, tbody th { font-size: 14px; }
td:first-child { white-space: nowrap; }
th:first-child, td:first-child { padding-left: 12px; }
th:last-child, td:last-child { padding-right: 12px; }
/* Dòng xen kẽ màu nền (bỏ qua dòng tổng cộng) */
tbody tr:nth-child(even):not(:has(> th)) { background: var(--zebra); }
thead th { font-size: var(--fs-sm); font-weight: 500; color: var(--ink-2); white-space: nowrap; padding-top: 10px; padding-bottom: 10px; }
tbody tr.clickable { cursor: pointer; }
@media (hover: hover) { tbody tr.clickable:hover { background: var(--row-hover); } } /* không dính màu sau khi chạm trên điện thoại */
tbody tr.clickable:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; background: var(--row-hover); }
/* Bảng thay thế cho biểu đồ (cho trình đọc màn hình / xem số liệu chi tiết) */
.chart-table { margin-top: 12px; font-size: var(--fs-sm); }
.chart-table summary { cursor: pointer; color: var(--accent); padding: 6px 0; }
.pw-wrap { position: relative; }
.pw-wrap input { padding-right: 64px; }
.pw-toggle { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); min-height: 36px; padding: 0 10px;
  border: none; background: none; font: inherit; font-size: var(--fs-sm); color: var(--accent); cursor: pointer; border-radius: var(--r-sm); }
tbody th { font-weight: 600; }
td.num, th.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.empty { padding: 40px 16px; text-align: center; color: var(--ink-2); }
.pager { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 8px; padding: 14px 4px; }
.pager .muted { margin-right: auto; font-size: var(--fs-sm); }

.badge { display: inline-block; white-space: nowrap; padding: 1px 8px; border-radius: 999px; font-size: var(--fs-xs); font-weight: 500;
  background: var(--canvas); color: var(--ink-2); border: 1px solid var(--line); }
.badge.ok { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.badge.warn { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.badge.blue { background: var(--paper); color: var(--ink); }

/* ---------- Doanh thu (Tổng quan) ---------- */
.hero { margin: 8px 0 28px; }
.hero-label { font-size: var(--fs-base); color: var(--ink-2); }
.hero-value { font-size: var(--fs-hero); font-weight: 700; letter-spacing: -.035em; line-height: 1.1; margin: 4px 0 6px;
  font-variant-numeric: tabular-nums; }
.hero-value .unit { font-size: var(--fs-lg); font-weight: 600; color: var(--ink-2); letter-spacing: -.01em; margin-left: 6px; }
.hero-sub { font-size: var(--fs-sm); color: var(--ink-3); }
.stats { display: flex; flex-wrap: wrap; gap: 0; margin: 0 0 36px; padding: 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.stats > div { flex: 1 1 160px; padding: 16px 20px; border-left: 1px solid var(--line); }
.stats > div:first-child { border-left: none; padding-left: 4px; }
.stats dt { font-size: var(--fs-sm); color: var(--ink-2); }
.stats dd { margin: 2px 0 0; font-size: var(--fs-lg); font-weight: 600; font-variant-numeric: tabular-nums; }
.stats dd a { color: inherit; display: inline-block; min-width: 44px; min-height: 32px; }
.stats dd a.due { color: var(--danger); }
.section { margin-bottom: 40px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 40px; }
.chart-box { position: relative; height: 300px; }

/* ---------- Chi tiết ---------- */
.info-grid { display: grid; grid-template-columns: 150px 1fr; gap: 10px 20px; margin: 0; }
.info-grid dt { color: var(--ink-2); font-size: var(--fs-sm); padding-top: 1px; }
.info-grid dd { margin: 0; word-break: break-word; }
.back { display: inline-block; margin-bottom: 14px; font-size: var(--fs-sm); color: var(--ink-2); }
.section-back { display: none; } /* chỉ hiện trên điện thoại, xem @media max-width 768px */
.page-sub { margin: -14px 0 24px; color: var(--ink-2); }
.note { padding: 14px 0; border-bottom: 1px solid var(--line); }
.note:first-child { border-top: 1px solid var(--line); }
.note-head { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; margin-bottom: 6px; font-size: var(--fs-sm); }
.note-head .actions { margin-left: auto; display: flex; gap: 16px; }
.note-content { white-space: pre-wrap; word-break: break-word; }
.note-meta { font-size: var(--fs-sm); color: var(--ink-3); margin-top: 6px; }

/* ---------- Trang giữ chỗ & tài khoản ---------- */
.placeholder { padding: 56px 24px; text-align: center; border: 1px dashed var(--line); border-radius: var(--r-md); }
.placeholder p { max-width: 420px; margin: 0 auto; color: var(--ink-2); }
.account { max-width: 520px; }
.account-head { display: flex; align-items: center; gap: 16px; margin-bottom: 24px; }
.account-name { font-size: var(--fs-md); font-weight: 600; }
.avatar { width: 36px; height: 36px; border-radius: 50%; border: none; background: var(--accent-soft); color: var(--accent);
  font: inherit; font-weight: 700; cursor: pointer; flex-shrink: 0; }
.avatar.lg { width: 56px; height: 56px; display: grid; place-items: center; font-size: 22px; cursor: default; }
.account-actions { display: flex; flex-wrap: wrap; gap: 10px; }

/* ---------- Hộp thoại & thông báo ---------- */
dialog { width: min(880px, calc(100vw - 32px)); max-height: calc(100vh - 64px); padding: 24px 28px; border: none; border-radius: var(--r-lg);
  color: var(--ink); box-shadow: 0 24px 64px rgba(16, 24, 20, .18); }
dialog::backdrop { background: rgba(24, 32, 28, .35); }
.modal-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 20px; }
.modal-head h2 { margin: 0; font-size: var(--fs-lg); }
.modal-head .link { font-size: 20px; line-height: 1; padding: 4px; color: var(--ink-3); }
.modal-head .link:hover { color: var(--ink); text-decoration: none; }
.toast { position: fixed; right: 24px; bottom: 24px; z-index: 100; padding: 12px 18px; border-radius: var(--r-sm);
  background: var(--ink); color: #fff; font-size: var(--fs-sm); }
.toast.err { background: var(--danger); }

/* ---------- Menu tài khoản (điện thoại) ---------- */
.user-menu { position: absolute; right: 12px; top: calc(100% + 6px); min-width: 210px; padding: 6px; display: flex; flex-direction: column;
  background: var(--paper); color: var(--ink); border: 1px solid var(--line); border-radius: var(--r-md); box-shadow: 0 12px 32px rgba(16, 24, 20, .12); }
.user-menu-name { padding: 10px 12px; font-weight: 600; border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.user-menu button { padding: 12px; border: none; border-radius: var(--r-sm); background: none; font: inherit; color: inherit; text-align: left; cursor: pointer; }
.user-menu button:hover, .user-menu button:active { background: var(--canvas); }

/* ---------- Trang chủ ---------- */
.nav-home { margin: 0 0 6px; font-weight: 600; }

.home-hero { position: relative; color: #fff; border-radius: 24px; padding: 28px 32px 56px; margin-bottom: 52px;
  background: linear-gradient(135deg, #0f7b5f 0%, #11807a 50%, #1d6fa3 100%); }
.hero-bar { display: none; }
.hero-hello { font-size: 28px; font-weight: 700; letter-spacing: -.02em; margin: 0 0 4px; color: #fff; }
.hero-date { margin: 0; color: rgba(255,255,255,.85); }
.home-search { position: absolute; left: 24px; right: 24px; bottom: -28px; display: flex; align-items: center; gap: 10px;
  height: 56px; padding: 0 18px; background: var(--paper); color: var(--ink-3); border-radius: 16px;
  box-shadow: 0 8px 24px rgba(16, 40, 32, .12), 0 1px 3px rgba(16, 40, 32, .08); }
.home-search input { border: none; padding: 0; height: 100%; font-size: 16px; background: transparent; }
.home-search input:focus { box-shadow: none; }
.home-search:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }

.search-results { margin: -36px 0 32px; padding: 8px 8px 4px; background: var(--paper); border: 1px solid var(--line);
  border-radius: 16px; box-shadow: 0 8px 24px rgba(16, 40, 32, .08); }
.search-results > p { margin: 8px; }
.sr-group + .sr-group { border-top: 1px solid var(--line); margin-top: 4px; padding-top: 4px; }
.sr-head { display: flex; justify-content: space-between; align-items: center; padding: 8px 10px 4px; font-size: var(--fs-sm);
  color: var(--ink-2); font-weight: 600; }
.sr-head a { font-weight: 500; }
.sr-item { display: flex; gap: 10px; align-items: baseline; width: 100%; min-height: 44px; padding: 10px; border: none; border-radius: var(--r-sm);
  background: none; font: inherit; color: var(--ink); text-align: left; cursor: pointer; text-decoration: none; }
.sr-item:hover { background: var(--canvas); text-decoration: none; }
.sr-item b { flex-shrink: 0; font-weight: 600; }
.sr-item span { color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.sr-none { color: var(--ink-2); }

.qa-group { margin-bottom: 28px; }
.qa-group h2 { font-size: var(--fs-md); margin-bottom: 12px; }
.qa-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 14px; }
/* Nhóm con trong một nhóm (vd Phát sinh: Chung, Kinh doanh…) — cùng kiểu tiêu đề nhóm con của trang nhóm (.sec-group h2) */
.qa-sub { margin: 18px 0 10px 2px; font-size: var(--fs-base); font-weight: 600; color: var(--ink-2); }
.qa-group h2 + .qa-sub { margin-top: 0; }
.qa-tile { --soft: #e9f6f0; --solid: #0f7b5f; position: relative; display: flex; flex-direction: column; gap: 2px; min-height: 132px;
  padding: 16px 16px 14px; border-radius: 18px; background: var(--soft); border: 1px solid color-mix(in srgb, var(--solid) 12%, transparent);
  color: var(--ink); text-decoration: none; box-shadow: 0 1px 2px rgba(16, 40, 32, .04), 0 4px 14px rgba(16, 40, 32, .05);
  transition: transform .12s ease, box-shadow .12s ease; }
.qa-tile:hover { text-decoration: none; box-shadow: 0 2px 4px rgba(16, 40, 32, .06), 0 10px 24px rgba(16, 40, 32, .08); }
.qa-tile:active { transform: scale(.98); }
.qa-icon { width: 48px; height: 48px; border-radius: 50%; display: grid; place-items: center; margin-bottom: 10px;
  background: var(--solid); color: #fff; box-shadow: 0 4px 10px color-mix(in srgb, var(--solid) 30%, transparent); }
.qa-title { font-weight: 600; font-size: var(--fs-base); line-height: 1.3; padding-right: 18px; }
.qa-desc { font-size: var(--fs-sm); color: var(--ink-2); line-height: 1.35; padding-right: 18px; }
.qa-chev { position: absolute; right: 12px; bottom: 14px; color: var(--ink-2); }
.qa-badge { position: absolute; top: 12px; right: 12px; padding: 2px 9px; border-radius: 999px; font-size: var(--fs-xs); font-weight: 600;
  background: var(--solid); color: #fff; }
.tone-green  { --soft: #e9f6f0; --solid: #0f7b5f; }
.tone-teal   { --soft: #e5f5f6; --solid: #0e7480; }
.tone-blue   { --soft: #e9f0fc; --solid: #2b5fd9; }
.tone-violet { --soft: #f0edfb; --solid: #6a4cc2; }
.tone-amber  { --soft: #fdf4e2; --solid: #985f04; }
.tone-rose   { --soft: #fdecf0; --solid: #c23b5c; }
.tone-orange { --soft: #fdeee5; --solid: #c2531f; }
.tone-sky    { --soft: #e6f4fb; --solid: #0a76a6; }

/* Trang nhóm: danh sách chức năng dạng dòng */
.sec-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; max-width: 720px; }
.sec-row { display: flex; align-items: center; gap: 14px; min-height: 68px; padding: 12px 14px; border-radius: 16px;
  background: var(--soft); border: 1px solid color-mix(in srgb, var(--solid) 16%, transparent); color: var(--ink); text-decoration: none;
  box-shadow: 0 1px 2px rgba(16, 40, 32, .04); transition: box-shadow .12s ease, border-color .12s ease, transform .12s ease; }
.sec-row:hover { text-decoration: none; border-color: color-mix(in srgb, var(--solid) 40%, transparent); box-shadow: 0 4px 14px rgba(16, 40, 32, .08); }
.sec-row:active { transform: scale(.99); }
.sec-row-icon { width: 44px; height: 44px; flex-shrink: 0; display: grid; place-items: center; border-radius: 50%;
  background: var(--solid); color: #fff; }
.sec-row-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.sec-row-title { font-weight: 600; font-size: 16px; line-height: 1.3; }
.sec-row-desc { font-size: var(--fs-sm); color: var(--ink-2); }
.sec-row-badge { position: static; flex-shrink: 0; }
.sec-row-chev { flex-shrink: 0; color: var(--ink-2); display: grid; }

/* ---------- Template Explore ---------- */
.explore-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.explore-head h1 { margin: 0; }
.write-note { margin: -8px 0 16px; font-size: var(--fs-sm); color: var(--ink-2); }
th.row-actions, td.row-actions { width: 1%; white-space: nowrap; text-align: right; }

/* ---------- Template Editor: form ---------- */
.ed-form { margin-top: 4px; }
/* Trường type: 'choice': hiện hết các lựa chọn thành nút, chọn một */
.choice-field { min-width: 0; margin: 0; padding: 0; border: 0; font-size: var(--fs-sm); font-weight: 500; color: var(--ink-2); }
.choice-field legend { padding: 0; margin-bottom: 6px; }
.choice-group { display: flex; flex-wrap: wrap; gap: 8px; }
.choice { display: block; position: relative; }
.choice input, .ed-form.is-view .choice input:disabled { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.choice span { display: flex; align-items: center; justify-content: center; min-height: 44px; padding: 8px 16px; text-align: center; font-size: 15px;
  color: var(--ink); background: var(--paper); border: 1px solid var(--line-strong); border-radius: var(--r-sm); }
/* Màu mục đã chọn: theo field.tone (biến --soft / --solid của .tone-*), mặc định màu nhấn */
.choice input:checked + span { font-weight: 600; color: var(--solid, var(--accent)); background: var(--soft, var(--accent-soft)); border-color: var(--solid, var(--accent)); }
.choice input:focus-visible + span { outline: 2px solid var(--solid, var(--accent)); outline-offset: 2px; }
.choice input:disabled, .ed-form.is-view .choice input:disabled { cursor: default; }
.ed-form .req { color: var(--danger); }
/* Ô báo lỗi đầu form: ẩn khi trống, nổi bật khi có lỗi */
.form-alert { min-height: 0; }
.form-alert:empty { display: none; }
.form-alert:not(:empty) { padding: 10px 14px; border-radius: var(--r-sm); background: var(--danger-soft); color: var(--danger);
  font-weight: 500; border: 1px solid color-mix(in srgb, var(--danger) 30%, transparent); }
.form-section { margin: 8px 0 -4px; padding-top: 14px; border-top: 1px solid var(--line); font-size: var(--fs-base); color: var(--ink); }
.field-help { font-size: var(--fs-xs); font-weight: 400; color: var(--ink-3); }
/* Chế độ Xem: ô nhập trông như chữ thường */
.ed-form.is-view input:disabled, .ed-form.is-view select:disabled, .ed-form.is-view textarea:disabled {
  border-color: transparent; background: var(--canvas); color: var(--ink); opacity: 1; -webkit-text-fill-color: var(--ink); }
.ed-form.is-view select:disabled { appearance: none; }
/* Sổ OQC — khối "Kết quả kiểm tra": Chỉ tiêu | Tiêu chuẩn | Thực tế */
.oqc-tests .field-help { margin: 6px 0 0; }
.oqc-grid { margin-top: 8px; max-width: 760px; }
.oqc-row { display: grid; grid-template-columns: minmax(150px, 1.1fr) minmax(110px, 1fr) minmax(130px, 1fr); gap: 12px;
  align-items: center; padding: 6px 0; border-bottom: 1px solid var(--line); }
.oqc-head { font-size: var(--fs-sm); color: var(--ink-2); padding: 0 0 6px; }
.oqc-group { margin: 14px 0 2px; font-size: var(--fs-sm); font-weight: 600; color: var(--accent); }
.oqc-row label.oqc-name { display: block; font-size: var(--fs-base); font-weight: 400; color: var(--ink); }
.oqc-tc { color: var(--ink-2); font-variant-numeric: tabular-nums; }
.oqc-val input[type=text] { width: 100%; }
.oqc-val input.num-input { text-align: right; }
.oqc-val input[type=checkbox] { width: 20px; height: 20px; }
/* Thông số máy tạo hạt — ô Thực tế dạng "tích + ghi chú" (Độ dày lưới, Nước làm mát, Máng nước, Hút chân không) */
.oqc-val.ts-ct { display: flex; align-items: center; gap: 10px; }
.oqc-val.ts-ct input[type=checkbox] { flex: none; }
@media (max-width: 768px) {
  .oqc-head { display: none; }
  .oqc-row { grid-template-columns: 1fr 1fr; gap: 4px 12px; padding: 8px 0; }
  .oqc-row label.oqc-name { grid-column: 1 / -1; font-weight: 500; }
  .oqc-tc:not(:empty)::before { content: 'Tiêu chuẩn: '; color: var(--ink-3); }
}
.ed-form input:disabled { cursor: default; }
.ed-form:not(.is-view) input:disabled { background: var(--canvas); color: var(--ink-2); }
/* Ô chọn lookup (B00Lookup) */
.lookup { position: relative; display: block; }
.lookup-list { position: absolute; z-index: 30; left: 0; right: 0; top: calc(100% + 4px); max-height: 300px; overflow-y: auto;
  margin: 0; padding: 4px; list-style: none; background: var(--paper); border: 1px solid var(--line-strong); border-radius: var(--r-sm);
  box-shadow: 0 10px 28px rgba(16, 40, 32, .14); }
.lookup-list li { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 8px; min-height: 44px; padding: 8px 10px;
  border-radius: 6px; cursor: pointer; color: var(--ink); font-weight: 400; }
.lookup-list li b { font-weight: 600; }
.lookup-list li small { flex-basis: 100%; color: var(--ink-2); font-size: var(--fs-xs); }
.lookup-list li[aria-selected="true"], .lookup-list li:hover { background: var(--row-hover); }
.lookup-list .lookup-empty { cursor: default; color: var(--ink-2); }
.lookup-list .lookup-empty:hover { background: none; }

.mode-note { margin: 10px 0 0; padding: 8px 12px; border-radius: var(--r-sm); background: var(--warn-soft); color: var(--warn); font-size: var(--fs-sm); }

/* ---------- Màn hình Editor ---------- */
.editor-head { margin-bottom: 20px; }
.editor-title { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 16px; }
.editor-title h1 { margin: 0; }
.editor-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.badge.readonly { background: var(--canvas); color: var(--ink-2); border: 1px dashed var(--line-strong); padding: 3px 10px; }

/* Tiêu đề nhóm con (Chung, Kinh doanh, Mua hàng…) */
.nav-group { margin: 6px 0 0 4px; font-size: var(--fs-xs); font-weight: 600; color: var(--ink-3); }
.nav-group:first-child { margin-top: 0; }
.sec-group h2 { margin: 18px 0 2px 2px; font-size: var(--fs-base); color: var(--ink-2); }
.sec-group:first-child h2 { margin-top: 0; }

.bottom-nav { display: none; }

/* Vuốt xuống để tải lại (chế độ app) */
.ptr { position: fixed; left: 50%; top: calc(env(safe-area-inset-top) + 8px); z-index: 25; display: flex; align-items: center; gap: 8px;
  padding: 8px 14px; font-size: var(--fs-sm); font-weight: 500; white-space: nowrap; color: var(--ink-2); background: var(--paper);
  border: 1px solid var(--line); border-radius: 999px; transform: translate(-50%, -52px); pointer-events: none; }
.ptr[hidden] { display: none; }
html.is-standalone, html.is-standalone body { overscroll-behavior-y: none; } /* không nảy trang chồng lên thao tác kéo */
.ptr, .ptr-pulling { will-change: transform; }
.ptr-pulling .topbar { background: var(--paper); backdrop-filter: none; -webkit-backdrop-filter: none; } /* làm mờ nền rất nặng khi cả trang đang di chuyển */
.ptr.ready { color: var(--accent); border-color: var(--accent); }
.ptr-spin { width: 16px; height: 16px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; }
.ptr.loading .ptr-spin { animation: ptr-spin .8s linear infinite; }
@keyframes ptr-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .ptr.loading .ptr-spin { animation: none; } }

@media (max-width: 1100px) {
  .grid-2 { grid-template-columns: 1fr; gap: 16px; }
  .content { padding: 28px 28px 40px; }
}

/* =====================================================================
   ĐIỆN THOẠI / MÁY TÍNH BẢNG NHỎ
   ===================================================================== */
@media (max-width: 768px) {
  /* 16px để iOS không tự phóng to khi chạm ô nhập */
  input, select, textarea, .btn { font-size: 16px; }
  .btn { min-height: 44px; padding: 10px 16px; }
  .btn.sm { min-height: 44px; font-size: 14px; }
  h1 { font-size: 22px; margin-bottom: 16px; }
  /* Vùng bấm tối thiểu 44px cho link/nút dạng chữ */
  .back { display: inline-flex; align-items: center; min-height: 44px; margin-bottom: 4px; }
  .note-head .actions .link { min-height: 44px; padding: 0 4px; }
  .avatar { width: 44px; height: 44px; }

  .layout { display: block; }

  /* Thanh trên cùng: trắng, kẻ mảnh */
  .topbar { display: flex; align-items: center; gap: 4px; position: sticky; top: 0; z-index: 20; height: calc(56px + env(safe-area-inset-top));
    padding: 0 12px 0 4px; padding-top: env(safe-area-inset-top); background: rgba(255,255,255,.94);
    backdrop-filter: saturate(1.4) blur(8px); -webkit-backdrop-filter: saturate(1.4) blur(8px); border-bottom: 1px solid var(--line); }
  .menu-btn { width: 44px; height: 44px; flex-shrink: 0; display: grid; place-items: center; border: none; background: none;
    color: var(--ink); border-radius: var(--r-sm); cursor: pointer; }
  .menu-btn:active { background: var(--canvas); }
  .topbar-title { flex: 1; min-width: 0; font-size: var(--fs-md); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  /* Tiêu đề đã hiện trên thanh trên cùng → ẩn khỏi màn hình nhưng giữ cho trình đọc màn hình */
  #view > h1:first-child { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  #view > h1:first-child + .page-sub, #view > h1:first-child + .section-back + .page-sub { margin-top: 0; margin-bottom: 16px; }
  /* Explore trên điện thoại: tiêu đề đã có ở thanh trên cùng → trái là link quay lại nhóm, phải là nút "+ Thêm" */
  .explore-head { justify-content: space-between; margin-bottom: 12px; }
  /* Nút quay lại nhóm: cùng cỡ nút "+ Thêm", viền + nền nhạt để nút Thêm vẫn là nút chính */
  .section-back { justify-content: center; gap: 6px; min-height: 44px; padding: 10px 16px; margin-bottom: 12px; font-size: 16px; font-weight: 600;
    color: var(--accent); background: var(--accent-soft); border: 1px solid var(--accent); border-radius: var(--r-sm); }
  .section-back:hover { text-decoration: none; }
  .explore-head .section-back { margin-bottom: 0; }
  .explore-head h1 { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .table-wrap td.row-actions { width: auto; padding: 8px 0 0; text-align: right; }
  .table-wrap td.row-actions::before { display: none; }
  .editor-actions { width: 100%; }
  .editor-actions .btn { flex: 1; }
  .editor-actions .badge.readonly { flex-basis: 100%; text-align: center; }

  /* Sidebar → menu trượt từ trái */
  .sidebar { position: fixed; top: 0; left: 0; bottom: 0; z-index: 40; width: min(86vw, 320px); height: 100dvh; border-right: none;
    transform: translateX(-100%); padding-top: env(safe-area-inset-top); padding-bottom: var(--safe-b);
    /* visibility: hidden khi đóng → phím Tab không lọt vào menu đang ẩn */
    visibility: hidden; transition: transform .22s ease, visibility 0s linear .22s; }
  .layout.drawer-open .sidebar { transform: none; visibility: visible; transition: transform .22s ease;
    box-shadow: 12px 0 40px rgba(16, 24, 20, .16); }
  .layout.drawer-open .drawer-backdrop { display: block; position: fixed; inset: 0; z-index: 30; background: rgba(24, 32, 28, .3); }
  .nav-sec { padding: 12px; font-size: 14px; }
  .nav-sub a, .nav-home { padding: 8px 12px; min-height: 48px; font-size: 16px; }
  .user-box { padding: 16px 24px; }

  .content { padding: 16px 16px calc(var(--safe-b) + 32px); }

  /* Thanh lọc */
  .toolbar { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 14px; margin-bottom: 16px; }
  .toolbar > * { width: auto !important; min-width: 0; }
  /* Ô ngày trên iPhone có độ rộng cố định riêng → tràn / dính nhau; ép co theo cột và căn trái */
  .toolbar input[type=date] { display: block; width: 100%; min-width: 0; max-width: 100%; -webkit-appearance: none; appearance: none;
    padding: 9px 10px; text-align: left; }
  .toolbar input[type=date]::-webkit-date-and-time-value { text-align: left; }
  .toolbar input[type=search], .toolbar > .btn { grid-column: 1 / -1; }

  .form-grid { grid-template-columns: 1fr; }
  .choice-group { display: grid; grid-template-columns: 1fr 1fr; }
  .form-actions { position: sticky; bottom: 0; padding: 12px 0 4px; background: var(--paper); }
  .form-actions .btn { flex: 1; }

  /* Doanh thu */
  .hero { margin: 4px 0 20px; }
  .hero-value { font-size: 36px; }
  .stats { margin-bottom: 28px; }
  .stats > div { flex: 1 1 50%; padding: 12px 0 12px 16px; }
  .stats > div:nth-child(odd) { border-left: none; padding-left: 0; }
  .stats > div:nth-child(n+3) { border-top: 1px solid var(--line); }
  .stats dd { font-size: var(--fs-md); }
  .stats dd a { display: inline-flex; align-items: center; min-height: 44px; margin: -6px 0; }
  .chart-box { height: 230px; }
  .section { margin-bottom: 32px; }
  .panel { padding: 16px; }

  .info-grid { grid-template-columns: 1fr; gap: 0; }
  .info-grid dt { margin-top: 12px; }
  .info-grid dt:first-child { margin-top: 0; }

  /* ---- Bảng → danh sách dòng (kiểu iOS) ---- */
  .table-wrap { overflow: visible; border-top: 1px solid var(--line); }
  .table-wrap table, .table-wrap tbody, .table-wrap tr, .table-wrap td, .table-wrap tbody th { display: block; width: 100%; }
  .table-wrap thead { display: none; }
  .table-wrap tbody tr { padding: 14px 12px; border-bottom: 1px solid var(--line); }
  .table-wrap tbody tr.clickable { position: relative; padding-right: 32px; }
  .table-wrap tbody tr.clickable::after { content: '›'; position: absolute; right: 12px; top: 50%; transform: translateY(-50%);
    font-size: 22px; color: var(--ink-3); }
  .table-wrap tbody tr.clickable:active { background: var(--row-hover); }
  .table-wrap td, .table-wrap tbody th { position: relative; min-height: 24px; padding: 2px 0 2px 40%; border: none;
    text-align: right; white-space: normal; word-break: break-word; font-size: 14px; }
  .table-wrap td::before, .table-wrap tbody th[data-label]::before { content: attr(data-label); position: absolute; left: 0; top: 2px;
    width: 38%; text-align: left; color: var(--ink-3); font-size: 13px; font-weight: 400; }
  .table-wrap td:empty, .table-wrap tbody th:empty { display: none; }
  /* Ô đầu tiên = tiêu đề dòng */
  .table-wrap td:first-child { padding: 0 0 4px; text-align: left; font-size: 16px; font-weight: 600; white-space: normal; }
  .table-wrap td:first-child::before { display: none; }
  /* Dòng tổng cộng */
  .table-wrap tbody tr:has(> th) { background: var(--canvas); padding: 12px; border-radius: var(--r-sm); margin-top: 8px; border-bottom: none; }
  .table-wrap tbody th { padding-left: 0; text-align: left; }
  .table-wrap tbody th.num { text-align: right; font-size: 16px; }
  .table-wrap td.empty { padding: 28px 0; text-align: center; font-size: 15px; font-weight: 400; }
  .table-wrap td.empty::before { display: none; }
  .pager { padding: 12px 0; }
  .pager .muted { flex-basis: 100%; text-align: center; margin: 0 0 4px; }
  .pager .btn { flex: 1; }

  .note-head .actions { margin-left: 0; width: 100%; justify-content: flex-end; gap: 20px; }

  /* Hộp thoại toàn màn hình */
  dialog { width: 100vw; max-width: 100vw; height: 100dvh; max-height: 100dvh; margin: 0; padding: 0 16px calc(16px + var(--safe-b)); border-radius: 0; }
  dialog[open] { display: flex; flex-direction: column; }
  .modal-head { position: sticky; top: 0; z-index: 2; margin: 0 -16px 16px; padding: 14px 16px; padding-top: max(14px, env(safe-area-inset-top));
    background: var(--paper); border-bottom: 1px solid var(--line); }
  .modal-head h2 { font-size: var(--fs-md); }

  .placeholder { padding: 40px 16px; }
  .account-actions .btn { flex: 1; }

  /* ---- Menu đáy ---- */
  :root { --bnav-h: 64px; }
  .bottom-nav:not([hidden]) { display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 25;
    height: calc(var(--bnav-h) + var(--safe-b)); padding-bottom: var(--safe-b);
    background: rgba(255,255,255,.96); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); border-top: 1px solid var(--line); }
  .bottom-nav a, .bottom-nav button { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
    border: none; background: none; font: inherit; font-size: 12px; font-weight: 500; color: var(--ink-2); text-decoration: none; cursor: pointer; }
  .bottom-nav a:active, .bottom-nav button:active { background: var(--canvas); }
  .bottom-nav a.active { color: var(--accent); font-weight: 700; }
  .content { padding-bottom: calc(var(--bnav-h) + var(--safe-b) + 24px); }
  .toast { left: 16px; right: 16px; bottom: calc(var(--bnav-h) + var(--safe-b) + 12px); text-align: center; }

  /* ---- Trang chủ trên điện thoại: header tràn viền, ẩn thanh trên cùng ---- */
  .layout.is-home .topbar { display: none; }
  .home-hero { margin: -16px -16px 48px; padding: 8px 20px 52px; padding-top: calc(8px + env(safe-area-inset-top));
    border-radius: 0 0 28px 28px; }
  .hero-bar { display: flex; align-items: center; gap: 8px; margin: 0 -8px 14px; }
  .hero-icon-btn { width: 44px; height: 44px; display: grid; place-items: center; border: none; border-radius: 12px;
    background: none; color: #fff; cursor: pointer; }
  .hero-icon-btn:active { background: rgba(255,255,255,.15); }
  .hero-brand { flex: 1; display: flex; align-items: center; }
  /* Logo xám/cam trên nền chuyển màu xanh → đặt trên ô trắng bo góc cho rõ */
  .hero-brand img { display: block; height: 38px; width: auto; padding: 4px 10px; border-radius: 10px; background: rgba(255,255,255,.96); }
  .hero-avatar { width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; background: rgba(255,255,255,.95);
    color: var(--accent); font-weight: 700; text-decoration: none; border: 2px solid rgba(255,255,255,.6); }
  .hero-hello { font-size: 22px; }
  .hero-date { font-size: 14px; }
  .home-search { left: 16px; right: 16px; height: 54px; }
  .search-results { margin: -32px 0 24px; }
  .qa-group { margin-bottom: 24px; }
  .qa-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
  .qa-tile { min-height: 128px; padding: 12px 10px 12px; border-radius: 16px; }
  .qa-icon { width: 42px; height: 42px; margin-bottom: 8px; }
  .qa-icon svg { width: 20px; height: 20px; }
  .qa-title { font-size: 14px; padding-right: 0; }
  .qa-desc { font-size: 12px; padding-right: 10px; }
  .qa-chev { right: 6px; bottom: 10px; }
  .qa-badge { top: 8px; right: 8px; padding: 1px 7px; font-size: 11px; }
}
@media (max-width: 359px) {
  .qa-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* ---------- Đầu phiếu gọn 4 cột (formHtml opts.columns = 4) ---------- */
.form-grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px 16px; }
.form-grid .span-2 { grid-column: span 2; }
.form-grid.cols-4 label.inline { align-self: end; min-height: 40px; }
/* Trang chứng từ có lưới chi tiết: dùng hết chiều rộng màn hình cho lưới */
.content:has(.grid-editor) { max-width: none; }

/* ---------- Lưới chi tiết chứng từ (gridHtml) ---------- */
.grid-editor { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.grid-editor > .btn[data-add] { align-self: flex-start; }
.grid-wrap { position: relative; overflow-x: auto; border: 1px solid var(--line); border-radius: var(--r-sm); }
.grid-table th, .grid-table td { padding: 6px 8px; vertical-align: middle; }
.grid-table td.g-no, .grid-table th.g-no { width: 36px; color: var(--ink-2); text-align: right; }
.grid-table td.g-act { width: 1%; white-space: nowrap; }
.grid-table input { padding: 6px 8px; min-width: 0; }
.grid-table td.num input { text-align: right; font-variant-numeric: tabular-nums; }
/* Danh sách lookup trong lưới: nổi trên mọi thứ (vị trí do JS đặt), mục gọn để thấy 6–8 dòng */
.lookup-list.floating { position: fixed; z-index: 120; right: auto; max-height: 420px; }
.lookup-list.floating li { min-height: 40px; padding: 6px 12px; gap: 0 10px; }
.lookup-list.floating li small { line-height: 1.35; }
.grid-table .req { color: var(--danger); }
.grid-table td.g-check { text-align: center; }
.grid-table td.g-check input { width: 20px; height: 20px; accent-color: var(--accent); }
/* Thẻ thu gọn (gridHtml opts.summary) — chỉ dùng trên điện thoại; máy tính ẩn ô tóm tắt / nút Xong */
.grid-table td.g-card-sum, .grid-table td.g-card-done, .g-card-help { display: none; }
.grid-actions { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; }
.ed-form.is-view .grid-table td { padding: 10px 8px; }
.grid-totals { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px 28px; padding-top: 4px; color: var(--ink-2); }
.grid-totals b { margin-left: 6px; color: var(--ink); font-variant-numeric: tabular-nums; }
.list-sum { margin: 0; padding: 10px 12px 0; text-align: right; font-size: var(--fs-sm); color: var(--ink-2); }
.list-sum b { color: var(--ink); font-variant-numeric: tabular-nums; }
/* Ô chọn nhiều: dấu tích trước mỗi mục */
.lookup-list li.multi { padding-left: 36px; position: relative; }
.lookup-list li.multi::before { content: ''; position: absolute; left: 10px; top: 12px; width: 16px; height: 16px;
  border: 1px solid var(--line-strong); border-radius: 4px; background: var(--paper); }
.lookup-list li.multi.is-on::before { content: '✓'; color: #fff; background: var(--accent); border-color: var(--accent);
  font-size: 12px; line-height: 15px; text-align: center; font-weight: 700; }
.lookup-list li.multi[aria-selected="true"] { background: none; }
.lookup-list li.is-active, .lookup-list li.multi.is-active { background: var(--row-hover); }

@media (max-width: 1100px) {
  .form-grid.cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 768px) {
  .form-grid.cols-4 { grid-template-columns: 1fr; }
  .form-grid .span-2 { grid-column: auto; }

  /* Mỗi dòng chi tiết thành một thẻ: thanh tiêu đề "Dòng n" + nút Xóa, nhãn (nhỏ, đậm, xám) tách khỏi giá trị */
  .grid-wrap { overflow: visible; border: none; }
  .grid-table, .grid-table tbody, .grid-table tr, .grid-table td { display: block; width: 100%; }
  .grid-table thead { display: none; }
  .grid-table tbody tr { position: relative; padding: 0 12px 12px; margin-bottom: 14px; border: 1px solid var(--line-strong);
    border-radius: var(--r-md); background: var(--paper); overflow: visible; }
  .grid-table tbody tr:nth-child(even) { background: var(--paper); }
  .grid-table td { border: none; padding: 10px 0 0; }
  .grid-table td::before { content: attr(data-label); display: block; margin-bottom: 4px; font-size: var(--fs-xs);
    font-weight: 600; letter-spacing: .01em; color: var(--ink-2); }
  /* Thanh tiêu đề thẻ */
  .grid-table td.g-no { margin: 0 -12px; width: calc(100% + 24px); padding: 10px 12px; min-height: 48px; text-align: left;
    font-size: var(--fs-base); font-weight: 700; color: var(--accent); background: var(--accent-soft);
    border-bottom: 1px solid var(--line); border-radius: var(--r-md) var(--r-md) 0 0; }
  .grid-table td.g-no::before { content: 'Dòng'; display: inline; margin: 0 6px 0 0; font-size: inherit; font-weight: inherit; color: inherit; }
  .grid-table td.g-act { position: absolute; top: 2px; right: 8px; width: auto; padding: 0; }
  .grid-table td.g-act::before { display: none; }
  .grid-table td.g-act .btn { min-height: 44px; border: none; background: none; color: var(--danger); font-weight: 600; }
  .grid-table td.num, .grid-table td.num input { text-align: left; }
  .grid-table input { padding: 10px 12px; font-size: 16px; background: var(--paper); }
  .lookup-list.floating li { min-height: 44px; }
  /* Bấm vào ô tìm: ô được cuộn lên ngay dưới thanh tiêu đề; khi đang tìm thì thêm khoảng trống cuối trang
     để cả ô ở cuối phiếu cũng cuộn lên được (danh sách hiện bên dưới, không bị bàn phím che) */
  .lookup-input { scroll-margin-top: 80px; }
  .content:has(.lookup-input:focus) { padding-bottom: 70vh; }
  /* Chế độ Xem: nhãn trái, giá trị phải đậm, kẻ ngăn từng dòng */
  .ed-form.is-view .grid-table td:not(.g-no) { display: flex; justify-content: space-between; align-items: baseline; gap: 12px;
    padding: 8px 0; border-bottom: 1px solid var(--line); font-size: var(--fs-base); font-weight: 500; color: var(--ink); text-align: right; }
  .ed-form.is-view .grid-table td:not(.g-no)::before { flex: 0 0 42%; margin: 0; text-align: left; font-weight: 500; font-size: var(--fs-sm); }
  .ed-form.is-view .grid-table td:last-child { border-bottom: none; }
  .ed-form.is-view .grid-table td:not(.g-no):empty { display: none; }
  .grid-totals { flex-direction: column; align-items: flex-end; }
  .grid-table td.g-check { text-align: left; }
  .grid-table td.g-check input { width: 24px; height: 24px; }

  /* Thẻ thu gọn: tiêu đề "Dòng n" → tóm tắt vài cột; bấm để mở đủ ô, nút "Xong" thu lại */
  .g-card-help { display: block; margin: 0; }
  .has-cards .grid-table tbody tr { display: flex; flex-direction: column; scroll-margin-top: 72px; }
  .has-cards .grid-table td.g-no { order: -2; }
  .has-cards .grid-table td.g-card-sum { order: -1; display: block; padding: 0; border-bottom: none; }
  /* chế độ Xem: bỏ kẻ ngăn / căn phải của ô thường (.ed-form.is-view … td) cho ô tóm tắt */
  .ed-form .has-cards .grid-table td.g-card-sum { padding: 0 0 12px; border-bottom: none; text-align: left; }
  .has-cards .grid-table td.g-card-sum::before, .has-cards .grid-table td.g-card-done::before { display: none; }
  .has-cards .grid-table tr:not(.g-collapsed) td.g-card-sum { display: none; }
  .has-cards .grid-table tr.g-collapsed td:not(.g-no):not(.g-act):not(.g-card-sum) { display: none; }
  .has-cards .grid-table td.g-card-done { display: flex; justify-content: flex-end; padding-top: 12px; border-bottom: none; }
  .has-cards .grid-table td.g-card-done .btn { min-width: 120px; min-height: 44px; }
  .g-sum { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px 16px; width: 100%; padding: 12px 0 0;
    border: none; background: none; text-align: left; font: inherit; color: inherit; cursor: pointer; }
  .g-sum-item { display: flex; flex-direction: column; min-width: 0; }
  .g-sum-item small { font-size: var(--fs-xs); font-weight: 600; color: var(--ink-2); }
  .g-sum-item b { font-weight: 600; overflow-wrap: anywhere; }
  .g-sum:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; border-radius: var(--r-sm); }
}

/* ======================= Kiểm kê vật tư ======================= */
.kk-entry, .kk-lines { margin-top: 16px; }
.kk-line-edit.grid-wrap { overflow: visible; border: none; border-radius: 0; }
.kk-edit-title { margin: 0; font-size: var(--fs-base); }
.table-wrap td.kk-edit-cell { padding: 14px 12px; background: var(--accent-soft); font-size: var(--fs-base); font-weight: 400; white-space: normal; }
.kk-title { margin: 0 0 12px; font-size: var(--fs-md); }
.kk-scan { display: flex; gap: 8px; align-items: stretch; }
.kk-scan input { flex: 1; min-width: 0; }
.kk-scan .btn { flex-shrink: 0; display: inline-flex; align-items: center; justify-content: center; width: 128px; min-height: 56px; padding: 0 12px; color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }
.kk-stock output { min-height: 40px; display: flex; align-items: center; font-weight: 600; font-variant-numeric: tabular-nums; }
.kk-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }
.kk-sum { margin: 0 0 10px; color: var(--ink-2); }
.kk-sum b { color: var(--ink); font-variant-numeric: tabular-nums; }
.kk-gap { margin-left: 24px; }
.kk-camera { position: fixed; inset: 0; z-index: 1000; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 16px; padding: 16px; background: var(--paper); }
.kk-camera #kk-camera-view { width: 100%; max-width: 480px; }
@media (max-width: 768px) {
  .kk-actions .btn.primary { flex: 1 1 100%; }
  #kl-form .kk-actions { flex-wrap: nowrap; }
  #kl-form .kk-actions .btn { flex: 1 1 0; min-width: 0; }  /* Cập nhật dòng / Bỏ sửa: chia đôi chiều ngang */
}
/* Phân quyền (Người dùng / Nhóm người dùng) */
.perm-block { margin-top: 8px; }
.perm-block h2 { margin: 0 0 8px; font-size: var(--fs-base); font-weight: 600; color: var(--ink); }
.perm-block > p { margin: 0 0 12px; font-size: var(--fs-sm); }
.perm-table th.perm-cell, .perm-table td.perm-cell { text-align: center; width: 110px; }
.perm-table tbody th { background: var(--canvas); text-align: left; font-weight: 600; }
.tree-name { display: inline-block; padding-left: calc(var(--depth, 0) * 20px); }
.tree-name.is-group { font-weight: 600; }
.perm-check, .perm-all { display: inline-flex; flex-direction: row; align-items: center; justify-content: center; gap: 6px; }
.perm-all { font-size: var(--fs-xs); white-space: nowrap; }
.perm-from { display: block; font-size: var(--fs-xs); color: var(--danger); white-space: nowrap; }
.perm-table th.perm-scope, .perm-table td.perm-scope { width: 130px; }
.perm-scope select { width: 100%; min-height: 36px; }
.perm-scope .muted { font-size: var(--fs-xs); }
.table-wrap.perm-table tbody tr:nth-child(even) { background: transparent; }
@media (max-width: 768px) {
  .tree-name { padding-left: calc(var(--depth, 0) * 10px); }
  .perm-table th.perm-cell, .perm-table td.perm-cell { width: 100%; }
  .perm-table td.perm-cell { display: flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 0 0 40%; text-align: left; }
  .perm-table td.perm-cell::before { top: 50%; transform: translateY(-50%); }
  .perm-check { min-width: 44px; min-height: 44px; justify-content: flex-start; }
  .perm-from { display: inline; }
  .perm-table th.perm-scope, .perm-table td.perm-scope { width: 100%; }
  .perm-table td.perm-scope { flex-wrap: wrap; row-gap: 0; padding-top: 4px; padding-bottom: 4px; }
  .perm-scope select { width: auto; min-width: 140px; min-height: 44px; font-size: 16px; }
  .perm-scope .perm-from { flex-basis: 100%; }
}