:root {
  --brand: #E4502D; --brand-ink: #B83A1C; --brand-soft: #FDEEE9;
  --bg: #F4F3F1; --card: #FFFFFF; --ink: #1D1D1F; --muted: #6E6E73; --line: #E3E1DE;
  --ok: #1E8E4E; --ok-soft: #E3F4EA; --warn: #A86A00; --warn-soft: #FFF3D6; --bad: #C6322B; --bad-soft: #FDE7E5;
  --radius: 12px; --tap: 44px;
  --nav-h: 62px;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.5 -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Segoe UI", Roboto, sans-serif; -webkit-text-size-adjust: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
a { color: var(--brand-ink); }
h1, h2, h3 { margin: 0; line-height: 1.25; }

/* ---------- 登录 ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: linear-gradient(160deg, #fff 0%, var(--bg) 60%); }
.login-card { width: 100%; max-width: 360px; background: var(--card); border-radius: 16px; padding: 28px 22px; box-shadow: 0 10px 40px rgba(0,0,0,.08); display: grid; gap: 14px; }
.login-logo { width: 180px; justify-self: center; }
.login-card h1 { text-align: center; font-size: 18px; font-weight: 600; color: var(--muted); }

/* ---------- 布局 ---------- */
.app { min-height: 100vh; }
.nav { position: fixed; left: 0; right: 0; bottom: 0; height: calc(var(--nav-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom); background: rgba(255,255,255,.96); backdrop-filter: blur(12px); border-top: 1px solid var(--line); display: flex; z-index: 50; }
.nav-logo { display: none; }
.nav a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; text-decoration: none; color: var(--muted); font-size: 11.5px; min-height: var(--tap); }
.nav a svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.nav a.active { color: var(--brand); font-weight: 600; }
.view { padding: 14px 16px calc(var(--nav-h) + 28px + env(safe-area-inset-bottom)); max-width: 1500px; margin: 0 auto; }
@media (min-width: 980px) {
  .nav { top: 0; right: auto; width: 208px; height: 100vh; flex-direction: column; justify-content: flex-start; border-top: none; border-right: 1px solid var(--line); padding: 18px 12px; gap: 4px; }
  .nav-logo { display: block; width: 168px; margin: 4px auto 18px; }
  .nav a { flex: none; flex-direction: row; justify-content: flex-start; gap: 12px; padding: 10px 14px; border-radius: 10px; font-size: 15px; }
  .nav a.active { background: var(--brand-soft); }
  .view { margin-left: 208px; padding: 22px 28px 40px; }
}

/* ---------- 通用组件 ---------- */
.page-title { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 4px 0 14px; flex-wrap: wrap; }
.page-title h2 { font-size: 21px; font-weight: 700; }
.card { background: var(--card); border-radius: var(--radius); padding: 16px; box-shadow: 0 1px 2px rgba(0,0,0,.04); border: 1px solid rgba(0,0,0,.03); }
.card + .card { margin-top: 12px; }
.card h3 { font-size: 15px; font-weight: 700; margin-bottom: 10px; }
.btn { min-height: var(--tap); padding: 0 16px; border-radius: 10px; border: 1px solid var(--line); background: #fff; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 6px; font-weight: 600; white-space: nowrap; text-decoration: none; color: var(--ink); transition: background .15s, transform .1s; }
.btn:active { transform: scale(.98); }
.btn:hover { background: #fafafa; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-ink); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--brand-ink); }
.btn.danger { color: var(--bad); }
.btn.small { min-height: 36px; padding: 0 12px; font-size: 14px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.btns { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.field { display: grid; gap: 4px; min-width: 0; }
.field > span { font-size: 12.5px; color: var(--muted); }
input, select, textarea { width: 100%; min-height: var(--tap); border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; background: #fff; outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(228,80,45,.15); }
textarea { min-height: 120px; resize: vertical; line-height: 1.5; }
.grid { display: grid; gap: 10px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 560px) { .g3, .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.span2 { grid-column: span 2; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.err { color: var(--bad); font-size: 14px; min-height: 1em; margin: 0; }
.seg { display: inline-flex; background: #EEECE9; border-radius: 10px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.seg button { border: none; background: transparent; min-height: 38px; padding: 0 14px; border-radius: 8px; cursor: pointer; font-weight: 600; color: var(--muted); }
.seg button.on { background: #fff; color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.1); }
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: 999px; font-size: 12.5px; font-weight: 600; white-space: nowrap; }
.badge.matched { background: var(--ok-soft); color: var(--ok); }
.badge.fuzzy, .badge.manual { background: var(--warn-soft); color: var(--warn); }
.badge.not_found { background: var(--bad-soft); color: var(--bad); }
.badge.draft { background: #EEE; color: #555; } .badge.sent { background: #E3ECF8; color: #1F5FAD; } .badge.confirmed { background: var(--ok-soft); color: var(--ok); } .badge.cancelled { background: #EEE; color: #999; text-decoration: line-through; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { border: 1px dashed #CFCBC6; background: #fff; border-radius: 999px; padding: 6px 12px; font-size: 13px; cursor: pointer; color: var(--muted); text-align: left; min-height: 36px; }
.chip:hover { border-color: var(--brand); color: var(--brand-ink); }
.toast { position: fixed; left: 50%; bottom: calc(var(--nav-h) + 20px); transform: translateX(-50%) translateY(20px); background: #222; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 14px; opacity: 0; pointer-events: none; transition: .2s; z-index: 200; max-width: calc(100vw - 32px); }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.bad { background: var(--bad); }
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.35); display: grid; place-items: center; padding: 16px; z-index: 150; }
.modal-card { background: #fff; border-radius: 16px; padding: 20px; width: 100%; max-width: 640px; max-height: 86vh; overflow: auto; display: grid; gap: 12px; }
.empty { text-align: center; color: var(--muted); padding: 30px 10px; }

/* ---------- AI 报价 ---------- */
.q-layout { display: grid; gap: 14px; grid-template-columns: minmax(0, 1fr); }
.q-layout > *, .grid > * { min-width: 0; }
.chip { max-width: 100%; overflow-wrap: anywhere; }
.seg { max-width: 100%; }
@media (min-width: 1200px) { .q-layout.has-draft { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); align-items: start; } .q-preview-col { position: sticky; top: 16px; } }
.input-box { position: relative; }
.input-box textarea { min-height: 130px; padding-bottom: 12px; }
.img-thumb { display: flex; align-items: center; gap: 10px; margin-top: 8px; }
.img-thumb img { width: 64px; height: 64px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); }
.loading { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); }
.spinner { width: 18px; height: 18px; border: 2.5px solid #ddd; border-top-color: var(--brand); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.warn-box { background: var(--warn-soft); color: #6b4700; border-radius: 10px; padding: 10px 12px; font-size: 13.5px; }
.warn-box ul { margin: 4px 0 0; padding-left: 18px; }
.raw-box { background: #F7F6F4; border-radius: 10px; padding: 10px 12px; font-size: 13px; color: var(--muted); white-space: pre-wrap; word-break: break-word; max-height: 140px; overflow: auto; }
.tabs { display: flex; gap: 6px; margin-bottom: 10px; }
.tabs button { min-height: 40px; border-radius: 10px 10px 0 0; border: none; border-bottom: 3px solid transparent; background: transparent; padding: 0 16px; font-weight: 700; color: var(--muted); cursor: pointer; }
.tabs button.on { color: var(--brand-ink); border-bottom-color: var(--brand); }
.items { display: grid; gap: 10px; grid-template-columns: minmax(0, 1fr); }
.items > * { min-width: 0; }
.item { border: 1px solid var(--line); border-left: 5px solid var(--ok); border-radius: 12px; padding: 12px; background: #fff; }
.item.fuzzy, .item.manual { border-left-color: #E0A100; }
.item.not_found { border-left-color: var(--bad); background: #FFFAFA; }
.item-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.item-head .t { font-weight: 700; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-note { font-size: 12.5px; color: var(--muted); margin-top: 6px; }
.item-amt { font-weight: 700; text-align: right; margin-top: 6px; }
.item .grid { gap: 8px; }
.item input, .item select { min-height: 40px; padding: 6px 10px; }
.item .field > span { font-size: 12px; }
.totals-mini { display: grid; gap: 4px; font-size: 14px; }
.totals-mini div { display: flex; justify-content: space-between; }
.totals-mini .g { font-weight: 800; font-size: 16px; color: var(--brand-ink); }
.sticky-actions { position: sticky; bottom: calc(var(--nav-h) + 8px + env(safe-area-inset-bottom)); z-index: 20; background: rgba(255,255,255,.96); backdrop-filter: blur(10px); border-radius: 14px; padding: 10px; box-shadow: 0 6px 24px rgba(0,0,0,.1); margin-top: 12px; }
@media (min-width: 980px) { .sticky-actions { bottom: 12px; } }

.preview-wrap { background: #E7E5E2; border-radius: var(--radius); padding: 10px; overflow: hidden; }
.preview-scale { transform-origin: top left; }
.preview-scale .sheet { box-shadow: 0 2px 10px rgba(0,0,0,.15); margin-bottom: 12px; }
.print-root { position: absolute; left: -100000px; top: 0; }

/* ---------- 列表与表格 ---------- */
.filters { display: grid; gap: 8px; grid-template-columns: minmax(0, 2fr) repeat(3, minmax(0, 1fr)); margin-bottom: 12px; }
@media (max-width: 760px) { .filters { grid-template-columns: repeat(2, minmax(0, 1fr)); } .filters .q { grid-column: span 2; } }
.rec { display: grid; gap: 6px; }
.rec-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; align-items: center; }
.rec-no { font-weight: 700; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13.5px; }
.rec-amt { font-weight: 800; }
.tbl-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: var(--radius); background: #fff; border: 1px solid var(--line); }
table.grid-t { border-collapse: collapse; width: 100%; font-size: 13.5px; }
table.grid-t th { position: sticky; top: 0; background: #F7F6F4; text-align: left; font-weight: 600; color: var(--muted); padding: 8px 6px; border-bottom: 1px solid var(--line); white-space: nowrap; font-size: 12.5px; }
table.grid-t td { padding: 4px; border-bottom: 1px solid #F0EEEB; vertical-align: middle; }
table.grid-t td input, table.grid-t td select { min-height: 38px; padding: 4px 8px; border-color: transparent; background: transparent; min-width: 60px; }
table.grid-t td input:hover { border-color: var(--line); }
table.grid-t td input:focus { background: #fff; }
table.grid-t tr.stale td { background: #FFF8E1; }
table.grid-t tr.inactive td { opacity: .5; }
table.grid-t tr.dirty td { background: #EEF5FF; }
table.grid-t td.act { white-space: nowrap; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12.5px; color: var(--muted); margin: 8px 2px; }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; vertical-align: -2px; margin-right: 4px; }
.imp-list { font-size: 13px; max-height: 300px; overflow: auto; border: 1px solid var(--line); border-radius: 10px; }
.imp-list div { padding: 6px 10px; border-bottom: 1px solid #F0EEEB; }
.imp-list .bad { color: var(--bad); }
.theme-pick { display: flex; gap: 10px; flex-wrap: wrap; }
.theme-pick button { width: 44px; height: 44px; border-radius: 12px; border: 3px solid transparent; cursor: pointer; }
.theme-pick button.on { border-color: var(--ink); }
.bank-fixed { background: #F3F7FD; border: 1px solid #C9D9F0; color: #0E3D7A; border-radius: 10px; padding: 10px 12px; font-size: 14px; }
.terms-box { border-top: 1px solid var(--line); padding-top: 10px; }
.terms-box summary { cursor: pointer; font-weight: 600; font-size: 14px; color: var(--muted); min-height: 32px; display: flex; align-items: center; }
