:root {
  --bg: #f5f6f8;
  --card: #fff;
  --text: #1f2933;
  --muted: #6b7785;
  --line: #e1e5ea;
  --brand: #1d5fd1;
  --ok: #1a7f4b;
  --ok-bg: #e6f4ec;
  --bad: #c0392b;
  --bad-bg: #fdecea;
  --warn: #a86400;
  --warn-bg: #fff4e0;
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
}
* { box-sizing: border-box; }
body { margin: 0; }
button, .button, select, input, textarea { font: inherit; }
button, .button {
  display: inline-block;
  border: 1px solid var(--brand);
  background: var(--brand);
  color: #fff;
  border-radius: 6px;
  padding: 6px 12px;
  cursor: pointer;
}
.ghost { background: #fff; color: var(--brand); }
.danger { border-color: var(--bad); color: var(--bad); }
button.link { background: none; border: 0; color: var(--brand); padding: 0; font-weight: 600; text-align: left; }
select, input, textarea { border: 1px solid var(--line); border-radius: 6px; padding: 5px 8px; background: #fff; }
textarea { width: 100%; margin: 6px 0; }

.topbar {
  display: flex; flex-wrap: wrap; gap: 12px; justify-content: space-between; align-items: center;
  padding: 12px 20px; background: #fff; border-bottom: 1px solid var(--line);
}
.brand strong { font-size: 18px; display: block; }
.brand span { color: var(--muted); }
.period { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.period label { display: flex; gap: 6px; align-items: center; }

.tabs { display: flex; gap: 4px; padding: 0 20px; background: #fff; border-bottom: 1px solid var(--line); }
.tabs button { background: none; border: 0; border-bottom: 3px solid transparent; border-radius: 0; color: var(--muted); padding: 10px 14px; }
.tabs button.active { color: var(--brand); border-bottom-color: var(--brand); font-weight: 600; }

main { padding: 16px 20px 40px; }
.tab { display: none; }
.tab.active { display: block; }
.hint { color: var(--muted); max-width: 900px; }
.muted { color: var(--muted); }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 16px; display: flex; flex-direction: column; gap: 10px; align-items: flex-start; }
.card h3 { margin: 0; }
.status { margin: 0; color: var(--muted); }
.status.ok { color: var(--ok); }
.pending, details { width: 100%; }
.pending label { display: block; margin: 6px 0; }
.mapping { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 12px; margin: 8px 0; }
.mapping label { display: flex; flex-direction: column; font-size: 12px; color: var(--muted); }
.errors { color: var(--warn); }
.errors ul { margin: 6px 0; padding-left: 18px; max-height: 160px; overflow: auto; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.row.end { justify-content: flex-end; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-bottom: 14px; }
.stat { background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.stat span { display: block; color: var(--muted); font-size: 12px; }
.stat b { font-size: 20px; }
.stat.ok b { color: var(--ok); }
.stat.bad b { color: var(--bad); }
.stat.warn b { color: var(--warn); }

.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 10px; }
.toolbar input[type='search'] { min-width: 240px; }
.inline { display: flex; gap: 6px; align-items: center; }
.inline input { width: 90px; }

.table-wrap { overflow: auto; background: #fff; border: 1px solid var(--line); border-radius: 10px; }
.table-wrap.small { max-height: 200px; font-size: 12px; }
table { border-collapse: collapse; width: 100%; }
th, td { padding: 7px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; white-space: nowrap; }
th { background: #fafbfc; position: sticky; top: 0; font-weight: 600; }
td input[type='text'] { width: 260px; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
td.diff { color: var(--bad); font-weight: 600; }
td.missing { color: var(--warn); font-style: italic; }
tr.closed { opacity: 0.6; }
tr.detail td { background: #fafbfc; white-space: normal; font-size: 13px; }
.badge { padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge.khop { background: var(--ok-bg); color: var(--ok); }
.badge.lech { background: var(--bad-bg); color: var(--bad); }
.badge.thieu, .badge.chua_du { background: var(--warn-bg); color: var(--warn); }

dialog { border: 0; border-radius: 12px; width: min(640px, 92vw); }
dialog::backdrop { background: rgb(0 0 0 / 0.35); }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: #1f2933; color: #fff; padding: 8px 16px; border-radius: 8px; opacity: 0; transition: opacity 0.2s; pointer-events: none; }
.toast.show { opacity: 1; }

@media print {
  .topbar .period, .tabs, .toolbar, #tab-import, #tab-backup { display: none !important; }
  #tab-result { display: block !important; }
}
