:root {
  --bg: #efe6d6;
  --ink: #1a1510;
  --muted: #6b5e52;
  --paper: #fffaf2;
  --line: #d9cbb6;
  --teal: #134e4a;
  --chili: #c2410c;
  --shadow: 0 8px 20px rgba(67, 48, 26, 0.1);
  --radius: 16px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --label-width: 58mm;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { min-height: 100%; min-height: 100dvh; }
body {
  margin: 0;
  color: var(--ink);
  background: var(--bg);
  font-family: -apple-system, "SF Pro TH", "Leelawadee UI", "Sarabun", "Noto Sans Thai", "Segoe UI", sans-serif;
  overscroll-behavior: none;
}

button, input, select { font: inherit; color: inherit; }
button {
  cursor: pointer;
  touch-action: manipulation;
  appearance: none;
  -webkit-appearance: none;
}
button:disabled { opacity: 0.4; }
input, select {
  font-size: 16px;
  appearance: none;
  -webkit-appearance: none;
  border-radius: 12px;
}

#app { min-height: 100dvh; }

.wrap {
  width: min(480px, 100%);
  margin: 0 auto;
  padding: calc(12px + var(--safe-top)) 12px calc(18px + var(--safe-bottom));
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.logo {
  width: 40px; height: 40px; flex: none;
  background: var(--teal);
  border-radius: 12px;
  display: grid; place-items: center;
}
.logo svg { width: 24px; height: 24px; }
.shop-name {
  font-size: 1.05rem;
  font-weight: 800;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.shop-sub { color: var(--muted); font-size: 0.8rem; }

.icon-btn, .ghost-btn, .primary-btn, .danger-btn, .key, .product, .chip {
  border: 1px solid transparent;
  border-radius: 14px;
}
.icon-btn:active, .ghost-btn:active, .primary-btn:active, .danger-btn:active, .key:active, .product:active, .chip:active {
  transform: scale(0.97);
}

.icon-btn {
  width: 44px; height: 44px; flex: none;
  background: var(--paper);
  border-color: var(--line);
  display: grid; place-items: center;
}
.ghost-btn {
  background: var(--paper);
  border-color: var(--line);
  padding: 12px 14px;
  font-weight: 700;
  min-height: 48px;
}
.primary-btn {
  background: var(--teal);
  color: #fffaf2;
  padding: 14px 16px;
  font-weight: 800;
  font-size: 1.05rem;
  min-height: 52px;
  width: 100%;
}
.primary-btn.print { background: var(--chili); min-height: 56px; font-size: 1.2rem; }
.danger-btn {
  background: #fff1ee;
  border-color: #f0c4b8;
  color: #9a3412;
  padding: 10px 14px;
  font-weight: 700;
  min-height: 44px;
}

.card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
  margin-bottom: 12px;
}

.section-title {
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin: 0 0 8px;
}

.products {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.product {
  min-height: 76px;
  text-align: left;
  padding: 12px 12px 12px 18px;
  background: #fff;
  border: 2px solid var(--line);
  position: relative;
}
.product::before {
  content: "";
  position: absolute; left: 0; top: 0; bottom: 0;
  width: 7px;
  background: var(--swatch, var(--teal));
}
.product.on {
  border-color: var(--swatch, var(--teal));
  background: #eef6f4;
}
.product-name { font-weight: 800; font-size: 1.05rem; }
.product-price { color: var(--muted); margin-top: 2px; font-size: 0.82rem; font-weight: 600; }

.weight-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 8px;
  margin-top: 14px;
}
.weight-display {
  font-size: clamp(2.2rem, 12vw, 3.2rem);
  font-weight: 800;
  letter-spacing: -0.04em;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.unit-toggle { display: flex; gap: 6px; flex: none; }
.chip {
  padding: 10px 12px;
  background: #f3eadb;
  font-weight: 800;
  min-height: 44px;
}
.chip.on { background: var(--teal); color: #fffaf2; }

.keys {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 12px;
}
.key {
  min-height: 58px;
  background: #fff;
  border: 1px solid var(--line);
  font-size: 1.45rem;
  font-weight: 800;
}
.key.muted { background: #f3eadb; font-size: 1.05rem; }

.price-box {
  background: var(--teal);
  color: #fffaf2;
  border-radius: 16px;
  padding: 14px 16px;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  margin-top: 12px;
}
.price-box .lbl { opacity: 0.85; font-weight: 700; font-size: 0.9rem; }
.price-box .val {
  font-size: clamp(1.8rem, 8vw, 2.4rem);
  font-weight: 800;
  letter-spacing: -0.04em;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.label-preview { margin-top: 12px; }
.label-sheet {
  width: 100%;
  max-width: 260px;
  margin: 0 auto;
  background: #fff;
  color: #111;
  border: 1px solid #222;
  padding: 10px 10px 8px;
  text-align: center;
}
.label-name { font-size: 30px; font-weight: 800; margin: 0 0 4px; line-height: 1.15; }
.label-weight { font-size: 20px; font-weight: 700; margin: 4px 0; }
.label-price { font-size: 40px; font-weight: 900; margin: 8px 0 8px; }
.label-time { font-size: 14px; font-weight: 800; }

.actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin-top: 12px;
}

.hint { color: var(--muted); font-size: 0.84rem; line-height: 1.45; margin: 10px 0 0; }
.warn { color: #9a3412; font-weight: 700; }

.form-grid { display: grid; gap: 10px; }
.field label { display: block; font-weight: 700; margin-bottom: 6px; }
.field input, .field select {
  width: 100%;
  background: #fff;
  border: 1px solid var(--line);
  padding: 12px;
  min-height: 48px;
}

.product-edit-card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 10px;
  margin-bottom: 8px;
  display: grid;
  gap: 8px;
}
.product-edit-tools {
  display: flex;
  gap: 8px;
  align-items: center;
}
.swatch {
  width: 44px; height: 44px; border-radius: 10px; border: 1px solid var(--line); padding: 0; overflow: hidden; flex: none;
}
.swatch input { opacity: 0; width: 100%; height: 100%; }
.product-edit-tools .danger-btn { margin-left: auto; }

.row-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.row-actions .ghost-btn, .row-actions .primary-btn { width: auto; flex: 1; }

.history { display: grid; gap: 8px; }
.history-item {
  display: flex; justify-content: space-between; gap: 8px; align-items: center;
  background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px;
}
.history-item b { display: block; }
.history-item span { color: var(--muted); font-size: 0.82rem; }

.setup { padding-top: calc(20px + var(--safe-top)); }

.print-only { display: none !important; }

@media print {
  @page { size: auto; margin: 0; }
  html, body {
    background: #fff !important;
    height: auto;
    margin: 0;
    padding: 0;
  }
  body * { visibility: hidden; }
  #print-root, #print-root * { visibility: visible; }
  #print-root {
    display: block !important;
    position: absolute;
    left: 0; top: 0;
    width: 100%;
    padding: 8px;
    background: #fff;
    color: #000;
  }
  .print-label .name { font-size: 30px; font-weight: 900; margin: 0 0 8px; }
  .print-label .weight { font-size: 26px; font-weight: 900; margin: 2px 0; }
  .print-label .price { font-size: 26px; font-weight: 900; margin: 2px 0 12px; }
  .print-label .time { font-size: 16px; font-weight: 800; }
}
