:root {
  --bg: #0a0f17;
  --panel: #131c2a;
  --panel-soft: #0f1724;
  --panel-strong: #182233;
  --line: rgba(148, 163, 184, 0.16);
  --line-strong: rgba(148, 163, 184, 0.26);
  --text: #eef4ff;
  --muted: #8f9db2;
  --accent: #2962ff;
  --good: #22ab94;
  --bad: #f23645;
  --warn: #ff9800;
  --ready: #90a4ae;
  --shadow: 0 20px 60px rgba(0, 0, 0, 0.42);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }

body {
  font-family: "IBM Plex Sans", "Segoe UI", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(41, 98, 255, 0.12), transparent 28%),
    linear-gradient(180deg, #0b1018 0%, #09101a 100%);
}

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 28px;
  background:
    radial-gradient(circle at 18% 18%, rgba(34, 171, 148, 0.18), transparent 26%),
    radial-gradient(circle at 82% 12%, rgba(41, 98, 255, 0.16), transparent 30%),
    linear-gradient(145deg, #071018 0%, #0d1521 52%, #070b11 100%);
}

.login-shell {
  width: min(420px, 100%);
}

.login-card {
  padding: 30px;
  border: 1px solid var(--line);
  border-radius: 28px;
  background: linear-gradient(180deg, rgba(24, 34, 51, 0.94), rgba(13, 20, 31, 0.94));
  box-shadow: var(--shadow);
}

.login-card h1 {
  margin: 4px 0 24px;
  font-family: "Space Grotesk", "Arial Narrow", sans-serif;
}

.login-form {
  display: grid;
  gap: 16px;
}

.login-form label {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.login-form input {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 14px;
  padding: 12px 14px;
  background: rgba(8, 13, 21, 0.76);
  color: var(--text);
  font: inherit;
}

.login-error {
  padding: 10px 12px;
  border: 1px solid rgba(242,54,69,.34);
  border-radius: 14px;
  background: rgba(242,54,69,.12);
  color: #ff9da7;
}

.topbar {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 20px;
  align-items: center;
  padding: 16px 22px;
  border-bottom: 1px solid var(--line);
  background: rgba(6, 10, 16, 0.9);
  backdrop-filter: blur(18px);
  position: sticky;
  top: 0;
  z-index: 10;
}

.logout-form {
  margin: 0;
}

.topbar-actions {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.user-menu {
  position: relative;
}

.user-menu > summary {
  list-style: none;
}

.user-menu > summary::-webkit-details-marker {
  display: none;
}

.menu-sprite {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  min-height: 42px;
  padding: 10px 13px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #101926;
  color: var(--text);
  cursor: pointer;
  font-size: 0.86rem;
  font-weight: 800;
}

.menu-sprite:hover,
.user-menu[open] .menu-sprite {
  border-color: rgba(143, 157, 178, 0.34);
  background: #152235;
}

.menu-sprite:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(41, 98, 255, 0.18);
}

.menu-sprite-lines,
.menu-sprite-lines::before,
.menu-sprite-lines::after {
  display: block;
  width: 17px;
  height: 2px;
  border-radius: 2px;
  background: currentColor;
  content: "";
}

.menu-sprite-lines {
  position: relative;
}

.menu-sprite-lines::before,
.menu-sprite-lines::after {
  position: absolute;
  left: 0;
}

.menu-sprite-lines::before { top: -5px; }
.menu-sprite-lines::after { top: 5px; }

.user-menu-popover {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 30;
  width: 218px;
  padding: 7px;
  border: 1px solid var(--line-strong);
  border-radius: 16px;
  background: #121c2a;
  box-shadow: var(--shadow);
}

.user-menu-link,
.user-menu-logout {
  display: flex;
  align-items: center;
  width: 100%;
  min-height: 42px;
  padding: 10px 11px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-weight: 700;
  text-align: left;
  text-decoration: none;
}

.user-menu-link:hover {
  background: rgba(143, 157, 178, 0.12);
}

.user-menu-logout {
  color: #ffb4ba;
  cursor: pointer;
}

.user-menu-logout:hover {
  background: rgba(242, 54, 69, 0.14);
}

.user-menu-divider {
  height: 1px;
  margin: 5px 3px;
  background: var(--line);
}

.nav-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 41px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #101926;
  color: var(--text);
  font-weight: 700;
  text-decoration: none;
}

