:root {
  --bg: #f3f7fd;
  --panel: #ffffff;
  --panel-2: #f7faff;
  --text: #1d2f52;
  --muted: #6b7fa3;
  --line: #dde7f5;
  --brand: #2f7cff;
  --brand-2: #1859ff;
  --brand-soft: #eaf2ff;
  --ok: #1f8a4c;   --ok-bg: #eaf8ef;   --ok-line: #c3e8cf;
  --bad: #b4234a;  --bad-bg: #fff0f3;  --bad-line: #f3c4d0;
  --warn: #8a6212; --warn-bg: #fff7e5; --warn-line: #f0dcab;
  --info: #36568d; --info-bg: #f2f7ff; --info-line: #d5e4ff;
  --shadow: 0 6px 20px rgba(40, 90, 170, .08);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1422; --panel: #151d2f; --panel-2: #1a2438; --text: #e3eaf7; --muted: #8fa0c0;
    --line: #26324a; --brand: #4d8fff; --brand-2: #2f6dff; --brand-soft: #1b2a47;
    --ok: #5fd08f; --ok-bg: #11291d; --ok-line: #1f4a33;
    --bad: #ff7f9c; --bad-bg: #2c1420; --bad-line: #522436;
    --warn: #f0c56a; --warn-bg: #2b2312; --warn-line: #4d3f1d;
    --info: #9cb9ec; --info-bg: #172338; --info-line: #263a5c;
    --shadow: 0 6px 20px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0e1422; --panel: #151d2f; --panel-2: #1a2438; --text: #e3eaf7; --muted: #8fa0c0;
  --line: #26324a; --brand: #4d8fff; --brand-2: #2f6dff; --brand-soft: #1b2a47;
  --ok: #5fd08f; --ok-bg: #11291d; --ok-line: #1f4a33;
  --bad: #ff7f9c; --bad-bg: #2c1420; --bad-line: #522436;
  --warn: #f0c56a; --warn-bg: #2b2312; --warn-line: #4d3f1d;
  --info: #9cb9ec; --info-bg: #172338; --info-line: #263a5c;
  --shadow: 0 6px 20px rgba(0, 0, 0, .3);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
}
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h2 { font-size: 20px; margin-bottom: 14px; }
h3 { font-size: 15px; margin-bottom: 10px; }
code { font-family: ui-monospace, Consolas, monospace; font-size: .92em; background: var(--brand-soft); padding: 1px 5px; border-radius: 5px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }

input, select {
  font: inherit; color: var(--text); background: var(--panel);
  border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; min-width: 0;
  outline: none; transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus { border-color: var(--brand); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 18%, transparent); }

