:root {
  --bg: #070d14;
  --surface: rgba(16, 24, 36, 0.88);
  --surface-border: rgba(130, 154, 192, 0.22);
  --text: #dfe8f7;
  --muted: #9eb3cf;
  --accent: #23b26f;
  --accent-2: #4aa3ff;
  --danger: #d84f57;
  --glow-a: #1b5f46;
  --glow-b: #133a66;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  height: 100vh;
  font-family: "Space Grotesk", sans-serif;
  color: var(--text);
  background: radial-gradient(circle at 18% 10%, #173350 0%, transparent 35%),
    radial-gradient(circle at 82% 6%, #1f3b2b 0%, transparent 32%),
    linear-gradient(160deg, #070d14 0%, #09121d 45%, #0d1724 100%);
  overflow: hidden;
}

body.auth-locked .workspace-grid,
body.auth-locked .auth-banner {
  filter: blur(10px) saturate(0.7);
  pointer-events: none;
  user-select: none;
}

h1,
h2,
h3,
h4,
p {
  margin: 0;
}

.bg-orb {
  position: fixed;
  border-radius: 999px;
  filter: blur(70px);
  opacity: 0.3;
  z-index: 0;
  animation: drift 12s ease-in-out infinite alternate;
}

.bg-orb-a {
  width: 320px;
  height: 320px;
  left: -90px;
  bottom: 5%;
  background: var(--glow-a);
}

.bg-orb-b {
  width: 360px;
  height: 360px;
  right: -120px;
  top: 8%;
  background: var(--glow-b);
  animation-delay: 3s;
}

.auth-overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(5, 10, 16, 0.58);
  backdrop-filter: blur(14px);
}

.auth-overlay.visible {
  display: flex;
}

.auth-card {
  width: min(100%, 420px);
  border: 1px solid rgba(130, 154, 192, 0.24);
  border-radius: 24px;
  background: linear-gradient(180deg, rgba(13, 20, 31, 0.96), rgba(10, 16, 25, 0.92));
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
  padding: 28px;
}

.auth-card-head {
  display: grid;
  gap: 8px;
  margin-bottom: 18px;
}

.auth-kicker {
  color: #8df0bf;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 0.74rem;
  font-weight: 700;
}

.auth-copy {
  color: var(--muted);
  line-height: 1.5;
}

.auth-form {
  display: grid;
  gap: 14px;
}

.auth-form label {
  display: grid;
  gap: 8px;
}

.auth-error {
  min-height: 20px;
  margin: 0;
  color: #ff8f97;
  font-size: 0.9rem;
  display: none;
}

.auth-banner {
  position: fixed;
  top: 14px;
  right: 14px;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid rgba(130, 154, 192, 0.22);
  border-radius: 999px;
  background: rgba(8, 14, 22, 0.72);
  backdrop-filter: blur(12px);
}

.auth-user-label {
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.82rem;
  color: var(--text);
}

.workspace-grid {
  position: relative;
  z-index: 1;
  width: 100vw;
  height: 100vh;
  margin: 0;
  padding: 12px;
  display: grid;
  gap: 14px;
  grid-template-columns: 1fr;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--surface-border);
  backdrop-filter: blur(12px);
  border-radius: 16px;
  padding: 18px;
  box-shadow: 0 10px 34px rgba(0, 0, 0, 0.45);
  animation: reveal 0.8s ease both;
  min-height: 0;
}

.left-panel,
.center-panel,
.right-panel {
  height: 100%;
  min-height: 0;
}

.left-panel {
  display: flex;
  flex-direction: column;
}

.center-panel {
  display: flex;
  flex-direction: column;
}

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

.panel-head h2,
.panel-head h1 {
  letter-spacing: 0.02em;
}

.panel-head p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.86rem;
}

.center-head {
  margin-bottom: 14px;
}

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

.pair-search {
  width: 100%;
  margin-bottom: 10px;
}

.pair-list {
  flex: 1;
  min-height: 0;
  overflow: auto;
  display: grid;
  gap: 8px;
  padding-right: 2px;
}

.pair-item {
  border: 1px solid rgba(130, 154, 192, 0.24);
  border-radius: 12px;
  padding: 10px;
  background: rgba(13, 21, 33, 0.78);
  cursor: pointer;
  transition: border-color 0.15s ease, transform 0.15s ease;
}

