/* ===========================================
   弘轩达销售单生成器 - 样式
   =========================================== */

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

:root {
  --color-primary: #c00;
  --color-primary-dark: #900;
  --color-text: #222;
  --color-text-muted: #5f6670;
  --color-border: #e0e0e0;
  --color-bg: #f5f6f8;
  --color-card: #fff;
  --color-hover: #f0f2f5;
  --shadow-sm: 0 1px 3px rgba(0,0,0,.08);
  --shadow-md: 0 4px 12px rgba(0,0,0,.08);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "SimSun", sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  font-size: 14px;
  line-height: 1.5;
}

a { color: var(--color-primary-dark); }
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
summary:focus-visible {
  outline: 3px solid #1a73e8;
  outline-offset: 2px;
}

h1, h2, h3 { font-weight: 600; }
h2 {
  font-size: 16px;
  margin: 20px 0 10px;
  padding-bottom: 6px;
  border-bottom: 2px solid var(--color-primary);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* ===== 应用头部 ===== */
.app-header {
  background: linear-gradient(135deg, #c00 0%, #900 100%);
  color: #fff;
  box-shadow: var(--shadow-md);
  position: sticky;
  top: 0;
  z-index: 100;
}
.app-header-inner {
  padding: 14px 24px 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 0 auto;
}
.app-brand { color: #fff; font-size: 20px; font-weight: 700; letter-spacing: 1px; text-decoration: none; }
.app-brand:hover { color: #fff; text-decoration: none; }
.app-brand-tag { margin-left: 12px; color: #fff; font-size: 13px; }
.app-actions button {
  background: rgba(255,255,255,.18);
  color: #fff;
  border: 1px solid rgba(255,255,255,.3);
  padding: 6px 14px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
}
.app-actions button:hover { background: rgba(255,255,255,.28); }

.tabs {
  display: flex;
  padding: 0 16px 0 18px;
  margin: 0 auto;
  gap: 4px;
  background: linear-gradient(180deg, rgba(0,0,0,0.10) 0%, rgba(0,0,0,0) 100%);
}
.tab-btn {
  background: transparent;
  color: rgba(255,255,255,0.92);
  border: none;
  padding: 14px 22px 12px;
  cursor: pointer;
  font-size: 17px;
  font-weight: 500;
  border-radius: 10px 10px 0 0;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: background .18s, color .18s;
  border-bottom: 4px solid transparent;
  margin-bottom: -2px;
  margin-top: 6px;
}
.tab-btn:hover {
  color: #fff;
  background: rgba(255,255,255,0.08);
}
.tab-btn.active {
  background: #fff;
  color: #c00;
  font-weight: 700;
  border-bottom-color: #fff;
  box-shadow: 0 -3px 0 0 #ffd700 inset;
}
.tab-btn.active:hover { background: #fff; }

/* ===== 主区域 ===== */
.app-main {
  max-width: 1208px;
  margin: 0 auto;
  padding: 24px;
}
.tab-content { display: none; }
.tab-content.active { display: block; }

/* ===== 首页定位与可索引内容 ===== */
.tool-hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 310px;
  gap: 28px;
  align-items: center;
  max-width: 1160px;
  margin: 0 auto 24px;
  padding: clamp(28px, 5vw, 54px);
  border: 1px solid #f1d0d0;
  border-radius: 14px;
  background: linear-gradient(135deg, #fff 0%, #fff7f7 100%);
  box-shadow: var(--shadow-sm);
}
.tool-hero .eyebrow, .tool-heading .eyebrow, .seo-section .eyebrow { margin-bottom: 8px; }
.tool-hero h1 { font-size: clamp(30px, 5vw, 46px); line-height: 1.18; letter-spacing: -.02em; }
.tool-hero-lead { max-width: 700px; margin-top: 16px; color: #4c5360; font-size: 17px; line-height: 1.8; }
.hero-actions { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 24px; }
.hero-primary, .hero-secondary { display: inline-flex; min-height: 44px; align-items: center; text-decoration: none; }
.hero-primary { padding: 11px 18px; font-weight: 600; }
.hero-secondary { padding: 11px 18px; }
.hero-points { display: grid; gap: 10px; padding: 22px; border: 1px solid #f1d0d0; border-radius: 10px; background: rgba(255,255,255,.82); list-style: none; }
.hero-points li { position: relative; padding-left: 24px; color: #454b54; line-height: 1.55; }
.hero-points li::before { position: absolute; left: 0; color: #b00000; content: "✓"; font-weight: 700; }
.tool-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  max-width: 1160px;
  margin: 38px auto 16px;
  scroll-margin-top: 128px;
}
.tool-heading h2 { display: block; margin: 0; padding: 0; border: 0; font-size: 25px; }
.tool-heading p { margin-top: 7px; color: var(--color-text-muted); }
.tool-heading-note { max-width: 310px; padding: 10px 12px; border-left: 3px solid #d88c00; background: #fff8e8; color: #604b18 !important; font-size: 13px; line-height: 1.55; }
/* 首屏介绍仅服务于“开单”；管理页面直接进入各自的操作区域。 */
body.page-products .tool-hero,
body.page-products .tool-heading,
body.page-settings .tool-hero,
body.page-settings .tool-heading { display: none; }
.seo-section { max-width: 1160px; margin: 48px auto 0; }
.seo-section > h2 { justify-content: flex-start; font-size: 23px; }
.seo-section > p { max-width: 900px; color: #4c5360; line-height: 1.85; }
.value-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.value-card { min-height: 150px; padding: 20px; border: 1px solid var(--color-border); border-radius: 10px; background: #fff; box-shadow: var(--shadow-sm); }
.value-card h3 { margin-bottom: 8px; font-size: 16px; }
.value-card p { color: #5b6470; line-height: 1.65; }
.workflow-list { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; padding: 0; list-style: none; counter-reset: workflow; }
.workflow-list li { position: relative; min-height: 145px; padding: 58px 18px 18px; border: 1px solid var(--color-border); border-radius: 10px; background: #fff; color: #535b66; line-height: 1.65; }
.workflow-list li::before { position: absolute; top: 17px; left: 18px; display: grid; width: 28px; height: 28px; place-items: center; border-radius: 50%; background: var(--color-primary); color: #fff; content: counter(workflow); counter-increment: workflow; font-weight: 700; }
.workflow-list strong { color: #252a31; }
.scene-list { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 16px; }
.scene-list span { padding: 8px 13px; border: 1px solid #ebc5c5; border-radius: 999px; background: #fff7f7; color: #8b0000; font-size: 14px; }
.about-tool { padding: clamp(24px, 4vw, 42px); border-radius: 12px; background: #fff; box-shadow: var(--shadow-sm); }
.faq-section { padding-bottom: 10px; }
.faq-section details { padding: 16px 0; border-bottom: 1px solid var(--color-border); }
.faq-section summary { cursor: pointer; color: #262b33; font-size: 16px; font-weight: 600; }
.faq-section details p { margin-top: 10px; color: #59616c; line-height: 1.75; }

/* ===== 站点页脚与说明页 ===== */
.site-footer {
  margin-top: 28px;
  background: #fff;
  border-top: 1px solid var(--color-border);
  color: var(--color-text-muted);
  font-size: 13px;
}
.site-footer-inner {
  min-height: 76px;
  margin: 0 auto;
  padding: 18px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.app-header-inner,
.tabs,
.site-footer-inner { max-width: 1208px; }
.site-footer nav, .site-nav { display: flex; align-items: center; gap: 16px; }
.site-footer a { color: #555; text-decoration: none; }
.site-footer a:hover, .site-footer a:focus-visible { color: var(--color-primary); text-decoration: underline; }

.site-header .app-header-inner { min-height: 64px; padding-top: 12px; padding-bottom: 12px; }
.site-brand { color: #fff; font-size: 19px; font-weight: 700; letter-spacing: .5px; text-decoration: none; }
.site-nav a { color: #fff; font-size: 14px; text-decoration: none; }
.site-nav a:hover, .site-nav a[aria-current="page"] { color: #fff; text-decoration: underline; }
.content-shell { max-width: 900px; margin: 0 auto; padding: 48px 24px; }
.guide-article, .legal-article {
  background: #fff;
  border: 1px solid var(--color-border);
  border-radius: 12px;
  box-shadow: var(--shadow-sm);
  padding: clamp(24px, 5vw, 52px);
}
.eyebrow { color: var(--color-primary); font-weight: 700; font-size: 13px; letter-spacing: .08em; }
.guide-article h1, .legal-article h1 { font-size: clamp(28px, 5vw, 40px); line-height: 1.25; margin: 10px 0 16px; }
.lead { color: #4c5360; font-size: 17px; line-height: 1.8; max-width: 720px; }
.guide-article h2, .legal-article h2 { margin-top: 32px; }
.guide-article h3 { font-size: 16px; margin-bottom: 8px; }
.guide-article p, .legal-article p { line-height: 1.8; }
.guide-callout { margin-top: 28px; padding: 24px; border: 1px solid #f0caca; border-radius: 10px; background: #fff8f8; }
.guide-callout h2 { margin-top: 0; }
.steps-list { padding-left: 24px; }
.steps-list li { margin: 12px 0; line-height: 1.75; }
.guide-section { margin-top: 30px; }
.guide-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.guide-card { padding: 18px; border: 1px solid var(--color-border); border-radius: 8px; background: #fafbfc; }
.guide-card p { color: #545b66; font-size: 14px; }
.guide-article details { padding: 15px 0; border-bottom: 1px solid var(--color-border); }
.guide-article summary { cursor: pointer; color: #252a31; font-weight: 600; }
.guide-article details p { margin-top: 10px; color: #545b66; }
.guide-cta { margin-top: 36px; padding: 28px; border-radius: 10px; background: #f7f8fa; text-align: center; }
.guide-cta h2 { display: block; border: 0; margin: 0 0 6px; padding: 0; }
.content-button { display: inline-flex; margin-top: 18px; color: #fff; text-decoration: none; }
.guide-hub-shell { max-width: 1208px; }
.guide-layout { display: grid; grid-template-columns: 230px minmax(0, 1fr); align-items: start; gap: 24px; }
.guide-menu { position: sticky; top: 96px; padding: 18px; border: 1px solid var(--color-border); border-radius: 10px; background: #fff; box-shadow: var(--shadow-sm); }
.guide-menu h2 { display: block; margin: 0 0 10px; padding: 0 0 8px; font-size: 16px; }
.guide-menu ul { display: grid; gap: 4px; padding: 0; list-style: none; }
.guide-menu a { display: block; padding: 8px 9px; border-radius: 6px; color: #3f4752; font-size: 13px; line-height: 1.45; text-decoration: none; }
.guide-menu a:hover, .guide-menu a:focus-visible, .guide-menu a[aria-current="page"] { background: #fff1f1; color: var(--color-primary-dark); text-decoration: none; }
.guide-index-intro { margin-top: 26px; color: #4c5360; line-height: 1.8; }
.guide-index-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; margin-top: 22px; }
.guide-index-card { display: block; min-height: 148px; padding: 18px; border: 1px solid var(--color-border); border-radius: 10px; background: #fafbfc; color: inherit; text-decoration: none; }
.guide-index-card:hover, .guide-index-card:focus-visible { border-color: #dc9898; box-shadow: var(--shadow-sm); text-decoration: none; }
.guide-index-card h2 { display: block; margin: 0 0 8px; padding: 0; border: 0; color: #252a31; font-size: 17px; }
.guide-index-card p { color: #545b66; font-size: 14px; line-height: 1.65; }
.legal-article section { margin-top: 28px; }
.legal-note { margin-top: 32px; padding: 14px 16px; border-left: 4px solid #f0a000; background: #fff8e8; color: #604b18; font-size: 13px; }
.ad-slot { display: none; min-height: 0; margin: 34px 0; }
.ad-slot.is-active { display: block; }
.ad-label { margin: 0 0 8px; color: var(--color-text-muted); font-size: 12px; text-align: center; }

/* ===== 网格布局 ===== */
.layout-grid {
  display: grid;
  grid-template-columns: minmax(360px, 400px) minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}
.layout-grid > * {
  /* 防止被超宽內容（如 794px 发票）撑开 */
  min-width: 0;
}

.control-panel, .preview-panel {
  background: var(--color-card);
  border-radius: 8px;
  padding: 18px 20px;
  box-shadow: var(--shadow-sm);
}
.preview-panel {
  display: flex;
  flex-direction: column;
  height: clamp(560px, calc(100vh - 220px), 760px);
  min-height: 560px;
}
.preview-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 10px;
  margin-bottom: 10px;
  border-bottom: 1px solid var(--color-border);
}
.preview-toolbar span:first-child { font-weight: 600; }
.preview-tip { color: var(--color-text-muted); font-size: 12px; }
.preview-scroll {
  flex: 1;
  overflow: auto;
  background: #e8eaed;
  padding: 20px;
  border-radius: 4px;
  display: flex;
  justify-content: center;
}

/* ===== 表单 ===== */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px 14px;
}
.form-grid label {
  display: flex;
  flex-direction: column;
  font-size: 12px;
}
.form-grid label.span2 { grid-column: 1 / -1; }
.form-grid label span {
  color: var(--color-text-muted);
  margin-bottom: 4px;
}

/* 带按钮的 input (如 单号 + 🔄) */
.input-with-action {
  display: flex;
  gap: 6px;
  align-items: stretch;
}
.input-with-action input { flex: 1; min-width: 0; }
.input-with-action button {
  flex-shrink: 0;
  width: 38px;
  border-radius: 6px;
  border: 1px solid var(--color-border);
  background: #f7f8fa;
  cursor: pointer;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .18s, transform .15s;
}
.input-with-action button:hover { background: #ffeaea; }
.input-with-action button:active { transform: scale(0.92); }
input[type="text"], input[type="number"], input[type="date"], select, textarea {
  font-family: inherit;
  font-size: 13px;
  padding: 7px 10px;
  border: 1px solid var(--color-border);
  border-radius: 4px;
  background: #fff;
  outline: none;
  width: 100%;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 2px rgba(192,0,0,.1);
}
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 3px solid #1a73e8;
  outline-offset: 2px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.add-item-row {
  display: grid;
  grid-template-columns: 1fr 100px auto;
  gap: 8px;
  align-items: center;
}
.add-item-row select {
  font-size: 13px;
}
.hint {
  font-size: 12px;
  color: #9a4f00;
  margin: 8px 0;
}

/* 手机端专用的提示卡 (长按提示) */
.hint-mobile-only {
  display: none;
  margin: 0 0 8px;
  padding: 12px 14px;
  background: #fff7e6;
  border: 1px solid #ffd591;
  border-radius: 8px;
  font-size: 13px;
  color: #5c3d00;
  line-height: 1.5;
}
.hint-mobile-only b { color: #c00; }

/* ===== 按钮 ===== */
.btn-primary, .btn-secondary, .btn-link {
  font-family: inherit;
  font-size: 13px;
  padding: 8px 14px;
  border-radius: 4px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all .15s;
}
.btn-primary {
  background: var(--color-primary);
  color: #fff;
}
.btn-primary:hover { background: var(--color-primary-dark); }
.btn-primary.big {
  padding: 12px 24px;
  font-size: 15px;
  font-weight: 500;
}
.btn-secondary {
  background: #fff;
  color: var(--color-text);
  border-color: var(--color-border);
}
.btn-secondary:hover { background: var(--color-hover); }
.btn-link {
  background: none;
  border: none;
  color: var(--color-text-muted);
  text-decoration: underline;
  padding: 4px 6px;
  font-size: 12px;
}
.btn-link:hover { color: var(--color-primary); }

/* ===== 明细表 ===== */
.items-table-wrap {
  max-height: 220px;
  overflow-y: auto;
  border: 1px solid var(--color-border);
  border-radius: 4px;
}
.items-table, .products-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  background: #fff;
}
.items-table th, .products-table th {
  background: #f7f8fa;
  color: var(--color-text-muted);
  font-weight: 500;
  text-align: left;
  padding: 8px;
  border-bottom: 1px solid var(--color-border);
  position: sticky;
  top: 0;
}
.items-table td, .products-table td {
  padding: 8px;
  border-bottom: 1px solid var(--color-border);
}
.items-table .num, .products-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.items-table .center, .products-table .center { text-align: center; }
.items-table tbody tr:hover, .products-table tbody tr:hover { background: var(--color-hover); }
.items-table .item-del {
  color: var(--color-primary);
  background: none;
  border: none;
  cursor: pointer;
  font-size: 12px;
}
.items-table .qty-input {
  width: 80px;
  padding: 3px 6px;
  font-size: 12px;
}

/* ===== 汇总 ===== */
.summary-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 10px;
}
.summary-card {
  background: #f7f8fa;
  padding: 10px 14px;
  border-radius: 6px;
  border-left: 3px solid #ccc;
}
.summary-card.highlight {
  background: #fff5f5;
  border-left-color: var(--color-primary);
}
.summary-card .lbl {
  font-size: 12px;
  color: var(--color-text-muted);
}
.summary-card .val {
  font-size: 18px;
  font-weight: 600;
  margin-top: 2px;
  font-variant-numeric: tabular-nums;
}
.summary-card.highlight .val { color: var(--color-primary); }

/* 主按钮全宽、次按钮 3 列一行 */
.export-actions {
  margin-top: 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.export-actions > #btn-save {
  min-height: 52px;
  font-size: 16px;
  padding: 12px 20px;
}
.export-row2 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
}
.export-row2 button {
  min-height: 42px;
  font-size: 13px;
  padding: 8px 6px;
  min-width: 0;
}

/* ===== 商品表单 ===== */
.product-form {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 20px;
  padding: 16px;
  background: #f7f8fa;
  border-radius: 6px;
}
.product-form label { display: flex; flex-direction: column; font-size: 12px; }
.product-form label span { color: var(--color-text-muted); margin-bottom: 4px; }
.product-form .product-form-actions {
  grid-column: 1 / -1;
  display: flex;
  gap: 10px;
}
.products-table-wrap {
  border: 1px solid var(--color-border);
  border-radius: 4px;
  max-height: 500px;
  overflow: auto;
}
.count-badge {
  background: var(--color-primary);
  color: #fff;
  padding: 1px 8px;
  border-radius: 10px;
  font-size: 12px;
  font-weight: 500;
}

/* ===== 设置 ===== */
.settings-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-width: 700px;
}
.settings-form label { display: flex; flex-direction: column; }
.settings-form label > span {
  color: var(--color-text-muted);
  font-size: 12px;
  margin-bottom: 4px;
}
.settings-fieldset {
  min-width: 0;
  padding: 0;
  border: 0;
}
.settings-fieldset legend {
  color: var(--color-text-muted);
  font-size: 12px;
  margin-bottom: 4px;
}
.phone-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

/* ===== Modal —— 只展示图片（兼容 Safari iOS） ===== */
.modal {
  position: fixed;
  inset: 0;
  /* 重要：明确告诉 Safari 高度。inset:0 并不能让所有浏览器都准确填满。 */
  width: 100vw;
  height: 100vh;
  /* Safari iOS: 克服 URL 栏高度跳动问题（旧→100vh 过短，新→100dvh 自动避开工具栏） */
  height: 100dvh;
  height: -webkit-fill-available;
  background: rgba(10, 10, 15, 0.96);
  /* 使用 flexbox 居中：Safari iOS 对 flex 居中支持靠谱，对 grid + place-items 有偶有问题 */
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  padding: 60px 16px 64px;
  /* iOS Safari 点击区下沉避免 safe-area */
  padding-top: max(60px, env(safe-area-inset-top, 60px));
  padding-bottom: max(64px, calc(56px + env(safe-area-inset-bottom, 0px)));
  animation: modalFadeIn .25s ease-out;
  z-index: 1000;
}
@keyframes modalFadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.modal-img-wrap {
  /* 作为 flex 子元素，多重 flex 容器 */
  display: flex;
  align-items: center;
  justify-content: center;
  max-width: 100%;
  max-height: 100%;
  /* 让图片在 wrap 内可以溢出为滚动的贴中模式 */
  min-width: 0;
  min-height: 0;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

.modal-img-wrap img,
.modal-img-wrap canvas {
  display: block;
  /* 关键：不要给固定 width。让浏览器自动按 max-width/max-height 缩放 + flex 自然居中 */
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: calc(100vh - 140px);
  max-height: calc(100dvh - 140px);
  margin: auto;
  flex-shrink: 0;
  background: #fff;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.6);
  border-radius: 4px;
  /* iOS Safari 长按 -> 保存/分享 */
  -webkit-touch-callout: default;
  -webkit-user-select: auto;
  user-select: auto;
  pointer-events: auto;
}

.modal-close-float {
  position: fixed;
  top: max(14px, env(safe-area-inset-top, 14px));
  right: max(14px, env(safe-area-inset-right, 14px));
  z-index: 1001;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.2);
  color: #fff;
  border: none;
  font-size: 20px;
  font-weight: 300;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  transition: background 0.18s;
}
.modal-close-float:hover { background: rgba(255,255,255,.32); }

.modal-hint {
  position: fixed;
  bottom: max(16px, env(safe-area-inset-bottom, 16px));
  left: 50%;
  transform: translateX(-50%);
  background: rgba(255, 255, 255, 0.95);
  color: #333;
  padding: 8px 18px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 500;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  max-width: calc(100vw - 32px);
  overflow: hidden;
  text-overflow: ellipsis;
  z-index: 1001;
}
.modal-hint strong {
  color: #c00;
}
@media (max-width: 480px) {
  .modal-hint { font-size: 12px; padding: 7px 14px; }
}

/* ===== Toast 浮动提示 ===== */
.toast {
  position: fixed;
  /* 位置：头部 约 95-110px。以 150px 为起点，给安全间隔，避免遮挡菜单和表单 */
  top: 150px;
  top: max(150px, calc(135px + env(safe-area-inset-top, 0px)));
  left: 50%;
  transform: translate(-50%, -120%);
  background: rgba(34, 34, 34, 0.95);
  color: #fff;
  padding: 12px 22px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 500;
  box-shadow: 0 8px 32px rgba(0,0,0,.25);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  opacity: 0;
  pointer-events: none;
  transition: transform .3s cubic-bezier(.34,1.56,.64,1), opacity .3s;
  z-index: 9999;
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 92vw;
  white-space: normal;        /* 长提示换行 */
  line-height: 1.4;
  overflow: visible;
}
.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}
.toast.success { background: rgba(46, 125, 50, 0.95); }
.toast.error   { background: rgba(198, 40, 40, 0.95); }
.toast.info    { background: rgba(33, 150, 243, 0.95); }
.toast .toast-icon { font-size: 16px; flex-shrink: 0; }

/* ===========================================
   销售单图片样式 (核心 —— 模仿原图)
   =========================================== */

#invoice-preview, #modal-invoice {
  --ipx: 1;  /* scale factor */
}
.invoice {
  width: 794px;        /* A4 width @ 96dpi — 自然原尺寸，屏幕下滚动可看 */
  background: #fff;
  padding: 30px 36px 24px;
  font-family: "PingFang SC", "Microsoft YaHei", "STHeiti", "SimSun", serif;
  font-size: 14px;
  color: #000;
  box-shadow: 0 4px 20px rgba(0,0,0,.15);
  position: relative;
  margin: 0 auto;
  box-sizing: border-box;
}

/* ===== 头部 ===== */
.invoice-head {
  text-align: center;
  border-bottom: 2px solid #000;
  padding-bottom: 10px;
  margin-bottom: 6px;
}
.invoice-company {
  font-size: 30px;
  font-weight: 700;
  color: #000;
  letter-spacing: 4px;
  line-height: 1.2;
}
.invoice-tagline {
  font-size: 12px;
  color: #555;
  margin-top: 2px;
}
.invoice-address {
  font-size: 12px;
  color: #444;
  margin-top: 4px;
  display: flex;
  justify-content: center;
  gap: 18px;
}

/* ===== 单据元信息 ===== */
.invoice-meta {
  display: grid;
  grid-template-columns: 2fr 1.5fr 1fr;
  gap: 0;
  border: 1.5px solid #000;
  border-bottom: none;
  font-size: 13px;
}
.invoice-meta > div {
  padding: 6px 10px;
  border-right: 1.5px solid #000;
}
.invoice-meta > div:last-child { border-right: none; }
.invoice-meta b {
  margin-right: 4px;
}

/* ===== 明细表 ===== */
.invoice-table {
  width: 100%;
  border-collapse: collapse;
  border: 1.5px solid #000;
  font-size: 13px;
}
.invoice-table th {
  background: #f0f0f0;
  font-weight: 600;
  padding: 8px 4px;
  border: 1px solid #000;
  text-align: center;
}
.invoice-table td {
  padding: 7px 4px;
  border: 1px solid #000;
  text-align: center;
  height: 30px;
}
.invoice-table td.t-name { text-align: left; padding-left: 8px; }
.invoice-table td.t-num { text-align: right; padding-right: 8px; font-variant-numeric: tabular-nums; }
.invoice-table tr.empty td {
  color: transparent;
}

/* ===== 金额汇总 ===== */
.invoice-footer {
  border: 1.5px solid #000;
  border-top: none;
}
.inv-ft-row {
  display: grid;
  border-bottom: 1.5px solid #000;
}
.inv-ft-row:last-child { border-bottom: none; }
.inv-ft-row > div {
  padding: 7px 10px;
  border-right: 1.5px solid #000;
}
.inv-ft-row > div:last-child { border-right: none; }

.inv-summary-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
}
.inv-summary-row .label {
  font-weight: 500;
  background: #f7f7f7;
}
.inv-summary-row .val {
  text-align: right;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.inv-capital-row {
  grid-template-columns: auto 1fr;
}
.inv-capital-row .label {
  background: #f7f7f7;
  font-weight: 500;
  white-space: nowrap;
}

.inv-payment-row {
  grid-template-columns: 80px 1fr;
}

.invoice-notice {
  padding: 8px 10px;
  font-size: 11px;
  color: #444;
  border-bottom: 1.5px solid #000;
}

.inv-signature-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  padding: 0;
}
.inv-signature-row > div {
  padding: 14px 10px 8px;
  border-right: 1.5px solid #000;
  font-size: 12px;
}
.inv-signature-row > div:last-child { border-right: none; }
.inv-signature-row .sign-line {
  display: inline-block;
  border-bottom: 1px solid #000;
  width: 110px;
  margin-left: 4px;
  height: 16px;
}

.inv-page {
  text-align: right;
  padding: 6px 0;
  font-size: 11px;
  color: #666;
}

/* 导出前隐藏滚动条等 */
.invoice.exporting {
  position: relative;
  margin: 0;
  box-shadow: none;
}

/* ===========================================
   移动端适配 (≤ 768px) — 手机/平板
   =========================================== */

@media (max-width: 768px) {
  /* 头部变紧凑 */
  .app-header-inner {
    padding: 10px 14px 8px;
  }
  .app-brand { font-size: 16px; }
  .app-brand-tag { margin-left: 8px; font-size: 11px; }
  .app-actions button {
    padding: 6px 10px;
    font-size: 12px;
  }
  /* Tabs: 横向滚动 */
  .tabs {
    padding: 0 14px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    flex-wrap: nowrap;
  }
  .tabs::-webkit-scrollbar { display: none; }
  .tab-btn {
    white-space: nowrap;
    flex-shrink: 0;
    padding: 10px 12px;
    font-size: 13px;
  }

  .app-main { padding: 14px; }
  .tool-hero { grid-template-columns: 1fr; gap: 18px; margin-bottom: 18px; padding: 26px 20px; border-radius: 10px; }
  .tool-hero h1 { font-size: 31px; }
  .tool-hero-lead { font-size: 16px; }
  .hero-actions { display: grid; grid-template-columns: 1fr; }
  .hero-actions a { justify-content: center; }
  .tool-heading { display: block; margin: 32px 0 14px; }
  .tool-heading h2 { font-size: 22px; }
  .tool-heading-note { max-width: none; margin-top: 14px !important; }
  .seo-section { margin-top: 38px; }
  .seo-section > h2 { font-size: 21px; }
  .value-grid, .workflow-list { grid-template-columns: 1fr; }
  .value-card { min-height: auto; }
  .workflow-list li { min-height: 0; }
  .site-header .app-header-inner { min-height: 0; align-items: flex-start; gap: 10px; }
  .site-brand { font-size: 16px; white-space: nowrap; }
  .site-nav { justify-content: flex-end; flex-wrap: wrap; gap: 8px 12px; }
  .site-nav a { font-size: 12px; }
  .content-shell { padding: 24px 14px; }
  .guide-article, .legal-article { padding: 22px 18px; border-radius: 8px; }
  .lead { font-size: 16px; }
  .guide-grid { grid-template-columns: 1fr; }
  .guide-layout { grid-template-columns: 1fr; gap: 16px; }
  .guide-menu { position: static; padding: 12px; overflow-x: auto; }
  .guide-menu h2 { margin-bottom: 8px; }
  .guide-menu ul { display: flex; width: max-content; gap: 8px; }
  .guide-menu a { padding: 8px 10px; border: 1px solid var(--color-border); white-space: nowrap; }
  .guide-index-grid { grid-template-columns: 1fr; }
  .site-footer-inner { padding: 16px 14px; align-items: flex-start; flex-direction: column; gap: 8px; }

  /* 布局：表单在上、预览在下 */
  .layout-grid {
    grid-template-columns: 1fr;
    gap: 14px;
  }

  .control-panel, .preview-panel {
    padding: 14px;
  }
  /* 预览面板在手机上可隐藏/展示 */
  .preview-panel {
    position: relative;
    /* 使预览区域自适应高度 */
    min-height: auto;
    height: auto;
  }

  .preview-toolbar {
    font-size: 13px;
    padding-bottom: 8px;
    margin-bottom: 10px;
  }
  .preview-tip { font-size: 11px; }
  .preview-scroll {
    padding: 10px;
    overflow-x: hidden;       /* 发票在 JS 里 transform-scale 进装，隐藏滚动条 */
    -webkit-overflow-scrolling: touch;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    max-width: 100%;         /* 强制不超过父容器（关键） */
    width: 100%;
    box-sizing: border-box;
  }

  /* 发票本身在窄屏会减缩 (由 fitInvoiceDisplays 调度) */
  .preview-scroll .invoice,
  .modal-body .invoice {
    margin: 0;
  }

  /* Form grid: 1 列 */
  .form-grid { grid-template-columns: 1fr; gap: 10px; }

  /* 输入/按钮变高 */
  input[type="text"],
  input[type="number"],
  input[type="date"],
  select,
  textarea {
    font-size: 16px;     /* 防止 iOS 自动缩放 */
    padding: 10px 12px;
    min-height: 44px;
  }

  /* “添加明细” 上广列/下广列 */
  .add-item-row {
    grid-template-columns: 1fr;
    gap: 10px;
  }
  .add-item-row input, .add-item-row select { min-height: 44px; }
  .add-item-row button { min-height: 48px; font-size: 15px; }

  /* 明细表横向滚动 */
  .items-table-wrap { overflow-x: auto; }
  .items-table th, .items-table td { padding: 8px 6px; font-size: 12px; white-space: nowrap; }
  .items-table th:nth-child(2), .items-table td:nth-child(2) { min-width: 100px; }   /* 品名占用足够宽度 */

  /* 汇总: 2 列 */
  .summary-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .summary-card { padding: 8px 10px; }
  .summary-card .val { font-size: 16px; }

  /* 导出按钮（与桌面同一布局：垂直排。保存主按钮在前，3 个次按钮 3 列一行 */
  .export-actions > #btn-save {
    min-height: 56px;
    font-size: 17px;
    padding: 14px 20px;
  }
  .export-row2 button {
    min-height: 48px;
    font-size: 13px;
    padding: 8px 4px;
  }

  /* 商品表格 — 手机变为 2 列 */
  .product-form {
    grid-template-columns: 1fr 1fr;
    padding: 12px;
  }
  .product-form label:has(#p-name) { grid-column: 1 / -1; }   /* 品名跨 2 列 */
  .product-form label span { font-size: 11px; }

  /* 手机端：仅显示“下载”按钮，变为全宽主色按钮 */
  .hint-mobile-only { display: block; }

  .export-actions {
    flex-direction: column;
    gap: 8px;
  }
  .export-actions #btn-save,
  .export-actions #btn-preview,
  .export-actions #btn-copy {
    display: none !important;
  }
  .export-actions .export-row2 {
    display: block;
    background: var(--color-primary);
    border-radius: 10px;
    overflow: hidden;
    box-shadow: 0 4px 14px rgba(192,0,0,.25);
  }
  .export-actions #btn-export,
  .export-actions .export-row2 > #btn-export {
    width: 100% !important;
    min-height: 58px !important;
    font-size: 18px !important;
    font-weight: 600 !important;
    background: transparent !important;
    color: #fff !important;
    border: none !important;
    padding: 14px 20px !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    letter-spacing: 1px;
  }
  .export-actions #btn-export:active { background: rgba(255,255,255,0.18) !important; }

  .products-table th, .products-table td {
    padding: 8px 4px;
    font-size: 12px;
  }

  /* 移动端 Modal：主样式已在上面考虑 safe-area，这里只微调间距 */
  @media (max-width: 768px) {
    .modal { padding-left: 8px; padding-right: 8px; }
  }
}

/* ===========================================
   窄桌面与平板：避免双栏被压缩得过窄
   =========================================== */
@media (max-width: 1120px) {
  .layout-grid { grid-template-columns: 1fr; }
  .preview-panel { height: 640px; min-height: 560px; }
}

/* ===========================================
   小手机 (≤ 420px)  特例: 使表格都能看到
   =========================================== */
@media (max-width: 420px) {
  .summary-grid { grid-template-columns: 1fr; }
  .add-item-row button { font-size: 14px; }
  .invoice-company { font-size: 22px; letter-spacing: 2px; }
  .invoice-address { gap: 8px; font-size: 11px; flex-wrap: wrap; }
}

/* ===========================================
   长按保存提示
   =========================================== */
.save-tip {
  margin-top: 14px;
  padding: 12px 14px;
  background: #fff7e6;
  border: 1px solid #ffd591;
  border-radius: 8px;
  font-size: 13px;
  color: #5c3d00;
  line-height: 1.6;
  max-width: 794px;
}
.save-tip strong {
  display: block;
  margin-bottom: 6px;
  color: #c00;
  font-size: 14px;
}
.save-tip p { margin: 3px 0; }

/* 使发票图片本身支持长按（iOS） */
.invoice-rendered {
  display: block;
  width: 794px;
  max-width: 100%;
  height: auto;
  -webkit-touch-callout: default;     /* iOS允许长按 */
  -webkit-user-select: auto;
  user-select: auto;
  pointer-events: auto;
}

/* 让 iOS 实际能长按 img 上的“保存” */
img {
  -webkit-touch-callout: default;
}

/* 可点击发票上的图（iOS 重点） */
.modal-invoice canvas, .modal-invoice img {
  -webkit-touch-callout: default !important;
  -webkit-user-select: auto !important;
}
