:root {
  color-scheme: dark;
  --bg: #0a0d11;
  --surface: #12171e;
  --surface-2: #18202a;
  --surface-3: #202a36;
  --line: #303b49;
  --line-strong: #3d4c5d;
  --text: #e8edf3;
  --muted: #9ca8b6;
  --accent: #39c6ad;
  --accent-dark: #1d6f63;
  --blue: #4c8dff;
  --green: #65d6a9;
  --red: #ff7d89;
  --yellow: #f5bd48;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); }
body { font-family: Inter, "Segoe UI", "PingFang SC", Arial, sans-serif; letter-spacing: 0; }
button, input, select { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }

.app-shell { min-height: 100vh; }
.topbar {
  height: 60px; position: sticky; top: 0; z-index: 50; display: flex; align-items: center;
  justify-content: space-between; gap: 20px; padding: 0 22px; background: #11161d;
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-mark { width: 30px; height: 30px; display: grid; place-items: center; background: var(--accent-dark); color: #fff; font-weight: 800; }
.brand h1 { font-size: 18px; margin: 0; white-space: nowrap; }
.top-actions { display: flex; align-items: center; gap: 10px; }
.top-user { color: var(--muted); font-size: 13px; }
.nav { display: flex; height: 100%; align-items: stretch; }
.nav a { display: flex; align-items: center; padding: 0 16px; color: var(--muted); text-decoration: none; border-bottom: 2px solid transparent; }
.nav a.active { color: var(--text); border-color: var(--accent); background: rgba(57, 198, 173, .06); }

.content { width: min(1880px, 100%); margin: 0 auto; padding: 18px 22px 40px; }
.filter-bar {
  position: sticky; top: 60px; z-index: 40; display: grid;
  grid-template-columns: minmax(220px, 1.5fr) repeat(4, minmax(150px, .8fr)) auto;
  gap: 9px; padding: 12px; background: rgba(18, 23, 30, .97); border: 1px solid var(--line);
  border-top: 3px solid var(--accent); box-shadow: 0 10px 24px rgba(0, 0, 0, .32);
}
input, select {
  width: 100%; height: 40px; padding: 0 12px; color: var(--text); background: var(--surface-2);
  border: 1px solid var(--line-strong); border-radius: 3px; outline: none;
}
input:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(57, 198, 173, .13); }
.button { width: auto; min-height: 38px; padding: 0 15px; border: 1px solid var(--line-strong); border-radius: 3px; color: var(--text); background: var(--surface-3); }
.button:hover { border-color: var(--accent); }
.button.primary { border-color: var(--accent); background: var(--accent); color: #081311; font-weight: 700; }
.button.danger { color: var(--red); }
.button.small { min-height: 30px; padding: 0 10px; font-size: 12px; }
.icon-button { width: 38px; height: 38px; padding: 0; display: grid; place-items: center; }

.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin: 14px 0; }
.stat { min-height: 110px; padding: 16px; background: var(--surface); border: 1px solid var(--line); border-top: 3px solid var(--blue); }
.stat span { color: var(--muted); font-size: 13px; }
.stat strong { display: block; margin-top: 12px; font-size: 26px; overflow-wrap: anywhere; }
.stat small { display: block; margin-top: 6px; color: var(--muted); }
.positive { color: var(--green) !important; }
.negative { color: var(--red) !important; }

.panel { margin-top: 12px; background: var(--surface); border: 1px solid var(--line); border-top: 3px solid var(--blue); }
.panel-header { min-height: 48px; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 9px 14px; border-bottom: 1px solid var(--line); }
.panel-header h2 { margin: 0; font-size: 15px; }
.panel-header p { margin: 3px 0 0; color: var(--muted); font-size: 12px; }
.panel-actions { display: flex; gap: 8px; align-items: center; }
.panel-body { padding: 14px; }

.table-wrap { width: 100%; overflow: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { height: 42px; padding: 0 12px; text-align: left; color: #dce5ee; background: #22303c; white-space: nowrap; }
td { min-height: 45px; padding: 11px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tbody tr:hover { background: rgba(76, 141, 255, .05); }
.sort-button { display: inline-flex; gap: 7px; align-items: center; padding: 0; border: 0; background: transparent; color: inherit; font-weight: 700; }
.sort-button span { color: var(--accent); min-width: 10px; }
.mono { font-variant-numeric: tabular-nums; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.sub { margin-top: 4px; color: var(--muted); font-size: 11px; }
.exchange { font-weight: 800; }
.exchange-binance { color: #f3ba2f; } .exchange-bybit { color: #f5f7fb; }
.exchange-bitget { color: #28d7d8; } .exchange-gate { color: #3a85ff; }
.empty { padding: 42px 16px; text-align: center; color: var(--muted); }
.badge { display: inline-flex; align-items: center; min-height: 25px; padding: 0 8px; border: 1px solid var(--line-strong); font-size: 12px; }
.badge.ok { color: var(--green); border-color: rgba(101, 214, 169, .45); background: rgba(101, 214, 169, .08); }
.badge.off { color: var(--muted); }
.badge.warn { color: var(--yellow); }

.chart { height: 220px; position: relative; overflow: hidden; background: #111923; border: 1px solid var(--line); }
.chart svg { width: 100%; height: 100%; display: block; }
.chart .grid { stroke: #263443; stroke-width: 1; }
.chart .line { stroke: var(--blue); stroke-width: 2; fill: none; vector-effect: non-scaling-stroke; }
.chart .area { fill: rgba(76, 141, 255, .1); }
.chart-meta { display: flex; flex-wrap: wrap; gap: 10px 24px; margin-bottom: 10px; color: var(--muted); font-size: 12px; }

.login-layer { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: #090c10; }
.login-card { width: min(430px, 100%); padding: 26px; background: var(--surface); border: 1px solid var(--line); border-top: 3px solid var(--accent); }
.login-card h1 { margin: 0 0 8px; font-size: 23px; }
.login-card p { margin: 0 0 22px; color: var(--muted); line-height: 1.6; }
.form-field { display: grid; gap: 7px; margin-top: 13px; }
.form-field label { color: var(--muted); font-size: 12px; }
.login-card .button { width: 100%; margin-top: 18px; }
.error-box { margin-top: 13px; padding: 10px; border: 1px solid rgba(255, 125, 137, .4); color: var(--red); background: rgba(255, 125, 137, .07); font-size: 13px; }

.modal-backdrop { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 24px; background: rgba(0, 0, 0, .68); }
.modal { width: min(840px, 100%); max-height: min(820px, calc(100vh - 48px)); overflow: auto; background: #121820; border: 1px solid var(--line-strong); }
.modal-header { position: sticky; top: 0; z-index: 2; display: flex; justify-content: space-between; align-items: center; padding: 16px 18px; background: #1a222c; border-bottom: 1px solid var(--line); }
.modal-header h2 { margin: 0; font-size: 18px; }
.modal-body { padding: 18px; }
.modal-footer { position: sticky; bottom: 0; display: flex; justify-content: flex-end; gap: 8px; padding: 13px 18px; background: #161d26; border-top: 1px solid var(--line); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 13px; }
.scope-list { margin-top: 14px; border: 1px solid var(--line); max-height: 340px; overflow: auto; }
.scope-row { display: grid; grid-template-columns: 34px minmax(180px, 1fr) 130px 120px 170px; align-items: center; gap: 10px; min-height: 48px; padding: 7px 10px; border-bottom: 1px solid var(--line); }
.scope-row input { width: 18px; height: 18px; }

.tabs { display: flex; gap: 0; border-bottom: 1px solid var(--line); }
.tabs button { width: auto; height: 42px; padding: 0 16px; border: 0; border-bottom: 2px solid transparent; background: transparent; color: var(--muted); }
.tabs button.active { color: var(--text); border-color: var(--accent); }
.record-message { max-width: 480px; white-space: pre-wrap; overflow-wrap: anywhere; color: var(--muted); }
.loading-line { height: 2px; position: fixed; top: 60px; left: 0; right: 0; z-index: 90; overflow: hidden; }
.loading-line::after { content: ""; display: block; width: 35%; height: 100%; background: var(--accent); animation: loading 1s infinite ease-in-out; }
@keyframes loading { from { transform: translateX(-100%); } to { transform: translateX(390%); } }

@media (max-width: 1180px) {
  .filter-bar { grid-template-columns: repeat(3, minmax(150px, 1fr)); }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .nav a { padding: 0 10px; }
}
@media (max-width: 720px) {
  .topbar { height: auto; min-height: 58px; padding: 10px 12px; flex-wrap: wrap; }
  .nav { order: 3; width: 100%; height: 38px; overflow-x: auto; }
  .content { padding: 12px; }
  .filter-bar { position: static; grid-template-columns: 1fr; }
  .stats { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .scope-row { grid-template-columns: 28px 1fr; }
  .scope-row > :nth-child(n+3) { display: none; }
  .top-user { display: none; }
}
