:root {
  color-scheme: light;
  --bg: #f5f7f8;
  --panel: #ffffff;
  --panel-soft: #eef4f2;
  --line: #d7dedc;
  --text: #17211f;
  --muted: #64706d;
  --primary: #19705f;
  --primary-strong: #0f5b4c;
  --accent: #b46b2a;
  --warning: #b7791f;
  --danger: #b42318;
  --ok: #147a3d;
  --shadow: 0 10px 30px rgba(23, 33, 31, 0.08);
}

* {
  box-sizing: border-box;
}

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

button,
input,
textarea,
select {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

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

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 22px 28px;
  border-bottom: 1px solid var(--line);
  background: #ffffff;
}

.app-header h1 {
  margin: 0 0 6px;
  font-size: 24px;
  line-height: 1.2;
}

.app-header p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.header-actions,
.toolbar,
.button-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.app-download-link {
  text-decoration: none;
}

.layout {
  display: grid;
  grid-template-columns: minmax(300px, 360px) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
  width: 100%;
  max-width: 100%;
  padding: 18px;
}

.input-panel {
  min-width: 0;
  display: grid;
  gap: 14px;
  align-content: start;
}

.panel {
  min-width: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 16px;
}

.panel-title {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}

.panel-title h2 {
  margin: 0;
  font-size: 16px;
}

.panel-title svg,
button svg {
  width: 18px;
  height: 18px;
  stroke-width: 2;
}

.file-drop {
  display: grid;
  gap: 5px;
  min-height: 84px;
  padding: 18px;
  place-items: center;
  border: 1px dashed #a7b5b1;
  border-radius: 8px;
  background: var(--panel-soft);
  text-align: center;
}

.file-drop input {
  width: 1px;
  height: 1px;
  opacity: 0;
  position: absolute;
}

.file-drop span {
  font-weight: 700;
  color: var(--primary-strong);
}

.file-drop small {
  color: var(--muted);
}

.mobile-photo-actions {
  display: none;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 10px;
}

.mobile-photo-actions input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.mobile-photo-actions button {
  min-height: 48px;
}

.is-mobile .mobile-photo-actions:not([hidden]) {
  display: grid;
}

.image-preview {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(116px, 1fr));
  gap: 10px;
  align-items: stretch;
  min-height: 140px;
  margin: 12px 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fafafa;
  color: var(--muted);
}

.image-preview > span {
  place-self: center;
  grid-column: 1 / -1;
}

.image-preview img {
  width: 100%;
  height: 104px;
  object-fit: contain;
}

.preview-card {
  display: grid;
  gap: 7px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.preview-meta {
  display: grid;
  gap: 2px;
}

.preview-meta strong,
.preview-name {
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.preview-meta strong {
  color: var(--text);
}

.preview-meta span {
  color: var(--muted);
  font-size: 12px;
}

.preview-actions {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
}

.preview-actions button {
  min-height: 30px;
  padding: 0 8px;
}

.danger-button {
  color: var(--danger);
  border-color: #efc0bb;
}

textarea {
  width: 100%;
  resize: vertical;
  min-height: 180px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
}

.compact-textarea {
  min-height: 92px;
  margin-bottom: 8px;
}

.field-label {
  display: block;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.select-input,
.text-input {
  width: 100%;
  min-height: 38px;
  margin-bottom: 8px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--text);
}

.field-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(120px, 0.55fr);
  gap: 10px;
}

.button-row {
  margin: 4px 0 12px;
}

.button-row button {
  flex: 1;
}

.catalog-meta {
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 13px;
}

progress {
  width: 100%;
  height: 10px;
  margin-top: 12px;
  accent-color: var(--primary);
}

.primary-button,
.secondary-button,
.ghost-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 38px;
  padding: 0 14px;
  border-radius: 8px;
  white-space: nowrap;
}

.primary-button {
  background: var(--primary);
  color: #ffffff;
}

.primary-button:hover {
  background: var(--primary-strong);
}

.secondary-button {
  background: #e8efed;
  color: var(--primary-strong);
  border: 1px solid #cad8d4;
}

.secondary-button:hover {
  background: #dce9e5;
}

.ghost-button {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
}

.wide {
  width: 100%;
}

.stat-line {
  display: flex;
  justify-content: space-between;
  margin-top: 12px;
  color: var(--muted);
}

.stat-line strong {
  color: var(--text);
}

.alias-list {
  display: grid;
  gap: 8px;
  margin-top: 12px;
  color: var(--muted);
  font-size: 13px;
}

.rule-editor-list {
  display: grid;
  gap: 10px;
}

.rule-edit-row {
  display: grid;
  gap: 10px;
  align-items: end;
}

.alias-edit-row {
  grid-template-columns: minmax(0, 1fr) minmax(120px, 0.55fr);
}

.unit-edit-row {
  grid-template-columns: minmax(120px, 1fr) minmax(80px, 0.55fr) minmax(96px, 0.65fr) minmax(70px, 0.45fr);
}

.rule-edit-row .field-label {
  margin-bottom: 5px;
}

.alias-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfc;
}

.alias-item strong {
  color: var(--text);
}

.small-button {
  min-height: 30px;
  padding: 0 9px;
}

