:root {
  color-scheme: light;
  --bg: #f4f7f3;
  --panel: #ffffff;
  --panel-muted: #eef4ea;
  --text: #15201b;
  --muted: #637068;
  --line: #dbe4dc;
  --accent: #0f8a5f;
  --accent-strong: #056447;
  --amber: #bc7a12;
  --danger: #b42318;
  --shadow: 0 18px 50px rgba(35, 52, 42, 0.12);
  --radius: 8px;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "Microsoft JhengHei", "Noto Sans TC", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(135deg, rgba(15, 138, 95, 0.12), transparent 32%),
    linear-gradient(315deg, rgba(188, 122, 18, 0.1), transparent 30%),
    var(--bg);
  color: var(--text);
}

button,
input,
select {
  font: inherit;
}

.app-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 32px 0;
  display: grid;
  gap: 18px;
}

.query-panel,
.result-panel,
.table-card,
.detail-card {
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid rgba(219, 228, 220, 0.92);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.query-panel {
  padding: 22px;
}

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

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent-strong);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(1.8rem, 4vw, 3rem);
  line-height: 1.05;
}

h2 {
  font-size: 1rem;
}

.icon-button,
.primary-button {
  border: 0;
  cursor: pointer;
  transition:
    transform 160ms ease,
    background 160ms ease,
    color 160ms ease;
}

.icon-button {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--panel-muted);
  color: var(--accent-strong);
  font-size: 1.25rem;
}

.icon-button:hover,
.primary-button:hover {
  transform: translateY(-1px);
}

.query-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 14px;
  align-items: end;
}

.field {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 650;
}

.field input,
.field select {
  min-height: 44px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--text);
  padding: 0 12px;
  outline: none;
}

.field input:focus,
.field select:focus {
  border-color: rgba(15, 138, 95, 0.8);
  box-shadow: 0 0 0 3px rgba(15, 138, 95, 0.14);
}

.direction-field {
  grid-column: span 2;
}

.segmented {
  min-height: 44px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  padding: 3px;
}

.segmented label {
  position: relative;
}

.segmented input {
  position: absolute;
  inset: 0;
  opacity: 0;
}

.segmented span {
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: 6px;
  color: var(--muted);
  cursor: pointer;
}

.segmented input:checked + span {
  background: var(--accent);
  color: #fff;
  font-weight: 750;
}

.primary-button {
  min-height: 44px;
  border-radius: var(--radius);
  background: var(--text);
  color: #fff;
  font-weight: 760;
}

.status-bar {
  margin-top: 14px;
  min-height: 28px;
  display: flex;
  align-items: center;
  color: var(--muted);
  font-size: 0.86rem;
}

.status-bar.error {
  color: var(--danger);
}

.result-panel {
  padding: 18px;
  display: grid;
  gap: 16px;
  min-width: 0;
}

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

.summary-strip article {
  min-height: 92px;
  display: grid;
  align-content: center;
  gap: 8px;
  padding: 16px;
  border-radius: var(--radius);
  background: var(--panel-muted);
  border: 1px solid var(--line);
}

.summary-strip span {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 650;
}

.summary-strip strong {
  font-size: clamp(1.25rem, 3vw, 2rem);
  line-height: 1.1;
}

.tables-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.table-card,
.detail-card {
  padding: 16px;
  box-shadow: none;
  min-width: 0;
}

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

.table-heading span {
  color: var(--muted);
  font-size: 0.78rem;
}

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

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 560px;
}

th,
td {
  padding: 11px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  font-size: 0.88rem;
}

th {
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 750;
  text-transform: uppercase;
}

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

.rate {
  color: var(--accent-strong);
  font-weight: 800;
  white-space: nowrap;
}

.subtle {
  color: var(--muted);
  font-size: 0.78rem;
}

.pill-row {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 0 7px;
  border-radius: 999px;
  background: #eef2f0;
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 650;
}

.empty-row {
  color: var(--muted);
  text-align: center;
}

@media (max-width: 900px) {
  .query-grid,
  .tables-grid,
  .summary-strip {
    grid-template-columns: 1fr;
  }

  .direction-field {
    grid-column: auto;
  }
}

@media (max-width: 520px) {
  .app-shell {
    width: min(100% - 20px, 1180px);
    padding: 16px 0;
  }

  .query-panel,
  .result-panel,
  .table-card,
  .detail-card {
    padding: 14px;
  }

  .title-row {
    align-items: flex-start;
  }
}
