/* ============================================================
   数签签 H5 - 样式表
   设计：移动优先、扁平、橙色主色调、模拟原生APP体验
   ============================================================ */

:root {
  --primary: #FF6B35;
  --primary-dark: #E05520;
  --primary-light: #FFF0E8;
  --success: #1D9E75;
  --danger: #E24B4A;
  --warning: #BA7517;
  --white: #FFFFFF;
  --bg: #F5F5F5;
  --card: #FFFFFF;
  --text: #2C2C2A;
  --text-secondary: #888780;
  --text-muted: #B4B2A9;
  --border: #E8E8E8;
  --shadow: 0 2px 12px rgba(0,0,0,0.08);
  --radius: 12px;
  --radius-lg: 16px;
  --safe-bottom: env(safe-area-inset-bottom, 16px);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
  height: 100vh;
  height: 100dvh;
  /* 微信WebView兼容：禁用user-select会吞点击事件(X5浏览器) */
  -webkit-user-select: auto;
  user-select: auto;
  /* 消除300ms点击延迟 */
  touch-action: manipulation;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
  background: var(--bg);
  position: relative;
}

/* ========== 导航栏 ========== */
.navbar {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  padding-top: max(12px, env(safe-area-inset-top));
  background: var(--primary);
  color: var(--white);
  flex-shrink: 0;
  min-height: 56px;
}

.nav-back, .nav-action {
  background: none;
  border: none;
  color: var(--white);
  font-size: 18px;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border-radius: 50%;
}

.nav-title {
  flex: 1;
  font-size: 17px;
  font-weight: 600;
  text-align: center;
}

/* ========== 页面容器 ========== */
main {
  flex: 1;
  overflow-y: auto;
  position: relative;
  -webkit-overflow-scrolling: touch;
}

.page {
  display: none;
  min-height: 100%;
}

.page.active { display: block; }

/* ========== 相机页 ========== */
.camera-container {
  position: relative;
  width: 100%;
  aspect-ratio: 3/4;
  background: #000;
  overflow: hidden;
}

.camera-container video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.camera-overlay {
  position: absolute;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
}

.overlay-hint {
  background: rgba(0,0,0,0.6);
  color: #fff;
  padding: 8px 20px;
  border-radius: 20px;
  font-size: 14px;
  backdrop-filter: blur(10px);
}

.camera-controls {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 24px 0;
  gap: 12px;
}

.btn-capture {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  border: 4px solid var(--primary);
  background: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.15s;
}

.btn-capture:active { transform: scale(0.92); }
.btn-capture:disabled { opacity: 0.5; }

.capture-inner {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--primary);
}

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

