/* ═══════════════════════════════════════════════════════════════════════════
   SwingPulse — Complete Theme & UI System
   ═══════════════════════════════════════════════════════════════════════════ */

/* ── Design Tokens (Dark) ─────────────────────────────────────────────── */
:root,
[data-theme="dark"] {
  --bg-base:       #0a0e17;
  --bg-surface:    #111827;
  --bg-elevated:   #1a2332;
  --bg-card:       #151e2d;
  --bg-hover:      #1e293b;
  --bg-input:      #0f172a;
  --border:        #1e293b;
  --border-active: #334155;
  --text-primary:  #f1f5f9;
  --text-secondary:#94a3b8;
  --text-muted:    #64748b;
  --accent:        #6366f1;
  --accent-glow:   rgba(99,102,241,.25);
  --buy:           #10b981;
  --buy-soft:      rgba(16,185,129,.12);
  --buy-glow:      rgba(16,185,129,.35);
  --sell:          #ef4444;
  --sell-soft:     rgba(239,68,68,.12);
  --sell-glow:     rgba(239,68,68,.35);
  --watch:         #f59e0b;
  --watch-soft:    rgba(245,158,11,.12);
  --watch-glow:    rgba(245,158,11,.35);
  --volume:        #8b5cf6;
  --volume-soft:   rgba(139,92,246,.12);
  --volume-glow:   rgba(139,92,246,.35);
  --neutral:       #475569;
  --neutral-soft:  rgba(71,85,105,.15);
  --radius:        12px;
  --radius-sm:     8px;
  --radius-lg:     16px;
  --shadow:        0 4px 24px rgba(0,0,0,.4);
  --shadow-lg:     0 12px 48px rgba(0,0,0,.6);
  --transition:    .25s cubic-bezier(.4,0,.2,1);
  --glass:         rgba(17,24,39,.7);
  --glass-border:  rgba(255,255,255,.06);
  --scrollbar-bg:  #1e293b;
  --scrollbar-thumb:#334155;
}

/* ── Design Tokens (Light) ────────────────────────────────────────────── */
[data-theme="light"] {
  --bg-base:       #f8fafc;
  --bg-surface:    #ffffff;
  --bg-elevated:   #f1f5f9;
  --bg-card:       #ffffff;
  --bg-hover:      #f1f5f9;
  --bg-input:      #f1f5f9;
  --border:        #e2e8f0;
  --border-active: #cbd5e1;
  --text-primary:  #0f172a;
  --text-secondary:#475569;
  --text-muted:    #94a3b8;
  --accent:        #4f46e5;
  --accent-glow:   rgba(79,70,229,.15);
  --buy:           #059669;
  --buy-soft:      rgba(5,150,105,.08);
  --buy-glow:      rgba(5,150,105,.2);
  --sell:          #dc2626;
  --sell-soft:     rgba(220,38,38,.08);
  --sell-glow:     rgba(220,38,38,.2);
  --watch:         #d97706;
  --watch-soft:    rgba(217,119,6,.08);
  --watch-glow:    rgba(217,119,6,.2);
  --volume:        #7c3aed;
  --volume-soft:   rgba(124,58,237,.08);
  --volume-glow:   rgba(124,58,237,.2);
  --neutral:       #94a3b8;
  --neutral-soft:  rgba(148,163,184,.1);
  --shadow:        0 4px 24px rgba(0,0,0,.06);
  --shadow-lg:     0 12px 48px rgba(0,0,0,.1);
  --glass:         rgba(255,255,255,.8);
  --glass-border:  rgba(0,0,0,.06);
  --scrollbar-bg:  #e2e8f0;
  --scrollbar-thumb:#cbd5e1;
}

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

html {
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Inter', sans-serif;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
  scroll-behavior: smooth;
}

body {
  background: var(--bg-base);
  color: var(--text-primary);
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  transition: background var(--transition), color var(--transition);
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--scrollbar-bg); }
::-webkit-scrollbar-thumb { background: var(--scrollbar-thumb); border-radius: 3px; }

/* ── Typography ───────────────────────────────────────────────────────── */
h1, h2, h3, h4 { font-weight: 600; letter-spacing: -.01em; }
h3 { font-size: .9rem; color: var(--text-secondary); display: flex; align-items: center; gap: 6px; }

