:root {
  --bg: #EEF1EE;
  --surface: #FFFFFF;
  --surface-2: #F6F8F6;
  --ink: #1B2420;
  --ink-2: #55625C;
  --ink-3: #85918B;
  --line: #D8DED9;
  --jade: #0E7A5F;
  --jade-ink: #FFFFFF;
  --jade-soft: #DCEFE8;
  --gold: #A8791F;
  --gold-soft: #F6ECD6;
  --red: #B23A30;
  --red-soft: #F8E1DE;
  --amber-soft: #F5ECD2;
  --focus: #0E7A5F;
  --rail-bg: #1B2420;
  --rail-ink: #EEF1EE;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(27, 36, 32, .06), 0 4px 16px rgba(27, 36, 32, .06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111715; --surface: #18201D; --surface-2: #1E2723; --ink: #E4EAE6; --ink-2: #A6B2AC; --ink-3: #7B8882;
    --line: #2C3732; --jade: #3DBB93; --jade-ink: #0B1411; --jade-soft: #173A2F; --gold: #DDAE52; --gold-soft: #3A2F18;
    --red: #EB7B70; --red-soft: #3C1E1B; --amber-soft: #352D17; --focus: #3DBB93; --rail-bg: #0B100E; --rail-ink: #E4EAE6;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 6px 20px rgba(0,0,0,.25); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #111715; --surface: #18201D; --surface-2: #1E2723; --ink: #E4EAE6; --ink-2: #A6B2AC; --ink-3: #7B8882;
  --line: #2C3732; --jade: #3DBB93; --jade-ink: #0B1411; --jade-soft: #173A2F; --gold: #DDAE52; --gold-soft: #3A2F18;
  --red: #EB7B70; --red-soft: #3C1E1B; --amber-soft: #352D17; --focus: #3DBB93; --rail-bg: #0B100E; --rail-ink: #E4EAE6;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 6px 20px rgba(0,0,0,.25); color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--ink);
  font: 400 14px/1.5 "Be Vietnam Pro", "Noto Sans SC", system-ui, sans-serif;
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -.01em; }
h1 { font-size: 22px; line-height: 1.25; }
h2 { font-size: 17px; line-height: 1.3; }
h3 { font-size: 14px; }
p { margin: 0; }
a { color: var(--jade); }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
.muted { color: var(--ink-2); }
.faint { color: var(--ink-3); }
.small { font-size: 12.5px; }
.hidden { display: none !important; }
.zh { font-family: "Noto Sans SC", "Be Vietnam Pro", sans-serif; }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: 224px 1fr; min-height: 100vh; }
.side {
  position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 4px;
  padding: 20px 14px; border-right: 1px solid var(--line); background: var(--surface);
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 18px; }
.brand-mark {
  width: 30px; height: 30px; border-radius: 7px; background: var(--jade); color: var(--jade-ink);
  display: grid; place-items: center; font-weight: 700; font-size: 15px; font-family: "Noto Sans SC", sans-serif;
}
.brand b { display: block; font-size: 15px; }
.brand span { font-size: 12px; color: var(--ink-3); }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 6px;
  color: var(--ink-2); text-decoration: none; font-weight: 500;
}
.nav a svg { width: 18px; height: 18px; flex: none; }
.nav a:hover { background: var(--surface-2); color: var(--ink); }
.nav a[aria-current="page"] { background: var(--jade-soft); color: var(--jade); }
.side-foot { margin-top: auto; padding: 12px 8px 0; border-top: 1px solid var(--line); }
.who { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.who b { display: block; font-size: 13px; }
.who span { font-size: 12px; color: var(--ink-3); }

.main { min-width: 0; display: flex; flex-direction: column; }
.page { padding: 22px 28px 60px; max-width: 1440px; width: 100%; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head p { margin-top: 4px; color: var(--ink-2); }

/* ---------- scan rail (điểm nhấn) ---------- */
.rail {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 18px; padding: 10px 28px;
  background: var(--rail-bg); color: var(--rail-ink);
}
.rail .state { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1; }
.rail .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--ink-3); flex: none; }
.rail.on .dot { background: var(--jade); box-shadow: 0 0 0 4px color-mix(in srgb, var(--jade) 30%, transparent); }
.rail.running .dot { background: var(--gold); animation: pulse 1.2s ease-in-out infinite; }
.rail .label { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rail .count { font-size: 22px; font-weight: 600; letter-spacing: -.02em; min-width: 72px; text-align: right; }
.rail .count .pre { font-size: 12px; font-weight: 400; opacity: .7; margin-right: 6px; }
.rail .count small { font-size: 12px; font-weight: 400; opacity: .7; margin-left: 4px; }
.rail .bar {
  position: absolute; left: 0; bottom: 0; height: 3px; background: var(--gold);
  width: 0; transition: width .4s ease;
}
.rail .btn { background: transparent; color: var(--rail-ink); border-color: color-mix(in srgb, var(--rail-ink) 35%, transparent); }
.rail .btn:hover { background: color-mix(in srgb, var(--rail-ink) 12%, transparent); }
.rail .btn.primary { background: var(--jade); border-color: var(--jade); color: var(--jade-ink); }
@keyframes pulse { 50% { opacity: .35; } }

/* ---------- controls ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 34px; padding: 0 14px; border-radius: 6px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); font-weight: 500; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--jade); border-color: var(--jade); color: var(--jade-ink); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { color: var(--red); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.sm { height: 28px; padding: 0 10px; font-size: 13px; }
.btn svg { width: 16px; height: 16px; }
.icon-btn { width: 30px; height: 30px; padding: 0; border-radius: 6px; border: 0; background: transparent; color: var(--ink-2); cursor: pointer; display: inline-grid; place-items: center; }
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }
.icon-btn svg { width: 17px; height: 17px; }

.field { display: flex; flex-direction: column; gap: 5px; }
.field > span { font-weight: 500; font-size: 13px; }
.field small { color: var(--ink-3); font-size: 12px; line-height: 1.4; }
.input, select.input, textarea.input {
  height: 36px; padding: 0 11px; border-radius: 6px; border: 1px solid var(--line);
  background: var(--surface); width: 100%;
}
textarea.input { height: auto; padding: 8px 11px; min-height: 90px; resize: vertical; }
.input:focus { outline: none; border-color: var(--jade); box-shadow: 0 0 0 3px var(--jade-soft); }
.input-row { display: flex; gap: 8px; }
.input-row .input { flex: 1; min-width: 0; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }

.switch { position: relative; display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch i { width: 34px; height: 20px; border-radius: 20px; background: var(--line); position: relative; transition: background .15s; flex: none; }
.switch i::after { content: ""; position: absolute; top: 3px; left: 3px; width: 14px; height: 14px; border-radius: 50%; background: #fff; transition: transform .15s; }
.switch input:checked + i { background: var(--jade); }
.switch input:checked + i::after { transform: translateX(14px); }
.switch input:focus-visible + i { outline: 2px solid var(--focus); outline-offset: 2px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 4px; height: 24px; padding: 0 9px; border-radius: 5px;
  background: var(--surface-2); border: 1px solid var(--line); font-size: 12.5px; white-space: nowrap;
  font-family: "Noto Sans SC", "Be Vietnam Pro", sans-serif;
}
button.chip { cursor: pointer; height: 30px; padding: 0 12px; font-size: 13px; }
button.chip[aria-pressed="true"] { background: var(--jade-soft); border-color: var(--jade); color: var(--jade); font-weight: 500; }
.chip .x { border: 0; background: none; cursor: pointer; color: var(--ink-3); padding: 0 0 0 2px; font-size: 15px; line-height: 1; }

.badge { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 500; padding: 1px 8px; border-radius: 4px; white-space: nowrap; }
.badge.found { background: var(--jade-soft); color: var(--jade); }
.badge.notfound { background: var(--amber-soft); color: var(--gold); }
.badge.error { background: var(--red-soft); color: var(--red); }
.badge.idle { background: var(--surface-2); color: var(--ink-3); }

/* ---------- panels ---------- */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.panel-body { padding: 18px; }
.panel + .panel { margin-top: 16px; }
.stack { display: flex; flex-direction: column; gap: 14px; }

/* tổng quan */
.figures { display: grid; grid-template-columns: repeat(5, 1fr); border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); margin-bottom: 16px; }
.figure { padding: 16px 18px; border-left: 1px solid var(--line); }
.figure:first-child { border-left: 0; }
.figure b { display: block; font-size: 26px; font-weight: 600; letter-spacing: -.02em; line-height: 1.15; }
.figure span { color: var(--ink-2); font-size: 13px; }
.figure.found b { color: var(--jade); }
.figure.nf b { color: var(--gold); }
.figure.err b { color: var(--red); }
.dash-grid { display: grid; grid-template-columns: 1.35fr 1fr; gap: 16px; align-items: start; }
.notice { display: flex; gap: 12px; padding: 12px 16px; border-radius: var(--radius); background: var(--amber-soft); margin-bottom: 14px; align-items: flex-start; }
.notice.err { background: var(--red-soft); }
.notice svg { width: 18px; height: 18px; flex: none; margin-top: 2px; color: var(--gold); }
.notice.err svg { color: var(--red); }

