:root {
  color-scheme: light;
  --bg: #edf2f7;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --line: #d6deea;
  --line-strong: #aebbd0;
  --text: #17202c;
  --muted: #617086;
  --brand: #2563eb;
  --brand-dark: #1d4ed8;
  --brand-soft: rgba(37, 99, 235, 0.12);
  --ok: #15803d;
  --warn: #b45309;
  --bad: #b91c1c;
  --shadow: 0 14px 30px rgba(20, 28, 42, 0.08);
}

* {
  box-sizing: border-box;
}

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

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
  padding: 24px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin: 0 auto 18px;
  max-width: 1480px;
}

.topbar h1 {
  margin: 0 0 6px;
  font-size: 26px;
  font-weight: 700;
  letter-spacing: 0;
}

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

.status-pill {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 14px;
  color: var(--muted);
  background: var(--surface);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(360px, 430px) minmax(0, 1fr);
  gap: 20px;
  max-width: 1480px;
  margin: 0 auto;
}

.panel,
.content-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.setup-panel {
  align-self: start;
  border-radius: 10px;
  padding: 18px;
}

.content-panel {
  min-width: 0;
  overflow: hidden;
  border-radius: 10px;
  padding: 18px;
  display: flex;
  flex-direction: column;
}

.section-block {
  padding: 0 0 18px;
  margin: 0 0 18px;
  border-bottom: 1px solid var(--line);
}

.section-block:last-child {
  padding-bottom: 0;
  margin-bottom: 0;
  border-bottom: 0;
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

h2 {
  margin: 0 0 12px;
  font-size: 16px;
  font-weight: 700;
}

.section-heading h2 {
  margin: 0;
}

.upload-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.upload-card {
  display: grid;
  gap: 8px;
  min-height: 166px;
  border: 1px dashed var(--line-strong);
  border-radius: 10px;
  padding: 14px;
  color: var(--muted);
  background: linear-gradient(180deg, #ffffff 0%, #f8fbff 100%);
  transition: border-color 0.15s ease, background-color 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease;
  position: relative;
}

.upload-card input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}

.upload-card strong {
  display: block;
  overflow: hidden;
  color: var(--text);
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.upload-card:hover,
.upload-card.drag-over {
  border-color: var(--brand);
  box-shadow: 0 10px 24px rgba(37, 99, 235, 0.14);
  transform: translateY(-1px);
  background: linear-gradient(180deg, #ffffff 0%, #f3f7ff 100%);
}

.upload-icon {
  display: inline-grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: var(--brand-soft);
  color: var(--brand);
}

.upload-icon svg,
.icon-button svg,
.remove-button svg,
.primary-button svg,
.secondary-button svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.upload-title {
  color: var(--text);
  font-weight: 700;
}

.upload-card small {
  color: var(--muted);
  line-height: 1.5;
}

.sheet-row,
.rule-row {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 10px;
  align-items: end;
}

.sheet-row {
  grid-template-columns: 1fr 1fr;
  margin-top: 12px;
}

label {
  display: grid;
  gap: 6px;
  min-width: 0;
  color: var(--muted);
  font-size: 13px;
}

select,
input[type="search"],
input[list] {
  width: 100%;
  min-width: 0;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 10px;
  color: var(--text);
  background: #fff;
}

.rules {
  display: grid;
  gap: 10px;
}

.icon-button,
.remove-button {
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  background: #fff;
}

.icon-button:hover,
.remove-button:hover,
.secondary-button:hover {
  border-color: var(--brand);
}

.remove-button {
  color: var(--bad);
  padding: 0;
}

.option-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px 14px;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
}

.check-row input {
  width: 16px;
  height: 16px;
}

.check-row span {
  cursor: help;
}

.button-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 16px;
}

.primary-button,
.secondary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  border-radius: 6px;
  padding: 0 14px;
  font-weight: 700;
}

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

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

.secondary-button {
  border: 1px solid var(--line-strong);
  color: var(--text);
  background: #fff;
}

.secondary-button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(120px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.summary-grid article {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: var(--surface-2);
}

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

.summary-grid strong {
  font-size: 24px;
}

.table-tools {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tab {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 12px;
  color: var(--muted);
  background: #fff;
}

.tab.active {
  border-color: var(--brand);
  color: #fff;
  background: var(--brand);
}

.table-tools input {
  max-width: 260px;
}

.table-wrap {
  width: 100%;
  min-width: 0;
  flex: 1 1 auto;
  min-height: 0;
  overflow-x: scroll;
  overflow-y: auto;
  scrollbar-gutter: stable both-edges;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

table {
  width: max-content;
  min-width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  table-layout: auto;
}

th,
td {
  min-width: 130px;
  max-width: 260px;
  border-bottom: 1px solid var(--line);
  border-right: 1px solid var(--line);
  padding: 8px 10px;
  text-align: left;
  vertical-align: top;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  color: var(--text);
  background: #eef4fb;
  font-weight: 700;
}

tbody tr:nth-child(even) td {
  background: #fbfcfe;
}

tr.status-hit td:first-child {
  border-left: 4px solid var(--ok);
}

tr.status-miss td:first-child {
  border-left: 4px solid var(--warn);
}

.empty-state {
  display: grid;
  place-items: center;
  min-height: 100%;
  padding: 30px;
  color: var(--muted);
  text-align: center;
}

.log-list {
  margin: 0;
  padding: 12px 18px;
}

.log-list li {
  margin: 0 0 8px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(15, 23, 42, 0.42);
}

.modal-backdrop[hidden] {
  display: none;
}

.modal-panel {
  width: min(520px, 100%);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 24px;
  text-align: center;
  background: var(--surface);
  box-shadow: 0 24px 60px rgba(15, 23, 42, 0.22);
}

.modal-icon {
  display: inline-grid;
  place-items: center;
  width: 48px;
  height: 48px;
  margin-bottom: 12px;
  border-radius: 999px;
  color: var(--ok);
  background: rgba(21, 128, 61, 0.12);
}

.modal-icon svg {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

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

.modal-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 20px;
}

.modal-stats article {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 10px;
  background: var(--surface-2);
}

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

.modal-stats strong {
  font-size: 18px;
}

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

  .table-wrap {
    min-height: 500px;
    max-height: none;
  }

  .empty-state {
    min-height: 420px;
  }
}

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

  .topbar,
  .table-tools {
    align-items: stretch;
    flex-direction: column;
  }

  .status-pill,
  .table-tools input {
    max-width: none;
  }

  .upload-grid,
  .sheet-row,
  .rule-row,
  .option-grid,
  .button-row,
  .summary-grid {
    grid-template-columns: 1fr;
  }

  .rule-row {
    align-items: stretch;
  }

  .remove-button {
    width: 100%;
  }

  .modal-stats {
    grid-template-columns: 1fr;
  }
}
