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

:root {
  --bg:        #060911;
  --surface:   #0c1018;
  --surface2:  #111720;
  --surface3:  #181f2c;
  --border:    #1a2130;
  --border2:   #222d40;
  --text:      #e8edf5;
  --text2:     #7f8ea3;
  --text3:     #3d4f65;
  --green:     #00d395;
  --green-bg:  rgba(0, 211, 149, .1);
  --red:       #f6465d;
  --red-bg:    rgba(246, 70, 93, .1);
  --purple:    #6d28d9;
  --purple2:   #a78bfa;
  --purple-bg: rgba(109, 40, 217, .12);
  --gold:      #f59e0b;
  --gold-bg:   rgba(245, 158, 11, .1);
  --blue:      #3b82f6;
  --blue-bg:   rgba(59, 130, 246, .1);
  --radius:    10px;
  --radius-lg: 14px;
  --shadow:    0 1px 3px rgba(0,0,0,.4), 0 4px 16px rgba(0,0,0,.25);
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

/* ── Scrollbar ────────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text3); }

/* ── Auth Gate ────────────────────────────────────────────────────────────── */
#auth-gate {
  position: fixed; inset: 0;
  background: radial-gradient(ellipse at 50% 40%, #0d1528 0%, var(--bg) 70%);
  display: flex; align-items: center; justify-content: center;
  z-index: 9999;
}
.auth-box {
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: 20px;
  padding: 48px;
  width: 380px;
  text-align: center;
  box-shadow: 0 0 0 1px rgba(109,40,217,.15), 0 32px 64px rgba(0,0,0,.5);
}
.auth-logo {
  width: 56px; height: 56px;
  background: linear-gradient(135deg, var(--purple), #a855f7);
  border-radius: 16px;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; font-weight: 800; color: #fff;
  margin: 0 auto 24px;
  box-shadow: 0 8px 24px rgba(109,40,217,.4);
}
.auth-box h2 { font-size: 22px; font-weight: 700; color: var(--text); margin-bottom: 6px; }
.auth-box p  { font-size: 13px; color: var(--text3); margin-bottom: 32px; }
.auth-box input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border2);
  color: var(--text);
  padding: 13px 16px;
  border-radius: var(--radius);
  font-size: 14px;
  outline: none;
  margin-bottom: 12px;
  transition: border-color .15s, box-shadow .15s;
}
.auth-box input:focus { border-color: var(--purple); box-shadow: 0 0 0 3px rgba(109,40,217,.15); }
.auth-box button {
  width: 100%;
  background: linear-gradient(135deg, var(--purple), #7c3aed);
  color: #fff;
  border: none;
  padding: 13px;
  border-radius: var(--radius);
  font-size: 14px; font-weight: 600;
  cursor: pointer;
  transition: opacity .15s, transform .1s;
  box-shadow: 0 4px 16px rgba(109,40,217,.35);
}
.auth-box button:hover  { opacity: .9; }
.auth-box button:active { transform: scale(.98); }
#pwd-error { color: var(--red); font-size: 12px; margin-top: 10px; min-height: 18px; }

/* ── Header ───────────────────────────────────────────────────────────────── */
header {
  position: sticky; top: 0; z-index: 100;
  background: rgba(12, 16, 24, .85);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
  padding: 0 32px;
  height: 58px;
  display: flex; align-items: center; justify-content: space-between;
}
.header-left  { display: flex; align-items: center; gap: 16px; }
.header-brand { display: flex; align-items: center; gap: 10px; }
.header-icon  {
  width: 30px; height: 30px;
  background: linear-gradient(135deg, var(--purple), #a855f7);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 800; color: #fff;
  flex-shrink: 0;
}
.header-title  { font-size: 15px; font-weight: 700; color: var(--text); }
.header-wallet {
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 11px; color: var(--text3);
  background: var(--surface2); padding: 4px 10px;
  border-radius: 6px; border: 1px solid var(--border);
}
.header-right  { display: flex; align-items: center; gap: 20px; }
.header-pseudo { font-size: 12px; font-weight: 600; color: var(--purple2); }
.live-indicator { display: flex; align-items: center; gap: 7px; font-size: 12px; color: var(--text3); }
.live-dot {
  width: 7px; height: 7px; border-radius: 50%; background: var(--text3);
  transition: background .3s;
}
.live-dot.active {
  background: var(--green);
  box-shadow: 0 0 0 0 rgba(0, 211, 149, .5);
  animation: livepulse 2s infinite;
}
.live-dot.error { background: var(--red); }
@keyframes livepulse {
  0%   { box-shadow: 0 0 0 0   rgba(0, 211, 149, .5); }
  70%  { box-shadow: 0 0 0 8px rgba(0, 211, 149, 0); }
  100% { box-shadow: 0 0 0 0   rgba(0, 211, 149, 0); }
}

/* ── Main Layout ──────────────────────────────────────────────────────────── */
main { max-width: 1440px; margin: 0 auto; padding: 28px 32px 56px; }

/* ── Balance Row ──────────────────────────────────────────────────────────── */
.balance-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 12px;
}
.balance-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px 26px;
  transition: border-color .2s, transform .15s;
  position: relative;
  overflow: hidden;
}
.balance-card::before {
  content: '';
  position: absolute; top: 0; left: 0; right: 0; height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,.06), transparent);
}
.balance-card:hover { border-color: var(--border2); transform: translateY(-1px); }
.balance-card.primary { border-color: var(--border2); }
.balance-card.accent  { border-top: 2px solid var(--gold); }
.bc-label {
  font-size: 10px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .1em; color: var(--text3); margin-bottom: 12px;
}
.bc-value {
  font-size: 30px; font-weight: 800; color: var(--text);
  letter-spacing: -.75px; margin-bottom: 6px;
  font-variant-numeric: tabular-nums;
  transition: color .3s;
}
.bc-sub { font-size: 11px; color: var(--text3); }