/* ── Top Bar ──────────────────────────────────────────────────────────── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 56px;
  padding: 0 16px;
  background: var(--glass);
  backdrop-filter: blur(16px) saturate(1.5);
  -webkit-backdrop-filter: blur(16px) saturate(1.5);
  border-bottom: 1px solid var(--glass-border);
  --pulse-color: var(--accent);
}

/* Sentiment-driven (keeps variable for the badge) */
.topbar.sentiment-bullish { --pulse-color: var(--buy); }
.topbar.sentiment-bearish { --pulse-color: var(--sell); }
.topbar.sentiment-mixed   { --pulse-color: var(--watch); }

/* Sentiment dot in topbar */
.topbar-sentiment {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: .78rem;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 20px;
  background: color-mix(in srgb, var(--pulse-color) 12%, transparent);
  color: var(--pulse-color);
  letter-spacing: .02em;
}
.topbar-sentiment-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--pulse-color);
  animation: dot-heartbeat 3.5s ease-in-out infinite;
}
@keyframes dot-heartbeat {
  0%, 60%, 100% { transform: scale(1); opacity: .5; }
  14% { transform: scale(1.5); opacity: 1; }
  28% { transform: scale(1); opacity: .6; }
  42% { transform: scale(1.35); opacity: 1; }
}

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

.logo { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 1.1rem; }
.logo-icon {
  width: 28px; height: 28px;
  background: linear-gradient(135deg, var(--buy), var(--accent));
  border-radius: 8px;
  position: relative;
  overflow: hidden;
}
.logo-icon::after {
  content: '';
  position: absolute;
  inset: 4px;
  background: var(--bg-surface);
  border-radius: 4px;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3E%3Cpolyline points='2,14 7,8 11,12 18,5' stroke='white' stroke-width='2.5' fill='none'/%3E%3C/svg%3E") center/80% no-repeat;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3E%3Cpolyline points='2,14 7,8 11,12 18,5' stroke='white' stroke-width='2.5' fill='none'/%3E%3C/svg%3E") center/80% no-repeat;
}

.date-badge {
  font-size: .75rem;
  font-weight: 500;
  padding: 4px 10px;
  background: var(--accent-glow);
  color: var(--accent);
  border-radius: 20px;
  letter-spacing: .02em;
}

.icon-btn {
  width: 36px; height: 36px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: all var(--transition);
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text-primary); }
.icon-btn:active { transform: scale(.92); }

#refreshBtn.spinning svg { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.theme-toggle .icon-sun { display: none; }
.theme-toggle .icon-moon { display: block; }
[data-theme="light"] .theme-toggle .icon-sun { display: block; }
[data-theme="light"] .theme-toggle .icon-moon { display: none; }

/* ── Main Content ─────────────────────────────────────────────────────── */
.content {
  padding: 16px 16px 80px;
  max-width: 1400px;
  margin: 0 auto;
}

@media (min-width: 768px) { .content { padding: 24px 24px 32px; } }

/* ── Tab Panes ────────────────────────────────────────────────────────── */
.tab-pane {
  display: none;
  animation: fadeIn .35s ease;
}
.tab-pane.active { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ── Bottom Nav ───────────────────────────────────────────────────────── */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 100;
  display: flex;
  height: 64px;
  padding-bottom: env(safe-area-inset-bottom, 0);
  background: var(--glass);
  backdrop-filter: blur(16px) saturate(1.5);
  -webkit-backdrop-filter: blur(16px) saturate(1.5);
  border-top: 1px solid var(--glass-border);
}

.nav-tab {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  cursor: pointer;
  font-size: .65rem;
  font-weight: 500;
  transition: all var(--transition);
  position: relative;
}
.nav-tab span { transition: color var(--transition); }
.nav-tab.active { color: var(--accent); }
.nav-tab.active::before {
  content: '';
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 32px;
  height: 3px;
  border-radius: 0 0 3px 3px;
  background: var(--accent);
  animation: slideDown .3s ease;
}
@keyframes slideDown { from { transform: translateX(-50%) scaleX(0); } to { transform: translateX(-50%) scaleX(1); } }

@media (min-width: 768px) {
  .bottom-nav {
    top: 56px; bottom: auto;
    height: 48px;
    border-top: none;
    border-bottom: 1px solid var(--glass-border);
    justify-content: center;
    gap: 4px;
    padding: 0 16px;
  }
  .nav-tab {
    flex: none;
    flex-direction: row;
    gap: 6px;
    padding: 0 20px;
    font-size: .8rem;
    border-radius: var(--radius-sm);
  }
  .nav-tab.active::before {
    top: auto; bottom: 0;
    border-radius: 3px 3px 0 0;
  }
  .content { padding-top: 72px; }
}

