/* ============ Nền tảng ============ */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; font: 400 var(--fs-md)/1.45 var(--font); color: var(--text); background: var(--bg);
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility; overflow: hidden;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3, h4, p { margin: 0; }
ul { margin: 0; padding: 0; list-style: none; }
a { color: var(--brand-600); }
mark { background: var(--accent-soft); color: inherit; border-radius: 3px; padding: 0 1px; box-shadow: 0 0 0 1px color-mix(in srgb, var(--accent) 45%, transparent); }
:focus-visible { outline: none; box-shadow: var(--focus); border-radius: var(--r-sm); }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--text-3); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip-link { position: absolute; left: -999px; top: 8px; z-index: 999; background: var(--brand-600); color: #fff; padding: 8px 12px; border-radius: var(--r-sm); }
.skip-link:focus { left: 8px; }
[hidden] { display: none !important; }
.ico { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.ico.sm { width: 15px; height: 15px; }
.ico.lg { width: 22px; height: 22px; }
::-webkit-scrollbar { width: 11px; height: 11px; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 8px; border: 3px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background: var(--text-3); background-clip: content-box; border: 3px solid transparent; }
::-webkit-scrollbar-track { background: transparent; }

/* ============ Khung ứng dụng ============ */
.app { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); height: 100vh; height: 100dvh; }
.app.side-collapsed { grid-template-columns: 0 minmax(0, 1fr); }
.app.side-collapsed .sidebar { visibility: hidden; overflow: hidden; }
.main-col { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.main { flex: 1; min-height: 0; overflow: auto; outline: none; position: relative; }
.main.table-page { overflow: hidden; display: flex; flex-direction: column; }
.page { padding: var(--s6) var(--s8) var(--s8); max-width: 1480px; margin: 0 auto; width: 100%; }
.page-head { display: flex; align-items: flex-start; gap: var(--s4); margin-bottom: var(--s5); flex-wrap: wrap; }
.page-head h1 { font-size: var(--fs-2xl); line-height: 1.2; letter-spacing: -.01em; }
.page-head .sub { color: var(--text-2); margin-top: 4px; max-width: 70ch; }
.page-head .actions { margin-left: auto; display: flex; gap: var(--s2); flex-wrap: wrap; }

/* ============ Nút & ô nhập ============ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px; height: 36px; padding: 0 14px;
  border-radius: var(--r-md); border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  font-weight: 560; font-size: var(--fs-md); white-space: nowrap; transition: background var(--t-fast), border-color var(--t-fast), box-shadow var(--t-fast), transform var(--t-fast);
}
.btn:hover { background: var(--surface-3); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--brand-600); border-color: var(--brand-600); color: #fff; box-shadow: var(--sh-1); }
:root[data-theme="dark"] .btn.primary { color: #04141c; }
.btn.primary:hover { background: var(--brand-700); border-color: var(--brand-700); }
:root[data-theme="dark"] .btn.primary:hover { background: var(--brand-500); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-3); }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, var(--border)); }
.btn.danger:hover { background: var(--danger-bg); }
.btn.sm { height: 30px; padding: 0 10px; font-size: var(--fs-sm); border-radius: var(--r-sm); }
.btn.icon { width: 36px; padding: 0; }
.btn.icon.sm { width: 30px; }
.btn[disabled] { opacity: .5; pointer-events: none; }
.icon-btn {
  display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: var(--r-sm); border: 0; background: transparent; color: var(--text-2);
  transition: background var(--t-fast), color var(--t-fast);
}
.icon-btn:hover { background: var(--surface-3); color: var(--text); }
.icon-btn.ok:hover { background: var(--ok-bg); color: var(--ok); }
.icon-btn.warn:hover { background: var(--warn-bg); color: var(--warn); }
.icon-btn.danger:hover { background: var(--danger-bg); color: var(--danger); }

.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field > label, .field > .lbl { font-size: var(--fs-sm); font-weight: 600; color: var(--text-2); }
.field .hint { font-size: var(--fs-xs); color: var(--text-3); }
.input, .select, .textarea {
  width: 100%; height: 36px; padding: 0 11px; border-radius: var(--r-md); border: 1px solid var(--border-strong); background: var(--surface);
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.textarea { height: auto; min-height: 76px; padding: 8px 11px; resize: vertical; line-height: 1.45; }
.input:hover, .select:hover, .textarea:hover { border-color: var(--text-3); }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--brand-500); box-shadow: var(--focus); }
.input[aria-invalid="true"] { border-color: var(--danger); }
.select { appearance: none; padding-right: 30px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2375869a' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; }

.seg { display: inline-flex; padding: 3px; gap: 2px; background: var(--surface-3); border-radius: var(--r-md); }
.seg button { border: 0; background: transparent; padding: 6px 12px; border-radius: 8px; font-size: var(--fs-sm); font-weight: 600; color: var(--text-2); }
.seg button[aria-pressed="true"], .seg button[aria-checked="true"] { background: var(--surface); color: var(--text); box-shadow: var(--sh-1); }

.chip {
  display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 11px; border-radius: var(--r-pill); border: 1px solid var(--border-strong);
  background: var(--surface); font-size: var(--fs-sm); font-weight: 560; color: var(--text-2); white-space: nowrap; transition: all var(--t-fast);
}
.chip:hover { border-color: var(--brand-500); color: var(--text); }
.chip[aria-pressed="true"] { background: var(--brand-50); border-color: var(--brand-500); color: var(--brand-700); }
.chip .count { font-size: var(--fs-xs); background: var(--surface-3); border-radius: var(--r-pill); padding: 0 7px; line-height: 18px; color: var(--text-2); }
.chip[aria-pressed="true"] .count { background: var(--brand-100); color: var(--brand-700); }

.badge { display: inline-flex; align-items: center; gap: 5px; height: 22px; padding: 0 8px; border-radius: var(--r-pill); font-size: var(--fs-xs); font-weight: 650; background: var(--surface-3); color: var(--text-2); white-space: nowrap; }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.danger { background: var(--danger-bg); color: var(--danger); }
.badge.info { background: var(--info-bg); color: var(--info); }
.badge .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }

/* ============ Thanh bên ============ */
.sidebar { background: var(--side-bg); color: var(--side-text); display: flex; flex-direction: column; min-height: 0; z-index: 30; }
.brand { display: flex; align-items: center; gap: 11px; padding: 18px 18px 14px; }
.brand-mark { width: 38px; height: 38px; border-radius: 11px; background: linear-gradient(145deg, #0a8bb8, #07536f); display: grid; place-items: center; box-shadow: inset 0 0 0 1px rgba(255,255,255,.12); flex: none; }
.brand-mark svg { width: 24px; height: 24px; }
.brand h1 { font-size: 15.5px; color: #fff; line-height: 1.15; font-weight: 700; letter-spacing: .01em; }
.brand p { font-size: var(--fs-xs); color: var(--side-text-2); margin-top: 2px; }
.side-scroll { flex: 1; overflow-y: auto; padding: 4px 10px 14px; min-height: 0; }
.side-scroll::-webkit-scrollbar-thumb { background: rgba(255,255,255,.18); background-clip: content-box; }
.nav-item {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 10px; border-radius: 9px; border: 0; background: transparent;
  color: var(--side-text); text-align: left; text-decoration: none; font-size: 13.5px; font-weight: 520; position: relative; transition: background var(--t-fast), color var(--t-fast);
}
.nav-item .ico { opacity: .85; }
.nav-item:hover { background: var(--side-bg-2); color: #fff; }
.nav-item[aria-current="page"] { background: var(--side-active); color: #fff; font-weight: 650; }
.nav-item[aria-current="page"]::before { content: ""; position: absolute; left: -10px; top: 8px; bottom: 8px; width: 4px; border-radius: 0 4px 4px 0; background: var(--accent); }
.nav-item .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-item .cnt { font-size: var(--fs-xs); color: var(--side-text-2); font-variant-numeric: tabular-nums; }
.nav-item[aria-current="page"] .cnt { color: #d9e8f2; }
.nav-item .flag { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); flex: none; }
.nav-head { display: flex; align-items: center; gap: 6px; padding: 16px 10px 6px; font-size: 11px; letter-spacing: .09em; text-transform: uppercase; color: var(--side-text-2); font-weight: 700; }
.nav-head button { margin-left: auto; background: transparent; border: 0; color: var(--side-text-2); display: grid; place-items: center; width: 22px; height: 22px; border-radius: 6px; }
.nav-head button:hover { background: var(--side-bg-2); color: #fff; }
.side-foot { padding: 10px 14px 14px; border-top: 1px solid rgba(255,255,255,.07); display: flex; align-items: center; gap: 8px; font-size: var(--fs-xs); color: var(--side-text-2); }
.side-foot .save-state { display: inline-flex; align-items: center; gap: 6px; flex: 1; min-width: 0; }
.side-foot .dot { width: 8px; height: 8px; border-radius: 50%; background: #3ecf8e; }
.side-foot .dot.busy { background: var(--accent); animation: pulse 1s infinite; }
.side-foot .dot.err { background: #ff6b60; }
.side-foot .icon-btn { color: var(--side-text-2); }
.side-foot .icon-btn:hover { background: var(--side-bg-2); color: #fff; }
@keyframes pulse { 50% { opacity: .35; } }

/* ============ Thanh trên ============ */
.topbar { height: var(--topbar-h); flex: none; display: flex; align-items: center; gap: var(--s3); padding: 0 var(--s6); background: var(--surface); border-bottom: 1px solid var(--border); position: relative; z-index: 20; }
.crumb { display: flex; align-items: center; gap: 8px; min-width: 0; font-size: var(--fs-sm); color: var(--text-3); }
.crumb strong { color: var(--text); font-size: var(--fs-lg); font-weight: 680; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.search { position: relative; flex: 1; max-width: 560px; margin-left: auto; }
.search .ico { position: absolute; left: 12px; top: 9px; color: var(--text-3); pointer-events: none; }
.search input { height: 38px; padding: 0 74px 0 38px; background: var(--surface-3); border: 1px solid transparent; border-radius: var(--r-md); width: 100%; transition: all var(--t-fast); }
.search input:hover { background: var(--surface-2); border-color: var(--border); }
.search input:focus { outline: none; background: var(--surface); border-color: var(--brand-500); box-shadow: var(--focus); }
.search .kbd { position: absolute; right: 10px; top: 8px; display: flex; gap: 4px; pointer-events: none; }
.search .clear { position: absolute; right: 6px; top: 4px; }
kbd { font: 600 11px var(--font-mono); padding: 2px 6px; border-radius: 5px; border: 1px solid var(--border-strong); background: var(--surface); color: var(--text-3); }

/* ============ Tổng quan ============ */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: var(--s3); margin-bottom: var(--s6); }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); padding: var(--s4) var(--s5); box-shadow: var(--sh-1); display: flex; gap: 14px; align-items: center; text-align: left; transition: transform var(--t) var(--ease), box-shadow var(--t); }
button.kpi:hover { transform: translateY(-2px); box-shadow: var(--sh-2); }
.kpi .ic { width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center; background: var(--brand-50); color: var(--brand-600); flex: none; }
.kpi.warn .ic { background: var(--warn-bg); color: var(--warn); }
.kpi.danger .ic { background: var(--danger-bg); color: var(--danger); }
.kpi.ok .ic { background: var(--ok-bg); color: var(--ok); }
.kpi .v { font-size: 26px; font-weight: 720; line-height: 1.05; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.kpi .l { font-size: var(--fs-sm); color: var(--text-2); margin-top: 3px; }
.sec-title { font-size: var(--fs-lg); font-weight: 700; margin: var(--s6) 0 var(--s3); display: flex; align-items: center; gap: 8px; }
.sec-title .badge { font-weight: 600; }
.group-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(262px, 1fr)); gap: var(--s3); }
.gcard { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); padding: var(--s4); text-align: left; display: flex; flex-direction: column; gap: 10px; box-shadow: var(--sh-1); transition: transform var(--t) var(--ease), box-shadow var(--t), border-color var(--t); text-decoration: none; color: inherit; }
.gcard:hover { transform: translateY(-2px); box-shadow: var(--sh-2); border-color: var(--brand-300); }
.gcard .top { display: flex; gap: 11px; align-items: center; }
.gcard .ic { width: 38px; height: 38px; border-radius: 11px; background: var(--accent-soft); color: #8a6500; display: grid; place-items: center; flex: none; }
:root[data-theme="dark"] .gcard .ic { color: var(--accent); }
.gcard h3 { font-size: 14.5px; line-height: 1.25; font-weight: 650; }
.gcard .sec { font-size: var(--fs-xs); color: var(--text-3); }
.gcard .stats { display: flex; gap: 14px; font-size: var(--fs-sm); color: var(--text-2); flex-wrap: wrap; }
.gcard .stats b { color: var(--text); font-variant-numeric: tabular-nums; }
.meter { height: 6px; background: var(--surface-3); border-radius: 6px; overflow: hidden; }
.meter > i { display: block; height: 100%; background: var(--brand-500); border-radius: 6px; transition: width var(--t) var(--ease); }
.meter-l { display: flex; justify-content: space-between; font-size: var(--fs-xs); color: var(--text-3); margin-top: 4px; }
.two-col { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s4); }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--sh-1); overflow: hidden; }
.panel > h3 { font-size: var(--fs-md); padding: 14px 16px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 8px; }
.list-row { display: flex; gap: 12px; align-items: center; padding: 10px 16px; border-bottom: 1px solid var(--border); width: 100%; background: transparent; border-left: 0; border-right: 0; border-top: 0; text-align: left; }
.list-row:last-child { border-bottom: 0; }
button.list-row:hover { background: var(--surface-2); }
.list-row .t { flex: 1; min-width: 0; }
.list-row .t b { display: block; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-row .t span { font-size: var(--fs-xs); color: var(--text-3); }

/* ============ Trang bảng thiết bị ============ */
.gh { padding: var(--s4) var(--s6) 0; background: var(--surface); }
.gh-top { display: flex; align-items: flex-start; gap: var(--s4); flex-wrap: wrap; }
.gh h1 { font-size: 22px; letter-spacing: -.01em; line-height: 1.2; }
.gh .sec { font-size: var(--fs-xs); font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--brand-600); margin-bottom: 3px; display: flex; gap: 6px; align-items: center; }
.gh .info { color: var(--text-2); font-size: var(--fs-sm); margin-top: 6px; max-width: 110ch; white-space: pre-line; }
.gh .info.clamp { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.gh .info-more { background: none; border: 0; color: var(--brand-600); padding: 0; font-size: var(--fs-sm); font-weight: 600; margin-top: 2px; }
.gh .actions { margin-left: auto; display: flex; gap: var(--s2); align-items: center; flex-wrap: wrap; }
.statbar { display: flex; gap: 22px; margin: 12px 0 10px; flex-wrap: wrap; }
.stat { font-size: var(--fs-sm); color: var(--text-2); }
.stat b { font-size: 17px; color: var(--text); font-weight: 700; font-variant-numeric: tabular-nums; margin-right: 4px; }
.stat.warn b { color: var(--warn); }
.stat.danger b { color: var(--danger); }
.toolbar { display: flex; align-items: center; gap: var(--s2); padding: 10px var(--s6) 12px; background: var(--surface); border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.toolbar .sp { flex: 1; }
.toolbar .result-count { font-size: var(--fs-sm); color: var(--text-3); margin-left: 6px; }
.scope-hint { margin: 0 var(--s6); padding: 8px 12px; background: var(--info-bg); color: var(--info); border-radius: var(--r-md); font-size: var(--fs-sm); display: flex; gap: 10px; align-items: center; margin-top: 10px; }
.scope-hint button { background: none; border: 0; color: inherit; font-weight: 700; text-decoration: underline; padding: 0; }

.table-wrap { flex: 1; min-height: 0; overflow: auto; background: var(--surface); position: relative; }
table.grid { border-collapse: separate; border-spacing: 0; width: max-content; min-width: 100%; font-size: 13.5px; table-layout: fixed; }
.grid th, .grid td { padding: 9px 12px; border-bottom: 1px solid var(--border); vertical-align: top; text-align: left; background: var(--surface); }
.grid thead th { position: sticky; z-index: 5; background: var(--surface-2); font-size: 12px; color: var(--text-2); font-weight: 650; vertical-align: middle; border-bottom: 1px solid var(--border-strong); white-space: nowrap; }
.grid thead tr.bands th { top: 0; height: 30px; padding: 0 12px; font-size: 11.5px; font-weight: 700; letter-spacing: .02em; color: var(--text-3); background: var(--surface-3); border-bottom: 1px solid var(--border); }
.grid thead tr.bands th.track { background: var(--track-head); color: var(--brand-700); }
.grid thead tr.cols th { top: 30px; height: 40px; }
.grid thead tr.cols th.track { background: var(--track-head); color: var(--brand-700); }
.grid th.sortable { cursor: pointer; user-select: none; }
.grid th.sortable:hover { color: var(--text); }
.grid th .sort { display: inline-block; margin-left: 4px; opacity: .35; font-size: 10px; }
.grid th[aria-sort="ascending"] .sort, .grid th[aria-sort="descending"] .sort { opacity: 1; color: var(--brand-600); }
.grid td.r, .grid th.r { text-align: right; }
.grid td.c, .grid th.c { text-align: center; }
.grid tbody tr { cursor: pointer; }
.grid tbody tr:hover td { background: var(--surface-2); }
.grid tbody tr:hover td.track { background: var(--brand-50); }
.grid tbody tr.sel td { background: var(--brand-50); }
.grid tbody tr:focus-visible { outline: none; box-shadow: none; }
.grid tbody tr:focus-visible td:first-child { box-shadow: inset 3px 0 0 var(--brand-500); }
.grid td.track { background: var(--track-bg); }
.grid td.sticky-l, .grid th.sticky-l { position: sticky; left: 0; z-index: 3; }
.grid thead th.sticky-l { z-index: 8; }
.grid td.sticky-last::after, .grid th.sticky-last::after { content: ""; position: absolute; top: 0; right: -9px; bottom: 0; width: 9px; pointer-events: none; background: linear-gradient(90deg, rgba(16,36,52,.10), transparent); opacity: 0; transition: opacity var(--t); }
.table-wrap.scrolled-x .sticky-last::after { opacity: 1; }
.grid td.sticky-r, .grid th.sticky-r { position: sticky; right: 0; z-index: 3; }
.grid thead th.sticky-r { z-index: 8; }
.grid tr.subrow td { background: var(--surface-3); font-weight: 700; font-size: var(--fs-sm); color: var(--text-2); padding: 7px 12px; position: sticky; left: 0; border-bottom: 1px solid var(--border); cursor: default; }
.grid tr.subrow:hover td { background: var(--surface-3); }
.grid tr.grouprow td { background: var(--accent-soft); font-weight: 700; padding: 8px 12px; cursor: default; border-bottom: 1px solid var(--border-strong); }
.grid tr.grouprow button { background: none; border: 0; font-weight: 700; color: inherit; display: flex; gap: 8px; align-items: center; padding: 0; }
.grid tr.grouprow button:hover { text-decoration: underline; }
.compact .grid td { padding: 5px 12px; }
.cell-name .vi { font-weight: 620; line-height: 1.3; overflow-wrap: anywhere; }
.cell-name .en { font-size: var(--fs-sm); color: var(--text-3); line-height: 1.3; overflow-wrap: anywhere; margin-top: 1px; }
.cell-name .tag { display: inline-flex; gap: 4px; align-items: center; font-size: 11px; color: var(--text-3); margin-top: 3px; }
.cell-spec { color: var(--text-2); font-size: var(--fs-sm); line-height: 1.4; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; white-space: pre-line; overflow-wrap: anywhere; }
.compact .cell-spec { -webkit-line-clamp: 1; }
.compact .cell-name .en { display: none; }
.rem { display: inline-flex; align-items: center; justify-content: center; min-width: 38px; height: 26px; padding: 0 9px; border-radius: var(--r-pill); font-weight: 720; font-variant-numeric: tabular-nums; }
.rem.pos { background: var(--ok-bg); color: var(--ok); }
.rem.zero { background: var(--danger-bg); color: var(--danger); }
.rem.neg { background: var(--danger); color: #fff; }
.rem.none { color: var(--text-3); font-weight: 500; }
.qbtn { display: inline-flex; align-items: center; gap: 3px; border: 1px dashed transparent; background: transparent; border-radius: var(--r-sm); padding: 1px 6px; font-variant-numeric: tabular-nums; font-weight: 600; color: var(--text); min-width: 34px; justify-content: flex-end; height: 26px; }
.qbtn .ico { opacity: 0; transition: opacity var(--t-fast); }
tr:hover .qbtn, .qbtn:focus-visible { border-color: var(--brand-300); }
tr:hover .qbtn .ico, .qbtn:focus-visible .ico { opacity: .8; }
.qbtn:hover { background: var(--brand-50); }
.qbtn.zero { color: var(--text-3); font-weight: 450; }
.status-btn { border: 0; background: transparent; padding: 0; }
.status-btn:hover .badge { filter: brightness(.96); }
.row-actions { display: flex; gap: 2px; justify-content: flex-end; opacity: .55; transition: opacity var(--t-fast); }
tr:hover .row-actions, tr:focus-within .row-actions, tr.sel .row-actions { opacity: 1; }
.dchips { display: flex; flex-direction: column; gap: 4px; align-items: flex-start; }
.dchip { display: inline-flex; align-items: center; gap: 6px; max-width: 100%; height: 26px; padding: 0 9px; border-radius: var(--r-pill); font-size: var(--fs-xs); font-weight: 650; border: 1px solid var(--border-strong); background: var(--surface); color: var(--text-2); }
.dchip .t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 130px; }
.dchip.pin { background: var(--brand-600); border-color: var(--brand-600); color: #fff; }
:root[data-theme="dark"] .dchip.pin { color: #04141c; }
.dchip.pin:hover { background: var(--brand-700); }
.dchip.doc { border-color: var(--brand-500); color: var(--brand-600); }
.dchip.doc:hover { background: var(--brand-50); }
.dchip.nofile { border-style: dashed; color: var(--text-3); }
.dchip.nofile:hover { background: var(--surface-3); }
.balloon { display: inline-flex; min-width: 22px; height: 22px; padding: 0 6px; border: 1.5px solid var(--text-3); border-radius: 12px; font-size: 11.5px; font-weight: 700; align-items: center; justify-content: center; color: var(--text-2); font-variant-numeric: tabular-nums; }
.empty { display: grid; place-items: center; text-align: center; padding: 60px 24px; color: var(--text-2); gap: 8px; }
.empty .ill { width: 64px; height: 64px; border-radius: 20px; background: var(--surface-3); display: grid; place-items: center; color: var(--text-3); margin-bottom: 4px; }
.empty h3 { color: var(--text); font-size: var(--fs-lg); }
.empty p { max-width: 46ch; }
.more-row td { text-align: center; padding: 16px; cursor: default; background: var(--surface); }
.skeleton { background: linear-gradient(90deg, var(--surface-3) 25%, var(--surface-2) 37%, var(--surface-3) 63%); background-size: 400% 100%; animation: shimmer 1.3s infinite; border-radius: 6px; height: 14px; }
@keyframes shimmer { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }

/* ============ Ngăn chi tiết ============ */
.drawer-scrim { position: fixed; inset: 0; background: rgba(8, 20, 30, .32); z-index: 40; animation: fade var(--t) var(--ease); }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(520px, 100vw); background: var(--surface); z-index: 41; box-shadow: var(--sh-3); display: flex; flex-direction: column; animation: slidein 240ms var(--ease); border-left: 1px solid var(--border); }
@keyframes slidein { from { transform: translateX(40px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }
.drawer header { padding: 16px 18px 12px; display: flex; gap: 10px; align-items: flex-start; border-bottom: 1px solid var(--border); }
.drawer header .ttl { flex: 1; min-width: 0; }
.drawer header .crumbs { font-size: var(--fs-xs); color: var(--brand-600); font-weight: 700; letter-spacing: .04em; text-transform: uppercase; }
.drawer header h2 { font-size: 19px; line-height: 1.25; margin-top: 3px; overflow-wrap: anywhere; }
.drawer header .en { color: var(--text-3); font-size: var(--fs-sm); margin-top: 2px; overflow-wrap: anywhere; }
.drawer .body { flex: 1; overflow: auto; padding: 4px 18px 18px; }
.drawer footer { padding: 12px 18px; border-top: 1px solid var(--border); display: flex; gap: var(--s2); background: var(--surface-2); }
.dsec { padding: 16px 0 4px; }
.dsec h4 { font-size: 11.5px; letter-spacing: .08em; text-transform: uppercase; color: var(--text-3); margin-bottom: 10px; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.dsec h4 .sp { flex: 1; }
.kv { display: grid; grid-template-columns: 130px 1fr; gap: 7px 12px; font-size: var(--fs-md); }
.kv dt { color: var(--text-3); font-size: var(--fs-sm); padding-top: 1px; }
.kv dd { margin: 0; overflow-wrap: anywhere; white-space: pre-line; }
.stock-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.stock-cell { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-md); padding: 10px 10px 8px; text-align: center; }
.stock-cell .l { font-size: 11px; color: var(--text-3); line-height: 1.25; min-height: 28px; display: flex; align-items: center; justify-content: center; }
.stock-cell .v { font-size: 22px; font-weight: 720; font-variant-numeric: tabular-nums; margin-top: 2px; }
.stock-cell.res { background: var(--ok-bg); border-color: transparent; }
.stock-cell.res .v { color: var(--ok); }
.stock-cell.res.zero { background: var(--danger-bg); } .stock-cell.res.zero .v { color: var(--danger); }
.formula { text-align: center; font-size: var(--fs-xs); color: var(--text-3); margin: 8px 0 12px; }
.mv-list li { display: flex; gap: 10px; align-items: center; padding: 8px 0; border-bottom: 1px dashed var(--border); font-size: var(--fs-sm); }
.mv-list li:last-child { border: 0; }
.mv-list .q { font-weight: 720; min-width: 46px; font-variant-numeric: tabular-nums; }
.mv-list .q.in { color: var(--ok); } .mv-list .q.out { color: var(--warn); }
.mv-list .t { flex: 1; min-width: 0; }
.mv-list .t span { color: var(--text-3); display: block; font-size: var(--fs-xs); }
.link-card { border: 1px solid var(--border); border-radius: var(--r-md); padding: 10px 12px; display: flex; gap: 10px; align-items: center; margin-bottom: 8px; background: var(--surface-2); }
.link-card .ic { width: 34px; height: 34px; border-radius: 9px; background: var(--brand-50); color: var(--brand-600); display: grid; place-items: center; flex: none; }
.link-card .t { flex: 1; min-width: 0; }
.link-card .t b { display: block; font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.link-card .t span { font-size: var(--fs-xs); color: var(--text-3); }
.link-card .btns { display: flex; gap: 4px; flex: none; }

/* ============ Hộp thoại ============ */
dialog { border: 0; padding: 0; background: var(--surface); color: var(--text); border-radius: var(--r-lg); box-shadow: var(--sh-3); max-width: calc(100vw - 32px); max-height: calc(100vh - 32px); overflow: hidden; }
dialog[open] { display: flex; flex-direction: column; animation: pop 200ms var(--ease); }
dialog::backdrop { background: rgba(8, 20, 30, .5); animation: fade var(--t); }
@keyframes pop { from { transform: translateY(10px) scale(.98); opacity: 0; } }
.dlg { width: min(720px, calc(100vw - 32px)); }
.dlg.sm { width: min(440px, calc(100vw - 32px)); }
.dlg.lg { width: min(860px, calc(100vw - 32px)); }
.dlg > header { padding: 16px 20px; display: flex; align-items: center; gap: 12px; border-bottom: 1px solid var(--border); }
.dlg > header h2 { font-size: var(--fs-lg); flex: 1; }
.dlg > .body { padding: 16px 20px; overflow: auto; flex: 1; }
.dlg > footer { padding: 12px 20px; border-top: 1px solid var(--border); display: flex; gap: var(--s2); justify-content: flex-end; background: var(--surface-2); align-items: center; }
.dlg > footer .sp { flex: 1; }
.form-grid { display: grid; grid-template-columns: repeat(12, 1fr); gap: 14px 14px; }
.form-grid .c2 { grid-column: span 2; } .form-grid .c3 { grid-column: span 3; } .form-grid .c4 { grid-column: span 4; } .form-grid .c6 { grid-column: span 6; } .form-grid .c8 { grid-column: span 8; } .form-grid .c12 { grid-column: span 12; }
.form-sec { grid-column: 1 / -1; font-size: 11.5px; letter-spacing: .08em; text-transform: uppercase; color: var(--text-3); font-weight: 700; padding-top: 6px; border-top: 1px solid var(--border); margin-top: 4px; display: flex; gap: 8px; align-items: center; }
.form-sec:first-child { border-top: 0; margin-top: 0; padding-top: 0; }
.calc { display: flex; align-items: center; justify-content: space-between; background: var(--ok-bg); color: var(--ok); border-radius: var(--r-md); padding: 8px 14px; font-weight: 700; }
.calc.zero { background: var(--danger-bg); color: var(--danger); }
.calc .v { font-size: 20px; font-variant-numeric: tabular-nums; }
.err-text { color: var(--danger); font-size: var(--fs-sm); }

/* ============ Popover / menu ============ */
.pop { position: fixed; z-index: 90; min-width: 180px; background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--r-md); box-shadow: var(--sh-2); padding: 6px; animation: pop 140ms var(--ease); }
.pop .mi { display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 10px; border: 0; background: transparent; border-radius: 7px; text-align: left; font-size: var(--fs-md); }
.pop .mi:hover, .pop .mi:focus-visible { background: var(--surface-3); }
.pop .mi[aria-checked="true"]::after { content: "✓"; margin-left: auto; color: var(--brand-600); font-weight: 800; }
.pop .mi.danger { color: var(--danger); }
.pop hr { border: 0; border-top: 1px solid var(--border); margin: 5px 0; }
.pop .ph { font-size: 11px; text-transform: uppercase; letter-spacing: .07em; color: var(--text-3); padding: 6px 10px 4px; font-weight: 700; }
.pop-form { padding: 10px; width: 300px; display: flex; flex-direction: column; gap: 10px; }
.pop-form h4 { font-size: var(--fs-md); }
.pop-form .row { display: flex; gap: 8px; }
.pop-form .foot { display: flex; justify-content: flex-end; gap: 8px; }
.pop .colopt { display: flex; align-items: center; gap: 10px; padding: 6px 10px; border-radius: 7px; font-size: var(--fs-md); cursor: pointer; }
.pop .colopt:hover { background: var(--surface-3); }
.pop .colopt input { accent-color: var(--brand-600); width: 16px; height: 16px; }

/* ============ Toast ============ */
.toasts { position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast { pointer-events: auto; background: #0f2331; color: #fff; padding: 11px 14px 11px 16px; border-radius: var(--r-md); box-shadow: var(--sh-3); display: flex; gap: 14px; align-items: center; font-size: var(--fs-md); animation: toastin 260ms var(--ease); max-width: min(560px, 92vw); border-left: 4px solid var(--brand-300); }
.toast.ok { border-left-color: #3ecf8e; } .toast.err { border-left-color: #ff6b60; } .toast.warn { border-left-color: var(--accent); }
.toast button { background: transparent; border: 0; color: var(--accent); font-weight: 700; padding: 2px 4px; }
.toast.out { animation: toastout 200ms forwards; }
@keyframes toastin { from { transform: translateY(14px); opacity: 0; } }
@keyframes toastout { to { transform: translateY(8px); opacity: 0; } }

/* ============ Thư viện bản vẽ ============ */
.dgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: var(--s3); }
.dcard { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); padding: var(--s4); box-shadow: var(--sh-1); display: flex; flex-direction: column; gap: 12px; transition: border-color var(--t), box-shadow var(--t); }
.dcard.drop { border-color: var(--brand-500); box-shadow: var(--focus); background: var(--brand-50); }
.dcard .top { display: flex; gap: 12px; }
.dcard .thumb { width: 46px; height: 56px; border-radius: 8px; border: 1px solid var(--border-strong); display: grid; place-items: center; background: var(--surface-2); color: var(--text-3); flex: none; position: relative; }
.dcard.has .thumb { background: var(--danger-bg); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 35%, var(--border)); }
.dcard .thumb small { position: absolute; bottom: 3px; font-size: 9px; font-weight: 800; letter-spacing: .05em; }
.dcard h3 { font-size: 14.5px; line-height: 1.3; overflow-wrap: anywhere; }
.dcard .code { font-family: var(--font-mono); font-size: var(--fs-sm); color: var(--brand-600); font-weight: 600; overflow-wrap: anywhere; }
.dcard .meta { display: flex; gap: 12px; font-size: var(--fs-sm); color: var(--text-2); flex-wrap: wrap; }
.dcard .btns { display: flex; gap: 6px; margin-top: auto; flex-wrap: wrap; }
.dropzone { border: 2px dashed var(--border-strong); border-radius: var(--r-lg); padding: 18px; text-align: center; color: var(--text-2); background: var(--surface); margin-bottom: var(--s4); display: flex; gap: 14px; align-items: center; justify-content: center; flex-wrap: wrap; transition: all var(--t-fast); }
.dropzone.drop { border-color: var(--brand-500); background: var(--brand-50); }
.callout { display: flex; gap: 12px; padding: 12px 14px; border-radius: var(--r-md); background: var(--info-bg); color: var(--text); font-size: var(--fs-sm); margin-bottom: var(--s4); border: 1px solid color-mix(in srgb, var(--info) 25%, transparent); }
.callout .ico { color: var(--info); margin-top: 1px; }
.callout code, code.path { font-family: var(--font-mono); font-size: 12px; background: var(--surface); padding: 1px 6px; border-radius: 5px; border: 1px solid var(--border); }

/* Bộ chọn tìm kiếm (picker) */
.picker { display: flex; flex-direction: column; gap: 8px; min-height: 0; }
.picker .results { border: 1px solid var(--border); border-radius: var(--r-md); max-height: 300px; overflow: auto; }
.picker .res { display: flex; gap: 10px; align-items: center; padding: 9px 12px; width: 100%; text-align: left; background: transparent; border: 0; border-bottom: 1px solid var(--border); }
.picker .res:last-child { border: 0; }
.picker .res:hover, .picker .res:focus-visible { background: var(--surface-3); }
.picker .res .t { flex: 1; min-width: 0; }
.picker .res .t b { display: block; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.picker .res .t span { font-size: var(--fs-xs); color: var(--text-3); }

/* ============ Đáp ứng ============ */
@media (max-width: 1100px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: min(300px, 86vw); transform: translateX(-102%); transition: transform var(--t) var(--ease); box-shadow: var(--sh-3); }
  .sidebar.open { transform: none; }
  .scrim { position: fixed; inset: 0; background: rgba(8, 20, 30, .45); z-index: 29; }
  .page { padding: var(--s4); }
  .gh, .toolbar { padding-left: var(--s4); padding-right: var(--s4); }
  .topbar { padding: 0 var(--s4); }
  .two-col { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .topbar .crumb .trail { display: none; }
  .kbd { display: none !important; }
  .form-grid .c2, .form-grid .c3, .form-grid .c4, .form-grid .c6, .form-grid .c8 { grid-column: span 12; }
  .stock-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; transition-duration: 1ms !important; }
}
@media print {
  .sidebar, .topbar, .toolbar, .row-actions, .drawer, .toasts { display: none !important; }
  body { overflow: visible; } .app { display: block; height: auto; } .main, .table-wrap { overflow: visible !important; height: auto; }
  .grid td, .grid th { background: #fff !important; }
}

/* Cột thao tác cố định bên phải: đủ chỗ cho 4 nút, không tràn sang cột trước */
.grid td.sticky-r, .grid th.sticky-r { padding-left: 6px; padding-right: 6px; overflow: hidden; }
.row-actions { flex-wrap: nowrap; }

/* Bản vẽ liên quan ở đầu mỗi nhóm */
.gdraw { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 12px; }
.gdraw .lbl { font-size: var(--fs-xs); color: var(--text-3); font-weight: 700; margin-right: 4px; display: inline-flex; gap: 5px; align-items: center; text-transform: uppercase; letter-spacing: .05em; }
.gdraw .dchip .t { max-width: 230px; }
.dcard .cat { font-size: var(--fs-xs); color: var(--text-3); font-weight: 600; }
.chip-sep { width: 1px; background: var(--border); margin: 4px 4px; }

/* Mã số thiết bị, nhật ký sự kiện */
.code { font-family: var(--font-mono); font-size: 12px; font-weight: 600; color: var(--brand-700); background: var(--brand-50); padding: 2px 7px; border-radius: 6px; white-space: nowrap; }
.cell-name .tag.ev { color: var(--brand-600); font-weight: 600; }
.cell-name .tag.ev.open { color: var(--warn); }
.ev-list { display: flex; flex-direction: column; gap: 10px; }
.ev-card { border: 1px solid var(--border); border-radius: var(--r-md); padding: 11px 13px; background: var(--surface-2); display: flex; flex-direction: column; gap: 6px; }
.ev-card .top { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.ev-card .top .d { font-size: var(--fs-sm); color: var(--text-3); font-variant-numeric: tabular-nums; }
.ev-card .top .sp { flex: 1; }
.ev-card h5 { margin: 0; font-size: var(--fs-md); font-weight: 650; overflow-wrap: anywhere; }
.ev-card dl { margin: 0; display: grid; grid-template-columns: 96px 1fr; gap: 3px 10px; font-size: var(--fs-sm); }
.ev-card dt { color: var(--text-3); }
.ev-card dd { margin: 0; overflow-wrap: anywhere; white-space: pre-line; }
.ev-card .foot { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.badge.t-incident { background: var(--danger-bg); color: var(--danger); }
.badge.t-repair { background: var(--warn-bg); color: var(--warn); }
.badge.t-replace { background: var(--info-bg); color: var(--info); }
.badge.t-maintenance { background: var(--ok-bg); color: var(--ok); }
.linklike { display: inline-flex; gap: 6px; align-items: center; font-size: var(--fs-sm); font-weight: 600; color: var(--brand-600); text-decoration: none; }
.linklike:hover { text-decoration: underline; }
.seg.wrap { flex-wrap: wrap; }

/* Quản trị: bảng tài khoản & nhật ký hoạt động */
.tbl-wrap { overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
.tbl th { text-align: left; font-weight: 650; color: var(--text-3); padding: 9px 14px; border-bottom: 1px solid var(--border); background: var(--surface-2); white-space: nowrap; }
.tbl td { padding: 9px 14px; border-bottom: 1px solid var(--border); vertical-align: top; overflow-wrap: anywhere; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl .ta-r { text-align: right; white-space: nowrap; }
.tbl .nowrap { white-space: nowrap; }

/* Tài liệu đính kèm (tệp gốc, phiếu nhập / xuất kho) */
.fl-quick { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.fl-group + .fl-group { margin-top: 12px; }
.fl-h { display: flex; align-items: center; gap: 6px; font-size: var(--fs-sm); font-weight: 650; color: var(--text-2); margin-bottom: 4px; }
.fl-h .n { background: var(--surface-3); border-radius: var(--r-pill); padding: 0 7px; font-size: var(--fs-xs); color: var(--text-3); }
.fl-list { list-style: none; margin: 0; padding: 0; }
.fl-list li { display: flex; gap: 8px; align-items: center; padding: 7px 0; border-bottom: 1px dashed var(--border); }
.fl-list li:last-child { border: 0; }
.fl-main { flex: 1; min-width: 0; }
.fl-name { display: flex; gap: 6px; align-items: center; color: var(--brand-600); font-weight: 600; font-size: var(--fs-sm); text-decoration: none; min-width: 0; }
.fl-name span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fl-name:hover span { text-decoration: underline; }
.fl-meta { font-size: var(--fs-xs); color: var(--text-3); overflow-wrap: anywhere; }
.fl-btns { display: flex; gap: 2px; flex-shrink: 0; }
.vch { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 2px; }
.dropzone { display: grid; gap: 4px; justify-items: center; text-align: center; padding: 18px 12px; border: 1.5px dashed var(--border-strong); border-radius: var(--r-md); color: var(--text-2); cursor: pointer; transition: background .15s, border-color .15s; }
.dropzone:hover, .dropzone.over { background: var(--brand-50); border-color: var(--brand-500); }
:root[data-theme="dark"] .dropzone:hover, :root[data-theme="dark"] .dropzone.over { background: color-mix(in srgb, var(--brand-500) 14%, transparent); }
.dropzone small { color: var(--text-3); }
.fl-pick { list-style: none; margin: 6px 0 0; padding: 0; display: grid; gap: 4px; }
.fl-pick li { display: flex; gap: 8px; align-items: center; font-size: var(--fs-sm); }
.fl-pick .n { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fl-pick .s { color: var(--text-3); font-size: var(--fs-xs); }
.fl-pick li.bad .s { color: var(--danger); font-weight: 600; }
.bar { height: 6px; background: var(--surface-3); border-radius: 3px; overflow: hidden; }
.bar > i { display: block; height: 100%; width: 0; background: var(--brand-500); transition: width .2s; }
