:root {
  --bg: #f4f6fb;
  --bg-elevated: #ffffff;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-soft: rgba(79, 70, 229, 0.1);
  --accent: #0ea5e9;
  --text: #0f172a;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 4px 24px rgba(15, 23, 42, 0.06);
  --shadow-lg: 0 12px 40px rgba(15, 23, 42, 0.12);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --font: "Segoe UI", "PingFang SC", "Microsoft YaHei", -apple-system, BlinkMacSystemFont, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
}

.hidden { display: none !important; }

/* Layout */
.app {
  max-width: 520px;
  margin: 0 auto;
  min-height: 100vh;
  padding-bottom: calc(76px + var(--safe-bottom));
}

.page { display: none; padding: 0 16px 20px; animation: fadeIn 0.25s ease; }
.page.active { display: block; }
.page-title {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 0;
  color: var(--text);
}
.page-title { margin-bottom: 14px; }

/* 签到卡片 */
.checkin-card {
  background: linear-gradient(145deg, #4f46e5 0%, #6366f1 50%, #818cf8 100%);
  border-radius: var(--radius);
  padding: 20px 18px;
  margin-bottom: 18px;
  color: #fff;
  box-shadow: 0 8px 28px rgba(79, 70, 229, 0.35);
}
.checkin-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}
.checkin-card-title {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0.02em;
}
.checkin-card-desc {
  font-size: 13px;
  opacity: 0.9;
  margin-bottom: 16px;
  line-height: 1.5;
}
.btn-checkin-main {
  width: 100%;
  padding: 14px 20px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  background: #fff;
  color: var(--primary);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
  transition: transform 0.15s, opacity 0.2s;
}
.btn-checkin-main:active:not(:disabled) { transform: scale(0.98); }
.btn-checkin-main:disabled {
  cursor: not-allowed;
  opacity: 0.75;
}
.btn-checkin-main.done {
  background: rgba(255, 255, 255, 0.25);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.4);
  box-shadow: none;
}
.btn-checkin-main.off {
  background: rgba(255, 255, 255, 0.15);
  color: rgba(255, 255, 255, 0.7);
}

