/* ===== CSS Variables ===== */
:root {
  --primary: #dc2626;
  --primary-dark: #b91c1c;
  --primary-light: #fef2f2;
  --success: #16a34a;
  --success-light: #f0fdf4;
  --warning: #d97706;
  --warning-light: #fffbeb;
  --info: #2563eb;
  --info-light: #eff6ff;
  --danger: #dc2626;
  --bg: #f3f4f6;
  --card: #ffffff;
  --text: #1f2937;
  --text-secondary: #6b7280;
  --text-tertiary: #9ca3af;
  --border: #e5e7eb;
  --border-dark: #d1d5db;
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-lg: 0 10px 25px rgba(0,0,0,0.1), 0 4px 10px rgba(0,0,0,0.04);
  --radius: 14px;
  --radius-sm: 10px;
  --radius-lg: 20px;
  --nav-height: 68px;
  --header-height: 56px;
  --max-width: 520px;
}

/* ===== Reset ===== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.5;
  overflow: hidden;
  height: 100vh;
  height: 100dvh;
  -webkit-user-select: none;
  user-select: none;
  overscroll-behavior-y: none;
}

input, textarea, select {
  -webkit-user-select: text;
  user-select: text;
  font-family: inherit;
}

/* ===== App Layout ===== */
#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  max-width: var(--max-width);
  margin: 0 auto;
  background: var(--bg);
  position: relative;
}

#app-header {
  height: calc(var(--header-height) + env(safe-area-inset-top, 0px));
  padding-top: env(safe-area-inset-top, 0px);
  background: var(--primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-left: 20px;
  padding-right: 20px;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(220,38,38,0.2);
  z-index: 10;
}

#app-header h1 {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.5px;
}

.shop-name {
  font-size: 13px;
  font-weight: 500;
  color: rgba(255,255,255,0.85);
  padding: 3px 10px;
  background: rgba(255,255,255,0.15);
  border-radius: 12px;
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: none;
  padding-bottom: calc(var(--nav-height) + env(safe-area-inset-bottom, 0px));
}

/* ===== Bottom Navigation ===== */
#bottom-nav {
  display: flex;
  height: var(--nav-height);
  background: var(--card);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  padding-bottom: env(safe-area-inset-bottom, 0px);
  z-index: 100;
  box-shadow: 0 -2px 12px rgba(0,0,0,0.06);
}

.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  background: none;
  border: none;
  color: var(--text-tertiary);
  cursor: pointer;
  transition: color 0.2s;
  padding: 6px 0;
  -webkit-tap-highlight-color: transparent;
}

.nav-item.active {
  color: var(--primary);
}

.nav-icon {
  width: 24px;
  height: 24px;
  stroke-width: 2;
}

.nav-label {
  font-size: 11px;
  font-weight: 500;
}

/* ===== Common Components ===== */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 12px;
}

.card-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.section {
  padding: 16px;
}

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px 24px;
  border-radius: var(--radius-sm);
  border: none;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  min-height: 52px;
  -webkit-tap-highlight-color: transparent;
  font-family: inherit;
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: var(--primary);
  color: white;
}

.btn-primary:active {
  background: var(--primary-dark);
}

.btn-success {
  background: var(--success);
  color: white;
}

.btn-warning {
  background: var(--warning);
  color: white;
}

.btn-info {
  background: var(--info);
  color: white;
}

.btn-outline {
  background: var(--card);
  color: var(--text);
  border: 2px solid var(--border-dark);
}

.btn-outline:active {
  background: var(--bg);
}

.btn-danger {
  background: #fee2e2;
  color: var(--danger);
}

.btn-block {
  width: 100%;
}

.btn-lg {
  padding: 18px 32px;
  font-size: 18px;
  min-height: 60px;
}

.btn-sm {
  padding: 8px 16px;
  font-size: 14px;
  min-height: 38px;
}

.btn-icon {
  padding: 10px;
  min-height: 44px;
  min-width: 44px;
}

/* ===== Dashboard ===== */
.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  padding: 16px;
}

.stat-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 18px 16px;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
}

.stat-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 4px;
  height: 100%;
}

.stat-card.red::before { background: var(--primary); }
.stat-card.red[data-action]:active { transform: scale(0.97); opacity: 0.85; }
.stat-card.green::before { background: var(--success); }
.stat-card.blue::before { background: var(--info); }
.stat-card.amber::before { background: var(--warning); }

.stat-label {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 6px;
  font-weight: 500;
}

.stat-value {
  font-size: 28px;
  font-weight: 800;
  color: var(--text);
  line-height: 1.2;
}

.stat-unit {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-left: 4px;
}

.stat-sub {
  font-size: 12px;
  color: var(--text-tertiary);
  margin-top: 4px;
}

/* ===== Low Stock Alert ===== */
.alert-list {
  padding: 0 16px 16px;
}

.alert-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--warning-light);
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
  border-left: 4px solid var(--warning);
}

.alert-item-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}

.alert-item-info {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 2px;
}

.alert-item-stock {
  font-size: 20px;
  font-weight: 800;
  color: var(--warning);
}

/* v162: pick ticket stock-in list */
.pick-stockin-item:active {
  background: var(--bg);
}

/* ===== Empty State ===== */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 48px 24px;
  text-align: center;
}

.empty-state-icon {
  width: 64px;
  height: 64px;
  color: var(--text-tertiary);
  margin-bottom: 16px;
}

.empty-state-text {
  font-size: 15px;
  color: var(--text-secondary);
  margin-bottom: 20px;
}

/* ===== Scan Page ===== */
.scan-container {
  display: flex;
  flex-direction: column;
  height: 100%;
  padding: 16px;
  gap: 16px;
}

