:root {
  color-scheme: dark;
  --bg: #0b0e10;
  --surface: #111619;
  --surface-2: #171d20;
  --surface-3: #1d2529;
  --line: #2a3439;
  --line-soft: #20282c;
  --text: #eef4f6;
  --muted: #93a3aa;
  --green: #29d391;
  --green-soft: #123529;
  --cyan: #4cc9e8;
  --amber: #f5bd52;
  --red: #ff646b;
  --purple: #9287ff;
  --radius: 6px;
  font-family: "Segoe UI", "Microsoft YaHei UI", sans-serif;
  font-size: 14px;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); }
body { letter-spacing: 0; }
button, input, select, textarea { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }

.app-shell { min-width: 1180px; min-height: 100vh; display: grid; grid-template-columns: 218px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; border-right: 1px solid var(--line); background: #0e1214; }
.sidebar-brand { height: 76px; display: flex; align-items: center; gap: 12px; padding: 0 20px; border-bottom: 1px solid var(--line); }
.brand-mark { display: grid; place-items: center; width: 34px; height: 34px; background: var(--green); color: #06120d; border-radius: 5px; font-weight: 800; font-size: 18px; }
.sidebar-brand strong { display: block; font-size: 16px; }
.sidebar-brand small { display: block; margin-top: 3px; color: var(--muted); font-size: 10px; }
.nav-list { display: grid; gap: 4px; padding: 16px 12px; }
.nav-item { height: 42px; padding: 0 14px; border: 1px solid transparent; border-radius: 5px; color: var(--muted); background: transparent; text-align: left; }
.nav-item:hover { color: var(--text); background: var(--surface-2); }
.nav-item.active { color: var(--green); background: var(--green-soft); border-color: #22533f; }
.sidebar-foot { margin-top: auto; display: grid; grid-template-columns: 1fr auto; gap: 6px; padding: 16px 20px; border-top: 1px solid var(--line); color: var(--muted); }
.sidebar-foot small { grid-column: 1 / -1; font-size: 11px; }
.link-button { padding: 0; border: 0; color: var(--cyan); background: none; }

.workspace { min-width: 0; padding: 0 26px 40px; }
.topbar { min-height: 76px; display: flex; align-items: center; justify-content: space-between; gap: 20px; border-bottom: 1px solid var(--line); }
.topbar h1 { margin: 0; font-size: 20px; }
.topbar p { margin: 5px 0 0; color: var(--muted); font-size: 12px; }
.top-actions { display: flex; align-items: center; gap: 12px; }
.status-pill { min-width: 114px; padding: 7px 10px; border-radius: 4px; border: 1px solid var(--line); text-align: center; font-size: 12px; }
.status-ok { color: var(--green); border-color: #236c50; background: #10281f; }
.status-warning { color: var(--amber); border-color: #725b2c; background: #2a2415; }
.status-error { color: var(--red); border-color: #71343a; background: #2c171a; }
.status-muted { color: var(--muted); }

.switch-line { display: flex; align-items: center; gap: 8px; color: var(--muted); }
.switch-line input {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  clip-path: inset(50%);
  white-space: nowrap;
}
.switch-line i { position: relative; display: block; width: 38px; height: 20px; border-radius: 10px; background: #394247; }
.switch-line i::after { content: ""; position: absolute; top: 3px; left: 3px; width: 14px; height: 14px; border-radius: 50%; background: #b5c0c4; transition: transform .15s ease; }
.switch-line input:checked + i { background: #1d7f5a; }
.switch-line input:checked + i::after { transform: translateX(18px); background: white; }
.switch-line input:focus-visible + i { outline: 2px solid var(--cyan); outline-offset: 2px; }

.button { min-height: 34px; padding: 0 14px; border: 1px solid var(--line); border-radius: 5px; color: var(--text); background: var(--surface-2); }
.button:hover { border-color: #536168; background: var(--surface-3); }
.button-primary { color: #06130d; background: var(--green); border-color: var(--green); font-weight: 700; }
.button-primary:hover { background: #48dda3; border-color: #48dda3; }
.button-danger { color: var(--red); border-color: #71343a; background: #2c171a; }
.button-small { min-height: 28px; padding: 0 9px; font-size: 12px; }
.button-wide { width: 100%; height: 42px; }

.tab-panel { display: none; padding-top: 22px; }
.tab-panel.active { display: block; }
.metric-grid { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 10px; }
.metric { min-height: 112px; padding: 16px; border: 1px solid var(--line); border-top: 2px solid var(--cyan); border-radius: var(--radius); background: var(--surface); }
.metric span { color: var(--muted); font-size: 12px; }
.metric strong { display: block; margin: 12px 0 7px; font-size: 26px; line-height: 1; }
.metric small { color: #75858c; }
.metric-alert { border-top-color: var(--red); }

.section-band { margin-top: 18px; border-top: 1px solid var(--line); background: var(--surface); }
.section-band.flush { margin-top: 0; }
.section-heading { min-height: 64px; display: flex; align-items: center; justify-content: space-between; padding: 0 14px; border-bottom: 1px solid var(--line); }
.section-heading h2 { margin: 0; font-size: 15px; }
.section-heading p { margin: 5px 0 0; color: var(--muted); font-size: 11px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; table-layout: auto; }
th { height: 38px; padding: 0 12px; color: #83949b; background: #0e1315; border-bottom: 1px solid var(--line); font-size: 11px; font-weight: 600; text-align: left; white-space: nowrap; }
td { height: 48px; padding: 7px 12px; border-bottom: 1px solid var(--line-soft); white-space: nowrap; vertical-align: middle; }
tbody tr:hover { background: #151b1e; }
.strategy-table table { min-width: 1450px; }
.account-select { min-width: 132px; height: 30px; padding: 0 28px 0 8px; font-size: 12px; }
.monitor-checkbox { width: 18px; height: 18px; padding: 0; accent-color: var(--green); cursor: pointer; }
.empty-row { height: 96px; color: var(--muted); text-align: center; }
.primary-cell { font-weight: 650; }
.secondary-cell { display: block; margin-top: 3px; color: var(--muted); font-size: 11px; }
.value-positive { color: var(--green); }
.value-negative { color: var(--red); }
.value-warning { color: var(--amber); }
.value-muted { color: var(--muted); }
.tag { display: inline-block; min-width: 42px; padding: 3px 7px; border-radius: 3px; text-align: center; font-size: 11px; }
.tag-buy, .tag-open { color: var(--green); background: #13382b; }
.tag-sell, .tag-close { color: var(--red); background: #3a1a1e; }
.tag-warning { color: var(--amber); background: #332a15; }
.tag-resize { color: var(--amber); background: #3d3016; }
.tag-neutral { color: var(--muted); background: #252d31; }

.toolbar { min-height: 58px; display: flex; align-items: center; gap: 12px; padding: 0 12px; border: 1px solid var(--line); background: var(--surface); }
.hub-banner { min-height: 52px; display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 0 14px; border: 1px solid #725b2c; border-left: 3px solid var(--amber); background: #211d13; }
.hub-banner > div { display: flex; align-items: center; gap: 9px; }
.hub-banner strong { color: var(--amber); font-size: 13px; }
.hub-banner small { color: var(--muted); }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--amber); box-shadow: 0 0 0 3px #f5bd5225; }
.hub-metric-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); margin-top: 12px; }
.hub-create-form { display: grid; grid-template-columns: minmax(220px, 1fr) minmax(220px, 1fr) auto; align-items: end; gap: 12px; padding: 14px; border-bottom: 1px solid var(--line); }
.hub-create-form .button { height: 36px; }
#hubClusterRows tr.selected { background: #14231d; box-shadow: inset 3px 0 var(--green); }
.hub-route-multiplier { width: 112px; min-width: 112px; height: 30px; }
.hub-cluster-editor { width: 180px; min-width: 180px; height: 30px; }
.hub-capture-switch { min-width: 92px; }
.hub-capture-switch span { color: var(--muted); font-size: 11px; }
#hubRouteRows table, #hubEventRows table { min-width: 1100px; }
.segmented { display: flex; padding: 3px; background: #0b0f11; border: 1px solid var(--line); border-radius: 5px; }
.segmented button { min-height: 29px; padding: 0 12px; border: 0; border-radius: 3px; color: var(--muted); background: transparent; }
.segmented button.active { color: #07120e; background: var(--green); font-weight: 650; }
.search-input { width: 260px; margin-left: auto; }

input, select, textarea { width: 100%; border: 1px solid var(--line); border-radius: 4px; color: var(--text); background: #0c1113; outline: none; }
input, select { height: 36px; padding: 0 10px; }
textarea { padding: 10px; resize: vertical; line-height: 1.5; }
input:focus, select:focus, textarea:focus { border-color: var(--cyan); }
label > span { display: block; margin-bottom: 7px; color: var(--muted); font-size: 12px; }
.settings-grid { display: grid; grid-template-columns: 1.25fr 1fr; gap: 14px; align-items: start; }
.settings-block { border: 1px solid var(--line); background: var(--surface); }
.settings-block form { padding: 16px; }
.settings-account-pool { grid-row: span 2; }
.settings-audit { grid-column: 1 / -1; }
.audit-table table { min-width: 980px; }
.audit-detail { display: block; max-width: 520px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); }
.account-pool-table { border-top: 1px solid var(--line); }
.account-pool-table table { min-width: 620px; }
.account-name-editor { min-width: 180px; height: 30px; }
.table-actions { display: flex; align-items: center; gap: 6px; }
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; }
.form-stack { display: grid; gap: 14px; }
.check-line { grid-column: 1 / -1; display: flex; align-items: center; gap: 8px; }
.check-line input { width: 16px; height: 16px; }
.check-line span { margin: 0; }

.toast { position: fixed; right: 22px; bottom: 22px; max-width: 420px; padding: 12px 16px; border: 1px solid var(--line); border-radius: 5px; color: var(--text); background: #1c2428; box-shadow: 0 12px 40px #0008; opacity: 0; transform: translateY(8px); pointer-events: none; transition: .16s ease; }
.toast.show { opacity: 1; transform: none; }
.toast.error { color: #ffd5d7; border-color: #7b373c; background: #371b1e; }

.login-body { min-height: 100vh; display: grid; place-items: center; background: #0a0d0f; }
.login-shell { width: min(420px, calc(100vw - 32px)); }
.login-panel { padding: 28px; border: 1px solid var(--line); border-top: 3px solid var(--green); border-radius: 7px; background: var(--surface); box-shadow: 0 24px 70px #0009; }
.brand-lockup { display: flex; align-items: center; gap: 13px; margin-bottom: 24px; }
.brand-lockup h1 { margin: 0; font-size: 21px; }
.brand-lockup p { margin: 5px 0 0; color: var(--muted); font-size: 12px; }
.login-form { display: grid; gap: 16px; }
.login-panel footer { margin-top: 20px; color: #64747b; font-size: 11px; text-align: center; }
.alert { margin-bottom: 16px; padding: 10px 12px; border-radius: 4px; }
.alert-error { color: #ffd3d5; border: 1px solid #71343a; background: #2c171a; }

@media (max-width: 1300px) {
  .metric-grid { grid-template-columns: repeat(3, 1fr); }
  .settings-grid { grid-template-columns: 1fr; }
}
