:root {
  --bg: #0e1419;
  --surface: #161e25;
  --surface-2: #1d2731;
  --line: #2a3540;
  --text: #d8e2ec;
  --muted: #889aa9;
  --accent: #14b8a6;
  --accent-h: #0d9488;
  --orange: #f59e0b;
  --red: #ef4444;
  --green: #22c55e;
  --blue: #3b82f6;
  color-scheme: dark;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
               "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 14px;
  line-height: 1.5;
}

#app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ---- Top bar ---- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  padding: 0 24px;
  height: 60px;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}
.brand .logo {
  color: var(--accent);
  font-size: 24px;
  font-weight: bold;
}
.brand h1 {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0.5px;
}
.brand .tag {
  font-size: 11px;
  color: var(--muted);
  background: var(--surface-2);
  padding: 2px 8px;
  border-radius: 4px;
  margin-left: 8px;
  font-weight: 400;
  letter-spacing: 0;
}
.tabs {
  display: flex;
  gap: 4px;
}
.tab {
  background: transparent;
  border: none;
  color: var(--muted);
  padding: 8px 16px;
  cursor: pointer;
  border-radius: 6px;
  font-size: 14px;
  transition: all 0.15s;
  font-weight: 500;
}
.tab:hover { color: var(--text); background: var(--surface-2); }
.tab.active { color: var(--accent); background: var(--surface-2); }
.userbox { display: flex; align-items: center; gap: 12px; }
.status-pill {
  font-size: 11px;
  padding: 4px 10px;
  border-radius: 12px;
  background: var(--surface-2);
  color: var(--muted);
  border: 1px solid var(--line);
}
.status-pill.ok { color: var(--green); border-color: var(--green); }
.status-pill.warn { color: var(--orange); border-color: var(--orange); }
.status-pill.err { color: var(--red); border-color: var(--red); }

/* ---- Main panels ---- */
main {
  flex: 1;
  padding: 24px;
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
}
.panel { display: block; }
.panel.hidden { display: none; }
.panel h2 {
  font-size: 18px;
  margin-bottom: 16px;
  color: var(--text);
  font-weight: 600;
}

footer {
  padding: 16px 24px;
  text-align: center;
  color: var(--muted);
  border-top: 1px solid var(--line);
  font-size: 11px;
}

/* ---- Cards ---- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 16px;
}
.card h3 {
  font-size: 14px;
  margin-bottom: 12px;
  color: var(--accent);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.card h4 {
  font-size: 13px;
  margin-bottom: 8px;
  color: var(--muted);
  font-weight: 500;
}
.mt-4 { margin-top: 16px; }

/* ---- Grid ---- */
.grid { display: grid; gap: 16px; }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
@media (max-width: 1024px) {
  .grid-3 { grid-template-columns: 1fr; }
}

/* ---- Forms ---- */
.form-row {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.form-row label {
  min-width: 120px;
  color: var(--muted);
  font-weight: 500;
}
input[type="text"], input[type="password"], input[type="date"],
input[type="number"], select {
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 8px 12px;
  border-radius: 4px;
  font-size: 14px;
  font-family: inherit;
  flex: 1;
  min-width: 120px;
}
input:focus, select:focus {
  outline: none;
  border-color: var(--accent);
}
.btn {
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 8px 18px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: all 0.15s;
}
.btn:hover { background: var(--line); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: white; border-color: var(--accent); }
.btn-primary:hover { background: var(--accent-h); }
.btn-ghost { background: transparent; }
.btn-full { width: 100%; }

/* ---- Trading mode radio buttons ---- */
.mode-radio {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 4px;
  cursor: pointer;
  width: 100%;
  transition: all 0.15s;
}
.mode-radio:hover { background: var(--surface-2); }
.mode-radio input[type="radio"] { margin: 0; cursor: pointer; }
.mode-radio:has(input:checked) {
  background: var(--surface-2);
  border-color: var(--accent);
}

/* ---- Key-value list ---- */
.kv-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.kv-list > div {
  display: flex;
  justify-content: space-between;
  padding: 4px 0;
  border-bottom: 1px solid var(--line);
}
.kv-list > div:last-child { border-bottom: none; }
.kv-list b { color: var(--muted); font-weight: 500; }
.kv-list .num { font-variant-numeric: tabular-nums; color: var(--text); }
.kv-list .pos { color: var(--green); }
.kv-list .neg { color: var(--red); }

/* ---- Tables ---- */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  margin-bottom: 8px;
}
.data-table th, .data-table td {
  padding: 8px 10px;
  text-align: left;
  border-bottom: 1px solid var(--line);
}
.data-table th {
  background: var(--surface-2);
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
  font-size: 11px;
  letter-spacing: 0.5px;
}
.data-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.data-table tbody tr:hover { background: var(--surface-2); }
.data-table .pos { color: var(--green); }
.data-table .neg { color: var(--red); }
.data-table .empty {
  text-align: center;
  color: var(--muted);
  padding: 24px;
}

