/* NoxAuto Dispatch - "ops console": token, nền, layout chung, component (nút, form, badge, bảng, thanh tiến độ).
   Style riêng từng trang ở pages.css. Không dùng style="" inline / data: URI (CSP default-src 'self'). */
:root {
  --bg: #121311; --surface: #1A1B19; --surface-2: #22231F; --surface-3: #2A2B26; --sunken: #0E0F0D;
  --line: #2E2F2A; --line-strong: #3B3C36;
  --text: #ECEDE6; --text-2: #A6A89C; --text-3: #8A8C80; /* text-3 nâng từ #74766B để đạt >= 4.5:1 trên surface */
  --text-4: #5E6057; /* chỉ dùng cho chi tiết trang trí, không dùng cho chữ */
  --accent: #C8F25A; --accent-hover: #D6F97C; --accent-ink: #151a05;
  --ok: #3DD6A3; --warn: #F2B33D; --err: #F0604D; --err-soft-text: #FF8C7B;
  --font-sans: "Be Vietnam Pro", system-ui, "Segoe UI", sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "Cascadia Mono", Consolas, monospace;
  --r-sm: 6px; --r: 8px; --r-md: 12px; --r-lg: 14px;
  --ease: cubic-bezier(.22, .61, .36, 1); --dur: 180ms;
  --topbar-h: 60px;
}
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: calc(var(--topbar-h) + 16px); }
body {
  margin: 0; min-height: 100dvh; background: var(--bg); color: var(--text); isolation: isolate;
  font: 400 15px/1.55 var(--font-sans); -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}
