:root {
  --bg: #0b0e11;
  --bg-elevated: #12161c;
  --bg-card: #161b22;
  --border: #21262d;
  --border-light: #30363d;
  --text: #e6edf3;
  --text-muted: #8b949e;
  --text-dim: #6e7681;
  --green: #3fb950;
  --green-bg: rgba(63, 185, 80, 0.12);
  --red: #f85149;
  --red-bg: rgba(248, 81, 73, 0.12);
  --blue: #58a6ff;
  --blue-bg: rgba(88, 166, 255, 0.12);
  --accent: #f0b429;
  --radius: 10px;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, monospace;
}

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

html { font-size: 14px; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
  overflow-x: hidden;
}

/* ========== TICKER ========== */
.ticker-wrap {
  background: #0d1117;
  border-bottom: 1px solid var(--border);
  height: 36px;
  overflow: hidden;
  position: relative;
}

.ticker-track {
  display: flex;
  gap: 40px;
  white-space: nowrap;
  animation: ticker 45s linear infinite;
  padding: 8px 0;
  width: max-content;
}

.ticker-item {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-family: var(--mono);
}

.ticker-item .sym { font-weight: 600; color: var(--text); }
.ticker-item .px { color: var(--text-muted); }
.ticker-item .chg.up { color: var(--green); }
.ticker-item .chg.down { color: var(--red); }

@keyframes ticker {
  0% { transform: translateX(0); }
  100% { transform: translateX(-50%); }
}

/* ========== HEADER ========== */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  height: 56px;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-left, .header-right {
  display: flex;
  align-items: center;
  gap: 24px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 800;
  font-size: 18px;
  letter-spacing: -0.5px;
}

.logo-icon {
  color: var(--accent);
  font-size: 22px;
}

.logo-text span { color: var(--accent); }

.nav {
  display: flex;
  gap: 4px;
}

.nav-link {
  color: var(--text-muted);
  text-decoration: none;
  padding: 6px 12px;
  border-radius: 6px;
  font-weight: 500;
  font-size: 13px;
  transition: all 0.15s;
}

.nav-link:hover { color: var(--text); background: rgba(255,255,255,0.04); }
.nav-link.active { color: var(--text); background: rgba(255,255,255,0.06); }

.search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 12px;
  width: 260px;
  color: var(--text-dim);
}

.search-box input {
  background: transparent;
  border: none;
  outline: none;
  color: var(--text);
  font-size: 13px;
  width: 100%;
  font-family: var(--font);
}

.search-box input::placeholder { color: var(--text-dim); }

.balance-pill {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  line-height: 1.2;
}

.balance-label { font-size: 10px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.5px; }
.balance-value { font-family: var(--mono); font-weight: 600; font-size: 13px; color: var(--text); }

.btn-primary {
  background: var(--accent);
  color: #0b0e11;
  border: none;
  padding: 8px 16px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  transition: opacity 0.15s;
}

.btn-primary:hover { opacity: 0.9; }

.user-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: linear-gradient(135deg, #f0b429, #e85d04);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 12px;
  color: #0b0e11;
  cursor: pointer;
}

/* ========== MAIN LAYOUT ========== */
.main {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 16px;
  padding: 16px;
  max-width: 1600px;
  margin: 0 auto;
}

.left-col { display: flex; flex-direction: column; gap: 16px; }
.right-col { display: flex; flex-direction: column; gap: 16px; }

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}

.card-header h2, .card-header h3 {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.2px;
}

.live-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 600;
  color: var(--green);
  letter-spacing: 0.5px;
}

.pulse {
  width: 7px;
  height: 7px;
  background: var(--green);
  border-radius: 50%;
  animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(0.85); }
}

/* ========== MARKET OVERVIEW ========== */
.indices {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1px;
  background: var(--border);
}

.index-item {
  background: var(--bg-card);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.index-item .name { font-size: 12px; color: var(--text-muted); font-weight: 500; }
.index-item .value { font-family: var(--mono); font-size: 16px; font-weight: 600; }
.index-item .chg { font-size: 12px; font-family: var(--mono); }
.up { color: var(--green); }
.down { color: var(--red); }

/* ========== CHART ========== */
.chart-header { flex-wrap: wrap; gap: 12px; }

.symbol-info { display: flex; flex-direction: column; gap: 2px; }

.symbol-info h2 { font-size: 20px; font-weight: 700; letter-spacing: -0.5px; }
.symbol-name { font-size: 12px; color: var(--text-muted); }
.price-row { display: flex; align-items: baseline; gap: 10px; margin-top: 4px; }
.price { font-family: var(--mono); font-size: 22px; font-weight: 600; }
.change { font-family: var(--mono); font-size: 13px; font-weight: 500; }

.timeframes { display: flex; gap: 4px; }

.tf {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-muted);
  padding: 5px 10px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}

.tf:hover { color: var(--text); background: rgba(255,255,255,0.04); }
.tf.active { color: var(--text); background: rgba(255,255,255,0.08); border-color: var(--border-light); }

.chart-container {
  height: 280px;
  padding: 8px 12px 4px;
  position: relative;
}

#priceChart { width: 100%; height: 100%; display: block; }

.chart-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  border-top: 1px solid var(--border);
}

.stat {
  padding: 10px 16px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  border-right: 1px solid var(--border);
}

.stat:last-child { border-right: none; }
.stat span { font-size: 11px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.3px; }
.stat strong { font-family: var(--mono); font-size: 13px; font-weight: 500; }

