/* US Top 50 Scanner — Mobile-first dark UI */

:root {
  --bg: #0a0e17;
  --surface: #111827;
  --surface2: #1a2234;
  --border: #1e2a3a;
  --text: #e5e7eb;
  --text-dim: #6b7280;
  --green: #00e676;
  --red: #ff1744;
  --blue: #2196f3;
  --yellow: #ffc107;
  --radius: 12px;
  --font: system-ui, -apple-system, 'Segoe UI', sans-serif;
}

*, *::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: 100dvh;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

/* Sticky header */
.header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 12px 16px 8px;
}
.header__top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.header__title {
  font-size: 1.1rem;
  font-weight: 700;
  white-space: nowrap;
}
.header__session {
  font-size: 0.75rem;
  color: var(--text-dim);
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--surface2);
}
.header__refresh {
  background: none;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 0.8rem;
  cursor: pointer;
  white-space: nowrap;
}
.header__refresh:active { background: var(--surface2); }
.header__info-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 6px;
  flex-wrap: wrap;
}
.header__info-bar > span {
  font-size: 0.62rem;
  color: var(--text-dim);
  padding: 2px 7px;
  border-radius: 4px;
  background: var(--surface2);
  white-space: nowrap;
}
.header__source { border-left: 2px solid var(--blue); }
.header__rate { border-left: 2px solid var(--green); }
.header__next { border-left: 2px solid var(--yellow); }
.header__updated { border-left: 2px solid var(--text-dim); }

/* Search */
.search-bar {
  margin: 8px 16px 0;
  position: sticky;
  top: 70px;
  z-index: 99;
}
.search-bar input {
  width: 100%;
  padding: 10px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.9rem;
  outline: none;
}
.search-bar input:focus { border-color: var(--blue); }
.search-bar input::placeholder { color: var(--text-dim); }

/* Stock Position List */
.position-list {
  margin: 8px 12px 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.position-list__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  cursor: pointer;
  user-select: none;
}
.position-list__title {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text);
}
.position-list__count {
  font-size: 0.7rem;
  color: var(--text-dim);
  background: var(--surface2);
  padding: 2px 8px;
  border-radius: 999px;
}
.position-list__arrow {
  font-size: 0.7rem;
  color: var(--text-dim);
  transition: transform 0.2s;
}
.position-list__body {
  display: none;
  padding: 0 10px 10px;
}
.position-list__body.open { display: block; }
.position-list__body.open ~ .position-list__header .position-list__arrow,
.position-list.expanded .position-list__arrow { transform: rotate(0deg); }
.position-list:not(.expanded) .position-list__arrow { transform: rotate(-90deg); }
.position-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}
.pos-chip {
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 0.7rem;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
  transition: all 0.15s;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text-dim);
}
.pos-chip.in-scan {
  color: var(--text);
  border-color: rgba(0,230,118,0.3);
}
.pos-chip.in-scan.up {
  border-color: var(--green);
  color: var(--green);
}
.pos-chip.in-scan.down {
  border-color: var(--red);
  color: var(--red);
}
.pos-chip.not-in-scan {
  opacity: 0.45;
}
.pos-chip.selected {
  background: var(--blue);
  border-color: var(--blue);
  color: #fff;
  opacity: 1;
}
.pos-chip .pos-price {
  font-weight: 400;
  font-size: 0.6rem;
  margin-left: 3px;
  opacity: 0.7;
}
.pos-chip .pos-change {
  font-size: 0.6rem;
  margin-left: 2px;
}

/* Filter chips */
.chips {
  display: flex;
  gap: 6px;
  padding: 10px 16px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex-shrink: 0;
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 0.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-dim);
  cursor: pointer;
  user-select: none;
  transition: all 0.15s;
}
.chip.active {
  background: var(--blue);
  border-color: var(--blue);
  color: #fff;
}
.chip[data-filter="watchlist"] {
  border-color: var(--yellow);
  color: var(--yellow);
}
.chip[data-filter="watchlist"].active {
  background: var(--yellow);
  border-color: var(--yellow);
  color: #000;
}

/* Settings bar */
.settings-bar {
  display: flex;
  justify-content: flex-end;
  padding: 0 16px 6px;
}
.settings-bar label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.7rem;
  color: var(--text-dim);
  cursor: pointer;
}

/* Card grid */
.card-list {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  padding: 0 12px 80px;
}
@media (min-width: 640px) {
  .card-list { grid-template-columns: 1fr 1fr; gap: 12px; padding: 0 16px 80px; }
}

/* Card */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: box-shadow 0.3s;
}
.card.glow-green { box-shadow: 0 0 12px rgba(0,230,118,0.25); }
.card.glow-red { box-shadow: 0 0 12px rgba(255,23,68,0.25); }

