:root {
  color-scheme: light;
  --bg: #f4f6f5;
  --card: #ffffff;
  --ink: #17211d;
  --muted: #5f6d67;
  --line: #dde3e0;
  --line-strong: #c3ccc8;
  --accent: #0f6b52;
  --accent-ink: #ffffff;
  --accent-soft: #e4f2ed;
  --warn: #8a5300;
  --warn-soft: #fdf2dc;
  --bad: #a42a24;
  --bad-soft: #fbe9e7;
  --ok: #0f6b52;
  --ok-soft: #e4f2ed;
  --info: #2a5a8f;
  --info-soft: #e7eff8;
  --radius: 8px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.5 "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
}

[hidden] { display: none !important; }

.wrap { max-width: 1320px; margin: 0 auto; padding: 0 20px; }

.topbar { background: var(--card); border-bottom: 1px solid var(--line); }
.topbar-in { display: flex; justify-content: space-between; align-items: center; gap: 16px; padding-top: 14px; padding-bottom: 14px; flex-wrap: wrap; }
h1 { font-size: 19px; margin: 0; font-weight: 650; letter-spacing: -0.01em; }
.topbar p { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.topbar-actions { display: flex; gap: 8px; flex-wrap: wrap; }

button, .btn {
  font: inherit;
  border: 1px solid var(--line-strong);
  background: var(--card);
  color: var(--ink);
  border-radius: 6px;
  padding: 6px 12px;
  cursor: pointer;
}
button:hover:not(:disabled), .btn:hover { background: #f0f3f1; }
button:disabled { opacity: 0.5; cursor: not-allowed; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
button.primary:hover:not(:disabled) { background: #0c5943; }
button.link { border: 0; background: none; color: var(--accent); padding: 0; text-decoration: underline; }
button.link:hover:not(:disabled) { background: none; color: #0c5943; }
button.link.quiet { color: var(--muted); }
button.link.quiet:hover:not(:disabled) { color: var(--bad); }
button:focus-visible, input:focus-visible, select:focus-visible, .drop:focus-within { outline: 2px solid var(--accent); outline-offset: 1px; }

.uploads { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 16px 0; }
.drop {
  display: flex; gap: 12px; align-items: center;
  background: var(--card);
  border: 1.5px dashed var(--line-strong);
  border-radius: var(--radius);
  padding: 12px 14px;
  cursor: pointer;
}
.drop:hover, .drop.over { border-color: var(--accent); background: var(--accent-soft); }
.drop.done { border-style: solid; border-color: var(--accent); }
.drop input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.drop-step {
  flex: none; width: 28px; height: 28px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--bg); color: var(--muted); font-weight: 600;
}
.drop.done .drop-step { background: var(--accent); color: var(--accent-ink); }
.drop-body { display: flex; flex-direction: column; min-width: 0; }
.drop-status { color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }

.error { background: var(--bad-soft); color: var(--bad); border-radius: var(--radius); padding: 10px 14px; margin-bottom: 12px; }

.steps { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 10px; }
.step {
  display: flex; flex-direction: column; align-items: flex-start; gap: 3px; text-align: left;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px;
}
button.step { cursor: pointer; }
button.step:hover:not(:disabled) { background: var(--card); border-color: var(--accent); }
.step.current { border: 1.5px solid var(--accent); }
.step .primary { margin-top: 6px; }
.step-title { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.step-no {
  flex: none; width: 22px; height: 22px; border-radius: 50%; font-size: 12.5px;
  display: inline-flex; align-items: center; justify-content: center; background: var(--bg); color: var(--muted);
}
.step.current .step-no, .step.done .step-no { background: var(--accent); color: var(--accent-ink); }
.step-value { font-size: 20px; font-weight: 650; font-variant-numeric: tabular-nums; line-height: 1.3; }
.step-sub { color: var(--muted); font-size: 12.5px; }
.totals { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; margin-bottom: 10px; }
.totals b { color: var(--ink); font-weight: 600; }
.totals .sep { margin: 0 7px; opacity: 0.6; }
.intro { margin: 0 0 10px; color: var(--muted); }
.intro b { color: var(--ink); font-weight: 600; }

.banner { background: var(--warn-soft); color: var(--warn); border-radius: var(--radius); padding: 8px 14px; margin-bottom: 12px; }

.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 12px; overflow-x: auto; }
.tabs button {
  border: 0; background: none; border-radius: 0; padding: 8px 14px; color: var(--muted);
  border-bottom: 2px solid transparent; white-space: nowrap;
}
.tabs button:hover:not(:disabled) { background: none; color: var(--ink); }
.tabs button[aria-selected="true"] { color: var(--ink); font-weight: 600; border-bottom-color: var(--accent); }
.tab-count { color: var(--muted); font-weight: 400; margin-left: 4px; font-variant-numeric: tabular-nums; }

.toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 10px; flex-wrap: wrap; }
.toolbar .grow { flex: 1 1 240px; }
.toolbar .spacer { flex: 1; }
input[type="text"], input[type="search"], input[type="number"], select {
  font: inherit; color: inherit; background: var(--card);
  border: 1px solid var(--line-strong); border-radius: 6px; padding: 6px 9px; min-width: 0;
}
select { max-width: 340px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
.empty { padding: 28px; text-align: center; color: var(--muted); }

/* Khớp mặt hàng */
.match-row { display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); gap: 16px; padding: 12px 14px; border-top: 1px solid var(--line); }
.match-row:first-child { border-top: 0; }
.match-head { padding-top: 8px; padding-bottom: 8px; color: var(--muted); font-weight: 600; font-size: 12.5px; background: #fafbfa; border-radius: var(--radius) var(--radius) 0 0; }
.src-name { font-weight: 600; overflow-wrap: anywhere; }
.meta { color: var(--muted); font-size: 12.5px; overflow-wrap: anywhere; }
.meta b { color: var(--ink); font-weight: 600; }
.meta .sep { margin: 0 5px; opacity: 0.6; }
.note { color: var(--info); font-size: 12.5px; }
.badge { display: inline-block; font-size: 12px; font-weight: 600; padding: 0 7px; border-radius: 10px; white-space: nowrap; line-height: 20px; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.high { background: var(--info-soft); color: var(--info); }
.badge.low { background: var(--warn-soft); color: var(--warn); }
.badge.none, .badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.muted { background: var(--bg); color: var(--muted); }

.opts { display: flex; flex-direction: column; gap: 1px; }
.opt { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 8px; align-items: baseline; padding: 3px 6px; border-radius: 5px; cursor: pointer; }
.opt:hover { background: var(--bg); }
.opt.selected { background: var(--accent-soft); }
.opt-name { overflow-wrap: anywhere; }
.opt-meta { color: var(--muted); font-size: 12.5px; font-variant-numeric: tabular-nums; white-space: nowrap; text-align: right; }
.opt-meta > span { display: block; }
.opt-sub { display: block; color: var(--muted); font-size: 12.5px; overflow-wrap: anywhere; }
.opt-price.same { color: var(--ok); font-weight: 600; }
.dst-tools { display: flex; gap: 8px; margin-top: 6px; align-items: center; flex-wrap: wrap; }
.dst-tools input { flex: 1 1 200px; }
.matched { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.matched-name { overflow-wrap: anywhere; }

.pager { display: flex; justify-content: space-between; align-items: center; padding: 10px 2px; color: var(--muted); flex-wrap: wrap; gap: 8px; }
.pager-btns { display: flex; gap: 6px; align-items: center; }

/* Bảng */
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; }
th, td { padding: 7px 10px; text-align: left; border-top: 1px solid var(--line); vertical-align: top; }
thead th { border-top: 0; color: var(--muted); font-weight: 600; font-size: 12.5px; background: #fafbfa; white-space: nowrap; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
td.name { min-width: 220px; overflow-wrap: anywhere; }
tfoot td { font-weight: 600; border-top: 1px solid var(--line-strong); }

/* Chiết khấu */
.inv-card { padding: 12px 14px; border-top: 1px solid var(--line); }
.inv-card:first-child { border-top: 0; }
.inv-head { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; align-items: baseline; }
.inv-title { font-weight: 600; overflow-wrap: anywhere; }
.inv-totals { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 13px; }
.inv-totals b { color: var(--ink); }
.disc-list { margin: 6px 0 0; padding: 0; list-style: none; }
.disc-list li { padding: 3px 0; display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 12px; }
.disc-amount { font-variant-numeric: tabular-nums; font-weight: 600; }
.warn-text { color: var(--warn); font-size: 12.5px; }
.detail { margin-top: 8px; border: 1px solid var(--line); border-radius: 6px; }

/* Cài đặt */
.settings { padding: 16px; display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px 20px; }
.field { display: flex; flex-direction: column; gap: 3px; }
.field > span { font-weight: 600; font-size: 13px; }
.field small { color: var(--muted); }
.check { display: flex; gap: 8px; align-items: flex-start; }
.settings-group { grid-column: 1 / -1; font-weight: 650; margin-top: 4px; padding-top: 12px; border-top: 1px solid var(--line); }
.settings-group:first-child { border-top: 0; padding-top: 0; margin-top: 0; }
.settings-actions { grid-column: 1 / -1; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* Khung xem nhanh */
.quick {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(540px, 100vw); z-index: 5;
  display: flex; flex-direction: column;
  background: var(--card); border-left: 1px solid var(--line-strong); box-shadow: -8px 0 28px rgba(0, 0, 0, 0.14);
}
.quick-head { display: flex; align-items: center; gap: 8px; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.quick-head .spacer { flex: 1; }
.quick-body { flex: 1; overflow-y: auto; padding: 4px 14px 12px; }
.quick-section { padding: 10px 0; border-top: 1px solid var(--line); }
.quick-section:first-child { border-top: 0; }
.quick-label { font-size: 12.5px; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
.quick-table { margin-top: 6px; }
.quick-table th, .quick-table td { padding: 4px 8px; font-size: 13px; }
.quick-search { width: 100%; margin-bottom: 6px; }
.quick-opts { display: flex; flex-direction: column; gap: 4px; }
.quick-opt { display: block; width: 100%; text-align: left; padding: 6px 9px; }
.quick-opt[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); }
.quick-opt-name { display: block; overflow-wrap: anywhere; }
.quick-info { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 3px 12px; margin: 0 0 6px; }
.quick-info dt { color: var(--muted); font-size: 13px; }
.quick-info dd { margin: 0; overflow-wrap: anywhere; }
.quick-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 10px 14px; border-top: 1px solid var(--line); }

.busy { position: fixed; inset: 0; background: rgba(23, 33, 29, 0.28); display: flex; align-items: center; justify-content: center; z-index: 10; }
.busy-card { background: var(--card); border-radius: var(--radius); padding: 14px 20px; display: flex; gap: 12px; align-items: center; box-shadow: 0 6px 24px rgba(0, 0, 0, 0.18); }
.spinner { width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--line); border-top-color: var(--accent); animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2.4s; } }

@media (max-width: 900px) {
  .uploads, .match-row, .steps { grid-template-columns: minmax(0, 1fr); }
  .match-head { display: none; }
  .wrap { padding: 0 16px; }
}