/* Kết cấu nền: lưới 32px rất mờ, tắt dần về cuối trang (thuần CSS gradient, không ảnh) */
body::before {
  content: ""; position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background-image:
    radial-gradient(900px 420px at 80% -8%, rgba(200, 242, 90, .055), transparent 70%),
    linear-gradient(rgba(236, 237, 230, .022) 1px, transparent 1px),
    linear-gradient(90deg, rgba(236, 237, 230, .022) 1px, transparent 1px);
  background-size: auto, 32px 32px, 32px 32px;
  -webkit-mask-image: linear-gradient(to bottom, #000 0%, rgba(0, 0, 0, .35) 55%, transparent 100%);
  mask-image: linear-gradient(to bottom, #000 0%, rgba(0, 0, 0, .35) 55%, transparent 100%);
}
::selection { background: rgba(200, 242, 90, .28); color: var(--text); }
h1, h2, h3 { margin: 0; line-height: 1.25; font-weight: 600; letter-spacing: -.01em; text-wrap: balance; }
h1 { font-size: 28px; font-weight: 700; letter-spacing: -.02em; }
h2 { font-size: 17px; }
p { margin: 0; }
a { color: var(--text); text-decoration: none; transition: color var(--dur) var(--ease); }
a:hover { color: var(--accent); }
code, kbd, .num { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
code { font-size: .86em; padding: 1px 6px; border-radius: 5px; background: var(--surface-2); border: 1px solid var(--line); color: var(--text); }
.num { font-size: .93em; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
#main:focus { outline: none; }
.icon { flex: none; width: 16px; height: 16px; }

/* ---------- Tiện ích ---------- */
.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; }
.skip-link { position: absolute; left: 12px; top: -48px; z-index: 50; padding: 8px 14px; border-radius: var(--r);
  background: var(--accent); color: var(--accent-ink); font-weight: 600; transition: top var(--dur) var(--ease); }
.skip-link:focus { top: 12px; color: var(--accent-ink); }
.muted { color: var(--text-2); } .small { font-size: 13px; } .nowrap { white-space: nowrap; }
.ok-text { color: var(--ok); } .err-text { color: var(--err-soft-text); } .warn-text { color: var(--warn); }
.t-right { text-align: right; } .inline { display: inline; } .no-margin { margin: 0; }
.eyebrow { font-size: 12px; font-weight: 600; letter-spacing: .09em; text-transform: uppercase; color: var(--accent); margin-bottom: 8px; }

/* ---------- Topbar + khung trang ---------- */
.topbar { position: sticky; top: 0; z-index: 20; background: rgba(18, 19, 17, .8); border-bottom: 1px solid var(--line);
  -webkit-backdrop-filter: blur(12px) saturate(140%); backdrop-filter: blur(12px) saturate(140%); }
.topbar-inner { max-width: 1240px; margin: 0 auto; padding: 0 24px; height: var(--topbar-h); display: flex; align-items: center; gap: 28px; }
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--text); font-weight: 700; font-size: 15px; letter-spacing: -.01em; white-space: nowrap; }
.brand:hover { color: var(--text); }
.brand-mark { flex: none; display: block; }
.brand-word-2 { color: var(--text-2); font-weight: 500; }
.mainnav { display: flex; align-self: stretch; gap: 4px; }
.mainnav-link { position: relative; display: inline-flex; align-items: center; gap: 8px; padding: 0 12px; color: var(--text-2); font-weight: 500; font-size: 14px; }
.mainnav-link::after { content: ""; position: absolute; left: 12px; right: 12px; bottom: -1px; height: 2px; border-radius: 2px 2px 0 0;
  background: var(--accent); transform: scaleX(0); transition: transform var(--dur) var(--ease); }
.mainnav-link:hover { color: var(--text); }
.mainnav-link.is-active { color: var(--text); }
.mainnav-link.is-active::after { transform: scaleX(1); }
.mainnav-link.is-active .icon { color: var(--accent); }
.topbar-end { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.server-time { display: inline-flex; align-items: center; gap: 6px; color: var(--text-3); font-size: 13px; }
.container { max-width: 1240px; margin: 0 auto; padding: 32px 24px 72px; }
.page-header { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px 24px; flex-wrap: wrap; margin-bottom: 24px; }
.page-heading { min-width: 0; }
.page-lede { margin-top: 6px; color: var(--text-2); font-size: 14px; }
.title-row { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; }
.backlink { display: inline-flex; align-items: center; gap: 6px; margin-bottom: 14px; color: var(--text-2); font-size: 13px; }
.backlink:hover { color: var(--text); }
.section { margin-top: 32px; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 12px; }

/* ---------- Card ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); padding: 20px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .025); }
.card-title { font-size: 14px; font-weight: 600; margin-bottom: 14px; color: var(--text); }

/* ---------- Nút ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 40px; padding: 0 16px;
  border: 1px solid transparent; border-radius: var(--r); background: var(--surface-2); color: var(--text);
  font: 500 14px/1 var(--font-sans); white-space: nowrap; cursor: pointer; user-select: none; text-decoration: none;
  transition: background-color var(--dur) var(--ease), border-color var(--dur) var(--ease), color var(--dur) var(--ease),
    box-shadow var(--dur) var(--ease), transform 90ms var(--ease); }
.btn:hover { color: var(--text); }
.btn:active { transform: translateY(1px); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .45; cursor: not-allowed; transform: none; }
.btn-secondary, .btn:not([class*="btn-"]) { background: var(--surface-2); border-color: var(--line-strong); }
.btn-secondary:hover, .btn:not([class*="btn-"]):hover { background: var(--surface-3); border-color: #4A4B44; }
.btn-primary { background: var(--accent); color: var(--accent-ink); font-weight: 600;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .35), 0 8px 20px -12px rgba(200, 242, 90, .55); }
.btn-primary:hover { background: var(--accent-hover); color: var(--accent-ink); box-shadow: inset 0 1px 0 rgba(255, 255, 255, .35), 0 10px 24px -12px rgba(200, 242, 90, .7); }
.btn-danger { background: var(--err); color: #1E0805; font-weight: 600; box-shadow: 0 8px 20px -14px rgba(240, 96, 77, .8); }
.btn-danger:hover { background: #F4745F; color: #1E0805; }
.btn-danger-soft { background: rgba(240, 96, 77, .1); border-color: rgba(240, 96, 77, .35); color: var(--err-soft-text); }
.btn-danger-soft:hover { background: rgba(240, 96, 77, .18); border-color: rgba(240, 96, 77, .55); color: #FFA597; }
.btn-quiet, .btn-ghost { background: transparent; color: var(--text-2); }
.btn-quiet:hover, .btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-sm { height: 34px; padding: 0 12px; font-size: 13px; }
.btn-lg { height: 48px; padding: 0 22px; font-size: 15px; }
.btn-block { width: 100%; }

/* ---------- Form ---------- */
.stack-form { display: flex; flex-direction: column; gap: 20px; }
.field label { display: block; margin-bottom: 8px; font-size: 14px; font-weight: 500; color: var(--text); }
.field-help { margin-top: 6px; font-size: 13px; color: var(--text-3); }
.field-error { display: flex; align-items: center; gap: 6px; margin-top: 6px; font-size: 13px; color: var(--err-soft-text); }
input[type=text], input[type=password], input[type=number], select {
  display: block; width: 100%; height: 44px; padding: 0 14px; border-radius: var(--r);
  background: var(--sunken); color: var(--text); border: 1px solid var(--line-strong);
  font: 400 16px/1.2 var(--font-sans); transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease); }
textarea {
  display: block; width: 100%; min-height: 150px; padding: 12px 14px; border-radius: var(--r); resize: vertical;
  background: var(--sunken); color: var(--text); border: 1px solid var(--line-strong);
  font: 400 15px/1.6 var(--font-mono); white-space: pre; overflow-x: auto;
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease); }
textarea::placeholder { color: var(--text-3); opacity: 1; }
textarea:hover { border-color: #4A4B44; }
textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(200, 242, 90, .18); }
.has-error textarea { border-color: rgba(240, 96, 77, .7); }
.mono { font-family: var(--font-mono); font-size: .95em; color: var(--text-2); }
input::placeholder { color: var(--text-3); opacity: 1; }
input:hover, select:hover { border-color: #4A4B44; }
input:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(200, 242, 90, .18); }
.input-mono { font-family: var(--font-mono) !important; font-size: 15px !important; }
.has-error input, .has-error select, [aria-invalid="true"] { border-color: rgba(240, 96, 77, .7); }
/* Mũi tên select vẽ bằng gradient (data: URI bị CSP chặn) */
select { appearance: none; -webkit-appearance: none; padding-right: 40px; cursor: pointer;
  background-image: linear-gradient(45deg, transparent 50%, var(--text-2) 50%), linear-gradient(135deg, var(--text-2) 50%, transparent 50%);
  background-position: calc(100% - 20px) 52%, calc(100% - 15px) 52%; background-size: 5px 5px; background-repeat: no-repeat; }
