:root {
  --bg: #0b0e14;
  --surface: #121722;
  --surface-2: #171e2d;
  --border: #1e2638;
  --border-bright: #2b3752;
  --text: #f1f5f9;
  --muted: #8b9bb4;
  --emerald: #10b981;
  --emerald-soft: rgba(16, 185, 129, 0.14);
  --rose: #f43f5e;
  --rose-soft: rgba(244, 63, 94, 0.14);
  --cyan: #06b6d4;
  --cyan-soft: rgba(6, 182, 212, 0.14);
  --amber: #f59e0b;
  --amber-soft: rgba(245, 158, 11, 0.14);
  --purple: #a855f7;
  --indigo: #6366f1;
  --radius: 12px;
}

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

body {
  background: radial-gradient(circle at top right, #131c31 0%, var(--bg) 45%);
  color: var(--text);
  font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 13.5px;
  line-height: 1.45;
  min-height: 100vh;
}

.mono {
  font-family: 'JetBrains Mono', monospace;
  font-variant-numeric: tabular-nums;
}

.muted {
  color: var(--muted);
}

.c-cyan { color: var(--cyan); }
.c-amber { color: var(--amber); }
.c-purple { color: var(--purple); }
.c-emerald { color: var(--emerald); }
.c-rose { color: var(--rose); }
.text-danger { color: var(--rose); }
.text-success { color: var(--emerald); }
.hidden { display: none !important; }
.full-width { width: 100%; }

/* Topbar */
.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 20px;
  background: rgba(18, 23, 34, 0.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 40;
}

.topbar-left, .topbar-center, .topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

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

.brand-mark {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--cyan), var(--indigo));
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 18px;
  color: #fff;
  box-shadow: 0 4px 14px rgba(6, 182, 212, 0.25);
}

.brand-mark.large {
  width: 48px;
  height: 48px;
  font-size: 22px;
  margin: 0 auto 12px;
}

.brand-title {
  font-weight: 800;
  font-size: 15px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.badge-tag {
  font-size: 10px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 5px;
  background: var(--cyan-soft);
  color: var(--cyan);
  letter-spacing: 0.5px;
}

.brand-sub {
  font-size: 11px;
  color: var(--muted);
}

.connection-pill {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 5px 10px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 11.5px;
  color: var(--muted);
}

.connection-pill .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--amber);
}

.connection-pill.online .dot {
  background: var(--emerald);
  box-shadow: 0 0 8px var(--emerald);
}

.control-group {
  display: flex;
  align-items: center;
  gap: 6px;
}

.ctrl-label {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.select-ctrl {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border-bright);
  border-radius: 8px;
  padding: 6px 10px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 12.5px;
  cursor: pointer;
}

.tf-pills {
  display: flex;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 2px;
}

.tf-btn {
  background: transparent;
  border: none;
  color: var(--muted);
  padding: 5px 9px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: 0.15s;
}

.tf-btn:hover { color: var(--text); }
.tf-btn.active {
  background: var(--indigo);
  color: #fff;
}

.mode-switch {
  display: flex;
  background: var(--surface-2);
  border: 1px solid var(--border-bright);
  border-radius: 9px;
  padding: 3px;
}

.mode-btn {
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 700;
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: 0.2s;
}

.mode-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
}

.mode-dot.paper { background: var(--cyan); }
.mode-dot.live { background: var(--rose); }

.mode-btn.active[data-mode="PAPER"] {
  background: var(--cyan-soft);
  color: var(--cyan);
}

.mode-btn.active[data-mode="LIVE"] {
  background: var(--rose-soft);
  color: var(--rose);
}

/* Buttons */
.btn {
  border: none;
  border-radius: 8px;
  padding: 8px 14px;
  font-weight: 700;
  font-size: 12.5px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  transition: 0.15s ease;
  font-family: inherit;
}

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

