:root {
  color-scheme: light;
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #e2e5ea;
  --text: #15181d;
  --text-2: #4a515c;
  --muted: #6b7280;
  --primary: #2a62d6;
  --primary-hover: #234fb0;
  --primary-ink: #ffffff;
  --focus: #2a78d6;
  --series-1: #2a78d6;
  --series-1-hover: #1c5cab;
  --grid: #e7e9ed;
  --ok: #157a3c;    --ok-bg: #e6f4ea;
  --warn: #9a5b00;  --warn-bg: #fdf1dc;
  --bad: #c4291c;   --bad-bg: #fdeaea;
  --info: #2450a8;  --info-bg: #e7eefc;
  --neutral-bg: #eceef2;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .07);
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0f1115;
    --surface: #171a20;
    --surface-2: #1f232b;
    --border: #2b303a;
    --text: #eceef2;
    --text-2: #c2c7d0;
    --muted: #9aa1ad;
    --primary: #3f7fe8;
    --primary-hover: #5a92ee;
    --focus: #5598e7;
    --series-1: #3987e5;
    --series-1-hover: #6da7ec;
    --grid: #262b34;
    --ok: #4cc27a;    --ok-bg: #16301f;
    --warn: #f0b04a;  --warn-bg: #33270f;
    --bad: #f07a6f;   --bad-bg: #3a1a18;
    --info: #8db3f5;  --info-bg: #182640;
    --neutral-bg: #262a33;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h2 { font-size: 16px; font-weight: 650; }
h3 { font-size: 15px; font-weight: 650; }
code, pre, .mono { font-family: var(--mono); font-size: 12.5px; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
[hidden] { display: none !important; }
.boot { padding: 40px; text-align: center; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.pos { color: var(--ok); }
.neg { color: var(--bad); }

/* ---------- khung trang ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: 1200px; margin: 0 auto; padding: 0 16px;
  display: flex; align-items: center; gap: 16px; min-height: 56px;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; white-space: nowrap; }
.brand-mark {
  width: 26px; height: 26px; border-radius: 7px; display: grid; place-items: center;
  background: var(--primary); color: var(--primary-ink); font-size: 13px;
}
.nav { display: flex; gap: 2px; overflow-x: auto; flex: 1; scrollbar-width: none; }
.nav::-webkit-scrollbar { display: none; }
.nav a {
  padding: 8px 12px; border-radius: 8px; color: var(--text-2); white-space: nowrap; font-weight: 500;
}
.nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav a.active { background: var(--info-bg); color: var(--info); }
.main { max-width: 1200px; margin: 0 auto; padding: 20px 16px 64px; }
.view > * + * { margin-top: 16px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.page-head h1 { font-size: 20px; font-weight: 700; }
@media (max-width: 720px) {
  .topbar-inner { flex-wrap: wrap; gap: 4px 12px; padding-top: 8px; }
  .brand { flex: 1; }
  .nav { order: 3; flex-basis: 100%; padding-bottom: 6px; }
  .main { padding-top: 16px; }
}

/* ---------- thẻ ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px;
}
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.grid { display: grid; gap: 12px; }
.kpis { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.todo { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 960px) { .kpis, .todo { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 420px) { .kpis, .todo { grid-template-columns: 1fr; } }
.kpi-label { color: var(--muted); font-size: 12.5px; font-weight: 500; }
.kpi-value { font-size: 22px; font-weight: 700; margin: 2px 0 4px; font-variant-numeric: tabular-nums; }
.kpi-sub { font-size: 12.5px; color: var(--text-2); font-variant-numeric: tabular-nums; }
a.todo-item { display: block; color: inherit; }
a.todo-item:hover { text-decoration: none; border-color: var(--focus); }
.todo-item .kpi-value { font-size: 20px; }
.todo-item.attn { border-left: 3px solid var(--warn); }

/* ---------- nút & ô nhập ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 36px; padding: 0 14px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 550; cursor: pointer;
  white-space: nowrap; text-decoration: none;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:disabled { opacity: .55; cursor: progress; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn.primary:hover { background: var(--primary-hover); }
.btn.danger { color: var(--bad); border-color: currentColor; background: transparent; }
.btn.danger:hover { background: var(--bad-bg); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.sm { min-height: 30px; padding: 0 10px; font-size: 13px; }
.btn.block { width: 100%; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
input[type="text"], input[type="password"], input[type="search"], input[type="number"], input:not([type]),
select, textarea {
  width: 100%; min-height: 36px; padding: 7px 10px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); color: var(--text); font: inherit;
}
textarea { resize: vertical; line-height: 1.45; }
textarea.mono { font-family: var(--mono); font-size: 12.5px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--focus); outline-offset: -1px; border-color: transparent; }
.field { display: block; }
.field-label { display: block; font-weight: 550; margin-bottom: 4px; font-size: 13px; }
.hint { display: block; color: var(--muted); font-size: 12px; margin-top: 4px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.form-grid .span-2 { grid-column: 1 / -1; }
@media (max-width: 560px) { .form-grid { grid-template-columns: 1fr; } }
.check { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.check input { width: 16px; height: 16px; margin: 0; }
.form-error { color: var(--bad); min-height: 1.5em; margin: 6px 0; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.toolbar input[type="search"] { max-width: 280px; }
.toolbar select { width: auto; max-width: 100%; }
.tier-row { display: grid; grid-template-columns: 1fr 1fr auto; gap: 8px; margin-bottom: 8px; align-items: center; }

/* ---------- chip lọc ---------- */
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--border); background: var(--surface); color: var(--text-2);
  border-radius: 999px; padding: 4px 12px; font: inherit; font-size: 13px; cursor: pointer;
}
.chip:hover { background: var(--surface-2); }
.chip[aria-pressed="true"] { background: var(--info-bg); border-color: transparent; color: var(--info); font-weight: 600; }
.chip .count { margin-left: 4px; opacity: .75; font-variant-numeric: tabular-nums; }

/* ---------- bảng ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 9px 12px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
.table .num { text-align: right; }
.table th { font-size: 12px; font-weight: 600; color: var(--muted); background: var(--surface-2); white-space: nowrap; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tr.clickable { cursor: pointer; }
.table tr.clickable:hover td { background: var(--surface-2); }
.table td.empty { text-align: center; color: var(--muted); padding: 28px 12px; }
.table .content-cell { max-width: 520px; }
.clip { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 520px; }
.sub { display: block; color: var(--muted); font-size: 12px; }
.pager { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 10px; }

/* ---------- nhãn trạng thái ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 999px;
  font-size: 12px; font-weight: 600; white-space: nowrap;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.bad { background: var(--bad-bg); color: var(--bad); }
.badge.info { background: var(--info-bg); color: var(--info); }
.badge.muted { background: var(--neutral-bg); color: var(--muted); }

/* ---------- công tắc ---------- */
.switch { position: relative; display: inline-flex; align-items: center; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch .track {
  width: 36px; height: 20px; border-radius: 999px; background: var(--border); position: relative; transition: background .15s;
}
.switch .track::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.3); transition: transform .15s;
}
.switch input:checked + .track { background: var(--primary); }
.switch input:checked + .track::after { transform: translateX(16px); }
.switch input:focus-visible + .track { outline: 2px solid var(--focus); outline-offset: 2px; }