.nav-link:hover {
  background: #152235;
  border-color: rgba(143, 157, 178, 0.34);
}

.brand-block {
  display: flex;
  gap: 14px;
  align-items: center;
}

.brand-mark {
  width: 46px;
  height: 46px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #2962ff, #1d3f8c);
  font-family: "Space Grotesk", "Arial Narrow", sans-serif;
  font-weight: 800;
}

.brand-block h1,
.setup-heading h2,
.section-heading h2 {
  margin: 0;
  font-family: "Space Grotesk", "Arial Narrow", sans-serif;
}

.ticker-strip {
  display: flex;
  gap: 10px;
  overflow-x: auto;
}

.ticker-chip {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(20, 28, 41, 0.96), rgba(15, 23, 36, 0.96));
}

.shell {
  display: grid;
  grid-template-columns: 430px 1fr;
  min-height: calc(100vh - 79px);
}

.hero-panel {
  padding: 20px 14px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  border-right: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(15, 23, 36, 0.98), rgba(10, 15, 23, 0.98));
}

.setup-heading h2 {
  font-size: 1.25rem;
  line-height: 1;
}

.eyebrow {
  margin: 0 0 8px;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  font-size: 0.72rem;
  font-weight: 700;
  color: #5f90ff;
}

.subtitle,
.empty-state p,
.notice,
label span,
.instrument-subtitle,
.instrument-key,
.metric-title,
.table-legend {
  color: var(--muted);
}

.workspace {
  padding: 20px;
}

.wide-workspace {
  display: block;
}

.form-card,
.list-card,
.settings-modal-card {
  background: linear-gradient(180deg, rgba(19, 28, 42, 0.98), rgba(13, 20, 31, 0.98));
  border: 1px solid var(--line);
  border-radius: 24px;
  box-shadow: var(--shadow);
}

.hero-panel .form-card {
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - 130px);
}

.compact-card {
  padding: 12px;
}

.setup-heading {
  margin-bottom: 14px;
}

.setup-heading h2,
.section-heading h2 {
  font-size: 1.35rem;
  line-height: 1.1;
}

.list-card {
  padding: 22px;
}

.expanded-list-card {
  min-height: calc(100vh - 130px);
}

.section-heading {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 16px;
}

.table-legend {
  display: flex;
  gap: 18px;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
}

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

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

label {
  display: grid;
  gap: 5px;
}

label span {
  font-size: 0.76rem;
}

input,
select,
button {
  border-radius: 14px;
  border: 1px solid var(--line);
  font: inherit;
}

input,
select {
  width: 100%;
  padding: 9px 10px;
  background: #0d1521;
  color: var(--text);
}

input[readonly] {
  opacity: 0.72;
  cursor: default;
}

input:focus,
select:focus {
  outline: none;
  border-color: rgba(41, 98, 255, 0.7);
  box-shadow: 0 0 0 3px rgba(41, 98, 255, 0.14);
}

.actions {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 2px;
}

button {
  cursor: pointer;
  padding: 10px 14px;
  font-weight: 700;
  transition:
    transform 120ms ease,
    box-shadow 140ms ease,
    border-color 140ms ease,
    background 140ms ease,
    opacity 140ms ease;
}

button:hover:not(:disabled) {
  box-shadow: 0 10px 22px rgba(0, 0, 0, 0.22);
}

button:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(41, 98, 255, 0.18);
}

button:active:not(:disabled),
button.is-pressed {
  transform: translateY(1px) scale(0.98);
}

button.is-pending {
  position: relative;
  border-color: rgba(255, 255, 255, 0.34);
  box-shadow: 0 0 0 3px rgba(41, 98, 255, 0.12);
}

button.is-active {
  transform: translateY(1px);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.08),
    inset 0 0 0 1px rgba(255, 255, 255, 0.04),
    0 8px 18px rgba(0, 0, 0, 0.28);
}

button.state-locked,
button.state-locked:disabled {
  background: rgba(143, 157, 178, 0.14);
  border-color: rgba(143, 157, 178, 0.4);
  color: #dbe3ef;
  opacity: 1;
  transform: translateY(1px);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.05),
    inset 0 0 0 1px rgba(255, 255, 255, 0.03),
    0 8px 18px rgba(0, 0, 0, 0.18);
  transition: none;
}