.btn-primary {
  background: linear-gradient(135deg, var(--indigo), #4f46e5);
  color: #fff;
}
.btn-primary:hover { filter: brightness(1.1); }

.btn-emerald {
  background: linear-gradient(135deg, var(--emerald), #059669);
  color: #fff;
}
.btn-emerald:hover { filter: brightness(1.1); }

.btn-amber {
  background: linear-gradient(135deg, var(--amber), #d97706);
  color: #0b0e14;
}

.btn-danger {
  background: linear-gradient(135deg, var(--rose), #e11d48);
  color: #fff;
}

.btn-danger-outline {
  background: var(--rose-soft);
  border: 1px solid rgba(244, 63, 94, 0.35);
  color: var(--rose);
}
.btn-danger-outline:hover {
  background: var(--rose);
  color: #fff;
}

.btn-ghost {
  background: var(--surface-2);
  border: 1px solid var(--border-bright);
  color: var(--text);
}

.btn-sm {
  padding: 4px 9px;
  font-size: 11.5px;
  border-radius: 6px;
}

.pulse-ring {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #fff;
  animation: pulse 1.3s infinite;
}

@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(255, 255, 255, 0.7); }
  70% { box-shadow: 0 0 0 7px rgba(255, 255, 255, 0); }
  100% { box-shadow: 0 0 0 0 rgba(255, 255, 255, 0); }
}

/* KPI Strip */
.kpi-strip {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 12px;
  padding: 14px 20px 0;
}

.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
}

.kpi-card.highlight {
  background: linear-gradient(145deg, #131c2e, #121722);
  border-color: var(--border-bright);
}

.kpi-label {
  font-size: 11.5px;
  color: var(--muted);
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}

.kpi-value {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.3px;
}

.kpi-sub {
  font-size: 11.5px;
  color: var(--muted);
  margin-top: 3px;
}

.pill {
  font-size: 10px;
  font-weight: 800;
  padding: 2px 7px;
  border-radius: 999px;
  letter-spacing: 0.4px;
}
.pill-paper { background: var(--cyan-soft); color: var(--cyan); }
.pill-live { background: var(--rose-soft); color: var(--rose); }

/* Main Workspace */
.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 350px;
  gap: 14px;
  padding: 14px 20px 28px;
  align-items: start;
}

.main-col {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
}

.side-col {
  display: flex;
  flex-direction: column;
  gap: 12px;
  position: sticky;
  top: 72px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}

/* Chart Card */
.chart-header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.chart-title-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 14px;
}

.chart-title-group h2 {
  font-size: 16px;
  font-weight: 800;
}

.ema-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  font-size: 12px;
  color: var(--muted);
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.swatch {
  width: 10px;
  height: 3px;
  border-radius: 2px;
  display: inline-block;
}
.swatch.ema9 { background: var(--cyan); }
.swatch.ema21 { background: var(--amber); }
.swatch.ema50 { background: var(--purple); }

.subchart-tabs {
  display: flex;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 2px;
}

.sub-tab {
  border: none;
  background: transparent;
  color: var(--muted);
  padding: 5px 10px;
  font-size: 11.5px;
  font-weight: 700;
  border-radius: 6px;
  cursor: pointer;
}

.sub-tab.active {
  background: var(--border-bright);
  color: var(--text);
}

.main-chart {
  width: 100%;
  height: 360px;
}

.subchart-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 2px 4px;
  border-top: 1px solid var(--border);
  margin-top: 6px;
  font-size: 11.5px;
}

.subchart-label {
  font-weight: 700;
  color: var(--text);
}

.sub-chart {
  width: 100%;
  height: 135px;
}

/* Tabs Card */
.tabs-header {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 10px;
  margin-bottom: 14px;
  overflow-x: auto;
}

.tab-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--muted);
  padding: 7px 12px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 12.5px;
  cursor: pointer;
  white-space: nowrap;
}

.tab-btn:hover { color: var(--text); background: var(--surface-2); }
.tab-btn.active {
  background: var(--surface-2);
  border-color: var(--border-bright);
  color: var(--text);
}

