:root {
  --bg: #f7f5ef;
  --surface: #ffffff;
  --ink: #1c1917;
  --muted: #6b6259;
  --line: #ded8cf;
  --green: #0f6f4a;
  --green-dark: #0a5137;
  --amber: #f6dc8b;
  --rose: #b42335;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family:
    "Noto Sans TC", "Microsoft JhengHei", "PingFang TC", Arial, sans-serif;
}

button,
input,
select {
  font: inherit;
}

a {
  color: var(--green);
  text-decoration-thickness: 1px;
  text-underline-offset: 4px;
}

.hero {
  position: relative;
  overflow: hidden;
  background: #111;
  color: #fff;
}

.hero__image,
.hero__shade {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.hero__image {
  object-fit: cover;
  opacity: 0.56;
}

.hero__shade {
  background: linear-gradient(90deg, #111 0%, rgb(17 17 17 / 86%) 42%, rgb(17 17 17 / 24%) 100%);
}

.hero__content {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 420px;
  gap: 28px;
  max-width: 1200px;
  min-height: 370px;
  margin: 0 auto;
  padding: 32px 24px;
  align-items: end;
}

.hero__copy {
  max-width: 680px;
}

.eyebrow {
  margin: 0 0 12px;
  color: #a7f3d0;
  font-size: 14px;
  font-weight: 700;
}

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

h1 {
  margin-bottom: 16px;
  font-size: clamp(34px, 5vw, 56px);
  line-height: 1.06;
}

.hero__copy > p:not(.eyebrow) {
  max-width: 620px;
  color: #f5f5f4;
  font-size: 17px;
  line-height: 1.75;
}

.hero__badges {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 20px;
}

.hero__badges span,
#rowCount {
  border: 1px solid rgb(255 255 255 / 26%);
  border-radius: 6px;
  background: rgb(255 255 255 / 12%);
  padding: 8px 10px;
  font-size: 14px;
}

.query-panel {
  display: grid;
  gap: 14px;
  border: 1px solid rgb(255 255 255 / 22%);
  border-radius: 8px;
  background: rgb(255 255 255 / 96%);
  padding: 18px;
  color: var(--ink);
  box-shadow: 0 18px 45px rgb(0 0 0 / 24%);
}

.access-panel {
  display: grid;
  gap: 14px;
  border: 1px solid rgb(255 255 255 / 22%);
  border-radius: 8px;
  background: rgb(255 255 255 / 96%);
  padding: 20px;
  color: var(--ink);
  box-shadow: 0 18px 45px rgb(0 0 0 / 24%);
}

.panel-kicker {
  margin-bottom: 8px;
  color: var(--green);
  font-size: 13px;
  font-weight: 800;
}

.access-panel h2 {
  margin-bottom: 8px;
}

.access-panel p:not(.panel-kicker) {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.6;
}

.access-panel button {
  background: var(--green);
  color: #fff;
}

.access-error {
  border-radius: 6px;
  background: #fff1f2;
  padding: 10px;
  color: var(--rose) !important;
  font-weight: 700;
}

body:not(.is-authorized) .query-panel,
body:not(.is-authorized) .locked-content {
  display: none;
}

body.is-authorized .access-panel {
  display: none;
}

label {
  display: grid;
  gap: 7px;
  font-size: 14px;
  font-weight: 700;
}

input,
select {
  width: 100%;
  min-height: 42px;
  border: 1px solid #cfc7bd;
  border-radius: 6px;
  background: #fff;
  padding: 0 11px;
  outline: none;
}

input:focus,
select:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgb(15 111 74 / 18%);
}

.query-panel__row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.checkbox-row {
  display: flex;
  grid-template-columns: none;
  align-items: center;
  gap: 8px;
  font-weight: 600;
}

.checkbox-row input {
  width: 18px;
  min-height: 18px;
}

.query-panel__actions {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 10px;
}

button {
  min-height: 42px;
  border: 0;
  border-radius: 6px;
  padding: 0 16px;
  cursor: pointer;
  font-weight: 800;
}