/* ── Market Pulse Banner — heartbeat border ───────────────────────── */
.market-pulse {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  margin-bottom: 16px;
  border-radius: var(--radius-lg);
  background: linear-gradient(135deg, var(--bg-elevated), var(--bg-surface));
  border: 2px solid var(--border);
  position: relative;
  overflow: hidden;
  --mp-color: var(--accent);
}
.market-pulse.mp-bullish { --mp-color: var(--buy); }
.market-pulse.mp-bearish { --mp-color: var(--sell); }
.market-pulse.mp-mixed   { --mp-color: var(--watch); }

/* Heartbeat glow — double-beat then rest, like a real heart */
.market-pulse {
  animation: heartbeat 3.5s ease-in-out infinite;
}
@keyframes heartbeat {
  0%  {
    border-color: color-mix(in srgb, var(--mp-color) 30%, var(--border));
    box-shadow: 0 0 0px transparent;
  }
  /* first beat — quick strong punch */
  14% {
    border-color: var(--mp-color);
    box-shadow:
      0 0 18px color-mix(in srgb, var(--mp-color) 50%, transparent),
      0 0 6px color-mix(in srgb, var(--mp-color) 30%, transparent),
      inset 0 0 12px color-mix(in srgb, var(--mp-color) 10%, transparent);
  }
  /* brief dip between beats */
  28% {
    border-color: color-mix(in srgb, var(--mp-color) 50%, var(--border));
    box-shadow: 0 0 4px color-mix(in srgb, var(--mp-color) 15%, transparent);
  }
  /* second beat — slightly softer */
  42% {
    border-color: var(--mp-color);
    box-shadow:
      0 0 22px color-mix(in srgb, var(--mp-color) 45%, transparent),
      0 0 8px color-mix(in srgb, var(--mp-color) 25%, transparent),
      inset 0 0 14px color-mix(in srgb, var(--mp-color) 8%, transparent);
  }
  /* rest period */
  60%, 100% {
    border-color: color-mix(in srgb, var(--mp-color) 30%, var(--border));
    box-shadow: 0 0 0px transparent;
  }
}

/* Radial glow behind banner that also heartbeats */
.market-pulse::before {
  content: '';
  position: absolute;
  top: -50%;
  right: -20%;
  width: 200px;
  height: 200px;
  background: radial-gradient(circle, color-mix(in srgb, var(--mp-color) 15%, transparent), transparent 70%);
  pointer-events: none;
  animation: heartbeat-glow 3.5s ease-in-out infinite;
}
@keyframes heartbeat-glow {
  0%, 60%, 100% { opacity: .3; transform: scale(1); }
  14% { opacity: 1; transform: scale(1.1); }
  28% { opacity: .5; transform: scale(1); }
  42% { opacity: .9; transform: scale(1.08); }
}

/* Hide old rings */
.pulse-ring, .pulse-ring-2 { display: none; }

.pulse-inner { display: flex; align-items: center; gap: 12px; position: relative; z-index: 1; }
.pulse-info { display: flex; flex-direction: column; }
.pulse-label { font-size: .7rem; text-transform: uppercase; letter-spacing: .08em; color: var(--text-muted); }
.pulse-value { font-size: 1.1rem; font-weight: 700; }
.pulse-value.bullish { color: var(--buy); }
.pulse-value.bearish { color: var(--sell); }
.pulse-value.mixed { color: var(--watch); }

.pulse-stats {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: .78rem;
  color: var(--text-secondary);
  position: relative;
  z-index: 1;
}
.pulse-divider { opacity: .3; }

@media (max-width: 580px) {
  .market-pulse { flex-direction: column; gap: 12px; text-align: center; }
  .pulse-inner { justify-content: center; }
}

/* ── Stat Cards ───────────────────────────────────────────────────────── */
.stat-cards {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}
@media (min-width: 768px) { .stat-cards { grid-template-columns: repeat(4, 1fr); gap: 16px; } }

.stat-card {
  position: relative;
  padding: 16px;
  border-radius: var(--radius);
  background: var(--bg-card);
  border: 1px solid var(--border);
  overflow: hidden;
  transition: all var(--transition);
}
.stat-card:hover { transform: translateY(-2px); border-color: var(--border-active); }

