/* ============ 设计变量 ============ */
:root {
  --primary: #1a936f;
  --primary-dark: #147a5c;
  --accent: #f39c38;
  --bg: #f3f5f7;
  --panel: #ffffff;
  --border: #e5e7eb;
  --text: #1f2937;
  --text-secondary: #6b7280;
  --text-hint: #9ca3af;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --info: #3b82f6;
  --radius: 10px;
  --radius-lg: 14px;
  --shadow: 0 1px 3px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --nav-height: 62px;
  --topbar-height: 56px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html {
  touch-action: manipulation;
  -webkit-text-size-adjust: 100%;
}
html, body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', Arial, sans-serif;
  font-size: 16px;
  color: var(--text);
  background: var(--bg);
  height: 100%;
}
body {
  overscroll-behavior-y: contain;
}
.hidden { display: none !important; }

/* ============ 登录页 ============ */
.login-page {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: linear-gradient(135deg, #f0f9f6 0%, #fff 55%, #fef6ec 100%);
}
.login-card {
  background: var(--panel);
  border-radius: var(--radius-lg);
  padding: 28px 22px;
  width: 100%;
  max-width: 380px;
  box-shadow: var(--shadow-md);
}
.login-logo { text-align: center; margin-bottom: 12px; }
.login-logo img { height: 72px; border-radius: var(--radius); }
.login-title { font-size: 22px; font-weight: 700; text-align: center; margin: 0 0 4px; }
.login-sub { font-size: 13px; color: var(--text-secondary); text-align: center; margin: 0 0 28px; }
.login-form .form-row { margin-bottom: 18px; }
.login-form input { height: 48px; font-size: 16px; }
.login-tip {
  margin-top: 24px;
  padding: 12px;
  background: #f9fafb;
  border-radius: var(--radius);
  font-size: 12px;
  color: var(--text-secondary);
  border: 1px dashed var(--border);
}
.tip-title { font-weight: 600; margin-bottom: 6px; color: var(--text); }
.tip-row { line-height: 1.7; word-break: break-all; }

/* ============ 主应用壳 ============ */
.app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  padding-top: calc(var(--topbar-height) + var(--safe-top));
  padding-bottom: calc(var(--nav-height) + var(--safe-bottom));
}

/* ============ 顶部状态栏 ============ */
.topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: calc(var(--topbar-height) + var(--safe-top));
  padding-top: var(--safe-top);
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-left: 14px;
  padding-right: 12px;
  box-shadow: var(--shadow);
  z-index: 50;
}
.topbar-left { display: flex; align-items: center; gap: 10px; }
.topbar-logo { height: 34px; border-radius: 4px; }
.topbar-title { font-size: 17px; font-weight: 700; color: var(--text); }
.topbar-right { display: flex; align-items: center; gap: 8px; }
.user-info {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-secondary);
  max-width: 160px;
}
.user-info span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-role {
  flex-shrink: 0;
  background: var(--primary);
  color: #fff;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
}

/* ============ 内容区 ============ */
.content {
  flex: 1;
  padding: 14px 12px;
  overflow-x: hidden;
  overflow-y: auto;
}
.page-title { font-size: 18px; font-weight: 700; margin: 0 0 12px; }
.page-sub { color: var(--text-secondary); margin: -8px 0 14px; font-size: 13px; }

/* ============ 底部导航 ============ */
.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: calc(var(--nav-height) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: rgba(255,255,255,0.96);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: flex-start;
  justify-content: space-around;
  z-index: 50;
  padding-top: 6px;
}
.menu-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 3px;
  padding: 5px 0;
  color: var(--text-secondary);
  font-size: 11px;
  cursor: pointer;
  transition: all .15s;
  border-radius: 10px;
  margin: 0 4px;
  min-height: 48px;
}
.menu-item .menu-icon { font-size: 20px; line-height: 1; margin: 0; }
.menu-item.active { color: var(--primary); background: rgba(26,147,111,0.08); font-weight: 600; }
.menu-item:active { transform: scale(0.96); }

