/* style.css — R103 电子报价单生成器 */
:root {
  --primary: #2563EB;
  --success: #10B981;
  --warning: #F59E0B;
  --bg: #F8FAFC;
  --text: #1E293B;
  --text-muted: #64748B;
  --paper: #FFFFFF;
  --border: #E2E8F0;
  --transition-speed: 0.3s;
  --contact-footer-h: 96px;
  --touch-min: 44px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-tap-highlight-color: transparent; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'PingFang SC', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  padding-bottom: calc(var(--contact-footer-h) + env(safe-area-inset-bottom));
}
body.has-contact-footer #app { max-width: 1200px; margin: 0 auto; min-height: calc(100dvh - var(--contact-footer-h)); }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: var(--touch-min); padding: 0 20px; border-radius: 8px;
  font-size: 16px; font-weight: 600; border: none; cursor: pointer;
  transition: all var(--transition-speed);
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-outline { background: transparent; color: var(--primary); border: 1px solid var(--primary); }
.btn-lg { padding: 0 28px; min-height: 52px; font-size: 18px; }
.btn-sm { min-height: 36px; padding: 0 12px; font-size: 13px; }
.btn-icon { width: 44px; height: 44px; border: none; background: var(--paper); border-radius: 8px; font-size: 20px; cursor: pointer; }
.btn-back { border: none; background: none; color: var(--primary); font-size: 15px; cursor: pointer; padding: 8px; }

/* Hero */
.hero { padding: 40px 20px 60px; text-align: center; }
.hero h1 { font-size: clamp(24px, 5vw, 36px); margin-bottom: 12px; }
.hero__sub { color: var(--text-muted); font-size: 16px; margin-bottom: 24px; }
.hero__cards { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin-bottom: 28px; }
.hero-card {
  padding: 10px 16px; background: var(--paper); border-radius: 20px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06); font-size: 14px;
}
.hero .btn { margin: 6px; }
.hero__hint { font-size: 13px; color: var(--text-muted); margin-top: 12px; }