select option { background: var(--surface); color: var(--text); }

/* ---------- Badge trạng thái: màu + hình dấu khác nhau (không chỉ dựa vào màu) ---------- */
.badge { --tone: var(--text-3); display: inline-flex; align-items: center; gap: 6px; height: 22px; padding: 0 8px;
  border-radius: var(--r-sm); font: 600 12px/1 var(--font-sans); letter-spacing: .01em; white-space: nowrap; vertical-align: middle;
  color: var(--tone); background: color-mix(in srgb, var(--tone) 14%, transparent); border: 1px solid color-mix(in srgb, var(--tone) 32%, transparent); }
.badge::before { content: ""; flex: none; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-lg { height: 28px; padding: 0 11px; font-size: 13px; gap: 8px; }
.badge-lg::before { width: 7px; height: 7px; }
.badge-ok { --tone: var(--ok); }                                                     /* chấm tròn */
.badge-info { --tone: var(--accent); }                                               /* chấm tròn nhấp nháy: đang chạy */
.badge-info::before { animation: pulse-dot 1.8s var(--ease) infinite; }
.badge-warn { --tone: var(--warn); }
.badge-warn::before { border-radius: 1px; transform: rotate(45deg) scale(.9); }      /* hình thoi */
.badge-err { --tone: var(--err); color: var(--err-soft-text); }
.badge-err::before { border-radius: 1px; }                                           /* hình vuông */
.badge-muted { --tone: var(--text-3); color: var(--text-2); }
.badge-muted::before { background: transparent; box-shadow: inset 0 0 0 1.5px currentColor; } /* vòng rỗng */
.badge-local { --tone: #7cc4ff; color: var(--text); margin-left: 4px; }              /* "Tại máy": chạy bắt đầu tại máy NoxAuto */
.badge-local::before { border-radius: 2px; width: 6px; height: 4px; }                /* hình chữ nhật: khác chấm/thoi/vuông */
.page-filters { display: flex; flex-wrap: wrap; gap: 10px 14px; align-items: center; }
@keyframes pulse-dot { 0% { box-shadow: 0 0 0 0 rgba(200, 242, 90, .6); } 70%, 100% { box-shadow: 0 0 0 6px rgba(200, 242, 90, 0); } }

/* ---------- Thông báo ---------- */
.alert { display: flex; align-items: flex-start; gap: 10px; padding: 12px 14px; margin: 0 0 16px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface-2); font-size: 14px; line-height: 1.5; }
.alert .icon { margin-top: 2px; }
.alert-warn { background: rgba(242, 179, 61, .08); border-color: rgba(242, 179, 61, .3); }
.alert-warn .icon { color: var(--warn); }
.alert-error { background: rgba(240, 96, 77, .09); border-color: rgba(240, 96, 77, .35); }
.alert-error .icon { color: var(--err); }
.alert a, .steps a { color: var(--accent); text-decoration: underline; text-underline-offset: 3px; }

/* ---------- Bảng (cuộn ngang trong khung riêng trên mobile) ---------- */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); }
.table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 14px; font-variant-numeric: tabular-nums; }
.table th { padding: 11px 14px; text-align: left; font-size: 12px; font-weight: 500; color: var(--text-3); white-space: nowrap;
  background: rgba(255, 255, 255, .015); border-bottom: 1px solid var(--line); }
