/* =====================================================================
 * NVR Key Store — Admin UI design system
 * Viết tay, không phụ thuộc CDN/framework. Nạp trực tiếp từ public/assets.
 * Bảng màu categorical/status lấy theo bộ palette đã validate (xem báo cáo
 * cuối nhiệm vụ) — chart-1 = xanh dương, chart-2 = cam, status cố định
 * không đổi theo theme.
 * ===================================================================== */

/* ---------- Reset tối giản ---------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body,
h1,
h2,
h3,
h4,
p,
figure,
blockquote,
dl,
dd,
ul,
ol {
  margin: 0;
}

ul,
ol {
  padding: 0;
  list-style: none;
}

img,
svg {
  display: block;
  max-width: 100%;
}

a {
  color: inherit;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

table {
  border-collapse: collapse;
  width: 100%;
}

/* ---------- Design tokens — light (mặc định) ---------- */
:root {
  color-scheme: light;

  /* Nền */
  --bg-page: #f9f9f7;
  --bg-surface: #fcfcfb;
  --bg-surface-raised: #ffffff;
  --bg-sidebar: #f3f2ee;
  --bg-hover: #eeede8;
  --bg-input: #ffffff;
  --bg-code: #f0efec;

  /* Chữ */
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --text-on-accent: #ffffff;

  /* Viền / lưới */
  --border: rgba(11, 11, 11, 0.12);
  --border-strong: rgba(11, 11, 11, 0.22);
  --grid: #e1e0d9;
  --baseline: #c3c2b7;

  /* Accent (thương hiệu) — trùng chart-1 */
  --accent: #2a78d6;
  --accent-hover: #1c5cab;
  --accent-wash: rgba(42, 120, 214, 0.12);

  /* Biểu đồ — categorical, thứ tự cố định, không đảo */
  --chart-1: #2a78d6; /* upload */
  --chart-2: #eb6834; /* claim */
  --chart-3: #1baf7a;
  --chart-4: #eda100;

  /* Trạng thái — cố định, không đổi theo theme */
  --status-good: #0ca30c;
  --status-good-bg: rgba(12, 163, 12, 0.12);
  --status-warning: #b9790f;
  --status-warning-bg: rgba(250, 178, 25, 0.18);
  --status-serious: #c85f39;
  --status-serious-bg: rgba(236, 131, 90, 0.16);
  --status-critical: #d03b3b;
  --status-critical-bg: rgba(208, 59, 59, 0.12);
  --status-neutral: #4a3aa7;
  --status-neutral-bg: rgba(74, 58, 167, 0.12);

  /* Bóng đổ + bo góc */
  --shadow-sm: 0 1px 2px rgba(11, 11, 11, 0.06);
  --shadow-md: 0 6px 20px rgba(11, 11, 11, 0.10);
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;

  --sidebar-w: 248px;
  --topbar-h: 60px;
}

/* ---------- Dark theo hệ điều hành (chỉ áp dụng khi chưa ép light) ---------- */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;

    --bg-page: #0d0d0d;
    --bg-surface: #1a1a19;
    --bg-surface-raised: #202020;
    --bg-sidebar: #161615;
    --bg-hover: #262624;
    --bg-input: #201f1e;
    --bg-code: #201f1e;

    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --text-on-accent: #ffffff;

    --border: rgba(255, 255, 255, 0.12);
    --border-strong: rgba(255, 255, 255, 0.24);
    --grid: #2c2c2a;
    --baseline: #383835;

    --accent: #3987e5;
    --accent-hover: #6da7ec;
    --accent-wash: rgba(57, 135, 229, 0.18);

    --chart-1: #3987e5;
    --chart-2: #d95926;
    --chart-3: #199e70;
    --chart-4: #c98500;

    --status-good: #0ca30c;
    --status-good-bg: rgba(12, 163, 12, 0.20);
    --status-warning: #fab219;
    --status-warning-bg: rgba(250, 178, 25, 0.20);
    --status-serious: #ec835a;
    --status-serious-bg: rgba(236, 131, 90, 0.20);
    --status-critical: #e66767;
    --status-critical-bg: rgba(208, 59, 59, 0.22);
    --status-neutral: #9085e9;
    --status-neutral-bg: rgba(144, 133, 233, 0.20);

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 10px 28px rgba(0, 0, 0, 0.45);
  }
}