.tab-pane { display: none; }
.tab-pane.active { display: block; }

.pane-section + .pane-section {
  margin-top: 20px;
}

.section-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.section-head h3 { font-size: 14px; font-weight: 700; }

/* Tables */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 10px;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
}

.data-table th {
  text-align: left;
  padding: 9px 11px;
  background: var(--surface-2);
  color: var(--muted);
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  border-bottom: 1px solid var(--border);
}

.data-table td {
  padding: 9px 11px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.data-table tr:last-child td { border-bottom: none; }
.empty-cell {
  text-align: center;
  color: var(--muted);
  padding: 22px !important;
}

/* Side Column Cards */
.card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.card-head h3 {
  font-size: 14px;
  font-weight: 700;
}

.signal-pill {
  font-size: 11.5px;
  font-weight: 800;
  padding: 4px 11px;
  border-radius: 999px;
  letter-spacing: 0.5px;
}
.signal-pill.buy { background: var(--emerald-soft); color: var(--emerald); border: 1px solid rgba(16, 185, 129, 0.4); }
.signal-pill.sell { background: var(--rose-soft); color: var(--rose); border: 1px solid rgba(244, 63, 94, 0.4); }
.signal-pill.hold { background: var(--amber-soft); color: var(--amber); border: 1px solid rgba(245, 158, 11, 0.3); }

.gauge-bar-bg {
  height: 10px;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.gauge-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--amber), var(--emerald));
  border-radius: 999px;
  transition: width 0.35s ease;
}

.gauge-meta {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  margin-top: 6px;
  margin-bottom: 10px;
}

.reasons-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 11.5px;
  color: var(--muted);
}

.reasons-list li {
  padding-left: 14px;
  position: relative;
}

.reasons-list li::before {
  content: '•';
  position: absolute;
  left: 2px;
  color: var(--cyan);
}

.indicators-stack {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.ind-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 11px 13px;
}

.ind-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.ind-name {
  font-weight: 700;
  font-size: 12.5px;
}

.mini-badge {
  font-size: 10px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 5px;
}
.mini-badge.bull { background: var(--emerald-soft); color: var(--emerald); }
.mini-badge.bear { background: var(--rose-soft); color: var(--rose); }
.mini-badge.neutral { background: var(--surface-2); color: var(--muted); }

.ema-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.ema-grid > div {
  background: var(--surface-2);
  padding: 6px 8px;
  border-radius: 7px;
  display: flex;
  flex-direction: column;
  font-size: 11.5px;
}

.ema-grid small { font-size: 10px; font-weight: 700; }

.ind-metric-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 7px;
}

.big-val {
  font-size: 18px;
  font-weight: 700;
}

.cmf-meter {
  position: relative;
  height: 8px;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
}

.cmf-center {
  position: absolute;
  left: 50%;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--border-bright);
  z-index: 2;
}

.cmf-fill {
  position: absolute;
  top: 0;
  bottom: 0;
  transition: all 0.3s ease;
}

.rsi-track {
  position: relative;
  height: 8px;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--emerald) 0%, var(--emerald) 30%, var(--amber) 50%, var(--rose) 75%, var(--rose) 100%);
}

.rsi-marker {
  position: absolute;
  top: -3px;
  width: 4px;
  height: 14px;
  background: #fff;
  border-radius: 2px;
  transform: translateX(-50%);
  box-shadow: 0 0 6px rgba(0,0,0,0.8);
}

.rsi-labels {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  color: var(--muted);
  margin-top: 4px;
}

.adx-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.adx-row > div {
  background: var(--surface-2);
  padding: 6px 8px;
  border-radius: 7px;
  display: flex;
  flex-direction: column;
}
.adx-row small { font-size: 10px; color: var(--muted); }
.adx-row strong { font-size: 14px; }

/* Manual Card */
.pct-buttons {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin: 8px 0 10px;
}