#searchButton {
  background: var(--green);
  color: #fff;
}

#searchButton:hover {
  background: var(--green-dark);
}

#clearButton {
  border: 1px solid #cfc7bd;
  background: #fff;
  color: #53483f;
}

#logoutButton {
  border: 1px solid #cfc7bd;
  background: #f8f5ef;
  color: #53483f;
}

.source-bar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  padding: 15px max(24px, calc((100vw - 1200px) / 2 + 24px));
  color: var(--muted);
  font-size: 14px;
}

.source-bar p {
  margin: 0;
}

.metrics,
.content-grid {
  max-width: 1200px;
  margin: 0 auto;
  padding-inline: 24px;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  padding-top: 22px;
  padding-bottom: 18px;
}

.metrics article,
.table-card,
.insight-column section {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 1px 2px rgb(0 0 0 / 4%);
}

.metrics article {
  padding: 16px;
}

.metrics span,
dt {
  color: var(--muted);
  font-size: 13px;
}

.metrics strong {
  display: block;
  margin-top: 8px;
  font-size: 24px;
}

.metrics small {
  display: block;
  margin-top: 5px;
  color: var(--muted);
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 18px;
  padding-bottom: 42px;
}

.content-grid > *,
.table-card {
  min-width: 0;
}

.table-card {
  overflow: hidden;
}

.section-heading {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  border-bottom: 1px solid var(--line);
  padding: 16px;
}

.section-heading h2,
.insight-column h2 {
  margin-bottom: 4px;
  font-size: 18px;
}

.section-heading p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

#rowCount {
  border-color: #ead28a;
  background: #fff6d8;
  color: #6d4c05;
  white-space: nowrap;
}

.message {
  margin: 16px;
  border: 1px dashed #cfc7bd;
  border-radius: 8px;
  padding: 22px;
  text-align: center;
  color: var(--muted);
}

.table-wrap {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  overscroll-behavior-x: contain;
}

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

th,
td {
  border-top: 1px solid #eee8df;
  padding: 11px 12px;
  text-align: left;
  white-space: nowrap;
}

th:nth-child(1),
td:nth-child(1) {
  width: 112px;
}

th:nth-child(2),
td:nth-child(2) {
  width: 158px;
}

th:nth-child(3),
td:nth-child(3) {
  width: 96px;
}

th:nth-child(4),
td:nth-child(4),
th:nth-child(5),
td:nth-child(5),
th:nth-child(6),
td:nth-child(6) {
  width: 76px;
}

th:nth-child(7),
td:nth-child(7) {
  width: 86px;
}

th:nth-child(8),
td:nth-child(8) {
  width: 100px;
}

thead th {
  border-top: 0;
  background: #f5f1ea;
  color: var(--muted);
  font-weight: 800;
}

tbody tr:hover {
  background: #ecfdf3;
}

.num {
  text-align: right;
}

.avg {
  color: var(--green-dark);
  font-weight: 800;
}

.insight-column {
  display: grid;
  gap: 14px;
  align-content: start;
}

.insight-column section {
  padding: 16px;
}

dl {
  display: grid;
  gap: 12px;
  margin: 14px 0 0;
}

dl div {
  display: flex;
  justify-content: space-between;
  gap: 14px;
}

dd {
  margin: 0;
  text-align: right;
  font-weight: 700;
}

.insight-column p {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.7;
}

.substitute-list {
  display: grid;
  gap: 10px;
  margin: 14px 0 0;
  padding-left: 18px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.55;
}

.substitute-list strong {
  color: var(--ink);
}

@media (max-width: 920px) {
  .hero__content,
  .content-grid,
  .source-bar {
    grid-template-columns: 1fr;
  }

  .metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 620px) {
  .hero__content,
  .metrics,
  .content-grid {
    padding-inline: 16px;
  }

  .hero__content,
  .query-panel__row,
  .query-panel__actions,
  .metrics {
    grid-template-columns: 1fr;
  }

  h1 {
    font-size: 34px;
  }
}
