:root {
  color-scheme: dark;
  --bg: #0d1012;
  --surface: #14181b;
  --surface-raised: #191e22;
  --surface-hover: #1d2327;
  --border: #293137;
  --border-strong: #3a454c;
  --text: #f0f3f4;
  --muted: #8e9ba2;
  --subtle: #66737a;
  --accent: #62c6d8;
  --success: #55c58a;
  --warning: #e6b85c;
  --danger: #ed6a6a;
  --info: #7ea8ed;
}

* { box-sizing: border-box; }

html {
  font-size: 15px;
  background: var(--bg);
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI Variable Text", "Segoe UI Variable", "Segoe UI", Inter, Roboto, Arial, sans-serif;
  font-feature-settings: "tnum" 1, "cv02" 1, "cv03" 1;
  letter-spacing: 0;
  line-height: 1.5;
  text-align: left;
}

a {
  color: inherit;
  text-decoration: none;
}

button,
input,
select {
  font: inherit;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  border-bottom: 1px solid var(--border);
  background: rgba(13, 16, 18, .94);
  backdrop-filter: blur(12px);
}

.topbar-inner {
  width: min(1440px, calc(100% - 40px));
  min-height: 62px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 34px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  min-width: max-content;
}

.brand-mark {
  width: 30px;
  height: 30px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  display: grid;
  place-items: center;
  color: var(--accent);
  font-size: .72rem;
  font-weight: 800;
}

.brand strong,
.brand small {
  display: block;
  line-height: 1.1;
}

.brand strong {
  font-size: .92rem;
  font-weight: 680;
}

.brand small {
  margin-top: 4px;
  color: var(--subtle);
  font-size: .68rem;
  font-weight: 600;
  text-transform: uppercase;
}

nav {
  display: flex;
  align-items: center;
  gap: 4px;
}

nav a {
  position: relative;
  padding: 21px 12px 19px;
  color: var(--muted);
  font-size: .82rem;
  font-weight: 600;
}

nav a::after {
  content: "";
  position: absolute;
  right: 12px;
  bottom: -1px;
  left: 12px;
  height: 2px;
  background: transparent;
}

nav a:hover,
nav a.active {
  color: var(--text);
}

nav a.active::after {
  background: var(--accent);
}

.health-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: .78rem;
  font-weight: 600;
}

.topbar-actions {
  display: inline-flex;
  align-items: center;
  gap: 13px;
  justify-self: end;
}

.logout-form {
  margin: 0;
}

.link-button {
  min-height: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: .78rem;
  font-weight: 600;
}

.link-button:hover {
  background: transparent;
  color: var(--text);
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 0 3px rgba(85, 197, 138, .1);
}

.page {
  width: min(1440px, calc(100% - 40px));
  margin: 0 auto;
  padding: 34px 0 64px;
}

.login-shell {
  min-height: calc(100vh - 180px);
  display: grid;
  place-items: center;
}

.login-panel {
  width: min(420px, 100%);
  padding: 24px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  display: grid;
  gap: 16px;
}

.login-panel button {
  width: 100%;
}

.page-header,
.headline {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 26px;
}

.eyebrow {
  margin: 0 0 7px;
  color: var(--accent);
  font-size: .7rem;
  font-weight: 750;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 7px;
  font-size: 1.72rem;
  font-weight: 650;
  line-height: 1.2;
}

h2 {
  margin-bottom: 18px;
  font-size: .94rem;
  font-weight: 650;
}

h3 {
  font-size: .86rem;
  font-weight: 650;
}

p {
  color: var(--muted);
}

.page-subtitle {
  margin: 0;
  color: var(--muted);
  font-size: .82rem;
}

.actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.market-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 18px;
}

.market-controls,
.timeframe-switch {
  display: flex;
  align-items: center;
  gap: 0;
}

.market-controls {
  gap: 8px;
}

