:root {
  --bg: #f5f7fa;
  --panel: #ffffff;
  --ink: #1f2d3d;
  --muted: #6b7a90;
  --line: #e6ebf1;
  --brand: #2563eb;
  --brand-d: #1d4ed8;
  --green: #16a34a;
  --red: #dc2626;
  --amber: #d97706;
  --gray: #94a3b8;
  --shadow: 0 1px 3px rgba(16,24,40,.08), 0 1px 2px rgba(16,24,40,.06);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg); color: var(--ink); font-size: 14px; line-height: 1.5;
}
#app { min-height: 100vh; }

/* ---------- 登录 ---------- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg, #1e3a8a, #2563eb); }
.login-card { background: #fff; border-radius: 14px; padding: 36px 32px; width: 360px; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.login-card h1 { font-size: 20px; margin: 0 0 4px; }
.login-card .sub { color: var(--muted); margin: 0 0 22px; font-size: 13px; }
.login-card label { display: block; font-size: 13px; color: var(--muted); margin: 12px 0 6px; }
.login-card input, .login-card select { width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; font-size: 14px; outline: none; }
.login-card input:focus { border-color: var(--brand); }
.btn { cursor: pointer; border: none; border-radius: 8px; padding: 10px 16px; font-size: 14px; font-weight: 600; }
.btn-primary { background: var(--brand); color: #fff; width: 100%; margin-top: 18px; }
.btn-primary:hover { background: var(--brand-d); }
.hint { margin-top: 16px; font-size: 12px; color: var(--muted); background: #f1f5f9; padding: 10px; border-radius: 8px; }

/* ---------- 布局 ---------- */
.layout { display: flex; min-height: 100vh; }
.sidebar { width: 220px; background: #0f172a; color: #cbd5e1; display: flex; flex-direction: column; }
.sidebar .logo { padding: 14px 16px; display: flex; align-items: center; border-bottom: 1px solid #1e293b; }
.sidebar .logo-img { height: 40px; width: auto; max-width: 100%; display: block; }
.sidebar a { padding: 12px 20px; color: #cbd5e1; text-decoration: none; font-size: 14px; border-left: 3px solid transparent; }
.sidebar a:hover { background: #1e293b; }
.sidebar a.active { background: #1e293b; border-left-color: var(--brand); color: #fff; }
.sidebar .spacer { flex: 1; }
.sidebar .me { padding: 14px 20px; border-top: 1px solid #1e293b; font-size: 12px; }
.sidebar .me b { color: #fff; }
.sidebar .logout { color: #f87171; cursor: pointer; }
.main { flex: 1; padding: 24px 28px; overflow: auto; }
.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.page-head h2 { margin: 0; font-size: 20px; }

/* ---------- 卡片 / 网格 ---------- */
.grid { display: grid; gap: 16px; }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 18px; box-shadow: var(--shadow); }
.stat .num { font-size: 30px; font-weight: 700; }
.stat .lbl { color: var(--muted); font-size: 13px; }
.stat.s-blue .num { color: var(--brand); }
.stat.s-green .num { color: var(--green); }
.stat.s-red .num { color: var(--red); }
.stat.s-amber .num { color: var(--amber); }

/* ---------- 表格 / 列表 ---------- */
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: 11px 12px; border-bottom: 1px solid var(--line); font-size: 13px; }
.table th { color: var(--muted); font-weight: 600; background: #fafbfc; }
.table tr:hover td { background: #f8fafc; }
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge.gray { background: #eef2f7; color: #64748b; }
.badge.blue { background: #e0ecff; color: #2563eb; }
.badge.green { background: #dcfce7; color: #16a34a; }
.badge.red { background: #fee2e2; color: #dc2626; }
.badge.amber { background: #fef3c7; color: #d97706; }

.progress { height: 8px; background: #eef2f7; border-radius: 99px; overflow: hidden; width: 120px; }
.progress > span { display: block; height: 100%; background: var(--brand); }

.order-card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 16px; box-shadow: var(--shadow); cursor: pointer; }
.order-card:hover { border-color: var(--brand); }
.order-card .top { display: flex; justify-content: space-between; align-items: center; }
.order-card .mo { font-weight: 700; }
.order-card .meta { color: var(--muted); font-size: 13px; margin: 6px 0; }
.order-card .bar { display: flex; align-items: center; gap: 8px; margin-top: 8px; }

/* ---------- 表单 ---------- */
.form-row { display: flex; gap: 14px; flex-wrap: wrap; }
.form-row .field { flex: 1; min-width: 200px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin: 10px 0 5px; }
.field input, .field select, .field textarea { width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px; font-size: 14px; outline: none; font-family: inherit; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--brand); }
.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }
.btn-sm { padding: 7px 12px; font-size: 13px; }
.btn-outline { background: #fff; border: 1px solid var(--line); color: var(--ink); }
.btn-outline:hover { border-color: var(--brand); color: var(--brand); }
.btn-ghost { background: transparent; border: 1px solid var(--line); color: var(--muted); }
.btn-danger { background: #fee2e2; color: var(--red); border: 1px solid #fecaca; }
.btn-success { background: var(--green); color: #fff; }
.btn-success:hover { filter: brightness(.95); }
input.search { padding: 9px 12px; border: 1px solid var(--line); border-radius: 8px; min-width: 220px; outline: none; }
.sort-bar { display: inline-flex; gap: 6px; flex-wrap: wrap; }
.sort-btn { padding: 7px 12px; font-size: 13px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--ink); cursor: pointer; white-space: nowrap; transition: border-color .15s, color .15s, background .15s; }
.sort-btn:hover { border-color: var(--brand); color: var(--brand); }
.sort-btn.active { background: var(--brand); border-color: var(--brand); color: #fff; }
.proc-tabs { display: flex; flex-wrap: nowrap; align-items: center; gap: 8px; width: 100%; overflow-x: auto; padding: 2px 0; }
.proc-tab { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; padding: 6px 12px; border-radius: 999px; border: 1px solid transparent; font-size: 13px; line-height: 1.2; cursor: pointer; flex: 0 0 auto; transition: filter .15s, opacity .15s; }
.proc-tab b { font-weight: 700; opacity: .85; }
.proc-tab:hover { filter: brightness(.94); }
.proc-tab.active { box-shadow: 0 0 0 2px #fff inset, 0 2px 6px rgba(0,0,0,.18); border-color: rgba(0,0,0,.35); filter: brightness(.92); }
.tab-gray { background: #e5e7eb; color: #374151; }
.tab-blue { background: #dbeafe; color: #1d4ed8; }
.tab-green { background: #dcfce7; color: #15803d; }
.tab-red { background: #fee2e2; color: #b91c1c; }
.tab-indigo { background: #e0e7ff; color: #4338ca; }
.tab-orange { background: #ffedd5; color: #c2410c; }
.tab-cyan { background: #cffafe; color: #0e7490; }
.tab-purple { background: #f3e8ff; color: #7e22ce; }
.tab-pink { background: #fce7f3; color: #be185d; }
.tab-brown { background: #f5e6d3; color: #92400e; }
.tab-teal { background: #ccfbf1; color: #0f766e; }
.tab-yellow { background: #fef9c3; color: #a16207; }

/* ---------- 工序 ---------- */
.proc { display: flex; align-items: center; justify-content: space-between; padding: 11px 14px; border: 1px solid var(--line); border-radius: 10px; margin-bottom: 10px; }
.proc .name { font-weight: 600; }
.proc .sub { color: var(--muted); font-size: 12px; }
.proc .acts { display: flex; gap: 6px; }
.proc[draggable="true"] { cursor: grab; }
.proc.dragging { opacity: .5; }
.proc.drag-over { border-color: var(--brand); box-shadow: 0 0 0 2px rgba(37,99,235,.15); }
.proc-handle { cursor: grab; color: var(--muted); font-size: 18px; line-height: 1; padding: 0 4px; user-select: none; }
.proc.done { background: #f0fdf4; }
.proc.doing { background: #eff6ff; }
.proc.err { background: #fef2f2; }
.section-title { font-size: 15px; font-weight: 700; margin: 22px 0 12px; }

/* ---------- 报表 ---------- */
.report-grid { display: grid; grid-template-columns: repeat(4,1fr); gap: 16px; }
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: #0f172a; color: #fff; padding: 11px 18px; border-radius: 8px; font-size: 13px; opacity: 0; pointer-events: none; transition: opacity .25s; z-index: 99; }
.toast.show { opacity: 1; }
.muted { color: var(--muted); }
.empty { text-align: center; color: var(--muted); padding: 40px; }
.row-actions { display: flex; gap: 6px; }
@media (max-width: 880px) {
  .grid-4, .grid-3, .report-grid { grid-template-columns: repeat(2,1fr); }
  .sidebar { width: 64px; }
  .sidebar .logo-img, .sidebar a span, .sidebar .me { display: none; }
}

/* ---------- 订单详情页二维码（小尺寸） ---------- */
.detail-qr { width: 160px; height: 160px; flex: 0 0 160px; background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 8px; }
.detail-qr svg { width: 100% !important; height: 100% !important; display: block; }

/* ---------- 二维码批量打印 ---------- */
.qr-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
/* 标签纸规格预览：屏幕端按纸张比例展示列数 */
body.paper-5x7 .qr-grid { grid-template-columns: repeat(3, 1fr); }
body.paper-4x6 .qr-grid { grid-template-columns: repeat(4, 1fr); }
body.paper-3x5 .qr-grid { grid-template-columns: repeat(5, 1fr); }
.qr-card {
  position: relative; display: flex; flex-direction: column; gap: 6px;
  border: 1px dashed #cbd5e1; border-radius: 10px; padding: 10px;
  background: #fff; cursor: pointer; break-inside: avoid; page-break-inside: avoid;
}
.qr-card:hover { border-color: var(--brand); }
.qr-card .qr-chk { position: absolute; top: 8px; left: 8px; width: 16px; height: 16px; }
.qr-card.selected { border: 2px solid var(--brand); background: #f5f8ff; }
.qr-card .qr-head-bar { display: flex; flex-direction: row; align-items: center; width: 100%; }
.qr-card .qr-head-bar .qr-logo {
  display: block; height: 22px; width: auto; max-width: 90px; object-fit: contain; margin-right: auto;
  background: #fff; border-radius: 4px; padding: 2px; box-sizing: content-box;
  box-shadow: 0 0 0 1px rgba(0,0,0,.08);
}
.qr-card .qr-head-bar .qr-mo { font-weight: 700; font-size: 13px; }
.qr-card .qr-divider { height: 1px; background: #000; width: 100%; margin: 1px 0; }
.qr-card .qr-customer-line { font-weight: 700; font-size: 13px; line-height: 1.3; width: 100%; word-break: break-all; }
.qr-card .qr-body { display: flex; flex-direction: row; align-items: center; gap: 8px; width: 100%; }
.qr-card .qr-info { font-size: 12px; line-height: 1.45; flex: 1; min-width: 0; }
.qr-card .qr-line { color: var(--ink); white-space: normal; word-break: break-all; line-height: 1.35; }
.qr-card .qr-status { margin-top: 4px; }
.qr-card .qr-svg { width: 90px; height: 90px; flex: 0 0 auto; }
.qr-card .qr-svg svg { width: 100%; height: 100%; display: block; }
@media print {
  .qr-card .qr-head-bar .qr-logo { display: block !important; content: normal !important; background: #fff !important; box-shadow: none !important; border: none !important; padding: 0 !important; border-radius: 0 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
.qr-card .qr-check-mark {
  position: absolute; top: 6px; right: 8px; width: 20px; height: 20px; border-radius: 50%;
  background: var(--brand); color: #fff; font-size: 13px; line-height: 20px; text-align: center; display: none;
}
.qr-card.selected .qr-check-mark { display: block; }
.qr-section-title { font-weight: 700; font-size: 14px; margin: 12px 0 8px; color: var(--ink); }
.qr-card.printed { opacity: 0.6; }
.qr-card.printed .qr-svg svg { filter: grayscale(0.8); }
.qr-card.printed.selected { opacity: 1; }
.qr-card.printed.selected .qr-svg svg { filter: none; }
.badge.printed-badge { background: #dcfce7; color: #16a34a; }

/* 打印：由 app.js applyPrintPaper() 按标签纸规格动态注入 @page 尺寸与卡片布局；此处仅做基础隐藏兜底，避免与动态样式冲突 */
@media print {
  body { background: #fff; }
  .sidebar, .no-print, .page-head .no-print, .toast, .logout { display: none !important; }
  #app { min-height: 0; }
  .layout { display: block; }
  .main { padding: 0; overflow: visible; }
  .qr-card { page-break-inside: avoid; break-inside: avoid; }
  .qr-card .qr-chk { display: none; }
  .qr-card .qr-check-mark { display: none !important; }
  .qr-card:not(.selected) { display: none !important; }
}

/* ---------- 工序选择器（新建订单） ---------- */
.proc-picker { display: flex; gap: 18px; flex-wrap: wrap; margin-top: 6px; }
.proc-picker-side { flex: 1; min-width: 280px; }
.proc-picker-title { font-size: 13px; color: var(--muted); margin-bottom: 8px; font-weight: 600; }
.proc-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.proc-chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 6px 10px;
  background: #f1f5f9; border: 1px solid var(--line); border-radius: 99px;
  cursor: pointer; font-size: 13px; color: var(--ink);
}
.proc-chip:hover { background: #e0ecff; border-color: var(--brand); color: var(--brand); }
.proc-chip .hrs { color: var(--muted); font-size: 11px; }
.proc-custom-add { display: flex; gap: 8px; margin-top: 10px; }
.proc-custom-add input { flex: 1; }
.proc-custom-add input[type="number"] { width: 80px; flex: 0 0 80px; }

.selected-procs { min-height: 120px; }
.sel-proc {
  display: flex; align-items: center; gap: 10px; padding: 9px 12px;
  background: #fff; border: 1px solid var(--line); border-radius: 10px;
  margin-bottom: 8px; cursor: move;
}
.sel-proc.dragging { opacity: .4; }
.sel-proc.drag-over { border-color: var(--brand); background: #f5f8ff; }
.sel-proc .drag-handle {
  color: var(--gray); font-size: 15px; letter-spacing: -2px; cursor: move; user-select: none;
}
.sel-proc .seq { color: var(--muted); font-size: 12px; min-width: 20px; }
.sel-proc .name { flex: 1; font-weight: 600; }
.sel-proc .hrs-input { width: 80px; padding: 6px 8px; text-align: right; }
.sel-proc .del {
  width: 24px; height: 24px; line-height: 22px; text-align: center;
  border-radius: 50%; color: var(--muted); cursor: pointer; font-size: 18px;
}
.sel-proc .del:hover { background: #fee2e2; color: var(--red); }

/* 工序管理页工时输入 */
.hrs-input { padding: 6px 8px; width: 90px; border: 1px solid var(--line); border-radius: 8px; }

/* 状态变更记录 / 操作日志 */
.log-row { display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 8px 10px; border-bottom: 1px solid var(--line); font-size: 14px; }
.log-row:last-child { border-bottom: none; }
.log-row .muted { font-size: 12px; white-space: nowrap; }

/* 筛选行 */
.filter-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.filter-row input, .filter-row select { padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; font-size: 14px; min-width: 130px; }
.filter-row .btn { white-space: nowrap; }

/* ---------- 拍照识别弹窗 ---------- */
.modal-mask { position: fixed; inset: 0; background: rgba(15,23,42,.55); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 100; }
.modal-mask .modal { background: #fff; border-radius: 16px; padding: 22px; width: 100%; max-width: 520px; max-height: 90vh; overflow: auto; }
.modal-mask h3 { margin: 0 0 8px; font-size: 18px; }
.modal-mask input[type="file"] { width: 100%; padding: 10px; border: 1px dashed var(--line); border-radius: 10px; background: #fafbfc; }
.modal-mask input[type="file"]:hover { border-color: var(--brand); }
.modal-mask img { max-width: 100%; border-radius: 10px; }
@media (max-width: 640px) {
  .modal-mask { align-items: flex-end; padding: 0; }
  .modal-mask .modal { max-height: 92vh; border-radius: 16px 16px 0 0; }
}

/* ================= 手机竖屏适配（≤640px） ================= */
@media (max-width: 640px) {
  /* 输入控件 16px 字号，避免 iOS 聚焦自动缩放 */
  input, select, textarea { font-size: 16px; }

  /* ---- 布局：侧边栏 → 顶部横向导航 ---- */
  .layout { flex-direction: column; }
  .sidebar {
    width: auto;
    flex-direction: row; align-items: center;
    position: sticky; top: 0; z-index: 50;
    overflow-x: auto; -webkit-overflow-scrolling: touch;
    border-bottom: 1px solid #1e293b;
  }
  .sidebar .logo {
    padding: 10px 12px; white-space: nowrap;
    border-bottom: none; border-right: 1px solid #1e293b; flex: 0 0 auto;
  }
  .sidebar .logo-img { height: 22px; }
  .sidebar a {
    font-size: 14px; padding: 13px 14px; white-space: nowrap;
    border-left: none; border-bottom: 3px solid transparent; flex: 0 0 auto;
  }
  .sidebar a:hover { background: #1e293b; }
  .sidebar a.active { background: #1e293b; border-left: none; border-bottom-color: var(--brand); }
  /* 顶部导航下 spacer / 用户区不再需要，隐藏 */
  .sidebar .spacer, .sidebar .me { display: none; }

  /* ---- 主内容全宽、减小内边距 ---- */
  .main { padding: 14px 12px 24px; overflow: visible; }

  /* 页头可换行 */
  .page-head { flex-wrap: wrap; gap: 8px; }
  .page-head h2 { font-size: 18px; }

  /* ---- 网格在窄屏下改单列 ---- */
  .grid-4, .grid-3, .grid-2, .report-grid { grid-template-columns: 1fr; gap: 12px; }
  .qr-grid { grid-template-columns: 1fr; gap: 12px; }
  .detail-qr { width: 120px; height: 120px; flex: 0 0 120px; }

  /* ---- 表格：卡片内横向滚动，避免内容挤压 ---- */
  .card { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .table { min-width: 600px; }
  .table th, .table td { padding: 10px; }

  /* ---- 筛选行 / 工具栏 单列全宽 ---- */
  .filter-row { flex-direction: column; align-items: stretch; gap: 10px; }
  .filter-row input, .filter-row select { width: 100%; min-width: 0; }
  .filter-row .btn { width: 100%; }
  .toolbar { flex-direction: column; align-items: stretch; }
  .toolbar input.search, .toolbar select { width: 100%; min-width: 0; }
  input.search { min-width: 0; width: 100%; }

  /* ---- 表单字段单列 ---- */
  .form-row .field { min-width: 100%; }

  /* ---- 工序行 / 已选工序 / 日志行 允许换行 ---- */
  .proc { flex-wrap: wrap; gap: 10px; }
  .proc .acts { flex-wrap: wrap; }
  .sel-proc { flex-wrap: wrap; }
  .log-row { flex-wrap: wrap; }
  .row-actions { flex-wrap: wrap; }

  /* ---- 按钮 / 输入框触控尺寸 ---- */
  .btn { padding: 12px 16px; font-size: 15px; }
  .btn-sm { padding: 10px 12px; font-size: 14px; }
  .field input, .field select, .field textarea { padding: 11px 12px; }
  .progress { width: 90px; }

  /* ---- 登录页全宽适配 ---- */
  .login-wrap { padding: 20px 16px; }
  .login-card { width: 100%; max-width: 400px; padding: 28px 20px; }
  .login-card input, .login-card select { padding: 12px; }

  /* ---- 弹窗补充内边距（与既有底部弹出规则共存） ---- */
  .modal-mask .modal { padding: 18px 16px; }
  .modal-mask .modal h3 { font-size: 17px; }
}

/* 焊前订单固定筛选按钮 */
.pre-filter { display:inline-flex; align-items:center; gap:6px; padding:7px 16px; border-radius:999px; border:1px solid rgba(0,0,0,.15); font-size:13px; font-weight:600; color:#fff; cursor:pointer; transition:filter .15s; background:hsl(145,72%,52%); }
.pre-filter b { font-weight:700; opacity:.92; }
.pre-filter:hover { filter: brightness(.92); }
.pre-filter.active { box-shadow: 0 0 0 2px #fff inset, 0 2px 6px rgba(0,0,0,.25); border-color: rgba(0,0,0,.4); filter: brightness(.9); }

.card.stat.clickable { cursor: pointer; transition: transform .12s ease, border-color .12s ease, box-shadow .12s ease; }
.card.stat.clickable:hover { transform: translateY(-2px); border-color: var(--brand); }
.card.stat.clickable.active { border-color: var(--brand); box-shadow: 0 0 0 1px var(--brand) inset; }
.dash-clear { font-size: 13px; color: var(--brand); margin-left: 8px; text-decoration: none; }