/* ---------- Ép dark bằng nút chuyển (thắng cả OS) ---------- */
:root[data-theme="dark"] {
  color-scheme: dark;

  --bg-page: #0d0d0d;
  --bg-surface: #1a1a19;
  --bg-surface-raised: #202020;
  --bg-sidebar: #161615;
  --bg-hover: #262624;
  --bg-input: #201f1e;
  --bg-code: #201f1e;

  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #898781;
  --text-on-accent: #ffffff;

  --border: rgba(255, 255, 255, 0.12);
  --border-strong: rgba(255, 255, 255, 0.24);
  --grid: #2c2c2a;
  --baseline: #383835;

  --accent: #3987e5;
  --accent-hover: #6da7ec;
  --accent-wash: rgba(57, 135, 229, 0.18);

  --chart-1: #3987e5;
  --chart-2: #d95926;
  --chart-3: #199e70;
  --chart-4: #c98500;

  --status-good: #0ca30c;
  --status-good-bg: rgba(12, 163, 12, 0.20);
  --status-warning: #fab219;
  --status-warning-bg: rgba(250, 178, 25, 0.20);
  --status-serious: #ec835a;
  --status-serious-bg: rgba(236, 131, 90, 0.20);
  --status-critical: #e66767;
  --status-critical-bg: rgba(208, 59, 59, 0.22);
  --status-neutral: #9085e9;
  --status-neutral-bg: rgba(144, 133, 233, 0.20);

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 10px 28px rgba(0, 0, 0, 0.45);
}

/* ---------- Ép light bằng nút chuyển (thắng cả OS dark) ---------- */
:root[data-theme="light"] {
  color-scheme: light;

  --bg-page: #f9f9f7;
  --bg-surface: #fcfcfb;
  --bg-surface-raised: #ffffff;
  --bg-sidebar: #f3f2ee;
  --bg-hover: #eeede8;
  --bg-input: #ffffff;
  --bg-code: #f0efec;

  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --text-on-accent: #ffffff;

  --border: rgba(11, 11, 11, 0.12);
  --border-strong: rgba(11, 11, 11, 0.22);
  --grid: #e1e0d9;
  --baseline: #c3c2b7;

  --accent: #2a78d6;
  --accent-hover: #1c5cab;
  --accent-wash: rgba(42, 120, 214, 0.12);

  --chart-1: #2a78d6;
  --chart-2: #eb6834;
  --chart-3: #1baf7a;
  --chart-4: #eda100;

  --status-good: #0ca30c;
  --status-good-bg: rgba(12, 163, 12, 0.12);
  --status-warning: #b9790f;
  --status-warning-bg: rgba(250, 178, 25, 0.18);
  --status-serious: #c85f39;
  --status-serious-bg: rgba(236, 131, 90, 0.16);
  --status-critical: #d03b3b;
  --status-critical-bg: rgba(208, 59, 59, 0.12);
  --status-neutral: #4a3aa7;
  --status-neutral-bg: rgba(74, 58, 167, 0.12);

  --shadow-sm: 0 1px 2px rgba(11, 11, 11, 0.06);
  --shadow-md: 0 6px 20px rgba(11, 11, 11, 0.10);
}

/* ---------- Nền tảng ---------- */
html {
  font-size: 16px;
}

body {
  background: var(--bg-page);
  color: var(--text-primary);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.num {
  font-variant-numeric: tabular-nums;
}

code,
.mono {
  font-family: ui-monospace, "Cascadia Mono", "Consolas", monospace;
}

/* =====================================================================
 * Layout khung admin: sidebar cố định + topbar + content
 * ===================================================================== */
.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}

.sidebar {
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  z-index: 40;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 18px 14px;
  border-bottom: 1px solid var(--border);
}

.sidebar-brand img,
.sidebar-brand svg {
  width: 28px;
  height: 28px;
  flex: none;
}

.sidebar-brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}

.sidebar-brand-text strong {
  font-size: 14px;
}

.sidebar-brand-text span {
  font-size: 11px;
  color: var(--text-muted);
}

.sidebar-nav {
  flex: 1;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  text-decoration: none;
  color: var(--text-secondary);
  font-size: 13.5px;
  font-weight: 500;
}

.sidebar-nav a:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.sidebar-nav a.active {
  background: var(--accent-wash);
  color: var(--accent);
}

.sidebar-nav .nav-icon {
  width: 17px;
  height: 17px;
  flex: none;
  opacity: 0.9;
}

.sidebar-status {
  margin: 8px 10px 14px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  font-size: 12px;
  color: var(--text-secondary);
}