.stat-card-glow {
  position: absolute;
  top: -30px;
  right: -30px;
  width: 80px;
  height: 80px;
  border-radius: 50%;
  filter: blur(30px);
  pointer-events: none;
  transition: opacity var(--transition);
}
.stat-buy .stat-card-glow { background: var(--buy-glow); }
.stat-sell .stat-card-glow { background: var(--sell-glow); }
.stat-watch .stat-card-glow { background: var(--watch-glow); }
.stat-volume .stat-card-glow { background: var(--volume-glow); }

.stat-header { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }

.stat-icon-wrap {
  width: 32px; height: 32px;
  border-radius: var(--radius-sm);
  display: grid;
  place-items: center;
}
.buy-icon { background: var(--buy-soft); color: var(--buy); }
.sell-icon { background: var(--sell-soft); color: var(--sell); }
.watch-icon { background: var(--watch-soft); color: var(--watch); }
.volume-icon { background: var(--volume-soft); color: var(--volume); }

.stat-label { font-size: .75rem; color: var(--text-muted); font-weight: 500; }
.stat-number {
  font-size: 1.8rem;
  font-weight: 700;
  line-height: 1;
  margin-bottom: 10px;
  font-variant-numeric: tabular-nums;
}
.stat-buy .stat-number { color: var(--buy); }
.stat-sell .stat-number { color: var(--sell); }
.stat-watch .stat-number { color: var(--watch); }
.stat-volume .stat-number { color: var(--volume); }

.stat-bar {
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
}
.stat-bar-fill {
  height: 100%;
  border-radius: 2px;
  width: 0%;
  transition: width .8s cubic-bezier(.4,0,.2,1);
}
.buy-fill { background: var(--buy); }
.sell-fill { background: var(--sell); }
.watch-fill { background: var(--watch); }
.volume-fill { background: var(--volume); }

/* ── Cards ────────────────────────────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 16px;
  margin-bottom: 16px;
  transition: all var(--transition);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
  flex-wrap: wrap;
  gap: 8px;
}
.card-icon { display: inline-flex; margin-right: 2px; }
.card-icon.turning { color: var(--watch); }
.card-icon.watch { color: var(--accent); }
.card-icon.level { color: var(--buy); }
.card-icon.volume { color: var(--volume); }

/* ── Charts Row ───────────────────────────────────────────────────────── */
.charts-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
  margin-bottom: 16px;
}
@media (min-width: 768px) { .charts-row { grid-template-columns: 1fr 1fr 1fr; } }

.chart-card { min-height: 260px; }
.chart-wrap { position: relative; height: 220px; }
.chart-wrap canvas { width: 100% !important; height: 100% !important; }

/* ── Heatmap ──────────────────────────────────────────────────────────── */
.heatmap-legend { display: flex; gap: 12px; flex-wrap: wrap; }
.legend-item { display: flex; align-items: center; gap: 5px; font-size: .72rem; color: var(--text-muted); }
.legend-dot { width: 10px; height: 10px; border-radius: 3px; }
.buy-dot { background: var(--buy); }
.sell-dot { background: var(--sell); }
.neutral-dot { background: var(--neutral); }
.watch-dot { background: var(--watch); }

.heatmap-filters {
  display: flex;
  gap: 6px;
  margin-bottom: 12px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 4px;
}
.heatmap-filter-btn {
  border: none;
  padding: 5px 12px;
  border-radius: 20px;
  font-size: .72rem;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  background: var(--bg-hover);
  color: var(--text-secondary);
  transition: all var(--transition);
}
.heatmap-filter-btn.active { background: var(--accent); color: #fff; }

.heatmap-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
  gap: 6px;
}

.heatmap-cell {
  position: relative;
  aspect-ratio: 1.6;
  border-radius: var(--radius-sm);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: .68rem;
  font-weight: 600;
  transition: all var(--transition);
  border: 1px solid transparent;
  overflow: hidden;
}
.heatmap-cell:hover { transform: scale(1.05); z-index: 2; border-color: var(--text-muted); }
.heatmap-cell .cell-name { opacity: .9; }
.heatmap-cell .cell-signal {
  font-size: .58rem;
  font-weight: 700;
  opacity: .7;
  margin-top: 2px;
}

.heatmap-cell.hm-buy { background: var(--buy-soft); color: var(--buy); border-color: var(--buy-soft); }
.heatmap-cell.hm-sell { background: var(--sell-soft); color: var(--sell); border-color: var(--sell-soft); }
.heatmap-cell.hm-neutral { background: var(--neutral-soft); color: var(--neutral); }
.heatmap-cell.hm-watch { background: var(--watch-soft); color: var(--watch); border-color: var(--watch-soft); }

