:root {
  --bg: #0d1117;
  --surface: #161b22;
  --surface2: #21262d;
  --border: #30363d;
  --text: #e6edf3;
  --text-muted: #8b949e;
  --green: #3fb950;
  --red: #f85149;
  --yellow: #d29922;
  --blue: #58a6ff;
  --purple: #bc8cff;
  --accent: #238636;
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  min-height: 100vh;
}

/* ── Header ── */
/* Sticky wrapper for header + timeline */
#top-fixed {
  position: sticky;
  top: 0;
  z-index: 100;
}

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  background: var(--surface);
  border-bottom: none;
}
.header h1 { font-size: 18px; font-weight: 600; letter-spacing: -0.3px; }
.header .meta { display: flex; align-items: center; gap: 16px; color: var(--text-muted); font-size: 13px; }
/* ── Status pill ── */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
}
.pill.active   { background: rgba(63,185,80,.15);  color: var(--green);  border: 1px solid rgba(63,185,80,.3);  }
.pill.running  { background: rgba(88,166,255,.15); color: var(--blue);   border: 1px solid rgba(88,166,255,.3); }
.pill.idle     { background: rgba(139,148,158,.1); color: var(--text-muted); border: 1px solid var(--border); }
.pill.error    { background: rgba(248,81,73,.15);  color: var(--red);    border: 1px solid rgba(248,81,73,.3);  }
.pill .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill.running .dot { animation: pulse 1s infinite; }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.3} }

/* ── Layout ── */
.main { padding: 24px; max-width: 1400px; margin: 0 auto; }

/* ── Scanner module card ── */
.scanner-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 24px;
  overflow: hidden;
}
.scanner-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface2);
  flex-wrap: wrap;
  gap: 10px;
}
.scanner-header h2 { font-size: 15px; font-weight: 600; }
.scanner-header .sub { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.scanner-meta { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.scanner-meta .last-scan { font-size: 12px; color: var(--text-muted); }

/* ── Trigger button ── */
.btn-scan {
  padding: 6px 14px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  transition: background .15s, border-color .15s;
}
.btn-scan:hover { background: var(--border); border-color: var(--blue); }
.btn-scan:disabled { opacity: 0.5; cursor: not-allowed; }

/* ── Filters bar ── */
.filters-bar {
  padding: 10px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  gap: 16px;
  font-size: 12px;
  color: var(--text-muted);
  background: rgba(0,0,0,.15);
  flex-wrap: wrap;
}
.filters-bar .filter-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 8px;
}

/* ── Table ── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
thead th {
  padding: 10px 14px;
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  background: var(--surface2);
  white-space: nowrap;
}
tbody tr { border-bottom: 1px solid rgba(48,54,61,.5); transition: background .1s; }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: rgba(255,255,255,.03); }
tbody td { padding: 10px 14px; font-size: 13px; white-space: nowrap; }

/* ── Cell badges ── */
.badge-green { color: var(--green); font-weight: 600; }
.badge-red   { color: var(--red);   font-weight: 600; }
.badge-yellow{ color: var(--yellow); font-weight: 600; }
.badge-muted { color: var(--text-muted); }

.tag {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
}
.tag-green  { background: rgba(63,185,80,.15);  color: var(--green);  }
.tag-red    { background: rgba(248,81,73,.15);  color: var(--red);    }
.tag-yellow { background: rgba(210,153,34,.15); color: var(--yellow); }
.tag-muted  { background: var(--surface2); color: var(--text-muted); }

/* ── Empty / loading states ── */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-muted);
}
.empty-state .icon { font-size: 32px; margin-bottom: 12px; }
.empty-state p { font-size: 14px; }

/* ── Ticker link ── */
.ticker-link {
  color: var(--blue);
  font-weight: 700;
  font-size: 14px;
  letter-spacing: .3px;
  cursor: pointer;
  user-select: none;
}
.ticker-link:hover { text-decoration: underline; }

/* Filter toggles */
.filter-toggle {
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 4px;
  color: rgba(255,255,255,0.4);
  font-size: 11px;
  padding: 4px 8px;
  cursor: pointer;
  transition: all 0.15s ease;
}
.filter-toggle:hover {
  background: rgba(255,255,255,0.08);
  border-color: rgba(255,255,255,0.25);
}
.filter-toggle.active {
  background: rgba(255,255,255,0.12);
  border-color: rgba(255,255,255,0.35);
  color: rgba(255,255,255,0.85);
}
.filter-tag.muted {
  opacity: 0.5;
}

.member-link {
  color: inherit;
  text-decoration: none;
  border-bottom: 1px dotted rgba(255,255,255,0.3);
}
.member-link:hover {
  border-bottom-color: rgba(255,255,255,0.8);
}

