:root {
  --ink: #18232F; --muted: #4E5D69; --line: #DCE3DF; --line2: #E6ECE8; --bg: #F4F6F5;
  --accent: #1F6F4E; --accent-d: #145238;
  --ok-bg: #E3F2EA; --ok-fg: #1B5E3F;
  --warn-bg: #FFF1D6; --warn-fg: #7A4A00;
  --bad-bg: #FBE9E4; --bad-fg: #8A2E1F;
  --mono: "IBM Plex Mono", ui-monospace, Consolas, monospace;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: "IBM Plex Sans Thai", system-ui, sans-serif; line-height: 1.5; }
a { color: var(--accent); }
a:hover { color: var(--accent-d); }
h1, h2, p { margin: 0; }
.mono { font-family: var(--mono); }
.muted { color: var(--muted); }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.top :focus-visible { outline-color: #7FD3A8; }

/* header */
.top { background: var(--ink); color: #fff; padding: 10px 32px; min-height: 60px; display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 17px; }
.tagline { font-size: 12px; letter-spacing: 1px; color: #A9B7C2; }
.badges { margin-left: auto; display: flex; flex-wrap: wrap; gap: 10px; align-items: center; font-size: 13px; }
.badge { padding: 4px 10px; border-radius: 12px; }
.badge.conn { background: #24323F; color: #CFE8D8; }
.badge.demo { background: #F2B33D; color: var(--ink); font-weight: 600; }

/* layout */
.wrap { width: 100%; max-width: 1216px; margin: 0 auto; padding: 28px 32px 40px; display: flex; flex-direction: column; gap: 22px; }
#result { display: flex; flex-direction: column; gap: 22px; min-width: 0; }
.note { font-size: 13px; color: var(--muted); }

/* search form */
.search { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 18px 20px; }
.field-group, .field { display: flex; flex-direction: column; gap: 6px; }
.field { flex: 1 1 320px; min-width: 0; }
.lbl { font-size: 13px; color: var(--muted); }
.seg { display: flex; border: 1px solid #C9D3CE; border-radius: 10px; overflow: hidden; }
.seg button { height: 44px; padding: 0 18px; border: 0; background: #fff; color: var(--ink); font: inherit; cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--accent); color: #fff; font-weight: 600; }
.seg button:focus-visible { outline-offset: -3px; outline-color: var(--ink); }
.seg button[aria-pressed="true"]:focus-visible { outline-color: #fff; }
.field input { height: 44px; width: 100%; padding: 0 14px; border: 2px solid var(--accent); border-radius: 10px; font-size: 17px; color: var(--ink); background: #fff; }
.field input::placeholder { color: #7B8A95; font-family: "IBM Plex Sans Thai", system-ui, sans-serif; font-size: 15px; }
.go { height: 44px; min-width: 120px; padding: 0 22px; border: 0; border-radius: 10px; background: var(--ink); color: #fff; font: inherit; font-weight: 600; cursor: pointer; }
.go:hover { background: #0F1822; }

/* invoice header */
.inv-head { display: flex; flex-wrap: wrap; gap: 16px 32px; align-items: center; }
.inv-id { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.inv-no { font-size: 26px; font-weight: 600; overflow-wrap: anywhere; }
.inv-meta { font-size: 15px; color: var(--muted); }
.inv-total { margin-left: auto; display: flex; flex-wrap: wrap; gap: 24px; align-items: center; }
.total-box { display: flex; flex-direction: column; text-align: right; }
.total-box .lbl { font-size: 13px; }
.total-box .amt { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }

/* pills */
.pill { display: inline-block; padding: 6px 14px; border-radius: 16px; font-weight: 600; white-space: nowrap; }
.pill.sm { padding: 3px 10px; border-radius: 12px; font-size: 12px; }
.pill.ok { background: var(--ok-bg); color: var(--ok-fg); }
.pill.warn { background: var(--warn-bg); color: var(--warn-fg); }
.pill.bad { background: var(--bad-bg); color: var(--bad-fg); }

/* three cards */
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(320px, 100%), 1fr)); gap: 18px; align-items: start; }
.card { background: #fff; border: 1px solid var(--line); border-radius: 14px; overflow: hidden; min-width: 0; }
.card-h { display: flex; align-items: center; gap: 8px; padding: 14px 18px; border-bottom: 1px solid var(--line2); }
.card-h h2 { font-size: 16px; font-weight: 700; }
.card-meta { margin-left: auto; font-size: 12px; color: var(--muted); }
.card-f { padding: 12px 18px; border-top: 1px solid var(--line2); font-size: 13px; color: var(--muted); }
.scroll { overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th { padding: 8px 8px; background: var(--bg); color: var(--muted); font-size: 12px; font-weight: 500; text-align: left; white-space: nowrap; }
.tbl td { padding: 10px 8px; border-top: 1px solid var(--line2); vertical-align: top; }
.tbl th:first-child, .tbl td:first-child { padding-left: 18px; }
.tbl th:last-child, .tbl td:last-child { padding-right: 18px; }
.tbl .r { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.prod { font-weight: 500; }
.sku { font-family: var(--mono); font-size: 12px; color: var(--muted); }
.lot-link { font-family: var(--mono); font-size: 13px; white-space: nowrap; }
.lot-link.sel { font-weight: 600; background: var(--ok-bg); border-radius: 4px; padding: 1px 4px; margin: -1px -4px; }

/* copy doc */
.doc { display: flex; align-items: center; gap: 12px; padding: 12px 18px; border-bottom: 1px solid var(--line2); color: var(--ink); text-decoration: none; }
.doc:last-child { border-bottom: 0; }
.doc:hover { background: var(--bg); color: var(--ink); }
.doc-ext { width: 36px; height: 36px; flex-shrink: 0; border-radius: 8px; background: var(--line2); color: var(--muted); display: flex; align-items: center; justify-content: center; font-family: var(--mono); font-size: 11px; font-weight: 600; }
.doc-ext.pdf { background: var(--bad-bg); color: var(--bad-fg); }
.doc-ext.xls { background: var(--ok-bg); color: var(--ok-fg); }
.doc-txt { display: flex; flex-direction: column; min-width: 0; }
.doc-name { font-weight: 500; overflow-wrap: anywhere; }
.doc-date { font-size: 12px; color: var(--muted); }

/* payment */
.pay-sum { padding: 16px 18px; display: flex; flex-direction: column; gap: 12px; }
.bar { height: 10px; border-radius: 5px; background: var(--line2); overflow: hidden; }
.fill { height: 100%; background: var(--accent); }
.tiles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.tile { padding: 10px 12px; border-radius: 10px; background: var(--bg); }
.tile.warn { background: var(--warn-bg); color: var(--warn-fg); }
.tile.ok { background: var(--ok-bg); color: var(--ok-fg); }
.tile .k { font-size: 12px; color: var(--muted); }
.tile.warn .k, .tile.ok .k { color: inherit; }
.tile .v { font-weight: 700; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.pay-row { display: flex; gap: 12px; align-items: center; padding: 11px 18px; border-top: 1px solid var(--line2); font-size: 14px; }
.pay-row .d { font-family: var(--mono); font-size: 13px; color: var(--muted); }
.pay-row .a { margin-left: auto; font-variant-numeric: tabular-nums; font-weight: 500; }
.pay-row.none { color: var(--muted); }

/* lot strip */
.strip { background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 16px 18px; display: flex; flex-wrap: wrap; gap: 12px 20px; align-items: center; }
.strip .muted { font-size: 14px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { padding: 6px 12px; border-radius: 8px; background: var(--bg); color: var(--ink); font-family: var(--mono); font-size: 13px; text-decoration: none; }
.chip:hover { background: var(--line2); color: var(--ink); }
.chip.cur { background: var(--ok-bg); color: var(--ok-fg); }

/* lot result / pick list */
.lot-head { display: flex; flex-direction: column; gap: 4px; }
.lot-no { font-size: 24px; font-weight: 600; overflow-wrap: anywhere; }
.lot-sub { font-size: 14px; color: var(--muted); }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(300px, 100%), 1fr)); gap: 10px; }
.inv-card { display: flex; flex-direction: column; gap: 6px; padding: 14px; background: #fff; border: 1px solid var(--line); border-radius: 12px; color: var(--ink); text-decoration: none; min-width: 0; }
.inv-card:hover { border-color: var(--accent); color: var(--ink); }
.inv-card .top-row { display: flex; align-items: center; gap: 8px; }
.inv-card .no { font-family: var(--mono); font-weight: 600; overflow-wrap: anywhere; }
.inv-card .pill, .inv-card .cnt { margin-left: auto; }
.inv-card .cnt { font-size: 13px; color: var(--muted); }
.inv-card .line { font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }
.inv-card .line.two { display: flex; flex-wrap: wrap; gap: 4px 14px; }
.pick-h { font-size: 15px; color: var(--muted); }
.hint { font-size: 12px; color: var(--muted); }

/* empty state */
.empty { background: #fff; border: 1px dashed #C9D3CE; border-radius: 14px; padding: 28px 20px; display: flex; flex-direction: column; gap: 10px; align-items: flex-start; }
.empty h2 { font-size: 18px; font-weight: 700; overflow-wrap: anywhere; }
.empty p { color: var(--muted); font-size: 14px; }

/* toast */
.toast { position: fixed; left: 50%; bottom: 20px; transform: translate(-50%, 8px); max-width: calc(100vw - 32px); padding: 10px 16px; border-radius: 10px; background: var(--ink); color: #fff; font-size: 14px; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
@media (prefers-reduced-motion: reduce) { .toast { transition: none; } }

@media (max-width: 640px) {
  .top { padding: 10px 16px; min-height: 56px; }
  .tagline { display: none; }
  .badges { margin-left: 0; width: 100%; font-size: 12px; }
  .wrap { padding: 16px 16px 32px; gap: 16px; }
  #result { gap: 16px; }
  .search { padding: 14px; }
  .field-group { width: 100%; }
  .seg { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .field { flex-basis: 100%; }
  .field input { height: 48px; }
  .go { width: 100%; }
  .inv-no { font-size: 22px; }
  .inv-meta { font-size: 14px; }
  .inv-total { margin-left: 0; width: 100%; justify-content: space-between; gap: 12px; }
  .total-box { text-align: left; }
  .lot-no { font-size: 22px; }
}