/* ---------- table ---------- */
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.toolbar .input { width: 240px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow-x: auto; max-width: 100%; scrollbar-width: none; }
.seg::-webkit-scrollbar { display: none; }
.seg button { white-space: nowrap; flex: none; border: 0; background: var(--surface); padding: 0 11px; height: 32px; cursor: pointer; color: var(--ink-2); font-weight: 500; border-left: 1px solid var(--line); }
.seg button:first-child { border-left: 0; }
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--bg); }
.bulk { display: flex; align-items: center; gap: 8px; padding: 8px 14px; background: var(--jade-soft); border-bottom: 1px solid var(--line); }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-weight: 500; font-size: 12.5px; color: var(--ink-3); padding: 9px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; background: var(--surface-2); }
td { padding: 11px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: color-mix(in srgb, var(--surface-2) 70%, transparent); }
td.num, th.num { text-align: right; }
.pname { font-weight: 500; max-width: 260px; }
.pids { font-size: 12px; color: var(--ink-3); margin-top: 2px; }
.price { font-size: 17px; font-weight: 600; color: var(--gold); letter-spacing: -.01em; }
.price-cell { display: flex; align-items: center; gap: 10px; }
.spark { width: 64px; height: 22px; flex: none; }
.spark path { fill: none; stroke: var(--gold); stroke-width: 1.5; }
.res-meta { font-size: 12px; color: var(--ink-2); margin-top: 2px; }
.res-meta span { white-space: nowrap; }
td.result { min-width: 250px; }
.cond { font-size: 12.5px; color: var(--ink-2); margin-top: 5px; }
.row-actions { display: flex; gap: 2px; justify-content: flex-end; }
.empty { padding: 48px 20px; text-align: center; color: var(--ink-2); }
.empty h3 { color: var(--ink); margin-bottom: 6px; font-size: 15px; }
.empty .btn { margin-top: 14px; }

