/* ==========================================================================
   SONAR — AI Auto-Trading Terminal (v2)
   Tema instrumen kokpit trading: ink-navy + aksen amber, sinyal long/whale
   cyan, bahaya/short merah. Motif sonar-ping dipertahankan sebagai animasi
   utama "AI berpikir", diperluas dengan: PnL live animasi count-up + spark,
   leaderboard watchlist dengan FLIP reorder, score ring SVG, regime badge
   cross-fade, trade-plan reveal staggered, execution stepper hidup.
   ========================================================================== */

:root {
  --bg: #0A0E14;
  --panel: #10151C;
  --panel-alt: #141B24;
  --line: #1E2731;
  --text: #E7ECF2;
  --text-dim: #8891A0;
  --text-faint: #4E5867;

  --amber: #FFB020;
  --amber-dim: rgba(255, 176, 32, 0.14);
  --cyan: #3FDDD0;
  --cyan-dim: rgba(63, 221, 208, 0.14);
  --red: #FF5468;
  --red-dim: rgba(255, 84, 104, 0.14);
  --violet: #B18CFF;

  --font-display: 'Space Grotesk', 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', 'Consolas', monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--font-mono); font-size: 13.5px; -webkit-font-smoothing: antialiased; }
h1, h2, h3 { font-family: var(--font-display); margin: 0; font-weight: 600; }
ul { margin: 0; padding: 0; list-style: none; }
button:focus-visible, .btn:focus-visible { outline: 2px solid var(--amber); outline-offset: 2px; }
.app { display: flex; flex-direction: column; min-height: 100vh; }

/* ---------- TOPBAR ---------- */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 18px; padding: 12px 20px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand__icon { width: 28px; height: 28px; color: var(--amber); }
.brand__text { display: flex; flex-direction: column; line-height: 1.1; }
.brand__name { font-family: var(--font-display); font-size: 18px; font-weight: 700; letter-spacing: 0.04em; }
.brand__tag { font-size: 10.5px; color: var(--text-dim); }

.topbar__pnl { display: flex; flex-direction: column; gap: 2px; }
.pnl-live { display: flex; align-items: center; gap: 8px; }
.pnl-live__value { font-family: var(--font-mono); font-size: 26px; font-weight: 600; color: var(--text); transition: color 0.25s ease; padding: 2px 6px; border-radius: 3px; }
.pnl-live__value.flash-up { color: var(--cyan); background: var(--cyan-dim); }
.pnl-live__value.flash-down { color: var(--red); background: var(--red-dim); }
.pnl-live__spark { width: 90px; height: 28px; }

.topbar__stats { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
.stat { display: flex; flex-direction: column; gap: 3px; min-width: 64px; }
.stat__label { font-size: 10px; color: var(--text-dim); }
.stat__value { font-family: var(--font-mono); font-size: 14px; font-weight: 500; }
.stat__value--tag { display: inline-block; padding: 2px 8px; border: 1px solid var(--amber); color: var(--amber); font-size: 10.5px; border-radius: 2px; width: fit-content; transition: color 0.4s ease, border-color 0.4s ease, background 0.4s ease; }
.stat__value--tag.is-live { color: var(--red); border-color: var(--red); }
.stat__value--tag.regime-bull { color: var(--cyan); border-color: var(--cyan); background: var(--cyan-dim); }
.stat__value--tag.regime-bear { color: var(--red); border-color: var(--red); background: var(--red-dim); }
.stat__value--tag.regime-range { color: var(--amber); border-color: var(--amber); }
.stat__value--tag.regime-highvol { color: var(--violet); border-color: var(--violet); background: rgba(177,140,255,0.12); animation: regimePulse 1.4s ease-in-out infinite; }
.stat__value--tag.regime-lowvol { color: var(--text-dim); border-color: var(--text-faint); }
@keyframes regimePulse { 0%,100% { opacity: 1; } 50% { opacity: 0.55; } }

.stat--kill { min-width: 140px; }
.killgauge { width: 100%; height: 6px; background: var(--panel-alt); border: 1px solid var(--line); border-radius: 2px; overflow: hidden; }
.killgauge__fill { height: 100%; background: var(--cyan); transition: width 0.6s ease, background-color 0.4s ease; }
.killgauge__fill.is-warning { background: var(--amber); }
.killgauge__fill.is-danger { background: var(--red); animation: dangerPulse 1s ease-in-out infinite; }
@keyframes dangerPulse { 0%,100% { opacity: 1; } 50% { opacity: 0.5; } }

.stat--gov .stat__value { color: var(--text-dim); }
.stat--gov .stat__value.is-cooldown { color: var(--amber); }
.stat--gov .stat__value.is-locked { color: var(--cyan); }

.btn { font-family: var(--font-mono); font-size: 11.5px; background: transparent; border: 1px solid var(--line); color: var(--text-dim); padding: 6px 11px; border-radius: 2px; cursor: pointer; transition: border-color 0.15s ease, color 0.15s ease, transform 0.1s ease; }
.btn:hover { border-color: var(--text-dim); color: var(--text); }
.btn:active { transform: scale(0.96); }
.btn--amber { border-color: var(--amber); color: var(--amber); }
.btn--amber:hover { background: var(--amber-dim); }
.btn--ghost { border-color: var(--line); }
.btn--danger-outline { border-color: var(--red); color: var(--red); }
.btn--danger-outline:hover { background: var(--red-dim); }

/* ---------- MAIN GRID ---------- */
.grid {
  flex: 1; display: grid;
  grid-template-columns: 230px 1.7fr 300px;
  grid-template-areas:
    "watchlist chart ai"
    "watchlist tradeplan positions"
    "watchlist notrade risk"
    "whale whale whale";
  gap: 1px; background: var(--line);
}
.panel { background: var(--panel); padding: 14px 16px; display: flex; flex-direction: column; gap: 10px; }
.panel--watchlist { grid-area: watchlist; }
.panel--chart { grid-area: chart; }
.panel--ai { grid-area: ai; }
.panel--tradeplan { grid-area: tradeplan; }
.panel--notrade { grid-area: notrade; }
.panel--positions { grid-area: positions; }
.panel--risk { grid-area: risk; }
.panel--whale { grid-area: whale; padding: 8px 16px; }

.panel__head { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.panel__head h2 { font-size: 13px; display: flex; align-items: center; gap: 7px; }
.panel__sub { font-size: 10.5px; color: var(--text-dim); font-weight: 400; }
.panel__actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* ---------- WATCHLIST / SCANNER LEADERBOARD ---------- */
.watchlist { display: flex; flex-direction: column; gap: 6px; overflow-y: auto; max-height: 480px; }
.watch-row { position: relative; display: flex; align-items: center; gap: 8px; padding: 6px 8px; border: 1px solid var(--line); border-radius: 2px; transition: transform 0.4s ease, border-color 0.3s ease; }
.watch-row.is-top { border-color: var(--amber); }
.score-ring { width: 30px; height: 30px; flex-shrink: 0; }
.score-ring circle.bg { stroke: var(--line); fill: none; stroke-width: 3; }
.score-ring circle.fg { fill: none; stroke-width: 3; stroke-linecap: round; transition: stroke-dashoffset 0.6s ease, stroke 0.4s ease; transform: rotate(-90deg); transform-origin: center; }
.score-ring text { font-family: var(--font-mono); font-size: 9px; fill: var(--text); text-anchor: middle; dominant-baseline: middle; }
.watch-row__info { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.watch-row__symbol { font-size: 11.5px; font-weight: 600; }
.watch-row__meta { font-size: 9.5px; color: var(--text-dim); display: flex; gap: 5px; }
.watch-row__dir { margin-left: auto; font-size: 13px; }
.watch-row__dir.bullish { color: var(--cyan); }
.watch-row__dir.bearish { color: var(--red); }

/* ---------- CHART ---------- */
.chart-container { flex: 1; min-height: 320px; border: 1px solid var(--line); border-radius: 2px; }
.backtest-box { border: 1px solid var(--amber); background: var(--amber-dim); padding: 9px 12px; border-radius: 2px; }
.backtest-box__row { display: flex; gap: 22px; flex-wrap: wrap; }
.backtest-box__row > div { display: flex; flex-direction: column; gap: 2px; }
.mini-label { font-size: 10px; color: var(--text-dim); }
.mini-value { font-family: var(--font-mono); font-size: 14px; font-weight: 500; color: var(--amber); }
.backtest-box__note { margin: 7px 0 0; font-size: 11px; color: var(--text-dim); }

/* ---------- AI PANEL ---------- */
.ai-indicator { display: flex; align-items: center; gap: 7px; }
.ai-indicator__label { font-size: 10.5px; color: var(--amber); }
.sonar-ping { position: relative; width: 16px; height: 16px; display: inline-block; }
.sonar-ping__dot { position: absolute; top: 50%; left: 50%; width: 6px; height: 6px; margin: -3px 0 0 -3px; background: var(--amber); border-radius: 50%; }
.sonar-ping__ring { position: absolute; top: 50%; left: 50%; width: 6px; height: 6px; margin: -3px 0 0 -3px; border-radius: 50%; border: 1px solid var(--amber); animation: sonarExpand 2.2s ease-out infinite; }
.sonar-ping__ring--delay { animation-delay: 1.1s; }
@keyframes sonarExpand { 0% { width: 6px; height: 6px; margin: -3px 0 0 -3px; opacity: 0.9; } 100% { width: 34px; height: 34px; margin: -17px 0 0 -17px; opacity: 0; } }

.ai-feed { flex: 1; min-height: 220px; max-height: 340px; overflow-y: auto; border: 1px solid var(--line); border-radius: 2px; padding: 9px 11px; display: flex; flex-direction: column; gap: 7px; font-size: 11.5px; background: var(--panel-alt); }
.ai-feed__line { color: var(--text-dim); line-height: 1.5; border-left: 2px solid var(--line); padding-left: 8px; }
.ai-feed__line--fresh { color: var(--text); border-left-color: var(--amber); }
.ai-feed__time { color: var(--text-faint); margin-right: 6px; }

/* ---------- TRADE PLAN ---------- */
.execstepper { display: flex; gap: 4px; flex-wrap: wrap; }
.execstepper__step { font-size: 9px; padding: 3px 7px; border: 1px solid var(--line); border-radius: 2px; color: var(--text-faint); transition: all 0.3s ease; }
.execstepper__step.is-active { color: var(--bg); background: var(--amber); border-color: var(--amber); }
.execstepper__step.is-done { color: var(--amber); border-color: var(--amber); }
.execstepper__step.is-failed { color: var(--red); border-color: var(--red); background: var(--red-dim); }

.tradeplan-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 10px; }
.tradeplan-grid > div { display: flex; flex-direction: column; gap: 2px; opacity: 0; transform: translateY(6px); animation: planReveal 0.35s ease forwards; }
@keyframes planReveal { to { opacity: 1; transform: translateY(0); } }
.tp-label { font-size: 10px; color: var(--text-dim); }
.tp-value { font-family: var(--font-mono); font-size: 14.5px; font-weight: 600; }
.tp-value.tp-long { color: var(--cyan); }
.tp-value.tp-short { color: var(--red); }
.tradeplan-reason { font-size: 11px; color: var(--text-dim); margin: 0; line-height: 1.5; }

/* ---------- NO-TRADE ---------- */
.notrade-list { display: flex; flex-direction: column; gap: 6px; }
.notrade-list li { display: flex; gap: 7px; align-items: baseline; font-size: 11px; color: var(--red); opacity: 0; animation: slideInLeft 0.3s ease forwards; border-left: 2px solid var(--red); padding-left: 8px; }
@keyframes slideInLeft { from { opacity: 0; transform: translateX(-8px); } to { opacity: 1; transform: translateX(0); } }

/* ---------- POSITION SLOTS ---------- */
.position-slots { display: flex; flex-direction: column; gap: 9px; flex: 1; }
.position-slot { border: 1px solid var(--line); border-radius: 2px; padding: 11px 13px; min-height: 88px; display: flex; flex-direction: column; gap: 5px; justify-content: center; }
.position-slot--empty { border-style: dashed; align-items: center; color: var(--text-faint); font-size: 11.5px; }
.position-slot--long { border-left: 3px solid var(--cyan); background: var(--cyan-dim); justify-content: flex-start; }
.position-slot--short { border-left: 3px solid var(--red); background: var(--red-dim); justify-content: flex-start; }
.slot-row { display: flex; justify-content: space-between; align-items: baseline; font-size: 11.5px; }
.slot-row__side { font-weight: 600; letter-spacing: 0.03em; }
.slot-row__side--long { color: var(--cyan); }
.slot-row__side--short { color: var(--red); }
.slot-pnl { font-family: var(--font-mono); font-size: 15px; font-weight: 600; transition: color 0.2s ease; }
.slot-pnl.is-pos { color: var(--cyan); }
.slot-pnl.is-neg { color: var(--red); }
.slot-meta { font-size: 10.5px; color: var(--text-dim); display: flex; gap: 12px; flex-wrap: wrap; }
.slot-mfemae { font-size: 9.5px; color: var(--text-faint); display: flex; gap: 10px; }

/* ---------- RISK / GOVERNANCE PANEL ---------- */
.risk-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.risk-grid > div { display: flex; flex-direction: column; gap: 2px; }
.risk-label { font-size: 9.5px; color: var(--text-dim); }
.risk-value { font-family: var(--font-mono); font-size: 13.5px; font-weight: 500; }
.risk-value.is-warn { color: var(--amber); }
.risk-value.is-lock { color: var(--cyan); }

/* ---------- WHALE TICKER ---------- */
.whale-icon { width: 15px; height: 15px; color: var(--cyan); }
.whale-ticker { overflow: hidden; border: 1px solid var(--line); border-radius: 2px; background: var(--panel-alt); padding: 7px 0; }
.whale-ticker__track { display: inline-block; white-space: nowrap; padding-left: 100%; font-size: 11.5px; color: var(--cyan); animation: marquee 24s linear infinite; }
@keyframes marquee { 0% { transform: translateX(0); } 100% { transform: translateX(-100%); } }

/* ---------- ALERT BANNER ---------- */
.alert-banner { position: fixed; bottom: 44px; left: 50%; transform: translateX(-50%); display: flex; align-items: center; gap: 10px; background: var(--red-dim); border: 1px solid var(--red); color: var(--red); padding: 9px 15px; border-radius: 2px; font-size: 12px; max-width: min(560px, 90vw); animation: alertPulse 1.6s ease-in-out infinite; z-index: 20; }
.alert-banner svg { width: 17px; height: 17px; flex-shrink: 0; }
@keyframes alertPulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(255, 84, 104, 0.35); } 50% { box-shadow: 0 0 0 6px rgba(255, 84, 104, 0.08); } }

/* ---------- FOOTER ---------- */
.footer { padding: 8px 20px; border-top: 1px solid var(--line); font-size: 10.5px; color: var(--text-faint); }

/* ---------- RESPONSIVE ---------- */
@media (max-width: 1180px) {
  .grid { grid-template-columns: 200px 1.5fr 260px; }
}
@media (max-width: 980px) {
  .grid {
    grid-template-columns: 1fr;
    grid-template-areas: "chart" "tradeplan" "notrade" "ai" "positions" "risk" "watchlist" "whale";
  }
  .watchlist { max-height: 260px; }
  .chart-container { min-height: 260px; }
}
@media (max-width: 600px) {
  .topbar { padding: 10px 12px; }
  .topbar__stats { gap: 12px; }
  .panel { padding: 12px; }
  .pnl-live__value { font-size: 21px; }
  .alert-banner { bottom: 10px; font-size: 11px; }
}

/* ---------- REDUCED MOTION ---------- */
@media (prefers-reduced-motion: reduce) {
  .sonar-ping__ring, .whale-ticker__track, .alert-banner, .stat__value--tag.regime-highvol, .killgauge__fill.is-danger { animation: none !important; }
  .tradeplan-grid > div, .notrade-list li { animation: none !important; opacity: 1 !important; transform: none !important; }
}
