:root {
  color-scheme: light;
  --background: #f4f6fa;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --text: #172033;
  --muted: #697386;
  --line: #e2e8f0;
  --accent: #1769e0;
  --accent-hover: #0f57c4;
  --green: #11875d;
  --red: #c33b48;
  --amber: #9c6412;
  --shadow: 0 18px 48px rgba(30, 55, 90, 0.08);
  --radius: 18px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "PingFang SC", "Microsoft YaHei", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --background: #0b1020;
    --surface: #131a2a;
    --surface-soft: #182135;
    --text: #f1f5fb;
    --muted: #9ba7bb;
    --line: #27334a;
    --accent: #5a9cf8;
    --accent-hover: #76affd;
    --green: #57cca1;
    --red: #ff8290;
    --amber: #f2bc6a;
    --shadow: 0 18px 48px rgba(0, 0, 0, 0.24);
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 20% -15%, rgba(23, 105, 224, 0.14), transparent 32rem),
    var(--background);
  color: var(--text);
}

button,
input,
textarea {
  font: inherit;
}

button {
  border: 0;
}

.mono,
code {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

.topbar {
  padding: 30px 24px 12px;
}

.topbar-inner,
.page-shell {
  width: min(1180px, 100%);
  margin: 0 auto;
}

.topbar-inner {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
}

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

h1 {
  margin-bottom: 0;
  font-size: clamp(25px, 4vw, 36px);
  letter-spacing: -0.04em;
}

h2 {
  margin-bottom: 5px;
  font-size: 18px;
  letter-spacing: -0.02em;
}

h3 {
  margin-bottom: 12px;
  font-size: 15px;
  letter-spacing: -0.01em;
}

.eyebrow {
  margin-bottom: 5px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.page-shell {
  display: grid;
  gap: 20px;
  padding: 18px 24px 48px;
}

.card {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--surface) 96%, transparent);
  box-shadow: var(--shadow);
}

.query-card,
.results-card {
  padding: clamp(20px, 4vw, 30px);
}

.card-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 24px;
}

.card-heading p,
.query-actions p {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 13px;
}

.privacy-badge {
  flex: 0 0 auto;
  border: 1px solid color-mix(in srgb, var(--green) 35%, var(--line));
  border-radius: 999px;
  padding: 6px 10px;
  background: color-mix(in srgb, var(--green) 10%, transparent);
  color: var(--green);
  font-size: 12px;
  font-weight: 700;
}

.form-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.5fr) minmax(270px, 0.7fr);
  gap: 22px;
}

.date-grid {
  display: grid;
  align-content: start;
  gap: 16px;
}

.field label {
  display: block;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

input,
textarea {
  width: 100%;
  outline: none;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--surface-soft);
  color: var(--text);
  transition: border-color 0.15s, box-shadow 0.15s;
}

input {
  min-height: 44px;
  padding: 9px 12px;
}

textarea {
  min-height: 150px;
  resize: vertical;
  padding: 13px 14px;
  line-height: 1.65;
}

input:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 17%, transparent);
}

.field-help {
  display: block;
  margin-top: 7px;
  color: var(--muted);
  font-size: 12px;
}

.query-actions {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-top: 22px;
}

.button {
  display: inline-flex;
  min-height: 40px;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  padding: 9px 16px;
  cursor: pointer;
  font-weight: 700;
  transition: transform 0.15s, background 0.15s, color 0.15s;
}

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

.button:disabled {
  cursor: wait;
  opacity: 0.6;
  transform: none;
}

.button-primary {
  background: var(--accent);
  color: white;
  box-shadow: 0 8px 20px color-mix(in srgb, var(--accent) 26%, transparent);
}

.button-primary:hover {
  background: var(--accent-hover);
}

.button-ghost {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
}

.button-block {
  width: 100%;
}

.favorites-card {
  padding: clamp(20px, 4vw, 30px);
}

.count-badge {
  display: inline-block;
  min-width: 24px;
  border-radius: 999px;
  padding: 2px 8px;
  background: color-mix(in srgb, var(--accent) 13%, transparent);
  color: var(--accent);
  font-size: 13px;
  text-align: center;
}

.favorites-toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px 18px;
  border: 1px solid var(--line);
  border-radius: 13px;
  padding: 12px 14px;
  background: var(--surface-soft);
}

.check-inline {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  cursor: pointer;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
  white-space: nowrap;
}

.check-inline input {
  width: 17px;
  min-height: 17px;
  height: 17px;
  margin: 0;
  padding: 0;
  accent-color: var(--accent);
  cursor: pointer;
}

.bulk-dates,
.favorite-dates {
  display: flex;
  align-items: center;
  gap: 8px;
}

.bulk-dates input,
.favorite-dates input {
  width: auto;
  min-width: 138px;
  min-height: 38px;
  padding: 5px 9px;
  background: var(--surface);
  font-size: 13px;
}