button.is-pending::after {
  content: "";
  position: absolute;
  top: 50%;
  right: 10px;
  width: 12px;
  height: 12px;
  margin-top: -6px;
  border-radius: 999px;
  border: 2px solid rgba(255, 255, 255, 0.24);
  border-top-color: currentColor;
  animation: button-spin 0.7s linear infinite;
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

button[title] {
  position: relative;
}

.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

.ghost {
  background: #101926;
  color: var(--text);
}

.danger {
  background: rgba(242, 54, 69, 0.14);
  border-color: rgba(242, 54, 69, 0.38);
  color: #ffb4ba;
}

.warning {
  background: rgba(255, 152, 0, 0.14);
  border-color: rgba(255, 152, 0, 0.38);
  color: #ffd08a;
}

.ghost:hover:not(:disabled),
.ghost.is-pending {
  background: #152235;
  border-color: rgba(143, 157, 178, 0.34);
}

button[data-role="open-settings"].is-active {
  background: rgba(143, 157, 178, 0.16);
  border-color: rgba(143, 157, 178, 0.42);
  color: #f4f7ff;
}

.primary:hover:not(:disabled),
.primary.is-pending {
  background: #3a73ff;
  border-color: #3a73ff;
}

.danger:hover:not(:disabled),
.danger.is-pending {
  background: rgba(242, 54, 69, 0.22);
  border-color: rgba(242, 54, 69, 0.52);
}

.warning:hover:not(:disabled),
.warning.is-pending {
  background: rgba(255, 152, 0, 0.22);
  border-color: rgba(255, 152, 0, 0.56);
}


.instrument-list {
  display: grid;
  gap: 14px;
  margin-top: 18px;
}

.instrument-card {
  padding: 18px;
  border-radius: 20px;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(11, 18, 28, 0.98), rgba(14, 21, 31, 0.96));
}

.instrument-card-head {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 12px;
  margin-bottom: 14px;
}

.instrument-title {
  display: flex;
  align-items: center;
  gap: 10px;
}

.instrument-title strong {
  font-size: 1.1rem;
}

.instrument-key {
  margin-top: 6px;
  font-size: 0.82rem;
}

.instrument-card-grid {
  display: grid;
  grid-template-columns: 220px minmax(220px, 1fr) minmax(220px, 1fr) 220px;
  gap: 14px;
}

.metric-block,
.strategy-actions {
  border: 1px solid rgba(148, 163, 184, 0.1);
  border-radius: 16px;
  padding: 14px;
  background: rgba(10, 16, 25, 0.72);
}

.metric-title {
  margin: 0 0 10px;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
}

.metric-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px 12px;
}

.metric-grid span {
  color: var(--muted);
}

.metric-grid strong {
  justify-self: end;
}

.pnl-block {
  border-color: rgba(34, 171, 148, 0.28);
  background:
    radial-gradient(circle at top left, rgba(34, 171, 148, 0.16), transparent 58%),
    rgba(10, 16, 25, 0.78);
}

.pnl-value {
  margin: 8px 0 14px;
  font-family: "Space Grotesk", "Arial Narrow", sans-serif;
  font-size: 1.7rem;
  line-height: 1;
  font-weight: 800;
  color: #7ff3df;
}

.pnl-mini-grid {
  margin-bottom: 14px;
}

.export-link {
  display: inline-flex;
  justify-content: center;
  width: 100%;
  padding: 10px 12px;
  border-radius: 14px;
  border: 1px solid rgba(34, 171, 148, 0.38);
  background: rgba(34, 171, 148, 0.12);
  color: #9af7e8;
  font-weight: 800;
  text-decoration: none;
}

.export-link:hover {
  background: rgba(34, 171, 148, 0.2);
}

.strategy-actions {
  display: grid;
  align-content: start;
  gap: 10px;
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 88px;
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 800;
  letter-spacing: 0.08em;
}