/* Lag badges */
.lag-fresh  { color: #34c759; font-size: 11px; font-weight: 600; }
.lag-normal { color: var(--text-muted); font-size: 11px; }
.lag-stale  { color: rgba(255,255,255,0.35); font-size: 11px; }
.lag-old    { color: rgba(255,255,255,0.2); font-size: 11px; }

/* Buy to Open row highlight */
tr.row-buy-to-open {
  background: rgba(52, 199, 89, 0.08);
  border-left: 2px solid #34c759;
}
tr.row-buy-to-open td:first-child {
  padding-left: 10px;
}

/* Current price still below trade-date high */
.price-below-high {
  color: #ffd60a;
}

/* ── Refresh bar ── */
.refresh-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 20px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-muted);
  background: rgba(0,0,0,.1);
}
.refresh-bar .countdown { font-variant-numeric: tabular-nums; }

/* ── Data Source Status Bar ── */
.datasource-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  z-index: 200;
  font-size: 12px;
}
.datasource-bar-inner {
  display: flex;
  align-items: center;
  gap: 0;
  padding: 0 16px;
  height: 36px;
  overflow-x: auto;
}
.ds-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 14px;
  height: 100%;
  border-right: 1px solid var(--border);
  cursor: pointer;
  transition: background .1s;
  white-space: nowrap;
}
.ds-item:hover { background: rgba(255,255,255,.04); }
.ds-item:first-child { border-left: 1px solid var(--border); }
.ds-dot {
  width: 8px; height: 8px; border-radius: 50%;
  flex-shrink: 0;
}
.ds-dot.online  { background: var(--green); box-shadow: 0 0 6px var(--green); }
.ds-dot.offline { background: var(--red); }
.ds-dot.error   { background: var(--yellow); }
.ds-dot.checking{ background: var(--text-muted); animation: pulse 1s infinite; }
.ds-label { color: var(--text-muted); }
.ds-checked { margin-left: auto; color: var(--text-muted); padding: 0 14px; font-size: 11px; }

/* Tooltip card */
.ds-tooltip {
  position: absolute;
  bottom: 44px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 14px;
  font-size: 12px;
  min-width: 220px;
  box-shadow: 0 4px 16px rgba(0,0,0,.4);
  pointer-events: none;
  z-index: 300;
}
.ds-tooltip .ds-tooltip-title { font-weight: 600; margin-bottom: 4px; }
.ds-tooltip .ds-tooltip-detail { color: var(--text-muted); }

/* Bottom padding so page content isn't hidden behind bar */
body { padding-bottom: 44px; }

/* ── Daily Timeline ──────────────────────────────────────────────────────── */
#tl-wrap {
  background: var(--surface);
  border-bottom: 2px solid var(--border);
}

#tl-container {
  position: relative;
  height: 72px;
  padding: 0 2px;
  overflow: visible;
}

/* Colored zone strip */
#tl-zone-bar {
  position: absolute;
  top: 20px;
  left: 0; right: 0;
  height: 10px;
  overflow: hidden;
  border-radius: 2px;
}

/* Notch + label layer */
#tl-notch-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

/* Event dot layer (above zone bar) */
#tl-event-layer {
  position: absolute;
  top: 4px;
  left: 0; right: 0;
  height: 16px;
  overflow: visible;
  pointer-events: none;
}

/* Current-time cursor */
#tl-cursor {
  position: absolute;
  top: 14px;
  width: 2px;
  height: 34px;
  background: rgba(255,255,255,0.85);
  border-radius: 1px;
  transform: translateX(-50%);
  z-index: 10;
  box-shadow: 0 0 8px rgba(255,255,255,0.5);
  pointer-events: none;
}
#tl-cursor-time {
  position: absolute;
  bottom: 100%;
  margin-bottom: 2px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 10px;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  background: var(--surface);
  padding: 1px 4px;
  border-radius: 3px;
  border: 1px solid var(--border);
}

/* Notch marks */
.tl-notch {
  position: absolute;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  top: 30px;
  pointer-events: none;
}
.tl-notch-tick {
  width: 1px;
  height: 5px;
  background: rgba(255,255,255,0.25);
  flex-shrink: 0;
}
.tl-notch-label {
  font-size: 11px;
  font-weight: 500;
  text-align: center;
  line-height: 1.25;
  margin-top: 2px;
  white-space: nowrap;
  color: var(--text-muted);
}
.tl-notch-label.now { color: var(--text); }
.tl-notch-sub {
  font-size: 9px;
  color: var(--text-muted);
  opacity: 0.75;
}

/* Event markers */
.tl-ev {
  position: absolute;
  transform: translateX(-50%);
  top: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  pointer-events: all;
  cursor: default;
  z-index: 5;
}
.tl-ev-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}
.tl-ev.upcoming .tl-ev-dot { background: var(--yellow); box-shadow: 0 0 5px var(--yellow); }
.tl-ev.past     .tl-ev-dot { background: var(--text-muted); opacity: 0.5; }
.tl-ev.active   .tl-ev-dot { background: var(--red); box-shadow: 0 0 6px var(--red); animation: pulse 1s infinite; }