/* ── Stats Row ────────────────────────────────────────────────────────────── */
.stats-row {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  transition: border-color .2s;
}
.stat-card:hover { border-color: var(--border2); }
.stat-label { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .1em; color: var(--text3); margin-bottom: 8px; }
.stat-value { font-size: 22px; font-weight: 800; color: var(--text); font-variant-numeric: tabular-nums; }
.stat-sub   { font-size: 10px; color: var(--text3); margin-top: 4px; }

/* ── Panels ───────────────────────────────────────────────────────────────── */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  margin-bottom: 16px;
  overflow: hidden;
  box-shadow: var(--shadow);
}
.panel-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  background: rgba(255,255,255,.01);
}
.panel-title {
  display: flex; align-items: center; gap: 10px;
  font-size: 11px; font-weight: 700; color: var(--text);
  text-transform: uppercase; letter-spacing: .1em;
}
.panel-badge {
  font-size: 11px; font-weight: 600; color: var(--text3);
  background: var(--surface2); padding: 2px 10px; border-radius: 20px;
  text-transform: none; letter-spacing: 0;
  border: 1px solid var(--border);
}
.panel-meta { font-size: 11px; color: var(--text3); }

/* pulse dot in panels */
.pulse-dot {
  width: 7px; height: 7px; border-radius: 50%; background: var(--text3);
  flex-shrink: 0; transition: background .3s;
}
.pulse-dot.active {
  background: var(--green);
  box-shadow: 0 0 0 0 rgba(0, 211, 149, .5);
  animation: livepulse 2s infinite;
}
.pulse-dot.error { background: var(--red); }


/* ── Position Cards ───────────────────────────────────────────────────────── */
.positions-content { padding: 20px 24px; }
.positions-empty {
  text-align: center; padding: 48px;
  color: var(--text3); font-size: 13px;
}
.positions-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px;
}