.heatmap-cell.hm-buy.hm-primary {
  background: linear-gradient(135deg, var(--buy-soft), var(--buy-glow));
  box-shadow: 0 0 12px var(--buy-glow);
}
.heatmap-cell.hm-sell.hm-primary {
  background: linear-gradient(135deg, var(--sell-soft), var(--sell-glow));
  box-shadow: 0 0 12px var(--sell-glow);
}

/* ── Signal Feed ──────────────────────────────────────────────────────── */
.signal-feed {
  display: grid;
  gap: 8px;
  max-height: 400px;
  overflow-y: auto;
}

.signal-feed-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  cursor: pointer;
  transition: all var(--transition);
  border-left: 3px solid transparent;
}
.signal-feed-item:hover { background: var(--bg-hover); }
.signal-feed-item.feed-buy { border-left-color: var(--buy); }
.signal-feed-item.feed-sell { border-left-color: var(--sell); }

.feed-badge {
  font-size: .65rem;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 4px;
  letter-spacing: .04em;
}
.feed-badge.badge-p1 { background: linear-gradient(135deg, var(--buy), #059669); color: #fff; }
.feed-badge.badge-p2 { background: var(--buy); color: #fff; }
.feed-badge.badge-p3 { background: var(--buy-soft); color: var(--buy); }
.feed-badge.badge-p4 { background: var(--sell); color: #fff; }
.feed-badge.badge-sell-p1 { background: linear-gradient(135deg, var(--sell), #b91c1c); color: #fff; }
.feed-badge.badge-sell-p2 { background: var(--sell); color: #fff; }
.feed-badge.badge-secondary { background: var(--neutral-soft); color: var(--text-secondary); }

.feed-info { flex: 1; min-width: 0; }
.feed-name { font-weight: 600; font-size: .85rem; }
.feed-detail { font-size: .72rem; color: var(--text-muted); margin-top: 2px; }
.feed-group { font-size: .65rem; color: var(--text-muted); padding: 2px 8px; background: var(--bg-hover); border-radius: 10px; }
.feed-empty { text-align: center; padding: 32px; color: var(--text-muted); font-size: .85rem; }

/* ── Signals Tab ──────────────────────────────────────────────────────── */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 16px;
  align-items: center;
}

.search-wrap {
  flex: 1;
  min-width: 200px;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  transition: border-color var(--transition);
  color: var(--text-muted);
}
.search-wrap:focus-within { border-color: var(--accent); }
.search-input {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text-primary);
  font-size: .85rem;
  outline: none;
}
.search-input::placeholder { color: var(--text-muted); }

.select-input {
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text-primary);
  font-size: .82rem;
  outline: none;
  cursor: pointer;
  transition: border-color var(--transition);
}
.select-input:focus { border-color: var(--accent); }

.filter-chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; }
.chip {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-secondary);
  padding: 5px 14px;
  border-radius: 20px;
  font-size: .72rem;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: all var(--transition);
}
.chip:hover { border-color: var(--accent); color: var(--accent); }
.chip.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.chip-buy.active { background: var(--buy); border-color: var(--buy); }
.chip-sell.active { background: var(--sell); border-color: var(--sell); }

/* ── Signal List (Signals Tab) ────────────────────────────────────────── */
.signal-list { display: grid; gap: 8px; }

.signal-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: all var(--transition);
}
.signal-row:hover { background: var(--bg-hover); border-color: var(--border-active); }

.signal-row-left { min-width: 0; }
.signal-row-name { font-weight: 600; font-size: .88rem; }
.signal-row-status { font-size: .72rem; color: var(--text-muted); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.signal-row-badges { display: flex; gap: 6px; flex-wrap: wrap; }
.signal-row-trend {
  font-size: .65rem;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 4px;
}
.trend-up { background: var(--buy-soft); color: var(--buy); }
.trend-down { background: var(--sell-soft); color: var(--sell); }
.trend-neutral { background: var(--neutral-soft); color: var(--neutral); }
.signal-row-empty { text-align: center; padding: 40px; color: var(--text-muted); }

/* ── Scanner Tab ──────────────────────────────────────────────────────── */
.scanner-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px;
}

.scanner-card {
  padding: 16px;
  border-radius: var(--radius);
  background: var(--bg-card);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: all var(--transition);
  position: relative;
  overflow: hidden;
}
.scanner-card:hover { transform: translateY(-2px); border-color: var(--border-active); box-shadow: var(--shadow); }

.scanner-top { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 10px; }
.scanner-name { font-weight: 700; font-size: .95rem; }
.scanner-group { font-size: .65rem; color: var(--text-muted); }

.scanner-price { font-size: 1.3rem; font-weight: 700; font-variant-numeric: tabular-nums; margin-bottom: 6px; }

.scanner-meta { display: flex; flex-wrap: wrap; gap: 6px; }
.scanner-tag {
  font-size: .62rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 4px;
}
.tag-up { background: var(--buy-soft); color: var(--buy); }
.tag-down { background: var(--sell-soft); color: var(--sell); }
.tag-neutral { background: var(--neutral-soft); color: var(--text-muted); }

.scanner-signal-strip {
  position: absolute;
  top: 0;
  right: 0;
  font-size: .6rem;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 0 0 0 var(--radius-sm);
}
.strip-buy { background: var(--buy); color: #fff; }
.strip-sell { background: var(--sell); color: #fff; }

.scanner-mini-bar {
  margin-top: 10px;
  height: 3px;
  border-radius: 2px;
  overflow: hidden;
}
.scanner-mini-bar-inner {
  height: 100%;
  border-radius: 2px;
  transition: width .6s ease;
}

.scanner-empty { grid-column: 1 / -1; text-align: center; padding: 40px; color: var(--text-muted); }

/* ── Watchlist Tab ────────────────────────────────────────────────────── */
.watchlist-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}
@media (min-width: 768px) { .watchlist-grid { grid-template-columns: 1fr 1fr; } }

.watchlist-items {
  display: grid;
  gap: 6px;
  max-height: 360px;
  overflow-y: auto;
}
.watchlist-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  cursor: pointer;
  transition: all var(--transition);
}
.watchlist-item:hover { background: var(--bg-hover); }
.watchlist-item-name { font-weight: 600; font-size: .82rem; flex: 1; }
.watchlist-item-detail { font-size: .7rem; color: var(--text-muted); max-width: 60%; text-align: right; }
.watchlist-empty { padding: 24px; text-align: center; color: var(--text-muted); font-size: .82rem; }

/* ── Modal ────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(0,0,0,.6);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: none;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
}
.modal-overlay.open { display: flex; animation: fadeIn .2s ease; }

@media (min-width: 768px) {
  .modal-overlay { align-items: center; padding: 24px; }
}

.modal {
  position: relative;
  width: 100%;
  max-width: 680px;
  max-height: 90vh;
  max-height: 90dvh;
  background: var(--bg-surface);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  overflow: hidden;
  animation: slideUp .35s cubic-bezier(.22,1,.36,1);
}
@media (min-width: 768px) {
  .modal { border-radius: var(--radius-lg); }
}

@keyframes slideUp { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }

.modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 2;
  width: 32px; height: 32px;
  border: none;
  border-radius: 50%;
  background: var(--bg-hover);
  color: var(--text-secondary);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: all var(--transition);
}
.modal-close:hover { background: var(--sell-soft); color: var(--sell); }

.modal-body {
  padding: 24px;
  overflow-y: auto;
  max-height: 90vh;
  max-height: 90dvh;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  padding-right: 36px;
}
.modal-title { font-size: 1.2rem; font-weight: 700; }
.modal-subtitle { font-size: .75rem; color: var(--text-muted); margin-top: 2px; }
.modal-signal-badge {
  font-size: .7rem;
  font-weight: 700;
  padding: 4px 12px;
  border-radius: 6px;
}

.modal-stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 20px;
}
.modal-stat {
  padding: 12px;
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  text-align: center;
}
.modal-stat-label { font-size: .65rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .06em; }
.modal-stat-value { font-size: 1.1rem; font-weight: 700; margin-top: 4px; }

.modal-section { margin-bottom: 16px; }
.modal-section-title { font-size: .75rem; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .06em; margin-bottom: 8px; display: flex; align-items: center; gap: 8px; }

.modal-chart-wrap { height: 260px; margin-bottom: 16px; border-radius: var(--radius-sm); overflow: hidden; background: var(--bg-elevated); padding: 12px; }
.modal-chart-wrap canvas { width: 100% !important; height: 100% !important; }

.modal-ma-ribbon {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.ma-pill {
  font-size: .62rem;
  font-weight: 500;
  padding: 3px 8px;
  border-radius: 4px;
  background: var(--bg-hover);
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}
.ma-pill.above { background: var(--buy-soft); color: var(--buy); }
.ma-pill.below { background: var(--sell-soft); color: var(--sell); }

.modal-levels {
  display: grid;
  gap: 4px;
  max-height: 160px;
  overflow-y: auto;
}
.level-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: .75rem;
  padding: 6px 8px;
  border-radius: 4px;
  background: var(--bg-hover);
}
.level-type {
  font-weight: 700;
  font-size: .6rem;
  padding: 2px 6px;
  border-radius: 3px;
  text-transform: uppercase;
}
.level-type.top { background: var(--sell-soft); color: var(--sell); }
.level-type.bottom { background: var(--buy-soft); color: var(--buy); }
.level-price { font-weight: 600; font-variant-numeric: tabular-nums; flex: 1; }
.level-touches { font-size: .65rem; color: var(--text-muted); }
.level-date { font-size: .65rem; color: var(--text-muted); }

/* ── TradingView Hero Card ────────────────────────────────────────────── */
.tv-hero-card {
  display: flex;
  position: relative;
  border-radius: var(--radius-lg);
  overflow: hidden;
  margin-bottom: 16px;
  text-decoration: none;
  color: #fff;
  min-height: 120px;
  transition: all var(--transition);
  cursor: pointer;
}
.tv-hero-card:hover { transform: translateY(-2px); box-shadow: 0 8px 32px rgba(26,115,232,.35); }
.tv-hero-card:active { transform: translateY(0); }

.tv-hero-bg {
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, #1a1a2e 0%, #16213e 30%, #0f3460 60%, #1a73e8 100%);
  z-index: 0;
}
.tv-hero-bg::after {
  content: '';
  position: absolute;
  top: -40%;
  right: -10%;
  width: 280px;
  height: 280px;
  background: radial-gradient(circle, rgba(26,115,232,.3), transparent 65%);
  pointer-events: none;
}

.tv-hero-content {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 20px 24px;
  gap: 16px;
}

.tv-hero-left { flex: 1; min-width: 0; }
.tv-hero-name { font-size: 1.3rem; font-weight: 800; letter-spacing: -.02em; }
.tv-hero-sub { font-size: .72rem; opacity: .6; margin-top: 2px; }
.tv-hero-price { font-size: 1.6rem; font-weight: 700; margin-top: 8px; font-variant-numeric: tabular-nums; }

.tv-hero-right { display: flex; flex-direction: column; align-items: flex-end; gap: 8px; flex-shrink: 0; }
.tv-hero-signal {
  font-size: .68rem;
  font-weight: 700;
  padding: 4px 12px;
  border-radius: 6px;
  color: #fff;
}
.tv-hero-cta {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  background: rgba(255,255,255,.15);
  backdrop-filter: blur(8px);
  font-size: .82rem;
  font-weight: 600;
  transition: background var(--transition);
  white-space: nowrap;
}
.tv-hero-card:hover .tv-hero-cta { background: rgba(255,255,255,.25); }
.tv-hero-hint { font-size: .62rem; opacity: .45; text-align: right; }

@media (max-width: 480px) {
  .tv-hero-content { flex-direction: column; align-items: flex-start; padding: 16px 18px; }
  .tv-hero-right { align-items: flex-start; flex-direction: row; flex-wrap: wrap; gap: 6px; }
  .tv-hero-hint { display: none; }
}

/* ── MA Ribbon Gauge ──────────────────────────────────────────────────── */
.ribbon-gauge { padding: 8px 0; }
.ribbon-gauge-track {
  height: 10px;
  border-radius: 5px;
  background: var(--border);
  overflow: hidden;
  position: relative;
}
.ribbon-gauge-fill {
  height: 100%;
  border-radius: 5px;
  transition: width .8s cubic-bezier(.4,0,.2,1);
  position: relative;
}
.ribbon-gauge-fill::after {
  content: '';
  position: absolute;
  right: 0;
  top: -3px;
  width: 4px;
  height: 16px;
  background: #fff;
  border-radius: 2px;
  box-shadow: 0 0 6px rgba(0,0,0,.3);
}
.ribbon-gauge-labels {
  display: flex;
  justify-content: space-between;
  margin-top: 6px;
  font-size: .62rem;
  font-weight: 500;
}

/* ── Signal Status Card ───────────────────────────────────────────────── */
.modal-status-card {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  border-left: 4px solid var(--neutral);
  background: var(--bg-elevated);
}
.modal-status-card.status-buy { border-left-color: var(--buy); background: var(--buy-soft); }
.modal-status-card.status-sell { border-left-color: var(--sell); background: var(--sell-soft); }
.modal-status-card.status-neutral { border-left-color: var(--neutral); }
.status-main { font-size: .82rem; color: var(--text-secondary); }
.status-sub { font-size: .72rem; color: var(--text-muted); margin-top: 4px; }

/* ── TradingView Integration ──────────────────────────────────────────── */

/* Inline TV icon link (small, appears next to instrument names) */
.tv-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--accent);
  text-decoration: none;
  padding: 3px 6px;
  border-radius: 4px;
  transition: all var(--transition);
  font-size: .68rem;
  font-weight: 600;
  flex-shrink: 0;
}
.tv-link:hover {
  background: var(--accent-glow);
  color: var(--accent);
  transform: scale(1.08);
}
.tv-link .tv-icon { flex-shrink: 0; }

