:root {
    /* Màu nhận diện TCMS */
    --pri: #e31b23; --pri-d: #b8141b; --pri-l: #fdecec; --bg: #f5f6f8; --card: #fff; --line: #e1e4e8; --text: #222; --muted: #6c757d;
    --ok: #1f8a4c; --ok-bg: #e5f5ec; --warn: #a86700; --warn-bg: #fff4dc; --err: #c0392b; --err-bg: #fdecea;
}
* { box-sizing: border-box; }
body { margin: 0; font: 14px/1.45 Roboto, "Segoe UI", Arial, sans-serif; background: var(--bg); color: var(--text); }
a { color: var(--pri-d); }
h1 { font-size: 1.2rem; margin: .3rem 0 .9rem; color: var(--pri); font-weight: 600; display: flex; align-items: center; gap: .45rem; }
h1::before { content: ""; width: 4px; height: 1.1em; background: var(--pri); border-radius: 2px; }
h1 small { color: var(--muted); font-weight: 400; }
h2 { font-size: 1.15rem; margin: 0 0 .8rem; }
h3 { font-size: 1rem; margin: .2rem 0 .6rem; }
.muted { color: var(--muted); }
.small, small { font-size: .85em; }
.center { text-align: center; }
.right { text-align: right; margin-top: 1rem; }

/* Thanh trên */
.topbar { background: var(--pri); color: #fff; display: flex; align-items: center; gap: 1rem; padding: 0 1rem; min-height: 52px; flex-wrap: wrap;
          box-shadow: 0 2px 4px rgba(0,0,0,.12); position: sticky; top: 0; z-index: 50; }