.product-loading {
  text-align: center;
  padding: 40px 16px;
  color: var(--text-muted);
  font-size: 14px;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Header */
.shop-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(244, 246, 251, 0.9);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  padding: 16px 16px 14px;
}
.shop-header-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}
.shop-header h1 {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.shop-header .subtitle {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 4px;
}
.balance-pill {
  flex-shrink: 0;
  background: linear-gradient(135deg, var(--primary), #7c3aed);
  color: #fff;
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  box-shadow: 0 4px 14px rgba(79, 70, 229, 0.35);
}
.balance-pill small {
  display: block;
  font-size: 10px;
  font-weight: 500;
  opacity: 0.85;
  margin-bottom: 2px;
}

/* Tab bar */
.tabbar {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 520px;
  background: var(--bg-elevated);
  border-top: 1px solid var(--border);
  display: flex;
  padding: 8px 12px calc(8px + var(--safe-bottom));
  z-index: 200;
  box-shadow: 0 -4px 20px rgba(15, 23, 42, 0.04);
}
.tabbar a {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  text-decoration: none;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 500;
  padding: 6px 0;
  border-radius: var(--radius-sm);
  transition: color 0.2s, background 0.2s;
}
.tabbar a.active {
  color: var(--primary);
  background: var(--primary-soft);
}
.tabbar a svg {
  width: 22px;
  height: 22px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Login */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 20px;
  background:
    radial-gradient(ellipse 80% 50% at 50% -10%, rgba(79, 70, 229, 0.12), transparent),
    var(--bg);
}
.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--bg-elevated);
  border-radius: 20px;
  padding: 32px 24px 28px;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
}
.login-brand {
  text-align: center;
  margin-bottom: 28px;
}
.login-logo {
  width: 52px;
  height: 52px;
  margin: 0 auto 14px;
  background: linear-gradient(135deg, var(--primary), #7c3aed);
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.login-logo svg { width: 28px; height: 28px; stroke: #fff; fill: none; stroke-width: 2; }
.login-brand h2 { font-size: 22px; font-weight: 700; }
.login-brand p { font-size: 13px; color: var(--text-muted); margin-top: 6px; }

.field { margin-bottom: 14px; }
.field label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.field-input {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 15px;
  background: #fafbfc;
  color: var(--text);
  transition: border-color 0.2s, box-shadow 0.2s;
}
.field-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
  background: #fff;
}
.field-select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%2364748b' d='M1 1l5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 36px;
}

.btn {
  display: block;
  width: 100%;
  padding: 14px 20px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s, opacity 0.15s;
}
.btn:active { transform: scale(0.98); }
.btn-primary {
  background: linear-gradient(135deg, var(--primary), #6366f1);
  color: #fff;
  box-shadow: 0 4px 14px rgba(79, 70, 229, 0.35);
  margin-top: 6px;
}
.btn-primary:hover { box-shadow: 0 6px 20px rgba(79, 70, 229, 0.4); }
.btn-secondary {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  margin-top: 10px;
}
.btn-danger {
  background: var(--danger);
  color: #fff;
  margin-top: 16px;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.login-hint {
  text-align: center;
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 16px;
  line-height: 1.6;
}

/* Categories */
.category-scroll {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
  margin-bottom: 16px;
  scrollbar-width: none;
}
.category-scroll::-webkit-scrollbar { display: none; }
.category-pill {
  flex-shrink: 0;
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg-elevated);
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.2s;
}
.category-pill.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  box-shadow: 0 4px 12px rgba(79, 70, 229, 0.3);
}

/* Product grid */
.product-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}
.product-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
}
.product-card:active { transform: scale(0.98); }
.product-card:hover { box-shadow: var(--shadow); }
.product-thumb {
  aspect-ratio: 1;
  background: linear-gradient(145deg, #f1f5f9, #e2e8f0);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.product-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.product-thumb-letter {
  font-size: 28px;
  font-weight: 700;
  color: var(--primary);
  opacity: 0.7;
}
.product-info { padding: 12px; }
.product-name {
  font-size: 14px;
  font-weight: 600;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.product-price {
  margin-top: 8px;
  font-size: 16px;
  font-weight: 700;
  color: var(--primary);
}
.product-price span {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  margin-left: 2px;
}

/* List cards (orders) */
.card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 12px;
  overflow: hidden;
}
.card-body { padding: 16px; }
.list-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}
.list-item:last-child { border-bottom: none; }
.list-item-body { flex: 1; min-width: 0; }
.list-item-title { font-size: 15px; font-weight: 600; }
.list-item-desc { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.list-item-meta { text-align: right; flex-shrink: 0; }
.list-item-price { font-size: 14px; font-weight: 600; color: var(--primary); }
.status-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 6px;
  margin-bottom: 4px;
}
.status-pending { background: #fef3c7; color: #b45309; }
.status-done { background: #d1fae5; color: #047857; }
.status-cancel { background: #f1f5f9; color: var(--text-muted); }

/* Profile */
.profile-hero {
  text-align: center;
  padding: 24px 16px;
}
.profile-avatar {
  width: 64px;
  height: 64px;
  margin: 0 auto 12px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary-soft), rgba(124, 58, 237, 0.15));
  border: 2px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  font-weight: 700;
  color: var(--primary);
}
.profile-name { font-size: 18px; font-weight: 700; }
.profile-meta { font-size: 13px; color: var(--text-muted); margin-top: 4px; }
.profile-balance {
  display: inline-block;
  margin-top: 14px;
  padding: 8px 18px;
  background: var(--primary-soft);
  color: var(--primary);
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
}
.section-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0 4px 10px;
}
.role-chip {
  display: inline-block;
  padding: 8px 14px;
  margin: 0 6px 8px 0;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s;
}
.role-chip.active {
  border-color: var(--primary);
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 600;
}

