/* ===== Trading Simulator — Main Styles ===== */

:root {
  /* Colors */
  --bg: #0d1117;
  --bg-panel: #161b22;
  --bg-row: #1c2128;
  --bg-row-hover: #252c35;
  --border: #30363d;
  --text: #e6edf3;
  --text-dim: #8b949e;
  --text-muted: #6e7681;

  --bid: #3fb950;
  --bid-bg: rgba(63, 185, 80, 0.15);
  --bid-bar: rgba(63, 185, 80, 0.35);
  --bid-my: rgba(63, 185, 80, 0.6);

  --ask: #f85149;
  --ask-bg: rgba(248, 81, 73, 0.15);
  --ask-bar: rgba(248, 81, 73, 0.35);
  --ask-my: rgba(248, 81, 73, 0.6);

  --accent: #58a6ff;
  --accent-bg: rgba(88, 166, 255, 0.1);
  --accent-border: rgba(88, 166, 255, 0.5);

  --spread-bg: #1a1f26;

  /* Sizing */
  --row-height: 26px;
  --panel-radius: 8px;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  line-height: 1.4;
  overflow: hidden;
  height: 100vh;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* ===== Header ===== */

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 16px;
}

.logo {
  font-size: 16px;
  font-weight: 700;
  color: var(--accent);
}

.logo-img {
  height: 28px;
  width: auto;
  display: block;
}

.logo-tag {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
  border-left: 1px solid var(--border);
  padding-left: 10px;
  margin-left: -4px;
}

/* Symbol toggle buttons */
.symbol-toggles {
  display: flex;
  gap: 4px;
}

.sym-toggle {
  background: var(--bg);
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 4px 10px;
  font-size: 13px;
  font-weight: 600;
  font-family: monospace;
  cursor: pointer;
  transition: color 0.1s, border-color 0.1s, background 0.1s;
}

.sym-toggle:hover {
  color: var(--text);
  border-color: var(--accent);
}

.sym-toggle.active {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-bg);
}

.sym-toggle:disabled {
  opacity: 0.3;
  cursor: not-allowed;
  border-color: var(--border);
}

.username-label {
  font-size: 11px;
  color: var(--text-muted);
  margin-right: 6px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.username-input {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 4px 8px;
  font-size: 13px;
  font-weight: 600;
  font-family: monospace;
  width: 140px;
  transition: border-color 0.1s;
}

.username-input:focus {
  outline: none;
  border-color: var(--accent);
}

.username-input::placeholder {
  color: var(--text-muted);
  font-weight: 400;
}

/* ===== Halt Banner ===== */

.halt-banner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: rgba(248, 81, 73, 0.15);
  border-bottom: 1px solid var(--ask);
  color: var(--ask);
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 6px 0;
  flex-shrink: 0;
}

.halt-banner-icon {
  font-size: 14px;
}

/* ===== Main Layout ===== */

.main {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
}

/* ===== Columns Container ===== */

.columns-container {
  display: flex;
  flex-direction: row;
  flex: 1;
  overflow: hidden;
}

/* ===== Trading Column ===== */

.trading-column {
  display: flex;
  flex-direction: row;
  flex: 1;
  min-width: 0;
  border-right: 1px solid var(--border);
  overflow: hidden;
}

.trading-column:last-child {
  border-right: none;
}

.trading-column.active {
  box-shadow: inset 0 0 0 2px var(--accent-border);
}

/* Column symbol label */
.column-symbol-label {
  padding: 6px 12px;
  font-size: 14px;
  font-weight: 700;
  font-family: monospace;
  color: var(--accent);
  border-bottom: 1px solid var(--border);
  background: rgba(88, 166, 255, 0.05);
}

/* Orderbook panel */
.orderbook-panel {
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  overflow: hidden;
  flex: 0 0 48%;
}

/* Right panel inside each column */
.right-panel {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg-panel);
  flex: 1;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.panel-header h2 {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-dim);
}

.spread-label {
  font-size: 11px;
  color: var(--text-muted);
  font-family: monospace;
}

.orderbook {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
}

.orderbook-levels {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
}

/* ===== Book Row ===== */

