:root {
  --ink: #17201d;
  --muted: #6f7b76;
  --line: #dce5e0;
  --surface: #ffffff;
  --canvas: #f4f7f5;
  --green: #0c7a54;
  --green-dark: #07583d;
  --green-soft: #e7f5ee;
  --gold: #d88b22;
  --danger: #c8493c;
  --shadow: 0 16px 44px rgba(31, 58, 47, .08);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  min-width: 1060px;
  background:
    radial-gradient(circle at 85% -10%, rgba(12, 122, 84, .11), transparent 28%),
    var(--canvas);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

button, input, select { font: inherit; }
button { cursor: pointer; }

.app-shell { min-height: 100vh; }

.topbar {
  height: 92px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 48px;
  background: rgba(255, 255, 255, .9);
  border-bottom: 1px solid rgba(220, 229, 224, .9);
  backdrop-filter: blur(18px);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand { display: flex; align-items: center; gap: 14px; }
.brand-mark {
  width: 48px; height: 48px; border-radius: 15px;
  display: grid; place-items: center;
  background: var(--ink); color: #fff;
  font-size: 22px; font-weight: 800;
  box-shadow: 0 8px 18px rgba(23, 32, 29, .18);
}
.brand h1 { margin: 0; font-size: 20px; letter-spacing: -.2px; }
.brand p { margin: 4px 0 0; color: var(--muted); font-size: 12px; }

.privacy-badge {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 13px; border-radius: 999px;
  color: var(--green-dark); background: var(--green-soft);
  font-size: 12px; font-weight: 650;
}
.privacy-badge span { width: 8px; height: 8px; border-radius: 50%; background: #23aa78; box-shadow: 0 0 0 4px rgba(35, 170, 120, .13); }
.user-area { display: flex; align-items: center; gap: 14px; }
.current-user { min-width: 90px; padding-left: 14px; border-left: 1px solid var(--line); }
.current-user strong, .current-user small { display: block; }
.current-user strong { max-width: 160px; overflow: hidden; text-overflow: ellipsis; font-size: 13px; white-space: nowrap; }
.current-user small { margin-top: 3px; color: var(--muted); font-size: 10px; }
.logout-button { height: 34px; padding: 0 13px; border: 1px solid var(--line); border-radius: 9px; background: #fff; color: #4a5852; font-size: 11px; font-weight: 700; }
.logout-button:hover { border-color: #aabbb3; background: #f8faf9; }
.tool-home-link { height: 34px; display: inline-flex; align-items: center; padding: 0 13px; border: 1px solid var(--line); border-radius: 9px; color: #4a5852; background: #fff; font-size: 11px; font-weight: 700; text-decoration: none; }
.tool-home-link:hover { border-color: #aabbb3; background: #f8faf9; }

main { width: min(1480px, calc(100% - 96px)); margin: 34px auto 72px; }

.import-card, .search-section, .history-card {
  background: var(--surface);
  border: 1px solid rgba(220, 229, 224, .9);
  border-radius: 22px;
  box-shadow: var(--shadow);
}
.import-card { padding: 28px 30px 30px; }
.search-section { margin-top: 24px; padding: 28px 30px 30px; }
.history-card { margin-top: 24px; padding: 26px 30px; }

.section-heading, .history-head { display: flex; justify-content: space-between; gap: 28px; align-items: flex-start; }
.section-heading.compact { align-items: center; }
.eyebrow { color: var(--green); font-size: 11px; font-weight: 800; letter-spacing: 1.6px; text-transform: uppercase; margin-bottom: 7px; }
.section-heading h2, .history-head h2 { margin: 0; font-size: 23px; letter-spacing: -.35px; }
.section-heading p { margin: 8px 0 0; color: var(--muted); font-size: 13px; line-height: 1.6; }
.step-badge { color: #c9d6d0; font: 800 28px/1 Georgia, serif; }

.import-grid { display: grid; grid-template-columns: 250px minmax(420px, 1fr) 152px; gap: 16px; align-items: end; margin-top: 24px; }
.field { display: flex; flex-direction: column; gap: 8px; }
.field span { font-size: 12px; font-weight: 700; color: #4f5d57; }

input, select {
  height: 46px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0 14px;
  color: var(--ink);
  background: #fff;
  outline: none;
  transition: border-color .18s, box-shadow .18s;
}
input:focus, select:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(12, 122, 84, .1); }

.drop-zone {
  min-height: 76px;
  border: 1px dashed #a8bbb2;
  border-radius: 14px;
  background: #f9fbfa;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 15px 18px;
  cursor: pointer;
  transition: .18s ease;
}
.drop-zone:hover, .drop-zone.dragging { border-color: var(--green); background: var(--green-soft); transform: translateY(-1px); }
.upload-icon { width: 42px; height: 42px; display: grid; place-items: center; border-radius: 12px; color: var(--green); background: #fff; border: 1px solid #d7e9e1; font-size: 24px; font-weight: 600; }
.drop-zone strong { display: block; font-size: 13px; }
.drop-zone small { display: block; color: var(--muted); margin-top: 5px; }

.button { height: 46px; border-radius: 12px; border: 0; padding: 0 20px; font-weight: 750; transition: .18s ease; }
.button:hover:not(:disabled) { transform: translateY(-1px); }
.button:disabled { opacity: .45; cursor: not-allowed; }
.button-primary { color: #fff; background: var(--green); box-shadow: 0 8px 20px rgba(12, 122, 84, .2); }
.button-primary:hover:not(:disabled) { background: var(--green-dark); }
.button-dark { color: #fff; background: var(--ink); }
.button-outline { color: var(--green-dark); background: #fff; border: 1px solid #9dc8b6; }

.import-result { margin-top: 18px; border-radius: 13px; padding: 12px 15px; background: #f7faf8; border: 1px solid var(--line); font-size: 13px; }
.result-item { display: flex; gap: 10px; padding: 5px 0; }
.result-item.ok::before { content: "✓"; color: var(--green); font-weight: 900; }
.result-item.fail::before { content: "!"; color: var(--danger); font-weight: 900; }
.result-item span { color: var(--muted); }

.search-toolbar { display: grid; grid-template-columns: minmax(320px, 1.3fr) minmax(220px, .8fr) 190px 92px 132px; gap: 12px; margin-top: 24px; }
.search-box { position: relative; }
.search-box input { width: 100%; padding-left: 42px; }
.search-icon { position: absolute; left: 15px; top: 8px; color: var(--muted); font-size: 23px; transform: rotate(-12deg); }
.filter-presets { margin-top: 12px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 13px; background: #fafcfb; }
.filter-presets-heading { display: flex; align-items: center; gap: 10px; }
.filter-presets-heading strong { color: #34443d; font-size: 11px; }
.filter-presets-heading span { flex: 1; color: var(--muted); font-size: 10px; }
.filter-presets-heading button { height: 30px; padding: 0 10px; border: 1px solid #a9cdbd; border-radius: 8px; color: var(--green-dark); background: #fff; font-size: 10px; font-weight: 750; }
.filter-presets-heading button:hover { background: var(--green-soft); }
.filter-preset-list { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 10px; }
.filter-preset-empty { color: var(--muted); font-size: 10px; }
.filter-preset-tag { display: inline-flex; overflow: hidden; border: 1px solid #cbded5; border-radius: 999px; background: #fff; }
.filter-preset-tag button { height: 29px; border: 0; background: transparent; font-size: 10px; }
.filter-preset-apply { padding: 0 10px 0 12px; color: #345147; font-weight: 750; }
.filter-preset-remove { width: 27px; padding: 0; border-left: 1px solid #e0ebe6 !important; color: #997064; }
.filter-preset-tag button:hover { color: var(--green-dark); background: var(--green-soft); }
.filter-preset-remove:hover { color: #9c4034 !important; background: #f8e5e1 !important; }
.export-options { min-height: 36px; display: flex; justify-content: flex-end; align-items: center; gap: 12px; margin-top: 8px; color: var(--muted); }
.export-options small { font-size: 11px; }
.switch-control { display: inline-flex; align-items: center; gap: 9px; color: #415049; font-size: 12px; font-weight: 700; cursor: pointer; }
.switch-control input { position: absolute; opacity: 0; pointer-events: none; }
.switch-track { width: 38px; height: 22px; border-radius: 999px; background: #cbd5d0; position: relative; transition: .18s ease; }
.switch-track::after { content: ""; position: absolute; width: 16px; height: 16px; top: 3px; left: 3px; border-radius: 50%; background: #fff; box-shadow: 0 2px 5px rgba(0,0,0,.18); transition: .18s ease; }
.switch-control input:checked + .switch-track { background: var(--green); }
.switch-control input:checked + .switch-track::after { transform: translateX(16px); }
.switch-control input:focus-visible + .switch-track { box-shadow: 0 0 0 3px rgba(12, 122, 84, .18); }

.metrics { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 14px; margin-top: 18px; }
.metric { min-height: 104px; padding: 18px 20px; border-radius: 16px; border: 1px solid var(--line); background: #fbfcfb; position: relative; overflow: hidden; }
.metric.accent { background: var(--green-soft); border-color: #cfe8dd; }
.metric.invoiced-total { background: #f2f8f5; border-color: #d4e7de; }
.metric.uninvoiced-total { background: #faf6f1; border-color: #eadfd3; }
.metric.invoice-total strong { font-size: 23px; }
.metric span { display: block; color: var(--muted); font-size: 12px; font-weight: 650; }
.metric strong { display: inline-block; margin-top: 9px; font-size: 26px; letter-spacing: -.5px; }
.metric small { margin-left: 6px; color: var(--muted); font-size: 11px; }

.table-card { border: 1px solid var(--line); border-radius: 16px; overflow: hidden; margin-top: 18px; }
.table-head { height: 62px; display: flex; align-items: center; justify-content: space-between; padding: 0 18px 0 20px; border-bottom: 1px solid var(--line); }
.table-head strong { font-size: 14px; }
.table-head span { margin-left: 10px; color: var(--muted); font-size: 11px; }
.table-head select { height: 34px; font-size: 12px; border-radius: 9px; }
.table-controls { display: flex; align-items: center; gap: 14px; }
.batch-actions { display: flex; align-items: center; gap: 7px; }
.table-head .batch-actions span { margin: 0 3px 0 0; min-width: 52px; color: var(--green-dark); font-weight: 750; text-align: right; }
.batch-actions button { height: 32px; padding: 0 10px; border-radius: 9px; background: #fff; font-size: 11px; font-weight: 700; white-space: nowrap; }
.batch-actions button.batch-mark { border: 1px solid #9dc8b6; color: var(--green-dark); }
.batch-actions button.batch-restore { border: 1px solid #d6bda7; color: #8a5c39; }
.batch-actions button:hover:not(:disabled) { background: #f5f8f6; }
.batch-actions button:disabled { opacity: .4; cursor: not-allowed; }
.table-scroll { overflow: auto; max-height: 590px; }
table { border-collapse: separate; border-spacing: 0; width: 100%; min-width: 1790px; }
th { position: sticky; top: 0; z-index: 2; background: #f1f5f3; color: #4a5852; font-size: 11px; letter-spacing: .2px; text-align: left; padding: 12px 13px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 13px; font-size: 12px; border-bottom: 1px solid #edf1ef; color: #35423d; white-space: nowrap; }
tbody tr:hover td { background: #f8fbf9; }
tbody tr.selected-row td { background: #eef8f3; }
.select-cell { width: 42px; min-width: 42px; padding-left: 15px; padding-right: 7px; text-align: center; }
.select-cell input { width: 16px; height: 16px; accent-color: var(--green); cursor: pointer; }
th.amount, td.amount { text-align: right; }
td.amount { color: var(--danger); font-weight: 750; }
.phone-pill { padding: 4px 8px; border-radius: 8px; background: #eef3f0; color: #3d4a45; font-variant-numeric: tabular-nums; }
.counterparty { max-width: 230px; overflow: hidden; text-overflow: ellipsis; font-weight: 700; color: var(--ink); }
.product-cell { max-width: 340px; overflow: hidden; text-overflow: ellipsis; color: #53615b; }
.table-search-btn { display: block; max-width: 100%; overflow: hidden; padding: 4px 6px; margin: -4px -6px; border: 0; border-radius: 7px; background: transparent; color: inherit; font: inherit; font-weight: inherit; text-align: left; text-overflow: ellipsis; white-space: nowrap; cursor: pointer; transition: background .16s, color .16s; }
.table-search-btn:hover { background: var(--green-soft); color: var(--green-dark); }
.table-search-btn:focus-visible { outline: 2px solid rgba(12, 122, 84, .35); outline-offset: 1px; }
.wechat-searchable { cursor: pointer; transition: color .16s, background-color .16s; }
.wechat-searchable:hover { color: var(--green-dark); background: var(--green-soft); }
.invoice-chip { display: inline-flex; align-items: center; justify-content: center; min-width: 56px; height: 24px; padding: 0 8px; border-radius: 999px; font-size: 10px; font-weight: 800; }
.invoice-chip.invoiced { color: var(--green-dark); background: var(--green-soft); }
.invoice-chip.uninvoiced { color: #7a6250; background: #f4eee8; }
.invoice-chip.partial { color: #7a5a12; background: #fff3cd; }
.invoice-date { display: block; margin-top: 4px; color: var(--muted); font-size: 10px; }
.invoice-cell { min-width: 112px; position: relative; padding-right: 44px; }
.manual-label { display: block; margin-top: 3px; color: #8a5c39; font-size: 9px; }
.single-invoice-btn { position: absolute; top: 0; right: 0; height: 26px; padding: 0 7px; border: 1px solid #b9cec5; border-radius: 8px; background: #fff; color: var(--green-dark); font-size: 10px; font-weight: 750; }
.single-invoice-btn:hover:not(:disabled) { background: var(--green-soft); }
.single-invoice-btn:disabled { opacity: .5; cursor: wait; }
.order-cell { max-width: 235px; overflow: hidden; text-overflow: ellipsis; color: #76817d; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 10px; }
.empty-row td { height: 180px; text-align: center; color: var(--muted); }

.pagination { height: 56px; display: flex; justify-content: center; align-items: center; gap: 18px; background: #fbfcfb; }
.pagination button { border: 1px solid var(--line); background: #fff; border-radius: 9px; height: 32px; padding: 0 13px; color: #48564f; }
.pagination button:disabled { opacity: .4; cursor: not-allowed; }
.pagination span { color: var(--muted); font-size: 12px; }

.history-head { align-items: center; }
.history-description { margin: 8px 0 0; color: var(--muted); font-size: 12px; }
.text-button { border: 0; background: transparent; color: var(--green); font-weight: 700; }
.history-list { margin-top: 18px; border-top: 1px solid var(--line); }
.history-item { display: grid; grid-template-columns: 148px minmax(220px, 1fr) 190px 140px 160px 92px; align-items: center; gap: 16px; min-height: 66px; border-bottom: 1px solid #edf1ef; font-size: 12px; }
.history-item .file { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 650; }
.history-item .muted { color: var(--muted); }
.history-empty { padding: 36px; color: var(--muted); text-align: center; font-size: 13px; }
.status-chip { justify-self: start; padding: 5px 9px; border-radius: 999px; background: var(--green-soft); color: var(--green-dark); font-size: 11px; font-weight: 750; }
.correct-phone-btn { height: 32px; padding: 0 10px; border: 1px solid #9dc8b6; border-radius: 9px; background: #fff; color: var(--green-dark); font-size: 11px; font-weight: 700; white-space: nowrap; }
.correct-phone-btn:hover:not(:disabled) { background: var(--green-soft); }
.correct-phone-btn:disabled { opacity: .5; cursor: wait; }
.export-history-list { margin-top: 18px; border-top: 1px solid var(--line); }
.export-history-item { display: grid; grid-template-columns: 190px minmax(260px, 1fr) 105px 145px 90px 285px; align-items: center; gap: 14px; min-height: 78px; border-bottom: 1px solid #edf1ef; font-size: 12px; }
.export-history-item.voided { background: #fbf8f7; }
.export-history-item.voided .export-code, .export-history-item.voided .export-file { opacity: .62; }
.export-code { color: var(--green-dark); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11px; font-weight: 750; }
.export-file { min-width: 0; }
.export-file strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.export-file small, .export-total small { display: block; margin-top: 5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.export-total strong { font-size: 13px; }
.export-time { color: var(--muted); }
.export-actions { display: flex; gap: 7px; justify-content: flex-end; }
.export-actions button { height: 32px; padding: 0 10px; border: 1px solid var(--line); border-radius: 9px; background: #fff; color: #45534d; font-size: 11px; font-weight: 700; white-space: nowrap; }
.export-actions button.mark { border-color: #9dc8b6; color: var(--green-dark); }
.export-actions button.restore { border-color: #d6bda7; color: #8a5c39; }
.export-actions button.void { border-color: #dfb1a8; color: #a14739; }
.export-actions button.activate { border-color: #9dc8b6; color: var(--green-dark); }
.export-actions button:hover:not(:disabled) { background: #f5f8f6; }
.export-actions button:disabled { opacity: .5; cursor: wait; }
.invoice-chip.voided { color: #9c4034; background: #f8e5e1; }

.auth-page { min-width: 0; min-height: 100vh; background: #edf3f0; }
.auth-layout { width: 100%; min-height: 100vh; display: grid; grid-template-columns: minmax(420px, 1.05fr) minmax(460px, .95fr); margin: 0; }
.auth-intro { min-height: 100vh; display: flex; flex-direction: column; padding: 48px clamp(44px, 7vw, 108px); color: #f4faf7; background: radial-gradient(circle at 15% 80%, rgba(84, 199, 151, .2), transparent 28%), linear-gradient(145deg, #172b25 0%, #0c503c 100%); }
.auth-brand .brand-mark { color: #15372d; background: #eff9f4; }
.auth-brand h1 { color: #fff; }
.auth-brand p { color: rgba(237, 249, 243, .68); }
.auth-message { margin: auto 0; padding: 60px 0; }
.auth-kicker { display: inline-block; margin-bottom: 20px; color: #8cddbb; font-size: 12px; font-weight: 800; letter-spacing: 2px; }
.auth-message h2 { margin: 0; font-size: clamp(38px, 4.4vw, 66px); line-height: 1.08; letter-spacing: -2px; }
.auth-message p { max-width: 610px; margin: 28px 0 0; color: rgba(237, 249, 243, .74); font-size: 15px; line-height: 1.9; }
.security-points { display: flex; flex-wrap: wrap; gap: 10px; }
.security-points span { padding: 8px 12px; border: 1px solid rgba(220, 247, 235, .2); border-radius: 999px; color: rgba(240, 252, 246, .78); font-size: 11px; }
.auth-panel { display: flex; flex-direction: column; justify-content: center; align-items: center; padding: 44px; }
.auth-card { width: min(440px, 100%); min-height: 430px; display: flex; flex-direction: column; justify-content: center; padding: 42px; border: 1px solid rgba(220, 229, 224, .95); border-radius: 24px; background: #fff; box-shadow: 0 24px 70px rgba(23, 50, 40, .13); }
.auth-loading { color: var(--muted); text-align: center; }
.auth-form { display: flex; flex-direction: column; gap: 18px; }
.auth-form-heading { margin-bottom: 8px; }
.auth-form-heading h2 { margin: 0; font-size: 29px; letter-spacing: -.6px; }
.auth-form-heading p { margin: 9px 0 0; color: var(--muted); font-size: 13px; line-height: 1.6; }
.auth-submit { width: 100%; margin-top: 4px; }
.auth-error { margin-top: 18px; padding: 11px 13px; border: 1px solid #efc9c4; border-radius: 10px; color: #9d392f; background: #fff5f3; font-size: 12px; }
.auth-footnote { margin: 18px 0 0; color: var(--muted); font-size: 11px; }

.toast { position: fixed; left: 50%; bottom: 34px; transform: translate(-50%, 20px); background: var(--ink); color: #fff; padding: 11px 16px; border-radius: 10px; font-size: 12px; opacity: 0; pointer-events: none; transition: .2s; z-index: 100; box-shadow: 0 12px 30px rgba(0,0,0,.18); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 1200px) {
  main { width: calc(100% - 48px); }
  .topbar { padding: 0 24px; }
  .import-grid { grid-template-columns: 220px 1fr 150px; }
}

@media (max-width: 860px) {
  .auth-layout { display: block; }
  .auth-intro { min-height: auto; padding: 30px 24px 38px; }
  .auth-message { padding: 70px 0 50px; }
  .auth-message h2 { font-size: 42px; }
  .auth-panel { padding: 34px 20px 48px; }
  .auth-card { min-height: 0; padding: 30px 24px; }
}
