/* ==========================================================================
   Zhaojin Store — Order & Deposit Ledger
   Aesthetic: printed ledger paper. Warm paper ground with faint rules, ink
   hairlines with hard offset shadows, gold and jade accents. Matches the
   zjinstore.netlify.app house style: Fraunces for display, Space Mono for
   everything else.
   ========================================================================== */

:root {
  /* Palette taken from the shop's other site so the two read as one brand. */
  --paper: #f6efe2;
  --paper-dark: #ece1cb;
  --paper-bright: #fffdf8;
  --ink: #2b2420;
  --ink-soft: #5c5142;
  --gold: #a9782f;
  --gold-deep: #7c5620;
  --jade: #3f5d4d;
  --jade-deep: #2c4436;
  --rule: #d8c9a8;
  --danger: #8c3d32;
  --shadow: rgba(43, 36, 32, 0.18);

  /* Two extra stage hues, kept as muted as the originals: this ledger tracks
     six stages where the other site only shows four. */
  --slate: #4a5a8c;
  --plum: #7a4a63;

  --font-display: 'Fraunces', Georgia, serif;
  --font-mono: 'Space Mono', ui-monospace, 'SFMono-Regular', Menlo, monospace;

  --radius: 4px;
  --radius-sm: 3px;
  --lift: 6px 6px 0 var(--shadow);
  --lift-sm: 3px 3px 0 var(--shadow);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  /* Gold wash at the top, then ruled lines every 34px, as on the sister site. */
  background-color: var(--paper);
  background-image:
    linear-gradient(180deg, rgba(169, 120, 47, 0.05), transparent 200px),
    repeating-linear-gradient(
      0deg,
      rgba(43, 36, 32, 0.025) 0px,
      rgba(43, 36, 32, 0.025) 1px,
      transparent 1px,
      transparent 34px
    );
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 14.5px;
  line-height: 1.6;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* --- Atmosphere: fine grain, fixed and inert ----------------------------- */

.bg-grain {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 999;
  opacity: 0.05;
  mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

.page {
  position: relative;
  z-index: 1;
  width: min(1040px, 100% - 2.5rem);
  margin-inline: auto;
  padding: clamp(2rem, 5vw, 3rem) 0 3.5rem;
}

/* --- Masthead ------------------------------------------------------------- */

.masthead {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  padding-bottom: 1.75rem;
  border-bottom: 1px dashed var(--rule);
}

/* Outlined, slightly rocked stamp with a hard shadow — not a filled lacquer block. */
.seal {
  flex: none;
  display: grid;
  place-items: center;
  width: 3.75rem;
  height: 3.75rem;
  border: 1.5px solid var(--gold-deep);
  border-radius: 2px;
  background: var(--paper);
  box-shadow: 3px 3px 0 var(--rule);
  transform: rotate(-2deg);
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-weight: 600;
  line-height: 1.05;
  color: var(--gold-deep);
}

.masthead-text {
  min-width: 0;
}

.masthead h1 {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(1.6rem, 4vw, 2.1rem);
  font-weight: 600;
  line-height: 1.1;
  letter-spacing: 0.01em;
  color: var(--ink);
}

.masthead p {
  margin: 0.15rem 0 0;
  font-size: 0.72rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

/* --- Lookup panel -------------------------------------------------------- */

.lookup {
  margin-top: clamp(1.75rem, 4vw, 2.5rem);
  max-width: 640px;
  padding: clamp(1.5rem, 4vw, 2rem) clamp(1.25rem, 3vw, 1.75rem);
  border: 1.5px solid var(--ink);
  border-radius: var(--radius);
  background: var(--paper);
  box-shadow: var(--lift);
}

.lookup h2 {
  margin: 0 0 0.2rem;
  font-family: var(--font-display);
  font-size: clamp(1.25rem, 3vw, 1.5rem);
  font-weight: 500;
  line-height: 1.25;
  color: var(--ink);
}

.lookup .lede {
  margin: 0 0 1.1rem;
  color: var(--ink-soft);
  font-size: 0.82rem;
}

.field {
  display: flex;
  gap: 0.75rem;
  align-items: stretch;
  flex-wrap: wrap;
}

.input-shell {
  position: relative;
  flex: 1 1 16rem;
  display: flex;
  align-items: center;
  overflow: hidden;
  border: 1.5px solid var(--ink);
  border-radius: var(--radius-sm);
  background: var(--paper-bright);
  transition: box-shadow 0.15s ease;
}

.input-shell:focus-within {
  box-shadow: 3px 3px 0 var(--gold);
}

.input-shell .at {
  padding-left: 0.9rem;
  font-size: 1rem;
  line-height: 1;
  color: var(--ink-soft);
  user-select: none;
}

#username {
  flex: 1;
  min-width: 0;
  padding: 0.85rem 0.9rem 0.85rem 0.3rem;
  border: 0;
  background: none;
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 1rem;
}

#username:focus {
  outline: none;
}

#username::placeholder {
  color: #a89b84;
}