/* v160: Back button overlaid on the camera view — scan page had no way back */
.scan-back-btn {
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: rgba(0, 0, 0, 0.4);
  color: #fff;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.scan-back-btn:active {
  background: rgba(0, 0, 0, 0.6);
}

.scan-video-wrapper {
  position: relative;
  width: 100%;
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  aspect-ratio: 3 / 4;
}

#scan-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  background: #000;
}

.scan-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  display: flex;
  align-items: center;
  justify-content: center;
}

.scan-frame {
  width: 80%;
  height: 120px;
  border: 3px solid rgba(255,255,255,0.7);
  border-radius: 12px;
  position: relative;
  box-shadow: 0 0 0 9999px rgba(0,0,0,0.3);
}

.scan-frame::before,
.scan-frame::after {
  content: '';
  position: absolute;
  width: 24px;
  height: 24px;
  border: 4px solid var(--primary);
}

.scan-frame::before {
  top: -3px;
  left: -3px;
  border-right: none;
  border-bottom: none;
  border-radius: 12px 0 0 0;
}

.scan-frame::after {
  bottom: -3px;
  right: -3px;
  border-left: none;
  border-top: none;
  border-radius: 0 0 12px 0;
}

.scan-hint {
  position: absolute;
  bottom: 16px;
  left: 0;
  right: 0;
  text-align: center;
  color: white;
  font-size: 14px;
  font-weight: 500;
  text-shadow: 0 1px 4px rgba(0,0,0,0.5);
}

.scan-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: white;
  gap: 12px;
}

.scan-placeholder svg {
  width: 48px;
  height: 48px;
  opacity: 0.6;
}

.scan-placeholder-text {
  font-size: 14px;
  opacity: 0.7;
}

/* ===== Ticket Card ===== */
.ticket-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 10px;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform 0.1s;
  border-left: 4px solid transparent;
}

.ticket-card:active {
  transform: scale(0.98);
}

