:root {
  color-scheme: dark;
  --bg: #070a10;
  --panel: #10151f;
  --panel-2: #151b27;
  --line: #242d3b;
  --text: #f2f5fb;
  --muted: #8e9bad;
  --blue: #4d7cff;
  --green: #25c28a;
  --yellow: #e6aa3b;
  --red: #f15f6d;
  --radius: 16px;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg); }
body { margin: 0; min-height: 100vh; background: radial-gradient(circle at 50% -20%, #15213a 0, var(--bg) 38rem); color: var(--text); }
button, input, select { font: inherit; }
button { cursor: pointer; }

.topbar { height: 68px; padding: 0 max(24px, calc((100vw - 1480px) / 2)); display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); background: rgb(7 10 16 / 82%); backdrop-filter: blur(18px); position: sticky; top: 0; z-index: 20; }
.brand { color: var(--text); display: inline-flex; align-items: center; gap: 11px; font-weight: 800; letter-spacing: .08em; text-decoration: none; }
.brand-mark { width: 34px; height: 34px; display: inline-grid; place-items: center; border-radius: 10px; color: white; background: linear-gradient(145deg, #638dff, #345ce4); box-shadow: 0 8px 25px rgb(77 124 255 / 26%); font-weight: 900; }
.top-actions { display: flex; align-items: center; gap: 12px; }
.top-actions form { margin: 0; }
.runtime-load { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 10px; font-variant-numeric: tabular-nums; }
.runtime-load span { padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px; background: #0b1018; white-space: nowrap; }
.runtime-load b { color: #cbd5e4; font-weight: 700; }
.link-button, .icon-button { border: 0; color: var(--muted); background: transparent; }
.link-button:hover, .icon-button:hover { color: var(--text); }
.icon-button { width: 38px; height: 38px; border-radius: 9px; border: 1px solid var(--line); font-size: 20px; }

.dashboard { width: min(1480px, calc(100% - 48px)); margin: 0 auto; padding: 40px 0 70px; }
.hero-row, .section-title { display: flex; justify-content: space-between; align-items: center; gap: 20px; }
.hero-row { margin-bottom: 24px; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: clamp(27px, 3vw, 40px); letter-spacing: -.04em; }
h2 { margin-bottom: 6px; font-size: 18px; letter-spacing: -.015em; }
.eyebrow { margin-bottom: 8px; color: var(--blue); font-size: 12px; font-weight: 800; letter-spacing: .12em; }
.section-title p { margin-bottom: 0; color: var(--muted); font-size: 13px; }

.card { border: 1px solid var(--line); border-radius: var(--radius); background: linear-gradient(150deg, rgb(20 27 39 / 94%), rgb(13 18 27 / 94%)); box-shadow: 0 18px 55px rgb(0 0 0 / 20%); }
.metrics { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 14px; }
.metric { min-height: 138px; padding: 22px; display: flex; flex-direction: column; }
.metric span, .metric small { color: var(--muted); font-size: 13px; }
.metric strong { margin: auto 0 3px; font-size: clamp(23px, 2.2vw, 32px); letter-spacing: -.04em; font-variant-numeric: tabular-nums; }
.metric strong.positive, #chart-value.positive { color: var(--green); }
.metric strong.negative, #chart-value.negative { color: var(--red); }

.layout-grid { display: grid; grid-template-columns: 390px minmax(0, 1fr); gap: 14px; margin-bottom: 14px; }
.control-card, .trade-card, .chart-card { padding: 22px; }
.settings-grid { margin-top: 24px; display: grid; grid-template-columns: 1fr 100px; gap: 13px; }
label { display: grid; gap: 8px; color: #bec7d5; font-size: 13px; font-weight: 650; }
input, select { width: 100%; min-height: 44px; padding: 0 13px; color: var(--text); border: 1px solid var(--line); border-radius: 10px; outline: 0; background: #0b1018; font-variant-numeric: tabular-nums; }
input:focus, select:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgb(77 124 255 / 14%); }
.margin-hint { grid-column: 1 / -1; padding: 11px 13px; border-radius: 10px; color: var(--muted); background: rgb(77 124 255 / 8%); font-size: 13px; }
.margin-hint strong { color: var(--text); float: right; }
.settings-grid .button { grid-column: 1 / -1; }
.button-stack { display: grid; gap: 9px; margin-top: 9px; }
.button { min-height: 44px; padding: 0 16px; border: 1px solid transparent; border-radius: 10px; color: white; font-weight: 750; transition: filter .15s, opacity .15s, transform .15s; }
.button:hover:not(:disabled) { filter: brightness(1.08); transform: translateY(-1px); }
.button:disabled { cursor: not-allowed; opacity: .42; }
.button.primary { background: var(--blue); }
.button.secondary { color: #d9e2f2; border-color: #344052; background: #202938; }
.button.warning { color: #ffd98b; border-color: rgb(230 170 59 / 40%); background: rgb(230 170 59 / 10%); }
.button.danger { color: #ff9da6; border-color: rgb(241 95 109 / 38%); background: rgb(241 95 109 / 10%); }
.stream-status { display: grid; gap: 7px; margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--line); color: var(--muted); font-size: 12px; }
.stream-status span { display: flex; justify-content: space-between; gap: 12px; }
.stream-status b { color: #c6d0de; font-weight: 650; }

.trade-summary { display: grid; grid-template-columns: repeat(4, 1fr); gap: 9px; margin: 22px 0; }
.trade-summary div { padding: 12px; border-radius: 10px; background: #0b1018; }
.trade-summary dt { color: var(--muted); font-size: 11px; }
.trade-summary dd { margin: 7px 0 0; font-size: 14px; font-weight: 750; font-variant-numeric: tabular-nums; }
.value-chip, .badge, .mode { padding: 7px 11px; border: 1px solid var(--line); border-radius: 999px; color: #cbd5e4; background: #0b1018; font-size: 12px; font-weight: 750; }
.mode.running { color: #70e5ba; border-color: rgb(37 194 138 / 35%); background: rgb(37 194 138 / 10%); }
.mode.waiting { color: #ffd98b; border-color: rgb(230 170 59 / 35%); background: rgb(230 170 59 / 10%); }
.mode.faulted { color: #ff9da6; border-color: rgb(241 95 109 / 35%); background: rgb(241 95 109 / 10%); }
.badge.online { color: #70e5ba; }

.table-scroll { max-width: 100%; overflow: auto; }
table { width: 100%; border-collapse: collapse; font-size: 12px; font-variant-numeric: tabular-nums; }
th { padding: 10px; color: var(--muted); font-weight: 600; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 11px 10px; border-bottom: 1px solid rgb(36 45 59 / 60%); white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
.empty { height: 145px; color: var(--muted); text-align: center; }
.chart-card canvas { display: block; width: 100%; height: 280px; margin-top: 14px; }

.alert { margin-bottom: 14px; padding: 13px 15px; border: 1px solid rgb(241 95 109 / 35%); border-radius: 11px; color: #ffb0b7; background: rgb(241 95 109 / 9%); font-size: 13px; }
.toast { position: fixed; right: 24px; bottom: 24px; z-index: 100; max-width: min(390px, calc(100vw - 48px)); padding: 13px 16px; border: 1px solid #3a465a; border-radius: 11px; background: #1a2230; box-shadow: 0 16px 45px #0008; font-size: 13px; }
.toast.error { color: #ffb0b7; border-color: rgb(241 95 109 / 45%); }

.modal { width: min(510px, calc(100% - 32px)); padding: 0; color: var(--text); border: 1px solid var(--line); border-radius: 16px; background: var(--panel); box-shadow: 0 30px 100px #000b; }
.modal::backdrop { background: rgb(0 0 0 / 72%); backdrop-filter: blur(5px); }
.modal form { padding: 24px; display: grid; gap: 16px; }
.credential-state { padding: 11px 13px; border-radius: 9px; color: var(--muted); background: #0b1018; font-size: 13px; }
.security-note { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.55; }
.field-error, .form-error { color: #ff9da6; font-size: 12px; }

.login-page { display: grid; place-items: center; padding: 24px; }
.login-card { width: min(390px, 100%); padding: 34px; border: 1px solid var(--line); border-radius: 20px; background: var(--panel); box-shadow: 0 30px 100px #0008; text-align: center; }
.login-card .brand-mark { margin: 0 auto 20px; }
.login-card h1 { font-size: 25px; }
.login-card > p { margin: 8px 0 28px; color: var(--muted); }
.login-card form { display: grid; gap: 14px; text-align: left; }
.error-page { width: min(500px, calc(100% - 32px)); margin: 15vh auto 0; padding: 34px; text-align: center; }
.error-page .brand-mark { margin: 0 auto 20px; background: var(--red); }
.error-page p, .error-page small { color: var(--muted); }
.error-page .button { margin-top: 24px; display: inline-grid; place-items: center; text-decoration: none; }

@media (max-width: 1050px) {
  .metrics { grid-template-columns: repeat(2, 1fr); }
  .layout-grid { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .topbar { padding: 0 16px; }
  .brand > span:last-child, .runtime-load span:nth-child(3) { display: none; }
  .runtime-load { gap: 5px; }
  .runtime-load span { padding: 5px; font-size: 9px; }
  .dashboard { width: min(100% - 24px, 1480px); padding-top: 24px; }
  .metrics { grid-template-columns: 1fr; }
  .metric { min-height: 122px; }
  .trade-summary { grid-template-columns: repeat(2, 1fr); }
  .control-card, .trade-card, .chart-card { padding: 16px; }
  .badge { display: none; }
}

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