.book-row {
  display: flex;
  align-items: center;
  height: var(--row-height);
  padding: 0 6px;
  cursor: pointer;
  position: relative;
  transition: background 0.1s;
  user-select: none;
  touch-action: none;
}

.book-row:hover {
  background: var(--bg-row-hover);
}

.book-row.side-ask {
  border-left: 3px solid transparent;
}

.book-row.side-bid {
  border-left: 3px solid transparent;
}

.book-row.has-my-order.side-ask {
  border-left-color: var(--ask);
  background: var(--ask-bg);
}

.book-row.has-my-order.side-bid {
  border-left-color: var(--bid);
  background: var(--bid-bg);
}

.book-row .price {
  width: 90px;
  text-align: right;
  font-family: "SF Mono", "Cascadia Code", "Fira Code", monospace;
  font-size: 12px;
  font-weight: 500;
  flex-shrink: 0;
}

.book-row.side-ask .price {
  color: var(--ask);
}

.book-row.side-bid .price {
  color: var(--bid);
}

.book-row.empty-level .price {
  color: var(--text-dim);
  opacity: 0.6;
}

.book-row.empty-level:hover {
  background: var(--bg-row-hover);
}

.book-row.empty-level:hover .price {
  opacity: 0.8;
}

/* Highlighted price level (selected via click or price input). */
.book-row.price-selected {
  background: var(--accent-bg);
  outline: 1px solid var(--accent-border);
  outline-offset: -1px;
}

.book-row.price-selected .price {
  color: var(--accent) !important;
  opacity: 1 !important;
}

.book-row .qty-bar-container {
  flex: 1;
  height: 16px;
  margin-left: 8px;
  position: relative;
  border-radius: 2px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.03);
}

.book-row .qty-bar {
  height: 100%;
  border-radius: 2px;
  transition: width 0.15s ease;
}

.book-row.side-ask .qty-bar {
  background: var(--ask-bar);
}

.book-row.side-bid .qty-bar {
  background: var(--bid-bar);
}

.book-row .my-qty-bar {
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  border-radius: 2px;
  transition: width 0.15s ease;
}

.book-row.side-ask .my-qty-bar {
  background: var(--ask-my);
}

.book-row.side-bid .my-qty-bar {
  background: var(--bid-my);
}

.book-row .qty-text {
  position: absolute;
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
  font-family: "SF Mono", "Cascadia Code", "Fira Code", monospace;
  font-size: 11px;
  color: var(--text);
  z-index: 1;
}

/* Drag states */
.book-row.dragging {
  opacity: 0.35;
  transform: scale(0.98);
}

.book-row.drag-target {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
  background: var(--accent-bg) !important;
}

/* Cross-side drag target (crossing the spread) gets a brighter highlight. */
.book-row.drag-target-cross {
  outline: 2px solid #f0c040;
  outline-offset: -2px;
  background: rgba(240, 192, 64, 0.15) !important;
}

.drag-ghost {
  position: fixed;
  pointer-events: none;
  z-index: 1000;
  opacity: 0.85;
  transform: scale(1.02);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
  border-radius: 4px;
  background: var(--bg-panel);
  padding: 4px 12px;
  font-family: "SF Mono", "Cascadia Code", "Fira Code", monospace;
  font-size: 12px;
  font-weight: 600;
}

.drag-ghost.side-bid {
  color: var(--bid);
  border-left: 3px solid var(--bid);
}

.drag-ghost.side-ask {
  color: var(--ask);
  border-left: 3px solid var(--ask);
}

/* ===== Order Entry (per-column, compact) ===== */

.order-entry-panel {
  padding: 10px;
  border-bottom: 1px solid var(--border);
}

.order-entry-panel h2 {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-dim);
  margin-bottom: 10px;
}

.field-group {
  margin-bottom: 8px;
}