/* Blink animation */
@keyframes blink-green {
  0%, 100% { box-shadow: 0 0 4px rgba(0,230,118,0.1); }
  50% { box-shadow: 0 0 16px rgba(0,230,118,0.4); }
}
@keyframes blink-red {
  0%, 100% { box-shadow: 0 0 4px rgba(255,23,68,0.1); }
  50% { box-shadow: 0 0 16px rgba(255,23,68,0.4); }
}
.card.blink-up-fast { animation: blink-green 0.6s infinite; }
.card.blink-up-slow { animation: blink-green 2s infinite; }
.card.blink-down-fast { animation: blink-red 0.6s infinite; }
.card.blink-down-slow { animation: blink-red 2s infinite; }

@media (prefers-reduced-motion: reduce) {
  .card.blink-up-fast, .card.blink-up-slow,
  .card.blink-down-fast, .card.blink-down-slow { animation: none; }
  .card.blink-up-fast, .card.blink-up-slow { box-shadow: 0 0 8px rgba(0,230,118,0.3); }
  .card.blink-down-fast, .card.blink-down-slow { box-shadow: 0 0 8px rgba(255,23,68,0.3); }
}
/* User toggle for reduced motion */
body.reduce-motion .card { animation: none !important; }
body.reduce-motion .card.blink-up-fast, body.reduce-motion .card.blink-up-slow { box-shadow: 0 0 8px rgba(0,230,118,0.3); }
body.reduce-motion .card.blink-down-fast, body.reduce-motion .card.blink-down-slow { box-shadow: 0 0 8px rgba(255,23,68,0.3); }

/* Card header */
.card__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px 6px;
}
.card__symbol {
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}
.card__badge {
  font-size: 0.65rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  text-transform: uppercase;
}
.card__badge.up { background: rgba(0,230,118,0.15); color: var(--green); }
.card__badge.down { background: rgba(255,23,68,0.15); color: var(--red); }
.card__badge.neutral { background: rgba(255,255,255,0.08); color: var(--text-dim); }
.card__name {
  font-size: 0.7rem;
  color: var(--text-dim);
  padding: 0 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Metrics row */
.card__metrics {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 2px;
  padding: 8px 12px;
}
.metric {
  text-align: center;
}
.metric__label {
  font-size: 0.6rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.metric__value {
  font-size: 0.85rem;
  font-weight: 600;
}
.metric__value.positive { color: var(--green); }
.metric__value.negative { color: var(--red); }

/* Mini analytics */
.card__analytics-mini {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 2px;
  padding: 4px 12px 6px;
  border-top: 1px solid var(--border);
}

/* BOLL & S/R rows */
.card__data-row {
  display: flex;
  justify-content: space-between;
  padding: 4px 12px;
  border-top: 1px solid var(--border);
  font-size: 0.7rem;
}
.card__data-row .label { color: var(--text-dim); }
.card__data-row .values { display: flex; gap: 8px; }
.card__data-row .val-green { color: var(--green); }
.card__data-row .val-red { color: var(--red); }
.card__data-row .val-blue { color: var(--blue); }

/* Reasons */
.card__reasons {
  padding: 4px 12px 6px;
  font-size: 0.65rem;
  color: var(--yellow);
  border-top: 1px solid var(--border);
}

/* Toggle buttons */
.card__toggles {
  display: flex;
  border-top: 1px solid var(--border);
}
.card__toggle-btn {
  flex: 1;
  padding: 8px;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 0.75rem;
  cursor: pointer;
  border-right: 1px solid var(--border);
  transition: color 0.15s, background 0.15s;
}
.card__toggle-btn:last-child { border-right: none; }
.card__toggle-btn:active { background: var(--surface2); }
.card__toggle-btn.active { color: var(--blue); background: rgba(33,150,243,0.08); }

/* Expanded chart */
.card__chart-area {
  display: none;
  border-top: 1px solid var(--border);
}
.card__chart-area.open { display: block; }
.tf-tabs {
  display: flex;
  align-items: center;
  padding: 6px 12px;
  gap: 6px;
  overflow: hidden;
}
.tf-tab {
  padding: 4px 14px;
  border-radius: 6px;
  font-size: 0.75rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text-dim);
  cursor: pointer;
}
.tf-tab.active { background: var(--blue); border-color: var(--blue); color: #fff; }
.chart-container {
  width: 100%;
  height: 320px;
  padding: 0 4px 8px;
}

/* Indicator toggle pills */
.chart-indicator-toggles {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 4px 12px 6px;
  align-items: center;
}
.ind-pill {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.62rem;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text-dim);
  transition: all 0.15s;
}
.ind-pill input { display: none; }
.ind-pill:has(input:checked) {
  background: rgba(33,150,243,0.15);
  border-color: var(--blue);
  color: var(--blue);
}
.ind-sep {
  width: 1px;
  height: 16px;
  background: var(--border);
  margin: 0 2px;
}

/* Sub-chart panes */
.sub-charts-area {
  padding: 0 4px;
}
.sub-chart-wrap {
  position: relative;
  margin-top: 2px;
}
.sub-chart-label {
  position: absolute;
  top: 2px;
  left: 8px;
  z-index: 2;
  font-size: 0.58rem;
  font-weight: 600;
  color: var(--text-dim);
  background: rgba(15,19,24,0.7);
  padding: 1px 6px;
  border-radius: 3px;
  pointer-events: none;
}

/* Expanded analytics with insights */
.card__analytics-full {
  display: none;
  padding: 10px 12px;
  border-top: 1px solid var(--border);
  font-size: 0.78rem;
}
.card__analytics-full.open { display: block; }

.analytics-insights { display: flex; flex-direction: column; gap: 2px; }

.ai-section-title {
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--blue);
  margin-top: 10px;
  padding-bottom: 3px;
  border-bottom: 1px solid rgba(33,150,243,0.2);
}
.ai-section-title:first-child { margin-top: 0; }