.pct-btn {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 5px;
  border-radius: 6px;
  font-size: 11.5px;
  font-weight: 700;
  cursor: pointer;
}
.pct-btn:hover { border-color: var(--cyan); color: var(--text); }

.manual-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

/* Forms & Config */
.config-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.config-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
}

.config-card h4 {
  font-size: 13.5px;
  margin-bottom: 10px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-bottom: 10px;
}

.field label {
  font-size: 11.5px;
  color: var(--muted);
}

.input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border-bright);
  border-radius: 7px;
  padding: 7px 10px;
  color: var(--text);
  font-size: 12.5px;
  font-family: inherit;
}

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

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

.form-row-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.checkbox-field {
  justify-content: flex-end;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  color: var(--text) !important;
  font-size: 12px !important;
  padding: 7px 0;
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 6px;
}

/* Backtest */
.backtest-controls {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.btn-align { justify-content: flex-end; }

.bt-metrics {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}

.bt-stat {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.bt-stat span { font-size: 11px; color: var(--muted); }
.bt-stat strong { font-size: 14px; }

.bt-chart {
  height: 200px;
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}

.api-result {
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--bg);
  border: 1px solid var(--border-bright);
  font-size: 12px;
}

.vps-guide h5 {
  font-size: 12.5px;
  margin-bottom: 6px;
}

.code-box {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 11.5px;
  color: var(--cyan);
  overflow-x: auto;
  white-space: pre-wrap;
}

/* Logs */
.logs-console {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  height: 320px;
  overflow-y: auto;
  font-size: 12px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.log-line {
  display: flex;
  gap: 8px;
  line-height: 1.4;
}

.log-time { color: var(--muted); flex-shrink: 0; }
.log-lvl { font-weight: 700; width: 58px; flex-shrink: 0; }
.log-lvl.INFO { color: var(--cyan); }
.log-lvl.SIGNAL { color: var(--amber); }
.log-lvl.TRADE { color: var(--emerald); }
.log-lvl.WARN { color: var(--amber); }
.log-lvl.ERROR { color: var(--rose); }

/* Modals & Toasts */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(5, 8, 14, 0.78);
  backdrop-filter: blur(6px);
  display: grid;
  place-items: center;
  z-index: 100;
  padding: 16px;
}

.modal-card {
  background: var(--surface);
  border: 1px solid var(--border-bright);
  border-radius: 14px;
  padding: 22px;
  max-width: 460px;
  width: 100%;
  box-shadow: 0 24px 60px rgba(0,0,0,0.6);
}

.pin-card { text-align: center; max-width: 360px; }
.pin-card .input { margin: 14px 0 10px; text-align: center; }

.modal-badge {
  display: inline-block;
  font-size: 10.5px;
  font-weight: 800;
  padding: 3px 9px;
  border-radius: 6px;
  margin-bottom: 10px;
}
.modal-badge.danger { background: var(--rose-soft); color: var(--rose); }

.modal-card h3 { font-size: 17px; margin-bottom: 8px; }
.checklist {
  margin: 12px 0 18px 18px;
  font-size: 12.5px;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.toast-container {
  position: fixed;
  bottom: 18px;
  right: 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 120;
}

.toast {
  background: var(--surface-2);
  border: 1px solid var(--border-bright);
  border-left: 4px solid var(--cyan);
  padding: 10px 14px;
  border-radius: 9px;
  font-size: 12.5px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.45);
  max-width: 340px;
}
.toast.success { border-left-color: var(--emerald); }
.toast.error { border-left-color: var(--rose); }

@media (max-width: 1200px) {
  .kpi-strip { grid-template-columns: repeat(3, 1fr); }
  .workspace { grid-template-columns: 1fr; }
  .side-col { position: static; }
}

@media (max-width: 768px) {
  .kpi-strip { grid-template-columns: repeat(2, 1fr); }
  .config-grid, .backtest-controls, .bt-metrics { grid-template-columns: 1fr; }
}