.pair-item:hover {
  transform: translateY(-1px);
  border-color: rgba(74, 163, 255, 0.45);
}

.pair-item.active {
  border-color: rgba(35, 178, 111, 0.7);
  box-shadow: inset 0 0 0 1px rgba(35, 178, 111, 0.2);
}

.pair-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.pair-symbol {
  font-weight: 700;
}

.pair-last,
.pair-volume,
.pair-change {
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.82rem;
}

.pair-volume {
  color: var(--muted);
  font-size: 0.75rem;
  margin-top: 6px;
}

.change-up {
  color: var(--accent);
}

.change-down {
  color: var(--danger);
}

label {
  font-size: 0.92rem;
  color: var(--muted);
}

select,
input,
button {
  font-family: inherit;
  border-radius: 10px;
  border: 1px solid rgba(130, 154, 192, 0.35);
  padding: 10px 12px;
  font-size: 0.95rem;
}

select,
input {
  background: rgba(10, 16, 26, 0.9);
  color: var(--text);
}

button {
  border: none;
  color: white;
  background: linear-gradient(130deg, var(--accent), #1a8e58);
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

button:hover {
  transform: translateY(-1px);
  box-shadow: 0 7px 16px rgba(20, 108, 67, 0.3);
}

.ws-badge {
  display: inline-block;
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
  font-family: "IBM Plex Mono", monospace;
  letter-spacing: 0.03em;
}

.ws-connecting {
  background: rgba(189, 138, 29, 0.22);
  color: #ffd889;
}

.ws-open {
  background: rgba(20, 136, 84, 0.2);
  color: #8df0bf;
}

.ws-closed {
  background: rgba(216, 79, 87, 0.22);
  color: #ffb7bd;
}

#lastPriceChange {
  font-size: 0.78rem;
  font-weight: 500;
  padding: 2px 6px;
  border-radius: 6px;
}

.chart-panel {
  animation-delay: 0.2s;
}

.ticker-info {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}

.ticker-info span {
  color: var(--muted);
  font-size: 0.8rem;
}

.ticker-info strong {
  display: block;
  margin-top: 4px;
  font-family: "IBM Plex Mono", monospace;
  font-size: 1.1rem;
}

#candlestickChart {
  width: 100%;
  flex: 1;
  min-height: 420px;
  border-radius: 12px;
  overflow: hidden;
}

.right-panel {
  display: grid;
  gap: 12px;
  grid-template-rows: auto 1fr;
}

.block {
  border: 1px solid rgba(130, 154, 192, 0.22);
  border-radius: 12px;
  padding: 12px;
  background: rgba(11, 18, 29, 0.85);
}

.orderbook-block h3,
.bot-block h3 {
  margin-bottom: 10px;
}