.btn {
  font: inherit; font-weight: 650; border-radius: 10px; padding: 9px 16px; cursor: pointer;
  border: 1px solid var(--line); background: var(--panel); color: var(--text);
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; text-decoration: none; white-space: nowrap;
}
.btn:hover { border-color: var(--brand); }
.btn:disabled { opacity: .6; cursor: wait; }
.btn.primary { background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: #fff; border-color: transparent; }
.btn.primary:hover { filter: brightness(1.05); }
.btn.ghost { background: transparent; }
.btn.sm { padding: 5px 10px; font-size: 12.5px; border-radius: 8px; }
.btn.danger { color: var(--bad); }
.btn.danger:hover { border-color: var(--bad); }
.btn.okb { color: var(--ok); }
.btn.okb:hover { border-color: var(--ok); }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: 100%; max-width: 360px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 18px; padding: 28px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 12px;
}
.login-card h1 { font-size: 21px; }
.login-card p { margin: -6px 0 6px; }
.login-card label { display: flex; flex-direction: column; gap: 5px; font-weight: 600; font-size: 13px; }
.form-err { color: var(--bad); font-size: 13px; min-height: 18px; }
.logo { width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; font-size: 22px;
  background: linear-gradient(135deg, #3075ff, #94ccff); color: #fff; }
.logo.sm { width: 30px; height: 30px; font-size: 16px; border-radius: 9px; }

/* Layout */
.app { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.side {
  background: var(--panel); border-right: 1px solid var(--line); padding: 18px 12px;
  display: flex; flex-direction: column; gap: 18px; position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 16px; padding: 0 6px; }
nav { display: flex; flex-direction: column; gap: 4px; }
nav button {
  font: inherit; text-align: left; border: 0; background: transparent; color: var(--text);
  padding: 10px 12px; border-radius: 10px; cursor: pointer; display: flex; align-items: center; gap: 10px;
}
nav button:hover { background: var(--panel-2); }
nav button.active { background: var(--brand-soft); color: var(--brand); font-weight: 700; }
.badge { font-style: normal; margin-left: auto; background: var(--bad); color: #fff; font-size: 11px; font-weight: 700;
  border-radius: 999px; padding: 1px 7px; }
.logout { margin-top: auto; }
main { padding: 24px; max-width: 1180px; width: 100%; min-width: 0; }
section { display: flex; flex-direction: column; gap: 16px; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 16px; box-shadow: var(--shadow); min-width: 0; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 8px; }
.card-head h3 { margin: 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.tag { display: inline-block; font-size: 10.5px; font-weight: 700; padding: 0 6px; border-radius: 5px; margin-right: 4px; background: var(--brand-soft); color: var(--brand); }
.banner { border-radius: 12px; padding: 10px 14px; margin-bottom: 16px; border: 1px solid; }
.banner.warn { background: var(--warn-bg); border-color: var(--warn-line); color: var(--warn); }

.stats { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; box-shadow: var(--shadow); }
.stat .n { font-size: 26px; font-weight: 800; font-variant-numeric: tabular-nums; }
.stat .l { color: var(--muted); font-size: 12.5px; }
.stat.ok .n { color: var(--ok); } .stat.bad .n { color: var(--bad); } .stat.warn .n { color: var(--warn); }

.status-line { display: flex; align-items: center; gap: 8px; font-weight: 650; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); flex: 0 0 auto; }
.dot.on { background: var(--ok); box-shadow: 0 0 0 4px color-mix(in srgb, var(--ok) 20%, transparent); }
.dot.off { background: var(--bad); }
.dot.mid { background: var(--warn); }
.note { margin: 8px 0 0; font-size: 12.5px; color: var(--muted); }
.note.err { color: var(--bad); }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; margin: 10px 0 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }

/* Tables */
.table-wrap { overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.tbl th { text-align: left; color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .3px;
  padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl td { padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl .empty { text-align: center; color: var(--muted); padding: 22px; }
.tbl .nowrap { white-space: nowrap; }
.tbl .acts { display: flex; gap: 6px; justify-content: flex-end; }
.tbl input.inline { padding: 5px 8px; border-radius: 8px; width: 100%; min-width: 120px; background: transparent; border-color: transparent; }
.tbl input.inline:hover { border-color: var(--line); }
.tbl input.inline:focus { background: var(--panel); border-color: var(--brand); }
.pill { display: inline-block; font-size: 12px; font-weight: 700; padding: 2px 9px; border-radius: 999px; border: 1px solid; white-space: nowrap; }
.pill.ok { color: var(--ok); background: var(--ok-bg); border-color: var(--ok-line); }
.pill.bad { color: var(--bad); background: var(--bad-bg); border-color: var(--bad-line); }
.pill.warn { color: var(--warn); background: var(--warn-bg); border-color: var(--warn-line); }
.pill.error, .pill.notfound { color: var(--muted); background: var(--panel-2); border-color: var(--line); }
.pill.off { color: var(--muted); background: var(--panel-2); border-color: var(--line); }
.src { font-size: 11px; color: var(--muted); }

/* Forms */
.lookup-form { display: flex; gap: 10px; }
.lookup-form input { flex: 1; font-size: 16px; padding: 12px 14px; }
.add-staff .row, .settings .row { display: flex; gap: 10px; }
.add-staff .row input { flex: 1; }
.filter { display: flex; gap: 10px; flex-wrap: wrap; }
.filter input { flex: 1 1 220px; }
.settings { display: flex; flex-direction: column; gap: 14px; }
.settings .field label { font-weight: 650; display: block; margin-bottom: 6px; }
.settings .row input { flex: 1; }
.settings .hint { font-size: 12.5px; color: var(--muted); margin-top: 4px; }
.settings .actions { display: flex; gap: 10px; flex-wrap: wrap; }
.more { margin: 12px auto 0; display: flex; }

/* Kết quả tra cứu */
.result { display: flex; flex-direction: column; gap: 8px; max-width: 680px; }
.rc { border: 1px solid; border-radius: 12px; padding: 12px 14px; overflow-wrap: anywhere; }
.rc.ok { background: var(--ok-bg); border-color: var(--ok-line); color: var(--ok); }
.rc.bad { background: var(--bad-bg); border-color: var(--bad-line); color: var(--bad); }
.rc.warn { background: var(--warn-bg); border-color: var(--warn-line); color: var(--warn); }
.rc.info { background: var(--info-bg); border-color: var(--info-line); color: var(--info); }
.rc .t { font-weight: 800; }
.rc .mono { font-family: ui-monospace, Consolas, monospace; font-weight: 700; }
.rc .sub { font-size: 12.5px; opacity: .9; }
.verdict { font-size: 17px; font-weight: 800; }

#toast {
  position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%) translateY(20px); opacity: 0;
  background: var(--text); color: var(--panel); padding: 10px 16px; border-radius: 10px; font-weight: 600;
  transition: all .2s; pointer-events: none; max-width: calc(100vw - 32px); z-index: 50;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.err { background: var(--bad); color: #fff; }

@media (max-width: 960px) {
  .stats { grid-template-columns: repeat(3, 1fr); }
  .grid2, .grid3 { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .side { position: sticky; top: 0; z-index: 10; height: auto; flex-direction: row; align-items: center; padding: 8px 12px; gap: 8px; border-right: 0; border-bottom: 1px solid var(--line); }
  .brand { display: none; }
  nav { flex-direction: row; flex: 1; overflow-x: auto; gap: 2px; }
  nav button { padding: 8px 10px; white-space: nowrap; }
  nav button span { display: none; }
  nav button.active span { display: inline; }
  .logout { margin: 0; }
  main { padding: 16px; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .lookup-form, .add-staff .row { flex-direction: column; }
}
