:root {
  --bg: #f4efe4;
  --card: #fffdf8;
  --ink: #1c1914;
  --muted: #6b6458;
  --line: #e4d8c4;
  --price: #0d6b3a;
  --accent: #c45c00;
  --accent-ink: #fff;
  --chip: #efe6d4;
  --stale: #8a8172;
  --danger: #9b2c2c;
  --shadow: 0 8px 28px rgba(60, 40, 10, 0.12);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16140f;
    --card: #221f18;
    --ink: #f4efe4;
    --muted: #b3aa9a;
    --line: #3a3428;
    --price: #6ee7a8;
    --accent: #ffb020;
    --accent-ink: #1c1914;
    --chip: #2c281f;
    --stale: #9c9486;
    --danger: #f0a0a0;
    --shadow: 0 10px 28px rgba(0, 0, 0, 0.35);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "PingFang HK", "Noto Sans TC", "Hiragino Sans GB", sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.3;
  padding-bottom: calc(1rem + var(--safe-bottom));
}
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}
.top {
  position: sticky;
  top: 0;
  z-index: 4;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.6rem;
  padding: calc(0.45rem + env(safe-area-inset-top)) 0.75rem 0.4rem;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; gap: 0.45rem; align-items: center; }
.brand img, .brand svg { width: 28px; height: 28px; }
.brand h1 { margin: 0; font-size: 1.05rem; letter-spacing: 0.02em; }
.brand p, .sync { margin: 0; color: var(--muted); font-size: 0.75rem; }
main { max-width: 40rem; margin: 0 auto; padding: 0.45rem 0.6rem 0.8rem; }
.toolbar {
  display: flex;
  gap: 0.35rem;
  align-items: center;
  margin-bottom: 0.45rem;
}
#search, select, input, button {
  font: inherit;
  color: inherit;
}
#search,
select,
input[type="number"],
input[type="datetime-local"],
input[type="text"],
input[type="search"],
input[type="password"],
input:not([type]) {
  width: 100%;
  min-height: 2.9rem;
  padding: 0.55rem 0.8rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
}
.chips {
  display: flex;
  gap: 0.3rem;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  flex: 1;
}
.chip, .kind, .ghost, .fab, .actions button, .alert button, .report {
  min-height: 2rem;
  border: 0;
  border-radius: 999px;
  padding: 0.2rem 0.7rem;
  background: var(--chip);
  color: var(--ink);
}
.chip.new-shop {
  flex: 0 0 auto;
  font-size: 0.82rem;
  font-weight: 700;
}
.chip.is-on {
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 700;
}
.status { color: var(--danger); }
.section { margin: 0.45rem 0 0.35rem; }
.section h2 {
  margin: 0 0 0.2rem;
  font-size: 0.78rem;
  color: var(--muted);
  font-weight: 700;
}
.hint { font-weight: 500; margin-left: 0.3rem; }
.list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
}
.card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  grid-template-areas: "who price report";
  align-items: center;
  gap: 0.1rem 0.28rem;
  padding: 0.32rem 0.38rem 0.3rem;
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-right: 1px solid var(--line);
  border-radius: 0;
}
.card:nth-child(2n) { border-right: 0; }
.card:nth-last-child(-n + 2):nth-child(odd) { border-bottom: 0; }
.card:last-child { border-bottom: 0; }
.who {
  grid-area: who;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.04rem;
}
.card h3 {
  margin: 0;
  font-size: 0.88rem;
  font-weight: 650;
  line-height: 1.2;
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.meta {
  margin: 0;
  color: var(--muted);
  font-size: 0.65rem;
  white-space: nowrap;
}
.amounts {
  grid-area: price;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  justify-content: center;
  gap: 0.02rem;
  text-align: right;
}
.price {
  margin: 0;
  font-size: 0.98rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.03em;
  color: var(--price);
  text-align: right;
  line-height: 1.1;
  white-space: nowrap;
}
.amounts.stacked .price {
  display: flex;
  align-items: baseline;
  gap: 0.16rem;
  font-size: 0.8rem;
  line-height: 1.15;
}
.price-kind {
  font-size: 0.58rem;
  font-weight: 700;
  color: var(--muted);
}
.card.stale .price { color: var(--stale); }
.card.stale .price-kind { color: var(--stale); }
.report {
  grid-area: report;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 0.68rem;
  font-weight: 700;
  min-height: 1.55rem;
  padding: 0.08rem 0.38rem;
  align-self: center;
}
.empty { color: var(--muted); padding: 0.8rem 0.2rem; }
.fab { display: none; }
.sheet { position: fixed; inset: 0; z-index: 8; }
.backdrop {
  position: absolute;
  inset: 0;
  background: rgba(20, 16, 10, 0.45);
  border: 0;
  width: 100%;
  height: 100%;
}
.panel {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: 92vh;
  overflow: auto;
  padding: 1rem 1rem calc(1rem + var(--safe-bottom));
  background: var(--bg);
  border-radius: 20px 20px 0 0;
  box-shadow: var(--shadow);
  display: grid;
  gap: 0.45rem;
}
.panel h2 { margin: 0 0 0.4rem; }
.price-head {
  margin: 0.15rem 0 0;
  font-size: 0.82rem;
  font-weight: 700;
}
.price-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 0.4rem;
}
.price-cell {
  display: grid;
  gap: 0.18rem;
}
.price-cell label {
  font-size: 0.75rem;
  color: var(--muted);
  font-weight: 700;
}
.price-cell input {
  min-height: 2.5rem;
  padding: 0.35rem 0.25rem;
  text-align: center;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  appearance: textfield;
}
.price-cell input::-webkit-outer-spin-button,
.price-cell input::-webkit-inner-spin-button {
  appearance: none;
  margin: 0;
}
.turnstile-box {
  margin: 0.15rem 0 0.1rem;
  min-height: 1px;
}
.preview {
  margin: 0.15rem 0 0.4rem;
  padding: 0.65rem 0.8rem;
  background: var(--card);
  border-radius: 12px;
  color: var(--muted);
  font-size: 1rem;
}
.preview strong { color: var(--ink); }
.form-error { color: var(--danger); margin: 0.2rem 0; }
.actions { display: grid; grid-template-columns: 1fr 1.4fr; gap: 0.6rem; margin-top: 0.4rem; }
.actions button[type="submit"] {
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 800;
}
.hp { position: absolute; left: -9999px; height: 0; width: 0; }
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(1.2rem + var(--safe-bottom));
  transform: translateX(-50%);
  z-index: 9;
  margin: 0;
  padding: 0.7rem 1rem;
  background: var(--ink);
  color: var(--bg);
  border-radius: 999px;
  box-shadow: var(--shadow);
  white-space: nowrap;
}
.admin { max-width: 40rem; margin: 0 auto; padding: 1rem; display: grid; gap: 0.7rem; }
.admin button { min-height: 2.6rem; }
.alert {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0.9rem 1rem;
}
.alert.read { opacity: 0.65; }

@media (min-width: 720px) {
  .panel {
    left: 50%;
    right: auto;
    width: 26rem;
    transform: translateX(-50%);
    border-radius: 20px 20px 0 0;
  }
}