.badge-running { background: rgba(34,171,148,.16); color: #7ff3df; }
.badge-stopped { background: rgba(242,54,69,.16); color: #ff9aa5; }
.badge-ready { background: rgba(144,164,174,.16); color: #c6d0d8; }
.badge-paused { background: rgba(255,152,0,.18); color: #ffd58d; }

.notice {
  padding: 10px 12px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(9, 14, 22, 0.86);
}

.setup-notice {
  margin-top: auto;
  min-height: 42px;
}

.setup-notice.is-hidden {
  visibility: hidden;
  display: block;
}

.notice-success { border-color: rgba(34,171,148,.34); color: #81f0de; }
.notice-error { border-color: rgba(242,54,69,.34); color: #ff9da7; }
.is-hidden { display: none; }
.modal-backdrop.is-hidden { display: none; }

.empty-state {
  padding: 28px;
  border: 1px dashed var(--line-strong);
  border-radius: 20px;
  text-align: center;
  background: rgba(11, 18, 28, 0.6);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(3, 6, 11, 0.7);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 20;
}

.settings-modal-card {
  width: min(860px, 100%);
  padding: 22px;
}

.account-shell {
  width: min(1240px, calc(100% - 40px));
  margin: 0 auto;
  padding: 24px 0 42px;
}

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

.account-header h2,
.account-card h3 {
  margin: 0;
  font-family: "Space Grotesk", "Arial Narrow", sans-serif;
}

.account-intro,
.account-card-head p:not(.eyebrow) {
  margin: 8px 0 0;
  color: var(--muted);
  line-height: 1.5;
}

.account-intro {
  max-width: 620px;
}

.account-layout {
  display: grid;
  grid-template-columns: minmax(230px, 270px) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.account-sidebar {
  position: sticky;
  top: 98px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: linear-gradient(180deg, rgba(19, 28, 42, 0.98), rgba(13, 20, 31, 0.98));
}

.account-sidebar-user {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 6px 6px 16px;
  border-bottom: 1px solid var(--line);
}

.account-avatar {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border-radius: 12px;
  background: rgba(41, 98, 255, 0.18);
  color: #a9c0ff;
  font-weight: 800;
}

.account-sidebar-user strong,
.account-sidebar-user span:not(.account-avatar) {
  display: block;
}

.account-sidebar-user span:not(.account-avatar) {
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.78rem;
}

.account-nav {
  display: grid;
  gap: 4px;
  margin-top: 12px;
}

.account-nav a {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 11px 10px;
  border-radius: 12px;
  color: var(--text);
  font-weight: 700;
  text-decoration: none;
}

.account-nav a:hover {
  background: rgba(143, 157, 178, 0.1);
}

.account-nav small {
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 700;
  white-space: nowrap;
}

.account-nav small.is-configured {
  color: #7ff3df;
}

.account-settings-list {
  display: grid;
  gap: 18px;
}

.account-card {
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: linear-gradient(180deg, rgba(19, 28, 42, 0.98), rgba(13, 20, 31, 0.98));
  box-shadow: var(--shadow);
}

.account-card-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.account-card {
  scroll-margin-top: 98px;
}

.account-form {
  display: grid;
  gap: 14px;
}

.token-delete-form {
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.token-state {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 132px;
  padding: 7px 10px;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  white-space: nowrap;
}

.token-state-set {
  background: rgba(34, 171, 148, 0.16);
  color: #7ff3df;
}

.token-state-empty {
  background: rgba(144, 164, 174, 0.16);
  color: #c6d0d8;
}

.token-state-warning {
  background: rgba(255, 184, 77, 0.16);
  color: #ffd38f;
}

.token-state-error {
  background: rgba(242, 54, 69, 0.18);
  color: #ff9aa5;
}

.account-notice {
  min-width: min(360px, 100%);
}

.modal-heading {
  margin-bottom: 18px;
}

@keyframes button-spin {
  to {
    transform: rotate(360deg);
  }
}

@media (max-width: 1280px) {
  .shell {
    grid-template-columns: 1fr;
  }

  .hero-panel {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .instrument-card-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 760px) {
  .topbar,
  .strategy-form,
  .create-form,
  .account-layout,
  .account-header {
    grid-template-columns: 1fr;
  }

  .topbar,
  .account-header {
    align-items: stretch;
  }

  .topbar-actions { justify-content: flex-end; }

  .account-sidebar { position: static; }

  .menu-sprite-label { display: none; }

  .table-legend {
    display: none;
  }

  .actions,
  .strategy-actions {
    grid-auto-flow: row;
  }
}
