:root {
  --bg: #0b0f14;
  --surface: #121820;
  --surface-2: #171f29;
  --border: #263241;
  --border-strong: #3a4a5d;
  --text: #e8eef6;
  --muted: #96a6b8;
  --accent: #4ea1ff;
  --success: #39d98a;
  --warn: #ffb020;
  --danger: #ff5c77;
  --cyan: #56d5ff;
  --radius: 8px;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
}

* {
  box-sizing: border-box;
}

* {
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) #0b1016;
}

*::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

*::-webkit-scrollbar-track {
  background: #0b1016;
  border-radius: 999px;
}

*::-webkit-scrollbar-thumb {
  background: linear-gradient(180deg, #3a4a5d 0%, #263241 100%);
  border: 2px solid #0b1016;
  border-radius: 999px;
}

*::-webkit-scrollbar-thumb:hover {
  background: linear-gradient(180deg, #4ea1ff 0%, #3a4a5d 100%);
}

*::-webkit-scrollbar-corner {
  background: #0b1016;
}

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

.banner {
  padding: 0.6rem 1rem;
  font-size: 0.85rem;
}
.banner-error {
  background: rgba(255, 92, 119, 0.18);
  color: #ffc1ca;
}
.banner-warn {
  background: rgba(255, 176, 32, 0.14);
  color: #ffd58a;
}
.banner-muted {
  background: var(--surface);
  color: var(--muted);
  text-align: center;
}
.hidden {
  display: none !important;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  background: rgba(11, 15, 20, 0.96);
  backdrop-filter: blur(10px);
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 1rem;
  min-width: 0;
}

.title {
  margin: 0;
  font-size: 1.12rem;
  font-weight: 700;
  letter-spacing: 0;
  white-space: nowrap;
}

.badges,
.top-actions,
.admin-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 1.55rem;
  padding: 0.18rem 0.55rem;
  border-radius: 999px;
  border: 1px solid transparent;
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.badge-ok {
  border-color: rgba(57, 217, 138, 0.42);
  background: rgba(57, 217, 138, 0.12);
  color: var(--success);
}
.badge-warn {
  border-color: rgba(255, 176, 32, 0.42);
  background: rgba(255, 176, 32, 0.12);
  color: var(--warn);
}
.badge-danger {
  border-color: rgba(255, 92, 119, 0.42);
  background: rgba(255, 92, 119, 0.12);
  color: var(--danger);
}
.badge-muted {
  border-color: var(--border);
  background: var(--surface);
  color: var(--muted);
}

.cockpit {
  display: grid;
  grid-template-columns: minmax(0, 1.55fr) minmax(380px, 0.8fr);
  grid-template-areas:
    "strip strip"
    "status status"
    "positions rail"
    "trades rail"
    "signals rail"
    "footer footer";
  gap: 0.5rem;
  padding: 0.75rem;
  max-width: 1920px;
  margin: 0 auto;
}

.strip {
  grid-area: strip;
  display: grid;
  grid-template-columns: 1.45fr repeat(6, minmax(130px, 1fr));
  gap: 0.55rem;
}

.metric {
  min-height: 4.2rem;
  padding: 0.7rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}
.metric span {
  display: block;
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.metric strong {
  display: block;
  margin-top: 0.35rem;
  font-size: 1.08rem;
  font-weight: 750;
  letter-spacing: 0;
}
.metric-large strong {
  font-size: 1.45rem;
}

.statusline {
  grid-area: status;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.7rem;
  min-height: 2.1rem;
  padding: 0.45rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--muted);
  font-size: 0.78rem;
}
.statusline strong {
  color: var(--text);
  font-weight: 700;
}

.panel {
  min-height: 0;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.area-orders {
  align-self: start;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 2.3rem;
  padding: 0.55rem 0.7rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
}

.panel h2,
.settings-head h2,
.settings-panel h3 {
  margin: 0;
  font-size: 0.78rem;
  color: var(--muted);
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.area-positions { grid-area: positions; }
.area-signals { grid-area: signals; }
.area-trades { grid-area: trades; }

.right-rail {
  grid-area: rail;
  display: grid;
  align-content: start;
  gap: 0.5rem;
  min-width: 0;
}

.table-wrap {
  overflow: auto;
  max-height: 28vh;
}
.area-positions .table-wrap {
  max-height: 34vh;
}

.area-orders .table-wrap {
  max-height: 12rem;
}
.area-signals .table-wrap,
.area-trades .table-wrap {
  max-height: 45vh;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.76rem;
}
.data-table th,
.data-table td {
  padding: 0.42rem 0.55rem;
  text-align: left;
  border-bottom: 1px solid rgba(38, 50, 65, 0.9);
  white-space: nowrap;
}
.data-table th {
  position: sticky;
  top: 0;
  z-index: 2;
  color: var(--muted);
  background: #111821;
  font-size: 0.66rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.data-table tbody tr:hover {
  background: rgba(78, 161, 255, 0.06);
}

.pnl-pos {
  color: var(--success);
}
.pnl-neg {
  color: var(--danger);
}
.cell-status-accepted {
  color: var(--success);
  font-weight: 700;
}
.cell-status-rejected {
  color: var(--danger);
  font-weight: 700;
}

.btn,
.icon-btn {
  cursor: pointer;
  border: 1px solid transparent;
  border-radius: 7px;
  font: inherit;
  font-weight: 750;
}
.btn {
  min-height: 2rem;
  padding: 0.42rem 0.72rem;
  font-size: 0.78rem;
}
.btn-primary {
  background: var(--accent);
  color: #04111f;
}
.btn-secondary {
  border-color: var(--border-strong);
  background: var(--surface-2);
  color: var(--text);
}
.btn-danger {
  background: var(--danger);
  color: #fff;
}
.btn-warn {
  background: var(--warn);
  color: #1b1200;
}
.icon-btn {
  width: 2rem;
  height: 2rem;
  background: var(--surface-2);
  border-color: var(--border);
  color: var(--text);
  font-size: 1.1rem;
  line-height: 1;
}

.settings-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(0, 0, 0, 0.48);
}

.settings-panel {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 50;
  width: min(520px, 100vw);
  height: 100vh;
  overflow: auto;
  padding: 1rem;
  border-left: 1px solid var(--border);
  background: #0f151d;
  box-shadow: -18px 0 40px rgba(0, 0, 0, 0.35);
}
.settings-panel-wide {
  width: min(1100px, 100vw);
}
.settings-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.9rem;
}
.settings-grid,
.settings-tables {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
}
.settings-grid section,
.settings-tables section {
  min-width: 0;
  padding: 0.85rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}
.settings-tables {
  margin-top: 1rem;
}
.sim-table {
  grid-column: 1 / -1;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.65rem;
  margin: 0.75rem 0;
}
.form-grid.compact {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}
.form-grid label span {
  display: block;
  margin-bottom: 0.25rem;
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.input {
  width: 100%;
  min-width: 0;
  min-height: 2.1rem;
  padding: 0.43rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: #0b1016;
  color: var(--text);
  font-size: 0.85rem;
}

.settings-stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.55rem;
  margin: 0.75rem 0 0;
}
.settings-stats div {
  padding: 0.6rem;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: #0b1016;
}
.settings-stats dt {
  margin: 0;
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 800;
  text-transform: uppercase;
}
.settings-stats dd {
  margin: 0.25rem 0 0;
  font-weight: 750;
}

.hint {
  margin: 0.55rem 0;
  color: var(--muted);
  font-size: 0.78rem;
}
.admin-message {
  min-height: 1.25rem;
  margin: 0.65rem 0 0;
  font-size: 0.82rem;
}

.footer {
  grid-area: footer;
  color: var(--muted);
  font-size: 0.75rem;
  text-align: center;
}
.footer p {
  margin: 0.35rem 0;
}

code {
  padding: 0.1rem 0.28rem;
  border-radius: 4px;
  background: #0b1016;
  color: var(--cyan);
}

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

@media (max-width: 1200px) {
  .cockpit {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    grid-template-areas:
      "strip strip"
      "status status"
      "positions positions"
      "trades trades"
      "signals signals"
      "rail rail"
      "footer footer";
  }
  .strip {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

@media (max-width: 760px) {
  .topbar,
  .brand-block {
    align-items: flex-start;
    flex-direction: column;
  }
  .cockpit {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas:
      "strip"
      "status"
      "positions"
      "trades"
      "signals"
      "rail"
      "footer";
  }
  .strip,
  .settings-grid,
  .settings-tables,
  .form-grid {
    grid-template-columns: minmax(0, 1fr);
  }
  .table-wrap,
  .area-positions .table-wrap,
  .area-orders .table-wrap,
  .area-signals .table-wrap,
  .area-trades .table-wrap {
    max-height: 42vh;
  }
}
