@font-face {
  font-family: "Archivo";
  src: url("../fonts/archivo-latin-wght.woff2") format("woff2");
  font-weight: 100 900;
  font-display: swap;
}

:root {
  --bg: #ffffff;
  --soft: #f5f5f4;
  --text: #1c1c1a;
  --text-2: #6b6b67;
  --line: #e8e8e5;
  --prompt-paid: #157a3c;
  --cod-paid: #1d4fd6;
  --cod-unpaid: #c02a1f;
  --font: "Archivo", "Helvetica Neue", Arial, sans-serif;
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px; --s7: 48px; --s8: 72px;
  color-scheme: light;
  scrollbar-color: #c9c9c5 var(--bg);
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
::selection { background: #e2e2de; color: var(--text); }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 15px/1.5 var(--font);
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
}

:focus-visible { outline: 2px solid var(--text); outline-offset: 3px; border-radius: 2px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.num { text-align: right; }

/* Header */
.top {
  max-width: 1100px; margin: 0 auto; padding: var(--s8) var(--s4) var(--s5);
  display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: var(--s2) var(--s5);
}
.top__title { margin: 0; font-size: clamp(1.5rem, 2vw + 1rem, 2rem); font-weight: 600; letter-spacing: -0.02em; line-height: 1.1; }
.top__meta { margin: 0; color: var(--text-2); font-size: 0.875rem; }

.sheet { max-width: 1100px; margin: 0 auto; padding: 0 var(--s4) var(--s8); }

/* Category index + legend */
.index {
  display: flex; flex-wrap: wrap; gap: var(--s2) var(--s5);
  padding-bottom: var(--s4); margin-bottom: var(--s4); border-bottom: 1px solid var(--line);
}
.index a {
  display: inline-flex; align-items: baseline; gap: 6px; padding: var(--s1) 0;
  color: var(--text); font-size: 0.875rem; font-weight: 500; text-decoration: none;
}
.index a:hover { text-decoration: underline; text-underline-offset: 4px; }
.index b { font-weight: 400; color: var(--text-2); }

.legend { display: flex; flex-wrap: wrap; gap: var(--s2) var(--s5); margin: 0 0 var(--s6); padding: 0; list-style: none; }
.legend li { display: flex; align-items: center; gap: var(--s2); font-size: 0.8125rem; color: var(--text-2); }

/* Status */
.status { display: inline-flex; align-items: center; gap: 7px; font-size: 0.8125rem; font-weight: 500; white-space: nowrap; }
.status__dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; flex: none; }
.status--prompt_paid { color: var(--prompt-paid); }
.status--cod_paid { color: var(--cod-paid); }
.status--cod_unpaid { color: var(--cod-unpaid); }

/* States */
.state { padding: var(--s7) 0; }
.state__text { margin: 0 0 var(--s2); font-size: 1rem; font-weight: 500; max-width: 60ch; }
.state__hint { margin: 0 0 var(--s4); color: var(--text-2); max-width: 65ch; }
.btn {
  min-height: 40px; padding: 0 var(--s4); border: 1px solid var(--text); border-radius: 6px;
  background: var(--text); color: var(--bg); font: 500 0.875rem var(--font); cursor: pointer;
}
.btn:hover { background: #3a3a37; }

/* Table */
.table-wrap { overflow-x: auto; }
.items { width: 100%; border-collapse: collapse; }
.items thead th {
  padding: 0 var(--s3) var(--s2); border-bottom: 1px solid var(--line);
  font-size: 0.75rem; font-weight: 500; color: var(--text-2); text-align: left; white-space: nowrap;
}
.items thead th.num { text-align: right; }
.items th:first-child, .items td:first-child { padding-left: 0; }
.items th:last-child, .items td:last-child { padding-right: 0; }
.items td { padding: var(--s3); border-bottom: 1px solid var(--line); vertical-align: top; }

.band-row th { padding: var(--s7) 0 var(--s3); border-bottom: 1px solid var(--line); text-align: left; scroll-margin-top: var(--s4); }
.items tbody:first-of-type .band-row th { padding-top: var(--s5); }
.band-row__inner { display: flex; align-items: baseline; gap: var(--s2); }
.band-row__inner > :first-child { font-size: 1.0625rem; font-weight: 600; letter-spacing: -0.01em; }
.band-row__count { font-size: 0.875rem; font-weight: 400; color: var(--text-2); }

.cell-id { font-size: 0.8125rem; white-space: nowrap; color: var(--text-2); padding-top: 14px; }
.cell-num { text-align: right; white-space: nowrap; }
.cell-status { width: 1%; white-space: nowrap; padding-top: 13px; }

.item-btn {
  display: inline; padding: 0; border: 0; background: none; color: var(--text); cursor: pointer; text-align: left;
  font: 500 0.9375rem/1.4 var(--font);
  text-decoration: underline; text-decoration-color: transparent; text-underline-offset: 4px;
  transition: text-decoration-color 150ms;
}
.item-btn:hover { text-decoration-color: currentColor; }
.item-store { display: block; margin-top: 2px; font-size: 0.8125rem; color: var(--text-2); }

.chips { display: flex; flex-wrap: wrap; gap: var(--s1) 6px; }
.chip { padding: 2px 8px; border-radius: 4px; background: var(--soft); font-size: 0.8125rem; white-space: nowrap; }
.chip b { font-weight: 400; color: var(--text-2); margin-left: var(--s1); }
.chip--none b { margin-left: 0; }

/* Phone: stacked rows */
@media (max-width: 719px) {
  .top { padding-top: var(--s7); }
  .items, .items tbody { display: block; }
  .items thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  .band-row, .band-row th { display: block; }
  .band-row th { padding-top: var(--s6); }
  .items tbody tr:not(.band-row) {
    display: grid; grid-template-columns: 1fr auto; gap: 6px var(--s3);
    grid-template-areas: "item status" "variants variants" "id total";
    padding: var(--s4) 0; border-bottom: 1px solid var(--line);
  }
  .items td { padding: 0; border: 0; }
  .cell-item { grid-area: item; }
  .cell-status { grid-area: status; width: auto; padding-top: 2px; }
  .cell-variants { grid-area: variants; }
  .cell-id { grid-area: id; padding-top: 0; }
  .cell-qty { display: none; }
  .cell-total { grid-area: total; color: var(--text-2); font-size: 0.8125rem; }
  .cell-total::before { content: "THB "; }
}

/* Viewer */
.viewer {
  width: min(560px, calc(100% - var(--s5))); max-height: calc(100dvh - var(--s5));
  padding: 0; border: 0; border-radius: 12px; background: var(--bg); color: var(--text);
  box-shadow: 0 24px 64px -16px rgb(0 0 0 / 0.28);
}
.viewer::backdrop { background: rgb(28 28 26 / 0.4); }
.label { display: flex; flex-direction: column; padding: var(--s5); max-height: calc(100dvh - var(--s5)); overflow-y: auto; }
.label__head { order: 0; display: flex; align-items: center; justify-content: space-between; margin: -6px -8px 0 0; }
.label__id { font-size: 0.8125rem; color: var(--text-2); }
.label__title { order: 1; margin: var(--s1) 0 2px; font-size: 1.25rem; font-weight: 600; letter-spacing: -0.01em; line-height: 1.25; text-wrap: balance; }
.label__row { order: 2; margin: 0; font-size: 0.875rem; color: var(--text-2); }

.frame {
  order: 3; position: relative; margin: var(--s4) 0 0; aspect-ratio: 4 / 3; border-radius: 8px;
  background: var(--soft); display: grid; place-items: center; overflow: hidden;
}
.frame img { width: 100%; height: 100%; object-fit: contain; transition: opacity 200ms; }
.frame.is-loading img, .frame.is-broken img { opacity: 0; }
.frame__note { position: absolute; font-size: 0.875rem; color: var(--text-2); }

.pager { order: 4; display: flex; align-items: center; justify-content: center; gap: var(--s3); padding-top: var(--s3); }
.pager__count { font-size: 0.8125rem; color: var(--text-2); min-width: 5ch; text-align: center; }

.icon-btn {
  display: inline-grid; place-items: center; width: 40px; height: 40px; padding: 0;
  border: 0; border-radius: 8px; background: none; color: var(--text); cursor: pointer;
}
.icon-btn:hover { background: var(--soft); }
.icon-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }

.label__grid { order: 5; display: grid; grid-template-columns: 1fr 1fr; gap: var(--s4) var(--s5); margin: var(--s5) 0 0; padding-top: var(--s4); border-top: 1px solid var(--line); }
.label__grid > div { min-width: 0; }
.label__grid dt { font-size: 0.75rem; color: var(--text-2); }
.label__grid dd { margin: var(--s1) 0 0; font-size: 0.9375rem; }

@media (prefers-reduced-motion: no-preference) {
  .viewer[open] { animation: viewer-in 220ms var(--ease-out); }
}
@keyframes viewer-in { from { transform: translateY(8px); opacity: 0; } }
