@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
  --bg:      #0b0e11;
  --surface: #1e2026;
  --surf2:   #2b3139;
  --border:  #2b3139;
  --text:    #eaecef;
  --muted:   #848e9c;
  --green:   #0ecb81;
  --red:     #f6465d;
  --yellow:  #f0b90b;
  --blue:    #1890ff;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 13px;
  line-height: 1.5;
}

/* ── Header ─────────────────────────────────────────── */
#header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
#header h1 { font-size: 14px; font-weight: 700; color: var(--yellow); }

.badge {
  display: inline-flex; align-items: center;
  padding: 2px 7px;
  border-radius: 3px;
  font-size: 10px; font-weight: 600; letter-spacing: .4px; text-transform: uppercase;
}
.badge-running { background: rgba(14,203,129,.15); color: var(--green); }
.badge-stale   { background: rgba(240,185,11,.15);  color: var(--yellow); }
.badge-offline,
.badge-stopped { background: rgba(246,70,93,.15);   color: var(--red); }
.badge-buy     { background: rgba(14,203,129,.15);  color: var(--green); }
.badge-sell    { background: rgba(246,70,93,.15);   color: var(--red); }
.badge-session { background: rgba(24,144,255,.12);  color: var(--blue); }
.badge-neutral { background: var(--surf2); color: var(--muted); }

#header-meta { margin-left: auto; color: var(--muted); font-size: 11px; }
#ws-dot {
  display: inline-block; width: 7px; height: 7px;
  border-radius: 50%; background: var(--muted);
  margin-right: 4px; vertical-align: middle; transition: background .3s;
}
#ws-dot.live { background: var(--green); box-shadow: 0 0 5px var(--green); }

/* ── Bot Tab Bar ─────────────────────────────────────── */
#bot-tabs {
  display: flex;
  align-items: stretch;
  flex-wrap: wrap;
  gap: 0;
  padding: 0 4px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.bot-tab {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  cursor: pointer;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  border-bottom: 2px solid transparent;
  white-space: nowrap;
  transition: color .15s, border-color .15s;
  user-select: none;
}
.bot-tab:hover { color: var(--text); }
.bot-tab.active { color: var(--yellow); border-bottom-color: var(--yellow); }

.bot-tab .bot-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--muted);
  flex-shrink: 0;
  transition: background .3s;
}
.bot-tab .bot-dot.running { background: var(--green); box-shadow: 0 0 5px rgba(14,203,129,.5); }
.bot-tab .bot-dot.stale   { background: var(--yellow); }
.bot-tab .bot-dot.offline,
.bot-tab .bot-dot.stopped { background: var(--red); }

.bot-tab .bot-pnl {
  font-size: 10px;
  font-weight: 500;
  margin-left: 2px;
}
.bot-tab .bot-pnl.pos { color: var(--green); }
.bot-tab .bot-pnl.neg { color: var(--red); }

/* ── Grid ───────────────────────────────────────────── */
#main {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px; padding: 8px;
}

/* ── Card ───────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 12px 14px;
}
.card-title {
  font-size: 10px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .6px;
  color: var(--muted); margin-bottom: 8px;
}

/* ── Stat cards ─────────────────────────────────────── */
.stat-val { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -.3px; }
.stat-sub { font-size: 11px; color: var(--muted); margin-top: 2px; }
.positive { color: var(--green); }
.negative { color: var(--red); }
.neutral  { color: var(--text); }
.warn     { color: var(--yellow); }

/* ── Candlestick chart ──────────────────────────────── */
#chart-card { grid-column: 1 / 4; }
#chart-card .card-title { margin-bottom: 4px; }

.legend-item { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; font-weight: 500; color: var(--muted); }
.legend-box  { width: 12px; height: 6px; border-radius: 1px; }
.legend-box.bull      { background: var(--green); border: 1px solid var(--green); }
.legend-box.bear      { background: var(--red);   border: 1px solid var(--red); }
.legend-box.bull-slow { background: transparent;  border: 1px dashed var(--blue); }
.legend-box.bear-slow { background: transparent;  border: 1px dashed var(--yellow); }

#candle-chart-wrap { position: relative; height: 320px; width: 100%; }
#candle-chart      { width: 100%; height: 100%; }
#chart-empty {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  color: var(--muted); font-size: 12px; pointer-events: none;
}

/* ── Position card ──────────────────────────────────── */
#position-card { grid-column: 4 / 5; overflow-y: auto; max-height: 380px; }

.pos-block { padding: 4px 0; }
.pos-divider { height: 1px; background: var(--border); margin: 6px 0; }
.pos-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 3px 0;
  font-size: 12px;
}
.pos-label { color: var(--muted); flex-shrink: 0; margin-right: 8px; }
.pos-val   { font-variant-numeric: tabular-nums; font-weight: 500; text-align: right; }

/* ── Signal ─────────────────────────────────────────── */
#signal-card { grid-column: 1 / 3; }

.sig-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2px 10px;
}

/* Each sig-item is now a column (row + optional progress bar) */
.sig-item {
  display: flex; flex-direction: column;
  padding: 4px 0; border-bottom: 1px solid rgba(43,49,57,.6);
  font-size: 11px;
}
.sig-item:last-child  { border-bottom: none; }

