/* ==========================================
   📈 MARKET LIVE PAGE STYLES
   Trading Platform Pro - Market Live v4.0
   Full live-trading terminal with animations
   ========================================== */

/* ==========================================
   Layout
   ========================================== */
.market-live-page {
  padding: 0 !important;
  padding-bottom: 170px !important;
  overflow-y: auto;
}

@media (min-width: 768px) {
  .market-live-page {
    padding-left: 260px !important;
  }
}

/* ==========================================
   Generic section header
   ========================================== */
.ml-section-hdr {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 14px;
  background: var(--bg-card, #1e1e22);
  border-bottom: 1px solid var(--border-color, #2a2a2e);
}
.ml-section-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--primary-orange, #f97316);
  text-transform: uppercase;
  letter-spacing: .5px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.ml-section-title .live-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: #ef4444;
  animation: livePulse 1.4s ease-in-out infinite;
}
@keyframes livePulse {
  0%,100% { opacity: 1; box-shadow: 0 0 0 0 rgba(239,68,68,.6); }
  50% { opacity: .6; box-shadow: 0 0 0 4px rgba(239,68,68,0); }
}
.ml-expand-btn {
  width: 28px; height: 28px; display: flex; align-items: center; justify-content: center;
  background: transparent; border: 1px solid var(--border-color, #2a2a2e);
  border-radius: 6px; color: var(--text-muted, #71717a); cursor: pointer;
  transition: all .2s;
}
.ml-expand-btn:hover { color: var(--text-primary, #fff); border-color: var(--text-secondary); }

/* ==========================================
   1. LIVE TRADE SECTION
   ========================================== */
.ml-livetrade-wrap {
  border-bottom: 1px solid var(--border-color, #2a2a2e);
  max-height: 220px;
  overflow: hidden;
  transition: max-height .3s ease;
  overflow-anchor: none; /* prevent scroll jump when live trades update */
  contain: layout;
}
.ml-livetrade-wrap.expanded { max-height: 500px; }

.ml-livetrade-scroll {
  height: 180px;
  overflow: hidden;
  position: relative;
}
.ml-livetrade-wrap.expanded .ml-livetrade-scroll { height: 460px; overflow-y: auto; }

.ml-lt-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}
.ml-lt-table thead {
  position: sticky; top: 0; z-index: 5;
}
.ml-lt-table th {
  padding: 4px 6px;
  background: var(--bg-elevated, #27272a);
  color: var(--text-muted, #71717a);
  font-weight: 600; font-size: 9px; text-transform: uppercase;
  letter-spacing: .5px; text-align: right; white-space: nowrap;
  border-bottom: 1px solid var(--border-color, #2a2a2e);
}
.ml-lt-table th:first-child,
.ml-lt-table td:first-child { text-align: left; }
.ml-lt-table th:nth-child(2),
.ml-lt-table td:nth-child(2) { text-align: left; }

.ml-lt-table td {
  padding: 3px 6px;
  text-align: right;
  white-space: nowrap;
  color: var(--text-secondary, #a1a1aa);
  border-bottom: 1px solid rgba(255,255,255,.03);
}
.ml-lt-table tbody tr {
  transition: background .15s;
}

/* Blink flash for new rows */
@keyframes ltFlashIn {
  0% { background: rgba(249,115,22,.25); }
  100% { background: transparent; }
}
.ml-lt-table tbody tr.lt-flash {
  animation: ltFlashIn .35s ease-out;
}
.ml-lt-code { font-weight: 700; color: var(--text-primary, #fff); }

/* Live Trade — entire row red/green coloring */
.ml-lt-table tr.lt-row-positive td { color: #22c55e; }
.ml-lt-table tr.lt-row-positive .ml-lt-code { color: #22c55e; }
.ml-lt-table tr.lt-row-negative td { color: #ef4444; }
.ml-lt-table tr.lt-row-negative .ml-lt-code { color: #ef4444; }
.ml-lt-table tr.lt-row-neutral td  { color: var(--text-muted, #71717a); }

/* ==========================================
   2. IHSG BAR + WORLD INDICES
   ========================================== */
.ml-ihsg-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: var(--bg-card, #1e1e22);
  border-bottom: 1px solid var(--border-color, #2a2a2e);
}
.ml-ihsg-left {
  display: flex; align-items: center; gap: 8px; flex-shrink: 0;
}
.ml-ihsg-label {
  font-size: 13px; font-weight: 800;
  color: var(--primary-orange, #f97316);
  letter-spacing: .5px;
}
.ml-ihsg-value {
  font-size: 15px; font-weight: 700;
  color: var(--text-primary, #fff);
  font-variant-numeric: tabular-nums;
  transition: color .3s, text-shadow .3s;
}
.ml-ihsg-change {
  display: inline-flex; align-items: center; gap: 3px;
  font-size: 12px; font-weight: 600;
  padding: 2px 6px; border-radius: 4px;
  transition: color .3s;
}
.ml-ihsg-change.positive { color: #22c55e; background: rgba(34,197,94,.12); }
.ml-ihsg-change.negative { color: #ef4444; background: rgba(239,68,68,.12); }

.ml-ihsg-sub {
  display: flex; align-items: center; gap: 10px;
  font-size: 10px; color: var(--text-muted, #71717a);
  padding: 2px 14px 6px;
  background: var(--bg-card, #1e1e22);
  border-bottom: 1px solid var(--border-color, #2a2a2e);
}
.ml-ihsg-sub-item { display: flex; align-items: center; gap: 3px; }
.ml-sub-label { font-weight: 600; color: var(--text-muted, #71717a); }
.ml-sub-value { font-variant-numeric: tabular-nums; font-weight: 600; }
.ml-sub-value.positive { color: #22c55e; }
.ml-sub-value.negative { color: #ef4444; }

.ml-ihsg-stats {
  display: flex; align-items: center; gap: 12px;
  margin-left: auto; flex-shrink: 0;
}
.ml-ihsg-stat {
  display: flex; flex-direction: column; align-items: center; gap: 1px;
}
.ml-stat-label {
  font-size: 9px; font-weight: 600;
  color: var(--text-muted, #71717a);
  text-transform: uppercase; letter-spacing: .5px;
}
.ml-stat-value {
  font-size: 11px; font-weight: 600;
  color: var(--text-secondary, #a1a1aa);
}
.ml-stat-value.positive { color: #22c55e; }
.ml-stat-value.negative { color: #ef4444; }

.ml-ihsg-kurs {
  flex-shrink: 0; font-size: 11px; font-weight: 700;
  color: var(--primary-orange, #f97316);
  background: rgba(249,115,22,.12);
  padding: 4px 10px; border-radius: 6px;
  text-decoration: none; transition: background .2s;
}
.ml-ihsg-kurs:hover { background: rgba(249,115,22,.25); }

/* IHSG tick animation */
.ml-ihsg-value.tick-up { color: #22c55e !important; text-shadow: 0 0 8px rgba(34,197,94,.5); }
.ml-ihsg-value.tick-down { color: #ef4444 !important; text-shadow: 0 0 8px rgba(239,68,68,.5); }

/* ==========================================
   World Indices Section
   ========================================== */
.ml-world-section {
  border-bottom: 1px solid var(--border-color, #2a2a2e);
  max-height: 280px;
  overflow: hidden;
  transition: max-height .3s ease;
}
.ml-world-section.expanded { max-height: 600px; }

.ml-indices-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 8px;
  padding: 4px 12px 8px;
}
.ml-indices-col {
  display: flex; flex-direction: column;
}
.ml-idx-row {
  display: grid;
  grid-template-columns: 58px 1fr 52px 48px;
  align-items: center;
  padding: 5px 4px;
  font-size: 11px;
  border-bottom: 1px solid rgba(255,255,255,.04);
  transition: background .15s;
}
.ml-idx-row:hover { background: rgba(255,255,255,.04); }
.ml-idx-row:last-child { border-bottom: none; }
.ml-idx-name {
  font-weight: 600; color: var(--text-primary, #fff);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.ml-idx-last {
  text-align: right; font-weight: 600;
  color: var(--text-primary, #fff); font-variant-numeric: tabular-nums;
  transition: color .2s, text-shadow .2s;
}
.ml-idx-chg, .ml-idx-pct {
  text-align: right; font-weight: 500; font-variant-numeric: tabular-nums;
}
.ml-idx-chg.positive, .ml-idx-pct.positive { color: #22c55e; }
.ml-idx-chg.negative, .ml-idx-pct.negative { color: #ef4444; }
.ml-idx-chg.neutral, .ml-idx-pct.neutral { color: var(--text-muted, #71717a); }

/* Blink for index updates */
@keyframes idxFlash {
  0% { background: rgba(249,115,22,.15); }
  100% { background: transparent; }
}
.ml-idx-row.idx-flash { animation: idxFlash .3s ease-out; }

/* Index skeleton */
.ml-idx-skeleton {
  height: 24px;
  background: linear-gradient(90deg, var(--bg-elevated, #27272a) 25%, rgba(255,255,255,.06) 50%, var(--bg-elevated, #27272a) 75%);
  background-size: 200% 100%;
  animation: mlShimmer 1.5s infinite;
  border-radius: 4px; margin-bottom: 4px;
}
@keyframes mlShimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ==========================================
   3. STOCK LIST SECTION
   ========================================== */
.ml-stock-section {
  flex: 1; display: flex; flex-direction: column; min-height: 0;
}
.ml-stock-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 14px;
  background: var(--bg-card, #1e1e22);
  border-bottom: 1px solid var(--border-color, #2a2a2e);
}
.ml-stock-title {
  font-size: 13px; font-weight: 700; color: var(--text-primary, #fff);
}
.ml-stock-actions {
  display: flex; align-items: center; gap: 4px;
}
.ml-action-btn {
  width: 30px; height: 30px;
  display: flex; align-items: center; justify-content: center;
  background: transparent;
  border: 1px solid var(--border-color, #2a2a2e);
  border-radius: 6px; color: var(--text-muted, #71717a);
  cursor: pointer; transition: all .2s;
}
.ml-action-btn:hover {
  color: var(--text-primary, #fff);
  border-color: var(--text-secondary, #a1a1aa);
}
.ml-action-btn.active {
  background: var(--primary-orange, #f97316);
  border-color: var(--primary-orange, #f97316);
  color: white;
}

/* Stock Table (sticky CODE + LAST) */
.ml-table-container {
  flex: 1; overflow: auto; position: relative;
  -webkit-overflow-scrolling: touch;
}
.ml-stock-table {
  width: max-content; min-width: 100%;
  border-collapse: collapse;
  font-size: 11px; font-variant-numeric: tabular-nums;
}
.ml-stock-table thead {
  position: sticky; top: 0; z-index: 20;
}
.ml-stock-table th {
  padding: 6px 8px;
  background: var(--bg-elevated, #27272a);
  color: var(--text-muted, #71717a);
  font-weight: 600; font-size: 10px;
  text-transform: uppercase; letter-spacing: .5px;
  text-align: right; white-space: nowrap;
  border-bottom: 1px solid var(--border-color, #2a2a2e);
  user-select: none;
}
.ml-stock-table th.col-code { text-align: left; min-width: 65px; }
.ml-stock-table th.col-last { min-width: 60px; }

.ml-stock-table td {
  padding: 5px 8px; text-align: right;
  white-space: nowrap;
  color: var(--text-secondary, #a1a1aa);
  border-bottom: 1px solid rgba(255,255,255,.04);
}
.ml-stock-table tbody tr {
  cursor: pointer; transition: background .12s;
}
.ml-stock-table tbody tr:hover { background: rgba(255,255,255,.04); }
.ml-stock-table tbody tr:active { background: rgba(249,115,22,.1); }

/* Sticky columns */
.sticky-col {
  position: sticky; z-index: 10;
  background: var(--bg-dark, #18181b);
}
.ml-stock-table thead .sticky-col {
  background: var(--bg-elevated, #27272a); z-index: 25;
}
.sticky-col.col-code { left: 0; }
.sticky-col.col-last { left: 65px; box-shadow: 2px 0 8px rgba(0,0,0,.3); }

/* Code cell */
.ml-code-cell {
  display: flex; align-items: center; gap: 5px; text-align: left;
}
.ml-code-dot {
  width: 5px; height: 5px; border-radius: 50%; flex-shrink: 0;
}
.ml-code-dot.up { background: #22c55e; }
.ml-code-dot.down { background: #ef4444; }
.ml-code-dot.flat { background: var(--text-muted, #71717a); }
.ml-code-text {
  font-weight: 700; color: var(--text-primary, #fff); font-size: 11px;
}

/* Value colors */
.ml-val-pos { color: #22c55e !important; }
.ml-val-neg { color: #ef4444 !important; }
.ml-val-zero { color: var(--text-muted, #71717a) !important; }
.ml-val-last {
  font-weight: 700; color: var(--text-primary, #fff);
  font-variant-numeric: tabular-nums;
  transition: color .3s, text-shadow .3s;
}

/* Cell blink for stock price updates */
@keyframes cellFlashUp {
  0% { color: #22c55e; text-shadow: 0 0 6px rgba(34,197,94,.5); }
  100% { text-shadow: none; }
}
@keyframes cellFlashDown {
  0% { color: #ef4444; text-shadow: 0 0 6px rgba(239,68,68,.5); }
  100% { text-shadow: none; }
}
.price-flash-up {
  animation: cellFlashUp .25s ease-out;
  color: #22c55e !important;
}
.price-flash-down {
  animation: cellFlashDown .25s ease-out;
  color: #ef4444 !important;
}

/* ==========================================
   Loading / Error states
   ========================================== */
.ml-loading {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 12px; padding: 40px 20px;
  color: var(--text-muted, #71717a); font-size: 13px;
}
.ml-spinner {
  width: 28px; height: 28px;
  border: 3px solid var(--border-color, #2a2a2e);
  border-top-color: var(--primary-orange, #f97316);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.ml-error {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 10px; padding: 40px 20px;
  color: var(--text-muted, #71717a); font-size: 13px;
}
.ml-retry-btn {
  padding: 8px 20px;
  background: var(--primary-orange, #f97316); color: white;
  border: none; border-radius: 8px;
  font-size: 12px; font-weight: 600;
  cursor: pointer; transition: opacity .2s;
}
.ml-retry-btn:hover { opacity: .85; }

/* ==========================================
   4. WATCHLIST BAR (sticky bottom)
   ========================================== */
.ml-watchlist-bar {
  position: fixed;
  bottom: 104px;
  left: 0; right: 0;
  z-index: 92;
  background: var(--bg-elevated, #27272a);
  border-top: 1px solid var(--border-color, #2a2a2e);
  border-bottom: 1px solid var(--border-color, #2a2a2e);
  padding: 0;
  overflow: hidden;
}
@media (min-width: 768px) {
  .ml-watchlist-bar { left: 260px; }
}
.ml-wl-scroll {
  display: flex; gap: 0;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.ml-wl-scroll::-webkit-scrollbar { display: none; }

.ml-wl-chip {
  flex-shrink: 0;
  display: flex; align-items: center; gap: 6px;
  padding: 6px 12px;
  border-right: 1px solid rgba(255,255,255,.06);
  cursor: pointer;
  transition: background .15s;
}
.ml-wl-chip:hover { background: rgba(255,255,255,.04); }
.ml-wl-chip-icon {
  width: 18px; height: 18px;
  border-radius: 4px;
  background: var(--primary-orange, #f97316);
  display: flex; align-items: center; justify-content: center;
  font-size: 8px; font-weight: 800; color: #fff;
}
.ml-wl-info {
  display: flex; flex-direction: column; gap: 0;
}
.ml-wl-top {
  display: flex; align-items: center; gap: 4px;
  font-size: 11px; font-weight: 700; color: var(--text-primary, #fff);
}
.ml-wl-price { font-variant-numeric: tabular-nums; }
.ml-wl-arrow { font-size: 10px; }
.ml-wl-bottom {
  display: flex; align-items: center; gap: 6px;
  font-size: 9px; font-weight: 600;
}
.ml-wl-bottom .wl-pct {
  font-variant-numeric: tabular-nums;
}
.ml-wl-bottom.positive { color: #22c55e; }
.ml-wl-bottom.negative { color: #ef4444; }
.ml-wl-bottom.neutral { color: var(--text-muted, #71717a); }

/* ==========================================
   5. BOTTOM STOCK TABS
   ========================================== */
.ml-stock-tabs {
  position: fixed;
  bottom: 66px;
  left: 0; right: 0;
  z-index: 90;
  background: var(--bg-card, #1e1e22);
  border-top: 1px solid var(--border-color, #2a2a2e);
  padding: 0;
}
@media (min-width: 768px) {
  .ml-stock-tabs { left: 260px; }
}
.ml-tabs-scroll {
  display: flex; gap: 0;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.ml-tabs-scroll::-webkit-scrollbar { display: none; }

.ml-tab-btn {
  flex-shrink: 0;
  padding: 8px 14px;
  background: transparent; border: none;
  border-right: 1px solid rgba(255,255,255,.06);
  color: var(--text-secondary, #a1a1aa);
  font-size: 11px; font-weight: 600; font-family: inherit;
  cursor: pointer; transition: all .2s; white-space: nowrap;
}
.ml-tab-btn:hover {
  background: rgba(255,255,255,.04);
  color: var(--text-primary, #fff);
}
.ml-tab-btn.active {
  background: var(--primary-orange, #f97316); color: white;
}
.ml-tab-fav {
  display: flex; align-items: center; gap: 4px;
  color: var(--primary-orange, #f97316);
}
.ml-tab-fav.active { background: var(--primary-orange, #f97316); color: white; }
.ml-tab-all {
  display: flex; align-items: center; gap: 4px;
  color: var(--primary-orange, #f97316); font-weight: 700;
}
.ml-tab-all.active { background: var(--primary-orange, #f97316); color: white; }

/* ==========================================
   Responsive
   ========================================== */
@media (max-width: 380px) {
  .ml-ihsg-stats { display: none; }
  .ml-ihsg-sub { font-size: 9px; gap: 6px; }
  .ml-idx-row { grid-template-columns: 50px 1fr 50px 45px; font-size: 10px; }
  .ml-lt-table { font-size: 10px; }
}
@media (min-width: 768px) {
  .ml-idx-row { grid-template-columns: 80px 1fr 70px 60px; font-size: 12px; padding: 5px 8px; }
  .ml-stock-table { font-size: 12px; }
  .ml-stock-table th { font-size: 11px; padding: 8px 10px; }
  .ml-stock-table td { padding: 6px 10px; }
  .ml-lt-table { font-size: 12px; }
  .ml-lt-table th { font-size: 10px; }
}