/* ---------- drawer / modal ---------- */
.scrim { position: fixed; inset: 0; background: rgba(10, 15, 13, .38); z-index: 20; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(480px, 100%); z-index: 21;
  background: var(--surface); box-shadow: var(--shadow); display: flex; flex-direction: column;
  animation: slidein .18s ease-out;
}
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.drawer-body { padding: 20px; overflow-y: auto; flex: 1; display: flex; flex-direction: column; gap: 16px; }
.drawer-foot { padding: 14px 20px; border-top: 1px solid var(--line); display: flex; gap: 8px; justify-content: flex-end; }
.modal {
  position: fixed; z-index: 21; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: min(560px, calc(100% - 32px)); max-height: calc(100vh - 48px); overflow: auto;
  background: var(--surface); border-radius: 10px; box-shadow: var(--shadow);
}
@keyframes slidein { from { transform: translateX(24px); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

.lookup-result { font-size: 12.5px; padding: 8px 10px; border-radius: 6px; background: var(--jade-soft); color: var(--jade); }
.lookup-result.err { background: var(--red-soft); color: var(--red); }

.toast-wrap { position: fixed; bottom: 20px; right: 20px; z-index: 40; display: flex; flex-direction: column; gap: 8px; }
.toast { background: var(--ink); color: var(--bg); padding: 10px 14px; border-radius: 6px; box-shadow: var(--shadow); max-width: 360px; }
.toast.err { background: var(--red); color: #fff; }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-box { width: min(380px, 100%); }
.login-box .brand { justify-content: center; padding-bottom: 22px; }
.login-box .panel-body { display: flex; flex-direction: column; gap: 14px; }
.err-text { color: var(--red); font-size: 13px; }

/* admin */
.admin-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
.kv { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; border-bottom: 1px dashed var(--line); font-size: 13px; }
.kv:last-child { border-bottom: 0; }
.copy { font-size: 12.5px; word-break: break-all; background: var(--surface-2); padding: 6px 9px; border-radius: 5px; border: 1px solid var(--line); }

.chart { width: 100%; height: 180px; }
.chart .ln { fill: none; stroke: var(--gold); stroke-width: 2; }
.chart .ar { fill: var(--gold-soft); opacity: .7; }
.chart text { fill: var(--ink-3); font-size: 11px; }
.chart .grid { stroke: var(--line); }

/* ---------- mobile ---------- */
@media (max-width: 1100px) {
  .dash-grid, .admin-grid { grid-template-columns: 1fr; }
  .figures { grid-template-columns: repeat(3, 1fr); }
  .figure:nth-child(4) { border-left: 0; }
  .figure:nth-child(n+4) { border-top: 1px solid var(--line); }
}
@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; top: auto; bottom: 0; left: 0; right: 0; height: auto; flex-direction: row; padding: 6px 8px; z-index: 10; border-right: 0; border-top: 1px solid var(--line); }
  .brand, .side-foot { display: none; }
  .nav { display: flex; width: 100%; justify-content: space-around; }
  .nav a { flex-direction: column; gap: 2px; font-size: 11px; padding: 6px 4px; }
  .page { padding: 16px 16px 90px; }
  .rail { padding: 10px 16px; gap: 10px; }
  .rail .count { font-size: 18px; min-width: 0; }
  .rail .hide-sm { display: none; }
  .figures { grid-template-columns: 1fr 1fr; }
  .figure { border-left: 0 !important; border-top: 1px solid var(--line); }
  .figure:nth-child(-n+2) { border-top: 0; }
  .figure:nth-child(even) { border-left: 1px solid var(--line) !important; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .toolbar .input { width: 100%; }
  /* bảng -> thẻ */
  table.cards thead { display: none; }
  table.cards, table.cards tbody, table.cards tr, table.cards td { display: block; width: 100%; }
  table.cards tr { padding: 12px 14px; border-bottom: 1px solid var(--line); position: relative; }
  table.cards td { border: 0; padding: 3px 0; }
  table.cards td.sel { position: absolute; right: 12px; top: 12px; width: auto; }
  table.cards td.num { text-align: left; }
  table.cards .row-actions { justify-content: flex-start; margin-top: 6px; }
  .toast-wrap { left: 16px; right: 16px; bottom: 80px; }
}