.table td { padding: 12px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr { transition: background-color var(--dur) var(--ease); }
.table tbody tr:hover { background: rgba(255, 255, 255, .022); }
.table th.t-right, .table td.t-right { text-align: right; }
.table tr.is-dim td { color: var(--text-2); }
.table a { font-weight: 500; }

/* ---------- Key-value ---------- */
.kv { display: grid; grid-template-columns: minmax(120px, 160px) 1fr; gap: 10px 16px; margin: 0; font-size: 14px; }
.kv dt { color: var(--text-3); }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.kv-stack { grid-template-columns: 1fr; gap: 4px; }
.kv-stack dd { margin-bottom: 10px; }
.kv-tight { margin-bottom: 14px; }

/* ---------- Thanh tiến độ: <progress> (CSP chặn style inline nên không đặt width động) ---------- */
progress.bar { --bar: var(--accent); appearance: none; -webkit-appearance: none; display: block; width: 100%; min-width: 80px; height: 8px;
  border: 0; border-radius: 999px; background: var(--surface-3); overflow: hidden; color: var(--bar); }
progress.bar::-webkit-progress-bar { background: var(--surface-3); border-radius: 999px; }
progress.bar::-webkit-progress-value { background: var(--bar); border-radius: 999px; transition: width .5s var(--ease); }
progress.bar::-moz-progress-bar { background: var(--bar); border-radius: 999px; }
progress.bar-sm { height: 6px; }
progress.bar-lg { height: 12px; }
progress.bar.tone-badge-ok { --bar: var(--ok); } progress.bar.tone-badge-warn { --bar: var(--warn); }
progress.bar.tone-badge-err { --bar: var(--err); } progress.bar.tone-badge-muted { --bar: var(--text-3); }

/* ---------- Checklist readiness: ✓ / ✗ / ? bằng SVG + chữ ---------- */
.checklist { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px 12px; }
.check { display: flex; align-items: center; gap: 8px; min-width: 0; font: 400 13px/1.3 var(--font-mono); color: var(--text); }
.check-mark { flex: none; display: inline-grid; place-items: center; width: 20px; height: 20px; border-radius: 6px; }
.check-mark .icon { width: 14px; height: 14px; stroke-width: 2; }
.check.is-ok .check-mark { background: rgba(61, 214, 163, .14); color: var(--ok); }
.check.is-bad .check-mark { background: rgba(240, 96, 77, .14); color: var(--err-soft-text); }
.check.is-bad .check-label { color: var(--err-soft-text); }
.check.is-unknown .check-mark { background: var(--surface-3); color: var(--text-2); }
.mark { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; }
.mark.is-ok { color: var(--ok); } .mark.is-bad { color: var(--err-soft-text); } .mark.is-unknown { color: var(--text-2); }

/* ---------- Danh sách bước + trạng thái rỗng ---------- */
.steps { list-style: none; counter-reset: step; margin: 0; padding: 0; display: grid; gap: 12px; text-align: left; }
.steps li { counter-increment: step; position: relative; padding-left: 38px; min-height: 26px; color: var(--text-2); font-size: 14px; }
.steps li strong { color: var(--text); font-weight: 600; }
.steps li::before { content: counter(step); position: absolute; left: 0; top: -1px; width: 26px; height: 26px; border-radius: 8px;
  display: grid; place-items: center; font: 500 12px/1 var(--font-mono); color: var(--accent); background: var(--surface-2); border: 1px solid var(--line-strong); }
.empty-inline { padding: 22px; border: 1px dashed var(--line-strong); border-radius: var(--r-md); color: var(--text-3); text-align: center; font-size: 14px; }

@media (max-width: 720px) {
  .container { padding: 20px 16px 56px; }
  .topbar-inner { padding: 0 12px; gap: 6px; }
  .mainnav-link { padding: 0 10px; }
  .server-time { display: none; }
  h1 { font-size: 24px; }
  .kv:not(.kv-stack) { grid-template-columns: 1fr; gap: 2px; }
  .kv:not(.kv-stack) dd { margin-bottom: 10px; }
}
@media (max-width: 480px) {
  .topbar .brand-word { display: none; }
  .collapse-xs { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .checklist { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
}

/* ---------- Instance Nox (máy từ xa) ---------- */
.alert-info { background: rgba(200, 242, 90, .06); border-color: rgba(200, 242, 90, .25); }
.alert-info .icon { color: var(--accent); }
.badge-pulse::before { animation: pulse-warn 1.6s var(--ease) infinite; }
@keyframes pulse-warn { 0% { box-shadow: 0 0 0 0 rgba(242, 179, 61, .65); } 70%, 100% { box-shadow: 0 0 0 6px rgba(242, 179, 61, 0); } }
@media (prefers-reduced-motion: reduce) { .badge-pulse::before { animation: none; } }