.sidebar-status h4 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin-bottom: 8px;
  font-weight: 600;
}

.sidebar-status-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 3px 0;
}

.sidebar-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex: none;
  display: inline-block;
}

.sidebar-status-dot.ok { background: var(--status-good); }
.sidebar-status-dot.warn { background: var(--status-warning); }
.sidebar-status-dot.bad { background: var(--status-critical); }

.sidebar-logout {
  margin: 0 10px 14px;
}

.sidebar-logout button {
  width: 100%;
}

.main-col {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  height: var(--topbar-h);
  border-bottom: 1px solid var(--border);
  background: var(--bg-surface);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  position: sticky;
  top: 0;
  z-index: 30;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.drawer-toggle {
  display: none;
}

.breadcrumb {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-secondary);
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.breadcrumb strong {
  color: var(--text-primary);
  font-weight: 600;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-btn {
  width: 34px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-surface-raised);
  cursor: pointer;
}

.icon-btn:hover {
  background: var(--bg-hover);
}

.icon-btn svg {
  width: 17px;
  height: 17px;
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 10px 5px 6px;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 12.5px;
  background: var(--bg-surface-raised);
}

.user-avatar {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--text-on-accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  flex: none;
}

.user-role {
  color: var(--text-muted);
}

.content {
  padding: 22px 24px 60px;
  flex: 1;
}

.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.page-head h1 {
  font-size: 20px;
  font-weight: 700;
}

.page-head p {
  color: var(--text-secondary);
  font-size: 13px;
  margin-top: 4px;
}

.page-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.drawer-backdrop {
  display: none;
}

/* =====================================================================
 * Thẻ / khối chung
 * ===================================================================== */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px;
}

.card + .card {
  margin-top: 16px;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.card-head h2 {
  font-size: 15px;
  font-weight: 700;
}

.card-head p {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.grid {
  display: grid;
  gap: 16px;
}

.grid-cols-2 { grid-template-columns: repeat(2, 1fr); }
.grid-cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid-cols-4 { grid-template-columns: repeat(4, 1fr); }

.two-col {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 16px;
  align-items: start;
}

/* =====================================================================
 * Stat tile
 * ===================================================================== */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 14px;
  margin-bottom: 18px;
}

.stat-tile {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.stat-tile .stat-label {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 600;
}

.stat-tile .stat-value {
  font-size: 26px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}

.stat-tile .stat-delta {
  font-size: 12px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  width: fit-content;
  padding: 2px 7px;
  border-radius: 999px;
}

.stat-delta.up { color: var(--status-good); background: var(--status-good-bg); }
.stat-delta.down { color: var(--status-critical); background: var(--status-critical-bg); }
.stat-delta.flat { color: var(--text-muted); background: var(--bg-hover); }

.stat-tile.accent-1 { border-top: 3px solid var(--chart-1); }
.stat-tile.accent-2 { border-top: 3px solid var(--status-good); }
.stat-tile.accent-3 { border-top: 3px solid var(--status-neutral); }
.stat-tile.accent-4 { border-top: 3px solid var(--chart-2); }
.stat-tile.accent-5 { border-top: 3px solid var(--status-critical); }
.stat-tile.accent-6 { border-top: 3px solid var(--text-muted); }

/* =====================================================================
 * Bảng dữ liệu
 * ===================================================================== */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}

table.data-table {
  width: 100%;
  font-size: 13px;
  min-width: 640px;
}

.data-table thead th {
  position: sticky;
  top: 0;
  background: var(--bg-surface-raised);
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  font-weight: 600;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  z-index: 5;
}

.data-table td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--grid);
  vertical-align: middle;
  color: var(--text-primary);
}

.data-table tbody tr:nth-child(even) {
  background: var(--bg-surface-raised);
}

.data-table tbody tr:hover {
  background: var(--bg-hover);
}

.data-table td.num,
.data-table th.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.data-table td.mono {
  font-size: 12px;
}

.table-toolbar {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

/* =====================================================================
 * Badge trạng thái
 * ===================================================================== */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  white-space: nowrap;
}

.badge::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  flex: none;
}

.badge-good { color: var(--status-good); background: var(--status-good-bg); }
.badge-warning { color: var(--status-warning); background: var(--status-warning-bg); }
.badge-serious { color: var(--status-serious); background: var(--status-serious-bg); }
.badge-critical { color: var(--status-critical); background: var(--status-critical-bg); }
.badge-neutral { color: var(--status-neutral); background: var(--status-neutral-bg); }
.badge-accent { color: var(--accent); background: var(--accent-wash); }
.badge-muted { color: var(--text-muted); background: var(--bg-hover); }