/* Full-width TV button (in modal) */
.tv-btn-full {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, #1a73e8, #6c5ce7);
  color: #fff;
  font-size: .82rem;
  font-weight: 600;
  text-decoration: none;
  transition: all var(--transition);
  box-shadow: 0 4px 12px rgba(26,115,232,.3);
}
.tv-btn-full:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(26,115,232,.4);
}
.tv-btn-full:active { transform: translateY(0); }

.modal-tv-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

/* TradingView iframe chart in modal */
.modal-tv-chart-wrap {
  width: 100%;
  height: 380px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
}
.modal-tv-chart-wrap iframe {
  width: 100%;
  height: 100%;
  border: none;
}

/* Inline "Open full chart" link in section title */
.tv-link-inline {
  font-size: .68rem;
  color: var(--accent);
  text-decoration: none;
  font-weight: 500;
  text-transform: none;
  letter-spacing: 0;
  margin-left: auto;
  padding: 2px 8px;
  border-radius: 4px;
  transition: all var(--transition);
}
.tv-link-inline:hover { background: var(--accent-glow); }

/* Heatmap cell actions (TV + info buttons) */
.heatmap-cell-actions {
  position: absolute;
  top: 2px;
  right: 2px;
  display: flex;
  gap: 2px;
  opacity: 0;
  transition: opacity var(--transition);
  z-index: 1;
}
.heatmap-cell:hover .heatmap-cell-actions { opacity: 1; }
.hm-detail-btn {
  border: none;
  background: rgba(0,0,0,.3);
  color: #fff;
  width: 18px;
  height: 18px;
  border-radius: 3px;
  display: grid;
  place-items: center;
  cursor: pointer;
  font-size: .6rem;
  padding: 0;
}
.hm-detail-btn:hover { background: rgba(0,0,0,.5); }