.range-dash {
  color: var(--muted);
  font-size: 12px;
}

.toolbar-actions {
  display: flex;
  gap: 9px;
  margin-left: auto;
}

.favorites-toolbar .button,
.favorite-row-actions .button {
  min-height: 38px;
  padding: 6px 14px;
  font-size: 13px;
}

.favorites-hint {
  min-height: 18px;
  margin: 9px 2px 0;
  color: var(--accent);
  font-size: 12px;
}

.favorites-list {
  display: grid;
  overflow: hidden;
  gap: 1px;
  margin-top: 6px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--line);
}

.favorite-row {
  display: grid;
  align-items: center;
  grid-template-columns: auto minmax(120px, 1.1fr) minmax(0, auto) auto auto;
  gap: 10px 14px;
  padding: 12px 14px;
  background: var(--surface);
}

.favorite-remark {
  min-height: 38px;
  padding: 6px 10px;
  font-size: 13px;
  font-weight: 650;
}

.favorite-address {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.favorite-row-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.favorite-remove {
  color: var(--red);
}

.empty-state,
.loading-state,
.error-state {
  display: grid;
  min-height: 170px;
  place-items: center;
  align-content: center;
  gap: 10px;
  border: 1px dashed var(--line);
  border-radius: 14px;
  background: var(--surface-soft);
  color: var(--muted);
  text-align: center;
}

.empty-state p,
.loading-state p,
.error-state p {
  margin-bottom: 0;
}

.empty-icon {
  display: grid;
  width: 40px;
  height: 40px;
  place-items: center;
  border-radius: 12px;
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  color: var(--accent);
  font-size: 20px;
  font-weight: 800;
}

.error-state {
  border-color: color-mix(in srgb, var(--red) 45%, var(--line));
  background: color-mix(in srgb, var(--red) 7%, var(--surface-soft));
  color: var(--red);
}

.spinner {
  width: 30px;
  height: 30px;
  border: 3px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

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

.summary-item {
  display: grid;
  gap: 5px;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px;
  background: var(--surface-soft);
}

.summary-item span,
.summary-item small,
.wallet-metrics span,
.wallet-metrics small {
  color: var(--muted);
  font-size: 12px;
}

.summary-item strong {
  overflow-wrap: anywhere;
  font-size: clamp(18px, 3vw, 24px);
  letter-spacing: -0.03em;
}

.summary-item.loss strong {
  color: var(--amber);
}

.summary-item.total-loss {
  border-color: color-mix(in srgb, var(--red) 24%, var(--line));
  background: color-mix(in srgb, var(--red) 5%, var(--surface-soft));
}

.summary-item.total-loss strong.negative {
  color: var(--red);
}

.summary-item.total-loss strong.positive {
  color: var(--green);
}

.method-note {
  margin: 14px 0 20px;
  border-radius: 11px;
  padding: 11px 13px;
  background: color-mix(in srgb, var(--accent) 7%, var(--surface-soft));
  color: var(--muted);
  font-size: 12px;
  line-height: 1.6;
}

.overview-section,
.detail-section {
  margin-top: 20px;
}

.overview-scroll {
  max-height: none;
  border: 1px solid var(--line);
  border-radius: 14px;
}

.overview-table {
  min-width: 960px;
}

.overview-table th,
.overview-table td {
  padding: 16px 14px;
}

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

.remark-cell {
  font-weight: 750;
}

.volume-value {
  color: color-mix(in srgb, var(--accent) 85%, var(--text));
  font-weight: 800;
}

.loss-pill {
  display: inline-flex;
  min-width: 88px;
  justify-content: flex-end;
  border-radius: 999px;
  padding: 5px 9px;
  background: color-mix(in srgb, currentColor 9%, transparent);
  font-weight: 800;
}

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

.range-cell {
  color: var(--muted);
  font-size: 11px;
}

.star-cell {
  text-align: right;
}

.star-button {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 11px;
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
}

.star-button:hover {
  border-color: color-mix(in srgb, var(--amber) 50%, var(--line));
  color: var(--amber);
}

.star-button.active {
  border-color: color-mix(in srgb, var(--amber) 45%, var(--line));
  background: color-mix(in srgb, var(--amber) 12%, transparent);
  color: var(--amber);
}

.wallet-details-list {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 14px;
}

.wallet-detail {
  border-top: 1px solid var(--line);
}

.wallet-detail:first-child {
  border-top: 0;
}

.wallet-detail > summary {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface-soft);
}

.wallet-detail > summary span {
  min-width: 72px;
  color: var(--text);
}

.wallet-detail > summary code {
  min-width: 0;
  overflow: hidden;
  color: var(--muted);
  text-overflow: ellipsis;
}

.wallet-detail > summary small {
  margin-left: auto;
  color: var(--muted);
  font-weight: 500;
}

.wallet-list {
  display: grid;
  gap: 14px;
}

.wallet-card {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 14px;
}

.wallet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--line);
  padding: 14px 16px;
  background: var(--surface-soft);
}

