:root {
  color-scheme: light;
  --bg: #eef2f4;
  --surface: #ffffff;
  --surface-strong: #f7fafb;
  --line: #cfd8dc;
  --line-dark: #aebdc4;
  --text: #17252b;
  --muted: #60727b;
  --teal: #0f6f84;
  --teal-dark: #0a5364;
  --green: #1f8a58;
  --amber: #b87912;
  --danger: #b3261e;
  --shadow: 0 12px 36px rgba(34, 52, 61, 0.12);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  min-width: 320px;
  font-family: "Microsoft YaHei", "PingFang SC", "Segoe UI", Arial, sans-serif;
  color: var(--text);
  background: linear-gradient(180deg, #f8fafb 0%, var(--bg) 100%);
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
}

.app-shell {
  min-height: 100%;
  display: grid;
  grid-template-rows: auto auto 1fr auto;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(240px, 330px) 1fr;
  gap: 16px;
  align-items: center;
  padding: 12px 18px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  box-shadow: 0 4px 18px rgba(23, 37, 43, 0.08);
  z-index: 2;
}

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

.brand-mark {
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--teal);
  color: #fff;
  font-weight: 800;
  font-size: 14px;
  letter-spacing: 0;
  box-shadow: inset 0 -6px 0 rgba(0, 0, 0, 0.11);
}

.brand h1 {
  margin: 0;
  font-size: 22px;
  line-height: 1.18;
  letter-spacing: 0;
}

.brand p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  min-width: 0;
  flex-wrap: wrap;
}