.timeframe-switch {
  border: 1px solid var(--border-strong);
  border-radius: 5px;
  overflow: hidden;
}

.timeframe-switch button {
  min-width: 52px;
  border: 0;
  border-right: 1px solid var(--border-strong);
  border-radius: 0;
}

.timeframe-switch button:last-child {
  border-right: 0;
}

.timeframe-switch button.active {
  background: var(--accent);
  color: #081417;
}

.market-status {
  display: grid;
  grid-template-columns: 1.7fr 1.4fr repeat(4, minmax(0, 1fr));
  margin-bottom: 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  background: var(--surface);
}

.market-status > div {
  min-width: 0;
  padding: 11px 13px;
  border-right: 1px solid var(--border);
}

.market-status > div:last-child {
  border-right: 0;
}

.market-status span {
  display: block;
  margin-bottom: 3px;
  color: var(--subtle);
  font-size: .64rem;
  font-weight: 700;
  text-transform: uppercase;
}

.market-status strong {
  display: block;
  overflow: hidden;
  font-size: .75rem;
  font-weight: 650;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.market-connection {
  display: flex;
  align-items: center;
  gap: 10px;
}

.market-connection .activity-dot {
  margin: 0 !important;
}

.activity-dot.connected {
  background: var(--success);
  animation: activity-pulse 2s ease-out infinite;
}

.activity-dot.mock {
  background: var(--warning);
  box-shadow: 0 0 0 4px rgba(230, 184, 92, .1);
  animation: none;
}

.activity-dot.disconnected {
  background: var(--danger);
  box-shadow: 0 0 0 4px rgba(237, 106, 106, .1);
  animation: none;
}

.market-chart-shell {
  position: relative;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  background: #101416;
}

.chart-toolbar,
.market-chart-footer {
  min-height: 43px;
  padding: 9px 13px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.chart-ohlc {
  display: flex;
  align-items: center;
  gap: 13px;
  min-width: 0;
  overflow: hidden;
  color: var(--muted);
  font-family: "Cascadia Code", Consolas, monospace;
  font-size: .71rem;
  white-space: nowrap;
}

.chart-ohlc strong {
  color: var(--text);
}

.market-chart {
  width: 100%;
  height: clamp(440px, 66vh, 720px);
}

.market-loading {
  position: absolute;
  inset: 43px 0 43px;
  z-index: 4;
  background: rgba(16, 20, 22, .82);
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: .78rem;
}

.market-loading[hidden] {
  display: none;
}

.market-chart-footer {
  min-height: 39px;
  border-top: 1px solid var(--border);
  border-bottom: 0;
  color: var(--subtle);
  font-size: .69rem;
}

.market-chart-footer a {
  color: var(--muted);
}

.market-chart-footer a:hover {
  color: var(--text);
}

button,
.button {
  min-height: 36px;
  padding: 8px 13px;
  border: 1px solid var(--border-strong);
  border-radius: 5px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: .78rem;
  font-weight: 650;
  transition: background .15s ease, border-color .15s ease, color .15s ease;
}

button:hover,
.button:hover {
  border-color: #556168;
  background: var(--surface-hover);
}

button.primary,
.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: #081417;
}

button.primary:hover,
.primary:hover {
  background: #78d0df;
}

button.danger,
.danger {
  border-color: rgba(237, 106, 106, .55);
  color: var(--danger);
}

button.danger:hover,
.danger:hover {
  background: rgba(237, 106, 106, .08);
}

button.warning-action,
.warning-action {
  border-color: rgba(230, 184, 92, .55);
  color: var(--warning);
}

button.warning-action:hover,
.warning-action:hover {
  background: rgba(230, 184, 92, .08);
}

.live-warning {
  margin-bottom: 22px;
  padding: 12px 14px;
  border: 1px solid rgba(237, 106, 106, .45);
  border-left: 3px solid var(--danger);
  border-radius: 5px;
  background: rgba(237, 106, 106, .06);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  color: var(--danger);
  font-size: .78rem;
  font-weight: 750;
  text-transform: uppercase;
}

.live-warning span {
  color: var(--text);
  font-size: .75rem;
  font-weight: 550;
  text-transform: none;
}

.connection-result {
  margin-bottom: 18px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-left-width: 3px;
  border-radius: 5px;
  background: var(--surface);
  display: grid;
  gap: 3px;
  font-size: .78rem;
}

.connection-result.success {
  border-left-color: var(--success);
}

.connection-result.failure {
  border-left-color: var(--danger);
}

.connection-result span {
  color: var(--muted);
}

.broker-activity {
  margin-bottom: 22px;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-left: 3px solid var(--success);
  border-radius: 6px;
  background: var(--surface);
  display: grid;
  grid-template-columns: minmax(210px, .8fr) minmax(0, 2.4fr);
  gap: 14px 24px;
}

.broker-activity.mock {
  border-left-color: var(--warning);
}

.broker-activity.disconnected {
  border-left-color: var(--danger);
}

.broker-activity-title {
  display: flex;
  align-items: center;
  gap: 11px;
}

.broker-activity-title > div,
.broker-activity-meta > div {
  min-width: 0;
}

.broker-activity-title span,
.broker-activity-meta span {
  display: block;
  margin-bottom: 3px;
  color: var(--subtle);
  font-size: .65rem;
  font-weight: 700;
  text-transform: uppercase;
}

.broker-activity-title strong,
.broker-activity-meta strong {
  display: block;
  overflow: hidden;
  font-size: .76rem;
  font-weight: 680;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.activity-dot {
  flex: 0 0 auto;
  width: 9px;
  height: 9px;
  margin: 0 !important;
  border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 0 4px rgba(85, 197, 138, .1);
  animation: activity-pulse 2s ease-out infinite;
}

.broker-activity.mock .activity-dot {
  background: var(--warning);
  box-shadow: 0 0 0 4px rgba(230, 184, 92, .1);
  animation: none;
}

.broker-activity.disconnected .activity-dot {
  background: var(--danger);
  box-shadow: 0 0 0 4px rgba(237, 106, 106, .1);
  animation: none;
}

.broker-activity-meta {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.broker-activity p {
  grid-column: 1 / -1;
  margin: 0;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  font-size: .75rem;
}

@keyframes activity-pulse {
  0% { box-shadow: 0 0 0 0 rgba(85, 197, 138, .28); }
  70%, 100% { box-shadow: 0 0 0 7px rgba(85, 197, 138, 0); }
}

.status-strip {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  margin-bottom: 18px;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  background: var(--surface);
}

.status-strip > div {
  min-width: 0;
  padding: 13px 15px;
  border-right: 1px solid var(--border);
}

.status-strip > div:last-child {
  border-right: 0;
}

.status-strip span,
.metric-grid span {
  display: block;
  margin-bottom: 5px;
  color: var(--subtle);
  font-size: .67rem;
  font-weight: 700;
  text-transform: uppercase;
}

.status-strip strong {
  display: block;
  overflow: hidden;
  color: var(--text);
  font-size: .78rem;
  font-weight: 620;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ok { color: var(--success) !important; }
.bad { color: var(--danger) !important; }
.muted { color: var(--muted) !important; }
.warning { color: var(--warning) !important; }

.metric-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 22px;
}

.metric-grid article {
  min-width: 0;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
}

.metric-grid strong {
  display: block;
  overflow-wrap: anywhere;
  font-size: 1.12rem;
  font-weight: 620;
}

.two-column {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 16px;
}

.panel {
  margin-bottom: 16px;
  padding: 19px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  overflow: hidden;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.panel-header h2 {
  margin: 0;
}

dl {
  display: grid;
  grid-template-columns: minmax(130px, .72fr) minmax(0, 1.28fr);
  gap: 11px 20px;
  margin: 0;
}

dt {
  color: var(--subtle);
  font-size: .75rem;
}

dd {
  margin: 0;
  color: var(--text);
  font-size: .79rem;
  font-weight: 550;
  overflow-wrap: anywhere;
}

.decision-code {
  display: inline-flex;
  width: fit-content;
  margin: 0 0 10px;
  padding: 4px 7px;
  border: 1px solid rgba(230, 184, 92, .25);
  border-radius: 4px;
  background: rgba(230, 184, 92, .07);
  color: var(--warning);
  font-family: "Cascadia Code", Consolas, monospace;
  font-size: .7rem;
  font-weight: 600;
}

.error-band,
.notice,
.validation {
  margin-bottom: 18px;
  padding: 12px 14px;
  border: 1px solid rgba(237, 106, 106, .3);
  border-left: 3px solid var(--danger);
  border-radius: 5px;
  background: rgba(237, 106, 106, .05);
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  color: var(--text);
  font-size: .78rem;
}

.error-band.resolved {
  border-color: var(--border);
  background: var(--surface);
  color: var(--muted);
}

.notice {
  border-color: rgba(85, 197, 138, .3);
  border-left-color: var(--success);
  background: rgba(85, 197, 138, .05);
}

.validation:empty {
  display: none;
}

.settings-form {
  display: grid;
  gap: 0;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 15px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: .72rem;
  font-weight: 600;
}

label small {
  color: var(--subtle);
  font-family: "Cascadia Code", Consolas, monospace;
  font-size: .66rem;
  font-weight: 500;
}

label.check {
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: #111518;
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  font-size: .76rem;
}

input,
select {
  width: 100%;
  min-height: 40px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 5px;
  outline: none;
  background: #0f1315;
  color: var(--text);
  font-size: .78rem;
}

input:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(98, 198, 216, .09);
}

input[type="checkbox"] {
  width: 16px;
  min-height: 16px;
  margin: 0;
  accent-color: var(--accent);
}

.help {
  margin: 15px 0 0;
  color: var(--subtle);
  font-size: .72rem;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  padding-top: 2px;
}

.table-wrap {
  width: 100%;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
}

table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  color: var(--text);
  font-size: .75rem;
  white-space: nowrap;
}

th,
td {
  padding: 11px 13px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: middle;
}

th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #111518;
  color: var(--subtle);
  font-size: .64rem;
  font-weight: 750;
  text-transform: uppercase;
}

tbody tr {
  transition: background .12s ease;
}

tbody tr:hover {
  background: var(--surface-hover);
}

tbody tr:last-child td {
  border-bottom: 0;
}

td a {
  color: var(--accent);
  font-weight: 700;
}

.cell-wrap {
  min-width: 240px;
  max-width: 430px;
  white-space: normal;
}

.cell-reason strong {
  display: block;
  margin-bottom: 3px;
  color: var(--text);
  font-family: "Cascadia Code", Consolas, monospace;
  font-size: .67rem;
}

.cell-reason span {
  color: var(--muted);
  line-height: 1.45;
}

.badge {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  padding: 3px 7px;
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  background: rgba(142, 155, 162, .06);
  color: var(--muted);
  font-size: .64rem;
  font-weight: 750;
  text-transform: uppercase;
}

.badge.success {
  border-color: rgba(85, 197, 138, .26);
  background: rgba(85, 197, 138, .07);
  color: var(--success);
}

.badge.danger {
  border-color: rgba(237, 106, 106, .28);
  background: rgba(237, 106, 106, .07);
  color: var(--danger);
}

.badge.warning {
  border-color: rgba(230, 184, 92, .28);
  background: rgba(230, 184, 92, .07);
  color: var(--warning);
}

.badge.info {
  border-color: rgba(126, 168, 237, .28);
  background: rgba(126, 168, 237, .07);
  color: var(--info);
}

.mono,
pre,
code {
  font-family: "Cascadia Code", "SFMono-Regular", Consolas, monospace;
}

pre {
  margin: 0;
  padding: 14px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: #0b0e10;
  color: #c5cfd4;
  font-size: .72rem;
  line-height: 1.6;
  white-space: pre-wrap;
}

details {
  border-top: 1px solid var(--border);
  padding: 12px 0;
}

details:first-of-type {
  border-top: 0;
}

summary {
  color: var(--muted);
  cursor: pointer;
  font-size: .76rem;
}

details[open] summary {
  margin-bottom: 12px;
  color: var(--text);
}

.event-list {
  display: grid;
  gap: 10px;
}

.event-item {
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
  color: var(--muted);
  font-size: .76rem;
}

.event-item:last-child {
  padding-bottom: 0;
  border-bottom: 0;
}

.event-item strong {
  color: var(--text);
}

.equity-list {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1px;
  border: 1px solid var(--border);
  border-radius: 5px;
  overflow: hidden;
  background: var(--border);
}

.equity-list > div {
  padding: 10px 12px;
  background: #111518;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: .72rem;
}

.equity-list span {
  color: var(--subtle);
}

.empty-state {
  padding: 44px 20px;
  color: var(--subtle);
  text-align: center;
  white-space: normal;
}

@media (max-width: 1050px) {
  .topbar-inner {
    grid-template-columns: auto 1fr;
  }

  .health-link {
    display: none;
  }

  .metric-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .form-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .broker-activity {
    grid-template-columns: 1fr;
  }

  .broker-activity-meta {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .market-status {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .market-status > div:nth-child(3n) {
    border-right: 0;
  }

  .market-status > div:nth-child(-n+3) {
    border-bottom: 1px solid var(--border);
  }
}

@media (max-width: 760px) {
  .topbar-inner {
    width: min(100% - 24px, 1440px);
    grid-template-columns: 1fr;
    gap: 8px;
    padding: 12px 0 0;
  }

  nav {
    overflow-x: auto;
  }

  nav a {
    padding: 10px 10px 12px;
  }

  .page {
    width: min(100% - 24px, 1440px);
    padding-top: 24px;
  }

  .headline,
  .page-header,
  .market-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .status-strip,
  .metric-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .status-strip > div:nth-child(2n) {
    border-right: 0;
  }

  .status-strip > div {
    border-bottom: 1px solid var(--border);
  }

  .two-column,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .broker-activity-meta {
    grid-template-columns: 1fr;
  }

  .market-status {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .market-status > div,
  .market-status > div:nth-child(3n) {
    border-right: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
  }

  .market-status > div:nth-child(2n) {
    border-right: 0;
  }

  .market-status > div:nth-last-child(-n+2) {
    border-bottom: 0;
  }

  .market-chart {
    height: 480px;
  }

  .chart-ohlc {
    gap: 8px;
  }

  .equity-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 480px) {
  .status-strip,
  .metric-grid,
  .equity-list {
    grid-template-columns: 1fr;
  }

  .status-strip > div {
    border-right: 0;
  }

  dl {
    grid-template-columns: 1fr;
    gap: 3px;
  }

  dd {
    margin-bottom: 9px;
  }

  .live-warning {
    align-items: flex-start;
    flex-direction: column;
  }

  .market-status {
    grid-template-columns: 1fr;
  }

  .market-status > div,
  .market-status > div:nth-child(2n),
  .market-status > div:nth-last-child(-n+2) {
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  .market-status > div:last-child {
    border-bottom: 0;
  }

  .market-controls {
    width: 100%;
    justify-content: space-between;
  }

  .chart-toolbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .chart-ohlc {
    width: 100%;
    overflow-x: auto;
  }

  .market-chart {
    height: 420px;
  }

  .market-chart-footer {
    align-items: flex-start;
    flex-direction: column;
  }
}
