/* ============================================================
   Matchloop Simulator — Custom CSS
   Dark navy palette with teal accent
   ============================================================ */

:root {
  --bg: #080c14;
  --surface: #0f1623;
  --surface2: #141d2e;
  --border: #1e2d45;
  --accent: #00d4aa;
  --accent-dim: rgba(0, 212, 170, 0.15);
  --accent-glow: rgba(0, 212, 170, 0.4);
  --buy: #00c853;
  --buy-dim: rgba(0, 200, 83, 0.12);
  --sell: #ff4757;
  --sell-dim: rgba(255, 71, 87, 0.12);
  --warn: #ffb300;
  --text: #e8edf5;
  --text-sec: #8892a4;
  --text-dim: #4a5568;
  --radius: 10px;
  --radius-sm: 6px;
}

/* ── Reset & Base ── */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", "Segoe UI", system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  overflow: hidden;
}

/* ── Scrollbar ── */
::-webkit-scrollbar {
  width: 5px;
  height: 5px;
}
::-webkit-scrollbar-track {
  background: var(--surface);
}
::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 99px;
}

/* ── Layout ── */
#app {
  display: grid;
  grid-template-rows: 52px 1fr;
  grid-template-columns: 280px 1fr;
  height: 100vh;
  overflow: hidden;
}

/* ── Header ── */
#header {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  padding: 0 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  gap: 12px;
  z-index: 10;
}

#header .logo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 15px;
  letter-spacing: -0.3px;
  color: var(--text);
}

#header .logo-icon {
  width: 26px;
  height: 26px;
  background: var(--accent);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
}

#header .spacer {
  flex: 1;
}

.status-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 99px;
  font-size: 12px;
  font-weight: 500;
  background: var(--surface2);
  border: 1px solid var(--border);
  transition: all 0.3s;
}

.status-badge .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-dim);
  transition: all 0.3s;
}

.status-badge.running {
  border-color: var(--accent);
  color: var(--accent);
}
.status-badge.running .dot {
  background: var(--accent);
  box-shadow: 0 0 6px var(--accent-glow);
  animation: pulse 1.2s infinite;
}
.status-badge.stopped {
  color: var(--text-sec);
}

@keyframes pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.4;
  }
}

/* ── Sidebar ── */
#sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.section-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 6px;
}

/* ── Preset buttons ── */
.preset-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.preset-btn {
  padding: 8px 6px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text-sec);
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
  text-align: center;
  transition: all 0.18s;
}

.preset-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-dim);
}
.preset-btn.active {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-dim);
}

.preset-btn .preset-name {
  display: block;
  font-weight: 600;
  font-size: 11px;
}
.preset-btn .preset-sub {
  display: block;
  font-size: 10px;
  color: var(--text-dim);
  margin-top: 2px;
}

/* ── Form ── */
.param-row {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.param-label {
  font-size: 11px;
  color: var(--text-sec);
  display: flex;
  justify-content: space-between;
}

.param-label span {
  color: var(--accent);
  font-weight: 600;
}

input[type="range"] {
  -webkit-appearance: none;
  width: 100%;
  height: 3px;
  background: var(--border);
  border-radius: 99px;
  outline: none;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  background: var(--accent);
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 0 6px var(--accent-glow);
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.toggle {
  position: relative;
  width: 36px;
  height: 20px;
}

.toggle input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle .slider {
  position: absolute;
  inset: 0;
  background: var(--border);
  border-radius: 99px;
  cursor: pointer;
  transition: 0.2s;
}

.toggle .slider::before {
  content: "";
  position: absolute;
  height: 14px;
  width: 14px;
  left: 3px;
  bottom: 3px;
  background: var(--text-sec);
  border-radius: 50%;
  transition: 0.2s;
}

.toggle input:checked + .slider {
  background: var(--accent);
}
.toggle input:checked + .slider::before {
  transform: translateX(16px);
  background: var(--bg);
}

/* ── Action buttons ── */
.btn {
  width: 100%;
  padding: 10px;
  border-radius: var(--radius-sm);
  border: none;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.18s;
  letter-spacing: 0.2px;
}

.btn-start {
  background: var(--accent);
  color: var(--bg);
}

.btn-start:hover {
  background: #00f0c0;
  box-shadow: 0 0 16px var(--accent-glow);
}
.btn-start:disabled {
  background: var(--text-dim);
  cursor: not-allowed;
  box-shadow: none;
}

.btn-stop {
  background: var(--sell-dim);
  color: var(--sell);
  border: 1px solid var(--sell);
}

.btn-stop:hover {
  background: rgba(255, 71, 87, 0.25);
}
.btn-stop:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn-reset {
  background: transparent;
  color: var(--text-sec);
  border: 1px solid var(--border);
  font-size: 12px;
}

.btn-reset:hover {
  border-color: var(--text-sec);
  color: var(--text);
}

/* ── Main content area ── */
#main {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
}

/* ── KPI bar ── */
#kpi-bar {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 1px;
  background: var(--border);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.kpi-card {
  background: var(--surface);
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.kpi-label {
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  color: var(--text-dim);
}
.kpi-value {
  font-size: 22px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  line-height: 1.1;
}
.kpi-sub {
  font-size: 10px;
  color: var(--text-sec);
}
.kpi-value.accent {
  color: var(--accent);
}
.kpi-value.buy {
  color: var(--buy);
}
.kpi-value.sell {
  color: var(--sell);
}

/* ── Charts + right column ── */
#content-row {
  display: grid;
  grid-template-columns: 1fr 360px;
  flex: 1;
  overflow: hidden;
  gap: 1px;
  background: var(--border);
}

#charts-col {
  display: flex;
  flex-direction: column;
  gap: 1px;
  background: var(--border);
  overflow: hidden;
}

