:root {
  --background: #101418;
  --surface: #171c21;
  --surface-raised: #1d2329;
  --border: #2d353d;
  --text: #f1f4f6;
  --muted: #929da7;
  --blue: #3697e8;
  --blue-soft: rgba(54, 151, 232, 0.14);
  --green: #30b987;
  --red: #ee6b72;
  --gold: #dfaa47;
  --focus: #8bc8f7;
}

* { box-sizing: border-box; }

html { background: var(--background); }

body {
  margin: 0;
  min-width: 320px;
  color: var(--text);
  background: var(--background);
  font-family: Inter, "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif;
  letter-spacing: 0;
}

button, input { font: inherit; letter-spacing: 0; }
button { color: inherit; }
button:focus-visible, input:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.topbar {
  min-height: 104px;
  padding: 24px clamp(20px, 4vw, 64px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  border-bottom: 1px solid var(--border);
  background: #13181d;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--gold);
  font-size: 11px;
  font-weight: 700;
}

h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: 26px; line-height: 1.2; }
h2 { margin-bottom: 5px; font-size: 18px; line-height: 1.3; }
.section-heading p, .surface-header p { margin-bottom: 0; color: var(--muted); font-size: 13px; }

.market-status {
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 0 4px rgba(48, 185, 135, 0.12);
}

main {
  width: min(1480px, 100%);
  margin: 0 auto;
  padding: 32px clamp(16px, 4vw, 56px) 56px;
}

.section-heading, .surface-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
}

.icon-button {
  width: 38px;
  height: 38px;
  border: 1px solid var(--border);
  background: transparent;
  border-radius: 6px;
  cursor: pointer;
  font-size: 22px;
}

.icon-button:hover, .text-button:hover, .command-button:hover, .pagination button:hover:not(:disabled) {
  border-color: #485560;
  background: var(--surface-raised);
}

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

.rate-card {
  min-height: 128px;
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
}

.rate-card-head, .rate-change {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.pair-name { color: #c8d0d7; font-size: 13px; font-weight: 700; }
.source { color: var(--muted); font-size: 11px; }
.rate-value { margin: 15px 0 12px; font: 600 25px/1.1 ui-monospace, SFMono-Regular, Menlo, monospace; }
.rate-change { color: var(--muted); font-size: 12px; }
.up { color: var(--green) !important; }
.down { color: var(--red) !important; }
.flat { color: var(--muted) !important; }

.surface {
  margin-top: 28px;
  border-top: 1px solid var(--border);
  padding-top: 26px;
}

.toolbar, .filters, .pair-toolbar, .filter-group {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.segmented {
  display: inline-grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(62px, auto);
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #12171b;
}

.segmented button {
  min-height: 30px;
  padding: 0 10px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
}

.segmented button.active { background: var(--blue); color: white; }
.segmented button:disabled { opacity: 0.35; cursor: not-allowed; }

.pair-toolbar {
  min-height: 48px;
  margin-top: 18px;
  padding: 9px 0;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}

.control-label { color: var(--muted); font-size: 12px; font-weight: 700; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  min-height: 28px;
  padding: 0 9px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 11px;
  font-weight: 700;
}
.chip.active { border-color: var(--blue); background: var(--blue-soft); color: #9ed3fb; }
.text-button {
  min-height: 28px;
  padding: 0 9px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: transparent;
  color: #c5ced5;
  cursor: pointer;
  font-size: 11px;
}
.selection-note { color: var(--muted); font-size: 11px; }

.chart { width: 100%; height: 470px; }

.detail-header { margin-bottom: 18px; }
.command-button {
  min-height: 36px;
  padding: 0 15px;
  border: 1px solid #397fb6;
  border-radius: 5px;
  background: var(--blue-soft);
  color: #a8d8fc;
  cursor: pointer;
  font-size: 12px;
  font-weight: 700;
}

.filters {
  min-height: 58px;
  padding: 10px 0;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}
.filter-pairs { flex: 1 1 580px; }
.toggle-control, .number-control {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: #c5ced5;
  font-size: 12px;
  white-space: nowrap;
}
.toggle-control input { position: absolute; opacity: 0; pointer-events: none; }
.toggle {
  width: 34px;
  height: 19px;
  padding: 2px;
  border-radius: 10px;
  background: #3a434b;
  cursor: pointer;
}
.toggle::after {
  display: block;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: white;
  content: "";
  transition: transform 160ms ease;
}
.toggle-control input:checked + .toggle { background: var(--blue); }
.toggle-control input:checked + .toggle::after { transform: translateX(15px); }
.number-control input {
  width: 72px;
  height: 32px;
  padding: 0 8px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: #11161a;
  color: var(--text);
}

.table-scroll { overflow-x: auto; }
table { width: 100%; min-width: 880px; border-collapse: collapse; }
th, td { padding: 13px 12px; border-bottom: 1px solid var(--border); text-align: left; font-size: 12px; white-space: nowrap; }
th { color: var(--muted); font-weight: 700; }
th button { padding: 0; border: 0; background: transparent; color: inherit; cursor: pointer; font-weight: inherit; }
tbody tr:hover { background: rgba(255, 255, 255, 0.018); }
.numeric { text-align: right; font-variant-numeric: tabular-nums; }
.table-empty, .empty-state { color: var(--muted); text-align: center; }
.empty-state { grid-column: 1 / -1; padding: 42px; border: 1px dashed var(--border); }

.pagination {
  display: grid;
  grid-template-columns: 100px 1fr 100px;
  align-items: center;
  gap: 12px;
  padding-top: 16px;
  color: var(--muted);
  text-align: center;
  font-size: 12px;
}
.pagination button {
  height: 34px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: transparent;
  cursor: pointer;
  font-size: 12px;
}
.pagination button:disabled { opacity: 0.35; cursor: not-allowed; }

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 20;
  max-width: min(420px, calc(100vw - 40px));
  padding: 12px 15px;
  border: 1px solid #3d8bc8;
  border-radius: 5px;
  background: #182c3b;
  color: #d9eeff;
  box-shadow: 0 14px 30px rgba(0, 0, 0, 0.32);
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: 160ms ease;
}
.toast.visible { opacity: 1; transform: translateY(0); }
.toast.error { border-color: #9c4a50; background: #351f23; color: #ffd8db; }

@media (max-width: 980px) {
  .rate-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .surface-header { align-items: flex-start; flex-direction: column; }
  .toolbar { width: 100%; }
  .chart { height: 420px; }
}

@media (max-width: 640px) {
  .topbar { min-height: 88px; padding: 18px 16px; align-items: flex-start; flex-direction: column; gap: 12px; }
  h1 { font-size: 22px; }
  main { padding: 24px 14px 40px; }
  .rate-grid { grid-template-columns: 1fr; }
  .rate-card { min-height: 116px; }
  .toolbar { align-items: stretch; flex-direction: column; }
  .segmented { width: 100%; overflow-x: auto; grid-auto-columns: minmax(66px, 1fr); }
  .segmented button { padding: 0 7px; }
  .pair-toolbar { align-items: flex-start; }
  .control-label { width: 100%; }
  .chart { height: 360px; }
  .detail-header { flex-direction: row; align-items: center; }
  .filters { align-items: flex-start; flex-direction: column; }
  .filter-pairs { flex-basis: auto; }
  .pagination { grid-template-columns: 88px 1fr 88px; }
}
