* { box-sizing: border-box; }

:root {
  --bg: #000000;
  --card: #121212;
  --chip: #1e1e1e;
  --line: #1a1a1a;
  --dim: #707070;
  --secondary: #8e8e93;
  --text: #ffffff;
  --green: #25a750;
  --red: #ca3f64;
  --danger: #e04a5e;
  --amber: #cea463;
  --ease: cubic-bezier(.22, 1, .36, 1);
  --control-motion: 160ms var(--ease);
  --gutter: clamp(16px, 2.8vw, 52px);
  color-scheme: dark;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", Inter, sans-serif;
  font-variant-numeric: tabular-nums;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.45;
}
button, input, select { font: inherit; font-variant-numeric: inherit; color: inherit; }
button { cursor: pointer; background: transparent; border: 0; padding: 0; }
button {
  transition: background-color var(--control-motion), border-color var(--control-motion),
    color var(--control-motion), transform var(--control-motion);
}
button:where(:not(#scrim)):active:not(:disabled) { transform: scale(.975); }
button:disabled { cursor: not-allowed; opacity: .48; }
:where(button, select, input):focus-visible { outline: 2px solid #bdbdbd; outline-offset: 3px; }
h1, h2, h3, dl, dd { margin: 0; }
h1, h2 { font-size: 15px; font-weight: 650; }
h3 { font-size: 19px; line-height: 1.2; font-weight: 600; letter-spacing: -.035em; }
.positive { color: var(--green); }
.negative { color: var(--red); }
.warn { color: var(--amber); }
.muted, .field, dt { color: var(--secondary); }

.topbar, main { width: 100%; padding-inline: var(--gutter); }
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  min-height: 52px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 6px; font: 750 20px/1 Arial, sans-serif; letter-spacing: -1px; }
.brand svg { width: 22px; height: 22px; }
.terminal { border-left: 1px solid #303030; padding-left: 16px; font-size: 13px; color: var(--secondary); }
.actions { margin-left: auto; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.connection { display: inline-flex; align-items: center; gap: 5px; margin-right: 6px; color: var(--secondary); font-size: 11px; }
.connection b { font-weight: 500; color: #ddd; }
.statusdot, .connection i {
  display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: var(--dim); flex: none;
}
.statusdot.on, .connection .on { background: var(--green); animation: online-breathe 2s var(--ease) infinite; }
.statusdot.off, .connection .off, .statusdot.live { background: var(--danger); }
.statusdot.warn, .connection .warn { background: var(--amber); }
@keyframes online-breathe { 0%, 80%, 100% { opacity: 1; } 90% { opacity: .72; } }

.actions button, button.primary, .dialog-actions button {
  height: 30px; padding: 0 14px; border-radius: 999px; border: 1px solid #3a3a3a;
  font-size: 12px; font-weight: 500; white-space: nowrap;
}
.actions button:hover:not(:disabled), .dialog-actions button:hover:not(:disabled) { background: var(--card); }
.actions .danger { border-color: rgba(224, 74, 94, .45); color: var(--danger); }
.actions .text-link { border: none; padding-inline: 6px; color: var(--secondary); }
.actions .text-link:hover { color: #fff; background: transparent; }
button.primary { color: #000; background: #fff; border-color: #fff; }
button.primary:hover:not(:disabled) { background: #dedede; border-color: #dedede; }

.layout { display: grid; grid-template-columns: 264px minmax(0, 1fr); min-height: calc(100vh - 52px); }
main { min-width: 0; }
#rail { border-right: 1px solid var(--line); padding: 14px 16px; }
#rail .bar { min-height: 32px; margin-bottom: 12px; }
#strategyList { display: grid; gap: 8px; }
.account-card {
  display: grid; width: 100%; gap: 7px; background: var(--card); border-radius: 10px; padding: 12px; text-align: left;
  box-shadow: inset 2px 0 transparent;
  transition: background-color var(--control-motion), box-shadow var(--control-motion);
}
.account-card:hover { background-color: #181818; }
.account-card[aria-current="true"] { background-color: #1c1c1c; box-shadow: inset 2px 0 #fff; }
.account-line { display: flex; align-items: center; gap: 7px; min-width: 0; }
.account-line strong { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-line .badge { margin-left: auto; }
.account-sub { font-size: 11px; color: var(--secondary); display: flex; justify-content: space-between; }
.rail-summary { margin-top: 18px; padding: 14px 2px; border-top: 1px solid var(--line); display: grid; gap: 8px; font-size: 12px; }
.rail-summary div { display: flex; justify-content: space-between; align-items: center; gap: 8px; }

.section-nav, .tabs { display: flex; align-items: stretch; border-bottom: 1px solid var(--line); }
.section-nav { justify-content: space-between; align-items: center; min-height: 44px; gap: 10px; }
.section-nav h1, .tabs button { position: relative; align-self: stretch; display: inline-flex; align-items: center; }
.section-nav h1::after, .tabs button::after {
  content: ""; position: absolute; bottom: -1px; left: 0; height: 2px; background: #fff;
}
.section-nav h1::after { width: 26px; }
#contextBadge { margin-right: auto; }
#asof { color: var(--dim); font-size: 11px; }

.cards {
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px; margin-block: 18px 17px;
}
.card {
  display: flex; flex-direction: column; min-width: 0; min-height: 184px;
  padding: 16px 20px; border-radius: 12px; background: var(--card);
  transition: background-color var(--control-motion);
}
.card:hover { background-color: #161616; }
.card > h2, .graph .bar { margin-bottom: 10px; }
.bar { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.details { display: grid; gap: 6px; font-size: 12px; }
.details > div { display: flex; align-items: baseline; justify-content: space-between; flex-wrap: wrap; gap: 2px 6px; }
.details dd { font-weight: 500; }
.equity-block { margin-bottom: 12px; }
.field { font-size: 12px; }
.equity-value { display: flex; align-items: baseline; gap: 6px; flex-wrap: wrap; }
#equity { font-size: clamp(24px, 2.1vw, 34px); font-weight: 620; line-height: 1.18; letter-spacing: -.045em; }
.equity-value span { color: var(--dim); font-size: 12px; }
.assets .details, .schedule, .strategy .details { margin-top: auto; }
.allocation { display: flex; height: 4px; gap: 2px; margin: 8px 0 10px; background: #242424; border-radius: 2px; overflow: hidden; }
.allocation i { display: block; min-width: 0; transition: width 200ms var(--ease); }
#poolBar { background: var(--green); }
#nakedBar { background: var(--amber); }
.schedule { display: grid; grid-template-columns: 1fr auto; align-items: baseline; gap: 2px 6px; padding-top: 10px; }
#deadbandSaved { font-size: 16px; font-weight: 550; }

.period { display: inline-flex; align-items: center; padding: 2px; border-radius: 6px; background: #1c1c1c; }
.period button { color: var(--secondary); padding: 2px 7px; font-size: 10px; line-height: 17px; border-radius: 4px; }
.period button.active { color: #fff; background: #2e2e2e; }
.legend { display: flex; align-items: center; gap: 12px; font-size: 11px; color: var(--secondary); }
.legend span::before { content: ""; display: inline-block; vertical-align: 1px; width: 5px; height: 5px; margin-right: 4px; border-radius: 50%; background: var(--green); }
.legend span + span::before { background: var(--amber); }
.chart { position: relative; min-height: 88px; flex: 1; margin-top: 4px; }
.chart svg { position: absolute; inset: 0; display: block; width: 100%; height: 100%; }
.chart text { font: 10px -apple-system, BlinkMacSystemFont, Inter, sans-serif; fill: var(--dim); }
.equity-line { fill: none; stroke: var(--green); stroke-width: 1.6; stroke-linejoin: round; stroke-linecap: round; }
.risk-line { fill: none; stroke: var(--amber); stroke-width: 1.4; stroke-linejoin: round; stroke-linecap: round; }
.chart-guide { stroke: #2a2a2a; }
.chart-cross { stroke: #777; stroke-width: 1; stroke-dasharray: 2 3; }
#tip { position: absolute; top: 1px; pointer-events: none; padding: 6px 8px; border-radius: 5px; background: #242424; color: #eee; font-size: 11px; white-space: pre-line; z-index: 5; }

.chips { display: flex; flex-wrap: wrap; gap: 5px; margin: 6px 0 10px; }
.chips span, .badge { display: inline-block; background: var(--chip); padding: 2px 7px; border-radius: 4px; font-size: 10px; line-height: 1.45; font-weight: 500; }
.badge.neutral { color: #b9b9ba; }
.badge.warn { color: var(--amber); }
.badge.positive { color: var(--green); }
.badge.negative { color: var(--danger); }

.workspace { background: var(--bg); min-width: 0; margin-bottom: 28px; }
.tabs { gap: clamp(14px, 2.1vw, 32px); overflow-x: auto; }
.tabs button { flex: none; flex-direction: column; justify-content: center; min-height: 44px; font-size: 14px; font-weight: 500; color: var(--secondary); white-space: nowrap; }
.tabs button::before { content: attr(aria-label); height: 0; overflow: hidden; visibility: hidden; font-weight: 650; }
.tabs button:hover { color: #ddd; }
.tabs .active { color: #fff; font-weight: 650; }
.tabs button::after { width: 100%; bottom: 0; transform: scaleX(0); transform-origin: left; transition: transform var(--control-motion); }
.tabs .active::after { transform: scaleX(1); }
#content { min-height: 220px; padding-top: 10px; }
.table-scroll { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; white-space: nowrap; }
td, th { text-align: right; border: none; }
td { padding: 12px 10px; line-height: 20px; font-size: 13px; border-bottom: 1px solid #141414; }
th { padding: 10px; font-size: 11px; color: var(--secondary); font-weight: 450; border-bottom: 1px solid var(--line); }
td:first-child, th:first-child { text-align: left; }
tbody tr { transition: background-color var(--control-motion); }
tbody tr:hover { background: var(--card); }
.empty { min-height: 124px; display: grid; place-items: center; color: var(--dim); font-size: 13px; }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 16px; padding: 8px 0 12px; font-size: 12px; color: var(--secondary); }
.preset-btn { color: #bbb; background: var(--chip); padding: 4px 11px; border-radius: 5px; font-size: 12px; }
.preset-btn.active { background: #fff; color: #000; }
.preset-btn:not(.active):hover { background: #2a2a2a; color: #fff; }

.stats-metrics { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin: 10px 0 16px; }
.metric, .stat-card { min-width: 0; border-radius: 12px; background: var(--card); padding: 16px; }
.metric { display: flex; flex-direction: column; gap: 6px; }
.metric strong { font-size: clamp(18px, 1.5vw, 24px); letter-spacing: -.03em; }
.metric small { color: var(--secondary); font-size: 11px; }
.riskgrid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; margin-bottom: 16px; }
.riskrow { display: flex; justify-content: space-between; gap: 8px; padding: 7px 0; font-size: 13px; border-bottom: 1px solid #181818; }
.riskrow > span { color: var(--secondary); }

.settings-grid { display: grid; grid-template-columns: minmax(260px, 1fr) minmax(260px, 1fr); gap: clamp(24px, 4vw, 64px); padding: 12px 0; }
.settings-grid fieldset, .settings-side section { margin: 0 0 18px; padding: 0 0 14px; border: 0; border-bottom: 1px solid var(--line); min-width: 0; }
.settings-grid legend, .settings-side h2 { padding: 0; margin: 0 0 8px; font-size: 15px; font-weight: 600; }
.settings-grid form > fieldset > label { display: flex; justify-content: space-between; align-items: center; gap: 12px; min-height: 36px; font-size: 13px; color: var(--secondary); }
.settings-grid input[type=number], .settings-grid select { width: 110px; padding: 5px 8px; border: 0; border-radius: 5px; background: var(--card); color: #fff; text-align: right; }
.settings-grid input[role=switch] { appearance: none; width: 31px; height: 18px; margin: 0; border-radius: 12px; background: #343434; cursor: pointer; }
.settings-grid input[role=switch]::after { content: ""; display: block; width: 12px; height: 12px; margin: 3px; border-radius: 50%; background: #fff; transition: transform var(--control-motion); }
.settings-grid input[role=switch]:checked { background: var(--green); }
.settings-grid input[role=switch]:checked::after { transform: translateX(13px); }

.hint { display: inline-grid; place-items: center; position: relative; vertical-align: middle; cursor: help; min-width: 14px; height: 14px; border: 1px solid #515151; border-radius: 50%; color: #b0b0b5; font: 500 10px/1 sans-serif; }
.hint:is(:hover, :focus)::after { content: attr(data-tip); position: absolute; left: 50%; bottom: calc(100% + 5px); transform: translateX(-50%); z-index: 10; width: max-content; max-width: min(220px, 60vw); background: #2c2c2e; color: #eee; padding: 7px 10px; border-radius: 6px; font: 400 12px/1.45 sans-serif; }

#menu, #mobileAccount { display: none; }
[hidden] { display: none !important; }
#loginScreen { min-height: 100svh; display: grid; place-items: center; padding: 16px; }
.login-card { display: grid; gap: 14px; width: min(100%, 340px); border-radius: 12px; background: var(--card); padding: 28px; }
.login-card label { display: grid; gap: 5px; font-size: 12px; color: var(--secondary); }
.login-card input { min-width: 0; border: 0; border-radius: 6px; padding: 9px 10px; background: #202020; }
#loginError { font-size: 12px; color: var(--danger); }
#loginError:empty { display: none; }

#closeMenu { position: relative; }
#closeScopes {
  position: absolute; z-index: 30; top: 100%; right: 0; width: min(310px, calc(100vw - 16px));
  padding: 6px; background: #161616; border: 1px solid #303030; border-radius: 8px;
}
.close-option { display: grid; grid-template-columns: minmax(0, 1fr) 98px; align-items: center; min-height: 43px; }
.actions .close-scope { height: auto; min-height: 36px; padding: 5px 9px; text-align: left; background: transparent; border: 0; border-radius: 5px; display: grid; width: 100%; }
.close-scope b, .close-scope small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.close-scope small { color: var(--secondary); }
.close-option:has(.flatten-now:not([hidden])) { background: #242424; border-radius: 5px; }
.actions .flatten-now { margin-inline: 8px; background: #b52f49; color: #fff; border: 0; }
dialog { color: #fff; background: var(--card); border: 0; border-radius: 12px; padding: 20px; width: min(460px, calc(100% - 24px)); }
dialog::backdrop { background: rgb(0 0 0 / 74%); }
#toast { position: fixed; bottom: 20px; right: var(--gutter); padding: 8px 14px; border-radius: 6px; background: #242424; color: #fff; font-size: 12px; max-width: 85vw; z-index: 40; }

@media (max-width: 1100px) { .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 960px) {
  .layout { display: block; }
  #menu { display: block; font-size: 19px; }
  #mobileAccount { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; }
  #rail { position: fixed; z-index: 20; inset: 0 auto 0 0; width: min(280px, 85vw); background: #0d0d0d; overflow: auto; border: 0; transform: translateX(-100%); visibility: hidden; transition: transform 180ms var(--ease), visibility 180ms var(--ease); }
  #rail.open { transform: translateX(0); visibility: visible; }
  #scrim { position: fixed; z-index: 15; inset: 0; background: #000a; }
  .riskgrid, .settings-grid, .stats-metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 640px) {
  .terminal { display: none; }
  .cards, .riskgrid, .settings-grid, .stats-metrics { grid-template-columns: minmax(0, 1fr); }
}
