/* Thành phần dùng chung (cần tokens.css). Dùng cho mọi trang + màn NOC.
   Không có style= trong template (CSP): mọi biến thể là class. */

/* ---------- nền tảng ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { font-size: 15px; -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: var(--font-sans); font-size: var(--fs-md); line-height: 1.5;
  font-feature-settings: "cv11", "ss01"; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale;
}
h1, h2, h3, h4 { margin: 0; line-height: 1.25; font-weight: 650; letter-spacing: -0.01em; }
p { margin: 0 0 var(--sp-3); }
a { color: var(--accent-fg); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 2px; }
code, pre, kbd, .mono { font-family: var(--font-mono); font-size: 0.92em; }
.mono { font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.num, .tabular { font-variant-numeric: tabular-nums; }
:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; border-radius: var(--radius-sm); }
::selection { background: var(--accent-bg); }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.muted { color: var(--text-muted); }
.faint { color: var(--text-faint); }
.small { font-size: var(--fs-sm); }
.xs { font-size: var(--fs-xs); }
.strong { font-weight: 650; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.inline { display: inline; }
[hidden] { display: none !important; }

/* ---------- icon (Lucide sprite: <svg class="icon"><use href="/static/vendor/lucide-sprite.svg#tên"/></svg>) ---------- */
.icon {
  width: 1.15em; height: 1.15em; flex: none; display: inline-block; vertical-align: -0.2em;
  fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}
.icon-sm { width: 14px; height: 14px; }
.icon-md { width: 16px; height: 16px; }
.icon-lg { width: 20px; height: 20px; }
.icon-xl { width: 24px; height: 24px; }
.icon-2xl { width: 32px; height: 32px; }
.icon-thin { stroke-width: 1.5; }

/* ---------- nút ---------- */
.btn, button {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
  min-height: 34px; padding: 0 var(--sp-4); border-radius: var(--radius-md);
  border: 1px solid var(--border-strong); background: var(--surface-3); color: var(--text);
  font: inherit; font-size: var(--fs-md); font-weight: 560; line-height: 1; white-space: nowrap;
  cursor: pointer; text-decoration: none; transition: background-color .15s, border-color .15s, color .15s;
}
.btn:hover, button:hover { background: var(--surface-2); border-color: var(--text-faint); text-decoration: none; }
.btn:active, button:active { transform: translateY(1px); }
.btn-primary, button.btn-primary {
  background: var(--accent-strong); border-color: var(--accent-strong); color: #fff;
}
.btn-primary:hover, button.btn-primary:hover { background: var(--accent); border-color: var(--accent); }
.btn-ghost, button.btn-ghost { background: transparent; border-color: transparent; color: var(--text-muted); }
.btn-ghost:hover, button.btn-ghost:hover { background: var(--surface-2); border-color: var(--border); color: var(--text); }
.btn-danger, button.btn-danger { background: var(--sev-critical-bg); border-color: transparent; color: var(--sev-critical-fg); }
.btn-danger:hover, button.btn-danger:hover { background: var(--sev-critical); color: #fff; border-color: var(--sev-critical); }
.btn-outline, button.btn-outline { background: transparent; border-color: var(--border-strong); color: var(--text); }
.btn-sm, button.btn-sm { min-height: 28px; padding: 0 var(--sp-3); font-size: var(--fs-sm); gap: 6px; }
.btn-lg, button.btn-lg { min-height: 42px; padding: 0 var(--sp-5); font-size: var(--fs-lg); }
.btn-block { width: 100%; }
.btn-icon, button.btn-icon { width: 34px; padding: 0; }
.btn-link, button.btn-link {
  min-height: 0; padding: 0; border: 0; background: none; color: var(--accent-fg); font-weight: 500;
}
.btn-link:hover, button.btn-link:hover { background: none; text-decoration: underline; }
button:disabled, .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; }

