/* GridMind 网格控制台样式。风格沿用 funding-arb（深色 + 薄荷绿），本文件自包含。 */

:root {
  color-scheme: dark;
  --bg: #0a1017;
  --surface: #101923;
  --surface-high: #15212e;
  --line: #22303d;
  --muted: #7f91a3;
  --text: #e6edf3;
  --accent: #71e4bd;
  --accent-dim: #17372f;
  --warning: #e3b969;
  --red: #e49292;
  --live: #ff4d4f; /* 实盘专用，比普通红更醒目 */
  --mono: ui-monospace, SFMono-Regular, Menlo, monospace;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { scroll-behavior: smooth; scroll-padding-top: 24px; -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button, input, select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.5; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
h1, h2, h3 { margin: 0; }
h2 { font-size: 16px; font-weight: 550; letter-spacing: 0.3px; margin-bottom: 12px; }
h3 { font-size: 17px; font-weight: 600; margin-bottom: 8px; }


/* 通用文字色 */
.muted { color: var(--muted); }
.small { font-size: 12px; }
.pos { color: var(--accent); }
.neg { color: var(--red); }
.warn-text { color: var(--warning); }
.error-text { color: var(--red); }
.strong { font-weight: 600; }
.nowrap { white-space: nowrap; }

/* ---------- 外壳：侧栏 + 主区 ---------- */

.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: 224px;
  z-index: 10;
  display: flex;
  flex-direction: column;
  padding: 32px 20px 20px;
  background: #0c131c;
  border-right: 1px solid #1d2935;
}
.brand { display: flex; align-items: center; gap: 11px; padding: 0 6px; font-size: 19px; font-weight: 650; letter-spacing: 1px; }
.brand small { display: block; margin-top: 3px; font-size: 8px; font-weight: 500; letter-spacing: 1.45px; color: #8295a6; }
.brand-mark {
  position: relative;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  width: 35px;
  height: 35px;
  border: 1px solid #548e7d;
  border-radius: 50%;
  background: repeating-radial-gradient(circle, transparent 0, transparent 6px, #2c4a43 7px, transparent 8px);
}
.brand-mark span { width: 5px; height: 5px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 15px #71e4bd77; }

.workspace-label { display: flex; justify-content: space-between; margin: 50px 13px 17px; font-size: 10px; letter-spacing: 1.6px; color: #607488; }
.workspace-label span { padding: 2px 5px; border-radius: 3px; background: #172432; font-size: 8px; letter-spacing: 1px; color: #8c9dae; }

nav { display: grid; gap: 6px; }
.nav-link { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 6px; font-size: 13px; color: #8a9daf; }
.nav-link:hover { color: #d0e0e7; background: #131e29; }
.nav-link.active { color: #a4f0d7; background: linear-gradient(100deg, #18362f, #12231f); box-shadow: inset 2px 0 0 var(--accent); }
.nav-symbol { width: 20px; font-size: 18px; line-height: 1; text-align: center; }
.nav-badge { margin-left: auto; min-width: 22px; padding: 1px 4px; border-radius: 4px; background: #294c41; color: var(--accent); font-size: 10px; text-align: center; }
.nav-badge-error { background: #4a2429; color: var(--red); }

.sidebar-bottom {
  margin-top: auto;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 21px 8px 2px;
  border-top: 1px solid var(--line);
  font-size: 11px;
  color: #b3c1ce;
}
.sidebar-bottom small { display: block; margin-top: 3px; font-size: 10px; color: #62778b; }
.status-dot { flex-shrink: 0; width: 6px; height: 6px; border-radius: 50%; background: var(--accent); }

.user-box { display: grid; gap: 9px; padding: 14px 8px 0; margin-top: 14px; border-top: 1px solid var(--line); }
.user-id { display: flex; align-items: center; gap: 8px; min-width: 0; font-size: 13px; color: #d5e0e9; }
.user-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.user-id .badge { flex-shrink: 0; }
.user-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.user-actions .btn { flex: 1; padding: 5px 8px; }

.main-shell { flex: 1; min-width: 0; margin-left: 224px; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  height: 73px;
  padding: 0 28px;
  border-bottom: 1px solid #1b2733;
}
.breadcrumb { font-size: 11px; color: #657b90; white-space: nowrap; }
.breadcrumb span { padding: 0 13px; color: #344a5d; }
.breadcrumb strong { font-weight: 500; color: #b4c3d1; }
.topbar-right { display: flex; align-items: center; flex-wrap: wrap; justify-content: flex-end; gap: 8px 14px; font-family: var(--mono); font-size: 10px; color: #6e8396; }

.topbar-left { display: flex; align-items: center; gap: 12px; min-width: 0; }
.icon-btn { display: inline-grid; place-items: center; width: 28px; height: 28px; padding: 0; border: 1px solid #243342; border-radius: 6px; background: #101923; color: #8a9daf; cursor: pointer; }
.icon-btn:hover { color: #d0e0e7; background: #131e29; border-color: #2f4357; }
.icon-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* 总览 */
.page-heading { margin-bottom: 20px; }
.eyebrow { margin-bottom: 10px; font-size: 9px; letter-spacing: 2.2px; color: #8b9ba9; }
h1 { margin: 0 0 10px; font-size: 31px; font-weight: 620; line-height: 1.3; letter-spacing: 0.4px; }
.heading-dot { margin-left: 3px; color: var(--accent); }
.page-heading p { margin: 0; font-size: 12px; color: var(--muted); }
.connection-error { margin-bottom: 14px; padding: 12px 15px; border: 1px solid #663f43; border-radius: 6px; background: #2b1e25; color: #dfb0b4; font-size: 12px; font-weight: 600; }
.status-strip { margin-bottom: 20px; }
.top-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; }
#ex-errors { margin-top: 6px; color: var(--red); }

/* ---------- 面板、徽标、按钮 ---------- */

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 9px; padding: 18px 20px; margin-bottom: 16px; min-width: 0; }
h2 + p.muted { margin: -6px 0 10px; }
.panel > p.muted:last-child { margin: 10px 0 0; }

.badge, .pill { display: inline-block; padding: 2px 9px; border: 1px solid transparent; border-radius: 20px; font-family: var(--font); font-size: 10px; letter-spacing: 0.3px; white-space: nowrap; }
.badge-gray, .pill-gray { color: #8c9dab; background: #1c2630; border-color: #344452; }
.badge-ok, .pill-ok { color: #9fe7c9; background: #16382d; border-color: #345b4e; }
.badge-warn { color: #dfbf81; background: #342a19; border-color: #5b4a2c; }
.badge-bad, .pill-bad { color: #e4a6a6; background: #352126; border-color: #654049; }
.badge-mock { color: #b6b0e4; background: #2c2944; border-color: #4b4566; }
.badge-paper { color: #c4d6e3; background: #1b2b3e; border-color: #314963; font-size: 12px; font-weight: 600; padding: 3px 12px; }
.badge-live { color: #fff; background: var(--live); border-color: #ff8a8a; font-size: 12px; font-weight: 700; padding: 3px 12px; animation: pulse 2s infinite; }
td .badge-live { font-size: 10px; padding: 1px 8px; animation: none; }
@keyframes pulse { 50% { opacity: 0.75; } }

.btn-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.btn {
  padding: 9px 15px;
  border: 1px solid #2b3b49;
  border-radius: 6px;
  background: #141f2b;
  color: #c0ced9;
  font-size: 12px;
  font-weight: 550;
  transition: background 0.15s, border-color 0.15s;
}
.btn:hover:not(:disabled) { background: #1d2c3a; border-color: #3b5365; }
.btn-primary { border-color: var(--accent); background: var(--accent); color: #10291f; }
.btn-primary:hover:not(:disabled) { background: #a1f3d7; border-color: #a1f3d7; }
.btn-danger { color: #f1afaf; background: #351f28; border-color: #62333e; }
.btn-danger:hover:not(:disabled) { background: #482733; border-color: #7a3f4c; }
.btn-small { padding: 4px 10px; font-size: 11px; white-space: nowrap; }
#account-check { margin-top: 10px; }

/* 汇总卡片 */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 16px; }
.card { min-width: 0; padding: 14px 16px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface); }
.card-label { font-size: 11px; color: #a3b2bf; }
.card-value { margin-top: 8px; font-size: 20px; font-weight: 500; font-variant-numeric: tabular-nums; letter-spacing: -0.5px; white-space: nowrap; }
.card-sub { margin-top: 4px; font-size: 10px; color: #607d8e; }

/* ---------- 表格 ---------- */

.table-wrap { max-width: 100%; overflow-x: auto; scrollbar-width: thin; scrollbar-color: #2c4354 transparent; }
.events-wrap { max-height: 360px; overflow-y: auto; }
table { width: 100%; min-width: 720px; border-collapse: collapse; font-size: 12px; }
th, td { padding: 9px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { position: sticky; top: 0; background: var(--surface); font-size: 11px; font-weight: 500; color: var(--muted); white-space: nowrap; }
td.num, th.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
td.empty { padding: 22px; text-align: center; color: #607e93; }
tbody tr:hover td { background: #121d28; }
tr.row-eligible td { background: #112620; }
tr.row-error td { background: #2b1e25; }
td.liq-warn { background: #342a19 !important; color: var(--warning); font-weight: 700; }
td.liq-danger { background: #3d2025 !important; color: var(--live); font-weight: 700; }
.reason { min-width: 220px; max-width: 280px; }
.reason-text { word-break: break-all; }

#tbl-events { min-width: 0; }

/* 筛选 */
.filters { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; margin-bottom: 10px; font-size: 12px; color: #a3b2bf; }
.filters label { display: inline-flex; align-items: center; gap: 6px; }

/* 事件 */
.level { font-weight: 600; }
.level-info { color: var(--muted); }
.level-warn { color: var(--warning); }
.level-error { color: var(--red); }
tr.ev-error td { background: #261a20; }
tr.ev-warn td { background: #231f17; }

/* ---------- 表单 ---------- */

input, select {
  min-width: 0;
  padding: 8px 10px;
  border: 1px solid #2a3c4b;
  border-radius: 5px;
  background: #0c151e;
  color: #c1d2dd;
  font-size: 12px;
  outline: none;
  transition: border-color 0.15s;
}
input[type="number"], input[type="text"], input[type="password"] { font-family: var(--mono); }
input:focus, select:focus { border-color: #5c9e87; }
input[type="checkbox"] { padding: 0; accent-color: var(--accent); }
input[readonly], input:disabled { background: #111b25; color: #607e93; cursor: not-allowed; }

/* ---------- 登录页 ---------- */

.login-view { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 24px 16px; }
.login-card {
  width: min(380px, 100%);
  padding: 30px 28px 24px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: 0 20px 60px #0007;
}
.login-brand { margin-bottom: 26px; padding: 0; }
.login-title { margin-bottom: 14px; font-size: 18px; }
.login-card label { display: flex; flex-direction: column; gap: 6px; margin: 0 0 14px; font-size: 12px; color: #8ea4b6; }
.login-card input { width: 100%; padding: 10px 12px; font-size: 14px; }
.login-btn { width: 100%; margin-top: 4px; padding: 11px 15px; font-size: 14px; }
.login-notice, .login-error { margin: 0 0 14px; padding: 9px 12px; border-radius: 6px; font-size: 12px; }
.login-notice { border: 1px solid #5b4a2c; background: #342a19; color: #dfbf81; }
.login-error { border: 1px solid #654049; background: #352126; color: #e4a6a6; }
.login-foot { margin: 16px 0 0; text-align: center; }

/* ---------- 对话框与提示 ---------- */

dialog {
  width: min(480px, calc(100vw - 32px));
  padding: 22px;
  border: 1px solid #2a3b47;
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 16px 40px #0008;
}
dialog::backdrop { background: rgba(3, 8, 13, 0.7); }
dialog label { display: flex; flex-direction: column; gap: 6px; margin: 12px 0; font-size: 12px; color: #a3b2bf; }
dialog input[type="text"], dialog input[type="password"], dialog input[type="number"] { width: 100%; }
dialog p { margin: 0 0 8px; font-size: 13px; color: #b9c8d4; }
.plain-list { margin: 6px 0; padding-left: 18px; font-size: 12px; color: #a3b2bf; }
.plain-list:empty { display: none; }
.dlg-btns { justify-content: flex-end; margin-top: 14px; }

#toast {
  position: fixed;
  right: 30px;
  bottom: 25px;
  z-index: 200;
  max-width: calc(100vw - 32px);
  padding: 13px 20px;
  border: 1px solid #365747;
  border-radius: 8px;
  background: #18332b;
  color: #c1ead4;
  font-size: 12px;
  box-shadow: 0 8px 28px #0005;
}
#toast.toast-error { border-color: #6a4145; background: #342229; color: #f0bec4; }

/* ---------- 侧栏随宽度收窄 / 窄屏导航条 ---------- */

@media (max-width: 1200px) {
  .sidebar { width: 196px; padding-left: 14px; padding-right: 14px; }
  .brand { font-size: 16px; gap: 9px; letter-spacing: 0.5px; }
  .brand-mark { width: 30px; height: 30px; }
  .main-shell { margin-left: 196px; }
}

/* 窄屏：侧栏变成顶部横向滚动导航条 */
@media (max-width: 899px) {
  html { scroll-padding-top: 112px; }
  .app-shell { display: block; }
  .sidebar {
    position: sticky;
    top: 0;
    inset: auto;
    width: 100%;
    padding: 8px 12px 0;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    background: #0c131cf5;
    backdrop-filter: blur(16px);
  }
  .brand { padding: 0; font-size: 16px; gap: 9px; }
  .brand-mark { width: 28px; height: 28px; }
  .workspace-label, .sidebar-bottom { display: none; }
  .sidebar { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; column-gap: 8px; }
  .brand { grid-column: 1; grid-row: 1; }
  nav { grid-column: 1 / -1; grid-row: 2; }
  .user-box { grid-column: 2; grid-row: 1; display: flex; align-items: center; gap: 6px; margin: 0; padding: 0; border-top: 0; min-width: 0; }
  .user-id { gap: 5px; font-size: 12px; }
  .user-name { max-width: 84px; }
  .user-actions { flex-wrap: nowrap; gap: 4px; }
  .user-actions .btn { flex: none; padding: 4px 7px; font-size: 11px; white-space: nowrap; }
  nav {
    display: flex;
    gap: 4px;
    margin: 6px -12px 0;
    padding: 0 12px 6px;
    overflow-x: auto;
    scrollbar-width: none;
  }
  nav::-webkit-scrollbar { display: none; }
  .nav-link { flex-shrink: 0; gap: 6px; padding: 8px 12px; white-space: nowrap; }
  .nav-link.active { box-shadow: inset 0 -2px 0 var(--accent); }
  .nav-symbol { width: auto; font-size: 14px; }
  .main-shell { margin-left: 0; }
  .topbar { height: auto; min-height: 48px; padding: 8px 16px; flex-wrap: wrap; }
  .topbar-right { justify-content: flex-start; }
  .content { padding: 20px 16px 32px; }
  h1 { font-size: 24px; }
  .card-value { font-size: 17px; }
  .panel { padding: 14px; }
  #toast { left: 16px; right: 16px; bottom: 17px; text-align: center; }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; animation: none !important; transition: none !important; }
}


/* ---------- GridMind 专用 ---------- */
.badge-lg { font-size: 12px; font-weight: 600; padding: 3px 12px; }
.badge-running { color: #9fe7c9; background: #16382d; border-color: #345b4e; }
.badge-paused { color: #dfbf81; background: #342a19; border-color: #5b4a2c; }
.badge-stopping { color: #b6b0e4; background: #2c2944; border-color: #4b4566; }
.live-tag { font-weight: 600; font-size: 12px; padding: 3px 12px; }

.pause-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; margin-bottom: 16px; padding: 14px 16px; border: 1px solid #5b4a2c; border-radius: 9px; background: #342a19; color: #ecd29a; }
.pause-bar .pause-text { flex: 1 1 260px; min-width: 0; font-size: 13px; font-weight: 600; word-break: break-all; }
.pause-bar .pause-text small { display: block; margin-bottom: 2px; font-size: 11px; font-weight: 500; color: #c0a468; }

.sub-note { margin: 0 0 10px; font-size: 12px; color: var(--muted); }
.panel-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 12px; margin-bottom: 12px; }
.panel-head h2 { margin: 0; }

.param-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin: 0; }
.param-list div { min-width: 0; }
.param-list dt { font-size: 11px; color: var(--muted); }
.param-list dd { margin: 4px 0 0; font-size: 15px; font-variant-numeric: tabular-nums; }

tr.price-row td { padding: 5px 10px; background: #112620; color: var(--accent); font-size: 12px; font-weight: 600; text-align: center; border-bottom: 1px solid #345b4e; border-top: 1px solid #345b4e; }
.side-buy { color: var(--accent); font-weight: 600; }
.side-sell { color: var(--red); font-weight: 600; }
.table-scroll { max-height: 420px; overflow-y: auto; }
table.compact { min-width: 0; }

/* 创建网格表单 */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px 16px; margin-bottom: 14px; }
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; font-size: 12px; color: #8ea4b6; }
.field > .hint { font-size: 11px; color: var(--muted); }
.field input, .field select { width: 100%; }
.range-pair { display: flex; align-items: center; gap: 8px; }
.range-pair input { flex: 1; }
.range-pair span { color: var(--muted); }
.input-unit { display: flex; align-items: center; gap: 6px; }
.input-unit input { flex: 1; }
.unit { min-width: 2.2em; font-size: 11px; color: var(--muted); white-space: nowrap; }
.field-wide { grid-column: 1 / -1; }
input[type="range"] { padding: 0; width: 100%; accent-color: var(--accent); }
.ticks { display: flex; justify-content: space-between; font-size: 10px; color: var(--muted); }
details.adv { margin-bottom: 14px; border: 1px solid var(--line); border-radius: 7px; padding: 8px 12px; }
details.adv summary { cursor: pointer; font-size: 12px; color: #a3b2bf; }
details.adv .field { margin-top: 10px; max-width: 240px; }
.preview-line { display: flex; flex-wrap: wrap; gap: 4px 18px; margin-bottom: 14px; font-size: 12px; color: #a3b2bf; }
.preview-line b { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
.form-errors { margin: 0 0 12px; padding: 9px 12px 9px 28px; border: 1px solid #654049; border-radius: 6px; background: #352126; color: #e4a6a6; font-size: 12px; }
.form-errors:empty { display: none; }
.form-errors li { margin: 2px 0; }
.msg { margin-top: 8px; font-size: 12px; font-weight: 600; }
.msg.err { color: var(--red); }
.msg.ok { color: var(--accent); }

/* API Key */
.key-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; margin: 12px 0; }
.key-form input { width: 100%; }

/* 右侧内容区：铺满右侧面板宽度，上下左右留白 */
.content { padding: 32px 28px 40px; }
@media (max-width: 899px) { .content { padding: 20px 16px 32px; } }
.mono { font-family: var(--mono); }
.nav-link { color: #8a9daf; }
.login-brand div { line-height: 1.2; }

@media (max-width: 899px) {
  .param-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .form-grid { grid-template-columns: 1fr; }
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .card-value { font-size: 16px; }
  th, td { padding: 8px 6px; }
  .btn { padding: 10px 14px; }
  input, select { font-size: 16px; } /* 防 iOS 自动放大 */
}

.level { white-space: nowrap; }
table.fills { min-width: 560px; }
@media (max-width: 899px) { .hide-m { display: none; } table.fills { min-width: 0; } }

/* 左侧导航栏：隐藏 / 显示（仅宽屏；窄屏下导航是顶部横条，不提供折叠） */
.sidebar { transition: transform 0.2s ease, visibility 0.2s; }
.main-shell { transition: margin-left 0.2s ease; }
body.sidebar-collapsed .sidebar { transform: translateX(-100%); visibility: hidden; }
body.sidebar-collapsed .main-shell { margin-left: 0; }
.top-row #btn-sidebar { flex: none; }
@media (max-width: 899px) {
  #btn-sidebar { display: none; }
  body.sidebar-collapsed .sidebar { transform: none; visibility: visible; }
}
@media (prefers-reduced-motion: reduce) {
  .sidebar, .main-shell { transition: none; }
}