/* ============ 卡片 ============ */
.card {
  background: var(--panel);
  border-radius: var(--radius-lg);
  padding: 16px;
  box-shadow: var(--shadow);
  margin-bottom: 14px;
}
.card-title {
  font-size: 15px;
  font-weight: 700;
  margin: 0 0 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.card-title::before { content: ''; display: inline-block; width: 4px; height: 16px; background: var(--primary); border-radius: 2px; }

/* ============ 表单 ============ */
.form-row { margin-bottom: 16px; }
.form-row label { display: block; font-size: 14px; color: var(--text); margin-bottom: 6px; font-weight: 500; }
.form-row label .required { color: var(--danger); margin-left: 2px; }
.form-row input,
.form-row select,
.form-row textarea {
  width: 100%;
  min-height: 46px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 16px;
  font-family: inherit;
  background: #fff;
  color: var(--text);
  transition: border-color .15s, box-shadow .15s;
  -webkit-appearance: none;
}
.form-row input:focus,
.form-row select:focus,
.form-row textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(26,147,111,0.12);
}
.form-row textarea { resize: vertical; min-height: 90px; }
.form-grid { display: grid; grid-template-columns: 1fr; gap: 0 14px; }
.form-grid-3 { display: grid; grid-template-columns: 1fr; gap: 0 14px; }
.form-actions { display: flex; gap: 10px; margin-top: 6px; }
.form-actions .btn { flex: 1; }
.form-error { color: var(--danger); font-size: 13px; min-height: 18px; margin-bottom: 10px; }