.heatmap-cell .tv-link {
  padding: 1px 3px;
  font-size: .58rem;
}
.heatmap-cell .tv-link .tv-icon { width: 11px; height: 11px; }

/* Scanner card actions */
.scanner-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

/* Signal row TV link alignment */
.signal-row-name {
  display: flex;
  align-items: center;
  gap: 4px;
}
.signal-row-name .tv-link { padding: 2px 4px; }

/* Watchlist TV link */
.watchlist-item .tv-link { padding: 2px 4px; }

/* ── Loading States ───────────────────────────────────────────────────── */
.skeleton {
  background: linear-gradient(90deg, var(--bg-elevated) 25%, var(--bg-hover) 50%, var(--bg-elevated) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--radius-sm);
}
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* ── Utility Animations ───────────────────────────────────────────────── */
.count-up { transition: all .4s ease; }

@keyframes pop {
  0% { transform: scale(0.8); opacity: 0; }
  50% { transform: scale(1.05); }
  100% { transform: scale(1); opacity: 1; }
}
.pop-in { animation: pop .4s cubic-bezier(.22,1,.36,1) both; }

@keyframes glow-pulse {
  0%, 100% { box-shadow: 0 0 0 0 transparent; }
  50% { box-shadow: 0 0 20px var(--accent-glow); }
}

/* ── Empty States ─────────────────────────────────────────────────────── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 48px 24px;
  color: var(--text-muted);
  text-align: center;
}
.empty-state svg { margin-bottom: 12px; opacity: .4; }