/* Fixed-position tooltip for timeline event blips (avoids sticky header clipping) */
.tl-ev-tip-fixed {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 6px 10px;
  font-size: 11px;
  white-space: nowrap;
  box-shadow: 0 4px 12px rgba(0,0,0,0.4);
  pointer-events: none;
  min-width: 140px;
  text-align: center;
}
.tl-ev-tip-title { font-weight: 600; color: var(--text); }
.tl-ev-tip-time  { color: var(--text-muted); margin-top: 2px; }
.tl-ev-tip-meta  { color: var(--yellow); margin-top: 2px; font-size: 10px; }

/* Event banner */
.tl-banner-hidden { display: none; }
#tl-banner {
  padding: 5px 20px;
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  border-bottom: 1px solid var(--border);
  min-height: 28px;
}
#tl-banner.urgent {
  background: rgba(210,153,34,0.12);
  border-bottom-color: rgba(210,153,34,0.4);
}
#tl-banner.info {
  background: rgba(88,166,255,0.04);
  border-bottom-color: rgba(88,166,255,0.15);
}
#tl-banner.past-only {
  background: transparent;
  border-bottom-color: rgba(255,255,255,0.05);
}
.tl-b-icon { font-size: 13px; }
.tl-b-title { font-weight: 600; color: var(--text); }
.tl-b-time  { color: var(--yellow); font-weight: 600; }
.tl-b-est   { color: var(--text-muted); }
.tl-b-sep   { color: var(--border); margin: 0 4px; }
.tl-b-upcoming { color: var(--text); }
.tl-b-upcoming em { color: var(--text-muted); font-style: normal; }
.tl-b-past  { color: var(--text-muted); font-style: italic; }

/* ── Collapse button ─────────────────────────────────────────── */
.btn-collapse {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 4px;
  padding: 4px 8px;
  font-size: 11px;
  cursor: pointer;
  transition: color .15s, border-color .15s;
  line-height: 1;
}
.btn-collapse:hover { color: var(--text); border-color: var(--text-muted); }
.scanner-card.collapsed .btn-collapse { transform: rotate(-90deg); }
.scanner-body {
  transition: none;
}
.scanner-card.collapsed .scanner-body { display: none; }

/* ── Timeline scroll-hide ────────────────────────────────────── */
#tl-wrap {
  overflow: hidden;
  transition: max-height 0.25s ease, opacity 0.25s ease;
  max-height: 200px;
  opacity: 1;
}
#tl-wrap.tl-hidden {
  max-height: 0;
  opacity: 0;
}

/* ── Strategy 2 ─────────────────────────────────────────────── */
.s2-section-label {
  padding: 10px 20px 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .05em;
  border-top: 1px solid var(--border);
}
.badge-red   { background: rgba(248,81,73,.15); color: var(--red);    padding: 2px 7px; border-radius: 4px; font-size: 12px; font-weight: 600; }
.tag.tag-red { background: rgba(248,81,73,.15); color: var(--red);    padding: 2px 7px; border-radius: 4px; font-size: 12px; }

/* -- Strategy 5 ------------------------------------------------------------ */
.s5-signal-banner {
  display: flex;
  align-items: center;
  gap: 16px;
  margin: 16px 20px;
  padding: 16px 20px;
  border-radius: 10px;
  border: 1px solid var(--border);
}
.s5-long   { background: rgba(52,199,89,.1);  border-color: rgba(52,199,89,.35); }
.s5-short  { background: rgba(255,69,58,.1);  border-color: rgba(255,69,58,.35); }
.s5-neutral{ background: rgba(255,255,255,.04); }
.s5-signal-icon { font-size: 2rem; }
.s5-signal-text { font-size: 1.1rem; font-weight: 600; color: var(--text); }
.s5-signal-sub  { font-size: 12px; color: var(--text-muted); margin-top: 3px; }

.s5-metrics {
  display: flex;
  flex-wrap: wrap;
  gap: 1px;
  margin: 0 20px 16px;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}
.s5-metric {
  flex: 1 1 120px;
  padding: 12px 14px;
  background: var(--surface);
}
.s5-metric-label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; margin-bottom: 4px; }
.s5-metric-value { font-size: 1.05rem; font-weight: 600; color: var(--text); font-family: monospace; }
.s5-above { color: var(--green) !important; }
.s5-below { color: var(--red)   !important; }

.s5-chart-wrap {
  margin: 0 20px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  padding: 8px 4px 0;
  min-height: 140px;
}
#s5-chart { display: block; width: 100%; }

/* -- Chart Hover Popup ------------------------------------------------------- */
#chart-popup {
  position: absolute;
  z-index: 9999;
  background: #0d1117;
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.7);
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease;
}
#chart-popup.visible {
  opacity: 1;
  pointer-events: all;
}
.cp-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.cp-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: .04em;
}
.cp-intervals {
  font-size: 11px;
  color: var(--text-muted);
}
.cp-charts {
  display: flex;
  height: 280px;
}
.cp-chart {
  flex: 1;
  position: relative;
  border-right: 1px solid var(--border);
  overflow: hidden;
}
.cp-chart:last-child { border-right: none; }
.cp-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  font-size: 12px;
  color: var(--text-muted);
}
.tradingview-widget-container,
.tradingview-widget-container__widget {
  width: 100% !important;
  height: 100% !important;
}
