:root {
  --green: #07c160;
  --green-dark: #06ad56;
  --bg: #f5f6f8;
  --card: #fff;
  --text: #1a1a1a;
  --muted: #8a8a8a;
  --line: #ebebeb;
  --danger: #fa5151;
  --radius: 12px;
  --tab-h: 56px;
  --top-h: 48px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang TC", "Noto Sans TC",
    "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
}
body { max-width: 480px; margin: 0 auto; }

.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 13px; }
.tiny { font-size: 12px; margin-top: 8px; text-align: center; }
.block { width: 100%; }

.btn {
  border: none;
  border-radius: 8px;
  padding: 12px 16px;
  font-size: 15px;
  cursor: pointer;
  font-weight: 600;
}
.btn.primary { background: var(--green); color: #fff; }
.btn.primary:active { background: var(--green-dark); }
.btn.primary:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.ghost {
  background: rgba(7, 193, 96, 0.1);
  color: var(--green);
  font-weight: 500;
  padding: 8px 12px;
  font-size: 13px;
}

/* Login */
.login-screen {
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: linear-gradient(160deg, #e8f8ef 0%, var(--bg) 50%);
}
.login-card {
  background: var(--card);
  border-radius: 16px;
  padding: 28px 22px;
  width: 100%;
  max-width: 340px;
  box-shadow: 0 8px 28px rgba(0,0,0,0.06);
}
.login-logo { font-size: 48px; text-align: center; }
.login-card h1 { text-align: center; font-size: 20px; margin: 8px 0 4px; }
.login-card .muted { text-align: center; margin-bottom: 20px; }
.login-card label { display: block; font-size: 13px; margin-bottom: 6px; color: var(--muted); }
.login-card input, .cash-form input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  font-size: 16px;
  margin-bottom: 16px;
  outline: none;
  background: #fafafa;
}
.login-card input:focus, .cash-form input:focus { border-color: var(--green); background: #fff; }

/* App shell */
.app {
  min-height: 100%;
  padding-bottom: calc(var(--tab-h) + env(safe-area-inset-bottom, 0px) + 12px);
  padding-top: var(--top-h);
}
.topbar {
  position: fixed;
  top: 0; left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  height: var(--top-h);
  background: var(--card);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  z-index: 20;
}
.brand { font-weight: 700; font-size: 16px; }
.user-chip {
  font-size: 13px;
  color: var(--muted);
  background: var(--bg);
  padding: 4px 10px;
  border-radius: 999px;
}

.view { padding: 12px 14px 0; }
.section { margin-top: 16px; }
.section h2 { font-size: 16px; margin-bottom: 12px; }
.subhead { font-size: 14px; margin: 20px 0 10px; color: var(--muted); }

.points-card {
  background: linear-gradient(135deg, #07c160, #10ad6a);
  color: #fff;
  border-radius: 16px;
  padding: 20px 18px 16px;
  box-shadow: 0 6px 20px rgba(7, 193, 96, 0.28);
}
.points-label { font-size: 13px; opacity: 0.9; }
.points-value { font-size: 40px; font-weight: 700; letter-spacing: 1px; margin: 4px 0 14px; }
.points-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.points-card .btn.ghost { background: rgba(255,255,255,0.2); color: #fff; }
.checkin-msg { font-size: 12px; margin-top: 10px; min-height: 16px; }
.points-card .checkin-msg { color: rgba(255,255,255,0.95); }

.product-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.product-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px 12px 12px;
  border: 1px solid var(--line);
  cursor: pointer;
  transition: transform 0.1s;
}
.product-card:active { transform: scale(0.98); }
.p-emoji {
  height: 72px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 40px;
  background: #f7f8fa;
  border-radius: 10px;
  margin-bottom: 10px;
}
.p-name { font-size: 14px; font-weight: 600; margin-bottom: 4px; line-height: 1.3; }
.p-cost { font-size: 13px; color: var(--green); font-weight: 700; }
.p-stock { font-size: 11px; color: var(--muted); margin-top: 2px; }

.cash-form {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  border: 1px solid var(--line);
}
.cash-form label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.cash-estimate { margin: 0 0 14px; font-size: 14px; }
.cash-estimate strong { color: var(--green); font-size: 18px; }

.list { list-style: none; }
.list li {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 14px;
  margin-bottom: 8px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
}
.list .title { font-size: 14px; font-weight: 600; }
.list .meta { font-size: 12px; color: var(--muted); margin-top: 4px; }
.list .right { text-align: right; font-size: 13px; white-space: nowrap; }
.badge {
  display: inline-block;
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 4px;
  background: #fff7e6;
  color: #d48806;
  margin-top: 4px;
}
.badge.ok { background: #e8f8ef; color: var(--green); }
.badge.fail { background: #fff1f0; color: var(--danger); }
.empty { text-align: center; color: var(--muted); font-size: 13px; padding: 24px 0; }

.me-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  gap: 12px;
  align-items: center;
  border: 1px solid var(--line);
}
.avatar {
  width: 52px; height: 52px;
  border-radius: 50%;
  background: #e8f8ef;
  display: flex; align-items: center; justify-content: center;
  font-size: 26px;
}
.me-name { font-size: 17px; font-weight: 700; }

/* Bottom sheet */
.sheet-mask {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 40;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.sheet {
  background: var(--card);
  width: 100%;
  max-width: 480px;
  border-radius: 16px 16px 0 0;
  padding: 20px 18px calc(20px + env(safe-area-inset-bottom, 0px));
  position: relative;
  animation: slideUp 0.22s ease;
}
@keyframes slideUp {
  from { transform: translateY(40px); opacity: 0.6; }
  to { transform: translateY(0); opacity: 1; }
}
.sheet-close {
  position: absolute;
  right: 12px; top: 10px;
  border: none; background: transparent;
  font-size: 28px; color: var(--muted); cursor: pointer; line-height: 1;
}
.detail-emoji {
  font-size: 56px;
  text-align: center;
  margin: 8px 0 12px;
  background: #f7f8fa;
  border-radius: 12px;
  padding: 16px;
}
.sheet h2 { font-size: 18px; margin-bottom: 8px; }
.detail-desc { font-size: 13px; color: var(--muted); line-height: 1.5; margin-bottom: 12px; }
.detail-cost { font-size: 20px; color: var(--green); font-weight: 700; margin-bottom: 16px; }

/* Tab bar */
.tabbar {
  position: fixed;
  bottom: 0; left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  height: calc(var(--tab-h) + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: var(--card);
  border-top: 1px solid var(--line);
  display: flex;
  z-index: 30;
}
.tab {
  flex: 1;
  border: none;
  background: transparent;
  font-size: 11px;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  cursor: pointer;
}
.tab span { font-size: 20px; line-height: 1; }
.tab.active { color: var(--green); font-weight: 600; }

.msg-ok { color: var(--green) !important; }
.msg-err { color: var(--danger) !important; }
