:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-muted: #edf1f4;
  --ink: #15191f;
  --muted: #64707d;
  --border: #d9e0e6;
  --primary: #1267d8;
  --primary-ink: #ffffff;
  --success: #0f9f6e;
  --danger: #c9374c;
  --warn: #9a6a00;
  --shadow: 0 16px 40px rgba(18, 32, 48, 0.08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  background: var(--bg);
  color: var(--ink);
}

button,
input,
select {
  font: inherit;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-mark {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border-radius: 8px;
  background: var(--ink);
  color: #ffffff;
  font-weight: 800;
}

.brand-name {
  font-weight: 800;
}

.brand-large {
  justify-content: center;
}

.brand-large .brand-mark {
  width: 42px;
  height: 42px;
}

.login-shell {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
}

.login-panel {
  width: min(100%, 460px);
  padding: 34px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  text-align: center;
}

.login-panel h1 {
  margin: 24px 0 10px;
  font-size: clamp(1.8rem, 4vw, 2.6rem);
  line-height: 1.05;
}

.login-panel p {
  margin: 0 auto 24px;
  color: var(--muted);
  line-height: 1.55;
}

.setup-list {
  display: grid;
  gap: 12px;
  margin: 26px 0 0;
  text-align: left;
}

.setup-list div {
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-muted);
}

.setup-list dt {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 700;
  text-transform: uppercase;
}

.setup-list dd {
  margin: 5px 0 0;
  overflow-wrap: anywhere;
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  font-size: 0.9rem;
}

.button {
  display: inline-flex;
  min-height: 42px;
  align-items: center;
  justify-content: center;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 0 16px;
  color: inherit;
  cursor: pointer;
  font-weight: 750;
  text-decoration: none;
  transition: transform 120ms ease, border-color 120ms ease, background 120ms ease;
}

.button:active {
  transform: translateY(1px);
}

.button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
  transform: none;
}

.button-primary {
  background: var(--primary);
  color: var(--primary-ink);
}

.button-secondary {
  border-color: var(--border);
  background: var(--surface);
}

.link-button {
  border: 0;
  background: transparent;
  color: var(--primary);
  cursor: pointer;
  font-weight: 750;
}

.app-shell {
  min-height: 100vh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  min-height: 70px;
  padding: 12px 22px;
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(14px);
}

.connection,
.account-tools {
  display: flex;
  align-items: center;
  gap: 12px;
}

.connection {
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 700;
}

.dot {
  display: block;
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: var(--warn);
}

.dot.open {
  background: var(--success);
}

.dot.closed {
  background: var(--danger);
}

select,
input[type="number"],
input[type="text"] {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  padding: 0 12px;
}

.balance {
  min-width: 120px;
  font-weight: 800;
  text-align: right;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(320px, 1.35fr) minmax(280px, 0.75fr);
  grid-template-areas:
    "market ticket"
    "account account";
  gap: 18px;
  max-width: 1280px;
  margin: 0 auto;
  padding: 22px;
}

.panel {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 18px;
}

.market-panel {
  grid-area: market;
  min-height: 460px;
}

.ticket-panel {
  grid-area: ticket;
}

.account-panel {
  grid-area: account;
}

.panel-heading,
.activity-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 18px;
}

.panel-heading h2,
.activity-head h3 {
  margin: 0;
  font-size: 1.06rem;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
}

.quote-state {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  border-radius: 999px;
  background: var(--surface-muted);
  color: var(--muted);
  padding: 0 10px;
  font-size: 0.82rem;
  font-weight: 800;
}

.price-strip {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}

.last-price {
  font-size: clamp(2.6rem, 8vw, 5.4rem);
  font-weight: 850;
  line-height: 1;
}

.tick-time {
  color: var(--muted);
  font-weight: 700;
  white-space: nowrap;
}

#sparkline {
  display: block;
  width: 100%;
  height: 300px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background:
    linear-gradient(var(--surface-muted) 1px, transparent 1px),
    linear-gradient(90deg, var(--surface-muted) 1px, transparent 1px);
  background-size: 44px 44px;
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 16px;
}

.segmented label {
  cursor: pointer;
}

.segmented input {
  position: absolute;
  opacity: 0;
}

.segmented span {
  display: grid;
  min-height: 42px;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  font-weight: 800;
}

.segmented input:checked + span {
  border-color: var(--primary);
  background: #e8f1ff;
  color: var(--primary);
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.field {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 750;
}

.quote-box,
.metric-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 16px;
}

.quote-box div,
.metric-grid div {
  display: grid;
  gap: 5px;
  min-width: 0;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-muted);
}

.quote-box span,
.metric-grid span {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 800;
  text-transform: uppercase;
}

.quote-box strong,
.metric-grid strong {
  overflow-wrap: anywhere;
  font-size: 1.1rem;
}

.confirm-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin: 18px 0;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.4;
}

.confirm-row input {
  margin-top: 3px;
}

.button-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.metric-grid {
  grid-template-columns: repeat(4, 1fr);
  margin-top: 0;
}

.activity-head {
  margin: 24px 0 10px;
}

.activity-log {
  display: grid;
  max-height: 260px;
  overflow-y: auto;
  gap: 8px;
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  font-size: 0.86rem;
}

.activity-log div {
  border-left: 3px solid var(--border);
  padding: 8px 10px;
  background: var(--surface-muted);
}

.activity-log .success {
  border-left-color: var(--success);
  color: var(--success);
}

.activity-log .warn {
  border-left-color: var(--warn);
  color: var(--warn);
}

.activity-log .error,
.negative {
  color: var(--danger);
}

.positive {
  color: var(--success);
}

@media (max-width: 900px) {
  .topbar,
  .account-tools {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar {
    position: static;
  }

  .connection,
  .account-tools,
  .account-tools form {
    width: 100%;
  }

  .balance {
    min-width: 0;
    text-align: left;
  }

  .workspace {
    grid-template-columns: 1fr;
    grid-template-areas:
      "market"
      "ticket"
      "account";
    padding: 14px;
  }

  .metric-grid {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 560px) {
  .login-panel {
    padding: 24px;
  }

  .panel-heading,
  .price-strip {
    align-items: stretch;
    flex-direction: column;
  }

  .form-grid,
  .quote-box,
  .metric-grid,
  .button-row {
    grid-template-columns: 1fr;
  }

  #sparkline {
    height: 220px;
  }
}