.ai-row {
  padding: 5px 0;
  border-bottom: 1px solid var(--border);
}
.ai-header {
  display: flex;
  align-items: center;
  gap: 8px;
}
.ai-header .a-label {
  color: var(--text-dim);
  font-size: 0.72rem;
  min-width: 85px;
  flex-shrink: 0;
}
.ai-value {
  font-weight: 600;
  font-size: 0.8rem;
  min-width: 60px;
}
.ai-signal {
  font-size: 0.62rem;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin-left: auto;
  white-space: nowrap;
}
.ai-signal.positive { background: rgba(0,230,118,0.12); color: var(--green); }
.ai-signal.negative { background: rgba(255,23,68,0.12); color: var(--red); }
.ai-signal:not(.positive):not(.negative) { background: rgba(255,255,255,0.06); color: var(--text-dim); }

.ai-guide {
  font-size: 0.65rem;
  color: var(--text-dim);
  margin-top: 3px;
  line-height: 1.4;
  padding-left: 2px;
  opacity: 0.85;
}

.ai-rank-bar {
  height: 6px;
  background: var(--surface2);
  border-radius: 3px;
  margin-top: 6px;
  overflow: hidden;
}
.ai-rank-fill {
  height: 100%;
  border-radius: 3px;
  background: linear-gradient(90deg, var(--red) 0%, var(--yellow) 40%, var(--green) 80%);
  transition: width 0.3s;
}

/* Scrolling news ticker (beside 1H / 4H tabs) */
.news-ticker {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  position: relative;
  height: 22px;
  margin-left: 4px;
  mask-image: linear-gradient(90deg, transparent, #000 5%, #000 95%, transparent);
  -webkit-mask-image: linear-gradient(90deg, transparent, #000 5%, #000 95%, transparent);
}
.news-ticker .ticker-empty {
  font-size: 0.65rem;
  color: var(--text-dim);
  line-height: 22px;
}
.news-ticker.scrolling .ticker-track {
  display: inline-flex;
  align-items: center;
  white-space: nowrap;
  gap: 10px;
  animation: tickerScroll 20s linear infinite;
}
.ticker-item {
  font-size: 0.65rem;
  line-height: 22px;
  white-space: nowrap;
}
.ticker-icon {
  margin-right: 3px;
  font-size: 0.5rem;
  vertical-align: middle;
}
.ticker-date {
  color: var(--text-dim);
  margin-right: 4px;
  font-size: 0.6rem;
}
.ticker-cat {
  font-size: 0.58rem;
  padding: 1px 5px;
  border-radius: 3px;
  margin-right: 4px;
  vertical-align: middle;
}
.cat-catalyst .ticker-icon { color: var(--yellow); }
.cat-news .ticker-icon { color: var(--blue); }
.cat-catalyst .ticker-cat { background: rgba(255,193,7,0.15); color: var(--yellow); }
.cat-news .ticker-cat { background: rgba(33,150,243,0.15); color: var(--blue); }
.sent-pos { color: var(--green); }
.sent-neg { color: var(--red); }
.sent-neu { color: var(--text-dim); }
.ticker-sep {
  color: var(--text-dim);
  font-size: 0.6rem;
  opacity: 0.3;
}
@keyframes tickerScroll {
  0%   { transform: translateX(0); }
  100% { transform: translateX(-50%); }  /* -50% because content is duplicated */
}

/* Status banner */
.status-banner {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-dim);
}
.status-banner .spinner {
  display: inline-block;
  width: 24px;
  height: 24px;
  border: 2px solid var(--border);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Offline banner */
.offline-banner {
  display: none;
  background: var(--yellow);
  color: #000;
  text-align: center;
  padding: 6px;
  font-size: 0.75rem;
  font-weight: 600;
}
body.offline .offline-banner { display: block; }

/* Bollinger alert banner on card */
.card__boll-alert {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  font-size: 0.7rem;
  font-weight: 600;
  border-top: 1px solid var(--border);
}
.card__boll-alert .boll-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.card__boll-alert.alert-near_upper,
.card__boll-alert.alert-above_upper {
  background: rgba(255,23,68,0.1);
  color: var(--red);
}
.card__boll-alert.alert-near_upper .boll-dot,
.card__boll-alert.alert-above_upper .boll-dot { background: var(--red); }
.card__boll-alert.alert-near_lower,
.card__boll-alert.alert-below_lower {
  background: rgba(0,230,118,0.1);
  color: var(--green);
}
.card__boll-alert.alert-near_lower .boll-dot,
.card__boll-alert.alert-below_lower .boll-dot { background: var(--green); }
.card__boll-alert.alert-near_mid {
  background: rgba(33,150,243,0.08);
  color: var(--blue);
}
.card__boll-alert.alert-near_mid .boll-dot { background: var(--blue); }

/* Pulsing dot for active alerts */
@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(1.4); }
}
.card__boll-alert .boll-dot { animation: pulse-dot 1.5s infinite; }
@media (prefers-reduced-motion: reduce) {
  .card__boll-alert .boll-dot { animation: none; }
}
body.reduce-motion .card__boll-alert .boll-dot { animation: none !important; }