/* ---------- form ---------- */
label { display: block; font-size: var(--fs-sm); font-weight: 560; color: var(--text-muted); margin: 0 0 6px; }
.field { display: flex; flex-direction: column; min-width: 0; }
.field + .field { margin-top: var(--sp-4); }
.hint { font-weight: 400; color: var(--text-faint); font-size: var(--fs-xs); }
input[type=text], input[type=password], input[type=number], input[type=search], input[type=email], select, textarea {
  width: 100%; min-height: 36px; padding: 0 var(--sp-3);
  border: 1px solid var(--border-strong); border-radius: var(--radius-md);
  background: var(--surface-2); color: var(--text); font: inherit; font-size: var(--fs-md);
  transition: border-color .15s, box-shadow .15s;
}
textarea { padding: var(--sp-2) var(--sp-3); min-height: 80px; }
select { padding-right: 28px; appearance: none; -webkit-appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--text-muted) 50%),
    linear-gradient(135deg, var(--text-muted) 50%, transparent 50%);
  background-position: calc(100% - 15px) 50%, calc(100% - 10px) 50%;
  background-size: 5px 5px, 5px 5px; background-repeat: no-repeat; }
input::placeholder { color: var(--text-faint); }
input:hover, select:hover, textarea:hover { border-color: var(--text-faint); }
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-bg);
}
input[type=checkbox], input[type=radio] { accent-color: var(--accent); width: 16px; height: 16px; margin: 0; }
.check { display: inline-flex; align-items: center; gap: var(--sp-2); margin: 0; font-weight: 500;
  color: var(--text); font-size: var(--fs-md); cursor: pointer; }

/* Công tắc bật/tắt: <label class="switch"><input type="checkbox" ...><span class="switch-track"></span> Nhãn</label> */
.switch { display: inline-flex; align-items: center; gap: var(--sp-3); margin: 0; cursor: pointer;
  color: var(--text); font-weight: 560; font-size: var(--fs-md); }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch-track { position: relative; width: 38px; height: 22px; flex: none; border-radius: var(--radius-pill);
  background: var(--surface-3); border: 1px solid var(--border-strong); transition: background-color .15s; }
.switch-track::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px;
  border-radius: 50%; background: var(--text-muted); transition: transform .15s, background-color .15s; }
.switch input:checked + .switch-track { background: var(--ok); border-color: var(--ok); }
.switch input:checked + .switch-track::after { transform: translateX(16px); background: #fff; }
.switch input:focus-visible + .switch-track { outline: 2px solid var(--focus-ring); outline-offset: 2px; }

/* ---------- panel ---------- */
.panel {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-1); min-width: 0; display: flex; flex-direction: column;
}
.panel-head {
  display: flex; align-items: center; gap: var(--sp-3); flex-wrap: wrap;
  padding: var(--sp-3) var(--sp-4); border-bottom: 1px solid var(--border); min-height: 48px;
}
.panel-head h2, .panel-title {
  font-size: var(--fs-md); font-weight: 650; letter-spacing: 0; display: flex; align-items: center; gap: var(--sp-2);
}
.panel-head h2 .icon, .panel-title .icon { color: var(--text-muted); }
.panel-sub { color: var(--text-muted); font-size: var(--fs-sm); }
.panel-actions { margin-left: auto; display: flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap; }
.panel-body { padding: var(--sp-4); min-width: 0; flex: 1; }
.panel-body > :last-child { margin-bottom: 0; }
.panel-body.flush { padding: 0; }
.panel-foot { padding: var(--sp-3) var(--sp-4); border-top: 1px solid var(--border); font-size: var(--fs-sm);
  color: var(--text-muted); display: flex; align-items: center; gap: var(--sp-3); flex-wrap: wrap; }
.panel-foot a { display: inline-flex; align-items: center; gap: 4px; font-weight: 560; }

/* ---------- KPI ---------- */
.kpi-row { display: grid; gap: var(--sp-3); grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
.kpi-row.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.kpi-row.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.kpi-row.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.kpi-row.cols-5 { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.span-6 .kpi-row.cols-5 .kpi { padding-left: var(--sp-3); padding-right: var(--sp-2); }
.span-6 .kpi-row.cols-5 .kpi-label { white-space: normal; min-height: 2.5em; align-items: flex-start; line-height: 1.25; }
@media (max-width: 1100px) { .kpi-row.cols-4, .kpi-row.cols-5 { grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); } }
.kpi {
  position: relative; display: flex; flex-direction: column; gap: 2px; min-width: 0;
  padding: var(--sp-3) var(--sp-4) var(--sp-3); background: var(--surface-2);
  border: 1px solid var(--border); border-radius: var(--radius-md); overflow: hidden;
}
.kpi::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 3px; background: var(--border-strong); }
.kpi.sev-critical::before { background: var(--sev-critical); }
.kpi.sev-high::before { background: var(--sev-high); }
.kpi.sev-medium::before { background: var(--sev-medium); }
.kpi.sev-low::before { background: var(--sev-low); }
.kpi.sev-info::before { background: var(--sev-info); }
.kpi.sev-ok::before { background: var(--ok); }
.kpi.sev-warn::before { background: var(--warn); }
.kpi.sev-nodata::before { background: var(--nodata); }
.kpi-label { display: flex; align-items: center; gap: 6px; font-size: 0.6875rem; font-weight: 650;
  text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); white-space: nowrap; overflow: hidden;
  text-overflow: ellipsis; }