/* =====================================================================
 * Nút bấm
 * ===================================================================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  line-height: 1.2;
  transition: background-color .12s ease, border-color .12s ease, opacity .12s ease;
}

.btn:disabled {
  opacity: .5;
  cursor: not-allowed;
}

.btn svg {
  width: 15px;
  height: 15px;
}

.btn-primary {
  background: var(--accent);
  color: var(--text-on-accent);
  border-color: var(--accent);
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.btn-ghost {
  background: transparent;
  color: var(--text-primary);
  border-color: var(--border-strong);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--bg-hover);
}

.btn-danger {
  background: transparent;
  color: var(--status-critical);
  border-color: var(--status-critical);
}

.btn-danger:hover:not(:disabled) {
  background: var(--status-critical-bg);
}

.btn-danger.btn-solid {
  background: var(--status-critical);
  color: #fff;
  border-color: var(--status-critical);
}

.btn-sm {
  padding: 5px 10px;
  font-size: 12px;
}

.btn-block {
  width: 100%;
}

/* =====================================================================
 * Form
 * ===================================================================== */
.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-bottom: 14px;
}

.field label {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-primary);
}

.field .hint {
  font-size: 11.5px;
  color: var(--text-muted);
  line-height: 1.4;
}

.field .error-text {
  font-size: 11.5px;
  color: var(--status-critical);
}

.input,
select.input,
textarea.input {
  background: var(--bg-input);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font-size: 13px;
  color: var(--text-primary);
  width: 100%;
}

.input:focus,
select.input:focus,
textarea.input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-color: var(--accent);
}

.input.small {
  padding: 6px 8px;
  font-size: 12.5px;
}

textarea.input {
  resize: vertical;
  min-height: 70px;
  font-family: ui-monospace, "Cascadia Mono", "Consolas", monospace;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0 16px;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 13px;
  padding: 4px 0;
}

.checkbox-group {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
}

/* Toggle switch cho cờ 0/1 */
.switch {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
}

.switch input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
}

.switch .track {
  width: 38px;
  height: 22px;
  border-radius: 999px;
  background: var(--bg-hover);
  border: 1px solid var(--border-strong);
  position: relative;
  flex: none;
  transition: background-color .15s ease;
}

.switch .track::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--bg-surface-raised);
  box-shadow: var(--shadow-sm);
  transition: transform .15s ease;
}

.switch input:checked + .track {
  background: var(--accent);
  border-color: var(--accent);
}

.switch input:checked + .track::after {
  transform: translateX(16px);
  background: #fff;
}

.switch .switch-label {
  font-size: 13px;
}

/* =====================================================================
 * Toast
 * ===================================================================== */
.toast-region {
  position: fixed;
  right: 18px;
  bottom: 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 200;
  max-width: 340px;
}

.toast {
  background: var(--bg-surface-raised);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  padding: 11px 14px;
  font-size: 13px;
  display: flex;
  align-items: flex-start;
  gap: 8px;
  animation: toast-in .18s ease;
}

.toast.success { border-left-color: var(--status-good); }
.toast.error { border-left-color: var(--status-critical); }
.toast.warning { border-left-color: var(--status-warning); }

.toast button {
  margin-left: auto;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 14px;
  line-height: 1;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* =====================================================================
 * Modal xác nhận
 * ===================================================================== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(11, 11, 11, 0.45);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 300;
  padding: 20px;
}

.modal-backdrop.open {
  display: flex;
}

.modal {
  background: var(--bg-surface-raised);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
  width: 100%;
  max-width: 420px;
  padding: 20px;
}

.modal h3 {
  font-size: 15px;
  margin-bottom: 8px;
}

.modal p {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.5;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 18px;
}

/* Khối hiện token 1 lần */
.reveal-box {
  border: 1px dashed var(--accent);
  background: var(--accent-wash);
  border-radius: var(--radius-md);
  padding: 14px;
  margin-bottom: 18px;
}

.reveal-box .reveal-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: .03em;
  margin-bottom: 6px;
}

.reveal-box .reveal-token {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-code);
  border-radius: var(--radius-sm);
  padding: 9px 10px;
  font-family: ui-monospace, "Cascadia Mono", "Consolas", monospace;
  font-size: 13px;
  word-break: break-all;
}

