:root {
  --bg: #f5f7f8;
  --panel: #ffffff;
  --ink: #20262d;
  --muted: #68717b;
  --line: #d8dfe4;
  --accent: #176b73;
  --accent-dark: #105158;
  --green: #277a53;
  --orange: #b85c10;
  --red: #b42318;
  --soft-green: #eaf5ef;
  --soft-orange: #fff2e6;
  --soft-blue: #edf4f6;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Microsoft YaHei", "Segoe UI", Arial, sans-serif;
}

button, input, select {
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  letter-spacing: 0;
}

button { padding: 0 13px; cursor: pointer; white-space: nowrap; }
button:hover { border-color: #9aabb4; background: #f8fafb; }
button:disabled { cursor: not-allowed; opacity: .55; }
button.primary { color: #fff; background: var(--accent); border-color: var(--accent); }
button.primary:hover { background: var(--accent-dark); }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 18px 26px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

h1, h2, h3, p { margin: 0; }
h1 { font-size: 23px; }
h2 { font-size: 17px; }
h3 { font-size: 15px; }
.brand p { margin-top: 5px; color: var(--muted); font-size: 13px; }
.actions, .filters, .tabs, .batchBar, .importControls, .modalFooter, .sectionHeader { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; }
.actions { justify-content: flex-end; }

main { padding: 16px 26px 32px; }

.filters, .panel, .kpis {
  padding: 13px;
  margin-bottom: 13px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.filters { align-items: end; }
label { display: grid; gap: 5px; color: var(--muted); font-size: 13px; }
label input, label select { min-width: 132px; padding: 0 9px; }
#startYear, #endYear { width: 100px; min-width: 100px; }
#startMonth, #endMonth { width: 88px; min-width: 88px; }
.searchLabel { flex: 1; min-width: 180px; }
.searchLabel input { width: 100%; }
.check, .inlineCheck { display: flex; flex-direction: row; align-items: center; gap: 6px; color: var(--ink); }
.check { height: 36px; }
.check input, .inlineCheck input, .fieldCheck input { min-width: 16px; width: 16px; height: 16px; margin: 0; }

.kpis { display: grid; grid-template-columns: repeat(4, minmax(140px, 1fr)); gap: 10px; }
.kpi { min-height: 76px; padding: 12px 14px; border-left: 4px solid var(--accent); background: var(--soft-blue); }
.kpi2 { border-color: #3976a8; background: #edf3f9; }
.kpi3 { border-color: var(--orange); background: var(--soft-orange); }
.kpi4 { border-color: #8b4b93; background: #f5eef6; }
.kpi span { color: var(--muted); font-size: 13px; }
.kpi strong { display: block; margin-top: 5px; font-size: 22px; }

.tabs { margin: 0 0 13px; }
.tab.active { color: #fff; background: var(--ink); border-color: var(--ink); }
.panel { display: none; padding: 0; overflow: hidden; }
.panel.active { display: block; }
.batchBar { padding: 10px 13px; border-bottom: 1px solid var(--line); background: #fbfcfc; }
#selectedCount { min-width: 100px; color: var(--muted); font-size: 13px; }
.batchDivider { width: 1px; height: 28px; margin: 0 3px; background: var(--line); }
.batchMonthLabel { display: flex; flex-direction: row; align-items: center; gap: 7px; white-space: nowrap; }
#batchMonth { width: 145px; min-width: 145px; padding: 0 9px; }

.tableWrap { overflow: auto; max-height: 62vh; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 8px 9px; text-align: left; vertical-align: middle; white-space: nowrap; border-bottom: 1px solid var(--line); }
th { position: sticky; top: 0; z-index: 2; background: #eef2f4; font-weight: 600; }
tr:hover > td { background: #fbfcfc; }
.num { text-align: right; }
.selectCol { width: 38px; text-align: center; }
.selectCol input { width: 16px; height: 16px; }
.noteCell { max-width: 220px; overflow: hidden; text-overflow: ellipsis; }
.emptyCell, .emptyState { padding: 28px; text-align: center; color: var(--muted); }

.badge { display: inline-block; padding: 3px 7px; border-radius: 999px; background: #e8edf0; color: #53616a; font-size: 12px; }
.badge.dup { background: var(--soft-orange); color: var(--orange); }
.linkBtn { height: auto; padding: 0; border: 0; background: transparent; color: var(--accent); text-decoration: underline; }
.linkBtn:hover { border: 0; background: transparent; color: var(--accent-dark); }
.rowActions { display: flex; gap: 5px; }
.rowActions button { height: 29px; padding: 0 9px; }
.attachmentActions { display: flex; align-items: center; gap: 5px; white-space: nowrap; }
.attachmentActions button { height: 28px; padding: 0 8px; }
.delete { color: var(--red); }
.statusBtn, .attachmentBtn { height: 28px; padding: 0 9px; }
.statusBtn.done { color: var(--green); background: var(--soft-green); border-color: #b9ddc9; }
.statusBtn.pending { color: var(--orange); background: var(--soft-orange); border-color: #efccb0; }
.attachmentBtn.ok { color: var(--green); }
.attachmentBtn.missing { color: var(--red); }

.miniTable { min-width: 610px; font-size: 12px; }
.miniTable th { position: static; }
.miniTable th, .miniTable td { padding: 5px 7px; }
.summaryGrid { display: grid; grid-template-columns: repeat(2, minmax(300px, 1fr)); gap: 0; }
.summaryGrid > div { padding: 16px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.summaryGrid h2 { margin-bottom: 10px; }

dialog.modal {
  width: min(720px, calc(100vw - 32px));
  max-height: calc(100vh - 40px);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 18px 52px rgba(24, 35, 43, .22);
  overflow: auto;
}
dialog.wideModal { width: min(1400px, calc(100vw - 30px)); }
dialog::backdrop { background: rgba(23, 31, 37, .45); }
.modalHeader { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between; padding: 14px 17px; background: #fff; border-bottom: 1px solid var(--line); }
.iconClose { width: 34px; padding: 0; font-size: 22px; line-height: 1; }
.modalFooter { justify-content: flex-end; padding: 13px 17px; border-top: 1px solid var(--line); background: #fbfcfc; }
.modalFooter span { margin-right: auto; color: var(--muted); }
dialog.filePickerModal {
  width: min(1120px, calc(100vw - 32px));
  color: #26323a;
  background: #f7f9fa;
}
dialog.filePickerModal[open] {
  display: flex;
  flex-direction: column;
  height: min(820px, calc(100vh - 32px));
  max-height: calc(100vh - 32px);
  overflow: hidden;
}
.filePickerModal .modalHeader, .filePickerToolbar, .driveBar, .filePickerModal .modalFooter { flex: 0 0 auto; }
.filePickerModal .modalHeader { min-height: 58px; padding: 12px 18px; }
.filePickerModal .modalHeader h2 { font-size: 18px; }
.filePickerModal .iconClose { border-color: transparent; background: transparent; }
.filePickerModal .iconClose:hover { border-color: var(--line); background: #f2f5f6; }
.filePickerToolbar {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) auto;
  gap: 8px;
  padding: 16px 18px 10px;
  background: #fff;
}
.filePickerToolbar input { width: 100%; height: 40px; padding: 0 12px; background: #fbfcfd; }
.filePickerToolbar input:focus { outline: 2px solid rgba(23, 107, 115, .18); border-color: var(--accent); }
.filePickerToolbar button { height: 40px; }
.iconButton { width: 42px; padding: 0; font-size: 20px; }
.driveBar {
  display: flex;
  align-items: center;
  gap: 7px;
  min-height: 48px;
  padding: 0 18px 12px;
  border-bottom: 1px solid var(--line);
  background: #fff;
}
.driveBar button { height: 30px; min-width: 52px; padding: 0 12px; color: #42515b; background: #f7f9fa; }
.driveBar button:hover { color: var(--accent-dark); border-color: #9ebdc1; background: #eef5f6; }
.filePickerBody {
  display: grid;
  flex: 1 1 auto;
  grid-template-columns: minmax(280px, .62fr) minmax(520px, 1.38fr);
  min-height: 0;
  overflow: hidden;
  background: #fff;
}
.filePickerModal.noFolders .filePickerBody { grid-template-columns: minmax(220px, .42fr) minmax(560px, 1.58fr); }
.filePickerModal.folderMode .filePickerBody { grid-template-columns: 1fr; }
.filePickerBody section { position: relative; min-width: 0; min-height: 0; overflow-x: hidden; overflow-y: auto; scrollbar-gutter: stable; background: #fff; }
.filePickerBody section + section { border-left: 1px solid var(--line); }
.filePickerBody h3 {
  position: sticky;
  top: 0;
  z-index: 2;
  margin: 0;
  padding: 13px 16px 11px;
  border-bottom: 1px solid #e8edf0;
  color: #5d6973;
  background: #f8fafb;
  font-size: 13px;
  font-weight: 600;
}
.pickerList { display: flex; flex-direction: column; min-width: 0; }
.pickerRow {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr);
  align-items: center;
  width: 100%;
  min-height: 42px;
  height: auto;
  padding: 8px 16px;
  border: 0;
  border-bottom: 1px solid #f0f3f4;
  border-radius: 0;
  text-align: left;
  white-space: normal;
  background: transparent;
}
.pickerRow:hover { border: 0; border-bottom: 1px solid #e4ecee; background: #f0f6f6; }
.folderMark { color: var(--accent); font-size: 11px; }
.pickerRow span:last-child { min-width: 0; overflow-wrap: anywhere; line-height: 20px; }
.pickerFile {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr) 70px;
  align-items: center;
  gap: 9px;
  min-height: 46px;
  padding: 7px 16px;
  border-bottom: 1px solid #edf1f3;
  color: #35434c;
  cursor: pointer;
}
.pickerFile:hover { background: #f5f9f9; }
.pickerFile:has(input:checked) { box-shadow: inset 3px 0 0 var(--accent); background: #eaf4f4; color: #173f43; }
.pickerFile input[type="radio"], .pickerFile input[type="checkbox"] {
  width: 17px;
  min-width: 17px;
  height: 17px;
  margin: 0;
  padding: 0;
  accent-color: var(--accent);
}
.pickerFile span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; line-height: 22px; }
.pickerFile small { color: #7a858d; text-align: right; white-space: nowrap; }
.pickerEmpty { display: grid; place-items: center; min-height: 150px; padding: 28px 18px; color: #87919a; text-align: center; }
.filePickerModal .modalFooter { min-height: 64px; padding: 12px 18px; background: #f8fafb; }
.filePickerModal .modalFooter button { height: 38px; }
.filePickerModal #filePickerSummary { color: #586670; font-size: 13px; }
.importControls { padding: 14px 17px; align-items: end; }
.pdfFolderLabel { min-width: min(430px, 100%); flex: 1; }
.pdfFolderLabel .folderControl { margin-top: 5px; }
.previewWrap { max-height: 58vh; border-top: 1px solid var(--line); }
.previewTable { min-width: 1380px; }
.tableInput { width: 130px; min-width: 0; padding: 0 7px; }
.invoiceInput { width: 205px; }
.amountInput { width: 110px; }
.sellerInput { width: 190px; }
.noteInput { width: 160px; }
.warningRow td { background: #fffaf2; }
.errorRow td { background: #fff4f2; }
.warningText { max-width: 230px; margin-top: 4px; color: var(--red); white-space: normal; font-size: 12px; }
.duplicateDetail { padding: 3px 0; color: var(--muted); white-space: normal; }
details summary { color: var(--orange); cursor: pointer; }
details .inlineCheck { margin-top: 6px; }

.formGrid { display: grid; grid-template-columns: repeat(2, minmax(220px, 1fr)); gap: 12px; padding: 17px; }
.formGrid label input, .formGrid label select { width: 100%; }
.span2 { grid-column: span 2; }
.settingsGrid { display: grid; grid-template-columns: 2fr 1fr; gap: 18px; padding: 17px; }
.displaySettings { grid-column: 1 / -1; }
.sectionHeader { justify-content: space-between; margin-bottom: 10px; }
.settingRow { display: grid; gap: 7px; padding: 9px 0; border-bottom: 1px solid var(--line); }
.companyRow { grid-template-columns: minmax(150px, .8fr) minmax(260px, 1.4fr) minmax(220px, 1.2fr) auto; }
.personRow { grid-template-columns: 1fr auto; }
.settingRow input { width: 100%; padding: 0 8px; }
.folderControl { display: flex; gap: 6px; }
.folderControl input { flex: 1; }
.associationControls { display: flex; align-items: end; gap: 9px; padding: 14px 17px 8px; }
.associationControls label { flex: 1; }
.associationControls .folderControl { margin-top: 5px; }
.associationRule { margin: 0; padding: 4px 17px 13px; color: var(--muted); font-size: 13px; }
.associationPreview { max-height: 56vh; border-top: 1px solid var(--line); }
.associationPreview table { min-width: 900px; }
.badge.safeMatch { color: var(--green); background: var(--soft-green); border-color: #b9ddc9; }
.checkGrid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 9px; padding: 17px; }
.compactChecks { grid-template-columns: repeat(4, minmax(120px, 1fr)); padding: 4px 0; }
.fieldCheck { display: flex; flex-direction: row; align-items: center; gap: 8px; color: var(--ink); }

.toast { position: fixed; right: 22px; bottom: 22px; z-index: 20; max-width: 460px; padding: 10px 14px; color: #fff; background: var(--ink); border-radius: 7px; opacity: 0; transform: translateY(8px); transition: .18s ease; pointer-events: none; }
.toast.show { opacity: 1; transform: translateY(0); }

@media (max-width: 900px) {
  .topbar { align-items: flex-start; flex-direction: column; }
  .actions { justify-content: flex-start; }
  .kpis, .summaryGrid, .settingsGrid, .formGrid { grid-template-columns: 1fr; }
  .span2 { grid-column: auto; }
  .companyRow { grid-template-columns: 1fr; }
  .associationControls { align-items: stretch; flex-direction: column; }
  .filePickerBody { grid-template-columns: 1fr; }
  .filePickerBody:not(:has(#filePickerPdfSection[hidden])) { grid-template-rows: minmax(0, 1fr) minmax(0, 1fr); }
  .filePickerBody section + section { border-top: 1px solid var(--line); border-left: 0; }
  main { padding: 12px; }
}

/* Web settings have name, buyer aliases and remove action. */
.companyRow { grid-template-columns: minmax(150px, 1fr) minmax(180px, 1.4fr) auto; }