.field-group label {
  display: block;
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 3px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.stepper {
  display: flex;
  align-items: center;
  gap: 0;
}

.stepper-btn {
  width: 28px;
  height: 28px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.1s;
}

.stepper-btn:first-child {
  border-radius: 4px 0 0 4px;
}

.stepper-btn:last-child {
  border-radius: 0 4px 4px 0;
}

.stepper-btn:hover {
  background: var(--bg-row-hover);
}

.stepper-btn:active {
  background: var(--border);
}

.field-input {
  flex: 1;
  height: 28px;
  border: 1px solid var(--border);
  border-left: none;
  border-right: none;
  background: var(--bg);
  color: var(--text);
  font-family: "SF Mono", "Cascadia Code", "Fira Code", monospace;
  font-size: 12px;
  text-align: center;
  padding: 0 4px;
}

.field-input:focus {
  outline: none;
  border-color: var(--accent);
}

.field-input.invalid {
  border-color: var(--ask);
}

.order-buttons {
  display: flex;
  gap: 6px;
  margin-top: 8px;
}

.btn {
  flex: 1;
  height: 30px;
  border: none;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  transition: opacity 0.1s, transform 0.05s;
}

.btn:active {
  transform: scale(0.97);
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* Limit block: full opacity + amber outline, vs faded generic disabled. */
.btn-buy.limit-blocked,
.btn-sell.limit-blocked {
  opacity: 1;
  cursor: not-allowed;
  outline: 2px solid #ffb400;
  outline-offset: -2px;
  filter: grayscale(0.7);
}

.btn-buy {
  background: var(--bid);
  color: #0d1117;
}

.btn-buy:hover:not(:disabled) {
  background: #4cc95f;
}

.btn-sell {
  background: var(--ask);
  color: #fff;
}

.btn-sell:hover:not(:disabled) {
  background: #fa6358;
}

.order-status {
  margin-top: 6px;
  font-size: 11px;
  min-height: 14px;
}

.order-status.success {
  color: var(--bid);
}

.order-status.error {
  color: var(--ask);
}

/* ===== Auto-center toggle ===== */

.auto-center-toggle {
  margin-top: 6px;
  font-size: 11px;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.auto-center-toggle input[type="checkbox"] {
  accent-color: var(--accent);
  cursor: pointer;
}

.auto-center-toggle label {
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
}

.center-now-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 13px;
  width: 24px;
  height: 20px;
  border-radius: 3px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: border-color 0.1s, color 0.1s;
}

.center-now-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* ===== My Orders ===== */

.my-orders-panel {
  padding: 10px;
  border-bottom: 1px solid var(--border);
  max-height: 160px;
  overflow-y: auto;
  flex-shrink: 0;
}

.my-orders-panel h2 {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-dim);
  margin-bottom: 0;
}

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

.cancel-all-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  padding: 2px 8px;
  border-radius: 3px;
  cursor: pointer;
  transition: border-color 0.1s, color 0.1s;
}

.cancel-all-btn:hover {
  border-color: var(--ask);
  color: var(--ask);
}

.cancel-all-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.my-orders-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.my-order-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 8px;
  border-radius: 4px;
  font-family: "SF Mono", "Cascadia Code", "Fira Code", monospace;
  font-size: 11px;
  background: var(--bg);
  border: 1px solid var(--border);
}

.my-order-row .side-tag {
  font-weight: 700;
  font-size: 10px;
  padding: 1px 4px;
  border-radius: 2px;
  margin-right: 6px;
}

.my-order-row .side-tag.buy {
  background: var(--bid-bg);
  color: var(--bid);
  border: 1px solid rgba(63, 185, 80, 0.3);
}

.my-order-row .side-tag.sell {
  background: var(--ask-bg);
  color: var(--ask);
  border: 1px solid rgba(248, 81, 73, 0.3);
}

.my-order-row .cancel-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 3px;
  cursor: pointer;
  margin-left: 8px;
}

.my-order-row .cancel-btn:hover {
  border-color: var(--ask);
  color: var(--ask);
}

/* ===== Shared Panels ===== */

.shared-panels {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0;
  border-top: 1px solid var(--border);
  flex: 0 0 260px;
  overflow: hidden;
}

.shared-panel {
  padding: 10px;
  border-right: 1px solid var(--border);
  overflow-y: auto;
  background: var(--bg-panel);
}

.shared-panel:last-child {
  border-right: none;
}

.shared-panel h2 {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-dim);
  margin-bottom: 6px;
}

/* ===== Positions ===== */

.positions-table {
  width: 100%;
  border-collapse: collapse;
  font-family: "SF Mono", "Cascadia Code", "Fira Code", monospace;
  font-size: 11px;
}

