:root {
  color-scheme: light;
  --bg: #f4f7f6;
  --surface: #ffffff;
  --surface-2: #eef5f3;
  --text: #17211e;
  --muted: #65746f;
  --border: #d9e3df;
  --accent: #0d7c66;
  --accent-2: #246bfe;
  --accent-soft: #e5f5ef;
  --warn: #a35a00;
  --danger: #b3261e;
  --shadow: 0 16px 40px rgba(22, 39, 33, 0.08);
  --radius: 8px;
  font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--text);
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

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

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 22px 32px;
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 10;
}

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

.brand-mark {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  flex: 0 0 44px;
  border-radius: var(--radius);
  color: #ffffff;
  background: linear-gradient(135deg, #0d7c66, #246bfe);
  box-shadow: 0 12px 28px rgba(13, 124, 102, 0.22);
}

.brand-mark svg,
button svg,
.field-icon {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

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

.brand p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.status-strip {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 36px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--muted);
  font-size: 13px;
}

.status-strip strong {
  color: var(--text);
  font-size: 13px;
}

.workspace {
  width: min(1480px, calc(100% - 40px));
  margin: 0 auto;
  padding: 28px 0 40px;
}

.search-panel {
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.search-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
}

.query-box {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fbfdfc;
  color: var(--muted);
}

.query-box:focus-within {
  border-color: rgba(13, 124, 102, 0.55);
  box-shadow: 0 0 0 4px rgba(13, 124, 102, 0.11);
}

.query-box input {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font-size: 16px;
}

.primary-button,
.ghost-button,
.copy-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  font-size: 14px;
  font-weight: 700;
}

.primary-button {
  min-width: 112px;
  min-height: 48px;
  padding: 0 18px;
  background: var(--accent);
  color: #ffffff;
}

.primary-button:hover {
  background: #086e59;
}

.ghost-button,
.copy-button {
  padding: 0 12px;
  border-color: var(--border);
  background: #ffffff;
  color: var(--text);
}

.ghost-button:hover,
.copy-button:hover {
  border-color: rgba(13, 124, 102, 0.45);
  color: var(--accent);
}

.ghost-button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.control-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  margin-top: 14px;
}

.select-control,
.check-control {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  color: var(--muted);
  font-size: 14px;
}

.select-control select {
  height: 38px;
  padding: 0 34px 0 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #ffffff;
  color: var(--text);
}

.check-control input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.example-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.example-row button {
  min-height: 34px;
  padding: 0 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--accent-soft);
  color: #115b4f;
  font-size: 13px;
  font-weight: 650;
}

.example-row button:hover {
  border-color: rgba(13, 124, 102, 0.5);
  background: #d9f0e8;
}

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

.summary-band > div {
  min-height: 66px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.summary-label {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.summary-band strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 18px;
  line-height: 1.25;
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.result-panel {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.result-panel {
  min-width: 0;
  overflow: hidden;
}

.table-wrap {
  overflow: auto;
  max-height: calc(100vh - 250px);
}

table {
  width: 100%;
  min-width: 1080px;
  border-collapse: separate;
  border-spacing: 0;
}

th,
td {
  border-bottom: 1px solid var(--border);
  padding: 11px 12px;
  text-align: left;
  vertical-align: top;
}

th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #f8fbfa;
  color: #42514d;
  font-size: 12px;
  font-weight: 800;
}

td {
  font-size: 13px;
  line-height: 1.4;
}

tbody tr:hover td {
  background: #fbfdfc;
}

.rank-col {
  width: 46px;
}

.score-col {
  width: 92px;
}

.code-col {
  width: 142px;
}

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

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

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

.unit-col {
  width: 62px;
}

.action-col {
  width: 92px;
}

.score-stack {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.confidence {
  width: fit-content;
  min-width: 34px;
  padding: 2px 7px;
  border-radius: var(--radius);
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
}

.confidence.low {
  background: #fff0df;
  color: var(--warn);
}

.confidence.medium {
  background: #edf4ff;
  color: var(--accent-2);
}

.code-copy-button {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 0;
  border: 0;
  background: transparent;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 13px;
  color: #14201c;
  font-weight: 700;
  text-align: left;
}

.code-copy-button:hover,
.code-copy-button:focus-visible {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.code-copy-button:focus-visible {
  outline: 2px solid rgba(13, 124, 102, 0.35);
  outline-offset: 3px;
}

.name-cell strong {
  display: block;
  margin-bottom: 5px;
  font-size: 14px;
  line-height: 1.35;
}

.reason-text {
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
  display: -webkit-box;
  overflow: hidden;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
}

.empty-state {
  height: 180px;
  color: var(--muted);
  text-align: center;
  vertical-align: middle;
}

.empty-note {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 20;
  max-width: min(420px, calc(100vw - 40px));
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #13211d;
  color: #ffffff;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
  font-size: 13px;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}

@media (max-width: 980px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .workspace {
    width: min(100% - 24px, 1480px);
  }

  .search-form,
  .content-grid,
  .summary-band {
    grid-template-columns: 1fr;
  }

  .primary-button {
    width: 100%;
  }

  .table-wrap {
    max-height: none;
  }
}

@media (max-width: 560px) {
  .topbar {
    padding: 18px 16px;
  }

  .brand {
    align-items: flex-start;
  }

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

  .control-row {
    align-items: stretch;
    flex-direction: column;
  }

  .select-control,
  .check-control,
  .ghost-button {
    width: 100%;
  }
}

@media (max-width: 700px) {
  .result-panel {
    overflow: visible;
  }

  .table-wrap {
    overflow: visible;
  }

  table,
  thead,
  tbody,
  tr,
  th,
  td {
    display: block;
    width: 100%;
    min-width: 0;
  }

  table {
    border-collapse: collapse;
  }

  thead {
    display: none;
  }

  tbody tr {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
  }

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

  td {
    display: grid;
    grid-template-columns: 88px minmax(0, 1fr);
    gap: 12px;
    min-height: 30px;
    padding: 6px 0;
    border-bottom: 0;
  }

  td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
  }

  td.name-cell {
    display: block;
  }

  td.name-cell::before {
    display: block;
    margin-bottom: 6px;
  }

  .score-stack {
    align-items: flex-start;
    flex-direction: row;
  }

  .copy-button {
    width: 44px;
  }

  .empty-state {
    display: block;
    height: auto;
    padding: 60px 16px;
    text-align: center;
  }

  .empty-state::before {
    content: "";
  }
}