/* ---------- biểu đồ ---------- */
.chart-wrap { position: relative; }
.chart { display: block; width: 100%; height: auto; overflow: visible; }
.chart .grid-line { stroke: var(--grid); stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 11px; }
.chart .bar { fill: var(--series-1); }
.chart .hit { fill: transparent; cursor: default; }
.chart .hit:focus { outline: none; }
.chart g.col:hover .bar, .chart g.col:focus-within .bar { fill: var(--series-1-hover); }
.chart .baseline { stroke: var(--border); stroke-width: 1; }
.tooltip {
  position: absolute; pointer-events: none; z-index: 5; min-width: 150px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 4px 16px rgba(0,0,0,.14);
  padding: 8px 10px; font-size: 12.5px; transform: translate(-50%, calc(-100% - 10px));
}
.tooltip strong { display: block; font-size: 14px; font-variant-numeric: tabular-nums; }
.tooltip .key { display: inline-block; width: 12px; height: 2px; background: var(--series-1); vertical-align: middle; margin-right: 6px; }
details.table-view summary { cursor: pointer; color: var(--muted); font-size: 13px; margin-top: 8px; }
details.table-view .table-wrap { margin-top: 8px; max-height: 320px; overflow: auto; }

/* ---------- hộp thoại ---------- */
dialog.modal {
  border: 1px solid var(--border); border-radius: 14px; padding: 0; width: min(680px, calc(100vw - 24px));
  max-height: calc(100vh - 40px); background: var(--surface); color: var(--text); box-shadow: 0 20px 50px rgba(0,0,0,.25);
}
dialog.modal::backdrop { background: rgba(10, 12, 16, .45); }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--surface); z-index: 1; }
.modal-body { padding: 16px; }
.modal-body > * + * { margin-top: 14px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; padding: 12px 16px; border-top: 1px solid var(--border); position: sticky; bottom: 0; background: var(--surface); }
.modal-foot .spacer { flex: 1; }
.icon-btn { border: 0; background: transparent; color: var(--muted); font-size: 18px; width: 32px; height: 32px; border-radius: 8px; cursor: pointer; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
dl.info { display: grid; grid-template-columns: 130px 1fr; gap: 6px 12px; margin: 0; }
dl.info dt { color: var(--muted); }
dl.info dd { margin: 0; word-break: break-word; }
@media (max-width: 480px) { dl.info { grid-template-columns: 1fr; gap: 0; } dl.info dd { margin-bottom: 8px; } }
pre.delivery {
  margin: 0; padding: 10px 12px; background: var(--surface-2); border-radius: 8px; max-height: 220px; overflow: auto;
  white-space: pre-wrap; word-break: break-all;
}
.section-title { font-weight: 650; margin-bottom: 6px; }
.note { padding: 10px 12px; border-radius: 8px; background: var(--info-bg); color: var(--info); font-size: 13px; }
.note.warn { background: var(--warn-bg); color: var(--warn); }

/* ---------- đăng nhập ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login { width: min(380px, 100%); }
.login h1 { font-size: 20px; margin-bottom: 4px; }
.login p.muted { margin: 0 0 16px; }
.login .btn { margin-top: 4px; }

/* ---------- thông báo nhanh ---------- */
.toasts { position: fixed; right: 16px; bottom: 16px; display: grid; gap: 8px; z-index: 100; max-width: calc(100vw - 32px); }
.toast {
  padding: 10px 14px; border-radius: 10px; background: var(--text); color: var(--bg); box-shadow: 0 6px 20px rgba(0,0,0,.2);
  max-width: 420px; transition: opacity .3s, transform .3s;
}
.toast.error { background: var(--bad); color: #fff; }
.toast.warn { background: var(--warn); color: #fff; }
.toast.hide { opacity: 0; transform: translateY(6px); }
.error-box { padding: 16px; border-radius: var(--radius); background: var(--bad-bg); color: var(--bad); }
.empty-state { text-align: center; padding: 40px 16px; color: var(--muted); }
.empty-state .btn { margin-top: 12px; }

/* ---------- hàng nhập liệu ---------- */
.import-row { display: flex; align-items: center; gap: 8px 12px; flex-wrap: wrap; margin-top: 10px; }
.grow, .spacer { flex: 1; }
.inline-field { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-2); white-space: nowrap; }
.inline-field input { width: 130px; }
.list-tools { margin-bottom: 10px; }
.clip { cursor: pointer; }
.clip.expanded { white-space: pre-wrap; word-break: break-all; overflow: visible; }
section > .card-head { margin-bottom: 8px; }

.auto-price { margin-top: 12px; padding-top: 12px; border-top: 1px dashed var(--border); }
.auto-price .form-grid { margin-top: 10px; }
input:disabled { opacity: .7; cursor: not-allowed; }
