:root {
  --bg: #f7f8fb;
  --panel: #ffffff;
  --ink: #172033;
  --muted: #667085;
  --line: #d8dee9;
  --accent: #0f766e;
  --accent-strong: #0b5f59;
  --danger: #b42318;
  --warning: #b54708;
  --shadow: 0 18px 50px rgba(23, 32, 51, 0.08);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  overflow-x: hidden;
}

a {
  color: var(--accent);
  text-decoration: none;
}

.app-shell {
  width: min(1280px, calc(100vw - 48px));
  margin: 0 auto;
  padding: 32px 0 48px;
}

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

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

.brand-title img {
  width: 38px;
  height: 38px;
  flex: 0 0 auto;
  border-radius: 10px;
  box-shadow: 0 10px 24px rgba(15, 118, 110, 0.18);
}

.topbar h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 900;
  line-height: 1.15;
  letter-spacing: 0;
}

.topbar p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.top-link,
.downloads a,
button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 700;
  line-height: 1;
}

.top-link,
.downloads a {
  border: 1px solid var(--line);
  background: var(--panel);
  padding: 0 14px;
}

.top-link:hover {
  border-color: rgba(15, 118, 110, 0.42);
  background: rgba(15, 118, 110, 0.07);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(480px, 520px) minmax(520px, 1fr);
  gap: 22px;
  align-items: start;
}

.upload-panel,
.result-panel,
.empty-panel {
  min-width: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.upload-panel {
  position: sticky;
  top: 18px;
  padding: 20px;
}

.privacy-note {
  border: 1px solid rgba(15, 118, 110, 0.24);
  border-radius: 8px;
  background: rgba(15, 118, 110, 0.08);
  color: var(--accent-strong);
  font-size: 13px;
  font-weight: 700;
  line-height: 1.55;
  padding: 11px 12px;
  margin-bottom: 16px;
}

.field {
  display: grid;
  gap: 8px;
  margin-bottom: 16px;
}

.field-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.field label,
.controls label {
  color: #2a3447;
  font-size: 14px;
  font-weight: 700;
}

.field span {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

input[type="file"],
input[type="number"],
select {
  width: 100%;
  min-width: 0;
  max-width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfe;
  color: var(--ink);
  font: inherit;
}

input[type="file"] {
  display: block;
  overflow: hidden;
  min-height: 46px;
  padding: 10px;
  font-size: 14px;
}

input[type="number"],
select {
  height: 40px;
  padding: 0 10px;
  margin-top: 6px;
}

.controls {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin: 8px 0 14px;
}

.toggles {
  display: grid;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 16px;
}

.toggles label {
  display: flex;
  align-items: center;
  gap: 8px;
}

button {
  width: 100%;
  min-width: 0;
  border: 0;
  background: var(--accent);
  color: white;
  cursor: pointer;
  min-height: 46px;
}

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

button:disabled {
  cursor: wait;
  opacity: 0.68;
}

.status-line {
  min-height: 20px;
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.result-panel,
.empty-panel {
  padding: 18px;
}

.result-panel {
  position: sticky;
  top: 18px;
  max-height: calc(100vh - 132px);
  overflow-y: auto;
  overscroll-behavior: contain;
}

.result-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.result-header h2 {
  margin: 0;
  font-size: 22px;
  line-height: 1.25;
}

.result-header p {
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.matched-card {
  border: 1px solid rgba(15, 118, 110, 0.22);
  border-radius: 8px;
  background: rgba(15, 118, 110, 0.07);
  padding: 14px;
  margin-bottom: 14px;
}

.matched-card h3 {
  margin: 0 0 10px;
  font-size: 15px;
  line-height: 1.25;
}

.name-list {
  display: grid;
  gap: 8px;
  margin: 0;
  padding-left: 22px;
  color: var(--accent-strong);
  font-size: 14px;
  font-weight: 800;
  line-height: 1.35;
}

.name-list li {
  overflow-wrap: anywhere;
}

.name-list .empty-name {
  color: var(--muted);
  font-weight: 700;
}

.empty-panel {
  min-height: 520px;
  display: grid;
  place-items: center;
}

.empty-state {
  max-width: 420px;
  text-align: center;
}

.empty-state h2 {
  margin: 0;
  font-size: 22px;
  line-height: 1.25;
}

.empty-state p {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.7;
}

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

.summary-grid div {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #fbfcfe;
}

.summary-grid span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.2;
}

.summary-grid strong {
  display: block;
  margin-top: 8px;
  font-size: 26px;
  line-height: 1;
}

.downloads {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 16px 0;
}

.image-frame {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #eef2f7;
}

.image-frame img {
  display: block;
  width: 100%;
  height: auto;
}

.lists {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
  margin: 18px 0;
}

.lists h2 {
  margin: 0 0 10px;
  font-size: 16px;
  line-height: 1.2;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chips span {
  max-width: 100%;
  overflow-wrap: anywhere;
  border: 1px solid rgba(15, 118, 110, 0.24);
  border-radius: 999px;
  background: rgba(15, 118, 110, 0.09);
  color: var(--accent-strong);
  padding: 7px 10px;
  font-size: 13px;
  font-weight: 700;
}

.chips.muted span {
  border-color: var(--line);
  background: #f4f6fa;
  color: var(--muted);
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

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

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 11px 12px;
  text-align: left;
  white-space: nowrap;
}

th {
  background: #f4f6fa;
  color: #354052;
  font-weight: 800;
}

tr:last-child td {
  border-bottom: 0;
}

tr[data-status="unknown"] td:nth-child(2) {
  color: var(--danger);
  font-weight: 800;
}

tr[data-status="ambiguous"] td:nth-child(2),
tr[data-status="duplicate_rejected"] td:nth-child(2) {
  color: var(--warning);
  font-weight: 800;
}

tr[data-status="matched"] td:nth-child(2) {
  color: var(--accent);
  font-weight: 800;
}

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

  .upload-panel {
    position: static;
  }

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

@media (max-width: 640px) {
  .app-shell {
    width: calc(100% - 20px);
    padding-top: 18px;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
    width: 100%;
    max-width: calc(100vw - 20px);
    min-width: 0;
  }

  .topbar h1 {
    font-size: 20px;
  }

  .topbar > div,
  .brand-title {
    width: 100%;
    max-width: calc(100vw - 20px);
    min-width: 0;
  }

  .topbar p {
    width: 100%;
    max-width: 100%;
    word-break: break-all;
  }

  .upload-panel,
  .result-panel {
    width: 100%;
    max-width: calc(100vw - 20px);
    overflow: hidden;
    padding: 16px 12px;
  }

  input[type="file"] {
    max-width: calc(100vw - 48px);
  }

  .controls,
  .summary-grid,
  .lists {
    grid-template-columns: 1fr;
  }
}