/* ========== 结果页 ========== */
.result-content {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.photo-preview {
  background: #000;
  border-radius: var(--radius-lg);
  overflow: hidden;
  aspect-ratio: 4/3;
  display: flex;
  align-items: center;
  justify-content: center;
}

.result-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.count-card {
  background: var(--primary-light);
  padding: 20px;
  border-radius: var(--radius-lg);
  text-align: center;
}

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

.count-number {
  font-size: 48px;
  font-weight: 700;
  color: var(--primary);
  margin: 4px 0;
}

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

.price-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.type-label, .input-label {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

.type-chips {
  display: flex;
  gap: 8px;
}

.chip {
  flex: 1;
  padding: 10px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--white);
  font-size: 13px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

.chip.active {
  border-color: var(--primary);
  background: var(--primary-light);
  color: var(--primary);
}

.input-group {
  display: flex;
  align-items: center;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0 12px;
}

.input-prefix, .input-suffix {
  font-size: 16px;
  color: var(--text-secondary);
}

.input-price {
  flex: 1;
  border: none;
  padding: 12px 8px;
  font-size: 18px;
  text-align: center;
  outline: none;
  background: transparent;
}

.total-card {
  background: var(--primary);
  padding: 24px;
  border-radius: var(--radius-lg);
  text-align: center;
  color: var(--white);
}

.total-label { font-size: 14px; opacity: 0.85; }
.total-amount { font-size: 40px; font-weight: 700; margin: 4px 0; }
.total-detail { font-size: 13px; opacity: 0.8; }

.result-actions {
  display: flex;
  gap: 12px;
  padding-bottom: var(--safe-bottom);
}

.result-actions button { flex: 1; }

/* ========== 按钮 ========== */
.btn-primary, .btn-outline, .btn-small, .btn-full,
.btn-capture, .btn-gallery-big, .nav-back, .nav-action, .chip {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.btn-primary {
  background: var(--primary);
  color: var(--white);
  border: none;
  padding: 14px 24px;
  border-radius: var(--radius);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

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

.btn-outline {
  background: var(--white);
  color: var(--primary);
  border: 1.5px solid var(--primary);
  padding: 14px 24px;
  border-radius: var(--radius);
  font-size: 16px;
  cursor: pointer;
}

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

.btn-small {
  background: var(--white);
  color: var(--primary);
  border: 1px solid var(--primary);
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
}

.btn-full {
  width: 100%;
  margin-top: 12px;
}

/* ========== 打印页 ========== */
.printer-content {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.bt-status {
  text-align: center;
  padding: 32px 16px;
  background: var(--white);
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.bt-icon { font-size: 48px; }
.bt-text { font-size: 16px; font-weight: 600; color: var(--text); }
.bt-hint { font-size: 13px; color: var(--text-secondary); }

.device-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* 小票预览 */
.receipt {
  background: #FFFEF9;
  padding: 16px;
  border-radius: var(--radius);
  border: 1px dashed var(--border);
  font-family: 'Courier New', monospace;
  font-size: 13px;
}

.receipt-title { text-align: center; font-weight: bold; font-size: 16px; }
.receipt-date { text-align: center; font-size: 12px; color: var(--text-secondary); margin: 4px 0; }
.receipt-divider { text-align: center; color: var(--text-muted); font-size: 11px; margin: 4px 0; }
.receipt-row { display: flex; justify-content: space-between; }
.receipt-header { font-weight: bold; }
.receipt-bold { font-weight: bold; font-size: 15px; }
.receipt-footer { text-align: center; font-size: 12px; color: var(--text-secondary); margin-top: 8px; }

/* 成功页面 */
#printDone {
  text-align: center;
  padding: 60px 20px;
}

.success-icon {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: var(--success);
  color: var(--white);
  font-size: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 16px;
}

#printDone h3 { font-size: 22px; margin-bottom: 8px; }
#printDone p { color: var(--text-secondary); margin-bottom: 24px; }

/* ========== 设置页 ========== */
.settings-content {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-bottom: var(--safe-bottom);
}

.settings-content h3 {
  font-size: 16px;
  color: var(--primary);
  margin-top: 8px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.form-group label {
  font-size: 13px;
  color: var(--text-secondary);
}

.form-input {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  font-size: 16px;
  background: var(--white);
  outline: none;
  transition: border-color 0.2s;
}

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

.help-list {
  padding-left: 20px;
  color: var(--text-secondary);
  font-size: 14px;
  line-height: 2;
}

.about-section {
  margin-top: 32px;
  padding: 16px;
  background: var(--white);
  border-radius: var(--radius);
  text-align: center;
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.8;
}

/* ========== Toast ========== */
.toast {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.8);
  background: rgba(0,0,0,0.85);
  color: #fff;
  padding: 12px 24px;
  border-radius: 24px;
  font-size: 14px;
  z-index: 9999;
  opacity: 0;
  pointer-events: none;
  transition: all 0.25s ease;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

/* ========== Loading ========== */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 9998;
  gap: 16px;
  color: #fff;
  font-size: 15px;
}

.loading-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ========== 相机错误提示 ========== */
.camera-error {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 85%;
  max-width: 320px;
  background: rgba(0,0,0,0.88);
  border-radius: var(--radius-lg);
  padding: 32px 20px;
  text-align: center;
  color: #fff;
  backdrop-filter: blur(10px);
}

.error-icon { font-size: 48px; margin-bottom: 12px; }
.error-title { font-size: 18px; font-weight: 700; margin-bottom: 8px; }
.error-msg { font-size: 13px; line-height: 1.6; color: rgba(255,255,255,0.85); margin-bottom: 12px; }
.error-hint { font-size: 12px; color: rgba(255,255,255,0.55); }

/* ========== 相机不可用横幅 ========== */
.camera-banner {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 16px;
  padding: 16px;
  background: #FFF3E0;
  border: 1px solid #FFB74D;
  border-radius: var(--radius);
}

.banner-icon { font-size: 32px; flex-shrink: 0; }
.banner-content { flex: 1; min-width: 0; }
.banner-title { font-size: 15px; font-weight: 700; color: #E65100; margin-bottom: 4px; }
.banner-msg { font-size: 13px; color: #BF360C; line-height: 1.5; }
.banner-action { font-size: 13px; color: var(--text-secondary); margin-top: 8px; line-height: 1.5; }

/* ========== 相册按钮（HTTP回退模式） ========== */
.btn-gallery {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  width: 80px;
  height: 80px;
  border-radius: var(--radius-lg);
  background: var(--primary);
  color: var(--white);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s, background 0.2s;
  box-shadow: 0 4px 16px rgba(255,107,53,0.35);
  border: none;
  -webkit-tap-highlight-color: transparent;
}

.btn-gallery:active { transform: scale(0.93); background: var(--primary-dark); }

/* 新版大号相册按钮 - HTTP 回退主操作入口 */
.btn-gallery-big {
  width: 140px;
  height: 140px;
  border-radius: 50%;
  background: linear-gradient(135deg, #FF6B35, #E05520);
  color: #fff;
  font-size: 18px;
  font-weight: 700;
  border: none;
  cursor: pointer;
  box-shadow: 0 6px 24px rgba(255,107,53,0.45);
  transition: transform 0.15s, box-shadow 0.2s;
  -webkit-tap-highlight-color: transparent;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  line-height: 1.3;
}

.btn-gallery-big:active { transform: scale(0.92); box-shadow: 0 3px 12px rgba(255,107,53,0.5); }
.btn-gallery-big:disabled { opacity: 0.5; }

.gallery-icon { font-size: 28px; line-height: 1; }

/* 微信原生相机按钮覆盖（绿色）—— JS 动态写入 */
.btn-gallery-big.wechat-capture {
  background: linear-gradient(135deg, #07C160, #06AD56) !important;
}