/* ---- Branches ---- */
.branch-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 8px;
}
.branch-chip {
  background: var(--surface-2);
  border: 1px solid var(--line);
  padding: 8px 12px;
  border-radius: 6px;
  cursor: pointer;
  text-align: center;
  font-size: 12px;
  font-weight: 500;
  transition: all 0.15s;
}
.branch-chip.enabled { border-color: var(--accent); color: var(--accent); }
.branch-chip.disabled { color: var(--muted); }
.branch-chip:hover { background: var(--line); }

.chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  flex: 1;
}
.chip {
  background: var(--surface-2);
  border: 1px solid var(--line);
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 12px;
  cursor: pointer;
}
.chip.on { border-color: var(--accent); color: var(--accent); }
.chip:hover { background: var(--line); }

/* ---- Loading / Empty ---- */
.loading, .muted { color: var(--muted); font-style: italic; }
.empty { color: var(--muted); padding: 12px; text-align: center; }

/* ---- Pause banner ---- */
.pause-banner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-left: 4px solid var(--orange);
}
.pause-banner h3 { margin-bottom: 8px; }
.pause-banner p { color: var(--muted); max-width: 600px; }

/* ---- Summary ---- */
.summary {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
}
.summary .stat {
  background: var(--surface-2);
  padding: 10px 14px;
  border-radius: 6px;
  border-left: 3px solid var(--accent);
}
.summary .stat .label {
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
}
.summary .stat .value {
  font-size: 18px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.summary .stat .value.pos { color: var(--green); }
.summary .stat .value.neg { color: var(--red); }

/* ---- Login ---- */
.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}
.login-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 32px;
  width: 380px;
  max-width: 90vw;
}
.login-brand {
  text-align: center;
  margin-bottom: 32px;
}
.login-brand .logo {
  color: var(--accent);
  font-size: 48px;
  display: block;
  margin-bottom: 12px;
}
.login-brand h1 {
  font-size: 20px;
  font-weight: 600;
  margin-bottom: 4px;
}
.login-brand .tag {
  font-size: 11px;
  color: var(--muted);
}
.login-card .form-row { flex-direction: column; align-items: stretch; }
.login-card .form-row label {
  margin-bottom: 4px;
  font-size: 12px;
}
.login-card .form-row input { flex: none; width: 100%; }
.login-hint {
  text-align: center;
  margin-top: 24px;
  color: var(--muted);
  font-size: 12px;
}
.login-hint code {
  background: var(--surface-2);
  padding: 1px 6px;
  border-radius: 3px;
  color: var(--accent);
}
.msg {
  margin-top: 8px;
  text-align: center;
  font-size: 13px;
  min-height: 18px;
}
.msg.ok { color: var(--green); }
.msg.err { color: var(--red); }

/* ---- Chart area ---- */
.chart-area {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px;
  min-height: 180px;
  overflow: hidden;
}
.chart-area svg { display: block; max-width: 100%; }
.chart-large { min-height: 320px; }

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

/* ---- Details / collapsible ---- */
details {
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 8px 12px;
  margin-bottom: 4px;
  background: var(--surface-2);
}
details summary {
  cursor: pointer;
  color: var(--text);
  padding: 4px 0;
  user-select: none;
}
details summary:hover { color: var(--accent); }
details[open] summary { color: var(--accent); margin-bottom: 8px; }

.mt-2 { margin-top: 8px; }

/* ---- Buttons (additions) ---- */
.btn-danger { background: var(--red); color: white; border-color: var(--red); }
.btn-danger:hover { background: #b91c1c; }
.btn-warn { background: var(--orange); color: white; border-color: var(--orange); }
.btn-warn:hover { background: #d97706; }




/* Order detail modal */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
}
.modal-card {
  background: #161e26; border: 1px solid #2a3540; border-radius: 4px;
  padding: 16px 20px; min-width: 420px; max-width: 700px;
  max-height: 80vh; overflow: auto;
  position: relative; color: #e6edf3;
}
.modal-close {
  position: absolute; top: 6px; right: 10px;
  background: transparent; border: none; color: #889aa9;
  font-size: 22px; cursor: pointer; line-height: 1;
}
.modal-close:hover { color: #e6edf3; }
.clickable-row { cursor: pointer; }
.clickable-row:hover { background: #1a242c; }
