@font-face {
  font-family: "Noto Sans Thai";
  src: url("fonts/noto-sans-thai-400.ttf") format("truetype");
  font-style: normal;
  font-weight: 400;
  font-display: swap;
}

@font-face {
  font-family: "Noto Sans Thai";
  src: url("fonts/noto-sans-thai-500.ttf") format("truetype");
  font-style: normal;
  font-weight: 500;
  font-display: swap;
}

@font-face {
  font-family: "Noto Sans Thai";
  src: url("fonts/noto-sans-thai-600.ttf") format("truetype");
  font-style: normal;
  font-weight: 600;
  font-display: swap;
}

@font-face {
  font-family: "Noto Sans Thai";
  src: url("fonts/noto-sans-thai-700.ttf") format("truetype");
  font-style: normal;
  font-weight: 700;
  font-display: swap;
}

@font-face {
  font-family: "Noto Sans Thai";
  src: url("fonts/noto-sans-thai-800.ttf") format("truetype");
  font-style: normal;
  font-weight: 800;
  font-display: swap;
}

:root {
  color-scheme: light;
  --ink: #17352e;
  --muted: #61736e;
  --paper: #ffffff;
  --canvas: #f3f6f2;
  --line: #dbe4df;
  --green: #1e6654;
  --green-dark: #143d33;
  --mint: #dff4e9;
  --gold: #f2c86b;
  --danger: #a53d3d;
  --shadow: 0 10px 28px rgba(25, 64, 53, 0.08);
  font-family: "Noto Sans Thai", "Leelawadee UI", Tahoma, sans-serif;
}

* {
  box-sizing: border-box;
  font-family: inherit;
}

body {
  margin: 0;
  min-width: 320px;
  background:
    radial-gradient(circle at top right, rgba(223, 244, 233, 0.9), transparent 35rem),
    radial-gradient(circle at left bottom, rgba(255, 244, 214, 0.72), transparent 18rem),
    var(--canvas);
  color: var(--ink);
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(115deg, rgba(20, 61, 51, 0.02), transparent 36%),
    linear-gradient(315deg, rgba(20, 61, 51, 0.03), transparent 42%);
  z-index: -1;
}

.preview-mode-banner {
  position: fixed;
  right: 16px;
  bottom: 82px;
  z-index: 40;
  max-width: calc(100% - 32px);
  padding: 9px 13px;
  border-radius: 999px;
  background: linear-gradient(135deg, #fff0c9, #ffe3a0);
  color: #72520d;
  font-size: 0.75rem;
  font-weight: 800;
  box-shadow: var(--shadow);
}

.access-gate {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(20, 61, 51, 0.82);
  backdrop-filter: blur(10px);
}

.access-gate-card {
  width: min(430px, 100%);
  padding: 28px;
  border-radius: 24px;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.96), rgba(248, 251, 249, 0.96)),
    white;
  border: 1px solid rgba(219, 228, 223, 0.9);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.28);
}

.access-gate-card > img {
  display: block;
  width: 70px;
  height: 70px;
  margin-bottom: 14px;
}

.access-gate-card h1 {
  margin: 4px 0 6px;
  font-size: 1.5rem;
  letter-spacing: -0.01em;
}

.access-message {
  margin: 0 0 18px;
  color: var(--muted);
}

.access-gate-card form {
  display: grid;
  gap: 12px;
}

.access-error {
  min-height: 22px;
  margin: 12px 0 0;
  color: var(--danger);
  font-size: 0.82rem;
}

.first-dev-link {
  display: block;
  margin-top: 8px;
  color: var(--green);
  font-size: 0.8rem;
  font-weight: 800;
  text-align: center;
}