/* ── Chart cards ── */
.chart-card {
  background: var(--surface);
  padding: 12px 16px;
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

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

.chart-title {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: var(--text-sec);
}

.chart-legend {
  display: flex;
  gap: 12px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 10px;
  color: var(--text-sec);
}

.legend-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.chart-wrap {
  flex: 1;
  min-height: 0;
  position: relative;
}
.chart-wrap canvas {
  width: 100% !important;
  height: 100% !important;
}

/* ── Right column ── */
#right-col {
  display: flex;
  flex-direction: column;
  gap: 1px;
  background: var(--border);
  overflow: hidden;
}

/* ── Order book ── */
#order-book {
  background: var(--surface);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

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

#symbol-select {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 3px 6px;
  font-size: 11px;
  outline: none;
  cursor: pointer;
}

#symbol-select:focus {
  border-color: var(--accent);
}

.book-cols {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  flex: 1;
  overflow: hidden;
}

.book-side {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.book-side-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 1px;
  text-transform: uppercase;
  margin-bottom: 4px;
  flex-shrink: 0;
}

.book-side-label.buy-label {
  color: var(--buy);
}
.book-side-label.sell-label {
  color: var(--sell);
}

.book-rows {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.book-row {
  position: relative;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 11.5px;
  font-variant-numeric: tabular-nums;
  display: flex;
  justify-content: space-between;
  align-items: center;
  overflow: hidden;
}

.book-row .bar {
  position: absolute;
  inset-y: 0;
  border-radius: 4px;
  opacity: 0.18;
  transition: width 0.3s ease;
  /* buy bars grow from right; sell bars from left — keeps price text clear */
}

.book-row.buy-row .bar {
  background: var(--buy);
  right: 0;
  left: auto;
}
.book-row.sell-row .bar {
  background: var(--sell);
  left: 0;
  right: auto;
}

.book-row span {
  position: relative;
  z-index: 1;
}
.book-row .price {
  color: var(--text);
  font-weight: 600;
  letter-spacing: 0.2px;
}
.book-row.buy-row .price {
  color: var(--buy);
}
.book-row.sell-row .price {
  color: var(--sell);
}
.book-row .qty {
  color: var(--text-sec);
  font-size: 10.5px;
}

/* ── Shard distribution ── */
#shard-bar {
  background: var(--surface);
  padding: 10px 14px;
  flex-shrink: 0;
}

.shard-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 3px;
}

.shard-label {
  font-size: 10px;
  color: var(--text-sec);
  width: 52px;
  flex-shrink: 0;
}
.shard-track {
  flex: 1;
  height: 6px;
  background: var(--border);
  border-radius: 99px;
  overflow: hidden;
}
.shard-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 99px;
  transition: width 0.4s ease;
}
.shard-count {
  font-size: 10px;
  color: var(--text-sec);
  width: 40px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* ── Match feed ── */
#match-feed {
  background: var(--surface);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

#feed-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.feed-item {
  padding: 5px 8px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface2);
  font-size: 10px;
  animation: slideIn 0.2s ease;
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(-4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.feed-key {
  font-weight: 600;
  color: var(--accent);
}
.feed-lat {
  color: var(--warn);
}
.feed-ids {
  color: var(--text-dim);
  margin-top: 2px;
  font-size: 9px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Progress bar ── */
#progress-wrap {
  flex-shrink: 0;
  padding: 4px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
}

#progress-track {
  flex: 1;
  height: 4px;
  background: var(--border);
  border-radius: 99px;
  overflow: hidden;
}

#progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), #00a884);
  border-radius: 99px;
  transition: width 0.4s ease;
}

#progress-label {
  font-size: 11px;
  color: var(--text-sec);
  width: 36px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* ── Divider ── */
.divider {
  height: 1px;
  background: var(--border);
  margin: 4px 0;
}

/* ── Idle overlay ── */
#idle-overlay {
  position: fixed;
  inset: 0;
  background: rgba(8, 12, 20, 0.75);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  transition: opacity 0.4s;
}

#idle-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.idle-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 40px 48px;
  text-align: center;
  max-width: 420px;
}

.idle-logo {
  font-size: 48px;
  margin-bottom: 16px;
}

.idle-title {
  font-size: 24px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 8px;
  letter-spacing: -0.5px;
}

.idle-sub {
  font-size: 14px;
  color: var(--text-sec);
  margin-bottom: 28px;
  line-height: 1.6;
}

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

.idle-preset {
  padding: 12px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface2);
  cursor: pointer;
  text-align: left;
  transition: all 0.18s;
}

.idle-preset:hover {
  border-color: var(--accent);
  background: var(--accent-dim);
}
.idle-preset .p-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}
.idle-preset .p-desc {
  font-size: 11px;
  color: var(--text-sec);
  margin-top: 3px;
}

.idle-custom {
  font-size: 12px;
  color: var(--text-dim);
  cursor: pointer;
  text-decoration: underline;
  text-decoration-color: var(--text-dim);
}

.idle-custom:hover {
  color: var(--text-sec);
}