/* Status timeline */
.status-panel { margin: 16px 0; padding: 12px; background: var(--paper); border-radius: 8px; border: 1px solid var(--border); }
.status-panel--compact { margin: 0 0 16px; }
.status-panel h4 { font-size: 13px; color: var(--text-muted); margin-bottom: 10px; }
.status-timeline { list-style: none; padding: 0; }
.status-timeline__item { display: flex; gap: 10px; align-items: flex-start; padding: 6px 0; font-size: 13px; }
.status-timeline__dot { width: 10px; height: 10px; border-radius: 50%; margin-top: 5px; flex-shrink: 0; background: var(--border); }
.status-timeline__item--pending .status-timeline__dot { background: #3B82F6; }
.status-timeline__item--viewed .status-timeline__dot { background: #F59E0B; }
.status-timeline__item--accepted .status-timeline__dot { background: #10B981; }
.status-timeline__item--rejected .status-timeline__dot { background: #EF4444; }
.status-timeline__item div { display: flex; flex-direction: column; gap: 2px; }
.status-timeline__item span { font-size: 11px; color: var(--text-muted); }
.view-status-bar { margin-top: 8px; }
.view-status--expired { color: #6B7280; }

/* Dashboard */
.dashboard-view { padding-bottom: 24px; }
.dash-cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; padding: 0 16px 16px; }
.dash-card { background: var(--paper); border-radius: 12px; padding: 16px; text-align: center; border: 1px solid var(--border); }
.dash-card--success { border-color: #A7F3D0; }
.dash-card--gold { border-color: #FDE68A; }
.dash-card__label { display: block; font-size: 12px; color: var(--text-muted); margin-bottom: 6px; }
.dash-card__value { font-size: 22px; color: var(--primary); }
.dash-chart, .dash-recent { padding: 0 16px 20px; }
.dash-chart h3, .dash-recent h3 { font-size: 15px; margin-bottom: 12px; }
.dash-bars { display: flex; align-items: flex-end; gap: 8px; height: 120px; padding: 8px; background: var(--paper); border-radius: 8px; border: 1px solid var(--border); }
.dash-bar { flex: 1; display: flex; flex-direction: column; align-items: center; height: 100%; justify-content: flex-end; }
.dash-bar__fill { width: 100%; max-width: 36px; background: linear-gradient(180deg, var(--primary), #93C5FD); border-radius: 4px 4px 0 0; min-height: 8px; transition: height 0.4s ease; }
.dash-bar__label { font-size: 10px; color: var(--text-muted); margin-top: 4px; }
.dash-bar__count { font-size: 11px; font-weight: 600; }
.dash-recent__list { list-style: none; background: var(--paper); border-radius: 8px; border: 1px solid var(--border); overflow: hidden; }
.dash-recent__item { padding: 12px 16px; border-bottom: 1px solid var(--border); font-size: 14px; }
.dash-recent__item:last-child { border-bottom: none; }
.dash-recent__meta { display: flex; justify-content: space-between; align-items: center; margin-top: 6px; font-size: 13px; }
.empty-hint { padding: 16px; text-align: center; color: var(--text-muted); }

/* WeChat tip */
.wechat-tip {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  margin: 12px 16px 0; padding: 10px 14px; background: #ECFDF5; border: 1px solid #A7F3D0;
  border-radius: 8px; font-size: 13px; color: #047857;
}
.wechat-tip__close { border: none; background: none; font-size: 18px; cursor: pointer; color: #047857; padding: 4px 8px; }

/* P2 — Theme */
.theme-toggle { position: fixed; top: 12px; right: 12px; z-index: 500; }
[data-theme="dark"] {
  --bg: #0F172A;
  --text: #F1F5F9;
  --text-muted: #94A3B8;
  --paper: #1E293B;
  --border: #334155;
}
[data-theme="dark"] .contact-footer { background: #1E293B; border-top-color: #334155; }
[data-theme="dark"] .contact-footer__btn { background: #334155; color: #E2E8F0; }
[data-theme="dark"] .hero-card, [data-theme="dark"] .template-card,
[data-theme="dark"] .quote-list-card, [data-theme="dark"] .dash-card,
[data-theme="dark"] .collab-card, [data-theme="dark"] .status-panel { background: #1E293B; }
[data-theme="dark"] .sig-canvas { border-color: #475569; }
[data-theme="dark"] .wechat-tip { background: #064E3B; border-color: #047857; color: #A7F3D0; }

/* P2 — AI Pricing */
.ai-pricing-panel { margin-top: 20px; padding: 14px; background: var(--paper); border: 1px solid var(--border); border-radius: 10px; }
.ai-pricing-panel__head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.ai-score { font-size: 13px; font-weight: 700; color: var(--primary); }
.ai-sug { padding: 10px; margin-top: 8px; border-radius: 8px; font-size: 13px; }
.ai-sug--warn { background: #FEF3C7; }
.ai-sug--info { background: #DBEAFE; }
.ai-sug--ok { background: #D1FAE5; }
.ai-insight { display: flex; gap: 10px; padding: 8px 0; font-size: 13px; }

/* P2 — Collaboration */
.collab-view { padding-bottom: 24px; }
.collab-card { margin: 0 16px 16px; padding: 16px; background: var(--paper); border: 1px solid var(--border); border-radius: 10px; }
.collab-card h3 { font-size: 16px; margin-bottom: 8px; }
.collab-qr { display: flex; justify-content: center; margin: 12px 0; }
.collab-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.collab-meta { font-size: 12px; color: var(--text-muted); margin-top: 10px; }
.collab-members { list-style: none; margin-top: 8px; font-size: 14px; }
.collab-members li { padding: 4px 0; }
.collab-import-label { cursor: pointer; }
.collab-feed, .collab-notes { list-style: none; font-size: 13px; }
.collab-feed li, .collab-notes li { padding: 8px 0; border-bottom: 1px solid var(--border); }
.collab-feed span, .collab-notes span { font-size: 11px; color: var(--text-muted); }
.collab-note-form { margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--border); }

/* P2 — E-sign API */
.esign-panel { margin: 16px 0; padding: 14px; background: var(--paper); border: 1px solid var(--border); border-radius: 10px; }
.esign-tabs { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; }
.esign-tab { padding: 8px 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); cursor: pointer; font-size: 13px; }
.esign-tab.active { border-color: var(--primary); background: #EFF6FF; color: var(--primary); font-weight: 600; }
.esign-form { display: grid; gap: 10px; margin: 10px 0; }
.esign-form label { font-size: 13px; display: flex; flex-direction: column; gap: 4px; }
.esign-form input { padding: 8px; border: 1px solid var(--border); border-radius: 6px; }
.esign-status { margin-top: 10px; font-size: 14px; font-weight: 600; }
.esign-status--pending { color: var(--warning); }
.esign-status--ok { color: var(--success); }
.esign-view-banner { text-align: center; padding: 12px; margin-bottom: 12px; background: #EFF6FF; border-radius: 8px; }

/* P2 — Payment */
.payment-panel { margin: 16px 0; padding: 14px; background: var(--paper); border: 1px solid var(--border); border-radius: 10px; }
.payment-toggle { display: flex; align-items: center; gap: 8px; font-size: 14px; margin: 8px 0; }
.payment-providers { display: flex; gap: 16px; margin-top: 10px; }
.payment-providers--hidden { display: none; }
.payment-provider { font-size: 14px; display: flex; align-items: center; gap: 6px; }
.payment-view { margin: 16px; padding: 16px; background: var(--paper); border: 1px solid var(--border); border-radius: 10px; text-align: center; }
.payment-view--paid { background: #D1FAE5; border-color: #A7F3D0; }
.payment-btns { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; max-width: 280px; margin-left: auto; margin-right: auto; }

/* Templates */
.view-header { display: flex; align-items: center; gap: 12px; padding: 16px; }
.view-header h2 { flex: 1; font-size: 18px; }
.template-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 16px; padding: 16px;
}
.template-card {
  border: 2px solid var(--border); border-radius: 12px; padding: 20px 12px;
  background: var(--paper); text-align: center; cursor: pointer;
  transition: all var(--transition-speed);
}
.template-card:hover { transform: translateY(-4px); box-shadow: 0 8px 24px rgba(0,0,0,0.1); }
.template-card.selected, .template-card:active { border-color: var(--primary); transform: scale(1.03); }
.template-card__icon { font-size: 36px; display: block; margin-bottom: 8px; }
.template-card__name { font-size: 14px; font-weight: 600; }
.template-tabs { display: none; }

/* Editor */
.editor-header { display: flex; align-items: center; padding: 12px 16px; background: var(--paper); border-bottom: 1px solid var(--border); }
.editor-header__id { flex: 1; text-align: center; font-size: 13px; color: var(--text-muted); }
.step-indicator { display: flex; align-items: center; justify-content: center; padding: 16px; gap: 4px; }
.step-dot {
  width: 32px; height: 32px; border-radius: 50%; background: var(--border);
  display: flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 700;
}
.step-dot.active { background: var(--primary); color: #fff; }
.step-dot.done { background: var(--success); color: #fff; }
.step-line { width: 24px; height: 2px; background: var(--border); }
.step-line.done { background: var(--success); }

.app-layout {
  display: grid; grid-template-columns: 1fr 1fr; gap: 16px;
  padding: 16px; align-items: start;
}
.editor-panel { background: var(--paper); border-radius: 12px; padding: 16px; box-shadow: 0 2px 8px rgba(0,0,0,0.06); }
.preview-panel { position: sticky; top: 16px; }
.preview-panel__title { font-size: 14px; color: var(--text-muted); margin-bottom: 8px; text-align: center; }

.step-content h3 { margin-bottom: 12px; }
.step-hint { font-size: 13px; color: var(--text-muted); margin-bottom: 16px; }
.form-grid { display: grid; gap: 12px; }
.form-grid label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--text-muted); }
.form-grid input, .form-grid select, .form-grid textarea {
  min-height: 48px; padding: 10px 12px; border: 1px solid var(--border);
  border-radius: 8px; font-size: 16px; background: var(--bg);
}
.fold-panel { margin-bottom: 16px; }
.fold-panel summary { font-weight: 600; cursor: pointer; padding: 8px 0; }

.color-swatches { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 12px; }
.color-swatch { width: 40px; height: 40px; border-radius: 50%; border: 2px solid transparent; cursor: pointer; transition: transform var(--transition-speed); }
.color-swatch.selected { border-color: var(--text); transform: scale(1.1); }

.quote-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.quote-table th { background: var(--bg); padding: 10px 8px; text-align: left; font-weight: 600; }
.quote-table td { padding: 8px; border-bottom: 1px solid var(--border); }
.quote-table input { width: 100%; min-height: 36px; padding: 6px; border: 1px solid var(--border); border-radius: 4px; }
.quote-table .num { text-align: right; font-variant-numeric: tabular-nums; }

.quote-card-item {
  background: var(--bg); border-radius: 8px; padding: 14px; margin-bottom: 12px;
  display: flex; flex-direction: column; gap: 8px;
}
.quote-card-item input { min-height: 44px; padding: 8px; border: 1px solid var(--border); border-radius: 6px; width: 100%; }
.field-row { display: flex; justify-content: space-between; align-items: center; }
.qty-control { display: flex; align-items: center; gap: 8px; }
.qty-control button { width: 36px; height: 36px; border-radius: 6px; border: 1px solid var(--border); background: var(--paper); cursor: pointer; }
.btn-del-product { align-self: flex-end; color: #EF4444; border: none; background: none; cursor: pointer; font-size: 13px; }
.btn-add-product { width: 100%; margin-top: 12px; }

.total-summary { margin-top: 16px; padding-top: 12px; border-top: 2px solid var(--border); }
.total-summary div { display: flex; justify-content: space-between; padding: 6px 0; font-size: 14px; }
.total-summary__grand { font-size: 18px; font-weight: 700; color: var(--primary); margin-top: 8px; }

.editor-nav {
  display: flex; justify-content: space-between; padding: 16px;
  padding-bottom: calc(16px + env(safe-area-inset-bottom));
}
.export-actions { display: flex; flex-direction: column; gap: 10px; margin-bottom: 20px; }

/* Preview A4 */
.preview-a4 {
  width: 100%; max-width: 210mm; min-height: 280px;
  background: var(--paper); box-shadow: 0 4px 24px rgba(0,0,0,0.12);
  padding: 16px; margin: 0 auto; font-size: 13px;
  transition: box-shadow var(--transition-speed);
}
.preview-a4.pulse-highlight { animation: pulse-highlight 0.3s ease; }
.preview-inner { }
.preview-header { display: flex; justify-content: space-between; gap: 16px; margin-bottom: 16px; padding-bottom: 12px; border-bottom: 2px solid var(--primary); }
.preview-header__company { display: flex; gap: 12px; }
.preview-logo { width: 48px; height: 48px; object-fit: contain; }
.preview-header h2 { font-size: 16px; margin-bottom: 4px; }
.preview-header h1 { font-size: 22px; color: var(--primary); }
.preview-header p { font-size: 12px; color: var(--text-muted); }
.preview-customer { margin-bottom: 16px; font-size: 14px; }
.preview-table { margin-bottom: 16px; }
.preview-totals { margin-left: auto; max-width: 240px; }
.preview-totals__row { display: flex; justify-content: space-between; padding: 4px 0; font-size: 13px; }
.preview-totals__grand { font-size: 16px; font-weight: 700; color: var(--primary); border-top: 1px solid var(--border); padding-top: 8px; margin-top: 4px; }
.preview-terms pre { white-space: pre-wrap; font-size: 11px; color: var(--text-muted); margin-top: 8px; }
.preview-footer, .preview-valid { font-size: 11px; color: var(--text-muted); margin-top: 12px; }
.preview-signature img { max-height: 60px; margin-top: 12px; }
.preview-signature p { font-size: 11px; color: var(--text-muted); }
.status-badge { display: inline-block; padding: 4px 10px; border-radius: 12px; font-size: 11px; font-weight: 600; }
.status-badge--draft { background: #F1F5F9; color: #64748B; }
.status-badge--pending { background: #DBEAFE; color: #1D4ED8; }
.status-badge--viewed { background: #FEF3C7; color: #B45309; }
.status-badge--accepted { background: #D1FAE5; color: #047857; }
.status-badge--rejected { background: #FEE2E2; color: #B91C1C; }
.status-badge--expired { background: #F3F4F6; color: #6B7280; }

.preview-overlay {
  display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.85);
  z-index: 300; align-items: flex-start; justify-content: center; padding: 60px 16px 16px; overflow-y: auto;
}
.preview-overlay--open { display: flex; }
.preview-overlay .close-btn {
  position: fixed; top: 16px; right: 16px; width: 44px; height: 44px;
  border: none; border-radius: 50%; background: rgba(255,255,255,0.2); color: #fff; font-size: 28px; cursor: pointer;
}

.mobile-bottom-bar {
  display: none; position: fixed; bottom: var(--contact-footer-h); left: 0; right: 0;
  background: var(--paper); border-top: 1px solid var(--border);
  padding: 12px 16px; z-index: 100; max-width: 1200px; margin: 0 auto;
  justify-content: space-between; align-items: center;
}
.mobile-bottom-bar .total-amount { font-size: 20px; font-weight: 700; color: var(--primary); }
.mobile-actions { display: flex; gap: 8px; }

/* Signature */
.signature-section { margin-top: 16px; }
.sig-canvas {
  width: 100%; height: 120px; border: 2px dashed var(--border);
  border-radius: 8px; touch-action: none; background: #fff;
}
.sig-actions { display: flex; gap: 8px; margin-top: 8px; }
.sig-actions button { padding: 8px 16px; border: 1px solid var(--border); border-radius: 6px; background: var(--paper); cursor: pointer; }

/* QR Modal */
.qr-modal--open { position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 200; display: flex; align-items: center; justify-content: center; }
.qr-modal-content { background: var(--paper); padding: 24px; border-radius: 16px; text-align: center; }
.qr-url { font-size: 11px; color: var(--text-muted); word-break: break-all; margin: 12px 0; }

/* List */
.quote-list { padding: 16px; display: flex; flex-direction: column; gap: 12px; padding-bottom: 80px; }
.quote-list-card {
  background: var(--paper); border-radius: 12px; padding: 16px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06); cursor: pointer; position: relative;
}
.quote-list-card__head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.quote-list-card__date { font-size: 12px; color: var(--text-muted); }
.btn-delete { position: absolute; bottom: 12px; right: 12px; border: none; background: none; color: #EF4444; font-size: 12px; cursor: pointer; }
.fab-new { position: fixed; bottom: calc(var(--contact-footer-h) + 16px); right: 16px; border-radius: 28px; box-shadow: 0 4px 16px rgba(37,99,235,0.4); z-index: 50; }

.empty-state { text-align: center; padding: 60px 20px; }
.empty-state .icon { font-size: 64px; margin-bottom: 16px; }

/* View page */
.view-landing #view-app { max-width: 800px; margin: 0 auto; padding: 16px; padding-bottom: var(--contact-footer-h); }
.view-page { }
.view-header { text-align: center; padding: 20px 0; }
.view-header h1 { font-size: 22px; margin-bottom: 4px; }
.view-preview { margin-bottom: 20px; }
.view-actions { padding: 0 16px 24px; display: flex; flex-direction: column; gap: 12px; }
.view-status { text-align: center; padding: 16px; font-size: 18px; font-weight: 600; }
.view-status--ok { color: var(--success); }
.view-status--no { color: #EF4444; }
.view-cta { text-align: center; padding: 16px; }
.view-cta a { color: var(--primary); font-weight: 600; }

.share-empty { text-align: center; padding: 48px 24px; }
.share-empty__icon { font-size: 56px; margin-bottom: 16px; }
.share-btn-primary {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 48px; padding: 12px 24px; border-radius: 8px;
  background: var(--primary); color: #fff; font-weight: 600; text-decoration: none; margin-top: 20px;
}

/* Toast */
.toast {
  position: fixed; top: 60px; left: 50%; transform: translateX(-50%);
  z-index: 9999; padding: 10px 24px; border-radius: 20px; font-size: 14px; color: #fff;
}
.toast--success { background: var(--success); }
.toast--error { background: #EF4444; }
.toast--info { background: var(--primary); }

/* Contact footer */
.contact-footer {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 400;
  background: #fff; border-top: 1px solid rgba(0,0,0,0.08);
  padding: 10px 12px calc(8px + env(safe-area-inset-bottom));
}
.contact-footer__btns { display: flex; gap: 8px; max-width: 1200px; margin: 0 auto 6px; }
.contact-footer__cta, .contact-footer__btn {
  flex: 1; text-align: center; padding: 8px 6px; border-radius: 8px; font-size: 13px; text-decoration: none; border: none; cursor: pointer;
}
.contact-footer__cta { background: linear-gradient(135deg, #e63946, #c1121f); color: #fff; font-weight: 600; }
.contact-footer__btn { background: #f3f4f6; color: #374151; }
.contact-footer__brand { text-align: center; font-size: 10px; color: #9ca3af; max-width: 1200px; margin: 0 auto; }

/* Animations */
@keyframes fade-in-up { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }
@keyframes step-slide-in { from { transform: translateX(16px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
@keyframes pulse-highlight { 0%, 100% { box-shadow: 0 4px 24px rgba(0,0,0,0.12); } 50% { box-shadow: 0 4px 32px rgba(37,99,235,0.25); } }
@keyframes bounce-in { 0% { transform: scale(0.3); opacity: 0; } 50% { transform: scale(1.05); } 100% { transform: scale(1); opacity: 1; } }
@keyframes shake { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }
.fade-in-up { animation: fade-in-up 0.8s ease-out; }
.step-slide-in { animation: step-slide-in 0.3s ease-out; }
.bounce-in { animation: bounce-in 0.6s ease-out; }
.shake { animation: shake 0.4s ease; }

/* Responsive */
@media (max-width: 768px) {
  .app-layout { grid-template-columns: 1fr; }
  .desktop-only { display: none !important; }
  .mobile-bottom-bar { display: flex; }
  .editor-nav { padding-bottom: calc(70px + env(safe-area-inset-bottom)); }
  .preview-a4 { padding: 12px; font-size: 12px; }
  .dash-cards { grid-template-columns: 1fr; }
}
@media (min-width: 769px) {
  .mobile-only { display: none !important; }
}

@media print {
  body { background: white; padding: 0; }
  .contact-footer, .editor-header, .step-indicator, .editor-nav,
  .mobile-bottom-bar, .preview-panel, .editor-panel { display: none !important; }
  .preview-a4 { box-shadow: none; width: 210mm; padding: 15mm; }
}