.wallet-head > div {
  display: grid;
  min-width: 0;
  gap: 4px;
}

.wallet-head span {
  color: var(--muted);
  font-size: 11px;
}

.wallet-head code {
  overflow-wrap: anywhere;
  font-size: 12px;
}

.transaction-count {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 8px;
}

.wallet-metrics {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 1px;
  background: var(--line);
}

.wallet-metrics > div {
  display: grid;
  align-content: start;
  gap: 5px;
  min-width: 0;
  padding: 14px;
  background: var(--surface);
}

.wallet-metrics strong {
  overflow-wrap: anywhere;
  font-size: 14px;
}

.positive {
  color: var(--green);
}

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

details {
  border-top: 1px solid var(--line);
}

summary {
  padding: 13px 16px;
  cursor: pointer;
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
}

.table-scroll {
  overflow: auto;
  max-height: 460px;
  border-top: 1px solid var(--line);
}

table {
  width: 100%;
  min-width: 820px;
  border-collapse: collapse;
  font-size: 12px;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 10px 12px;
  text-align: left;
  white-space: nowrap;
}

th {
  position: sticky;
  z-index: 1;
  top: 0;
  background: var(--surface-soft);
  color: var(--muted);
  font-weight: 700;
}

.numeric {
  text-align: right;
}

td small {
  display: block;
  margin-top: 3px;
  color: var(--muted);
}

.trade-tag {
  border-radius: 999px;
  padding: 3px 7px;
  font-weight: 700;
}

.trade-tag.buy {
  background: color-mix(in srgb, var(--green) 12%, transparent);
  color: var(--green);
}

.trade-tag.sell {
  background: color-mix(in srgb, var(--red) 12%, transparent);
  color: var(--red);
}

.trade-tag.failed {
  background: color-mix(in srgb, var(--muted) 15%, transparent);
  color: var(--muted);
}

.failed-row {
  background: color-mix(in srgb, var(--amber) 5%, transparent);
}

.muted-cell {
  color: var(--muted);
  font-weight: 500;
}

.tx-link {
  color: var(--accent);
  text-decoration: none;
}

.detail-empty {
  border-top: 1px solid var(--line);
  padding: 18px;
  color: var(--muted);
  text-align: center;
}

.wallet-error {
  padding-bottom: 14px;
}

.wallet-error p {
  margin: 14px 16px 0;
  color: var(--red);
  font-size: 13px;
}

.login-body {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: min(100%, 390px);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 34px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.brand-mark {
  display: grid;
  width: 48px;
  height: 48px;
  margin: 0 auto 18px;
  place-items: center;
  border-radius: 15px;
  background: linear-gradient(145deg, var(--accent), #7b61ff);
  color: white;
  font-size: 20px;
  font-weight: 900;
  box-shadow: 0 12px 28px rgba(23, 105, 224, 0.25);
}

.login-card h1 {
  text-align: center;
  font-size: 24px;
}

.login-subtitle {
  margin: 7px 0 27px;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

.login-card label {
  display: block;
  margin: 0 0 7px 2px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

.login-card input {
  margin-bottom: 16px;
}

.login-card .button {
  margin-top: 5px;
}

.form-error {
  min-height: 20px;
  margin: 12px 0 0;
  color: var(--red);
  font-size: 13px;
  text-align: center;
}

@media (max-width: 840px) {
  .form-grid {
    grid-template-columns: 1fr;
  }

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

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

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

  .favorite-row {
    grid-template-columns: auto minmax(0, 1fr);
  }

  .favorite-address,
  .favorite-dates,
  .favorite-row-actions {
    grid-column: 2;
  }

  .toolbar-actions {
    margin-left: 0;
  }
}

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

  .page-shell {
    padding: 12px 16px 32px;
  }

  .topbar-inner {
    align-items: center;
  }

  .topbar h1 {
    font-size: 24px;
  }

  .query-card,
  .results-card,
  .favorites-card {
    padding: 18px;
  }

  .bulk-dates,
  .favorite-dates {
    display: grid;
    width: 100%;
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  }

  .bulk-dates .button {
    grid-column: 1 / -1;
  }

  .bulk-dates input,
  .favorite-dates input {
    width: 100%;
    min-width: 0;
  }

  .toolbar-actions {
    width: 100%;
  }

  .toolbar-actions .button {
    flex: 1;
  }

  .card-heading,
  .query-actions {
    align-items: flex-start;
    flex-direction: column;
  }

  .date-grid,
  .summary-grid,
  .wallet-metrics {
    grid-template-columns: 1fr;
  }

  .query-actions .button {
    width: 100%;
  }

  .login-card {
    padding: 28px 22px;
  }
}