/* ========== ORDER BOOK + TRADES ========== */
.bottom-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.orderbook { padding: 8px 12px 12px; font-family: var(--mono); font-size: 12px; }

.ob-header {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  color: var(--text-dim);
  padding: 4px 0 8px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.ob-asks, .ob-bids { display: flex; flex-direction: column; gap: 1px; }

.ob-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  padding: 3px 0;
  position: relative;
}

.ob-row .bar {
  position: absolute;
  top: 0; bottom: 0; right: 0;
  opacity: 0.15;
  pointer-events: none;
}

.ob-row.ask .bar { background: var(--red); }
.ob-row.bid .bar { background: var(--green); }

.ob-row.ask .price { color: var(--red); }
.ob-row.bid .price { color: var(--green); }

.ob-spread {
  text-align: center;
  padding: 8px 0;
  color: var(--text-muted);
  font-size: 11px;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  margin: 4px 0;
}

.trades-list {
  max-height: 260px;
  overflow-y: auto;
  padding: 8px 12px 12px;
  font-family: var(--mono);
  font-size: 12px;
}

.trade-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  padding: 4px 0;
  border-bottom: 1px solid rgba(255,255,255,0.03);
}

.trade-row .price.up { color: var(--green); }
.trade-row .price.down { color: var(--red); }
.trade-row .time { color: var(--text-dim); text-align: right; }

/* ========== TRADE PANEL ========== */
.trade-tabs {
  display: flex;
  background: var(--bg);
  border-radius: 6px;
  padding: 2px;
}

.tab {
  background: transparent;
  border: none;
  color: var(--text-muted);
  padding: 5px 14px;
  border-radius: 5px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}

.tab.active[data-side="buy"] { background: var(--green); color: #0b0e11; }
.tab.active[data-side="sell"] { background: var(--red); color: #fff; }

.trade-form { padding: 16px; display: flex; flex-direction: column; gap: 14px; }

.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group label { font-size: 11px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.4px; font-weight: 500; }

.form-group input,
.form-group select {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--text);
  font-family: var(--mono);
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s;
}

.form-group input:focus,
.form-group select:focus { border-color: var(--blue); }

.est-cost {
  font-family: var(--mono);
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
}

.btn-trade {
  border: none;
  padding: 12px;
  border-radius: 8px;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
  margin-top: 4px;
}

.btn-trade:active { transform: scale(0.98); }
.btn-trade.buy { background: var(--green); color: #0b0e11; }
.btn-trade.sell { background: var(--red); color: #fff; }
.btn-trade:hover { opacity: 0.9; }

/* ========== PORTFOLIO ========== */
.portfolio-value {
  font-family: var(--mono);
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

.portfolio-summary {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1px;
  background: var(--border);
}

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

.ps-item span { font-size: 11px; color: var(--text-dim); }
.ps-item strong { font-family: var(--mono); font-size: 14px; }

.holdings {
  max-height: 220px;
  overflow-y: auto;
}

.holding {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  border-top: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.12s;
}

.holding:hover { background: rgba(255,255,255,0.03); }

.holding-left { display: flex; flex-direction: column; gap: 2px; }
.holding-sym { font-weight: 600; font-size: 13px; }
.holding-shares { font-size: 11px; color: var(--text-dim); font-family: var(--mono); }

.holding-right { text-align: right; }
.holding-value { font-family: var(--mono); font-size: 13px; font-weight: 500; }
.holding-pnl { font-family: var(--mono); font-size: 11px; }

/* ========== WATCHLIST ========== */
.icon-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  width: 28px;
  height: 28px;
  border-radius: 6px;
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}

.icon-btn:hover { color: var(--text); border-color: var(--border-light); background: rgba(255,255,255,0.04); }

.watchlist { max-height: 280px; overflow-y: auto; }

.watch-item {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 12px;
  align-items: center;
  padding: 10px 16px;
  border-top: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.12s;
}

.watch-item:hover { background: rgba(255,255,255,0.03); }
.watch-item.active { background: rgba(88, 166, 255, 0.08); }

.watch-sym { font-weight: 600; font-size: 13px; }
.watch-name { font-size: 11px; color: var(--text-dim); display: block; }
.watch-price { font-family: var(--mono); font-size: 13px; text-align: right; }
.watch-chg { font-family: var(--mono); font-size: 12px; text-align: right; min-width: 70px; }

/* ========== TOAST ========== */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-light);
  padding: 14px 20px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 500;
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
  transform: translateY(80px);
  opacity: 0;
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  z-index: 1000;
  max-width: 320px;
}

.toast.show { transform: translateY(0); opacity: 1; }
.toast.success { border-left: 3px solid var(--green); }
.toast.error { border-left: 3px solid var(--red); }

/* ========== SCROLLBAR ========== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #484f58; }

/* ========== RESPONSIVE ========== */
@media (max-width: 1100px) {
  .main { grid-template-columns: 1fr; }
  .right-col { display: grid; grid-template-columns: 1fr 1fr; }
  .indices { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 700px) {
  .header { flex-wrap: wrap; height: auto; padding: 10px 12px; gap: 10px; }
  .header-left, .header-right { width: 100%; justify-content: space-between; }
  .nav { display: none; }
  .search-box { width: 100%; max-width: 200px; }
  .bottom-row { grid-template-columns: 1fr; }
  .right-col { grid-template-columns: 1fr; }
  .indices { grid-template-columns: 1fr 1fr; }
  .chart-container { height: 220px; }
}