.sig-item-row {
  display: flex; justify-content: space-between; align-items: center;
}
.sig-label { color: var(--muted); }
.sig-val   { font-variant-numeric: tabular-nums; font-weight: 600; }
.ok        { color: var(--green); }
.fail      { color: var(--red); }

/* Progress bars */
.sig-item-progress { margin-top: 3px; }
.sig-bar-wrap {
  position: relative;
  height: 4px; border-radius: 2px;
  background: var(--surf2);
  overflow: hidden;
}
.sig-bar {
  height: 100%; border-radius: 2px;
  transition: width .3s ease;
}
.sig-bar-ok      { background: var(--green); }
.sig-bar-fail    { background: var(--red); }
.sig-bar-neutral { background: var(--muted); }
.sig-thresh {
  position: absolute; top: 0; bottom: 0;
  width: 2px; background: rgba(240,185,11,.9);
  transform: translateX(-50%);
  z-index: 1;
}

/* ── RSI Gauge ──────────────────────────────────────── */
.rsi-gauge-wrap {
  position: relative;
  height: 6px;
  border-radius: 3px;
  overflow: visible;
  background: var(--surf2);
  margin-top: 4px;
}

/* Colored zone segments */
.rsi-seg {
  position: absolute;
  top: 0; bottom: 0;
  border-radius: 0;
}
.rsi-seg:first-of-type { border-radius: 3px 0 0 3px; }
.rsi-seg:last-of-type  { border-radius: 0 3px 3px 0; }

.rsi-seg-dead { background: var(--surf2); }
.rsi-seg-buy  { background: rgba(14,203,129,.25); }
.rsi-seg-sell { background: rgba(246,70,93,.25); }
.rsi-seg-both { background: rgba(240,185,11,.25); }

/* Boundary tick marks */
.rsi-tick {
  position: absolute;
  top: -2px; bottom: -2px;
  width: 1.5px;
  transform: translateX(-50%);
  border-radius: 1px;
  z-index: 2;
  opacity: .75;
}
.rsi-tick-buy  { background: var(--green); }
.rsi-tick-sell { background: var(--red); }

/* Current value needle */
.rsi-needle {
  position: absolute;
  top: -3px; bottom: -3px;
  width: 3px;
  border-radius: 2px;
  transform: translateX(-50%);
  z-index: 3;
  box-shadow: 0 0 4px currentColor;
  transition: left .3s ease;
}
.rsi-needle-buy  { background: var(--green); box-shadow: 0 0 5px rgba(14,203,129,.7); }
.rsi-needle-sell { background: var(--red);   box-shadow: 0 0 5px rgba(246,70,93,.7); }
.rsi-needle-both { background: var(--yellow);box-shadow: 0 0 5px rgba(240,185,11,.7); }
.rsi-needle-dead { background: var(--muted); box-shadow: none; }

/* ── Next Order ─────────────────────────────────────── */
#nextorder-card { grid-column: 3 / 5; }

.req-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2px 10px;
}
.req-item {
  display: flex; justify-content: space-between; align-items: center;
  padding: 3px 0; border-bottom: 1px solid rgba(43,49,57,.6);
  font-size: 11px;
}
.req-item:last-child { border-bottom: none; }
.req-label { color: var(--muted); }
.req-val   { font-weight: 600; font-size: 11px; }

/* ── Trade table ────────────────────────────────────── */
#trades-card { grid-column: 1 / 5; }
.trade-table { width: 100%; border-collapse: collapse; }
.trade-table th {
  font-size: 10px; text-transform: uppercase; letter-spacing: .5px;
  color: var(--muted); text-align: left;
  padding: 4px 8px; border-bottom: 1px solid var(--border);
}
.trade-table td {
  padding: 5px 8px; font-size: 12px;
  border-bottom: 1px solid rgba(43,49,57,.6);
  font-variant-numeric: tabular-nums;
}
.trade-table tbody tr:hover td { background: var(--surf2); }
.dir-buy  { color: var(--green); font-weight: 600; }
.dir-sell { color: var(--red);   font-weight: 600; }

.no-data {
  color: var(--muted); font-style: italic;
  padding: 14px 0; text-align: center; font-size: 12px;
}

/* ── Tablet (600–1023px) ────────────────────────────── */
@media (max-width: 1023px) {
  #main { grid-template-columns: 1fr 1fr; }

  #chart-card,
  #position-card,
  #signal-card,
  #nextorder-card,
  #trades-card { grid-column: 1 / 3; }

  #position-card { max-height: none; }
}

/* ── Mobile (<600px) ────────────────────────────────── */
@media (max-width: 599px) {
  #main { grid-template-columns: 1fr 1fr; gap: 6px; padding: 6px; }

  .stat-card { padding: 8px 10px; }
  .stat-val  { font-size: 15px; }
  .stat-sub  { font-size: 10px; }

  #candle-chart-wrap { height: 220px; }

  .col-sl,
  .col-reason { display: none; }

  .trade-table th,
  .trade-table td { padding: 4px 5px; font-size: 11px; }

  #header { padding: 7px 10px; gap: 6px; }
  #header h1 { font-size: 13px; }

  .bot-tab { padding: 5px 7px; font-size: 10px; gap: 4px; }
  .bot-tab .bot-dot { width: 6px; height: 6px; }
  .bot-tab .bot-pnl { display: none; }
}