/* Watchlist reason banner */
.watchlist-reasons {
  padding: 5px 12px;
  font-size: 0.68rem;
  background: rgba(255,193,7,0.08);
  border-top: 1px solid rgba(255,193,7,0.2);
  color: var(--yellow);
  line-height: 1.4;
}
.watchlist-reasons .wl-icon {
  margin-right: 4px;
  font-size: 0.7rem;
}

/* Prediction / Recommendation section */
.card__prediction-1d {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 5px 12px;
  border-top: 1px solid var(--border);
  font-size: 0.7rem;
}
.card__prediction-1d .pred-label { color: var(--text-dim); }
.rec-badge {
  padding: 2px 10px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 0.65rem;
  text-transform: uppercase;
}
.rec-badge.strong-buy { background: rgba(0,230,118,0.2); color: var(--green); }
.rec-badge.buy { background: rgba(0,230,118,0.12); color: #66ffa6; }
.rec-badge.hold { background: rgba(255,193,7,0.15); color: var(--yellow); }
.rec-badge.sell { background: rgba(255,23,68,0.12); color: #ff6e7a; }
.rec-badge.strong-sell { background: rgba(255,23,68,0.2); color: var(--red); }

/* Predictions panel (expanded) */
.card__predictions {
  display: none;
  border-top: 1px solid var(--border);
  padding: 10px 12px;
}
.card__predictions.open { display: block; }
.pred-table {
  width: 100%;
  font-size: 0.72rem;
  border-collapse: collapse;
}
.pred-table th {
  text-align: left;
  color: var(--text-dim);
  font-weight: 500;
  padding: 4px 4px;
  border-bottom: 1px solid var(--border);
  font-size: 0.6rem;
  text-transform: uppercase;
}
.pred-table td {
  padding: 5px 4px;
  border-bottom: 1px solid var(--border);
}
.pred-table tr:last-child td { border-bottom: none; }
.pred-range {
  font-size: 0.6rem;
  color: var(--text-dim);
}
.pred-conf {
  display: inline-block;
  width: 36px;
  height: 4px;
  border-radius: 2px;
  background: var(--surface2);
  position: relative;
  vertical-align: middle;
}
.pred-conf-fill {
  position: absolute;
  left: 0; top: 0; bottom: 0;
  border-radius: 2px;
  background: var(--blue);
}
.pred-rationale {
  font-size: 0.6rem;
  color: var(--text-dim);
  padding: 6px 0 2px;
  line-height: 1.4;
  font-style: italic;
}

/* Legend panel */
.card__legend {
  display: none;
  border-top: 1px solid var(--border);
  padding: 10px 12px;
}
.card__legend.open { display: block; }
.legend-item {
  padding: 5px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.72rem;
  line-height: 1.45;
}
.legend-item:last-child { border-bottom: none; }
.legend-term {
  font-weight: 700;
  color: var(--blue);
}
.legend-def {
  color: var(--text-dim);
}

/* Header legend toggle */
.header__legend-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 4px 10px;
  border-radius: 8px;
  font-size: 0.7rem;
  cursor: pointer;
  white-space: nowrap;
}
.header__legend-btn:active { background: var(--surface2); }
.header__legend-btn.active { color: var(--blue); border-color: var(--blue); }

/* Scrollbar */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