.positions-table th {
  text-align: right;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  color: var(--text-muted);
  padding: 2px 4px 4px;
  border-bottom: 1px solid var(--border);
}

.positions-table th:first-child {
  text-align: left;
}

.positions-table td {
  padding: 3px 4px;
  text-align: right;
  border-bottom: 1px solid rgba(48, 54, 61, 0.4);
}

.positions-table td:first-child {
  text-align: left;
}

.position-symbol {
  font-weight: 700;
  color: var(--accent);
}

/* Position at/over its per-symbol limit — flag the row. */
.position-row.position-limit-warning {
  background: rgba(255, 180, 0, 0.12);
}
.position-row.position-limit-warning .position-symbol::after {
  content: " ⚠";
  color: #ffb400;
}

.position-shares {
  font-weight: 600;
}

.position-row.long .position-shares {
  color: var(--bid);
}

.position-row.short .position-shares {
  color: var(--ask);
}

.position-avg {
  color: var(--text-dim);
}

.position-mark {
  color: var(--text-muted);
}

.position-realized {
  font-weight: 600;
}

.position-realized.positive {
  color: var(--bid);
}

.position-realized.negative {
  color: var(--ask);
}

.position-row.flat .position-shares {
  color: var(--text-muted);
}

.position-row.flat .position-avg {
  color: var(--text-muted);
}

.position-pnl {
  font-weight: 700;
}

.position-pnl.positive {
  color: var(--bid);
}

.position-pnl.negative {
  color: var(--ask);
}

.total-pnl {
  font-family: "SF Mono", "Cascadia Code", "Fira Code", monospace;
  font-size: 14px;
  font-weight: 700;
}

.total-pnl.positive {
  color: var(--bid);
}

.total-pnl.negative {
  color: var(--ask);
}

/* ===== Trades ===== */

.trades-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.trade-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 2px 8px;
  font-family: "SF Mono", "Cascadia Code", "Fira Code", monospace;
  font-size: 11px;
  border-radius: 2px;
}

.trade-row.flash {
  animation: trade-flash 0.6s ease-out;
}

@keyframes trade-flash {
  0% { background: rgba(88, 166, 255, 0.2); }
  100% { background: transparent; }
}

.trade-row .trade-price {
  font-weight: 600;
}

.trade-row .trade-qty {
  color: var(--text-dim);
}

.trade-row .trade-time {
  color: var(--text-muted);
  font-size: 10px;
}

.trade-counterparty {
  color: var(--accent);
  font-size: 10px;
  font-weight: 600;
  margin-left: 4px;
}

/* ===== Trade History ===== */

.trade-history-table {
  width: 100%;
  border-collapse: collapse;
  font-family: "SF Mono", "Cascadia Code", "Fira Code", monospace;
  font-size: 11px;
}

.trade-history-table th {
  text-align: right;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  color: var(--text-muted);
  padding: 2px 4px 4px;
  border-bottom: 1px solid var(--border);
}

.trade-history-table th:first-child {
  text-align: left;
}

.trade-history-table td {
  padding: 3px 4px;
  text-align: right;
  border-bottom: 1px solid rgba(48, 54, 61, 0.4);
}

.trade-history-table td:first-child {
  text-align: left;
}

.trade-history-symbol {
  font-weight: 700;
  color: var(--accent);
}

.trade-history-side {
  font-weight: 700;
}

.trade-history-side.buy {
  color: var(--bid);
}

.trade-history-side.sell {
  color: var(--ask);
}

.trade-history-liquidity {
  font-size: 10px;
  font-weight: 600;
  padding: 1px 4px;
  border-radius: 2px;
}

.trade-history-liquidity.maker {
  background: rgba(88, 166, 255, 0.15);
  color: var(--accent);
  border: 1px solid rgba(88, 166, 255, 0.3);
}

.trade-history-liquidity.taker {
  background: rgba(210, 153, 34, 0.15);
  color: #d29922;
  border: 1px solid rgba(210, 153, 34, 0.3);
}

.trade-history-cp {
  color: var(--text-dim);
}

/* ===== Scrollbar ===== */

::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* ===== Empty state ===== */

.empty-state {
  text-align: center;
  color: var(--text-muted);
  font-size: 12px;
  padding: 20px;
}