.brand { display: flex; align-items: center; gap: .75rem; margin-right: auto; color: #fff; text-decoration: none; padding: .45rem 0; }
.brand-logo { height: 26px; width: auto; display: block; }
.brand-app { font-size: .82rem; font-weight: 500; letter-spacing: .02em; padding-left: .75rem; border-left: 1px solid rgba(255,255,255,.55); white-space: nowrap; }
.topbar nav { display: flex; gap: 0; flex-wrap: wrap; align-self: stretch; }
.topbar nav a { color: #fff; text-decoration: none; padding: 0 .6rem; display: flex; align-items: center; font-size: .86rem; font-weight: 500; white-space: nowrap;
                border-bottom: 3px solid transparent; border-top: 3px solid transparent; }
.topbar nav a:hover { background: rgba(0,0,0,.08); }
.topbar nav a.on { border-bottom-color: #fff; background: rgba(0,0,0,.1); }
.topbar nav a.logout { opacity: .85; }
.topbar nav a.user span { max-width: 140px; overflow: hidden; text-overflow: ellipsis; }
@media (min-width: 761px) and (max-width: 1500px) { .brand-app { display: none; } }
.menu-btn { display: none; background: none; border: 0; color: #fff; font-size: 1.5rem; }
.session-bar { background: #fff; border-bottom: 1px solid var(--line); padding: .4rem 1rem; font-size: .86rem; }
.session-bar b { color: var(--pri-d); }
.session-bar .warn { color: var(--err); }
.wrap { max-width: 1320px; margin: 0 auto; padding: 1rem; }
.foot { text-align: center; color: var(--muted); font-size: .8rem; padding: 1.5rem; }
.login-logo { display: block; width: 210px; max-width: 70%; margin: .5rem auto 1rem; }

/* Khối */
.card { background: var(--card); border: 1px solid var(--line); border-radius: 6px; padding: 1rem; margin-bottom: 1rem; box-shadow: 0 1px 2px rgba(0,0,0,.03); }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: .6rem; flex-wrap: wrap; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: .8rem; margin-bottom: 1rem; }
.stat { background: var(--card); border: 1px solid var(--line); border-top: 3px solid var(--pri); border-radius: 6px; padding: .7rem 1rem; }
.stat span { display: block; color: var(--muted); font-size: .85rem; }
.stat b { font-size: 1.7rem; }
.stat.ok { border-top-color: var(--ok); } .stat.warn { border-top-color: var(--warn); } .stat.err { border-top-color: #6c757d; }
.progress { height: 14px; background: #e6ebf1; border-radius: 8px; overflow: hidden; }
.progress div { height: 100%; background: linear-gradient(90deg, var(--ok), #39b36b); }
.progress-mini { background: var(--card); border: 1px solid var(--line); padding: .3rem .7rem; border-radius: 20px; font-size: .9rem; }

/* Form */
input, select, textarea { font: inherit; padding: .5rem .6rem; border: 1px solid #c8d1db; border-radius: 6px; background: #fff; width: 100%; }
input[type=checkbox], input[type=radio] { width: auto; }
input:focus, select:focus, textarea:focus { outline: 2px solid #f6b9bc; border-color: var(--pri); }
.form label { display: block; margin-bottom: .7rem; font-weight: 500; }
.form label input, .form label select, .form label textarea { margin-top: .25rem; font-weight: normal; }
label.radio { display: flex; align-items: center; gap: .45rem; font-weight: normal; margin: .3rem 0; }
fieldset { border: 1px solid var(--line); border-radius: 8px; margin: 0 0 .8rem; }
.form-inline { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.form-inline > * { flex: 1 1 140px; width: auto; }
.form-inline > .btn { flex: 0 0 auto; }

.btn { display: inline-block; font: inherit; font-weight: 500; padding: .45rem .9rem; border: 1px solid #d0d4d9; background: #eef0f2; color: var(--text); border-radius: 4px; cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { background: #e2e5e8; }
.btn.primary { background: var(--pri); color: #fff; border-color: var(--pri); }
.btn.primary:hover { background: var(--pri-d); }
.btn.primary:disabled { opacity: .5; cursor: not-allowed; }
.btn.danger { color: var(--err); border-color: #e9b4ae; }
.btn.danger:hover { background: var(--err-bg); }
.btn.sm { padding: .25rem .55rem; font-size: .85rem; }
.btn.big { padding: .75rem 1.3rem; font-size: 1.05rem; }
.btn.block { width: 100%; }

/* Bảng */
.table-wrap { overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; background: #fff; }
.tbl th, .tbl td { padding: .45rem .55rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.tbl th { background: #f2f3f5; font-weight: 600; font-size: .84rem; white-space: nowrap; border-bottom: 2px solid #dcdfe3; }
.tbl tbody tr:nth-child(even) td { background: #fafbfc; }
.tbl tbody tr:hover td { background: #fff5f5; }
.tbl .num { text-align: right; white-space: nowrap; }
.tbl tr.total td { font-weight: 700; background: #f6f8fb; }
.tbl tr.hl td { background: #fffaf0; }
.actions { white-space: nowrap; }
.actions form { display: inline; }
.tag { display: inline-block; padding: .1rem .5rem; border-radius: 20px; background: #eef1f5; color: var(--muted); font-size: .8rem; white-space: nowrap; }
.tag.ok { background: var(--ok-bg); color: var(--ok); }
.tag.warn { background: var(--warn-bg); color: var(--warn); }
.tag.err { background: var(--err-bg); color: var(--err); }
.chips-sum { display: flex; gap: .4rem; flex-wrap: wrap; margin-bottom: .8rem; }
.tabs { display: flex; gap: .3rem; flex-wrap: wrap; margin-bottom: -1px; }
.tabs a { padding: .5rem .9rem; border: 1px solid var(--line); border-bottom: 0; border-radius: 4px 4px 0 0; background: #eef0f2; text-decoration: none; color: var(--text); }
.tabs a.on { background: #fff; font-weight: 600; color: var(--pri); border-top: 2px solid var(--pri); }
.pager { display: flex; gap: .25rem; justify-content: center; margin: 1rem 0; flex-wrap: wrap; }
.pager a, .pager span { padding: .3rem .65rem; border: 1px solid var(--line); border-radius: 6px; background: #fff; text-decoration: none; }
.pager a.on { background: var(--pri); color: #fff; }

.alert { padding: .7rem 1rem; border-radius: 8px; margin-bottom: 1rem; background: var(--ok-bg); color: var(--ok); border: 1px solid #bfe3cd; }
.alert.err { background: var(--err-bg); color: var(--err); border-color: #f3c3bd; }
.alert.warn { background: var(--warn-bg); color: var(--warn); border-color: #f1d9a3; }

/* Đăng nhập */
.login-page { display: grid; place-items: center; min-height: 100vh; }
.login-card { width: min(380px, 92vw); }
.login-card h1 { text-align: center; margin: .3rem 0 0; }
.login-card p { text-align: center; font-size: .8rem; }
.login-card label { display: block; margin: .7rem 0; }

/* Quét */
.scan-page { max-width: 640px; margin: 0 auto; }
#reader { position: relative; border-radius: 8px; overflow: hidden; }
#reader.live { background: #111; }
#reader video { width: 100%; display: block; max-height: 60vh; object-fit: cover; }
.aim { position: absolute; inset: 15%; border: 3px solid rgba(255,255,255,.85); border-radius: 12px; box-shadow: 0 0 0 9999px rgba(0,0,0,.25); pointer-events: none; }
.aim { display: none; }
#reader.live .aim { display: block; }
#reader video { display: none; }
#reader.live video { display: block; }
.scan-ctl { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; margin: .7rem 0; }
.scan-ctl select { width: auto; flex: 1; }
#result { border-width: 2px; border-color: var(--pri); }
#result.unknown { border-color: var(--err); }
.res-head { display: flex; justify-content: space-between; gap: .5rem; align-items: start; }
.res-code { font-size: 1.4rem; font-weight: 700; }
.res-name { font-size: 1.05rem; }
.res-info { display: grid; grid-template-columns: max-content 1fr; gap: .2rem .8rem; margin: .8rem 0; }
.res-info dt { color: var(--muted); }
.res-info dd { margin: 0; }
.res-prev { color: var(--warn); margin-bottom: .6rem; }
.chips { display: flex; flex-wrap: wrap; gap: .4rem; margin-bottom: .8rem; }
.chip { margin: 0 !important; }
.chip input { display: none; }
.chip span { display: inline-block; padding: .45rem .75rem; border: 1px solid #c8d1db; border-radius: 20px; cursor: pointer; font-weight: normal; }
.chip input:checked + span { background: var(--pri); color: #fff; border-color: var(--pri); }
.toast { position: fixed; left: 50%; bottom: 20px; transform: translate(-50%, 150%); background: #222; color: #fff; padding: .7rem 1.1rem; border-radius: 8px; transition: transform .25s; z-index: 99; max-width: 92vw; }
.toast.show { transform: translate(-50%, 0); }
.toast.ok { background: var(--ok); } .toast.err { background: var(--err); }
.qr-box svg { width: 180px; height: 180px; }

/* Tem QR */
.labels { display: grid; gap: 3mm; }
.labels.size-s { grid-template-columns: repeat(4, 1fr); }
.labels.size-m { grid-template-columns: repeat(3, 1fr); }
.labels.size-l { grid-template-columns: repeat(2, 1fr); }
.label { display: flex; gap: 2mm; align-items: center; border: 1px dashed #999; padding: 2mm; background: #fff; break-inside: avoid; page-break-inside: avoid; overflow: hidden; }
.label .qr { flex: 0 0 auto; }
.label .qr svg { display: block; width: 100%; height: 100%; }
.size-s .label { height: 24mm; } .size-s .label .qr { width: 20mm; height: 20mm; }
.size-m .label { height: 30mm; } .size-m .label .qr { width: 26mm; height: 26mm; }
.size-l .label { height: 40mm; } .size-l .label .qr { width: 35mm; height: 35mm; }
.label .info { min-width: 0; font-family: Arial, sans-serif; line-height: 1.2; }
.label .org { font-size: 5.5pt; text-transform: uppercase; color: #333; }
.label .code { font-weight: 700; font-size: 10pt; margin: .5mm 0; }
.label .name { font-size: 7pt; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.label .dept { font-size: 6pt; color: #444; margin-top: .5mm; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.size-s .label .org { font-size: 4.5pt; } .size-s .label .code { font-size: 8pt; } .size-s .label .name { font-size: 6pt; -webkit-line-clamp: 2; }
.size-l .label .org { font-size: 7pt; } .size-l .label .code { font-size: 14pt; } .size-l .label .name { font-size: 9pt; } .size-l .label .dept { font-size: 8pt; }

@media print {
    @page { size: A4; margin: 8mm; }
    body { background: #fff; }
    .no-print { display: none !important; }
    .wrap { padding: 0; max-width: none; }
    .label { border-color: #bbb; }
}

@media (max-width: 760px) {
    .menu-btn { display: block; }
    .topbar nav { display: none; width: 100%; flex-direction: column; }
    .nav-open .topbar nav { display: flex; }
    .brand small { display: none; }
    .grid2 { grid-template-columns: 1fr; }
    .wrap { padding: .6rem; }
    .stat b { font-size: 1.35rem; }
}

/* Bổ sung: biểu mẫu 2 cột, phân quyền, tài sản thanh lý */
.grid-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 0 .8rem; }
.grid-fields .full { grid-column: 1 / -1; }
.form input[readonly], .form textarea[readonly], .form select:disabled { background: #f3f5f8; color: #4a5562; }
.tbl tr.disabled td { color: #8a94a0; background: #fafafa; }
.role-tag { float: right; font-size: .8rem; color: var(--muted); }
.topbar nav a.user { opacity: 1; font-weight: 600; }
.chips-sum .tag b { color: var(--text); }
@media (max-width: 760px) { .grid-fields { grid-template-columns: 1fr; } .role-tag { float: none; display: block; } }

/* Giao diện TCMS: nút chính đỏ, tiêu đề mục đỏ */
.card h2 { color: var(--text); font-size: 1.05rem; }
.alert.err { background: var(--err-bg); }
.progress div { background: linear-gradient(90deg, #1f8a4c, #39b36b); }
.tag.ok { background: #e7f6ed; }
.role-tag { background: var(--pri-l); color: var(--pri-d); padding: 0 .5rem; border-radius: 10px; }
.label .org-logo { height: 3.2mm; width: auto; display: block; margin-bottom: .6mm; }
.size-s .label .org-logo { height: 2.6mm; }
.size-l .label .org-logo { height: 4.5mm; }
@media (max-width: 760px) {
    .topbar { padding: 0 .8rem; }
    .brand-logo { height: 22px; }
    .brand-app { font-size: .75rem; }
    .topbar nav { flex-direction: column; align-self: auto; }
    .topbar nav a { padding: .6rem .5rem; border: 0; border-left: 3px solid transparent; }
    .topbar nav a.on { border-left-color: #fff; }
}
.login-card h1 { justify-content: center; font-size: 1.15rem; }
.login-card h1::before { display: none; }
.tbl td:nth-child(-n+2) small { white-space: nowrap; }
.pager { align-items: center; }
.pager .pager-info { border: 0; background: none; color: var(--muted); font-size: .85rem; padding-left: .6rem; }
[id] { scroll-margin-top: 72px; }

form.inline { display: inline; margin: 0; }
