:root {
  --page: #f4f6f8;
  --panel: #ffffff;
  --ink: #15231f;
  --muted: #66736f;
  --line: #d8e0dd;
  --line-soft: #e9eeec;
  --accent: #0f766e;
  --accent-dark: #0a5f59;
  --accent-soft: #eaf7f4;
  --blue: #2563eb;
  --blue-soft: #eff6ff;
  --amber: #b45309;
  --amber-soft: #fff7e8;
  --red: #c2414b;
  --red-soft: #fff1f2;
  --green: #14804a;
  --green-soft: #ecfdf3;
  --shadow: 0 14px 36px rgba(30, 54, 45, 0.08);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background: var(--page);
  color: var(--ink);
  font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select {
  font: inherit;
}

button,
.dropzone {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

h1,
h2,
p {
  margin: 0;
}

.app-header {
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.header-inner,
.page-shell {
  width: min(1540px, 100%);
  margin: 0 auto;
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  min-height: 78px;
  padding: 14px 24px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 13px;
  min-width: 0;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  border-radius: 8px;
  background: var(--accent);
  color: #ffffff;
  font-size: 19px;
  font-weight: 900;
}

h1 {
  font-size: 20px;
  line-height: 1.25;
}

.brand p,
.section-heading p,
.result-heading p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.55;
}

.back-link {
  color: var(--blue);
  font-size: 13px;
  font-weight: 800;
  text-decoration: none;
  white-space: nowrap;
}

.back-link:hover {
  text-decoration: underline;
}

.page-shell {
  padding: 22px 24px 40px;
}

.upload-section,
.result-section {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.section-heading,
.result-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line-soft);
}

.section-heading h2,
.result-heading h2 {
  font-size: 15px;
  line-height: 1.35;
}

.system-status {
  max-width: 52%;
  padding: 7px 10px;
  border: 1px solid #cfe7e1;
  border-radius: 6px;
  background: var(--accent-soft);
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 800;
  line-height: 1.5;
  text-align: right;
}

.system-status.error {
  border-color: #fecdd3;
  background: var(--red-soft);
  color: var(--red);
}

.upload-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  padding: 16px 18px;
}

.dropzone {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  min-height: 88px;
  padding: 14px;
  border: 1px dashed #98aaa4;
  border-radius: 8px;
  background: #fbfcfc;
  transition: border-color 0.16s ease, background 0.16s ease, box-shadow 0.16s ease;
}

.dropzone:hover,
.dropzone.drag-over {
  border-color: var(--accent);
  background: var(--accent-soft);
  box-shadow: inset 0 0 0 1px rgba(15, 118, 110, 0.14);
}

.dropzone.loaded {
  border-style: solid;
  border-color: #83c7b0;
  background: var(--green-soft);
}

.dropzone input {
  display: none;
}

.upload-step {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent);
  color: #ffffff;
  font-size: 13px;
  font-weight: 900;
}

.upload-copy {
  display: grid;
  gap: 5px;
  min-width: 0;
}

.upload-copy strong {
  font-size: 14px;
}

.upload-copy span {
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-state {
  color: var(--accent);
  font-size: 12px;
  font-weight: 900;
  white-space: nowrap;
}

.rule-bar {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) auto auto auto auto;
  align-items: end;
  gap: 12px;
  padding: 13px 18px;
  border-top: 1px solid var(--line-soft);
  background: #f8faf9;
}

.rule-summary {
  align-self: center;
  min-width: 0;
}

.rule-summary strong,
.rule-summary span {
  display: block;
}

.rule-summary strong {
  font-size: 13px;
}

.rule-summary span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.compact-field,
.toolbar-field {
  display: grid;
  gap: 5px;
  color: #44534e;
  font-size: 11px;
  font-weight: 800;
}

.input-suffix {
  display: flex;
  align-items: center;
  min-height: 36px;
  border: 1px solid #c8d4d0;
  border-radius: 6px;
  background: #ffffff;
  overflow: hidden;
}

.input-suffix:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(15, 118, 110, 0.12);
}

.input-suffix input {
  width: 62px;
  height: 34px;
  padding: 6px 4px 6px 10px;
  border: 0;
  outline: 0;
  color: var(--ink);
  text-align: right;
}

.input-suffix span {
  padding: 0 9px 0 4px;
  color: var(--muted);
  font-size: 12px;
}

.primary-button,
.secondary-button {
  min-height: 36px;
  padding: 8px 14px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 900;
  white-space: nowrap;
}

.primary-button {
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #ffffff;
}

.primary-button:not(:disabled):hover {
  border-color: var(--accent-dark);
  background: var(--accent-dark);
}

.secondary-button {
  border: 1px solid #c8d4d0;
  background: #ffffff;
  color: #394842;
}

.secondary-button:not(:disabled):hover {
  border-color: #93a7a0;
  background: #f7f9f8;
}

.result-section {
  margin-top: 18px;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(120px, 0.75fr)) minmax(190px, 1fr);
  border-bottom: 1px solid var(--line-soft);
  background: #fbfcfc;
}

.metric-cell {
  min-width: 0;
  padding: 15px 18px;
  border-right: 1px solid var(--line-soft);
}

.metric-cell:last-child {
  border-right: 0;
}

.metric-cell span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.metric-cell strong {
  display: block;
  margin-top: 7px;
  overflow: hidden;
  font-size: 24px;
  font-variant-numeric: tabular-nums;
  line-height: 1.15;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.metric-cell.exact strong {
  color: var(--green);
}

.metric-cell.similar strong {
  color: var(--amber);
}

.metric-cell.unmatched strong {
  color: var(--red);
}

.metric-cell.amount strong {
  color: var(--blue);
  font-size: 21px;
}

.result-heading {
  align-items: center;
}

.toolbar {
  display: flex;
  align-items: end;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line-soft);
  background: #ffffff;
}