input[readonly] {
  background: #eef3f0;
  color: var(--muted);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 70px;
  padding: 12px max(20px, calc((100vw - 1160px) / 2));
  background: rgba(255, 255, 255, 0.88);
  border-bottom: 1px solid rgba(219, 228, 223, 0.8);
  backdrop-filter: blur(14px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 13px;
  background: var(--green);
  color: white;
  font-size: 22px;
  font-weight: 800;
  box-shadow: 0 7px 18px rgba(30, 102, 84, 0.25);
}

.selected-brand-mark {
  overflow: hidden;
  padding: 0;
  border-radius: 50%;
  background: #ed1c24;
}

.selected-brand-mark img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.eyebrow,
.step-label {
  margin: 0;
  color: var(--green);
  font-size: 0.73rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.brand h1 {
  margin: 1px 0 0;
  font-size: 1rem;
}

.demo-badge {
  padding: 6px 11px;
  border-radius: 999px;
  background: #fff4d6;
  color: #79580e;
  font-size: 0.78rem;
  font-weight: 800;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.nav-link {
  padding: 8px 11px;
  border-radius: 10px;
  color: var(--green);
  font-size: 0.82rem;
  font-weight: 800;
  text-decoration: none;
}

.nav-link:hover {
  background: var(--mint);
}

.page-shell {
  width: min(1160px, calc(100% - 28px));
  margin: 24px auto 120px;
}

.intro-card,
.summary-card {
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 28px 30px;
  border-radius: 24px;
  background:
    linear-gradient(125deg, rgba(255,255,255,0.07), transparent 45%),
    var(--green-dark);
  color: white;
  box-shadow: 0 14px 36px rgba(20, 61, 51, 0.2);
}

.intro-card {
  position: relative;
}

.intro-card::after,
.summary-card::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(circle at 88% 12%, rgba(242, 200, 107, 0.18), transparent 16rem),
    radial-gradient(circle at 12% 86%, rgba(223, 244, 233, 0.08), transparent 14rem);
}

.intro-card > *,
.summary-card > * {
  position: relative;
  z-index: 1;
}

.intro-card h2,
.summary-card h2 {
  margin: 4px 0 8px;
  font-size: clamp(1.55rem, 4vw, 2.25rem);
  line-height: 1.25;
}

.intro-card p:last-child {
  max-width: 590px;
  margin: 0;
  color: #cfe0da;
}

.light {
  color: var(--gold);
}

.intro-number {
  flex: 0 0 160px;
  text-align: center;
}

.intro-number strong {
  display: block;
  font-size: 3.2rem;
  line-height: 1;
}

.intro-number span {
  color: #cfe0da;
  font-size: 0.82rem;
}

.card {
  margin-top: 18px;
  padding: 24px;
  border: 1px solid rgba(219, 228, 223, 0.85);
  border-radius: 22px;
  background: var(--paper);
  box-shadow: var(--shadow);
}

.section-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.section-heading h2 {
  margin: 2px 0 0;
  font-size: 1.35rem;
  letter-spacing: -0.01em;
}

.save-state {
  padding: 6px 10px;
  border-radius: 999px;
  background: #f2f4f3;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 700;
}

.save-state.saved {
  background: var(--mint);
  color: var(--green);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
}

label {
  display: grid;
  gap: 7px;
  color: #344b45;
  font-size: 0.83rem;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid #ccd9d3;
  border-radius: 12px;
  background: white;
  color: var(--ink);
  outline: none;
  transition: border-color 0.18s, box-shadow 0.18s;
}

input,
select {
  min-height: 46px;
  padding: 10px 12px;
}

textarea {
  padding: 12px;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(30, 102, 84, 0.12);
}

.text-button {
  border: 0;
  background: transparent;
  color: var(--green);
  font-weight: 800;
}

.entry-legend {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 10px;
  border: 1px solid #e4b84d;
  border-radius: 999px;
  background: linear-gradient(135deg, #fff6d9, #fff1c1);
  color: #76570d;
  font-size: 0.76rem;
  font-weight: 800;
}

.entry-legend span {
  width: 12px;
  height: 12px;
  border: 2px solid #d59800;
  border-radius: 4px;
  background: #fff1ad;
}

.toolbar {
  display: grid;
  grid-template-columns: 1fr 210px;
  gap: 12px;
}

.search-box {
  position: relative;
}

.search-box span {
  position: absolute;
  left: 14px;
  bottom: 11px;
  z-index: 1;
  color: var(--muted);
  font-size: 1.2rem;
}

.search-box input {
  padding-left: 40px;
}

.column-guide {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin: 16px 0;
  padding: 10px;
  border-radius: 12px;
  background: #f6f9f7;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.column-guide b {
  color: var(--green);
}

.item-list {
  display: grid;
  gap: 10px;
}

.item-card {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: white;
  transition: border-color 0.18s, box-shadow 0.18s;
}

.item-card.has-data {
  border-color: #9fcbb9;
}

.item-card.open {
  border-color: var(--green);
  box-shadow: 0 8px 22px rgba(30, 102, 84, 0.1);
}

.item-summary {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) 76px 24px;
  align-items: center;
  width: 100%;
  min-height: 66px;
  padding: 8px 14px 8px 10px;
  border: 0;
  background: transparent;
  color: var(--ink);
  text-align: left;
}

.item-number {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border-radius: 10px;
  background: #eef3f0;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.has-data .item-number {
  background: var(--mint);
  color: var(--green);
}

.item-name-wrap {
  min-width: 0;
}

.item-name {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.92rem;
}

.item-unit {
  color: var(--muted);
}

.item-price {
  display: block;
  margin-top: 2px;
  color: #8a5400;
  font-size: 0.72rem;
  font-weight: 800;
}

.item-result {
  text-align: right;
}

.item-result small {
  display: block;
  color: var(--muted);
  font-size: 0.68rem;
}

.item-result b {
  color: var(--green);
  font-size: 1.1rem;
}

.chevron {
  margin-left: 7px;
  color: var(--muted);
  font-size: 1.35rem;
  transition: transform 0.2s;
}

.open .chevron {
  transform: rotate(180deg);
}

.item-fields {
  padding: 0 16px 16px;
  border-top: 1px solid #edf1ef;
  background: #fbfcfb;
}

.item-meta-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin: 14px 0;
}

.pack-size-field {
  grid-template-columns: 1fr 100px;
  align-items: center;
  max-width: 100%;
  margin: 0;
}

.pack-size-field input {
  min-height: 40px;
}

.price-field {
  grid-template-columns: 1fr 130px;
  align-items: center;
}

.price-field input {
  min-height: 40px;
}

fieldset {
  display: grid;
  grid-template-columns: repeat(2, minmax(90px, 1fr)) minmax(90px, 0.8fr);
  gap: 10px;
  margin: 10px 0 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: linear-gradient(180deg, #ffffff, #fcfdfc);
}

legend {
  padding: 0 7px;
  color: var(--green);
  font-size: 0.8rem;
  font-weight: 800;
}

fieldset input {
  min-height: 42px;
}

.stock-block {
  align-content: start;
}

.auto-stock {
  border-color: #c9d9d2;
  background: #f4f8f6;
}

.input-stock {
  border: 2px solid #d79b00;
  background: linear-gradient(180deg, #fff8dc, #fff3c7);
  box-shadow: 0 5px 16px rgba(185, 127, 0, 0.1);
}

.input-stock legend {
  color: #76570d;
}

.input-stock input {
  border: 2px solid #d79b00;
  background: #fffdf5;
  color: #3e3007;
  font-size: 1rem;
  font-weight: 800;
}

.input-stock input:focus {
  border-color: #ad6500;
  box-shadow: 0 0 0 4px rgba(215, 155, 0, 0.22);
}

.sold-stock {
  border-color: #d87a2d;
  background: linear-gradient(180deg, #fff1e6, #ffe8da);
}

.sold-stock input {
  border-color: #d87a2d;
}

.required-chip {
  margin-left: 4px;
  padding: 2px 7px;
  border-radius: 999px;
  background: #8a5400;
  color: white;
  font-size: 0.67rem;
}

.calculated-field {
  display: grid;
  align-content: center;
  min-height: 68px;
  padding: 8px 12px;
  border-radius: 10px;
  background: #eef5f1;
}

.calculated-field span {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
}

.calculated-field strong {
  font-size: 1.08rem;
}

.stock-warning {
  grid-column: 1 / -1;
  margin: 4px 0 0;
  padding: 10px 12px;
  border: 1px solid #dd7777;
  border-radius: 10px;
  background: #fff0f0;
  color: #8e2727;
  font-size: 0.8rem;
  font-weight: 800;
}

.item-card.invalid-stock {
  border: 2px solid #bf4141;
  box-shadow: 0 0 0 3px rgba(191, 65, 65, 0.11);
}

.item-card.invalid-stock .remaining-value,
.item-card.invalid-stock .remaining-total {
  color: #b62f2f;
}

.is-loading .item-list {
  opacity: 0.58;
  pointer-events: none;
}

button:disabled {
  cursor: wait;
  opacity: 0.66;
}

.sold-panel {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  margin-top: 12px;
  padding: 14px 16px;
  border-radius: 14px;
  background: var(--green-dark);
  color: white;
}

.sold-panel > span {
  color: var(--gold);
  font-weight: 800;
}

.sold-panel strong {
  font-size: 1.25rem;
}

.sold-panel small {
  grid-column: 1 / -1;
  color: #bcd1ca;
}

.empty-message {
  padding: 28px;
  color: var(--muted);
  text-align: center;
}

.summary-card {
  margin-top: 18px;
  position: relative;
}

.summary-card h2 {
  font-size: 1.4rem;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  flex: 1;
}

.summary-grid > div {
  padding: 12px;
  border-left: 1px solid rgba(255, 255, 255, 0.13);
  text-align: center;
}

.summary-grid span,
.summary-grid small {
  display: block;
  color: #bfd3cc;
  font-size: 0.75rem;
}

.summary-grid strong {
  display: block;
  margin: 2px 0;
  font-size: 1.75rem;
}

.summary-grid .highlight-total strong {
  color: var(--gold);
}

.notes-card {
  margin-bottom: 20px;
}

.action-bar {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 20;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 12px max(20px, calc((100vw - 1160px) / 2));
  padding-bottom: max(12px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 -8px 24px rgba(25, 64, 53, 0.08);
  backdrop-filter: blur(14px);
}

.primary-button,
.secondary-button {
  min-height: 46px;
  padding: 10px 18px;
  border-radius: 12px;
  font-weight: 800;
}

.primary-button {
  border: 1px solid var(--green);
  background: var(--green);
  color: white;
}

.secondary-button {
  border: 1px solid #cbd8d2;
  background: white;
  color: var(--ink);
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 84px;
  z-index: 30;
  max-width: 340px;
  padding: 12px 16px;
  border-radius: 12px;
  background: #102c25;
  color: white;
  box-shadow: 0 10px 26px rgba(0,0,0,0.2);
  opacity: 0;
  pointer-events: none;
  transform: translateY(10px);
  transition: opacity 0.2s, transform 0.2s;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

@media (min-width: 840px) {
  .item-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: start;
  }

  .item-card.open {
    grid-column: 1 / -1;
  }

  .item-card.open .item-fields {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
  }

  .item-card.open .item-meta-grid,
  .item-card.open .stock-warning {
    grid-column: 1 / -1;
  }
}

@media (max-width: 780px) {
  .page-shell {
    width: min(100% - 20px, 620px);
    margin-top: 12px;
  }

  .topbar {
    min-height: 62px;
    padding: 9px 12px;
  }

  .brand-mark {
    width: 38px;
    height: 38px;
  }

  .intro-card {
    align-items: flex-end;
    padding: 22px 20px;
  }

  .intro-card p:last-child {
    font-size: 0.84rem;
  }

  .intro-number {
    flex-basis: 88px;
  }

  .intro-number strong {
    font-size: 2.5rem;
  }

  .card {
    padding: 18px 14px;
    border-radius: 18px;
  }

  .form-grid {
    grid-template-columns: 1fr 1fr;
  }

  .summary-card {
    display: block;
    padding: 20px;
  }

  .summary-grid {
    margin-top: 12px;
    grid-template-columns: repeat(2, 1fr);
  }

  .summary-grid > div:nth-child(odd) {
    border-left: 0;
  }
}

@media (max-width: 520px) {
  .brand .eyebrow,
  .desktop-only {
    display: none;
  }

  .nav-link {
    max-width: 100px;
    padding: 7px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .intro-card h2 {
    font-size: 1.35rem;
  }

  .intro-card p:last-child {
    display: none;
  }

  .form-grid,
  .toolbar {
    grid-template-columns: 1fr;
  }

  .items-heading {
    align-items: center;
  }

  .entry-legend {
    max-width: 155px;
    border-radius: 12px;
    line-height: 1.3;
  }

  .column-guide {
    gap: 6px;
    overflow-x: auto;
    justify-content: flex-start;
    white-space: nowrap;
  }

  .item-summary {
    grid-template-columns: 38px minmax(0, 1fr) 58px 18px;
    padding-right: 9px;
  }

  .item-fields {
    padding: 0 10px 12px;
  }

  .item-meta-grid {
    grid-template-columns: 1fr;
  }

  fieldset {
    grid-template-columns: repeat(2, 1fr);
  }

  .calculated-field {
    grid-column: 1 / -1;
    min-height: 52px;
  }

  .action-bar {
    padding: 9px 10px max(9px, env(safe-area-inset-bottom));
  }

  .action-bar button {
    flex: 1;
    padding-right: 10px;
    padding-left: 10px;
  }
}

@media print {
  body {
    background: white;
  }

  .topbar,
  .intro-card,
  .toolbar,
  .column-guide,
  .text-button,
  .action-bar,
  .toast {
    display: none !important;
  }

  .page-shell {
    width: 100%;
    margin: 0;
  }

  .card,
  .summary-card {
    box-shadow: none;
    break-inside: avoid;
  }

  .item-list {
    grid-template-columns: 1fr 1fr;
  }

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

  .item-fields {
    display: none !important;
  }
}
