/* ═══════════════════════════════════════════════════════════════════════
   Judah — D1/D2 Hybrid Scanner (V5.2)
   ═══════════════════════════════════════════════════════════════════════ */

:root {
  --bg: #080c14;
  --bg-card: #0f1520;
  --bg-card-new: #111d2e;
  --bg-hover: #1a2438;
  --border: #1c2a3a;
  --border-subtle: #141e2c;
  --text: #e2e8f0;
  --text-sec: #94a3b8;
  --text-muted: #546178;
  --accent: #3b82f6;

  --green: #22c55e;
  --red: #ef4444;
  --amber: #f59e0b;
  --orange: #f97316;
  --blue: #3b82f6;
  --yellow: #eab308;
  --purple: #a855f7;

  --radius: 8px;
  --radius-sm: 5px;
  --gap: 8px;
  --transition: 0.15s ease;
}

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

html { -webkit-text-size-adjust: 100%; -webkit-tap-highlight-color: transparent; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 13px;
  line-height: 1.4;
  overflow-x: hidden;
}

.app { max-width: 1440px; margin: 0 auto; padding: 8px; }

/* ── Scrollbar ───────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #1e293b; border-radius: 4px; }

/* ── Header ──────────────────────────────────────────────────────── */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 8px;
  gap: 12px;
  flex-wrap: wrap;
}

.header-left { display: flex; align-items: center; gap: 10px; }
.logo-icon { color: var(--accent); display: flex; }
.logo-text h1 { font-size: 16px; font-weight: 700; letter-spacing: 0.5px; line-height: 1.1; }
.logo-text span { font-size: 11px; color: var(--text-sec); }