/* ============ 按钮 ============ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-height: 44px;
  padding: 9px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  font-size: 15px;
  cursor: pointer;
  transition: all .15s;
  font-family: inherit;
  white-space: nowrap;
}
.btn:hover { background: #f9fafb; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); }
.btn-accent { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-accent:hover { background: #e08a26; }
.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-ghost { border-color: transparent; background: transparent; color: var(--text-secondary); }
.btn-sm { min-height: 34px; padding: 5px 12px; font-size: 13px; }
.btn-block { width: 100%; }
.btn-float {
  position: fixed;
  right: 16px;
  bottom: calc(var(--nav-height) + var(--safe-bottom) + 16px);
  width: 56px;
  height: 56px;
  border-radius: 50%;
  box-shadow: var(--shadow-md);
  z-index: 40;
}

/* ============ 状态徽章 ============ */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
}
.badge-pending { background: #fef3c7; color: #92400e; }
.badge-white_confirmed { background: #dbeafe; color: #1e40af; }
.badge-printing { background: #e0e7ff; color: #3730a3; }
.badge-printed { background: #d1fae5; color: #065f46; }
.badge-inspecting { background: #e0e7ff; color: #3730a3; }
.badge-inspected { background: #d1fae5; color: #065f46; }
.badge-packaging { background: #e0e7ff; color: #3730a3; }
.badge-packaged { background: #d1fae5; color: #065f46; }
.badge-ready_to_ship { background: #fce7f3; color: #9d174d; }
.badge-shipped { background: #d1fae5; color: #065f46; }

/* ============ 筛选条 ============ */
.filter-bar {
  display: none;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 14px;
  padding: 14px;
  background: var(--panel);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}
.filter-bar.open { display: flex; }
.filter-bar .filter-row { display: flex; flex-direction: column; gap: 4px; width: 100%; }
.filter-bar label { font-size: 13px; color: var(--text-secondary); }
.filter-bar input,
.filter-bar select {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 16px;
  background: #fff;
  width: 100%;
  min-height: 44px;
}
.filter-actions { width: 100%; display: flex; gap: 10px; }
.filter-actions .btn { flex: 1; }
.filter-toggle {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
  background: var(--panel);
  padding: 12px 14px;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  font-size: 14px;
  color: var(--text-secondary);
}
.filter-toggle strong { color: var(--text); }

/* ============ 订单卡片列表 ============ */
.order-list { display: flex; flex-direction: column; gap: 12px; }
.order-card {
  background: var(--panel);
  border-radius: var(--radius-lg);
  padding: 14px;
  box-shadow: var(--shadow);
}
.order-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.order-card-no { font-size: 15px; font-weight: 700; }
.order-card-body {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 14px;
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 12px;
}
.order-card-body .full { grid-column: 1 / -1; }
.order-card-body strong { color: var(--text); font-weight: 500; }
.order-card-footer {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  border-top: 1px solid var(--border);
  padding-top: 12px;
}
.order-card-footer .btn { flex: 1; min-width: 72px; }

/* ============ 看板卡片 ============ */
.stat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; margin-bottom: 16px; }
.stat-card {
  background: var(--panel);
  padding: 16px;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  border-left: 4px solid var(--primary);
}
.stat-card.c-warning { border-left-color: var(--warning); }
.stat-card.c-info { border-left-color: var(--info); }
.stat-card.c-success { border-left-color: var(--success); }
.stat-label { font-size: 12px; color: var(--text-secondary); margin-bottom: 6px; }
.stat-value { font-size: 26px; font-weight: 700; color: var(--text); }

/* ============ 待办区域 ============ */
.todo-section { margin-bottom: 18px; }
.todo-section-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-secondary);
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.todo-section-title::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}
.todo-card {
  background: var(--panel);
  border-radius: var(--radius-lg);
  padding: 14px;
  box-shadow: var(--shadow);
  margin-bottom: 10px;
}
.todo-card-title { font-size: 15px; font-weight: 700; margin-bottom: 6px; }
.todo-card-meta { font-size: 13px; color: var(--text-secondary); margin-bottom: 12px; display: flex; flex-wrap: wrap; gap: 6px 14px; }
.todo-card-actions { display: flex; gap: 8px; }
.todo-card-actions .btn { flex: 1; }

/* ============ 表格（桌面端保留） ============ */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  background: var(--panel);
  border-radius: var(--radius);
  overflow: hidden;
}
.table th, .table td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.table th {
  background: #f9fafb;
  font-weight: 600;
  color: var(--text-secondary);
  font-size: 12px;
}
.table tbody tr:hover { background: #f9fafb; }
.table .actions { display: flex; gap: 6px; }

/* ============ 弹窗（移动端底部 Sheet / 桌面居中） ============ */
.modal-mask {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 100;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 0;
}
.modal {
  background: #fff;
  border-radius: 20px 20px 0 0;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  box-shadow: 0 -4px 20px rgba(0,0,0,0.15);
  animation: sheetUp .25s ease-out;
}
.modal-lg { max-height: 92vh; }
@keyframes sheetUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: #fff;
  z-index: 1;
}
.modal-title { font-size: 17px; font-weight: 700; margin: 0; }
.modal-close { background: none; border: none; font-size: 24px; cursor: pointer; color: var(--text-hint); padding: 0; width: 32px; height: 32px; }
.modal-body { padding: 18px; }
.modal-footer {
  padding: 12px 18px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  background: #fff;
  position: sticky;
  bottom: 0;
  z-index: 1;
}
.modal-footer .btn { flex: 1; }

/* ============ 详情页 ============ */
.stage-flow {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  align-items: center;
  padding: 12px;
  background: #f9fafb;
  border-radius: var(--radius);
  margin-bottom: 14px;
}
.stage-node {
  padding: 5px 10px;
  border-radius: 12px;
  font-size: 11px;
  background: #fff;
  border: 1px solid var(--border);
  color: var(--text-secondary);
}
.stage-node.done { background: var(--success); color: #fff; border-color: var(--success); }
.stage-node.current { background: var(--primary); color: #fff; border-color: var(--primary); font-weight: 600; }
.stage-arrow { color: var(--text-hint); font-size: 11px; }

.stage-block {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 10px;
  overflow: hidden;
}
.stage-block-header {
  background: #f9fafb;
  padding: 10px 14px;
  font-weight: 700;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.stage-block-body { padding: 12px 14px; }
.field-row { display: flex; padding: 7px 0; font-size: 14px; }
.field-label { width: 100px; color: var(--text-secondary); flex-shrink: 0; }
.field-value { flex: 1; color: var(--text); word-break: break-all; }
.empty-hint { color: var(--text-hint); font-size: 13px; padding: 8px 0; }

/* ============ 分页 ============ */
.pagination { display: flex; gap: 6px; justify-content: center; margin-top: 16px; align-items: center; }
.pagination .page-btn { padding: 8px 14px; border: 1px solid var(--border); background: #fff; border-radius: var(--radius); cursor: pointer; font-size: 14px; min-height: 40px; }
.pagination .page-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.pagination .page-btn:disabled { opacity: .5; cursor: not-allowed; }
.pagination .page-info { color: var(--text-secondary); font-size: 13px; padding: 0 8px; }

/* ============ Toast ============ */
.toast {
  position: fixed;
  top: calc(var(--topbar-height) + var(--safe-top) + 10px);
  left: 50%;
  transform: translateX(-50%);
  background: #1f2937;
  color: #fff;
  padding: 10px 20px;
  border-radius: 24px;
  font-size: 14px;
  z-index: 200;
  box-shadow: var(--shadow-md);
  animation: toastIn .2s;
  max-width: 90vw;
  text-align: center;
}
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, -10px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* ============ 空状态 ============ */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-hint);
  font-size: 14px;
}

/* ============ PWA 安装提示 ============ */
.install-prompt,
.ios-install-tip,
.update-toast {
  position: fixed;
  left: 12px;
  right: 12px;
  background: #fff;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  z-index: 250;
  padding: 14px;
}
.install-prompt {
  bottom: calc(var(--nav-height) + var(--safe-bottom) + 10px);
}
.install-body { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.install-icon { width: 48px; height: 48px; border-radius: 10px; }
.install-text { display: flex; flex-direction: column; }
.install-text strong { font-size: 15px; margin-bottom: 2px; }
.install-text span { font-size: 13px; color: var(--text-secondary); }
.install-actions { display: flex; gap: 10px; }
.install-actions .btn { flex: 1; }

.ios-install-tip {
  bottom: calc(var(--nav-height) + var(--safe-bottom) + 10px);
  padding: 12px 14px;
}
.ios-body {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 14px;
  gap: 10px;
}
.ios-share { width: 18px; height: 18px; fill: var(--primary); vertical-align: -3px; }
.ios-close { background: none; border: none; font-size: 22px; color: var(--text-hint); cursor: pointer; width: 28px; height: 28px; }

.update-toast {
  top: calc(var(--topbar-height) + var(--safe-top) + 10px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 14px;
}

/* ============ 打印样式 ============ */
.print-root { display: none; }
@media print {
  body * { visibility: hidden; }
  .print-root, .print-root * { visibility: visible; }
  .print-root {
    display: block !important;
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
  }
  @page { size: A4; margin: 15mm; }
}
.print-doc { font-family: 'SimSun', serif; color: #000; background: #fff; }
.print-header { text-align: center; margin-bottom: 16px; border-bottom: 2px solid #000; padding-bottom: 12px; }
.print-logo { height: 50px; margin-bottom: 8px; }
.print-title { font-size: 22px; font-weight: bold; margin: 8px 0 4px; }
.print-subtitle { font-size: 13px; color: #333; }
.print-section { margin: 14px 0; }
.print-section-title { font-weight: bold; font-size: 14px; border-left: 3px solid #000; padding-left: 8px; margin-bottom: 8px; }
.print-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.print-table td, .print-table th { border: 1px solid #333; padding: 6px 8px; }
.print-table th { background: #f0f0f0; font-weight: bold; }
.print-footer { margin-top: 24px; display: flex; justify-content: space-between; font-size: 12px; }

/* ============ 桌面端增强 ============ */
@media (min-width: 769px) {
  .app { max-width: 900px; margin: 0 auto; }
  .topbar,
  .bottom-nav { max-width: 900px; left: 50%; transform: translateX(-50%); }
  .modal-mask { justify-content: center; padding: 20px; }
  .modal {
    border-radius: var(--radius-lg);
    max-width: 640px;
    animation: fadeIn .2s ease-out;
  }
  .modal-lg { max-width: 860px; }
  @keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
  .form-grid { grid-template-columns: repeat(2, 1fr); }
  .form-grid-3 { grid-template-columns: repeat(3, 1fr); }
  .filter-bar { display: flex !important; }
  .filter-toggle { display: none; }
  .filter-bar .filter-row { width: auto; flex: 1; min-width: 160px; }
  .filter-actions { width: auto; }
  .stat-grid { grid-template-columns: repeat(4, 1fr); }
  .order-card-body { grid-template-columns: repeat(3, 1fr); }
}