.workspace {
  width: 100%;
  min-width: 0;
  display: grid;
  gap: 14px;
  align-content: start;
  overflow: hidden;
}

.summary-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(130px, 1fr));
  gap: 12px;
}

.summary-strip div {
  min-width: 0;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.summary-strip span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 6px;
}

.summary-strip strong {
  display: block;
  font-size: 22px;
  line-height: 1.1;
}

.toolbar {
  min-width: 0;
  justify-content: flex-end;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.catalog-editor-panel {
  min-width: 0;
  max-width: 100%;
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.catalog-editor-head {
  min-width: 0;
  display: grid;
  grid-template-columns: auto minmax(180px, 1fr) auto auto;
  gap: 10px;
  align-items: center;
}

.catalog-editor-head > * {
  min-width: 0;
}

.product-search {
  margin-bottom: 0;
}

.product-editor-wrap {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  max-height: 360px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.ocr-review-wrap {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  max-height: 320px;
  overflow: auto;
  margin-bottom: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.ocr-review-table {
  min-width: 900px;
}

.ocr-review-table th,
.ocr-review-table td {
  padding: 8px;
}

.ocr-review-warning {
  background: #fff8ea;
}

.ocr-name-input {
  min-width: 220px;
}

.ocr-quantity-input {
  min-width: 82px;
}

.ocr-unit-input {
  min-width: 70px;
}

.ocr-raw-input {
  min-width: 240px;
}

.ocr-hint-cell {
  min-width: 160px;
  color: var(--warning);
  font-size: 13px;
  line-height: 1.4;
}

.product-editor-table {
  min-width: 980px;
  box-shadow: none;
}

.product-editor-table th,
.product-editor-table td {
  padding: 8px;
}

.product-name-edit {
  min-width: 260px;
}

.unit-edit {
  min-width: 72px;
}

.price-edit {
  min-width: 100px;
}

.category-edit,
.source-edit {
  min-width: 150px;
}

.table-wrap {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

table {
  width: 100%;
  min-width: 1680px;
  border-collapse: collapse;
}

th,
td {
  padding: 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
  font-size: 14px;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f0f5f3;
  color: #2b3936;
  font-weight: 700;
}

tbody tr:hover {
  background: #fafcfb;
}

.unmatched-row {
  background: #fff0ee;
}

.unmatched-row:hover {
  background: #ffe5e1;
}

.unmatched-row td {
  color: #8f1d16;
}

.unmatched-row .table-input {
  border-color: #e7a19a;
  background: #fff9f8;
}

.empty-cell {
  height: 220px;
  text-align: center;
  color: var(--muted);
}

.table-input {
  width: 100%;
  min-width: 90px;
  padding: 8px;
  border: 1px solid #cfd8d5;
  border-radius: 6px;
  background: #ffffff;
}

.name-input {
  min-width: 190px;
}

.product-input {
  min-width: 260px;
}

.amount-cell {
  font-weight: 700;
}

.conversion-cell {
  color: var(--muted);
  min-width: 150px;
}

.merge-cell {
  min-width: 120px;
  color: var(--primary-strong);
  font-size: 13px;
}

.reason-cell {
  min-width: 230px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.suggestion-line {
  display: block;
  margin-top: 5px;
  color: var(--warning);
  font-size: 12px;
  line-height: 1.35;
}

.row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-width: 190px;
}

.row-actions button {
  min-height: 30px;
  padding: 0 9px;
}

.history-panel {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.history-head {
  display: grid;
  grid-template-columns: auto minmax(180px, 320px);
  gap: 12px;
  align-items: center;
}

.history-search {
  margin-bottom: 0;
}

.history-list {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.history-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfc;
}

.history-item strong {
  color: var(--text);
}

.history-actions {
  display: flex;
  gap: 6px;
}

.badge {
  display: inline-flex;
  min-width: 76px;
  justify-content: center;
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}

.badge-ok {
  color: var(--ok);
  background: #e4f5eb;
}

.badge-review {
  color: var(--warning);
  background: #fff3d6;
}

.badge-miss {
  color: var(--danger);
  background: #ffe8e5;
}

.score-cell {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

@media (max-width: 1280px) {
  .app-header {
    align-items: flex-start;
    flex-direction: column;
  }

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

@media (max-width: 980px) {

  .summary-strip {
    grid-template-columns: repeat(2, minmax(140px, 1fr));
  }

  .catalog-editor-head {
    grid-template-columns: 1fr 1fr;
  }

  .catalog-editor-head strong,
  .catalog-editor-head .product-search {
    grid-column: 1 / -1;
  }
}

@media (max-width: 560px) {
  .app-header,
  .layout {
    padding: 14px;
  }

  .header-actions,
  .toolbar,
  .button-row {
    width: 100%;
  }

  .header-actions button,
  .toolbar button,
  .button-row button {
    flex: 1;
  }

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

  .alias-edit-row,
  .unit-edit-row {
    grid-template-columns: 1fr;
  }

  .summary-strip {
    grid-template-columns: 1fr;
  }

  .history-head,
  .history-item,
  .catalog-editor-head {
    grid-template-columns: 1fr;
  }

  .mobile-photo-actions:not([hidden]) {
    display: grid;
  }
}
