:root {
  --bg: #f4f4f2;
  --panel: #ffffff;
  --panel-2: #f8faf9;
  --text: #1d2522;
  --muted: #63716b;
  --line: #ccd6d1;
  --line-dark: #1f2a26;
  --accent: #0f766e;
  --accent-dark: #0b5e57;
  --danger: #b42318;
  --shadow: 0 16px 40px rgba(23, 31, 27, 0.08);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family:
    "Microsoft YaHei", "PingFang SC", "Noto Sans SC", Arial, sans-serif;
}

button,
input,
textarea {
  font: inherit;
}

button {
  align-items: center;
  border: 1px solid transparent;
  border-radius: 6px;
  cursor: pointer;
  display: inline-flex;
  gap: 8px;
  height: 36px;
  justify-content: center;
  padding: 0 12px;
  white-space: nowrap;
}

button svg {
  height: 17px;
  width: 17px;
}

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

.primary {
  background: var(--accent);
  color: #fff;
}

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

.secondary {
  background: #fff;
  border-color: var(--line);
  color: var(--text);
}

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

.ghost {
  background: transparent;
  color: var(--danger);
}

.ghost:hover {
  background: #fff1ef;
}

.wide {
  width: 100%;
}

.controls-row {
  display: grid;
  gap: 8px;
}

.app-shell {
  margin: 0 auto;
  max-width: 1500px;
  padding: 20px;
}

.topbar {
  align-items: center;
  display: flex;
  justify-content: space-between;
  margin-bottom: 16px;
}

.topbar h1 {
  font-size: 24px;
  line-height: 1.2;
  margin: 0 0 4px;
}

.topbar p {
  color: var(--muted);
  margin: 0;
}

.topbar-actions,
.toolbar-group {
  display: flex;
  gap: 10px;
}

.workspace {
  display: grid;
  gap: 16px;
  grid-template-columns: 300px minmax(560px, 1fr) 360px;
  height: calc(100vh - 104px);
  min-height: calc(100vh - 104px);
}

.source-panel,
.table-panel,
.ocr-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.source-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 14px;
}

.upload-zone {
  align-items: center;
  background: var(--panel-2);
  border: 1px dashed #9aaba4;
  border-radius: 8px;
  cursor: pointer;
  display: grid;
  gap: 4px;
  min-height: 104px;
  padding: 14px;
  text-align: center;
}

.upload-zone.dragover {
  background: #e9f5f2;
  border-color: var(--accent);
}

.upload-zone input {
  display: none;
}

.upload-icon {
  color: var(--accent);
  display: inline-flex;
  justify-content: center;
}

.upload-icon svg {
  height: 26px;
  width: 26px;
}

.upload-title {
  font-size: 16px;
  font-weight: 700;
}

.upload-file {
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.image-frame {
  align-items: center;
  background: #111a17;
  border-radius: 6px;
  display: flex;
  height: 260px;
  justify-content: center;
  overflow: hidden;
  position: relative;
}

.image-frame img {
  display: none;
  height: 100%;
  object-fit: contain;
  width: 100%;
}

.image-frame.has-image img {
  display: block;
}

.empty-preview {
  color: #b9c5c0;
}

.image-frame.has-image .empty-preview {
  display: none;
}

.field-label {
  color: var(--muted);
  font-size: 13px;
  margin-bottom: -6px;
}

.text-input {
  border: 1px solid var(--line);
  border-radius: 6px;
  height: 36px;
  padding: 0 10px;
  width: 100%;
}

.progress-shell {
  background: #e5ebe8;
  border-radius: 999px;
  height: 8px;
  overflow: hidden;
}

.progress-bar {
  background: var(--accent);
  height: 100%;
  transition: width 180ms ease;
  width: 0;
}

.table-panel,
.ocr-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
}

.panel-toolbar {
  align-items: center;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  min-height: 54px;
  padding: 10px 12px;
}

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

.summary-strip {
  color: var(--muted);
  display: flex;
  gap: 18px;
}

.summary-strip strong {
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.table-wrap {
  flex: 1;
  min-height: 0;
  overflow: auto;
}

table {
  border-collapse: collapse;
  min-width: 690px;
  table-layout: fixed;
  width: 100%;
}

th,
td {
  border: 1px solid var(--line-dark);
  height: 40px;
  padding: 0;
}

th {
  background: #f2f5f3;
  font-size: 14px;
  font-weight: 700;
  position: sticky;
  top: 0;
  z-index: 2;
  text-align: center;
}

tfoot td {
  background: #f7faf8;
  border: 1px solid var(--line-dark);
  bottom: 0;
  font-weight: 700;
  height: 40px;
  position: sticky;
  text-align: center;
  z-index: 2;
}

tfoot td:nth-child(4),
tfoot td:nth-child(6) {
  font-variant-numeric: tabular-nums;
  text-align: right;
  padding-right: 8px;
}

td input {
  border: 0;
  height: 100%;
  outline: 0;
  padding: 0 8px;
  text-align: center;
  width: 100%;
}

td input.numeric {
  font-variant-numeric: tabular-nums;
  text-align: right;
}

td:last-child {
  text-align: center;
  width: 56px;
}

th:nth-child(1),
td:nth-child(1) {
  width: 112px;
}

th:nth-child(2),
td:nth-child(2) {
  width: 142px;
}

th:nth-child(3),
td:nth-child(3) {
  width: 128px;
}

th:nth-child(4),
td:nth-child(4) {
  width: 72px;
}

th:nth-child(5),
td:nth-child(5) {
  width: 86px;
}

th:nth-child(6),
td:nth-child(6) {
  width: 112px;
}

.row-delete {
  background: transparent;
  color: var(--danger);
  height: 32px;
  padding: 0;
  width: 32px;
}

.row-delete:hover {
  background: #fff1ef;
}

#ocrText {
  border: 0;
  flex: 1;
  min-height: 280px;
  outline: 0;
  padding: 12px;
  resize: none;
  width: 100%;
}

@media (max-width: 1180px) {
  .workspace {
    grid-template-columns: 280px minmax(540px, 1fr);
  }

  .ocr-panel {
    grid-column: 1 / -1;
    min-height: 260px;
  }
}

@media (max-width: 820px) {
  .app-shell {
    padding: 12px;
  }

  .topbar {
    align-items: stretch;
    gap: 12px;
    flex-direction: column;
  }

  .topbar-actions,
  .toolbar-group,
  .panel-toolbar {
    align-items: stretch;
    flex-wrap: wrap;
  }

  .workspace {
    grid-template-columns: 1fr;
    height: auto;
    min-height: 0;
  }

  .table-wrap {
    max-height: 70vh;
  }

  .source-panel,
  .table-panel,
  .ocr-panel {
    box-shadow: none;
  }
}