.ticket-card.denom-5 { border-left-color: #10b981; }
.ticket-card.denom-10 { border-left-color: #dc2626; }
.ticket-card.denom-20 { border-left-color: #f59e0b; }
.ticket-card.denom-30 { border-left-color: #8b5cf6; }
.ticket-card.denom-50 { border-left-color: #3b82f6; }
.ticket-card.denom-100 { border-left-color: #ec4899; }

.ticket-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 8px;
}

.ticket-name {
  font-size: 17px;
  font-weight: 700;
  color: var(--text);
}

.ticket-denom {
  font-size: 13px;
  color: var(--text-secondary);
  background: var(--bg);
  padding: 2px 10px;
  border-radius: 20px;
  font-weight: 600;
  white-space: nowrap;
}

.ticket-stock-row {
  display: flex;
  gap: 16px;
  font-size: 14px;
  color: var(--text-secondary);
}

.ticket-stock-item {
  display: flex;
  align-items: baseline;
  gap: 4px;
}

.ticket-stock-num {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
}

.ticket-stock-label {
  font-size: 12px;
  color: var(--text-tertiary);
}

.ticket-total {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px solid var(--border);
}

.ticket-total strong {
  color: var(--primary);
  font-size: 16px;
}

/* ===== Search & Filter ===== */
.search-bar {
  padding: 12px 16px;
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 5;
}

/* ===== Inventory Mode Tabs ===== */
.inv-mode-tabs {
  display: flex;
  gap: 8px;
  margin: 16px 16px 0;
  border-radius: var(--radius);
  padding: 6px;
}

.inv-mode-tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 16px 12px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--card-bg, var(--card));
  color: var(--text-tertiary);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  -webkit-tap-highlight-color: transparent;
  font-family: inherit;
}

.inv-mode-tab:active {
  transform: scale(0.96);
}

.inv-mode-tab.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  box-shadow: 0 4px 12px rgba(220, 38, 38, 0.35);
}

.inv-mode-tab.active .inv-mode-label {
  color: #fff;
  font-weight: 700;
}

.inv-mode-icon {
  font-size: 26px;
  line-height: 1;
}

.inv-mode-label {
  font-size: 15px;
}

/* Inventory secondary info text */
.inv-secondary-info {
  font-size: 12px;
  color: var(--text-tertiary);
}

/* Book mode highlight number */
.inv-book-num {
  color: var(--info) !important;
  font-size: 20px !important;
}

/* Loose mode highlight number */
.inv-loose-num {
  color: var(--warning) !important;
  font-size: 20px !important;
}

/* ===== Stat card category breakdown ===== */
.stat-sub-sports {
  display: inline-block;
  background: #e3f2fd;
  color: #1565c0;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
}

.stat-sub-welfare {
  display: inline-block;
  background: #ffebee;
  color: #c62828;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
  margin-left: 6px;
}

.stat-sub-count {
  color: var(--text-tertiary);
  font-size: 11px;
  margin-left: 6px;
}

/* ===== Category Sales Summary ===== */
.category-sales-summary {
  display: flex;
  gap: 10px;
  margin: 0 16px 12px;
}

.category-sales-item {
  flex: 1;
  background: var(--card);
  border-radius: var(--radius-sm);
  padding: 12px;
  text-align: center;
  box-shadow: var(--shadow);
}

.category-sales-item .css-label {
  display: block;
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.category-sales-item .css-value {
  display: block;
  font-size: 18px;
  font-weight: 800;
  color: var(--text);
}

.category-sales-item .css-count {
  display: block;
  font-size: 12px;
  color: var(--text-tertiary);
  margin-top: 2px;
}

.sports-sales .css-value { color: #e74c3c; }
.welfare-sales .css-value { color: #27ae60; }

/* ===== Action Button: Stock Out ===== */
.action-btn-purple {
  background: #8b5cf6;
  color: #fff;
}
.action-btn-purple:hover { background: #7c3aed; }
.action-btn-purple:active { background: #6d28d9; }

/* ===== Records Page ===== */
.records-type-tabs {
  display: flex;
  gap: 0;
  margin: 16px 16px 0;
  background: var(--bg);
  border-radius: var(--radius-sm);
  padding: 4px;
}

.records-type-tab {
  flex: 1;
  padding: 10px 8px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  -webkit-tap-highlight-color: transparent;
  font-family: inherit;
}

.records-type-tab.active {
  background: var(--card);
  color: var(--text);
  box-shadow: var(--shadow);
}

.records-type-tab:nth-child(1).active { color: var(--danger); }
.records-type-tab:nth-child(2).active { color: var(--success); }
.records-type-tab:nth-child(3).active { color: #8b5cf6; }

.records-date-tabs {
  display: flex;
  gap: 6px;
  margin: 10px 16px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.records-date-tabs::-webkit-scrollbar { display: none; }

.records-date-tab {
  flex-shrink: 0;
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--card);
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  -webkit-tap-highlight-color: transparent;
  font-family: inherit;
  white-space: nowrap;
}

.records-date-tab.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.records-summary {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 16px 8px;
  padding: 10px 14px;
  background: var(--card);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
}

.records-summary-label {
  font-size: 13px;
  color: var(--text-secondary);
  font-weight: 600;
}

.records-summary-value {
  font-size: 18px;
  font-weight: 800;
  color: var(--danger);
  flex: 1;
}

.records-summary-count {
  font-size: 12px;
  color: var(--text-tertiary);
}

/* ===== Records Page (records-list) ===== */
.records-list {
  margin: 0 16px;
}

.records-list .record-item {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  background: var(--card);
  margin-bottom: 6px;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  gap: 10px;
}

.records-list .record-info {
  flex: 1;
  min-width: 0;
  overflow: hidden;
}

.records-list .record-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.records-list .record-detail {
  font-size: 12px;
  color: var(--text-tertiary);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.records-list .record-amount {
  font-size: 15px;
  font-weight: 700;
  flex-shrink: 0;
  white-space: nowrap;
}

.records-list .record-amount.in { color: var(--success); }
.records-list .record-amount.out { color: var(--danger); }

/* Summary bar overflow fix */
.records-summary-value {
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.records-summary-count {
  flex-shrink: 0;
  white-space: nowrap;
}

/* ===== Records: Custom Date Picker ===== */
.records-custom-picker {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 16px 8px;
  padding: 10px 14px;
  background: var(--card);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
}

.records-custom-picker input[type="date"] {
  flex: 1;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  min-width: 0;
}

.records-custom-picker input[type="month"] {
  flex: 1;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  min-width: 0;
}

/* ===== Records: Date Group Headers ===== */
.date-group-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  background: var(--card);
  margin-bottom: 6px;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s;
}

.date-group-header:active {
  background: var(--bg);
}

.date-group-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

.date-group-arrow {
  color: var(--text-tertiary);
  flex-shrink: 0;
}

.date-group-date {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
}

.date-group-stats {
  display: flex;
  align-items: center;
  gap: 10px;
}

.date-group-amount {
  font-size: 16px;
  font-weight: 800;
  color: var(--danger);
}

.date-group-count {
  font-size: 12px;
  color: var(--text-tertiary);
  white-space: nowrap;
}

/* ===== Records: Date Group Detail (ticket merge rows) ===== */
.date-group-detail {
  margin-bottom: 6px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  box-shadow: var(--shadow);
}

.ticket-merge-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px 10px 38px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s;
}

.ticket-merge-row:last-child {
  border-bottom: none;
}

.ticket-merge-row:active {
  background: var(--bg);
}

.ticket-merge-info {
  flex: 1;
  min-width: 0;
}

.ticket-merge-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ticket-merge-qty {
  font-size: 12px;
  color: var(--text-tertiary);
  margin-top: 1px;
}

.ticket-merge-amount {
  font-size: 14px;
  font-weight: 700;
  color: var(--danger);
  flex-shrink: 0;
  margin-left: 10px;
}

.search-input {
  width: 100%;
  padding: 12px 16px 12px 44px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 16px;
  background: var(--card);
  outline: none;
  transition: border-color 0.2s;
}

.search-input:focus {
  border-color: var(--primary);
}

.search-input-wrapper {
  position: relative;
}

.search-input-wrapper svg {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  width: 20px;
  height: 20px;
  color: var(--text-tertiary);
}

.filter-tabs {
  display: flex;
  gap: 8px;
  padding: 0 16px 12px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.filter-tabs::-webkit-scrollbar {
  display: none;
}

.filter-tab {
  padding: 8px 18px;
  border-radius: 20px;
  border: 2px solid var(--border);
  background: var(--card);
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.filter-tab.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

/* ===== Modal ===== */
#modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.5);
  z-index: 1000;
  display: none;
  align-items: flex-end;
  justify-content: center;
  animation: fadeIn 0.2s ease;
  touch-action: none;
  overscroll-behavior: none;
}

#modal-overlay.show {
  display: flex;
}

.modal {
  background: var(--card);
  width: 100%;
  max-width: var(--max-width);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  /* Modal itself must scroll — content overflows 85vh and gets clipped
     otherwise. overflow:hidden + flex column + bare div children = no
     scroll area at all. */
  overflow-y: auto;
  overflow-x: hidden;
  touch-action: pan-y;
  overscroll-behavior: none;
  -webkit-overflow-scrolling: touch;
  animation: slideUp 0.25s ease;
  padding: 20px 20px calc(20px + env(safe-area-inset-bottom, 0px));
}

/* Prevent flex from squashing modal children — let content render at
   natural height so the modal itself can scroll when it overflows. */
.modal > * {
  flex-shrink: 0;
}

.modal-handle {
  width: 40px;
  height: 4px;
  background: var(--border-dark);
  border-radius: 2px;
  margin: 0 auto 16px;
}

.modal-title {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 16px;
  text-align: center;
}

.modal-section {
  margin-bottom: 16px;
}

.modal-section-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

/* ===== Form ===== */
.form-group {
  margin-bottom: 14px;
}

.form-label {
  display: block;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.form-input {
  width: 100%;
  padding: 14px 16px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 17px;
  background: var(--card);
  outline: none;
  transition: border-color 0.2s;
  font-family: inherit;
}

.form-input:focus {
  border-color: var(--primary);
}

.form-row {
  display: flex;
  gap: 12px;
}

.form-row .form-group {
  flex: 1;
}

.form-hint {
  font-size: 12px;
  color: var(--text-tertiary);
  margin-top: 4px;
}

/* ===== Quantity Selector ===== */
.qty-selector {
  display: flex;
  gap: 10px;
  margin: 16px 0;
}

.qty-btn {
  flex: 1;
  padding: 16px 8px;
  border-radius: var(--radius-sm);
  border: 2px solid var(--border);
  background: var(--card);
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  cursor: pointer;
  transition: all 0.15s;
  text-align: center;
  -webkit-tap-highlight-color: transparent;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.qty-btn:active {
  transform: scale(0.95);
}

.qty-btn.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

.qty-btn-icon {
  font-size: 24px;
}

.qty-btn-label {
  font-size: 14px;
}

.qty-btn-sub {
  font-size: 12px;
  opacity: 0.8;
}

.qty-btn-split {
  border-color: var(--primary);
  background: linear-gradient(135deg, rgba(220,38,38,0.06), rgba(220,38,38,0.02));
}
.qty-btn-split:active {
  background: linear-gradient(135deg, rgba(220,38,38,0.12), rgba(220,38,38,0.05));
}

.qty-input-wrapper {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 12px 0;
}

.qty-input-btn {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-sm);
  border: 2px solid var(--border);
  background: var(--card);
  font-size: 24px;
  font-weight: 700;
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
}

.qty-input-btn:active {
  background: var(--bg);
}

.qty-input {
  flex: 1;
  text-align: center;
  font-size: 24px;
  font-weight: 800;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  outline: none;
  font-family: inherit;
}

.qty-input:focus {
  border-color: var(--primary);
}

/* ===== Info Display ===== */
.info-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.info-row:last-child {
  border-bottom: none;
}

.info-label {
  font-size: 15px;
  color: var(--text-secondary);
}

.info-value {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
}

.info-value.highlight {
  color: var(--primary);
  font-size: 20px;
}

.info-value.success {
  color: var(--success);
}

/* ===== Sales Record List (record-list, used in stats page) ===== */
.record-list {
  padding: 0 16px;
}

.record-list .record-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
  gap: 10px;
}

.record-list .record-item:last-child {
  border-bottom: none;
}

.record-list .record-info {
  flex: 1;
  min-width: 0;
  overflow: hidden;
}

.record-list .record-name {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.record-list .record-meta {
  font-size: 13px;
  color: var(--text-tertiary);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.record-list .record-amount {
  text-align: right;
  flex-shrink: 0;
  white-space: nowrap;
}

.record-list .record-qty {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}

.record-list .record-price {
  font-size: 14px;
  color: var(--primary);
  font-weight: 700;
}

/* ===== Stats Page ===== */
.stats-tabs {
  display: flex;
  padding: 12px 16px;
  gap: 8px;
}

.stats-tab {
  flex: 1;
  padding: 10px;
  border-radius: var(--radius-sm);
  border: 2px solid var(--border);
  background: var(--card);
  font-size: 15px;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  text-align: center;
  -webkit-tap-highlight-color: transparent;
}

.stats-tab.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

.chart-container {
  padding: 16px;
}

.chart-wrapper {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  margin-bottom: 12px;
}

.chart-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 12px;
}

.chart-canvas-wrapper {
  position: relative;
  height: 220px;
}

/* ===== Ranking List ===== */
.ranking-list {
  padding: 0 16px 16px;
}

.ranking-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

.ranking-item:last-child {
  border-bottom: none;
}

.ranking-num {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 700;
  background: var(--bg);
  color: var(--text-secondary);
  flex-shrink: 0;
}

.ranking-item:nth-child(1) .ranking-num {
  background: #fef3c7;
  color: #d97706;
}

.ranking-item:nth-child(2) .ranking-num {
  background: #f3f4f6;
  color: #6b7280;
}

.ranking-item:nth-child(3) .ranking-num {
  background: #fed7aa;
  color: #c2410c;
}

.ranking-info {
  flex: 1;
}

.ranking-name {
  font-size: 15px;
  font-weight: 600;
}

.ranking-qty {
  font-size: 13px;
  color: var(--text-secondary);
}

.ranking-amount {
  font-size: 16px;
  font-weight: 700;
  color: var(--primary);
}

/* ===== Settings ===== */
.settings-group {
  padding: 0 16px;
  margin-bottom: 24px;
}

.settings-group-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 12px 0 8px;
}

.settings-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  background: var(--card);
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
  box-shadow: var(--shadow);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.settings-item:active {
  background: var(--bg);
}

.settings-item-active {
  background: rgba(220,38,38,0.06);
  border-left: 3px solid var(--primary);
}

.settings-item-label {
  font-size: 16px;
  font-weight: 500;
}

.settings-item-value {
  font-size: 14px;
  color: var(--text-tertiary);
}

.settings-item-arrow {
  color: var(--text-tertiary);
}

/* ===== Scan Hero Buttons ===== */
.scan-hero-btns {
  display: flex;
  gap: 10px;
  margin: 16px 0 10px;
}

.scan-hero-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 18px 12px;
  border-radius: var(--radius);
  border: none;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s;
  -webkit-tap-highlight-color: transparent;
  color: #fff;
  min-height: 56px;
}

.scan-hero-btn:active {
  transform: scale(0.96);
}

.scan-hero-btn svg {
  width: 24px;
  height: 24px;
  flex-shrink: 0;
}

.scan-hero-sell {
  background: linear-gradient(135deg, #dc2626, #b91c1c);
  box-shadow: 0 2px 8px rgba(220, 38, 38, 0.3);
}

.scan-hero-sell:active {
  background: linear-gradient(135deg, #b91c1c, #991b1b);
}

.scan-hero-stockin {
  background: linear-gradient(135deg, #16a34a, #15803d);
  box-shadow: 0 2px 8px rgba(22, 163, 74, 0.3);
}

.scan-hero-stockin:active {
  background: linear-gradient(135deg, #15803d, #166534);
}

/* ===== Action Grid ===== */
.action-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 16px 0;
}

.action-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 16px 8px;
  border-radius: var(--radius-sm);
  border: none;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  -webkit-tap-highlight-color: transparent;
  min-height: 80px;
}

.action-btn:active {
  transform: scale(0.95);
}

.action-btn svg {
  width: 28px;
  height: 28px;
}

.action-btn-green {
  background: var(--success-light);
  color: var(--success);
}

.action-btn-blue {
  background: var(--info-light);
  color: var(--info);
}

.action-btn-amber {
  background: var(--warning-light);
  color: var(--warning);
}

.action-btn-red {
  background: var(--primary-light);
  color: var(--primary);
}

/* ===== Sell Action Grid (Dashboard quick sell) ===== */
.sell-action-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.sell-action-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 16px 10px;
  border-radius: var(--radius);
  border: none;
  cursor: pointer;
  transition: all 0.15s;
  -webkit-tap-highlight-color: transparent;
  min-height: 80px;
  color: #fff;
}

.sell-action-btn:active {
  transform: scale(0.95);
}

.sell-action-icon {
  font-size: 26px;
  font-weight: 800;
  line-height: 1;
}

.sell-action-label {
  font-size: 15px;
  font-weight: 700;
}

.sell-action-desc {
  font-size: 11px;
  opacity: 0.75;
  font-weight: 400;
}

.sell-action-red {
  background: linear-gradient(135deg, #dc2626, #c0392b);
  box-shadow: 0 2px 8px rgba(220, 38, 38, 0.3);
}

.sell-action-orange {
  background: linear-gradient(135deg, #f59e0b, #d97706);
  box-shadow: 0 2px 8px rgba(245, 158, 11, 0.3);
}

.sell-action-blue {
  background: linear-gradient(135deg, #3b82f6, #2563eb);
  box-shadow: 0 2px 8px rgba(59, 130, 246, 0.3);
}

.sell-action-purple {
  background: linear-gradient(135deg, #8b5cf6, #6d28d9);
  box-shadow: 0 2px 8px rgba(139, 92, 246, 0.3);
}

/* v192: 扫码销售大按钮（占满整行，横排） */
.sell-action-wide {
  grid-column: 1 / -1;
  flex-direction: row;
  justify-content: center;
  gap: 10px;
  min-height: 62px;
  padding: 14px 16px;
}
.sell-action-wide .sell-action-icon {
  font-size: 26px;
}
.sell-action-wide .sell-action-label {
  font-size: 17px;
}
.sell-action-wide .sell-action-desc {
  font-size: 12px;
  margin-left: 4px;
}

.action-btn-teal {
  background: var(--success-light);
  color: var(--success);
}

/* 扫码入库醒目大按钮 */
.stock-in-hero {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  padding: 16px 20px;
  border: 2px dashed #15803d;
  border-radius: var(--radius);
  background: linear-gradient(135deg, rgba(22, 163, 74, 0.18), rgba(21, 128, 61, 0.08));
  color: #15803d;
  font-size: 17px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s;
  -webkit-tap-highlight-color: transparent;
}

/* v195: 库存/销售操作区按钮（统一结构：大按钮 icon圆+两行文字+箭头，小按钮上下居中） */
.hero-action {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 12px 14px;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  color: #fff;
  font-weight: 700;
  text-align: left;
  min-height: 62px;
}
.hero-action:active { transform: scale(0.98); opacity: 0.9; }
.hero-action .hero-icon {
  width: 44px; height: 44px;
  border-radius: 50%;
  background: rgba(255,255,255,0.22);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.hero-action .hero-icon svg { width: 24px; height: 24px; display: block; }
.hero-action .hero-text {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.hero-action .hero-label { font-size: 16px; font-weight: 700; line-height: 1.3; text-align: center; }
.hero-action .hero-desc { font-size: 12px; opacity: 0.85; margin-top: 2px; font-weight: 400; text-align: center; }
.hero-action .hero-arrow { font-size: 24px; opacity: 0.7; flex-shrink: 0; line-height: 1; }

.hero-action-green { background: linear-gradient(135deg, #22c55e, #15803d); box-shadow: 0 2px 8px rgba(22,163,74,0.3); }
.hero-action-red   { background: linear-gradient(135deg, #ef4444, #dc2626); box-shadow: 0 2px 8px rgba(220,38,38,0.3); }
.hero-action-orange { background: linear-gradient(135deg, #f59e0b, #d97706); box-shadow: 0 2px 8px rgba(245,158,11,0.3); }
.hero-action-teal  { background: linear-gradient(135deg, #14b8a6, #0d9488); box-shadow: 0 2px 8px rgba(20,184,166,0.3); }
.hero-action-blue  { background: linear-gradient(135deg, #3b82f6, #2563eb); box-shadow: 0 2px 8px rgba(59,130,246,0.3); }
.hero-action-purple { background: linear-gradient(135deg, #8b5cf6, #6d28d9); box-shadow: 0 2px 8px rgba(139,92,246,0.3); }

/* v193: 单行预警条 */
.compact-warning {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  background: rgba(245,158,11,0.08);
  border: 1px solid rgba(245,158,11,0.25);
  border-radius: var(--radius);
  color: #b45309;
  font-size: 14px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.compact-warning .warn-icon { font-size: 18px; }
.compact-warning .warn-text { flex: 1; }
.compact-warning .warn-arrow { opacity: 0.6; }

/* v193: 店铺名胶囊加箭头 */
.shop-name { display: inline-flex; align-items: center; gap: 4px; }
.shop-name::after { content: '›'; font-size: 16px; opacity: 0.85; }
.shop-name[data-action="switch-shop"] { cursor: pointer; }
.shop-name[data-action="switch-shop"]:active { opacity: 0.85; }

.stock-in-hero svg {
  width: 26px;
  height: 26px;
  flex-shrink: 0;
}

.stock-in-hero:active {
  transform: scale(0.97);
  background: #15803d;
  color: #fff;
}

/* ===== Toast ===== */
#toast-container {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  background: rgba(31,41,55,0.92);
  color: white;
  padding: 14px 24px;
  border-radius: var(--radius-sm);
  font-size: 16px;
  font-weight: 500;
  text-align: center;
  animation: toastIn 0.25s ease;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  max-width: 320px;
  pointer-events: auto;
}

.toast.success {
  background: rgba(22,163,74,0.92);
}

.toast.error {
  background: rgba(220,38,38,0.92);
}

.toast.warning {
  background: rgba(217,119,6,0.92);
}

/* Undo link inside toast */
.toast span {
  display: inline-block;
  padding: 2px 8px;
  background: rgba(255,255,255,0.25);
  border-radius: 4px;
  white-space: nowrap;
}

/* ===== Quick Stats Bar ===== */
.quick-stats {
  display: flex;
  padding: 16px;
  gap: 12px;
}

.quick-stat {
  flex: 1;
  text-align: center;
  background: var(--card);
  border-radius: var(--radius-sm);
  padding: 12px 8px;
  box-shadow: var(--shadow);
}

.quick-stat-value {
  font-size: 22px;
  font-weight: 800;
  color: var(--text);
}

.quick-stat-label {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 2px;
}

/* ===== History List ===== */
.history-list {
  max-height: 300px;
  overflow-y: auto;
}

.history-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}

.history-item:last-child {
  border-bottom: none;
}

.history-time {
  color: var(--text-tertiary);
  font-size: 13px;
}

.history-desc {
  color: var(--text);
  font-weight: 500;
}

.history-value {
  font-weight: 700;
}

.history-value.in {
  color: var(--success);
}

.history-value.out {
  color: var(--primary);
}

.history-item-undo {
  background: rgba(255, 152, 0, 0.06);
  border-radius: 6px;
  padding-left: 8px;
  padding-right: 4px;
}

.history-undo-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--primary);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  padding: 4px 10px;
  border-radius: 4px;
  background: rgba(221, 42, 42, 0.08);
  transition: background 0.2s;
  white-space: nowrap;
}

.history-undo-btn:active {
  background: rgba(221, 42, 42, 0.18);
}

/* ===== Today Sales List ===== */
.today-sales-list {
  background: var(--card);
  border-radius: 12px;
  padding: 0 14px;
  box-shadow: var(--shadow);
}

.today-sale-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

.today-sale-item:last-child {
  border-bottom: none;
}

.today-sale-info {
  flex: 1;
  min-width: 0;
}

.today-sale-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.today-sale-detail {
  font-size: 12px;
  color: var(--text-tertiary);
}

.today-sale-amount {
  font-size: 14px;
  font-weight: 700;
  color: var(--primary);
  white-space: nowrap;
}

.today-sale-undo {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 600;
  color: #fff;
  background: linear-gradient(135deg, #ff5252, #ff1744);
  border: none;
  border-radius: 6px;
  padding: 6px 14px;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
  box-shadow: 0 2px 6px rgba(255, 23, 68, 0.25);
}

.today-sale-undo:active {
  transform: scale(0.95);
  box-shadow: 0 1px 3px rgba(255, 23, 68, 0.3);
}

/* ===== Animations ===== */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

@keyframes toastIn {
  from { opacity: 0; transform: translateY(-10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ===== Misc ===== */
.text-center { text-align: center; }
.text-right { text-align: right; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mb-8 { margin-bottom: 8px; }
.mb-16 { margin-bottom: 16px; }
.hidden { display: none !important; }
.flex { display: flex; }
.flex-1 { flex: 1; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.w-full { width: 100%; }

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
}

.badge-success {
  background: var(--success-light);
  color: var(--success);
}

.badge-warning {
  background: var(--warning-light);
  color: var(--warning);
}

.badge-danger {
  background: var(--primary-light);
  color: var(--primary);
}

.divider {
  height: 1px;
  background: var(--border);
  margin: 12px 0;
}

/* ===== Category Badges ===== */
.cat-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 700;
  line-height: 1.4;
}

.cat-badge-sports {
  background: #fef2f2;
  color: #dc2626;
  border: 1px solid #fecaca;
}

.cat-badge-welfare {
  background: #f0fdf4;
  color: #16a34a;
  border: 1px solid #bbf7d0;
}

/* ===== Category Stats Cards (Dashboard) ===== */
.category-stats {
  display: flex;
  gap: 10px;
  padding: 0 16px 16px;
}

.category-stat-card {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 12px;
  background: var(--card);
  border-radius: var(--radius-sm);
  border: 2px solid var(--border);
  box-shadow: var(--shadow);
  cursor: pointer;
  border: none;
  text-align: left;
  font-family: inherit;
  -webkit-tap-highlight-color: transparent;
  transition: all 0.15s;
}

.category-stat-card:active {
  transform: scale(0.97);
}

.category-sports {
  background: linear-gradient(135deg, #fef2f2 0%, #ffffff 100%);
  border-left: 4px solid #dc2626;
}

.category-welfare {
  background: linear-gradient(135deg, #f0fdf4 0%, #ffffff 100%);
  border-left: 4px solid #16a34a;
}

.category-stat-icon {
  font-size: 22px;
  line-height: 1;
  flex-shrink: 0;
}

.category-stat-info {
  flex: 1;
  min-width: 0;
}

.category-stat-label {
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 600;
  margin-bottom: 2px;
}

.category-stat-value {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ===== Category Selector (Form) ===== */
.cat-selector {
  display: flex;
  gap: 10px;
}

.cat-select-btn {
  flex: 1;
  padding: 12px;
  border-radius: var(--radius-sm);
  border: 2px solid var(--border);
  background: var(--card);
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s;
  -webkit-tap-highlight-color: transparent;
  font-family: inherit;
}

.cat-select-btn:active {
  transform: scale(0.97);
}

.cat-select-btn.cat-sports.active {
  background: #fef2f2;
  border-color: #dc2626;
  color: #dc2626;
}

.cat-select-btn.cat-welfare.active {
  background: #f0fdf4;
  border-color: #16a34a;
  color: #16a34a;
}

/* ===== Category Filter Tabs ===== */
.cat-tab.cat-sports.active {
  background: #fef2f2;
  color: #dc2626;
  border-color: #dc2626;
}

.cat-tab.cat-welfare.active {
  background: #f0fdf4;
  color: #16a34a;
  border-color: #16a34a;
}

/* ===== Login Page ===== */
.login-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 20px;
  padding-top: calc(20px + env(safe-area-inset-top, 0px));
  padding-bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  background: linear-gradient(180deg, #fef2f2 0%, var(--bg) 40%);
  max-width: var(--max-width);
  margin: 0 auto;
  box-sizing: border-box;
}

.login-logo {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 48px;
}

.login-logo svg {
  margin-bottom: 16px;
  filter: drop-shadow(0 4px 12px rgba(220,38,38,0.25));
}

.login-title {
  font-size: 26px;
  font-weight: 800;
  color: var(--text);
  letter-spacing: 1px;
}

.login-subtitle {
  font-size: 14px;
  color: var(--text-tertiary);
  margin-top: 4px;
}

.login-form {
  width: 100%;
  max-width: 340px;
}

.login-field {
  margin-bottom: 14px;
}

.login-input {
  width: 100%;
  padding: 15px 18px;
  border: 2px solid var(--border);
  border-radius: 14px;
  font-size: 17px;
  background: var(--card);
  color: var(--text);
  box-sizing: border-box;
  transition: border-color 0.2s;
  -webkit-appearance: none;
  outline: none;
}

.login-input:focus {
  border-color: var(--primary);
}

.login-code-field {
  display: flex;
  gap: 10px;
}

.login-code-input {
  flex: 1;
}

.login-code-btn {
  flex-shrink: 0;
  padding: 0 20px;
  border: 2px solid var(--primary);
  border-radius: 14px;
  background: var(--card);
  color: var(--primary);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

.login-code-btn:disabled {
  border-color: var(--text-tertiary);
  color: var(--text-tertiary);
  cursor: not-allowed;
}

.login-btn {
  width: 100%;
  padding: 16px;
  border: none;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: white;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 4px;
  cursor: pointer;
  margin-top: 8px;
  box-shadow: 0 4px 16px rgba(220,38,38,0.3);
  transition: transform 0.15s, opacity 0.2s;
}

.login-btn:active {
  transform: scale(0.98);
}

.login-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.login-buttons {
  display: flex;
  gap: 12px;
  margin-top: 8px;
}

.login-buttons .login-btn {
  flex: 1;
  margin-top: 0;
  letter-spacing: 2px;
}

.login-btn-register {
  background: var(--card) !important;
  color: var(--primary) !important;
  border: 2px solid var(--primary) !important;
  box-shadow: none !important;
}

.login-hint {
  text-align: center;
  font-size: 14px;
  min-height: 20px;
  margin-top: 12px;
  color: var(--text-tertiary);
}

.login-hint-error {
  color: var(--danger);
}

.login-hint-success {
  color: var(--success);
}

.login-footer {
  margin-top: 48px;
  font-size: 13px;
  color: var(--text-tertiary);
  text-align: center;
}

/* ===== Responsive: Tablet (>= 768px) ===== */
@media (min-width: 768px) {
  :root {
    --max-width: 100%;
  }

  #app {
    max-width: 100%;
  }

  /* Dashboard: 2-column layout for sell actions */
  .sell-action-grid {
    max-width: 600px;
    margin: 0 auto;
  }

  /* Inventory cards: wider */
  .quick-stats {
    max-width: 600px;
    margin: 0 auto;
  }

  /* Settings: centered with max-width */
  #content > div {
    max-width: 640px;
    margin: 0 auto;
  }
}

/* ===== Responsive: Large tablet / desktop (>= 1024px) ===== */
@media (min-width: 1024px) {
  :root {
    --max-width: 800px;
  }

  #app {
    max-width: 800px;
    margin: 0 auto;
    box-shadow: 0 0 40px rgba(0,0,0,0.08);
  }
}

/* ===== Responsive: Small phones (<= 360px) ===== */
@media (max-width: 360px) {
  :root {
    --header-height: 50px;
    --nav-height: 60px;
  }

  #app-header h1 {
    font-size: 18px;
  }

  .nav-label {
    font-size: 11px;
  }

  .sell-action-btn {
    padding: 14px 8px;
    font-size: 14px;
  }

  .login-title {
    font-size: 22px;
  }

  .login-input {
    font-size: 16px;
    padding: 13px 14px;
  }
}

/* ===== Responsive: Landscape (short height) ===== */
@media (orientation: landscape) and (max-height: 500px) {
  .login-logo {
    margin-bottom: 20px;
  }

  .login-logo svg {
    width: 40px;
    height: 40px;
    margin-bottom: 8px;
  }

  .login-title {
    font-size: 20px;
  }

  .login-subtitle {
    display: none;
  }

  .login-footer {
    margin-top: 20px;
  }
}

/* ===== v231: 中奖登记 ===== */
.prize-tabs { display: flex; gap: 8px; margin-bottom: 12px; }
.prize-tab {
  flex: 1; padding: 9px 0; border: none; background: var(--card);
  border-radius: 10px; font-size: 14px; font-weight: 600;
  color: var(--text-secondary); box-shadow: var(--shadow); cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.prize-tab.active { background: var(--primary); color: #fff; }

.prize-form-row { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--border); }
.prize-form-row:last-of-type { border-bottom: none; }
.prize-form-label { flex: none; width: 88px; font-size: 14px; color: var(--text); }
.prize-select, .prize-input {
  flex: 1; min-width: 0; width: 100%; box-sizing: border-box;
  border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px;
  font-size: 15px; background: #fff; color: var(--text);
}
.prize-select { -webkit-appearance: none; appearance: none; }

.prize-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.prize-cell {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 4px; padding: 8px 2px; min-height: 64px; box-sizing: border-box;
  border: 1.5px solid var(--border); border-radius: 10px; background: var(--card);
  cursor: pointer; -webkit-tap-highlight-color: transparent;
}
.prize-cell.won { background: #fff1f0; border-color: #ff7875; }
.prize-cell-no { font-size: 13px; font-weight: 700; color: var(--text-secondary); }
.prize-cell.won .prize-cell-no { color: #cf1322; }
.prize-cell-amt { font-size: 12px; font-weight: 700; color: var(--primary); min-height: 16px; line-height: 16px; }

.prize-sumbar {
  display: flex; align-items: center; justify-content: center;
  flex-wrap: wrap; gap: 8px 16px;
  margin: 12px 0; padding: 13px;
  background: linear-gradient(135deg, #fff1f0, #ffe7e5);
  border: 1px solid #ffa39e; border-radius: 12px;
}
.prize-sumbar-item { display: flex; align-items: baseline; gap: 4px; }
.prize-sumbar-num { font-size: 22px; font-weight: 800; color: var(--primary); }
.prize-sumbar-unit { font-size: 13px; color: var(--primary); }
.prize-sumbar-label { font-size: 12px; color: var(--text-secondary); }
.prize-sumbar-item.muted .prize-sumbar-num,
.prize-sumbar-item.muted .prize-sumbar-unit { color: #8c8c8c; }
.prize-sumbar-sep { width: 1px; height: 26px; background: #ffa39e; }

.prize-history-item { margin-bottom: 10px; padding: 12px 14px; cursor: pointer; }

.prize-amt-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.prize-amt-btn {
  padding: 10px 0; border: 1.5px solid var(--border); border-radius: 8px;
  background: var(--card); font-size: 14px; font-weight: 600; color: var(--text);
  cursor: pointer; -webkit-tap-highlight-color: transparent;
}
.prize-amt-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ===== v232: 票种可搜索选择器 ===== */
.prize-pick-btn {
  flex: 1; min-width: 0; display: flex; align-items: center; justify-content: space-between;
  gap: 8px; box-sizing: border-box;
  border: 1px solid var(--border); border-radius: 8px; padding: 9px 10px;
  background: #fff; color: var(--text); font-size: 15px; text-align: left;
  cursor: pointer; -webkit-tap-highlight-color: transparent;
}
.prize-pick-txt { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.prize-pick-txt b { color: var(--primary); }
.prize-pick-caret { flex: none; font-size: 11px; color: var(--text-tertiary); }

.prize-picker { margin: 8px 0 4px; }
.prize-picker .prize-input { width: 100%; box-sizing: border-box; }
.prize-picker-list {
  margin-top: 8px; max-height: 280px; overflow-y: auto; -webkit-overflow-scrolling: touch;
  border: 1px solid var(--border); border-radius: 8px; background: var(--card);
}
.prize-pick-item {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  width: 100%; box-sizing: border-box; padding: 11px 12px;
  border: none; border-bottom: 1px solid var(--border);
  background: transparent; font-size: 14px; color: var(--text); text-align: left;
  cursor: pointer; -webkit-tap-highlight-color: transparent;
}
.prize-pick-item:last-child { border-bottom: none; }
.prize-pick-item.active { background: #fff1f0; }
.prize-pick-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.prize-pick-deno { flex: none; font-size: 12px; color: var(--text-secondary); }
.prize-pick-item.active .prize-pick-deno { color: var(--primary); font-weight: 700; }
.prize-picker-empty { padding: 22px 12px; text-align: center; font-size: 13px; color: var(--text-tertiary); }

/* ===== v237: 标记无奖 ===== */
.prize-cell.none { background: #f2f3f5; border-color: #dfe2e6; }
.prize-cell.none .prize-cell-no { color: #a8adb3; }
.prize-cell.none .prize-cell-amt { color: #b0b5ba; font-weight: 600; }

.prize-amt-none {
  display: block; width: 100%; box-sizing: border-box; margin-top: 10px;
  padding: 11px 0; border: 1.5px solid var(--border); border-radius: 8px;
  background: #f7f8fa; font-size: 14px; font-weight: 600; color: var(--text-secondary);
  cursor: pointer; -webkit-tap-highlight-color: transparent;
}
.prize-amt-none.active { background: #e8eaed; border-color: #b6bcc4; color: #5a5f66; }