.pos-card {
  border-radius: var(--radius);
  padding: 18px;
  border: 1px solid;
  position: relative;
  transition: transform .15s, border-color .2s;
}
.pos-card:hover { transform: translateY(-2px); }
.pos-card.live-up   { background: #00130b; border-color: rgba(0,211,149,.25); }
.pos-card.live-down { background: #130008; border-color: rgba(246,70,93,.25); }

.pos-tag {
  position: absolute; top: 14px; right: 14px;
  font-size: 9px; font-weight: 700; letter-spacing: .12em;
  padding: 3px 8px; border-radius: 5px; text-transform: uppercase;
}
.pos-tag.live { background: var(--green-bg); color: var(--green); border: 1px solid rgba(0,211,149,.2); }

.pos-top  { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.pos-icon { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; flex-shrink: 0; }
.pos-icon-fb {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--surface2); border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  font-size: 10px; font-weight: 700; color: var(--text3); flex-shrink: 0;
}
.pos-info { flex: 1; min-width: 0; }
.pos-name { font-size: 13px; font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pos-time { font-size: 10px; color: var(--text3); margin-top: 2px; }
.dir-badge { padding: 5px 12px; border-radius: 6px; font-size: 11px; font-weight: 700; flex-shrink: 0; }
.dir-badge.up   { background: var(--green-bg); color: var(--green); }
.dir-badge.down { background: var(--red-bg);   color: var(--red); }

.pos-stats { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
.ps-item .ps-label { font-size: 9px; color: var(--text3); text-transform: uppercase; letter-spacing: .08em; margin-bottom: 4px; font-weight: 700; }
.ps-item .ps-val   { font-size: 15px; font-weight: 700; color: var(--text); font-variant-numeric: tabular-nums; }
.ps-item .ps-val.green { color: var(--green); }
.ps-item .ps-val.red   { color: var(--red); }

.price-bar { margin-top: 14px; }
.price-bar-labels { display: flex; justify-content: space-between; font-size: 10px; color: var(--text3); margin-bottom: 6px; font-weight: 600; }
.price-bar-track  { height: 3px; background: var(--surface2); border-radius: 2px; overflow: hidden; }
.price-bar-fill   { height: 100%; border-radius: 2px; transition: width .5s ease; }
.price-bar-fill.up   { background: var(--green); box-shadow: 0 0 8px rgba(0,211,149,.4); }
.price-bar-fill.down { background: var(--red);   box-shadow: 0 0 8px rgba(246,70,93,.4); }


/* ── Trades Table ─────────────────────────────────────────────────────────── */
.search-input {
  background: var(--bg);
  border: 1px solid var(--border2);
  color: var(--text);
  padding: 7px 14px;
  border-radius: 8px;
  font-size: 13px;
  width: 220px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.search-input:focus { border-color: var(--purple); box-shadow: 0 0 0 3px rgba(109,40,217,.12); }
.filter-bar {
  display: flex; flex-wrap: wrap; gap: 14px;
  padding: 12px 24px;
  border-bottom: 1px solid var(--border);
  background: rgba(255,255,255,.02);
}
.filter-group { display: flex; align-items: center; gap: 8px; }
.filter-label {
  font-size: 11px; font-weight: 600; color: var(--text2);
  text-transform: uppercase; letter-spacing: .06em; white-space: nowrap;
}
.filter-chips { display: flex; gap: 4px; flex-wrap: wrap; }
.chip {
  padding: 4px 10px; border-radius: 20px; font-size: 11px; font-weight: 600;
  border: 1px solid var(--border2); background: transparent; color: var(--text2);
  cursor: pointer; transition: all .15s; white-space: nowrap;
}
.chip:hover { border-color: var(--purple); color: var(--text); }
.chip.active { background: var(--purple); border-color: var(--purple); color: #fff; }
.chip-won.active { background: var(--green); border-color: var(--green); }
.chip-lost.active { background: var(--red); border-color: var(--red); }
.chip-live.active { background: #2563eb; border-color: #2563eb; }
.date-range-wrap { display: flex; align-items: center; gap: 6px; }
.date-input {
  background: var(--surface2); border: 1px solid var(--border2); color: var(--text);
  border-radius: 8px; padding: 4px 8px; font-size: 12px; outline: none;
  cursor: pointer; transition: border-color .15s; color-scheme: dark;
}
.date-input:focus { border-color: var(--purple); }
.date-sep { color: var(--text2); font-size: 12px; }
.table-wrap { overflow-x: auto; max-height: 520px; overflow-y: auto; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th {
  text-align: left; padding: 11px 16px;
  font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em;
  color: var(--text3); border-bottom: 1px solid var(--border);
  background: var(--surface); position: sticky; top: 0;
  cursor: pointer; user-select: none; white-space: nowrap;
  transition: color .15s;
}
thead th:hover { color: var(--purple2); }
tbody td {
  padding: 12px 16px; border-bottom: 1px solid var(--border);
  white-space: nowrap; color: var(--text2);
  font-variant-numeric: tabular-nums;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--surface2); }
tbody tr.flash-row td { animation: rowflash .6s ease; }
@keyframes rowflash { 0% { background: rgba(109,40,217,.15); } 100% { background: transparent; } }

.badge { display: inline-block; padding: 3px 10px; border-radius: 5px; font-size: 11px; font-weight: 700; }
.badge.up   { background: var(--green-bg); color: var(--green); }
.badge.down { background: var(--red-bg);   color: var(--red); }
.badge.live { background: var(--blue-bg);  color: var(--blue); }

.pnl-positive { color: var(--green); font-weight: 700; }
.pnl-negative { color: var(--red);   font-weight: 700; }
.pnl-pending  { color: var(--blue);  font-size: 12px; font-weight: 600; }
tbody tr.pending-row td { background: rgba(59,130,246,.04); color: var(--blue); }
tbody tr.pending-row td:first-child { border-left: 2px solid rgba(59,130,246,.4); }
.pnl-unknown  { color: var(--text3); }

.tx-link { color: var(--text3); font-family: 'SF Mono', 'Fira Code', monospace; font-size: 11px; text-decoration: none; transition: color .15s; }
.tx-link:hover { color: var(--purple2); }

.market-cell { display: flex; align-items: center; gap: 10px; }
.trade-coin-icon { width: 22px; height: 22px; border-radius: 50%; flex-shrink: 0; }
.market-meta { display: flex; flex-direction: column; gap: 1px; }
.market-date { font-size: 12px; font-weight: 600; color: var(--text); }
.market-time-win { font-size: 10px; color: var(--text3); }

/* ── Flash animation for value changes ────────────────────────────────────── */
@keyframes flashGreen { 0%,100% { color: inherit; } 30% { color: var(--green); } }
@keyframes flashRed   { 0%,100% { color: inherit; } 30% { color: var(--red); } }
.value-up   { animation: flashGreen .8s ease; }
.value-down { animation: flashRed   .8s ease; }

/* ── Responsive ───────────────────────────────────────────────────────────── */
@media (max-width: 1100px) {
  .balance-row { grid-template-columns: repeat(2, 1fr); }
  .stats-row   { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 700px) {
  header { padding: 0 16px; }
  main   { padding: 16px 12px; }
  .balance-row { grid-template-columns: 1fr 1fr; }
  .stats-row   { grid-template-columns: 1fr 1fr; }
  .bc-value    { font-size: 22px; }
  .positions-grid { grid-template-columns: 1fr; }
  .table-wrap { max-height: 400px; }
}

/* ── Bot Control Bar ──────────────────────────────────────────────────────── */
.bot-bar {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 14px 24px;
  margin-bottom: 12px; gap: 16px; flex-wrap: wrap;
}
.bot-bar-left  { display: flex; align-items: center; gap: 16px; flex: 1; min-width: 0; }
.bot-bar-right { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.bot-bar-sep   { width: 1px; height: 24px; background: var(--border2); flex-shrink: 0; }

.bot-status-wrap { display: flex; align-items: center; gap: 8px; white-space: nowrap; font-size: 12px; font-weight: 600; color: var(--text2); }
.bot-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--text3); flex-shrink: 0; transition: background .3s; }
.bot-dot.running { background: var(--green); box-shadow: 0 0 0 0 rgba(0,211,149,.5); animation: livepulse 2s infinite; }
.bot-dot.stopped { background: var(--red); }
.bot-dot.pending { background: var(--gold); box-shadow: 0 0 0 0 rgba(245,158,11,.5); animation: livepulse 0.7s infinite; }

.window-mini   { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 120px; }
.window-label  { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--text3); white-space: nowrap; }
.window-track  { flex: 1; height: 4px; background: var(--surface2); border-radius: 2px; overflow: hidden; min-width: 60px; }
.window-fill   { height: 100%; background: linear-gradient(90deg, var(--purple), var(--blue)); border-radius: 2px; transition: width .5s linear; }
.window-rem    { font-size: 11px; font-weight: 700; color: var(--text2); white-space: nowrap; font-variant-numeric: tabular-nums; min-width: 36px; text-align: right; }

.ctrl-btn {
  padding: 7px 14px; border-radius: 7px; border: none;
  font-size: 12px; font-weight: 600; cursor: pointer;
  transition: opacity .15s, transform .1s; white-space: nowrap;
  background: var(--purple); color: #fff;
}
.ctrl-btn:hover  { opacity: .85; }
.ctrl-btn:active { transform: scale(.97); }
.ctrl-btn.start  { background: var(--green); color: #111; font-weight: 700; }
.ctrl-btn.stop   { background: var(--red); color: #fff; font-weight: 700; }
.ctrl-btn.secondary { background: var(--surface2); color: var(--text2); border: 1px solid var(--border2); }
.ctrl-btn.danger    { background: rgba(246,70,93,.15); color: var(--red); border: 1px solid rgba(246,70,93,.25); }
.ctrl-btn.ghost     { background: transparent; color: var(--text3); border: 1px solid var(--border2); }
.ctrl-btn.ghost:hover { color: var(--purple2); border-color: var(--purple); }

/* ── Settings Panel ───────────────────────────────────────────────────────── */
.settings-panel {
  background: var(--surface); border: 1px solid var(--border2);
  border-radius: var(--radius-lg); padding: 20px 24px;
  margin-bottom: 12px;
}
.settings-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 16px; }
@media (max-width: 900px) { .settings-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 500px) { .settings-grid { grid-template-columns: 1fr; } }
.setting-item.full { grid-column: 1 / -1; }
.setting-item label { display: block; font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--text3); margin-bottom: 6px; }
.setting-item input,
.setting-item select {
  width: 100%; background: var(--bg); border: 1px solid var(--border2);
  color: var(--text); padding: 8px 10px; border-radius: 7px;
  font-size: 13px; outline: none; transition: border-color .15s;
}
.setting-item input:focus,
.setting-item select:focus { border-color: var(--purple); box-shadow: 0 0 0 2px rgba(109,40,217,.12); }

.pairs-grid { display: flex; gap: 8px; flex-wrap: wrap; }
.pair-toggle {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 12px; border-radius: 7px;
  border: 1px solid var(--border2); cursor: pointer;
  font-size: 12px; font-weight: 600; color: var(--text2);
  background: var(--bg); transition: all .15s; user-select: none;
}
.pair-toggle:has(input:checked) { background: var(--purple-bg); border-color: var(--purple); color: var(--purple2); }
.pair-toggle input { width: 14px; height: 14px; accent-color: var(--purple); cursor: pointer; }

.settings-footer { display: flex; align-items: center; gap: 16px; }
.settings-saved  { font-size: 12px; color: var(--green); font-weight: 600; opacity: 0; transition: opacity .3s; }
.settings-saved.show { opacity: 1; }

/* ── Live Log ─────────────────────────────────────────────────────────────── */
.logbox {
  padding: 12px 20px; max-height: 220px; overflow-y: auto;
  font-family: 'SF Mono','Fira Code',monospace; font-size: 11px;
  line-height: 1.9; color: var(--text3);
}
.logbox::-webkit-scrollbar { width: 4px; }
.logbox::-webkit-scrollbar-track { background: transparent; }
.logbox::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 2px; }
.log-line { white-space: pre-wrap; word-break: break-all; }
.log-win  { color: var(--green); }
.log-loss { color: var(--red); }
.log-trade { color: var(--purple2); }
.log-skip { color: var(--text3); opacity: .6; }
.log-err  { color: var(--red); font-weight: 700; }