.store-field select,
.search-field input {
  min-height: 36px;
  border: 1px solid #c8d4d0;
  border-radius: 6px;
  background: #ffffff;
  color: var(--ink);
  outline: 0;
}

.store-field select:focus,
.search-field input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(15, 118, 110, 0.12);
}

.store-field select {
  min-width: 160px;
  padding: 7px 30px 7px 10px;
}

.status-filter {
  display: inline-flex;
  min-height: 36px;
  padding: 3px;
  border: 1px solid #c8d4d0;
  border-radius: 6px;
  background: #f5f7f6;
}

.filter-button {
  min-height: 28px;
  padding: 4px 10px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.filter-button.active {
  background: #ffffff;
  color: var(--accent);
  box-shadow: 0 1px 4px rgba(30, 54, 45, 0.12);
}

.search-field {
  flex: 1;
  min-width: 180px;
}

.search-field input {
  width: 100%;
  padding: 7px 11px;
}

.visible-count {
  padding-bottom: 9px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 20px;
  padding: 9px 16px;
  border-bottom: 1px solid var(--line-soft);
  background: #fbfcfc;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.5;
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.legend-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #9ca3af;
}

.legend-dot.exact {
  background: var(--green);
}

.legend-dot.similar {
  background: var(--amber);
}

.legend-dot.unmatched {
  background: var(--red);
}

.table-wrap {
  position: relative;
  max-height: calc(100vh - 430px);
  min-height: 260px;
  overflow: auto;
}

table {
  width: 100%;
  min-width: 1320px;
  border-collapse: separate;
  border-spacing: 0;
}

th,
td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line-soft);
  background: #ffffff;
  font-size: 12px;
  line-height: 1.45;
  text-align: left;
  vertical-align: middle;
}

th {
  position: sticky;
  top: 0;
  z-index: 3;
  background: #f2f5f4;
  color: #4f5e59;
  font-size: 11px;
  font-weight: 900;
  white-space: nowrap;
}

tbody tr:hover td {
  background: #f9fbfa;
}

td.money,
th.money,
td.number,
th.number {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.row-number {
  width: 58px;
  color: #899590;
  text-align: right;
}

.store-name {
  max-width: 220px;
  color: var(--ink);
  font-weight: 800;
  white-space: nowrap;
}

.order-number {
  color: #42524c;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  white-space: nowrap;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  min-height: 25px;
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 900;
  white-space: nowrap;
}

.status-badge.exact {
  background: var(--green-soft);
  color: var(--green);
}

.status-badge.similar {
  background: var(--amber-soft);
  color: var(--amber);
}

.status-badge.unmatched {
  background: var(--red-soft);
  color: var(--red);
}

.difference-positive {
  color: var(--red);
}

.difference-negative {
  color: var(--blue);
}

.note-cell {
  min-width: 260px;
  max-width: 360px;
  color: #52605b;
}

.muted-cell {
  color: #9aa49f;
}

.empty-state,
.initial-state {
  color: var(--muted);
  text-align: center;
}

.empty-state {
  padding: 44px 18px;
  font-size: 13px;
}

.initial-state {
  display: grid;
  place-items: center;
  gap: 7px;
  min-height: 220px;
  margin-top: 18px;
  border: 1px dashed #bdc9c5;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.54);
}

.initial-state strong {
  color: #52605b;
  font-size: 14px;
}

.initial-state span {
  font-size: 12px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 980px) {
  .rule-bar {
    grid-template-columns: minmax(220px, 1fr) auto auto;
  }

  .rule-summary {
    grid-column: 1 / -1;
  }

  .metrics {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .metric-cell:nth-child(3) {
    border-right: 0;
  }

  .metric-cell:nth-child(n + 4) {
    border-top: 1px solid var(--line-soft);
  }

  .metric-cell.amount {
    grid-column: span 2;
  }

  .toolbar {
    flex-wrap: wrap;
  }

  .search-field {
    min-width: 280px;
  }
}

@media (max-width: 720px) {
  .header-inner,
  .page-shell {
    padding-left: 14px;
    padding-right: 14px;
  }

  .header-inner {
    min-height: 70px;
  }

  .brand p {
    display: none;
  }

  .back-link {
    font-size: 12px;
  }

  .section-heading,
  .result-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .system-status {
    max-width: none;
    text-align: left;
  }

  .upload-grid {
    grid-template-columns: 1fr;
  }

  .dropzone {
    grid-template-columns: 34px minmax(0, 1fr);
  }

  .file-state {
    grid-column: 2;
  }

  .rule-bar {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .rule-summary {
    grid-column: 1 / -1;
  }

  .primary-button,
  .secondary-button {
    width: 100%;
  }

  .metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .metric-cell:nth-child(2n) {
    border-right: 0;
  }

  .metric-cell:nth-child(3) {
    border-right: 1px solid var(--line-soft);
  }

  .metric-cell:nth-child(n + 3) {
    border-top: 1px solid var(--line-soft);
  }

  .metric-cell.amount {
    grid-column: 1 / -1;
    border-right: 0;
  }

  .status-filter {
    width: 100%;
    overflow-x: auto;
  }

  .filter-button {
    flex: 1 0 auto;
  }

  .store-field,
  .store-field select,
  .search-field {
    width: 100%;
    min-width: 0;
  }

  .visible-count {
    padding-bottom: 0;
  }

  .table-wrap {
    max-height: none;
  }
}

@media (max-width: 420px) {
  h1 {
    font-size: 17px;
  }

  .brand-mark {
    width: 38px;
    height: 38px;
  }

  .dropzone {
    padding: 12px;
  }

  .upload-copy span {
    white-space: normal;
  }
}