.reveal-box .reveal-warn {
  margin-top: 8px;
  font-size: 12px;
  color: var(--status-serious);
}

/* =====================================================================
 * Empty state
 * ===================================================================== */
.empty-state {
  text-align: center;
  padding: 46px 20px;
  color: var(--text-muted);
}

.empty-state svg {
  width: 40px;
  height: 40px;
  margin: 0 auto 12px;
  opacity: .6;
}

.empty-state h3 {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.empty-state p {
  font-size: 12.5px;
}

/* =====================================================================
 * Pagination keyset
 * ===================================================================== */
.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 14px;
  font-size: 12.5px;
  color: var(--text-muted);
}

.pagination .pager-btns {
  display: flex;
  gap: 8px;
}

/* =====================================================================
 * Biểu đồ SVG (render phía server)
 * ===================================================================== */
.chart-wrap {
  overflow-x: auto;
}

.chart-legend {
  display: flex;
  gap: 16px;
  margin-top: 10px;
  font-size: 12px;
  color: var(--text-secondary);
  flex-wrap: wrap;
}

.chart-legend .legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
}

.chart-legend .swatch {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  flex: none;
}

.chart-svg text {
  fill: var(--text-muted);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.chart-svg .bar:hover {
  opacity: 0.82;
}

/* =====================================================================
 * Alert / banner
 * ===================================================================== */
.alert {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  font-size: 13px;
  margin-bottom: 16px;
  border: 1px solid transparent;
}

.alert svg {
  width: 17px;
  height: 17px;
  flex: none;
  margin-top: 1px;
}

.alert-warning {
  background: var(--status-warning-bg);
  color: var(--status-warning);
  border-color: var(--status-warning);
}

.alert-critical {
  background: var(--status-critical-bg);
  color: var(--status-critical);
  border-color: var(--status-critical);
}

.alert-good {
  background: var(--status-good-bg);
  color: var(--status-good);
  border-color: var(--status-good);
}

.alert-neutral {
  background: var(--accent-wash);
  color: var(--accent);
  border-color: var(--accent);
}

.alert strong { color: inherit; }

/* =====================================================================
 * Trang đăng nhập
 * ===================================================================== */
.auth-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-page);
  padding: 20px;
}

.auth-card {
  width: 100%;
  max-width: 360px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: 28px 26px;
}

.auth-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  margin-bottom: 22px;
  text-align: center;
}

.auth-brand svg {
  width: 40px;
  height: 40px;
}

.auth-brand h1 {
  font-size: 17px;
  font-weight: 700;
}

.auth-brand p {
  font-size: 12.5px;
  color: var(--text-muted);
}

.auth-footer {
  margin-top: 16px;
  text-align: center;
  font-size: 11.5px;
  color: var(--text-muted);
}

/* =====================================================================
 * Tiện ích
 * ===================================================================== */
.text-muted { color: var(--text-muted); }
.text-secondary { color: var(--text-secondary); }
.text-good { color: var(--status-good); }
.text-critical { color: var(--status-critical); }
.mt-0 { margin-top: 0; }
.mb-0 { margin-bottom: 0; }
.flex { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.hidden { display: none !important; }
.tag-chip {
  display: inline-flex;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--bg-hover);
  font-size: 11.5px;
  color: var(--text-secondary);
}
.masked {
  font-family: ui-monospace, "Cascadia Mono", "Consolas", monospace;
  letter-spacing: 2px;
  color: var(--text-muted);
}

/* =====================================================================
 * Responsive — dưới 900px sidebar thành drawer trượt
 * ===================================================================== */
@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    width: min(84vw, 280px);
    transform: translateX(-100%);
    transition: transform .2s ease;
    box-shadow: var(--shadow-md);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .drawer-toggle {
    display: inline-flex;
  }

  .drawer-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(11, 11, 11, 0.4);
    opacity: 0;
    pointer-events: none;
    transition: opacity .2s ease;
    z-index: 39;
  }

  .drawer-backdrop.open {
    opacity: 1;
    pointer-events: auto;
  }

  .stat-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .grid-cols-2,
  .grid-cols-3,
  .grid-cols-4,
  .two-col,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .content {
    padding: 16px;
  }
}

@media (max-width: 560px) {
  .stat-grid {
    grid-template-columns: 1fr 1fr;
  }
}

/* In (loại trang trí, chỉ giữ nội dung đọc được) */
@media print {
  .sidebar, .topbar, .page-actions, .table-toolbar, .pagination { display: none; }
}