#imageInput {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.tool-button,
.ghost-button {
  min-height: 36px;
  border-radius: 8px;
  border: 1px solid var(--line-dark);
  background: var(--surface);
  color: var(--text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 0 12px;
  white-space: nowrap;
  transition: background 120ms ease, border-color 120ms ease, transform 120ms ease, opacity 120ms ease;
}

.tool-button:hover:not(:disabled),
.ghost-button:hover:not(:disabled) {
  background: var(--surface-strong);
  border-color: #7f969f;
}

.tool-button:active:not(:disabled),
.ghost-button:active:not(:disabled) {
  transform: translateY(1px);
}

.tool-button:disabled,
.ghost-button:disabled {
  opacity: 0.5;
}

.tool-button.primary {
  background: var(--teal);
  border-color: var(--teal);
  color: #fff;
}

.tool-button.primary:hover {
  background: var(--teal-dark);
}

.tool-button.accent {
  background: var(--green);
  border-color: var(--green);
  color: #fff;
}

.tool-button.export-button {
  min-width: 76px;
}

.tool-icon {
  width: 18px;
  height: 18px;
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
}

.tool-icon svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.control {
  height: 36px;
  display: grid;
  grid-template-columns: auto minmax(96px, 1fr);
  align-items: center;
  gap: 7px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
}

.control label {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.control select,
.control input[type="number"] {
  min-width: 0;
  height: 28px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  padding: 0 8px;
}

.ratio-control {
  grid-template-columns: auto minmax(110px, 150px);
}

.ratio-control input {
  width: 100%;
}

.compact-control {
  grid-template-columns: auto 64px;
}

.recognition-progress {
  margin: 12px 18px 0;
  padding: 10px 12px;
  border: 1px solid rgba(15, 111, 132, 0.2);
  border-radius: 8px;
  background: #f7fbfc;
  box-shadow: 0 8px 24px rgba(23, 37, 43, 0.08);
}

.recognition-progress[hidden] {
  display: none;
}

.progress-copy {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 7px;
  color: var(--text);
}

.progress-copy strong {
  min-width: 0;
  font-size: 13px;
  letter-spacing: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.progress-copy span {
  color: var(--teal);
  font-weight: 700;
  font-size: 13px;
  white-space: nowrap;
}

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

.progress-bar {
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--teal), #18a0a8);
  transition: width 260ms ease, background 160ms ease;
}

.recognition-progress.complete {
  border-color: rgba(31, 138, 88, 0.28);
  background: #f3fbf7;
}

.recognition-progress.complete .progress-copy span {
  color: var(--green);
}

.recognition-progress.complete .progress-bar {
  background: linear-gradient(90deg, var(--green), #31ad72);
}

.recognition-progress.error {
  border-color: rgba(179, 38, 30, 0.28);
  background: #fff8f7;
}

.recognition-progress.error .progress-copy span {
  color: var(--danger);
}

.recognition-progress.error .progress-bar {
  background: linear-gradient(90deg, var(--danger), #d95a52);
}

.workspace {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(430px, 58%) minmax(380px, 42%);
  gap: 14px;
  padding: 14px 18px;
}

.preview-pane,
.table-pane {
  min-height: 0;
  display: grid;
  grid-template-rows: auto 1fr;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.pane-head {
  min-height: 54px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-strong);
}

.pane-head h2 {
  margin: 0;
  font-size: 16px;
  line-height: 1.25;
  letter-spacing: 0;
}

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

.run-badge {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 10px;
  border-radius: 999px;
  border: 1px solid var(--line-dark);
  background: #fff;
  color: var(--muted);
  white-space: nowrap;
}

.run-badge.ready {
  border-color: rgba(31, 138, 88, 0.35);
  background: rgba(31, 138, 88, 0.08);
  color: var(--green);
}

.preview-stage {
  position: relative;
  min-height: 0;
  overflow: auto;
  background:
    linear-gradient(45deg, rgba(15, 111, 132, 0.04) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(15, 111, 132, 0.04) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, rgba(15, 111, 132, 0.04) 75%),
    linear-gradient(-45deg, transparent 75%, rgba(15, 111, 132, 0.04) 75%);
  background-size: 24px 24px;
  background-position: 0 0, 0 12px, 12px -12px, -12px 0;
}

.preview-stage img {
  display: none;
  width: 100%;
  min-height: 100%;
  object-fit: contain;
  object-position: top left;
  background: #fff;
}

.preview-stage.has-image img {
  display: block;
}

.empty-preview {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 8px;
  text-align: center;
  color: var(--muted);
  padding: 24px;
}

.empty-preview strong {
  color: var(--text);
  font-size: 20px;
}

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

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

table {
  width: 100%;
  min-width: 920px;
  border-collapse: collapse;
  table-layout: fixed;
  font-size: 13px;
}

th,
td {
  border-bottom: 1px solid #d9e1e5;
  border-right: 1px solid #e3e9ec;
  padding: 5px 6px;
  vertical-align: middle;
  height: 34px;
  overflow: hidden;
  text-overflow: ellipsis;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #e8eef1;
  color: #263b44;
  font-size: 12px;
  font-weight: 700;
}

th:nth-child(1),
td:nth-child(1) {
  width: 54px;
  text-align: center;
}

th:nth-child(2),
td:nth-child(2),
th:nth-child(3),
td:nth-child(3),
th:nth-child(7),
td:nth-child(7),
th:nth-child(8),
td:nth-child(8),
th:nth-child(9),
td:nth-child(9),
th:nth-child(10),
td:nth-child(10) {
  width: 78px;
}

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

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

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

tbody tr:hover {
  background: #f3f8f9;
}

.empty-row td {
  height: 120px;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
}

.cell-input {
  width: 100%;
  height: 26px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  padding: 0 6px;
}

.cell-input:focus {
  outline: none;
  border-color: rgba(15, 111, 132, 0.55);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(15, 111, 132, 0.12);
}

.readonly-cell {
  color: #41545c;
}

.statusbar {
  min-height: 36px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 0 18px;
  border-top: 1px solid var(--line);
  background: #26353b;
  color: #eaf1f3;
  font-size: 13px;
}

.statusbar span:last-child {
  color: #c7d4d9;
}

.is-busy {
  opacity: 0.76;
  pointer-events: none;
}

.status-error {
  color: var(--danger);
}

.status-warn {
  color: var(--amber);
}

@media (max-width: 1180px) {
  .topbar {
    grid-template-columns: 1fr;
  }

  .toolbar {
    justify-content: flex-start;
  }

  .workspace {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(420px, 55vh) minmax(360px, 45vh);
  }
}

@media (max-width: 720px) {
  .topbar,
  .recognition-progress,
  .workspace {
    padding-left: 10px;
    padding-right: 10px;
  }

  .recognition-progress {
    margin-left: 10px;
    margin-right: 10px;
  }

  .brand h1 {
    font-size: 19px;
  }

  .toolbar {
    gap: 8px;
  }

  .toolbar .tool-button,
  .toolbar .control {
    min-width: 100%;
  }

  .pane-head {
    align-items: flex-start;
  }

  .pane-head > div {
    min-width: 0;
    flex: 1 1 auto;
  }

  .pane-head h2 {
    white-space: nowrap;
  }

  .pane-head .ghost-button {
    min-width: 72px;
    width: auto;
  }

  .ratio-control,
  .compact-control,
  .control {
    grid-template-columns: 72px 1fr;
  }

  .workspace {
    grid-template-rows: minmax(330px, 48vh) minmax(360px, 1fr);
  }

  .statusbar {
    align-items: flex-start;
    flex-direction: column;
    justify-content: center;
    padding-top: 7px;
    padding-bottom: 7px;
  }
}