.kpi-value { font-size: var(--fs-kpi); font-weight: 700; line-height: 1.1; letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums; color: var(--text); }
.kpi-value .kpi-unit { font-size: var(--fs-lg); font-weight: 500; color: var(--text-muted); margin-left: 2px; }
.kpi-meta { font-size: var(--fs-xs); color: var(--text-faint); }
.kpi-delta { display: inline-flex; align-items: center; gap: 3px; font-size: var(--fs-xs); font-weight: 600;
  color: var(--text-muted); font-variant-numeric: tabular-nums; }
.kpi-delta .icon { width: 13px; height: 13px; }
.kpi-delta.up { color: var(--sev-critical-fg); }     /* cảnh báo/lỗ hổng tăng = xấu */
.kpi-delta.down { color: var(--ok-fg); }
.kpi-delta.flat { color: var(--text-faint); }
.kpi-delta.up.good { color: var(--ok-fg); }           /* chỉ số tăng = tốt (vd server kết nối) */
.kpi-delta.down.bad { color: var(--sev-critical-fg); }

/* ---------- badge ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px; height: 22px; padding: 0 8px;
  border-radius: var(--radius-sm); font-size: var(--fs-xs); font-weight: 650; line-height: 1;
  white-space: nowrap; letter-spacing: .01em;
  background: var(--nodata-bg); color: var(--nodata-fg); border: 1px solid transparent;
}
.badge .icon { width: 12px; height: 12px; }
.badge.sev-critical { background: var(--sev-critical-bg); color: var(--sev-critical-fg); border-color: color-mix(in srgb, var(--sev-critical) 35%, transparent); }
.badge.sev-high { background: var(--sev-high-bg); color: var(--sev-high-fg); border-color: color-mix(in srgb, var(--sev-high) 35%, transparent); }
.badge.sev-medium { background: var(--sev-medium-bg); color: var(--sev-medium-fg); border-color: color-mix(in srgb, var(--sev-medium) 35%, transparent); }
.badge.sev-low { background: var(--sev-low-bg); color: var(--sev-low-fg); border-color: color-mix(in srgb, var(--sev-low) 35%, transparent); }
.badge.sev-info { background: var(--sev-info-bg); color: var(--sev-info-fg); }
.badge.sev-ok, .badge.ok { background: var(--ok-bg); color: var(--ok-fg); border-color: color-mix(in srgb, var(--ok) 30%, transparent); }
.badge.sev-warn, .badge.warn { background: var(--warn-bg); color: var(--warn-fg); border-color: color-mix(in srgb, var(--warn) 30%, transparent); }
.badge.sev-nodata, .badge.nodata { background: var(--nodata-bg); color: var(--nodata-fg); border: 1px dashed var(--nodata); }
.badge.danger, .badge.crit { background: var(--sev-critical-bg); color: var(--sev-critical-fg); border-color: color-mix(in srgb, var(--sev-critical) 35%, transparent); }
.badge.info, .badge.accent { background: var(--accent-bg); color: var(--accent-fg); }
.badge.solid.sev-critical { background: var(--sev-critical); color: #fff; }
.badge-lg { height: 26px; padding: 0 10px; font-size: var(--fs-sm); }

/* ---------- đèn trạng thái ---------- */
.status-dot { position: relative; display: inline-block; flex: none; width: 10px; height: 10px; border-radius: 50%;
  background: var(--nodata); vertical-align: middle; }
