:root {
  color-scheme: dark;
  font-family: "Segoe UI", Inter, Arial, sans-serif;
  font-synthesis: none;
  --bg: #070a14;
  --surface: #0b0f1f;
  --surface-2: #111728;
  --surface-3: #181f34;
  --border: rgba(255,255,255,.08);
  --border-strong: rgba(255,255,255,.14);
  --text: #f4f7fb;
  --muted: #98a4b8;
  --primary: #6366f1;
  --primary-strong: #7c6ff5;
  --positive: #33d69f;
  --negative: #ff647c;
  --warning: #f8bd4f;
  --sidebar: 260px;
  --topbar: 64px;
}

* { box-sizing: border-box; }
html { background: var(--bg); -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility; }
body { margin: 0; min-width: 320px; min-height: 100vh; background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.5; }
body::before { content: ""; position: fixed; inset: 0; z-index: -1; pointer-events: none; background: radial-gradient(900px 520px at 9% -8%, rgba(99,102,241,.19), transparent 58%), radial-gradient(760px 520px at 101% 20%, rgba(124,58,237,.13), transparent 60%), linear-gradient(180deg, #070a14 0%, #080c17 55%, #070a14 100%); }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
a { color: inherit; }
.hidden { display: none !important; }
.full-width { width: 100%; }
.section-gap { height: 16px; }
.compact-metrics { margin: 16px 0 0; }
.compact-value { font-size: 20px; }
.detail-value { margin-top: 14px; }
.notification-message { margin-top: 12px; color: var(--muted); }
.notification-time { margin-top: 10px; }
.message-success { color: var(--positive); }
.message-error { color: var(--negative); }

.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: #090d16; }
.login-card { width: min(100%, 420px); padding: 32px; background: var(--surface); border: 1px solid var(--border-strong); border-radius: 20px; }
.brand-lockup { display: flex; align-items: center; gap: 12px; margin-bottom: 32px; }
.brand-mark { display: grid; place-items: center; width: 42px; height: 42px; border-radius: 12px; background: linear-gradient(135deg, #6366f1, #7c3aed); color: #fff; font-weight: 800; letter-spacing: -.5px; }
.brand-name { font-size: 20px; font-weight: 700; letter-spacing: -.3px; }
.login-card h1 { margin: 0 0 24px; font-size: 24px; line-height: 30px; }
.field { display: grid; gap: 8px; margin-bottom: 16px; }
.field label { color: #ccd4e3; font-size: 13px; font-weight: 600; }
.field input { width: 100%; height: 44px; padding: 0 13px; color: var(--text); background: var(--surface-2); border: 1px solid var(--border); border-radius: 9px; outline: none; }
.field input:focus { border-color: var(--primary-strong); box-shadow: 0 0 0 2px rgba(88,120,255,.2); }
.request-form { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; align-items: end; }
.request-form .field { margin: 0; }
.request-form select, .request-form input { width: 100%; height: 42px; padding: 0 12px; color: var(--text); background: var(--surface-2); border: 1px solid var(--border); border-radius: 9px; outline: none; }
.request-form .primary-button { width: auto; }
.request-message { min-height: 20px; margin-top: 12px; color: var(--muted); }
.mfa-setup { display: grid; gap: 14px; max-width: 420px; margin-top: 16px; }
.mfa-qr { width: 192px; height: 192px; padding: 8px; background: #fff; border-radius: 8px; }
.primary-button, .secondary-button { min-height: 42px; padding: 0 16px; border-radius: 9px; font-weight: 650; }
.primary-button { width: 100%; color: #fff; background: var(--primary); border: 1px solid var(--primary); }
.primary-button:hover { background: var(--primary-strong); }
.secondary-button { color: var(--text); background: var(--surface-2); border: 1px solid var(--border); }
.secondary-button:hover { border-color: var(--border-strong); }
.text-button { padding: 0; color: #b8c4ff; background: none; border: 0; font-size: 13px; font-weight: 600; }
.login-actions { display: flex; justify-content: flex-end; margin: 14px 0 22px; }
.login-divider { height: 1px; margin: 20px 0; background: var(--border); }
.login-message { min-height: 20px; margin-top: 16px; color: var(--negative); font-size: 13px; }

.portal-shell { min-height: 100vh; }
.sidebar { position: fixed; inset: 0 auto 0 0; z-index: 20; width: var(--sidebar); padding: 18px 14px; background: linear-gradient(180deg, rgba(13,17,30,.98), rgba(8,11,20,.99)); border-right: 1px solid var(--border); box-shadow: 24px 0 70px rgba(0,0,0,.16); }
.sidebar .brand-lockup { margin: 0 8px 30px; }
.sidebar-nav { display: grid; gap: 4px; }
.nav-button { display: flex; align-items: center; gap: 11px; width: 100%; min-height: 42px; padding: 0 12px; color: #aeb8c9; background: transparent; border: 1px solid transparent; border-radius: 9px; text-align: left; font-weight: 600; }
.nav-button:hover { color: var(--text); background: var(--surface); }
.nav-button.active { color: #fff; background: #19213a; border-color: #293867; }
.nav-icon { width: 22px; color: currentColor; text-align: center; font-size: 12px; font-weight: 800; }
.sidebar-footer { position: absolute; right: 14px; bottom: 18px; left: 14px; }
.sidebar-footer button { width: 100%; }
.topbar { position: fixed; top: 0; right: 0; left: var(--sidebar); z-index: 15; height: var(--topbar); padding: 0 24px; display: flex; align-items: center; justify-content: space-between; gap: 16px; background: rgba(8,11,18,.98); border-bottom: 1px solid var(--border); }
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 12px; }
.mobile-menu { display: none; width: 40px; height: 40px; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 9px; }
.broker-state, .mode-state { display: inline-flex; align-items: center; min-height: 30px; padding: 0 10px; border: 1px solid var(--border); border-radius: 8px; color: #cad3e2; font-size: 12px; font-weight: 650; }
.status-dot { width: 7px; height: 7px; margin-right: 7px; border-radius: 50%; background: var(--positive); }
.profile-button { display: grid; place-items: center; width: 36px; height: 36px; color: #fff; background: var(--surface-3); border: 1px solid var(--border); border-radius: 50%; font-weight: 700; }
.icon-button { display: grid; place-items: center; width: 36px; height: 36px; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 10px; }
.portal-main { margin-left: var(--sidebar); padding: calc(var(--topbar) + 26px) 26px 36px; }
.content { width: min(100%, 1600px); margin: 0 auto; }
.page-header { min-height: 44px; margin-bottom: 18px; display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.page-header h1 { margin: 0; font-size: 24px; line-height: 30px; letter-spacing: -.35px; }
.page-actions { display: flex; align-items: center; gap: 10px; }

.status-banner { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 48px; margin-bottom: 18px; padding: 0 16px; background: var(--surface); border: 1px solid var(--border); border-radius: 11px; }
.status-banner strong { font-size: 13px; }
.timestamp { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-bottom: 16px; }
.metric-card, .panel, .strategy-card { background: linear-gradient(145deg, rgba(17,23,40,.95), rgba(10,14,27,.98)); border: 1px solid var(--border); border-radius: 20px; box-shadow: 0 18px 55px rgba(0,0,0,.12); }
.metric-card { min-height: 116px; padding: 18px; }
.metric-card:nth-child(1) { background: linear-gradient(145deg, rgba(16,185,129,.13), rgba(10,14,27,.98) 62%); }
.metric-card:nth-child(2) { background: linear-gradient(145deg, rgba(99,102,241,.13), rgba(10,14,27,.98) 62%); }
.metric-card:nth-child(3) { background: linear-gradient(145deg, rgba(124,58,237,.12), rgba(10,14,27,.98) 62%); }
.metric-label { color: var(--muted); font-size: 12px; font-weight: 650; text-transform: uppercase; letter-spacing: .5px; }
.metric-value { margin-top: 14px; font-size: 28px; line-height: 34px; font-weight: 750; letter-spacing: -.45px; font-variant-numeric: tabular-nums; }
.positive { color: var(--positive) !important; }
.negative { color: var(--negative) !important; }
.warning { color: var(--warning) !important; }
.dashboard-grid { display: grid; grid-template-columns: minmax(0, 1.45fr) minmax(320px, .8fr); gap: 16px; margin-bottom: 16px; }
.panel { min-width: 0; overflow: hidden; }
.panel-header { min-height: 52px; padding: 0 16px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--border); }
.panel-header h2 { margin: 0; font-size: 16px; line-height: 24px; }
.panel-body { padding: 16px; }
.chart-frame { height: 260px; display: grid; place-items: center; color: var(--muted); }
.chart-frame svg { width: 100%; height: 100%; overflow: visible; }
.chart-line { fill: none; stroke: var(--primary-strong); stroke-width: 2; vector-effect: non-scaling-stroke; }
.chart-grid { stroke: #242c3b; stroke-width: 1; vector-effect: non-scaling-stroke; }
.strategy-list { display: grid; gap: 12px; }
.strategy-card { padding: 16px; }
.strategy-showcase { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.strategy-hero { min-height: 205px; padding: 22px; display: flex; flex-direction: column; justify-content: space-between; }
.strategy-code { font-size: 36px; line-height: 1; font-weight: 800; letter-spacing: -1.2px; color: transparent; background: linear-gradient(110deg, #eef2ff, #9ea8ff 55%, #c4b5fd); background-clip: text; }
.strategy-contract { display: grid; grid-template-columns: auto 1fr; gap: 8px 18px; padding-top: 18px; border-top: 1px solid var(--border); color: var(--muted); }
.strategy-contract strong { color: var(--text); text-align: right; }
.source-contract { display: flex; align-items: center; gap: 12px; color: var(--muted); }
.broker-account-list { display: grid; gap: 12px; }
.broker-account-card { display: grid; grid-template-columns: 46px minmax(0, 1fr) auto; align-items: center; gap: 16px; min-height: 92px; padding: 16px 18px; background: linear-gradient(145deg, rgba(17,23,40,.94), rgba(9,13,25,.98)); border: 1px solid var(--border); border-radius: 18px; }
.broker-account-card.selected { border-color: rgba(99,102,241,.65); box-shadow: inset 0 0 0 1px rgba(99,102,241,.16), 0 18px 50px rgba(52,55,160,.12); }
.broker-logo { display: grid; place-items: center; width: 46px; height: 46px; border-radius: 14px; color: #fff; font-size: 13px; font-weight: 800; background: linear-gradient(135deg, #4f46e5, #7c3aed); box-shadow: 0 10px 28px rgba(79,70,229,.26); }
.broker-account-main { min-width: 0; }
.broker-actions { display: flex; align-items: center; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.danger-outline { color: #ff8a9a; border-color: rgba(244,63,94,.42); }
.broker-meta { display: flex; flex-wrap: wrap; gap: 8px 18px; margin-top: 9px; color: var(--muted); font-size: 12px; }
.connect-panel { background: linear-gradient(145deg, rgba(99,102,241,.08), rgba(10,14,27,.98) 44%); }
.broker-connect-form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.broker-connect-form .field { margin: 0; }
.credential-grid { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.connect-action { width: max-content; min-width: 170px; }
.field select, .broker-connect-form input { width: 100%; height: 44px; padding: 0 13px; color: var(--text); background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; outline: none; }
.field select:focus, .broker-connect-form input:focus { border-color: var(--primary-strong); box-shadow: 0 0 0 3px rgba(99,102,241,.15); }
.strategy-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.strategy-name { font-size: 15px; font-weight: 700; }
.badge { display: inline-flex; align-items: center; min-height: 24px; padding: 0 8px; border-radius: 7px; color: #bdc8da; background: var(--surface-3); border: 1px solid var(--border); font-size: 12px; font-weight: 650; }
.badge.success { color: var(--positive); border-color: rgba(51,214,159,.32); background: rgba(51,214,159,.08); }
.badge.danger { color: var(--negative); border-color: rgba(255,100,124,.32); background: rgba(255,100,124,.08); }
.table-wrap { width: 100%; overflow: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
th { height: 42px; padding: 0 12px; color: var(--muted); border-bottom: 1px solid var(--border); text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .35px; white-space: nowrap; }
td { height: 48px; padding: 0 12px; border-bottom: 1px solid #202737; white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
.empty-state { min-height: 150px; display: grid; place-items: center; color: var(--muted); font-size: 14px; }
.error-state { color: var(--negative); }
.skeleton { min-height: 110px; background: #141a26; border: 1px solid var(--border); border-radius: 12px; }

@media (max-width: 1100px) {
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dashboard-grid { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  :root { --sidebar: 0px; }
  .sidebar { width: 248px; transform: translateX(-100%); transition: transform .18s ease; }
  .sidebar.open { transform: translateX(0); }
  .mobile-menu { display: inline-grid; place-items: center; }
  .portal-main { margin-left: 0; padding: calc(var(--topbar) + 18px) 16px 28px; }
  .topbar { left: 0; padding: 0 16px; }
  .broker-state { display: none; }
  .page-header { align-items: flex-start; }
  .request-form { grid-template-columns: 1fr; }
  .strategy-showcase, .broker-connect-form, .credential-grid { grid-template-columns: 1fr; }
  .credential-grid { grid-column: auto; }
  .broker-account-card { grid-template-columns: 42px minmax(0, 1fr); }
  .broker-actions { grid-column: 1 / -1; justify-content: stretch; }
  .broker-actions button { flex: 1; }
}
@media (max-width: 520px) {
  .metric-grid { grid-template-columns: 1fr; }
  .login-card { padding: 24px 20px; }
  .page-header h1 { font-size: 22px; }
  .metric-value { font-size: 26px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; animation: none !important; }
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f3f5fb;
  --surface: #ffffff;
  --surface-2: #f6f7fb;
  --surface-3: #eef1f8;
  --border: rgba(24,32,54,.10);
  --border-strong: rgba(24,32,54,.18);
  --text: #151a2b;
  --muted: #657087;
  --positive: #07875f;
  --negative: #d93651;
}
:root[data-theme="light"] body::before { background: radial-gradient(900px 520px at 8% -8%, rgba(99,102,241,.14), transparent 58%), linear-gradient(180deg, #f7f8fd, #f1f4fa); }
:root[data-theme="light"] .sidebar { background: linear-gradient(180deg, rgba(255,255,255,.98), rgba(247,248,252,.99)); }
:root[data-theme="light"] .topbar { background: rgba(250,251,254,.98); }
:root[data-theme="light"] .metric-card,
:root[data-theme="light"] .panel,
:root[data-theme="light"] .strategy-card,
:root[data-theme="light"] .broker-account-card { background: linear-gradient(145deg, #fff, #f8f9fd); box-shadow: 0 18px 55px rgba(43,52,90,.07); }
:root[data-theme="light"] .strategy-code { background: linear-gradient(110deg, #252c54, #4f46e5 60%, #7c3aed); background-clip: text; }
:root[data-theme="light"] .nav-button { color: #657087; }
:root[data-theme="light"] .nav-button:hover { color: #20263a; background: #f0f2f8; }
:root[data-theme="light"] .nav-button.active { color: #fff; background: #17203f; border-color: #17203f; }
:root[data-theme="light"] .field label { color: #4f5a72; }
:root[data-theme="light"] .broker-meta,
:root[data-theme="light"] .metric-label,
:root[data-theme="light"] .timestamp { color: #657087; }
:root[data-theme="light"] .badge { color: #465069; }