.btn-find {
  flex: 0 0 auto;
  position: relative;
  overflow: hidden;
  padding: 0.9rem 1.4rem;
  border: 1.5px solid var(--ink);
  border-radius: var(--radius-sm);
  background: var(--jade-deep);
  color: var(--paper);
  font-family: var(--font-mono);
  font-size: 0.9rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
  box-shadow: 3px 3px 0 var(--ink);
}

.btn-find:hover {
  background: var(--jade);
  transform: translate(-1px, -1px);
  box-shadow: 4px 4px 0 var(--ink);
}

.btn-find:active {
  transform: translate(1px, 1px);
  box-shadow: 1px 1px 0 var(--ink);
}

.btn-find:focus-visible {
  outline: 2px solid var(--gold-deep);
  outline-offset: 3px;
}

.btn-find[disabled] {
  cursor: progress;
  background: var(--jade);
}

/* Paper-coloured sweep while a lookup is in flight. */
.btn-find[disabled]::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(100deg, transparent 20%, rgba(246, 239, 226, 0.35) 50%, transparent 80%);
  transform: translateX(-100%);
  animation: sweep 1.1s linear infinite;
}

@keyframes sweep {
  to {
    transform: translateX(100%);
  }
}

.hint {
  margin: 0.9rem 0 0;
  font-size: 0.75rem;
  color: var(--ink-soft);
}

.hint code {
  font-family: inherit;
  color: var(--gold-deep);
}

/* --- Update board ------------------------------------------------------- */

.board {
  margin-top: clamp(1.75rem, 4vw, 2.25rem);
  max-width: 640px;
  border: 1.5px solid var(--ink);
  border-left: 5px solid var(--gold-deep);
  border-radius: var(--radius);
  background: var(--paper-bright);
  box-shadow: var(--lift-sm);
}

.board:not(:has(.board-item)) {
  display: none;
}

.board-title {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  margin: 0;
  padding: 0.75rem 1.1rem;
  border-bottom: 1px dashed var(--rule);
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: 500;
  color: var(--ink);
}

.board-mark {
  font-size: 1.35rem;
  line-height: 1;
  color: var(--gold);
}

.board-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.board-item {
  padding: 0.85rem 1.1rem 0.95rem;
}

.board-item + .board-item {
  border-top: 1px dashed var(--rule);
}

.board-item p {
  margin: 0;
}