.status-dot.ok { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-bg); }
.status-dot.warn { background: var(--warn); box-shadow: 0 0 0 3px var(--warn-bg); }
.status-dot.crit { background: var(--sev-critical); box-shadow: 0 0 0 3px var(--sev-critical-bg); }
.status-dot.nodata { background: transparent; border: 2px dashed var(--nodata); }
.status-dot.crit::after { content: ""; position: absolute; inset: -2px; border-radius: 50%;
  border: 2px solid var(--sev-critical); animation: sp-pulse 1.6s ease-out infinite; }
.status-dot.lg { width: 14px; height: 14px; }
.status-dot.xl { width: 18px; height: 18px; }
@keyframes sp-pulse { 0% { transform: scale(1); opacity: .9; } 100% { transform: scale(2.6); opacity: 0; } }
@keyframes sp-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .status-dot.crit::after { animation: none; opacity: .5; transform: scale(1.6); }
  *, *::before, *::after { transition-duration: 0s !important; animation-duration: 0s !important; }
}

/* ---------- bảng ---------- */
.table-wrap { overflow: auto; max-width: 100%; }
.table-wrap.scroll { max-height: 70vh; }
.table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: var(--fs-md); }
.table th, .table td { text-align: left; vertical-align: top; padding: 9px var(--sp-3);
  border-bottom: 1px solid var(--border); }
.table thead th {
  position: sticky; top: 0; z-index: 1; background: var(--surface-2); color: var(--text-muted);
  font-size: var(--fs-xs); font-weight: 650; text-transform: uppercase; letter-spacing: .06em; white-space: nowrap;
  padding-top: 8px; padding-bottom: 8px;
}
.table tbody tr:nth-child(even) > * { background: color-mix(in srgb, var(--surface-2) 45%, transparent); }
.table tbody tr:hover > * { background: var(--surface-2); }
.table tbody tr:last-child > * { border-bottom: 0; }
.table tbody th { font-weight: 500; }
.table .right, .table th.right { text-align: right; }
.table.middle td, .table.middle th { vertical-align: middle; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table.compact th, .table.compact td { padding: 6px var(--sp-3); }
.table td.actions-cell { text-align: right; white-space: nowrap; }
/* Dòng tô màu theo mức: vạch màu bên trái ô đầu */
.table tr[class*="row-sev-"] > :first-child { box-shadow: inset 3px 0 0 var(--sev-info); }
.table tr.row-sev-critical > :first-child { box-shadow: inset 3px 0 0 var(--sev-critical); }
.table tr.row-sev-high > :first-child { box-shadow: inset 3px 0 0 var(--sev-high); }
.table tr.row-sev-medium > :first-child { box-shadow: inset 3px 0 0 var(--sev-medium); }
.table tr.row-sev-low > :first-child { box-shadow: inset 3px 0 0 var(--sev-low); }
.table tr.row-sev-critical > * { background: color-mix(in srgb, var(--sev-critical) 6%, transparent); }
.table tr.row-muted > * { opacity: .62; }
.table tr.row-muted:hover > * { opacity: 1; }

/* ---------- thông báo / trạng thái rỗng / thiếu dữ liệu ---------- */
.msg { display: flex; gap: var(--sp-3); align-items: flex-start; padding: var(--sp-3) var(--sp-4);
  border-radius: var(--radius-md); margin-bottom: var(--sp-4); border: 1px solid transparent; font-size: var(--fs-md); }
.msg.ok { background: var(--ok-bg); color: var(--ok-fg); border-color: color-mix(in srgb, var(--ok) 30%, transparent); }
.msg.err { background: var(--sev-critical-bg); color: var(--sev-critical-fg); border-color: color-mix(in srgb, var(--sev-critical) 35%, transparent); }
.msg.warn { background: var(--warn-bg); color: var(--warn-fg); border-color: color-mix(in srgb, var(--warn) 35%, transparent); }
.msg.info { background: var(--accent-bg); color: var(--accent-fg); }
.msg strong { color: inherit; }

/* Nguồn dữ liệu lỗi: LUÔN xám, không có số */
div.nodata, p.nodata, .missing {
  background: var(--nodata-bg); color: var(--nodata-fg); border: 1px dashed var(--nodata);
  border-radius: var(--radius-md); padding: var(--sp-3) var(--sp-4); margin: 0 0 var(--sp-3);
}
.missing-title { display: flex; align-items: center; gap: var(--sp-2); margin: 0 0 4px; font-weight: 650; color: var(--text); }
.missing-title .icon { color: var(--nodata-fg); }
.missing-hint { margin: 0 0 6px; color: var(--text-muted); font-size: var(--fs-sm); }
.empty { display: flex; align-items: center; gap: var(--sp-2); color: var(--text-muted); font-size: var(--fs-md);
  padding: var(--sp-4) 0; margin: 0; }
.empty .icon { color: var(--ok); }

/* Chi tiết kỹ thuật thu gọn */
details.tech { margin-top: 6px; font-size: var(--fs-sm); color: var(--text-muted); }
details.tech > summary { cursor: pointer; list-style: none; display: inline-flex; align-items: center; gap: 4px;
  color: var(--text-faint); font-size: var(--fs-xs); font-weight: 560; user-select: none; }
details.tech > summary::-webkit-details-marker { display: none; }
details.tech > summary::before { content: "›"; display: inline-block; width: 10px; font-size: 14px; line-height: 1;
  transition: transform .15s; }
details.tech[open] > summary::before { transform: rotate(90deg); }
details.tech > summary:hover { color: var(--text-muted); }
details.tech pre, details.tech code { white-space: pre-wrap; word-break: break-word; }
details.tech pre { max-height: 320px; overflow: auto; margin: 6px 0 0; padding: var(--sp-2) var(--sp-3);
  background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm); color: var(--text-muted);
  font-size: var(--fs-xs); }

