:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --panel: #ffffff;
  --ink: #18202b;
  --muted: #667085;
  --line: #d9dee7;
  --accent: #176b87;
  --accent-strong: #0f5268;
  --gain: #c5362f;
  --loss: #087443;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  border: 0;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  min-height: 36px;
  padding: 0 14px;
  white-space: nowrap;
}

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

.ghost-button {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
}

.ghost-button:hover {
  background: #f2f4f7;
}

input,
select {
  width: 100%;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  padding: 6px 9px;
}

main {
  max-width: 1440px;
  margin: 0 auto;
  padding: 18px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: center;
  padding: 18px;
  background: #1f2933;
  color: #fff;
}

.topbar h1 {
  margin: 0 0 4px;
  font-size: 22px;
  letter-spacing: 0;
}

.topbar p {
  margin: 0;
  color: #d9e2ec;
}

.top-actions {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.account-menu {
  position: relative;
}

.account-menu summary {
  min-height: 36px;
  border-radius: 6px;
  background: #ffffff;
  color: var(--ink);
  cursor: pointer;
  list-style: none;
  padding: 7px 12px;
}

.account-menu summary::-webkit-details-marker {
  display: none;
}

.account-menu summary::after {
  content: "v";
  color: var(--muted);
  margin-left: 8px;
}

.account-popover {
  position: absolute;
  z-index: 20;
  top: calc(100% + 8px);
  right: 0;
  width: 280px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 16px 40px rgba(24, 32, 43, 0.16);
  color: var(--ink);
  padding: 12px;
}

.account-meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.account-meta span {
  color: var(--muted);
}

.account-form {
  display: grid;
  gap: 10px;
}

.account-form + form {
  margin-top: 10px;
}

.notice {
  border-radius: 6px;
  margin-bottom: 14px;
  padding: 10px 12px;
}

.notice.success {
  background: #e7f6ed;
  color: #075f36;
}

.notice.error {
  background: #fdebea;
  color: #9d271f;
}

.auth-page {
  min-height: 100vh;
  background: #eef2f5;
}

.auth-shell {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 18px;
}

.auth-panel {
  width: min(420px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 24px;
}

.auth-panel h1 {
  margin: 0 0 4px;
  font-size: 22px;
}

.auth-panel h2 {
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
}

.auth-form {
  display: grid;
  gap: 12px;
}

.auth-switch {
  margin: 14px 0 0;
  color: var(--muted);
}

.auth-switch a {
  color: var(--accent);
  font-weight: 600;
  text-decoration: none;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr)) minmax(0, 2fr);
  gap: 10px;
}

.metrics article,
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.metrics article {
  min-height: 94px;
  padding: 12px;
}

.metrics article > span {
  color: var(--ink);
  font-size: 13px;
  font-weight: 700;
}

label {
  color: var(--muted);
  font-size: 12px;
}

.metrics strong,
.metrics strong span {
  display: block;
  margin-top: 7px;
  color: var(--ink);
  font-size: 17px;
  line-height: 1.35;
  overflow-wrap: normal;
  word-break: normal;
}

.metrics strong span {
  display: inline;
  margin-top: 0;
}

.metrics .metric-lines {
  color: #475467;
  font-size: 16px;
  font-weight: 400;
  line-height: 1.32;
  white-space: pre-line;
}

.metrics .metric-plain {
  color: #475467;
  font-weight: 400;
}

.metrics .metric-plain span {
  color: inherit;
  font-weight: inherit;
}

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

.metric-wide strong {
  white-space: normal;
}

.workbench {
  display: grid;
  grid-template-columns: minmax(500px, 1.2fr) minmax(520px, 0.9fr);
  gap: 14px;
  margin-top: 14px;
}

.side-stack {
  display: grid;
  gap: 14px;
}

.panel {
  margin-top: 14px;
  padding: 14px;
}

.workbench .panel {
  margin-top: 0;
}

h2 {
  margin: 0 0 12px;
  font-size: 16px;
}

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

.panel-heading h2 {
  margin-bottom: 0;
}

.pager-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.pager-controls label {
  display: flex;
  align-items: center;
  gap: 6px;
}

.pager-controls select {
  width: 72px;
}

.pager-controls button {
  min-height: 32px;
  padding: 0 10px;
}

.pager-controls button:disabled {
  background: #c8d0da;
  cursor: not-allowed;
}

.pager-controls span {
  color: var(--muted);
  min-width: 112px;
  text-align: right;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  align-items: end;
}

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

.form-grid label {
  display: grid;
  gap: 4px;
}

.inline-form {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 8px;
}

.balances {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 10px;
}

.balances span {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px;
  background: #fafbfc;
}

.hidden {
  display: none !important;
}

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

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

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

th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  background: #fafbfc;
}

th[data-sort] {
  cursor: pointer;
  user-select: none;
}

th[data-sort]::after {
  color: var(--accent);
  content: "";
  display: inline-block;
  margin-left: 4px;
  min-width: 10px;
}

th[data-direction="asc"]::after {
  content: "↑";
}

th[data-direction="desc"]::after {
  content: "↓";
}

th[data-sort]:focus {
  outline: 2px solid rgba(23, 107, 135, 0.3);
  outline-offset: -2px;
}

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

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

.gain {
  color: var(--gain) !important;
}

.loss {
  color: var(--loss) !important;
}

@media (max-width: 1180px) {
  .metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .metric-wide {
    grid-column: 1 / -1;
  }

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

}

@media (max-width: 720px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  main {
    padding: 12px;
  }

  .metrics,
  .form-grid,
  .form-grid.compact,
  .balances {
    grid-template-columns: 1fr;
  }

  .inline-form {
    align-items: stretch;
    flex-direction: column;
  }

  .panel-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .pager-controls {
    justify-content: flex-start;
  }

  .account-popover {
    left: 0;
    right: auto;
    width: min(320px, calc(100vw - 24px));
  }

  button {
    width: 100%;
  }
}