.board-meta {
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.board-tag {
  font-weight: 700;
  color: var(--danger);
}

.board-item .board-th {
  margin-top: 0.35rem;
  font-family: system-ui, 'Noto Sans Thai', 'Leelawadee UI', sans-serif;
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.55;
  color: var(--ink);
}

.board-item .board-en {
  margin-top: 0.2rem;
  font-size: 0.8rem;
  color: var(--ink-soft);
}

/* --- Results shell ------------------------------------------------------- */

.results {
  margin-top: clamp(2rem, 4vw, 2.5rem);
}

.panel {
  border: 1.5px solid var(--ink);
  border-radius: var(--radius);
  background: var(--paper-bright);
  box-shadow: var(--lift);
  overflow: hidden;
}

.panel-quiet {
  padding: clamp(2rem, 6vw, 3rem) 1.5rem;
  text-align: center;
  border: 1px dashed var(--rule);
  border-radius: var(--radius);
  background: var(--paper);
  color: var(--ink-soft);
}

.panel-quiet .mark {
  font-family: var(--font-display);
  font-size: 2.4rem;
  line-height: 1;
  color: var(--gold);
}

.panel-quiet h3 {
  margin: 0.7rem 0 0.35rem;
  font-family: var(--font-display);
  font-size: 1.25rem;
  font-weight: 500;
  color: var(--ink);
}

.panel-quiet p {
  margin: 0 auto;
  max-width: 42ch;
  font-size: 0.85rem;
}

.panel-quiet strong {
  color: var(--ink);
}

.panel-quiet.is-error {
  border: 1.5px solid var(--danger);
  color: var(--danger);
}

.panel-quiet.is-error .mark,
.panel-quiet.is-error h3 {
  color: var(--danger);
}

/* --- Summary tiles ------------------------------------------------------- */

.result-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.3rem 0.7rem;
  margin-bottom: 1rem;
}

.result-head h3 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.35rem;
  font-weight: 600;
  color: var(--ink);
}

.result-head .count {
  color: var(--ink-soft);
  font-size: 0.78rem;
}

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 0.85rem;
  margin-bottom: 1.35rem;
}

.tile {
  padding: 0.85rem 1rem;
  border: 1.5px solid var(--ink);
  border-radius: var(--radius-sm);
  background: var(--paper-bright);
  box-shadow: var(--lift-sm);
}

.tile dt {
  margin: 0 0 0.3rem;
  font-size: 0.66rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.tile dd {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-weight: 600;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}

.tile-accent {
  background: rgba(169, 120, 47, 0.12);
}

.tile-accent dd {
  color: var(--gold-deep);
}

.tile-settled {
  background: rgba(63, 93, 77, 0.1);
}

.tile-settled dd {
  color: var(--jade-deep);
}

/* Totals on the left, one KEX parcel box per lot beside them. */
.summary {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.25fr);
  gap: 0.85rem;
  align-items: start;
  margin-bottom: 1.35rem;
}

.summary .tiles {
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  margin-bottom: 0;
}