.header-right { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.scan-status { display: flex; align-items: center; gap: 6px; font-size: 11px; color: var(--text-sec); }
.scan-dot {
  width: 7px; height: 7px; border-radius: 50%; background: #ef4444;
  display: inline-block; transition: background 0.3s;
}
.scan-dot.live { background: #22c55e; box-shadow: 0 0 6px rgba(34,197,94,0.4); }

.status-pill {
  display: flex; align-items: center; gap: 5px;
  padding: 3px 10px; border-radius: 20px;
  background: var(--bg-hover); border: 1px solid var(--border);
  font-size: 11px; color: var(--text-sec);
}
.pulse-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: #ef4444; transition: background 0.3s;
}
.pulse-dot.live { background: #22c55e; }

.stat-group { display: flex; gap: 4px; }
.stat-chip {
  display: flex; flex-direction: column; align-items: center;
  padding: 3px 8px; border-radius: var(--radius-sm);
  background: var(--bg-hover); border: 1px solid var(--border);
  min-width: 44px;
}
.stat-label { font-size: 9px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; }
.stat-value { font-size: 15px; font-weight: 700; color: var(--text); }
.stat-accent { border-color: #3b82f644; }
.stat-accent .stat-value { color: var(--accent); }

.btn-icon {
  width: 30px; height: 30px; border-radius: var(--radius-sm);
  background: var(--bg-hover); border: 1px solid var(--border);
  color: var(--text-sec); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all var(--transition);
}
.btn-icon:hover { background: var(--border); color: var(--text); }

/* ── Filter Section ──────────────────────────────────────────────── */
.filter-section {
  display: flex; align-items: center; gap: 6px;
  padding: 8px 12px; margin-bottom: 8px;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow-x: auto;
}

.filter-scroll { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.filter-group-label {
  font-size: 10px; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.5px; font-weight: 600;
  white-space: nowrap;
}
.filter-sep {
  width: 1px; height: 20px; background: var(--border);
  margin: 0 4px; flex-shrink: 0;
}

.filter-chip {
  padding: 4px 10px; border-radius: 20px;
  background: var(--bg-hover); border: 1px solid var(--border);
  color: var(--text-sec); cursor: pointer;
  font-size: 11px; white-space: nowrap;
  transition: all var(--transition);
}
.filter-chip:hover { border-color: var(--accent); color: var(--text); }
.filter-chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }

.dir-chip.bullish.active { background: var(--green); border-color: var(--green); color: #fff; }
.dir-chip.bearish.active { background: var(--red); border-color: var(--red); color: #fff; }

/* ── Activity Bar ────────────────────────────────────────────────── */
.activity-bar {
  display: flex; align-items: center; gap: 16px;
  padding: 6px 14px; margin-bottom: 8px;
  background: var(--bg-card); border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  font-size: 11px; color: var(--text-muted);
}
.activity-item { display: flex; align-items: center; gap: 4px; }
.act-label { font-weight: 600; color: var(--text-sec); }
.act-status { color: var(--text-muted); }
.act-dot { width: 5px; height: 5px; border-radius: 50%; background: var(--text-muted); }
.act-status:contains('Live') { color: var(--green); }

/* ── Type E Alert Bar ────────────────────────────────────────────── */
.type-e-alert {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 12px; margin-bottom: 6px;
  background: #ef444415; border: 1px solid #ef444444;
  border-radius: var(--radius-sm);
  font-size: 12px; color: #fca5a5;
}
.te-icon { font-size: 14px; }
.te-coin { font-weight: 700; color: #fff; }
.te-conflict { color: #fca5a5; }
.te-time { margin-left: auto; color: var(--text-muted); font-size: 10px; }

/* ── Signals Container ───────────────────────────────────────────── */
.signals-container { display: flex; flex-direction: column; gap: 6px; }

.empty-state {
  text-align: center; padding: 60px 20px;
  color: var(--text-muted);
}
.empty-spinner { margin-bottom: 16px; color: var(--text-muted); }
.empty-spinner svg { animation: spin 2s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
#emptyTitle { font-size: 16px; color: var(--text-sec); margin-bottom: 6px; font-weight: 600; }
#emptyMsg { font-size: 12px; }

.no-results {
  text-align: center; padding: 40px; color: var(--text-muted);
  display: flex; flex-direction: column; align-items: center; gap: 10px;
}
.clear-btn {
  padding: 6px 16px; border-radius: var(--radius-sm);
  background: var(--accent); color: #fff; border: none;
  cursor: pointer; font-size: 12px;
}

/* ── Card ────────────────────────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: border-color var(--transition);
}
.card:hover { border-color: #2d3f56; }
.card-new {
  background: var(--bg-card-new);
  border-color: #3b82f644;
  animation: cardPulse 3s ease-out;
}
@keyframes cardPulse {
  0% { border-color: #3b82f6; box-shadow: 0 0 12px rgba(59,130,246,0.15); }
  100% { border-color: var(--border); box-shadow: none; }
}

/* Card Header */
.card-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px; cursor: pointer;
  gap: 8px; flex-wrap: wrap;
}
.card-left { display: flex; align-items: center; gap: 8px; min-width: 0; flex: 1; flex-wrap: wrap; }
.card-right { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

.coin-link {
  font-size: 14px; font-weight: 700; color: var(--text);
  white-space: nowrap; text-decoration: none;
  display: inline-flex; align-items: center; gap: 5px;
  transition: color 0.15s;
}
.coin-link:hover { color: #3b82f6; }
.tv-icon { opacity: 0.5; transition: opacity 0.15s; flex-shrink: 0; }
.coin-link:hover .tv-icon { opacity: 1; }

.binance-link {
  display: inline-flex; align-items: center; color: var(--text-muted);
  text-decoration: none; opacity: 0.6; transition: all 0.15s;
}
.binance-link:hover { color: #f3ba2f; opacity: 1; }

/* ME State badge — shows market evolution state */
.me-state-badge {
  padding: 2px 7px; border-radius: 3px;
  font-size: 10px; font-weight: 600;
  background: #a855f722; color: #a855f7; border: 1px solid #a855f744;
  white-space: nowrap;
}

/* Score flow: D1 → D2 */
.score-flow {
  display: flex; align-items: center; gap: 4px;
  font-size: 12px; font-weight: 600;
}
.score-d1 { color: var(--text-sec); }
.score-arrow { color: var(--text-muted); font-size: 10px; }
.score-d2 { color: var(--text); font-size: 14px; font-weight: 700; }

/* Confidence badge */
.conf-badge {
  padding: 2px 7px; border-radius: 3px;
  font-size: 10px; font-weight: 700;
  border: 1px solid;
  white-space: nowrap;
}
.conf-high { background: #22c55e22; color: #22c55e; border-color: #22c55e44; }
.conf-mid { background: #f59e0b22; color: #f59e0b; border-color: #f59e0b44; }
.conf-low { background: #ef444422; color: #ef4444; border-color: #ef444444; }

/* Direction dot */
.dir-dot {
  width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0;
}
.dir-bullish { background: var(--green); }
.dir-bearish { background: var(--red); }
.dir-neutral { background: #6b7280; }

/* Tier badge */
.tier-badge {
  padding: 2px 8px; border-radius: 4px;
  font-size: 10px; font-weight: 700;
  border: 1px solid;
}
.tier-sniper { background: #eab30822; color: #eab308; border-color: #eab30844; }
.tier-opportunity { background: #22c55e22; color: #22c55e; border-color: #22c55e44; }
.tier-watch { background: #3b82f622; color: #3b82f6; border-color: #3b82f644; }
.tier-weak { background: #a855f722; color: #a855f7; border-color: #a855f744; }
.tier-rejected { background: #6b728022; color: #6b7280; border-color: #6b728044; }

/* Direction badge */
.dir-badge {
  padding: 2px 6px; border-radius: 3px;
  font-size: 10px; font-weight: 700; letter-spacing: 0.5px;
}
.dir-bullish { background: #22c55e22; color: #22c55e; }
.dir-bearish { background: #ef444422; color: #ef4444; }
.dir-neutral { background: #6b728022; color: #6b7280; }

/* Age badge */
.age-badge {
  font-size: 9px; font-weight: 700; letter-spacing: 0.5px;
  padding: 1px 5px; border-radius: 3px;
  background: var(--bg-hover); color: var(--text-muted);
}
.age-live { background: #22c55e22; color: #22c55e; animation: livePulse 1.5s infinite; }
@keyframes livePulse { 0%,100% { opacity:1; } 50% { opacity:0.5; } }

.expand-icon { color: var(--text-muted); font-size: 10px; }

/* ── Card Body ───────────────────────────────────────────────────── */
.card-body {
  padding: 0 14px 12px;
  border-top: 1px solid var(--border-subtle);
  display: flex; flex-direction: column; gap: 8px;
}

/* Market Evolution Detail Row */
.me-detail-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
  gap: 8px; padding: 8px 0;
}
.me-detail-cell { display: flex; flex-direction: column; gap: 2px; }
.me-lbl { font-size: 9px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; }
.me-evol { font-size: 11px; color: var(--text-sec); }
.me-decision { font-size: 12px; color: var(--text); }
.me-spiral { font-size: 12px; }
.me-momentum { font-size: 14px; font-weight: 700; color: var(--text); }

.conf-bar-bg {
  height: 4px; background: var(--bg-hover); border-radius: 2px;
  overflow: hidden;
}
.conf-bar-fill { height: 100%; border-radius: 2px; transition: width 0.3s; }
.conf-val { font-size: 11px; font-weight: 600; }

/* Structure Row: D1 + D2 */
.structure-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.struct-panel {
  background: var(--bg-hover);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
}

.struct-header {
  display: flex; align-items: center; gap: 6px;
  margin-bottom: 6px;
}
.struct-title { font-size: 10px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; }
.struct-tier {
  font-size: 10px; font-weight: 700; padding: 1px 6px; border-radius: 3px;
}
.struct-score { font-size: 12px; font-weight: 700; margin-left: auto; }

.struct-tags { display: flex; flex-wrap: wrap; gap: 4px; }

/* Tags */
.tag {
  display: inline-flex; align-items: center;
  padding: 2px 6px; border-radius: 3px;
  font-size: 10px; font-weight: 600;
  background: var(--bg-card); border: 1px solid var(--border);
  color: var(--text-sec);
}
.tag-msb { color: #a78bfa; border-color: #a78bfa33; }
.tag-ob { color: #fbbf24; border-color: #fbbf2433; }
.tag-fvg { color: #34d399; border-color: #34d39933; }
.tag-liq { color: #f87171; border-color: #f8717133; }
.tag-poc { color: #60a5fa; border-color: #60a5fa33; }
.tag-va { color: #94a3b8; border-color: #94a3b833; }
.tag-pd { color: #c084fc; border-color: #c084fc33; }
.tag-scenario { color: #f97316; border-color: #f9731633; }
.tag-disp { color: #fb923c; border-color: #fb923c33; }
.tag-nascent { background: #eab30822; color: #eab308; border-color: #eab30844; animation: livePulse 1.5s infinite; }

/* TF Breakdown */
.tf-breakdown {
  display: flex; flex-wrap: wrap; gap: 3px;
  margin-top: 6px; padding-top: 6px;
  border-top: 1px solid var(--border-subtle);
}
.tf-chip {
  padding: 1px 5px; border-radius: 3px;
  font-size: 9px; background: var(--bg-card);
  border: 1px solid;
}
.tf-chip b { font-size: 10px; }

/* Alignment */
.align-row {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 10px; border-radius: var(--radius-sm);
  font-size: 11px;
}
.align-high { background: #22c55e10; }
.align-mid { background: #f59e0b10; }
.align-low { background: #ef444410; }
.align-label { font-weight: 600; color: var(--text-sec); white-space: nowrap; }
.align-bar-bg {
  flex: 1; height: 4px; background: var(--bg-hover);
  border-radius: 2px; overflow: hidden; max-width: 100px;
}
.align-bar-fill { height: 100%; border-radius: 2px; transition: width 0.3s; }
.align-score { font-weight: 700; min-width: 30px; }
.align-dirs { color: var(--text-muted); }

/* Trade Levels */
.levels-row {
  display: flex; gap: 4px; flex-wrap: wrap;
}
.lvl-cell {
  display: flex; flex-direction: column; align-items: center;
  padding: 4px 10px; border-radius: var(--radius-sm);
  background: var(--bg-hover); border: 1px solid var(--border-subtle);
  min-width: 60px; flex: 1;
}
.lvl-lbl { font-size: 9px; color: var(--text-muted); text-transform: uppercase; }
.lvl-val { font-size: 12px; font-weight: 600; color: var(--text); }
.lvl-val2 { font-size: 10px; color: var(--text-sec); }
.lvl-entry { border-color: #22c55e33; }
.lvl-sl { border-color: #ef444433; }
.lvl-tp { border-color: #3b82f633; }
.lvl-rr { border-color: #f59e0b33; }

/* Meta Row */
.meta-row {
  display: flex; align-items: center; gap: 8px;
  padding-top: 6px; border-top: 1px solid var(--border-subtle);
}
.ev-cell { display: flex; align-items: center; gap: 4px; }
.ev-label { font-size: 9px; color: var(--text-muted); text-transform: uppercase; }
.ev-val { font-size: 12px; font-weight: 700; }
.ev-wr { font-size: 10px; color: var(--text-sec); }

.nascent-badge, .ep-badge {
  padding: 2px 6px; border-radius: 3px;
  font-size: 9px; font-weight: 700;
}
.nascent-badge { background: #eab30822; color: #eab308; }
.ep-badge { background: #3b82f622; color: #3b82f6; }

.born-time { font-size: 10px; color: var(--text-muted); margin-left: auto; }

/* Sparkline */
.sparkline { border-radius: 2px; }

/* ── Responsive ──────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .header { flex-direction: column; align-items: flex-start; }
  .header-right { width: 100%; justify-content: space-between; }
  .structure-row { grid-template-columns: 1fr; }
  .me-banner { grid-template-columns: repeat(2, 1fr); }
  .filter-section { flex-wrap: wrap; }
  .card-header { flex-direction: column; align-items: flex-start; }
  .card-right { width: 100%; justify-content: space-between; }
  .score-pair { font-size: 12px; }
  .score-d2 b { font-size: 16px; }
}

@media (max-width: 480px) {
  .app { padding: 4px; }
  .header { padding: 8px 10px; }
  .logo-text span { display: none; }
  .stat-chip { min-width: 36px; padding: 2px 6px; }
  .stat-value { font-size: 13px; }
  .me-banner { grid-template-columns: 1fr; }
}

/* ── Signal History ───────────────────────────────────────────────── */

@media (max-width: 768px) {
