:root {
  color-scheme: dark;
  font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  --bg: #071321;
  --bg-deep: #050d17;
  --surface: rgba(18, 39, 59, .78);
  --surface-strong: rgba(20, 44, 67, .94);
  --surface-soft: rgba(31, 57, 81, .56);
  --border: rgba(116, 157, 190, .22);
  --border-strong: rgba(119, 170, 211, .38);
  --text: #eef5fc;
  --muted: #91a5b9;
  --muted-strong: #b9c8d7;
  --primary: #1878f2;
  --primary-hover: #2d89ff;
  --green: #21ce77;
  --orange: #ffad1f;
  --red: #ff5a5f;
  --purple: #9f65f5;
  --shadow: 0 18px 50px rgba(0, 6, 14, .28);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { min-width: 320px; background: var(--bg-deep); }
body {
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  background:
    radial-gradient(circle at 72% 12%, rgba(19, 91, 164, .18), transparent 36%),
    radial-gradient(circle at 12% 72%, rgba(16, 83, 142, .13), transparent 32%),
    linear-gradient(145deg, #06111e 0%, #0b1c2d 55%, #071523 100%);
}
body::before {
  position: fixed;
  inset: 0;
  pointer-events: none;
  content: "";
  opacity: .22;
  background-image: linear-gradient(rgba(130, 174, 207, .03) 1px, transparent 1px), linear-gradient(90deg, rgba(130, 174, 207, .03) 1px, transparent 1px);
  background-size: 32px 32px;
}
button, input { font: inherit; }
button { color: inherit; }
h1, h2, h3, h4, p { margin-top: 0; }
h1 { font-size: 22px; }
h2 { font-size: 20px; }
h3 { font-size: 17px; }
p { color: var(--muted); line-height: 1.6; }

.brand-mark {
  position: relative;
  display: inline-block;
  width: 38px;
  height: 38px;
  flex: 0 0 38px;
  border: 8px solid #2081ff;
  border-radius: 50%;
  box-shadow: 0 0 22px rgba(32, 129, 255, .3);
}
.brand-mark::after {
  position: absolute;
  right: -10px;
  bottom: -9px;
  width: 11px;
  height: 11px;
  content: "";
  border: 3px solid #071321;
  border-radius: 50%;
  background: #2081ff;
}

.topbar {
  position: sticky;
  z-index: 10;
  top: 0;
  display: flex;
  min-height: 72px;
  padding: 0 24px;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
  background: rgba(5, 17, 30, .84);
  backdrop-filter: blur(16px);
}
.topbar-brand, .login-brand { display: flex; gap: 14px; align-items: center; }
.topbar-brand div, .login-brand div { display: flex; flex-direction: column; gap: 3px; }
.topbar-brand strong { font-size: 18px; letter-spacing: .02em; }
.topbar-brand span, .login-brand span { color: var(--muted); font-size: 13px; }
.topbar-actions { display: flex; align-items: center; gap: 18px; }
.topbar-divider { width: 1px; height: 28px; background: var(--border); }
.service-state { display: flex; color: var(--green); font-size: 14px; gap: 9px; align-items: center; }
.service-state i { width: 8px; height: 8px; border-radius: 50%; background: currentColor; box-shadow: 0 0 10px currentColor; }
.admin-name { display: flex; gap: 9px; align-items: center; font-size: 14px; }
.admin-name svg { width: 28px; height: 28px; padding: 5px; border-radius: 50%; background: #6c7988; }

.page-shell { position: relative; max-width: 1480px; margin: 0 auto; padding: 20px 22px 36px; }
.summary-row { display: grid; grid-template-columns: repeat(4, minmax(155px, 1fr)) minmax(310px, 1.5fr); gap: 14px; }
.summary-card {
  display: flex;
  min-height: 92px;
  padding: 17px;
  gap: 14px;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: linear-gradient(135deg, rgba(27, 51, 74, .9), rgba(18, 39, 58, .72));
  box-shadow: 0 10px 30px rgba(0, 7, 16, .12);
}
.summary-card > div { display: flex; flex-direction: column; gap: 4px; }
.summary-card span { color: var(--muted-strong); font-size: 13px; }
.summary-card strong { font-size: 25px; font-weight: 600; font-variant-numeric: tabular-nums; }
.summary-icon { display: grid; width: 48px; height: 48px; border-radius: 9px; place-items: center; }
.summary-icon svg { width: 27px; height: 27px; }
.summary-icon.blue { color: #4d9cff; background: rgba(37, 118, 210, .16); }
.summary-icon.purple { color: var(--purple); background: rgba(133, 82, 212, .15); }
.summary-icon.green { color: var(--green); background: rgba(33, 206, 119, .12); }
.summary-icon.red { color: var(--red); background: rgba(255, 90, 95, .12); }
.summary-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; align-items: center; padding-left: 10px; }

.button {
  display: inline-flex;
  min-height: 40px;
  padding: 9px 16px;
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  cursor: pointer;
  transition: border-color .16s ease, background .16s ease, opacity .16s ease, transform .16s ease;
  gap: 8px;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
}
.button svg { width: 17px; height: 17px; }
.button:hover:not(:disabled) { transform: translateY(-1px); }
.button.primary { border-color: #2788ff; background: linear-gradient(180deg, #2084ff, #1167d3); box-shadow: 0 8px 24px rgba(24, 120, 242, .2); }
.button.primary:hover:not(:disabled) { background: var(--primary-hover); }
.button.outline, .button.ghost { border-color: var(--border-strong); background: rgba(15, 35, 53, .46); color: #d6e3ee; }
.button.outline:hover:not(:disabled), .button.ghost:hover:not(:disabled) { border-color: rgba(123, 180, 226, .62); background: rgba(31, 61, 88, .7); }
.button.danger { border-color: rgba(255, 90, 95, .65); background: rgba(125, 36, 44, .2); color: #ff7b7f; }
.button.danger.filled { background: linear-gradient(180deg, #e84347, #bd292d); color: white; }
.button.text-button { padding-left: 0; border: 0; color: var(--muted-strong); }
.button.wide { width: 100%; }
.button:disabled { cursor: not-allowed; opacity: .5; transform: none; }

.tree-panel, .reconcile-panel, .relationship-panel {
  margin-top: 16px;
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: linear-gradient(145deg, rgba(18, 42, 64, .88), rgba(12, 31, 49, .8));
  box-shadow: var(--shadow);
}
.section-heading { display: flex; min-height: 38px; margin-bottom: 14px; align-items: center; justify-content: space-between; gap: 24px; }
.section-heading h1, .section-heading h2 { margin-bottom: 0; }
.section-heading p { margin-bottom: 0; font-size: 13px; }
.section-heading > p { text-align: right; }
.eyebrow { margin-bottom: 4px; color: #5f9fdf !important; font-size: 11px !important; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; }
.account-tree { display: flex; flex-direction: column; gap: 13px; }
.empty-state { display: grid; min-height: 180px; padding: 28px; text-align: center; place-items: center; border: 1px dashed var(--border-strong); border-radius: 9px; background: rgba(7, 22, 36, .35); }
.empty-state svg { width: 44px; height: 44px; margin-bottom: 10px; color: #6f879a; }
.empty-state h3 { margin-bottom: 4px; }
.empty-state p { margin-bottom: 0; }

.leader-group { position: relative; overflow: hidden; border: 1px solid var(--border-strong); border-radius: 10px; background: rgba(12, 31, 49, .54); }
.leader-head { display: flex; min-height: 70px; padding: 13px 16px; align-items: center; justify-content: space-between; gap: 18px; }
.account-identity { display: flex; min-width: 0; align-items: center; gap: 11px; }
.platform-logo { display: grid; width: 35px; height: 35px; flex: 0 0 35px; border-radius: 7px; background: #eff3f6; color: #09121b; place-items: center; }
.platform-logo.binance { color: #f5b612; background: transparent; }
.platform-logo svg { width: 29px; height: 29px; }
.identity-copy { min-width: 0; }
.identity-title { display: flex; margin-bottom: 7px; flex-wrap: wrap; align-items: center; gap: 8px; }
.identity-title h2, .identity-title h3 { overflow: hidden; margin: 0; text-overflow: ellipsis; white-space: nowrap; }
.metadata { display: flex; color: var(--muted); font-size: 13px; flex-wrap: wrap; align-items: center; gap: 8px 14px; }
.metadata-item { display: inline-flex; gap: 6px; align-items: center; }
.metadata-item svg { width: 15px; height: 15px; }
.account-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
.account-actions .button { min-height: 36px; padding: 7px 13px; font-size: 13px; }
.collapse-button { width: 34px; min-width: 34px; padding: 0 !important; }
.collapse-button svg { transition: transform .18s ease; }
.leader-group.collapsed .collapse-button svg { transform: rotate(-90deg); }
.leader-body { padding: 0 16px 16px; }
.leader-group.collapsed .leader-body { display: none; }

.badge { display: inline-flex; min-height: 24px; padding: 3px 8px; border: 1px solid transparent; border-radius: 5px; font-size: 12px; align-items: center; }
.badge.role { color: #61a8ff; background: rgba(23, 104, 205, .18); }
.badge.follower-role { color: #bb89ff; background: rgba(125, 71, 198, .18); }
.badge.demo { color: #78b7ff; border-color: rgba(50, 129, 226, .25); background: rgba(26, 104, 198, .18); }
.badge.live, .badge.error { color: #ff777b; border-color: rgba(255, 90, 95, .23); background: rgba(255, 90, 95, .13); }
.badge.running, .badge.enabled { color: var(--green); background: rgba(33, 206, 119, .12); }
.badge.waiting, .badge.reconciling { color: var(--orange); background: rgba(255, 173, 31, .13); }
.badge.paused { color: #a9b8c7; background: rgba(151, 169, 186, .12); }

.environment-warning, .error-banner, .risk-note, .info-banner { display: flex; margin: 0 0 12px; padding: 10px 12px; border: 1px solid; border-radius: 7px; font-size: 13px; line-height: 1.5; gap: 8px; align-items: flex-start; }
.environment-warning, .risk-note { border-color: rgba(255, 173, 31, .38); background: rgba(116, 76, 4, .2); color: var(--orange); }
.error-banner { border-color: rgba(255, 90, 95, .42); background: rgba(119, 30, 38, .19); color: #ff777b; }
.info-banner { border-color: var(--border); background: rgba(28, 56, 80, .46); color: var(--muted); }
.environment-warning svg, .error-banner svg, .info-banner svg { width: 17px; height: 17px; flex: 0 0 17px; margin-top: 1px; }
.positions-card { overflow: auto; margin-bottom: 12px; padding: 12px; border: 1px solid var(--border); border-radius: 8px; background: rgba(20, 43, 64, .52); }
.positions-card h4 { margin-bottom: 10px; color: var(--muted-strong); font-size: 13px; font-weight: 500; }
.positions-card .empty-inline { min-height: 55px; margin: 0; display: flex; align-items: center; justify-content: center; color: var(--muted); }

table { width: 100%; border-spacing: 0; border-collapse: separate; color: #dce8f2; font-size: 13px; font-variant-numeric: tabular-nums; }
th { color: #9fb2c5; background: rgba(34, 61, 84, .54); font-weight: 500; white-space: nowrap; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: rgba(45, 80, 109, .16); }
.positions-card table { min-width: 520px; }

.followers-tree { position: relative; display: flex; margin: 4px 0 0 48px; padding-left: 30px; flex-direction: column; gap: 11px; }
.followers-tree::before { position: absolute; top: -12px; bottom: 38px; left: 0; width: 2px; content: ""; background: rgba(103, 145, 178, .55); }
.follower-card { position: relative; padding: 13px 14px; border: 1px solid var(--border-strong); border-radius: 8px; background: rgba(16, 37, 56, .78); }
.follower-card::before { position: absolute; top: 33px; left: -31px; width: 30px; height: 2px; content: ""; background: rgba(103, 145, 178, .55); }
.follower-card::after { position: absolute; top: 28px; left: -9px; width: 8px; height: 8px; content: ""; border-top: 2px solid rgba(103, 145, 178, .8); border-right: 2px solid rgba(103, 145, 178, .8); transform: rotate(45deg); }
.follower-card.error-card { border-color: rgba(255, 73, 79, .68); }
.follower-main { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.follower-card .positions-card { margin-top: 12px; margin-bottom: 0; }

.detail-title { display: flex; min-height: 50px; align-items: center; gap: 18px; }
.detail-title > span { width: 1px; height: 28px; background: var(--border-strong); }
.detail-title h1 { margin: 0; }
.relationship-panel { display: grid; min-height: 180px; padding: 24px; grid-template-columns: minmax(520px, .95fr) 1.35fr; gap: 28px; align-items: center; }
.relation-flow { display: grid; grid-template-columns: 1fr 50px 1fr; align-items: center; gap: 8px; }
.relation-account { min-height: 100px; padding: 14px; border: 1px solid var(--border); border-radius: 8px; background: rgba(29, 56, 80, .48); }
.relation-account > span { display: block; margin-bottom: 12px; color: var(--muted); font-size: 12px; }
.relation-arrow { color: #7790a5; }
.relation-arrow svg { width: 44px; }
.relation-info { display: grid; padding-left: 28px; border-left: 1px solid var(--border); grid-template-columns: repeat(3, minmax(100px, 1fr)); gap: 18px; }
.relation-metric span { display: block; margin-bottom: 8px; color: var(--muted); font-size: 12px; }
.relation-metric strong { font-size: 14px; font-weight: 500; }
.relation-buttons { display: flex; grid-column: 1 / -1; justify-content: flex-end; gap: 10px; }
.relation-buttons .button { min-width: 130px; }
.reconcile-panel { margin-top: 18px; }
.reconcile-table-wrap { overflow-x: auto; border: 1px solid var(--border-strong); border-radius: 8px; }
.reconcile-table { min-width: 980px; }
.reconcile-table th, .reconcile-table td { height: 56px; text-align: center; }
.difference { display: flex; flex-direction: column; gap: 3px; }
.difference strong { color: var(--orange); font-size: 14px; }
.difference.consistent strong { color: var(--green); }
.difference span { color: var(--muted); font-size: 11px; }
.in-flight { color: #67aaff; }

.toast { position: fixed; z-index: 30; top: 82px; right: 22px; max-width: min(460px, calc(100vw - 44px)); padding: 11px 15px; border: 1px solid var(--border-strong); border-radius: 8px; background: rgba(20, 44, 66, .96); box-shadow: var(--shadow); color: #dbe8f3; opacity: 0; pointer-events: none; transform: translateY(-8px); transition: .2s ease; }
.toast:not(:empty) { opacity: 1; transform: translateY(0); }
.toast.error { border-color: rgba(255, 90, 95, .48); color: #ff8589; }

.login-view { position: relative; display: grid; min-height: 100vh; padding: 28px; overflow: hidden; place-items: center; }
.login-glow { position: absolute; width: 560px; height: 560px; border-radius: 50%; background: rgba(19, 114, 228, .14); filter: blur(90px); }
.login-card { position: relative; width: min(440px, 100%); padding: 34px; border: 1px solid var(--border-strong); border-radius: 14px; background: linear-gradient(145deg, rgba(20, 44, 66, .95), rgba(9, 26, 42, .94)); box-shadow: 0 30px 90px rgba(0, 5, 12, .5); }
.login-brand { margin-bottom: 30px; }
.login-brand strong { font-size: 20px; }
.login-copy { margin-bottom: 24px; }
.login-copy h1 { margin-bottom: 9px; font-size: 26px; }
.login-copy p { margin-bottom: 0; }
.login-footnote { margin: 20px 0 0; text-align: center; font-size: 12px; }

.form-stack { display: flex; flex-direction: column; gap: 15px; }
label, legend { color: var(--muted-strong); font-size: 13px; }
label { display: block; }
input {
  display: block;
  width: 100%;
  height: 44px;
  margin-top: 7px;
  padding: 0 13px;
  border: 1px solid var(--border-strong);
  outline: 0;
  border-radius: 7px;
  background: rgba(13, 31, 48, .82);
  color: var(--text);
  transition: border-color .16s ease, box-shadow .16s ease;
}
input::placeholder { color: #60788d; }
input:focus { border-color: #348df2; box-shadow: 0 0 0 3px rgba(52, 141, 242, .12); }
.input-shell { position: relative; display: block; }
.input-shell input { padding-right: 46px; }
.icon-button { display: grid; padding: 0; border: 0; background: transparent; color: #aabccc; cursor: pointer; place-items: center; }
.input-shell .icon-button { position: absolute; top: 7px; right: 0; width: 44px; height: 44px; }
.icon-button svg { width: 19px; height: 19px; }
.form-message { display: none; padding: 10px 12px; border: 1px solid rgba(255, 90, 95, .44); border-radius: 7px; background: rgba(112, 27, 35, .22); color: #ff7d81; font-size: 13px; line-height: 1.5; }
.form-message:not(:empty) { display: block; }
.form-message.info { border-color: var(--border-strong); background: rgba(28, 56, 80, .46); color: var(--muted-strong); }

.modal { width: min(650px, calc(100vw - 32px)); max-height: calc(100vh - 40px); padding: 0; overflow: auto; border: 1px solid var(--border-strong); border-radius: 12px; background: linear-gradient(145deg, #142d44, #0c2134); color: var(--text); box-shadow: 0 32px 100px rgba(0, 4, 10, .58); }
.modal::backdrop { background: rgba(2, 10, 18, .76); backdrop-filter: blur(8px); }
.modal form, .confirm-modal { padding: 24px 26px; }
.large-modal { width: min(790px, calc(100vw - 32px)); }
.small-modal { width: min(520px, calc(100vw - 32px)); }
.modal-head { display: flex; margin-bottom: 22px; justify-content: space-between; gap: 18px; }
.modal-head h2 { margin-bottom: 5px; }
.modal-head p { margin-bottom: 0; font-size: 13px; }
.modal-close { width: 32px; height: 32px; flex: 0 0 32px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.full-row { grid-column: 1 / -1; }
fieldset { min-width: 0; margin: 0; padding: 0; border: 0; }
legend { margin-bottom: 8px; }
.segments { display: grid; grid-template-columns: 1fr 1fr; overflow: hidden; border: 1px solid var(--border-strong); border-radius: 7px; }
.segments label { margin: 0; }
.segments input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.segments span { display: grid; height: 44px; cursor: pointer; color: var(--muted-strong); place-items: center; }
.segments label + label span { border-left: 1px solid var(--border-strong); }
.segments input:checked + span { background: linear-gradient(180deg, #2084ff, #146bd7); color: white; }
.option-field { padding: 13px 14px; border: 1px solid var(--border); border-radius: 8px; background: rgba(12, 29, 44, .4); }
.option-row { display: flex; gap: 22px; }
label.check { display: flex; margin: 0; cursor: pointer; align-items: flex-start; gap: 9px; }
label.check input { width: 17px; height: 17px; margin: 1px 0 0; accent-color: var(--primary); }
.risk-field { display: flex; flex-direction: column; gap: 12px; }
.risk-note { margin: 16px 0 0; }
.field-help { margin: 8px 0 16px; font-size: 12px; }
.modal-actions { display: flex; margin-top: 20px; justify-content: flex-end; gap: 10px; }
.modal-actions .button { min-width: 118px; }
.confirm-modal { text-align: center; }
.confirm-icon { display: grid; width: 52px; height: 52px; margin: 0 auto 15px; border-radius: 50%; background: rgba(255, 90, 95, .13); color: var(--red); place-items: center; }
.confirm-icon svg { width: 26px; height: 26px; }
.confirm-modal h2 { margin-bottom: 8px; }
.confirm-modal p { white-space: pre-line; }
.confirm-modal .modal-actions { justify-content: center; }

.spinner { width: 16px; height: 16px; border: 2px solid rgba(255,255,255,.3); border-top-color: white; border-radius: 50%; animation: spin .75s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 1100px) {
  .summary-row { grid-template-columns: repeat(2, 1fr); }
  .summary-actions { padding-left: 0; }
  .relationship-panel { grid-template-columns: 1fr; }
  .relation-info { padding: 20px 0 0; border-top: 1px solid var(--border); border-left: 0; }
  .follower-main, .leader-head { align-items: flex-start; flex-direction: column; }
  .account-actions { justify-content: flex-start; }
}

@media (max-width: 760px) {
  .topbar { padding: 12px 14px; }
  .topbar-brand span, .topbar-divider, .service-state, .admin-name { display: none; }
  .page-shell { padding: 14px; }
  .summary-row { grid-template-columns: 1fr 1fr; }
  .summary-actions { grid-column: 1 / -1; }
  .tree-panel, .reconcile-panel, .relationship-panel { padding: 13px; }
  .section-heading { align-items: flex-start; flex-direction: column; gap: 8px; }
  .section-heading > p { text-align: left; }
  .leader-head { padding: 13px; }
  .leader-body { padding: 0 13px 13px; }
  .followers-tree { margin-left: 10px; padding-left: 20px; }
  .follower-card::before { left: -21px; width: 20px; }
  .relation-flow { grid-template-columns: 1fr; }
  .relation-arrow { transform: rotate(90deg); text-align: center; }
  .relation-info { grid-template-columns: 1fr 1fr; }
  .relation-buttons { flex-wrap: wrap; justify-content: stretch; }
  .relation-buttons .button { flex: 1; }
  .form-grid { grid-template-columns: 1fr; }
  .full-row { grid-column: auto; }
  .modal form { padding: 20px; }
}

@media (max-width: 480px) {
  .summary-row { grid-template-columns: 1fr; }
  .summary-actions { grid-column: auto; }
  .summary-card { min-height: 78px; }
  .login-view { padding: 14px; }
  .login-card { padding: 25px 20px; }
  .account-actions { width: 100%; }
  .account-actions .button { flex: 1; }
  .relation-info { grid-template-columns: 1fr; }
}
