/* So Kep design system.
   Tokens are taken from the mockups in Giaodien/ so the shipped product and the approved
   designs stay one visual language. Paper-grey ground, near-black ink, a single teal for
   action, and amber/rose reserved for states that mean something. */

:root {
  --paper: #f2f5f9;
  --surface: #ffffff;
  --ink: #141a2e;
  --ink2: #5a6b82;
  --ink3: #8595a9;
  --rule: #dce3ed;
  --rule2: #eaeff5;

  --teal: #0d7a6b;
  --teal-bg: #e6f4f1;
  --teal-dk: #0a5f53;
  --amber: #b06f06;
  --amber-bg: #fdf3e2;
  --rose: #bc3826;
  --rose-bg: #fdecea;
  --violet: #5b41a8;
  --violet-bg: #f0ecfd;
  --mark: #fff2a8;

  --nav: #141a2e;
  --nav2: #1f2740;
  --nav-txt: #a9b6ca;

  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  /* Georgia and Times New Roman are missing Vietnamese's double-diacritic letters - ố ầ ề
     ổ ằ, a vowel carrying both a circumflex or breve and a tone. The browser then stacks
     the marks by hand and "Số 88" comes out as "Sô´ 88" on an invoice. Cambria and
     Constantia carry the real glyphs, and the generic serif fallback does too; measured,
     not assumed. Do not put Georgia back. */
  --serif: Cambria, "Noto Serif", Constantia, "Liberation Serif", serif;
  --sans: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
  html { scroll-behavior: auto; }
}

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button { font: inherit; cursor: pointer; border: none; background: none; color: inherit; }
a { color: inherit; }
input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--teal); outline-offset: 2px; border-radius: 3px; }