/* ---------- chip, thanh công cụ, chỉ báo sống ---------- */
.chip { display: inline-flex; align-items: center; gap: 4px; height: 22px; padding: 0 8px; border-radius: var(--radius-sm);
  background: var(--surface-3); color: var(--text-muted); font-size: var(--fs-xs); font-weight: 560; white-space: nowrap; }
.chip.mono { font-family: var(--font-mono); color: var(--text); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.toolbar { display: flex; flex-wrap: wrap; align-items: flex-end; gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4); background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); }
.toolbar .field { min-width: 160px; }
.toolbar .field label { font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: .06em; }
.toolbar .check { height: 36px; }
.toolbar-spacer { flex: 1; }
.live { display: inline-flex; align-items: center; gap: var(--sp-2); font-size: var(--fs-xs); color: var(--text-muted);
  font-weight: 560; }
.live .status-dot { width: 8px; height: 8px; }
.live .live-spin { display: none; width: 13px; height: 13px; animation: sp-spin 0.9s linear infinite; }
.live.htmx-request .live-spin { display: inline-block; }
.live.htmx-request .status-dot { display: none; }

/* ---------- bước (stepper) ---------- */
.stepper { list-style: none; display: flex; gap: 0; padding: 0; margin: 0 0 var(--sp-5); counter-reset: st; }
.stepper li { flex: 1; display: flex; align-items: center; gap: var(--sp-3); min-width: 0; color: var(--text-faint);
  font-size: var(--fs-sm); font-weight: 560; }
.stepper li::after { content: ""; flex: 1; height: 2px; background: var(--border); margin: 0 var(--sp-3); border-radius: 2px; }
.stepper li:last-child::after { display: none; }
.stepper li:last-child { flex: none; }
.step-num { flex: none; width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center;
  border: 2px solid var(--border-strong); color: var(--text-muted); font-weight: 700; font-size: var(--fs-sm);
  background: var(--surface); }
.stepper li.done { color: var(--text-muted); }
.stepper li.done .step-num { background: var(--ok); border-color: var(--ok); color: #fff; }
.stepper li.done::after { background: var(--ok); }
.stepper li.now { color: var(--text); }
.stepper li.now .step-num { border-color: var(--accent); background: var(--accent-bg); color: var(--accent-fg);
  box-shadow: 0 0 0 4px var(--accent-bg); }

/* ---------- lưới tiện ích ---------- */
.grid { display: grid; gap: var(--sp-4); grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.row { display: flex; flex-wrap: wrap; gap: var(--sp-2); align-items: center; }
.stack { display: flex; flex-direction: column; gap: var(--sp-4); }
.divider { height: 1px; background: var(--border); border: 0; margin: var(--sp-4) 0; }