.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-muted);
}
.empty-state svg {
  width: 48px;
  height: 48px;
  stroke: #cbd5e1;
  margin-bottom: 12px;
}
.empty-state p { font-size: 14px; }

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  z-index: 500;
  display: none;
  align-items: flex-end;
  justify-content: center;
}
.modal-overlay.show { display: flex; }
.modal-sheet {
  width: 100%;
  max-width: 520px;
  max-height: 88vh;
  overflow-y: auto;
  background: var(--bg-elevated);
  border-radius: 20px 20px 0 0;
  padding: 24px 20px calc(24px + var(--safe-bottom));
  animation: slideUp 0.3s ease;
}
@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}
.modal-handle {
  width: 36px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: 0 auto 20px;
}
.modal-title { font-size: 18px; font-weight: 700; text-align: center; margin-bottom: 20px; }
.modal-thumb {
  width: 100%;
  max-height: 160px;
  aspect-ratio: 16/10;
  background: linear-gradient(145deg, #f1f5f9, #e2e8f0);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 16px;
  overflow: hidden;
}
.modal-thumb img { width: 100%; height: 100%; object-fit: cover; }
.modal-thumb-letter { font-size: 48px; font-weight: 700; color: var(--primary); opacity: 0.5; }
.modal-price {
  font-size: 28px;
  font-weight: 800;
  color: var(--primary);
  text-align: center;
  margin-bottom: 8px;
}
.modal-price unit { font-size: 14px; font-weight: 500; color: var(--text-muted); }
.modal-desc {
  font-size: 14px;
  color: var(--text-muted);
  line-height: 1.6;
  margin-bottom: 12px;
}
.modal-meta { font-size: 12px; color: #94a3b8; margin-bottom: 20px; }

/* Toast */
.toast {
  position: fixed;
  bottom: calc(90px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--text);
  color: #fff;
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  z-index: 9999;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
  max-width: calc(100% - 32px);
  text-align: center;
  box-shadow: var(--shadow-lg);
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.modal-price .unit { font-size: 14px; font-weight: 500; color: var(--text-muted); }

/* Admin */
.admin-wrap {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px 20px 40px;
}
.admin-login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
}
.admin-login-card {
  width: 100%;
  max-width: 400px;
  background: var(--bg-elevated);
  border-radius: var(--radius);
  padding: 32px 28px;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
}
.admin-login-card h2 {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 6px;
  text-align: center;
}
.admin-login-card .login-sub {
  font-size: 13px;
  color: var(--text-muted);
  text-align: center;
  margin-bottom: 24px;
}
.admin-login-logo {
  width: 52px;
  height: 52px;
  margin: 0 auto 16px;
  background: var(--primary-soft);
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.admin-login-logo svg { width: 28px; height: 28px; stroke: var(--primary); fill: none; stroke-width: 2; }
.admin-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 12px;
}
.admin-header h1 { font-size: 24px; font-weight: 700; }
.admin-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 24px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}
.admin-nav a {
  padding: 8px 16px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-muted);
  text-decoration: none;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  transition: all 0.2s;
}
.admin-nav a:hover { color: var(--primary); border-color: var(--primary); }
.admin-nav a.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}
.admin-stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 14px;
}
.admin-stat {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 16px;
  text-align: center;
  box-shadow: var(--shadow);
}
.admin-stat .num {
  font-size: 28px;
  font-weight: 800;
  color: var(--primary);
  line-height: 1.2;
}
.admin-stat .label { font-size: 13px; color: var(--text-muted); margin-top: 6px; }
.admin-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-bottom: 16px;
}
.admin-table-wrap {
  overflow-x: auto;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.admin-table th,
.admin-table td {
  padding: 12px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
.admin-table th {
  background: var(--bg);
  font-weight: 600;
  color: var(--text-muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.admin-table tr:last-child td { border-bottom: none; }
.admin-table tr:hover td { background: rgba(79, 70, 229, 0.03); }
.admin-actions { white-space: nowrap; }
.admin-actions button {
  padding: 5px 10px;
  margin-right: 4px;
  font-size: 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-elevated);
  cursor: pointer;
  color: var(--primary);
  font-weight: 500;
}
.admin-actions button:hover { background: var(--primary-soft); }
.admin-form-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 20px;
  box-shadow: var(--shadow);
}
.admin-form-card h3 {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 16px;
}
.admin-form-row {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
  margin-bottom: 12px;
}
.admin-modal h3 {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 20px;
}
.admin-modal .field { margin-bottom: 12px; }
.admin-modal .btn-row {
  display: flex;
  gap: 10px;
  margin-top: 20px;
}
.admin-modal .btn-row .btn { flex: 1; }
.admin-toast {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(-12px);
  background: var(--text);
  color: #fff;
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  z-index: 9999;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
  box-shadow: var(--shadow-lg);
}
.admin-toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.item-picker-field { position: relative; }
.item-picker-selected {
  font-size: 13px;
  color: var(--primary);
  background: var(--primary-soft);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  margin-bottom: 8px;
  word-break: break-all;
}
.item-picker-selected.empty {
  color: var(--text-muted);
  background: var(--bg);
  border: 1px dashed var(--border);
}
.item-picker-results {
  position: absolute;
  left: 0;
  right: 0;
  top: 100%;
  margin-top: 4px;
  max-height: 220px;
  overflow-y: auto;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  z-index: 600;
}
.item-picker-results .item-row {
  padding: 10px 12px;
  font-size: 13px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
}
.item-picker-results .item-row:last-child { border-bottom: none; }
.item-picker-results .item-row:hover { background: var(--primary-soft); }
.item-picker-results .item-row .item-id {
  color: var(--text-muted);
  font-size: 12px;
  margin-right: 8px;
  display: inline-block;
  min-width: 52px;
}
.item-picker-results .item-row .item-name {
  word-break: break-all;
}
.item-picker-results .item-empty {
  padding: 16px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
}