.mono { font-family: var(--mono); }
.num { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.muted { color: var(--ink3); }
.dim { color: var(--ink2); }

/* ---------- buttons ---------- */
.btn {
  padding: 8px 15px; border-radius: 8px; font-size: 13px; font-weight: 650;
  background: var(--surface); border: 1px solid var(--rule); color: var(--ink);
  display: inline-flex; align-items: center; gap: 7px; text-decoration: none;
  transition: background .12s, border-color .12s;
}
.btn:hover { border-color: var(--ink3); }
.btn.primary { background: var(--teal); border-color: var(--teal); color: #fff; }
.btn.primary:hover { background: var(--teal-dk); border-color: var(--teal-dk); }
.btn.danger { color: var(--rose); border-color: #f0cdc7; }
.btn.danger:hover { background: var(--rose-bg); }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.sm { padding: 5px 10px; font-size: 12px; border-radius: 7px; }
.btn .kb {
  font-family: var(--mono); font-size: 11px; opacity: .75;
  border: 1px solid currentColor; border-radius: 4px; padding: 0 4px;
}

/* ---------- chips and badges ---------- */
.chip {
  font-size: 11px; padding: 3.5px 9px; border-radius: 20px;
  border: 1px solid var(--rule); color: var(--ink2); background: #fff;
}
.chip.on { background: var(--ink); border-color: var(--ink); color: #fff; font-weight: 600; }
.chip button { padding: 0; }

.badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 20px;
  border: 1px solid transparent; letter-spacing: .01em;
}
.badge.teal { background: var(--teal-bg); color: var(--teal-dk); border-color: #bfe3dc; }
.badge.amber { background: var(--amber-bg); color: var(--amber); border-color: #f0dcb5; }
.badge.rose { background: var(--rose-bg); color: var(--rose); border-color: #f4d3ce; }
.badge.violet { background: var(--violet-bg); color: var(--violet); border-color: #ddd4f7; }
.badge.grey { background: var(--rule2); color: var(--ink2); border-color: var(--rule); }

/* ---------- cards and panels ---------- */
.card {
  background: var(--surface); border: 1px solid var(--rule); border-radius: 14px;
}
.card-h {
  padding: 14px 18px; border-bottom: 1px solid var(--rule2);
  display: flex; align-items: center; gap: 12px;
}
.card-h h3 { margin: 0; font-size: 14px; font-weight: 700; letter-spacing: -.01em; }
.card-h .sp { flex: 1; }
.card-b { padding: 16px 18px; }

.sec-k {
  font-family: var(--mono); font-size: 10px; letter-spacing: .13em;
  text-transform: uppercase; color: var(--ink3); font-weight: 800;
}

/* ---------- tables ---------- */
table.grid { width: 100%; border-collapse: collapse; font-size: 13px; }
table.grid th {
  text-align: left; font-size: 10.5px; letter-spacing: .09em; text-transform: uppercase;
  color: var(--ink3); font-weight: 800; padding: 8px 12px;
  border-bottom: 1px solid var(--rule); white-space: nowrap;
}
table.grid td { padding: 10px 12px; border-bottom: 1px solid var(--rule2); vertical-align: top; }
table.grid tr:last-child td { border-bottom: 0; }
table.grid td.n, table.grid th.n { text-align: right; font-family: var(--mono); font-variant-numeric: tabular-nums; }
.scroll-x { overflow-x: auto; }

/* ---------- forms ---------- */
.field { display: block; margin-bottom: 14px; }
.field > span {
  display: block; font-size: 11px; font-weight: 700; letter-spacing: .06em;
  text-transform: uppercase; color: var(--ink3); margin-bottom: 6px;
}
.field input, .field select, .field textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--rule); border-radius: 9px;
  background: #fbfcfe;
}
.field input:focus, .field select:focus { background: #fff; }
.field .hint { font-size: 12px; color: var(--ink3); margin-top: 5px; font-weight: 400;
  letter-spacing: 0; text-transform: none; }

/* ---------- confidence meter ---------- */
.conf { display: inline-flex; align-items: center; gap: 6px; }
.conf .bar { width: 34px; height: 4px; border-radius: 3px; background: var(--rule); overflow: hidden; }
.conf .bar i { display: block; height: 100%; background: var(--teal); }
.conf.low .bar i { background: var(--amber); }
.conf.bad .bar i { background: var(--rose); }
.conf .pct { font-family: var(--mono); font-size: 11px; font-weight: 700; color: var(--ink2); }
.conf.low .pct { color: var(--amber); }
.conf.bad .pct { color: var(--rose); }

/* ---------- notices ---------- */
.notice {
  border-radius: 11px; padding: 12px 14px; font-size: 13px; line-height: 1.55;
  border: 1px solid var(--rule); background: var(--surface);
}
.notice.amber { background: var(--amber-bg); border-color: #f0dcb5; color: #6b4506; }
.notice.rose { background: var(--rose-bg); border-color: #f4d3ce; color: #7d2317; }
.notice.teal { background: var(--teal-bg); border-color: #bfe3dc; color: var(--teal-dk); }
.notice b { font-weight: 750; }

.empty { padding: 40px 20px; text-align: center; color: var(--ink3); font-size: 13px; }
.empty h4 { margin: 0 0 6px; font-size: 14px; color: var(--ink2); }

/* ---------- invoice rendering (left pane of the reconciliation screen) ---------- */
.inv-doc {
  background: #fff; padding: 26px 30px; font-family: var(--serif); color: #1b2233;
  max-width: 720px; margin: 0 auto; box-shadow: 0 1px 3px rgba(20,26,46,.07);
  border: 1px solid var(--rule);
}
.inv-kicker {
  text-align: center; font-family: var(--sans); font-size: 10px; letter-spacing: .16em;
  text-transform: uppercase; color: var(--ink3); font-weight: 800;
}
.inv-form { text-align: right; font-family: var(--sans); font-size: 11px; color: var(--ink3); }
/* Vietnamese invoices are titled in caps by convention. That is presentation, so it is
   done in CSS - the rendered document keeps the exact text the XML carried. */
.inv-title { text-align: center; font-size: 19px; margin: 6px 0 4px; letter-spacing: .02em;
  text-transform: uppercase; }
.inv-date { text-align: center; font-size: 13px; color: #384258; font-style: italic; }
.inv-ids {
  display: flex; justify-content: center; gap: 26px; margin: 10px 0 18px;
  font-family: var(--sans); font-size: 12.5px; color: var(--ink2);
}
.inv-ids b { font-family: var(--mono); color: var(--ink); margin-left: 5px; }
.inv-party { margin-bottom: 14px; }
.inv-party-h {
  font-family: var(--sans); font-size: 10px; letter-spacing: .1em; text-transform: uppercase;
  color: var(--ink3); font-weight: 800; border-bottom: 1px solid var(--rule2);
  padding-bottom: 4px; margin-bottom: 7px;
}
.inv-row {
  display: grid; grid-template-columns: 118px 1fr; gap: 10px; font-size: 13px; padding: 2.5px 0;
}
.inv-row span { color: var(--ink3); font-family: var(--sans); font-size: 12px; }
.inv-row b { font-weight: 600; }
table.inv-lines { width: 100%; border-collapse: collapse; font-size: 12.5px; margin: 14px 0; }
table.inv-lines th {
  font-family: var(--sans); font-size: 10px; letter-spacing: .06em; text-transform: uppercase;
  color: var(--ink3); border-top: 1px solid var(--ink); border-bottom: 1px solid var(--rule);
  padding: 6px 5px; text-align: left;
}
table.inv-lines td { padding: 6px 5px; border-bottom: 1px solid var(--rule2); }
table.inv-lines td.n, table.inv-lines th:nth-child(n+4) { text-align: right; font-family: var(--mono); }
.inv-totals { margin-left: auto; max-width: 340px; }
.inv-totals .inv-row { grid-template-columns: 1fr auto; }
.inv-totals b { font-family: var(--mono); }
.inv-totals .tot { border-top: 1px solid var(--ink); margin-top: 5px; padding-top: 7px; font-size: 14px; }
.inv-totals .tot b { font-weight: 750; }
.inv-words { font-size: 12.5px; font-style: italic; color: #384258; margin-top: 10px; }
.inv-sig {
  margin-top: 20px; border: 1px dashed var(--rule); border-radius: 8px; padding: 10px 12px;
  font-family: var(--sans); font-size: 11.5px; color: var(--ink2); max-width: 320px; margin-left: auto;
}
.inv-sig.ok { border-color: #bfe3dc; background: var(--teal-bg); color: var(--teal-dk); }
.inv-sig.bad { border-color: #f4d3ce; background: var(--rose-bg); color: var(--rose); }
.inv-sig .sig-badge { font-weight: 800; font-size: 10px; letter-spacing: .1em; text-transform: uppercase; margin-bottom: 4px; }

/* The link between a value on the right and its place on the document. */
.inv-doc [data-field] { border-radius: 3px; transition: background .13s, box-shadow .13s; }
.inv-doc [data-field].lit {
  background: var(--mark); box-shadow: 0 0 0 3px var(--mark);
}

/* ---------- utility ---------- */
.row { display: flex; align-items: center; gap: 10px; }
.col { display: flex; flex-direction: column; }
.sp { flex: 1; }
.wrap-1140 { max-width: 1140px; margin: auto; padding: 0 22px; }
.hidden { display: none !important; }

.spinner {
  width: 15px; height: 15px; border: 2px solid var(--rule); border-top-color: var(--teal);
  border-radius: 50%; animation: spin .7s linear infinite; display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

.toast-host {
  position: fixed; right: 18px; bottom: 18px; z-index: 200;
  display: flex; flex-direction: column; gap: 9px; max-width: 380px;
}
.toast {
  background: var(--ink); color: #fff; padding: 11px 15px; border-radius: 10px;
  font-size: 13px; box-shadow: 0 10px 28px rgba(20,26,46,.28); line-height: 1.45;
}
.toast.err { background: var(--rose); }
.toast.ok { background: var(--teal-dk); }

/* Document header: mẫu số on the left, the "this is a rendering" note on the right, the
   way it sits on a printed Vietnamese invoice. */
.inv-head { display: flex; align-items: flex-start; justify-content: space-between;
  gap: 16px; margin-bottom: 4px; }
.inv-head .inv-form { font-family: var(--sans); font-size: 11px; color: var(--ink2);
  text-transform: uppercase; letter-spacing: .06em; font-weight: 700; text-align: left; }
.inv-head .inv-kicker { font-family: var(--sans); font-size: 9.5px; letter-spacing: .1em;
  text-transform: uppercase; color: var(--ink3); font-weight: 800; text-align: right;
  border: 1px solid var(--rule); border-radius: 6px; padding: 4px 9px; white-space: nowrap; }

/* Confidence as a bare number. The weak row is already tinted, so a bar would only add
   ink; the meter variant is kept for screens that compare rates side by side. */
.conf { font-family: var(--mono); font-size: 11.5px; font-weight: 700; color: var(--ink3); }
.conf.low { color: var(--amber); }
.conf.bad { color: var(--rose); }
.conf.meter { display: inline-flex; align-items: center; gap: 6px; }
.conf.meter .pct { font-family: var(--mono); font-size: 11px; font-weight: 700; color: var(--ink2); }
.conf.meter.low .pct { color: var(--amber); }
.conf.meter.bad .pct { color: var(--rose); }
