:root {
  color-scheme: light;
  --bg: #f5f7f6;
  --surface: #ffffff;
  --surface-strong: #fdfaf4;
  --text: #17201d;
  --muted: #66736d;
  --line: #dce4df;
  --green: #0f8a61;
  --red: #c54848;
  --gold: #b27a18;
  --blue: #256f9d;
  --shadow: 0 12px 30px rgba(25, 35, 31, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family:
    "Noto Sans TC",
    "Microsoft JhengHei",
    system-ui,
    -apple-system,
    sans-serif;
}

.app-header {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(520px, auto);
  gap: 20px;
  align-items: end;
  padding: 28px clamp(18px, 4vw, 48px) 22px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--green);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 28px;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 0;
  font-size: 20px;
  letter-spacing: 0;
}

.query-bar {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
  align-items: end;
}

.field {
  display: grid;
  gap: 6px;
  min-width: 170px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.select-field {
  min-width: 150px;
}

input,
select,
button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
}

input,
select {
  padding: 0 12px;
}

button {
  padding: 0 14px;
  cursor: pointer;
  font-weight: 800;
}

button:hover {
  border-color: #9fb3aa;
}

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

main {
  width: min(1120px, calc(100% - 32px));
  margin: 24px auto 40px;
}

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

.list-panel {
  padding: 22px;
}

.panel-head,
.section-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: start;
  margin-bottom: 18px;
}

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

.list-output {
  min-height: 148px;
  padding: 18px;
  border-radius: 8px;
  background: var(--surface-strong);
  border: 1px solid #eadfc8;
  white-space: pre-wrap;
  line-height: 1.85;
  font-size: 18px;
  font-weight: 700;
}

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

.metrics div {
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.metrics span {
  display: block;
  margin-bottom: 4px;
  font-size: 30px;
  font-weight: 900;
}

.metrics div:nth-child(1) span {
  color: var(--green);
}

.metrics div:nth-child(2) span {
  color: var(--red);
}

.metrics div:nth-child(3) span {
  color: var(--red);
}

.metrics div:nth-child(4) span {
  color: var(--gold);
}

.metrics p {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

.details {
  padding: 0;
  overflow: hidden;
}

.section-head {
  padding: 18px 18px 0;
  margin-bottom: 14px;
}

.section-head p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  min-width: 860px;
  border-collapse: collapse;
  font-size: 14px;
}

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

th {
  background: #f0f5f2;
  color: #31413b;
  font-size: 13px;
  white-space: nowrap;
}

td {
  line-height: 1.5;
}

.tag {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 8px;
  border-radius: 8px;
  background: #eef4f1;
  color: #2f4a41;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.tag.in {
  background: #fff0ef;
  color: var(--red);
}

.tag.out {
  background: #edf8f3;
  color: var(--green);
}

.tag.next {
  background: #fff6df;
  color: var(--gold);
}

.tag.next-in {
  background: #fff0ef;
  color: var(--red);
}

.mapped-note {
  color: var(--blue);
  font-size: 12px;
  font-weight: 700;
}

.sources {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 16px;
  color: var(--muted);
  font-size: 13px;
}

.sources a {
  color: var(--blue);
  text-decoration: none;
  font-weight: 800;
}

.sources a:hover {
  text-decoration: underline;
}

.error {
  color: var(--red);
}

@media (max-width: 860px) {
  .app-header {
    grid-template-columns: 1fr;
    align-items: start;
  }

  .query-bar {
    justify-content: stretch;
  }

  .field,
  .select-field,
  .query-bar button {
    flex: 1 1 150px;
  }

  .metrics {
    grid-template-columns: 1fr;
  }

  .panel-head,
  .section-head {
    display: grid;
  }
}

@media (max-width: 560px) {
  h1 {
    font-size: 24px;
  }

  .app-header {
    padding: 22px 16px;
  }

  main {
    width: calc(100% - 20px);
    margin-top: 14px;
  }

  .list-panel {
    padding: 16px;
  }

  .list-output {
    padding: 14px;
    font-size: 16px;
  }
}