.secondary-btn {
  background: linear-gradient(130deg, #5f6d84, #76859e);
}

.danger-btn {
  background: linear-gradient(130deg, #c9373e, #dc3545);
}

/* ─── BOT PANEL ─────────────────────────────────────────── */
.bot-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.bot-badge {
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 700;
  font-family: "IBM Plex Mono", monospace;
}

.bot-stopped { background: #e8eaf0; color: #3e4a5e; }
.bot-running { background: rgba(20, 136, 84, 0.24); color: #8df0bf; }
.bot-scanning { background: rgba(224, 144, 0, 0.22); color: #ffd889; }
.bot-offline  { background: rgba(216, 79, 87, 0.22); color: #ffb7bd; }
.bot-stopped  { background: rgba(122, 132, 150, 0.2); color: #c6d2e8; }

.bot-badge::before {
  content: '';
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  margin-right: 5px;
  vertical-align: middle;
  margin-top: -1px;
}
.bot-stopped::before { background: #8a93a6; }
.bot-running::before { background: #198754; animation: pulse-dot 1.8s ease-in-out infinite; }
.bot-scanning::before { background: #e09000; animation: pulse-dot 0.6s ease-in-out infinite; }
.bot-offline::before  { background: #dc3545; }

@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%       { opacity: 0.4; transform: scale(1.5); }
}

.bot-controls {
  display: flex;
  gap: 6px;
  margin-bottom: 10px;
}

.bot-controls button {
  flex: 1;
  font-size: 0.8rem;
  padding: 7px 6px;
}

.bot-start-btn {
  background: linear-gradient(130deg, #146c43, #198754);
}

.bot-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-bottom: 10px;
}

.bot-stat {
  background: rgba(13, 21, 33, 0.88);
  border: 1px solid rgba(130, 154, 192, 0.2);
  border-radius: 10px;
  padding: 7px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.bot-stat span { font-size: 0.68rem; color: var(--muted); }
.bot-stat strong { font-size: 0.78rem; font-family: "IBM Plex Mono", monospace; }

.bot-mode-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: fit-content;
  padding: 3px 8px;
  border-radius: 999px;
  border: 1px solid transparent;
  font-size: 0.7rem;
  font-weight: 700;
  line-height: 1.2;
}

.bot-mode-badge.mode-signal {
  background: rgba(224, 144, 0, 0.15);
  color: #7a4e00;
  border-color: rgba(224, 144, 0, 0.25);
}

.bot-mode-badge.mode-auto {
  background: rgba(20, 108, 67, 0.14);
  color: #0e4d2a;
  border-color: rgba(25, 135, 84, 0.24);
}

.bot-mode-badge.pos-long::before {
  content: "▲";
  margin-right: 5px;
  font-size: 0.62rem;
}

.bot-config-wrap {
  margin-bottom: 10px;
  border: 1px solid rgba(27, 36, 48, 0.1);
  border-radius: 10px;
  padding: 0;
  overflow: hidden;
}

.bot-config-wrap summary {
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 600;
  padding: 8px 12px;
  user-select: none;
  background: rgba(255, 255, 255, 0.5);
  list-style: none;
}

.bot-config-wrap summary::-webkit-details-marker { display: none; }
.bot-config-wrap[open] summary { border-bottom: 1px solid rgba(27, 36, 48, 0.1); }

.bot-config-form {
  display: grid;
  gap: 7px;
  padding: 10px 12px;
}

.bot-config-form label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.8rem;
  gap: 8px;
}

.bot-config-form .stack-label {
  display: flex;
  flex-direction: column;
  align-items: stretch;
}

.bot-config-form input,
.bot-config-form select {
  width: 110px;
  padding: 5px 8px;
  font-size: 0.8rem;
}

.bot-config-form .wide-input {
  width: 100%;
  margin-top: 6px;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
  justify-content: flex-start !important;
}

.bot-form-actions {
  display: flex;
  gap: 8px;
  margin-top: 4px;
}

.bot-form-actions button { flex: 1; }

.bot-section-title {
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  margin: 9px 0 5px;
}

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

.btn-sm {
  padding: 2px 9px;
  font-size: 0.68rem;
  border-radius: 6px;
}

.bot-chip-list {
  list-style: none;
  margin: 0 0 8px;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.bot-chip {
  padding: 4px 8px;
  border-radius: 999px;
  border: 1px solid rgba(130, 154, 192, 0.2);
  background: rgba(13, 21, 33, 0.88);
  color: var(--text);
  font-size: 0.68rem;
  font-family: "IBM Plex Mono", monospace;
}

.bot-empty-chip {
  color: var(--muted);
}

.bot-list {
  list-style: none;
  margin: 0 0 4px;
  padding: 0;
  max-height: 160px;
  overflow-y: auto;
  display: grid;
  gap: 5px;
}

.bot-list-item {
  border: 1px solid rgba(130, 154, 192, 0.2);
  border-radius: 8px;
  padding: 7px 10px;
  background: rgba(12, 20, 32, 0.82);
  font-size: 0.78rem;
}

.bot-empty { color: var(--muted); font-style: italic; }

.bot-pos-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
  font-size: 0.8rem;
}

.bot-pos-detail {
  color: var(--muted);
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.7rem;
  margin-top: 2px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.bot-news-refs {
  display: grid;
  gap: 4px;
  margin-top: 6px;
}

.bot-news-link {
  display: block;
  color: #7ec9ff;
  font-size: 0.69rem;
  line-height: 1.35;
  text-decoration: none;
  word-break: break-word;
}

.bot-news-link:hover {
  text-decoration: underline;
}

.badge-buy {
  background: #b6f0cc;
  color: #0e4d2a;
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 0.65rem;
  font-weight: 700;
}

.badge-win {
  background: rgba(20, 136, 84, 0.25);
  color: #8df0bf;
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  font-family: "IBM Plex Mono", monospace;
}

.badge-loss {
  background: rgba(216, 79, 87, 0.25);
  color: #ffb7bd;
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  font-family: "IBM Plex Mono", monospace;
}

.bot-score-bar {
  display: inline-block;
  width: 60px;
  height: 6px;
  background: rgba(125, 151, 191, 0.2);
  border-radius: 3px;
  overflow: hidden;
  vertical-align: middle;
}

.bot-score-bar > div {
  height: 100%;
  border-radius: 3px;
  transition: width 0.4s;
}

.bot-log-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 150px;
  overflow-y: auto;
  display: grid;
  gap: 3px;
}

.bot-log-item {
  font-size: 0.68rem;
  font-family: "IBM Plex Mono", monospace;
  padding: 3px 7px;
  border-radius: 5px;
  word-break: break-word;
}

.log-info    { color: #b4c6de; background: rgba(125, 151, 191, 0.14); }
.log-success { color: #8df0bf; background: rgba(20, 136, 84, 0.2); }
.log-warn    { color: #ffd889; background: rgba(224, 144, 0, 0.18); }
.log-error   { color: #ffb7bd; background: rgba(216, 79, 87, 0.2); }

.orderbook-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.orderbook-head select {
  width: 100px;
}

.orderbook-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.orderbook-grid h4 {
  font-size: 0.86rem;
  margin-bottom: 8px;
  color: var(--muted);
}

.order-list {
  list-style: none;
  padding: 0;
  margin: 0;
  max-height: 190px;
  overflow: auto;
  display: grid;
  gap: 6px;
}

.order-list li {
  border-radius: 8px;
  padding: 6px 8px;
  display: flex;
  justify-content: space-between;
  gap: 6px;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.74rem;
  background: rgba(12, 20, 32, 0.86);
}

.pnl-profit-total {
  color: #7df1b3;
}

.pnl-loss-total {
  color: #ff9ea6;
}

.asks li {
  border-left: 3px solid #d15050;
}

.bids li {
  border-left: 3px solid #2f9b63;
}

.history-list {
  list-style: none;
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: auto;
}

.history-list li {
  padding: 10px;
  border-radius: 10px;
  margin-bottom: 8px;
  background: rgba(255, 255, 255, 0.65);
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.82rem;
}

.history-list .buy {
  border-left: 4px solid var(--accent);
}

.history-list .sell {
  border-left: 4px solid var(--danger);
}

@keyframes reveal {
  from {
    opacity: 0;
    transform: translateY(18px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes drift {
  from {
    transform: translateY(0px);
  }
  to {
    transform: translateY(-20px);
  }
}

@media (min-width: 960px) {
  .workspace-grid {
    grid-template-columns: minmax(280px, 0.95fr) minmax(620px, 2.1fr) minmax(340px, 1fr);
  }
}

@media (max-width: 959px) {
  body {
    height: auto;
    min-height: 100vh;
    overflow: auto;
  }

  .workspace-grid {
    width: 100%;
    height: auto;
    min-height: 100vh;
  }

  .ticker-info {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .left-panel,
  .center-panel,
  .right-panel {
    height: auto;
  }

  .pair-list,
  .order-list {
    max-height: 280px;
  }

  #candlestickChart {
    min-height: 340px;
  }

  .orderbook-grid {
    grid-template-columns: 1fr;
  }
}

/* ─── POSITION BAR ───────────────────────────────────────── */
.position-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 7px 10px;
  background: rgba(18, 22, 30, 0.85);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.pos-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 12px;
  border-radius: 6px;
  font-size: 0.72rem;
  font-family: "IBM Plex Mono", monospace;
  border: 1px solid;
}

.pos-chip-profit {
  background: rgba(20, 108, 67, 0.15);
  border-color: rgba(25, 135, 84, 0.4);
  color: #d0fde9;
}

.pos-chip-loss {
  background: rgba(201, 55, 62, 0.15);
  border-color: rgba(201, 55, 62, 0.4);
  color: #fde0e0;
}

.pos-chip-tag {
  font-weight: 700;
  font-size: 0.68rem;
  letter-spacing: 0.05em;
}

.pos-chip-sep {
  opacity: 0.3;
}

.pos-chip strong {
  font-weight: 600;
  color: #fff;
}

.pos-chip-tp { color: #7fffc4; }
.pos-chip-sl { color: #ffb3b3; }
.pos-chip-pnl { font-weight: 700; }
.pnl-pos { color: #4ade80; }
.pnl-neg { color: #f87171; }