.parcels-title {
  margin: 0 0 0.45rem;
  font-size: 0.66rem;
  font-weight: 400;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.parcel-list {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.6rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.parcel {
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding: 0.7rem 0.8rem;
  border: 1.5px dashed var(--rule);
  border-radius: var(--radius-sm);
  background: var(--paper-bright);
}

.parcel.is-shipped {
  border: 1.5px solid var(--jade-deep);
  box-shadow: var(--lift-sm);
}

.parcel-lot {
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: 600;
  line-height: 1.15;
  color: var(--gold-deep);
  overflow-wrap: anywhere;
}

.parcel-meta {
  margin-top: 0.2rem;
  font-size: 0.62rem;
  color: var(--ink-soft);
}

.parcel-pending {
  margin-top: 0.6rem;
  font-size: 0.66rem;
  color: var(--ink-soft);
}

.parcel .kex-link {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}

.parcels-more {
  margin: 0.45rem 0 0;
  font-size: 0.66rem;
  color: var(--ink-soft);
}

@media (max-width: 860px) {
  .summary {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 520px) {
  .parcel-list {
    grid-template-columns: 1fr;
  }
}

/* --- Ledger table -------------------------------------------------------- */

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

/* Reversed header band: ink ground, paper lettering. */
thead th {
  padding: 0.75rem 0.9rem;
  text-align: left;
  white-space: nowrap;
  font-family: var(--font-mono);
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--paper);
  background: var(--ink);
}

thead th.num,
td.num {
  text-align: right;
}

tbody tr {
  animation: rise 0.42s cubic-bezier(0.22, 1, 0.36, 1) backwards;
}

tbody tr:nth-child(odd) {
  background: rgba(169, 120, 47, 0.05);
}

tbody tr:hover {
  background: rgba(63, 93, 77, 0.08);
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(9px);
  }
}

td {
  padding: 0.75rem 0.9rem;
  border-bottom: 1px solid var(--rule);
  vertical-align: top;
}

tbody tr:last-child td {
  border-bottom: 0;
}

td.lot {
  font-variant-numeric: tabular-nums;
  color: var(--gold-deep);
  white-space: nowrap;
}

td.lot .ledger {
  display: block;
  margin-top: 0.15rem;
  font-size: 0.65rem;
  color: var(--ink-soft);
}

td.user {
  color: var(--ink-soft);
  white-space: nowrap;
}

td.product {
  min-width: 12rem;
  max-width: 20rem;
  color: var(--ink);
}

td.product .date {
  display: block;
  margin-top: 0.15rem;
  font-size: 0.65rem;
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
}

td.num {
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

td.remaining strong {
  color: var(--gold-deep);
  font-weight: 700;
}

td.remaining .settled {
  color: var(--jade-deep);
}

.muted {
  color: var(--ink-soft);
}

/* --- Status pill + progress track ---------------------------------------- */

/* Outline-only pills: the stage colour is carried by currentColor, so the
   border, the dot and the progress track can never disagree. Every colour used
   here clears 4.5:1 on the row ground — `--gold` does not, so it stays on large
   glyphs and non-text only. `other` is the unrecognised-status fallback and is
   deliberately neutral. */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.2rem 0.6rem;
  border: 1px solid currentColor;
  border-radius: 999px;
  font-size: 0.68rem;
  line-height: 1.45;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.badge::before {
  content: '';
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: currentColor;
  flex: none;
}

.badge-awaiting { color: var(--ink-soft); }
.badge-seller { color: var(--gold-deep); }
.badge-warehouse { color: var(--slate); }
.badge-transit { color: var(--plum); }
.badge-arrived { color: var(--jade-deep); }
.badge-other { color: var(--ink-soft); }
.badge-paid { color: var(--jade-deep); }
.badge-deposit { color: var(--gold-deep); }
.badge-unknown { color: var(--ink-soft); }

.badge-sm {
  font-size: 0.64rem;
  padding: 0.14rem 0.5rem;
}

td.status {
  min-width: 11.5rem;
  white-space: normal;
}

.track {
  display: flex;
  gap: 3px;
  margin-top: 0.5rem;
  width: 84px;
}

.track span {
  height: 3px;
  flex: 1;
  border-radius: 1px;
  background: var(--rule);
}

.track span.on {
  background: currentColor;
}

/* The track inherits its colour from the stage so it reads with the pill. */
.track-awaiting { color: var(--ink-soft); }
.track-seller { color: var(--gold-deep); }
.track-warehouse { color: var(--slate); }
.track-transit { color: var(--plum); }
.track-arrived { color: var(--jade-deep); }
.track-other { color: var(--ink-soft); }

/* KEX parcel link: appears under the status once the shop records a tracking number. */
.kex {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.3rem;
  margin-top: 0.6rem;
}

.kex-link {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.2rem 0.55rem 0.2rem 0.2rem;
  border: 1px solid var(--jade-deep);
  border-radius: var(--radius-sm);
  font-size: 0.68rem;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.03em;
  color: var(--jade-deep);
  text-decoration: none;
  white-space: nowrap;
}

.kex-link:hover,
.kex-link:focus-visible {
  background: var(--jade-deep);
  color: var(--paper-bright);
}

.kex-tag {
  padding: 0.05rem 0.3rem;
  border-radius: 2px;
  font-size: 0.58rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  background: var(--jade-deep);
  color: var(--paper-bright);
}

.kex-link:hover .kex-tag,
.kex-link:focus-visible .kex-tag {
  background: var(--paper-bright);
  color: var(--jade-deep);
}

/* --- Loading skeleton ---------------------------------------------------- */

.skeleton-row {
  display: grid;
  grid-template-columns: 4rem 1fr 8rem 5rem;
  gap: 1rem;
  padding: 0.9rem;
  border-bottom: 1px solid var(--rule);
}

.skeleton-row:last-child {
  border-bottom: 0;
}

.skeleton-row span {
  height: 12px;
  border-radius: 2px;
  background: linear-gradient(90deg, var(--paper-dark) 0%, var(--paper-bright) 50%, var(--paper-dark) 100%);
  background-size: 200% 100%;
  animation: shimmer 1.4s ease-in-out infinite;
}

@keyframes shimmer {
  from {
    background-position: 200% 0;
  }
  to {
    background-position: -200% 0;
  }
}

/* --- Notices ------------------------------------------------------------- */

.notice {
  display: flex;
  gap: 0.6rem;
  margin-bottom: 1rem;
  padding: 0.7rem 0.9rem;
  border: 1.5px solid var(--gold-deep);
  border-radius: var(--radius-sm);
  background: rgba(169, 120, 47, 0.1);
  font-size: 0.78rem;
  color: var(--gold-deep);
}

.notice::before {
  content: '!';
  flex: none;
  display: grid;
  place-items: center;
  width: 1.1rem;
  height: 1.1rem;
  margin-top: 1px;
  border: 1px solid currentColor;
  border-radius: 50%;
  font-size: 0.68rem;
  font-weight: 700;
}

/* --- Footer -------------------------------------------------------------- */

.foot {
  margin-top: 2.75rem;
  padding-top: 1.35rem;
  border-top: 1px dashed var(--rule);
  font-size: 0.72rem;
  color: var(--ink-soft);
  text-align: center;
}

.foot p {
  margin: 0 0 0.3rem;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* --- Narrow screens: the table becomes a stack of ledger cards ----------- */

@media (max-width: 860px) {
  .panel {
    border: 0;
    background: none;
    box-shadow: none;
    overflow: visible;
  }

  .table-wrap {
    overflow: visible;
  }

  thead {
    display: none;
  }

  table,
  tbody,
  tr,
  td {
    display: block;
    width: 100%;
  }

  tbody tr,
  tbody tr:nth-child(odd),
  tbody tr:hover {
    margin-bottom: 0.9rem;
    padding: 1rem 1.1rem;
    border: 1.5px solid var(--ink);
    border-radius: var(--radius);
    background: var(--paper-bright);
    box-shadow: 4px 4px 0 var(--shadow);
  }

  td {
    padding: 0;
    border-bottom: 0;
  }

  td.product {
    max-width: none;
    margin-bottom: 0.6rem;
    padding-right: 0;
    font-family: var(--font-display);
    font-size: 0.98rem;
    font-weight: 600;
    line-height: 1.35;
  }

  td.product .date {
    font-family: var(--font-mono);
    font-weight: 400;
  }

  td.lot {
    display: inline-block;
    width: auto;
    margin-bottom: 0.45rem;
    font-size: 0.7rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
  }

  td.lot .ledger {
    display: inline;
    margin-left: 0.4rem;
  }

  td.user {
    display: none; /* the customer already knows their own username */
  }

  td.status {
    margin-bottom: 0.75rem;
  }

  .track {
    width: 110px;
  }

  /* Money row: label above value, three across. */
  td.num {
    display: inline-block;
    width: 33.333%;
    text-align: left;
    padding-top: 0.7rem;
    border-top: 1px dashed var(--rule);
  }

  td.num::before {
    content: attr(data-label);
    display: block;
    margin-bottom: 0.12rem;
    font-size: 0.62rem;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--ink-soft);
  }
}

@media (max-width: 400px) {
  .field {
    flex-direction: column;
  }

  .btn-find {
    width: 100%;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms;
    animation-iteration-count: 1;
    transition-duration: 0.001ms;
  }
}
