/* ═══════════════════════════════════════════════
   CSS VARIABLES — dark fintech palette
═══════════════════════════════════════════════ */
:root {
  --bg:       #0b0e14;
  --surface:  #131824;
  --surface2: #1b2130;
  --border:   #242c3a;
  --text:     #e6edf3;
  --muted:    #8b95a5;
  --up:       #3fb950;
  --down:     #f85149;
  --accent:   #2f81f7;
  --amber:    #d29922;

  /* score band backgrounds (dark-appropriate, not neon) */
  --score-red:    rgba(248, 81,  73,  0.20);
  --score-amber:  rgba(210, 153, 34,  0.22);
  --score-green1: rgba(63,  185, 80,  0.18);
  --score-green2: rgba(63,  185, 80,  0.32);

  --mono: ui-monospace, "SF Mono", Menlo, "Cascadia Mono", monospace;
  --sans: system-ui, -apple-system, "Segoe UI", sans-serif;

  --radius-sm: 4px;
  --radius:    8px;
  --radius-lg: 12px;

  --panel-w: 340px;
  --strip-h: 56px;
}

/* ═══════════════════════════════════════════════
   RESET / BASE
═══════════════════════════════════════════════ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  font-size: 14px;
  -webkit-text-size-adjust: 100%;
}

body {
  direction: rtl;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  min-height: 100dvh;
  line-height: 1.5;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font-family: inherit; }

/* ═══════════════════════════════════════════════
   HEADER
═══════════════════════════════════════════════ */
.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

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

.brand-icon { font-size: 1.25rem; }

.brand-name {
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
}

.brand-sub {
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--muted);
  padding: 2px 7px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.header-meta {
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--muted);
}

/* ═══════════════════════════════════════════════
   DAY STRIP
═══════════════════════════════════════════════ */
.day-strip {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  height: var(--strip-h);
  display: flex;
  align-items: center;
  overflow: hidden;
}

.day-strip-inner {
  display: flex;
  gap: 6px;
  padding: 0 16px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  height: 100%;
  align-items: center;
  /* RTL: newest chip is visually first (rightmost) */
}

.day-strip-inner::-webkit-scrollbar { display: none; }

.day-chip {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 5px 11px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  transition: background 0.15s, border-color 0.15s;
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--muted);
  min-width: 64px;
  text-align: center;
}

.day-chip:hover {
  background: var(--surface2);
  border-color: var(--accent);
  color: var(--text);
}

.day-chip[aria-selected="true"] {
  background: rgba(47, 129, 247, 0.15);
  border-color: var(--accent);
  color: var(--accent);
}

.day-chip-date { font-weight: 600; font-size: 0.75rem; }

.day-chip-meta {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.68rem;
  color: var(--muted);
}

.day-chip[aria-selected="true"] .day-chip-meta { color: var(--accent); opacity: 0.8; }

.day-chip-70 {
  background: rgba(63, 185, 80, 0.22);
  color: var(--up);
  padding: 1px 4px;
  border-radius: 3px;
  font-size: 0.65rem;
  font-weight: 700;
}

/* ═══════════════════════════════════════════════
   MAIN LAYOUT
═══════════════════════════════════════════════ */
main {
  max-width: 1440px;
  margin: 0 auto;
  padding: 16px 20px 80px;
}

/* ═══════════════════════════════════════════════
   SUMMARY SECTION (cards + chart side by side)
═══════════════════════════════════════════════ */
.summary-section {
  display: grid;
  grid-template-columns: 1fr 280px;
  gap: 14px;
  margin-bottom: 16px;
  align-items: start;
}

.summary-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
  gap: 8px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.stat-card-val {
  font-family: var(--mono);
  font-size: 1.5rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  color: var(--text);
}

.stat-card-lbl {
  font-size: 0.72rem;
  color: var(--muted);
  white-space: nowrap;
}

.stat-card--highlight .stat-card-val { color: var(--up); }
.stat-card--accent .stat-card-val    { color: var(--accent); }

/* chart */
.chart-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
}

.chart-title {
  font-size: 0.72rem;
  color: var(--muted);
  margin-bottom: 8px;
  font-family: var(--mono);
}

/* ═══════════════════════════════════════════════
   CONTROLS
═══════════════════════════════════════════════ */
.controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.ctrl-input,
.ctrl-select {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 7px 10px;
  font-family: var(--sans);
  font-size: 0.85rem;
  outline: none;
  transition: border-color 0.15s;
  min-height: 36px;
}

.ctrl-input { min-width: 160px; }
.ctrl-select { min-width: 130px; }

.ctrl-input:focus,
.ctrl-select:focus { border-color: var(--accent); }

.ctrl-select option { background: var(--surface2); }

.ctrl-checkbox {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--muted);
  min-height: 36px;
  user-select: none;
}

.ctrl-checkbox input { accent-color: var(--accent); width: 15px; height: 15px; cursor: pointer; }
.ctrl-checkbox:hover { color: var(--text); }

.ctrl-count {
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--muted);
  margin-inline-start: auto;
}

/* ═══════════════════════════════════════════════
   TABLE (desktop)
═══════════════════════════════════════════════ */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  -webkit-overflow-scrolling: touch;
}

#grid {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.82rem;
  min-width: 860px;
}

#grid thead th {
  background: var(--surface2);
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 9px 10px;
  text-align: center;
  cursor: pointer;
  position: sticky;
  top: 0;
  z-index: 10;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  user-select: none;
  transition: color 0.12s;
}

#grid thead th:hover { color: var(--text); }
#grid thead th[aria-sort] { color: var(--accent); }

#grid tbody tr {
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.1s;
}

#grid tbody tr:last-child { border-bottom: none; }

#grid tbody tr:hover { background: var(--surface2); }

/* confluence accent */
#grid tbody tr[data-conf="true"] {
  border-inline-start: 3px solid var(--accent);
}

#grid tbody td {
  padding: 7px 10px;
  text-align: center;
  vertical-align: middle;
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

/* non-number columns */
td.col-ticker {
  font-weight: 700;
  font-size: 0.88rem;
  color: var(--text);
  letter-spacing: 0.02em;
  white-space: nowrap;
}

td.col-region,
td.col-sector {
  font-family: var(--sans);
  font-size: 0.80rem;
  color: var(--muted);
}

td.col-signals { text-align: start; white-space: nowrap; }

/* ═══════════════════════════════════════════════
   SIGNAL BADGES
═══════════════════════════════════════════════ */
.badges {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 4px;
  align-items: center;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 2px 7px;
  border-radius: 20px;
  font-family: var(--sans);
  font-size: 0.68rem;
  font-weight: 600;
  white-space: nowrap;
  border: 1px solid transparent;
}

/* primary badge = slightly larger */
.badge--primary {
  font-size: 0.73rem;
  padding: 3px 9px;
}

/* by signal type */
.badge--breakout    { background: rgba(63, 185, 80, 0.18); color: var(--up);     border-color: rgba(63, 185, 80, 0.30); }
.badge--highVolume  { background: rgba(210,153, 34, 0.18); color: var(--amber);  border-color: rgba(210,153, 34, 0.30); }
.badge--pullback    { background: rgba(47, 129,247, 0.18); color: var(--accent); border-color: rgba(47, 129,247, 0.30); }
.badge--near        { background: rgba(139,149,165, 0.14); color: var(--muted);  border-color: rgba(139,149,165, 0.22); }

/* confluence counter */
.conf-tag {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(47, 129, 247, 0.22);
  color: var(--accent);
  border-radius: 10px;
  font-family: var(--mono);
  font-size: 0.65rem;
  font-weight: 700;
  padding: 1px 5px;
  margin-inline-start: 2px;
  vertical-align: middle;
}

/* ═══════════════════════════════════════════════
   SCORE CELL (inline style sets --sc-bg via JS attr)
═══════════════════════════════════════════════ */
td.col-score {
  font-weight: 700;
  border-radius: 0;
}

/* ═══════════════════════════════════════════════
   UP / DOWN COLORS
═══════════════════════════════════════════════ */
.num-up   { color: var(--up); }
.num-down { color: var(--down); }
.num-neu  { color: var(--muted); }

/* ═══════════════════════════════════════════════
   CARD LIST (mobile view — hidden on desktop)
═══════════════════════════════════════════════ */
.card-list {
  display: none;
  flex-direction: column;
  gap: 8px;
}

.signal-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  cursor: pointer;
  transition: border-color 0.15s;
  position: relative;
}

.signal-card:hover,
.signal-card:focus-visible {
  border-color: var(--accent);
  outline: none;
}

.signal-card[data-conf="true"] {
  border-inline-start: 3px solid var(--accent);
}

.sc-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
  gap: 8px;
}

.sc-ticker {
  font-family: var(--mono);
  font-weight: 700;
  font-size: 1rem;
  color: var(--text);
}

.sc-score-badge {
  font-family: var(--mono);
  font-size: 0.78rem;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: var(--radius-sm);
}

.sc-badges { margin-bottom: 8px; }

.sc-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px 8px;
  font-size: 0.75rem;
}

.sc-kv {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.sc-k { color: var(--muted); font-size: 0.68rem; }
.sc-v { font-family: var(--mono); font-variant-numeric: tabular-nums; }

/* ═══════════════════════════════════════════════
   STATE MESSAGES (loading / empty)
═══════════════════════════════════════════════ */
.state-msg {
  padding: 48px 0;
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
}

/* ═══════════════════════════════════════════════
   DEEP-DIVE PANEL
═══════════════════════════════════════════════ */
.deepdive {
  position: fixed;
  inset-block: 0;
  inset-inline-end: 0;
  width: var(--panel-w);
  background: var(--surface);
  border-inline-start: 1px solid var(--border);
  z-index: 300;
  overflow-y: auto;
  transform: translateX(-100%);      /* LTR fallback, overridden below */
  transition: transform 0.22s ease;
}

/* RTL: panel slides in from left (visual right) */
[dir="rtl"] .deepdive {
  transform: translateX(100%);
}

.deepdive:not([hidden]) {
  transform: translateX(0);
}

.deepdive-inner {
  padding: 20px 18px;
}

.deepdive-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 299;
}

.deepdive-overlay:not([hidden]) { display: block; }

/* close button */
.btn-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--muted);
  cursor: pointer;
  font-size: 1rem;
  margin-bottom: 16px;
  transition: border-color 0.12s, color 0.12s;
}

.btn-close:hover { border-color: var(--down); color: var(--down); }

.dd-ticker {
  font-family: var(--mono);
  font-size: 1.4rem;
  font-weight: 700;
  margin-bottom: 4px;
}

.dd-sub {
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 14px;
}

.dd-badges { margin-bottom: 16px; }

.dd-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 18px;
}

.dd-kv {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
}

.dd-k { font-size: 0.68rem; color: var(--muted); margin-bottom: 2px; }
.dd-v { font-family: var(--mono); font-size: 0.9rem; font-weight: 600; font-variant-numeric: tabular-nums; }

.dd-tv-link {
  display: block;
  text-align: center;
  padding: 10px;
  background: rgba(47, 129, 247, 0.12);
  border: 1px solid rgba(47, 129, 247, 0.35);
  border-radius: var(--radius);
  color: var(--accent);
  font-weight: 600;
  font-size: 0.85rem;
  transition: background 0.15s;
}

.dd-tv-link:hover {
  background: rgba(47, 129, 247, 0.22);
  text-decoration: none;
}

/* ═══════════════════════════════════════════════
   MOBILE — 640px breakpoint
═══════════════════════════════════════════════ */
@media (max-width: 640px) {
  /* hide table, show card list */
  .table-wrap { display: none; }
  .card-list  { display: flex; }

  /* summary cards → 2-column compact */
  .summary-section {
    grid-template-columns: 1fr;
  }

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

  .stat-card-val { font-size: 1.2rem; }

  /* controls stack full-width */
  .controls { gap: 6px; }
  .ctrl-input,
  .ctrl-select {
    width: 100%;
    min-width: unset;
    min-height: 44px;  /* tap target */
    font-size: 1rem;
  }
  .ctrl-checkbox { min-height: 44px; font-size: 1rem; }

  /* deep-dive becomes bottom sheet */
  .deepdive {
    inset-inline: 0;
    inset-block-start: auto;
    inset-block-end: 0;
    width: 100%;
    max-height: 80dvh;
    border-inline-start: none;
    border-top: 1px solid var(--border);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    transform: translateY(100%);
  }

  [dir="rtl"] .deepdive {
    transform: translateY(100%);
  }

  .deepdive:not([hidden]) {
    transform: translateY(0);
  }

  .dd-grid { grid-template-columns: 1fr 1fr 1fr; }

  main { padding: 12px 12px 80px; }

  .ctrl-count { margin-inline-start: 0; width: 100%; }
}

/* ═══════════════════════════════════════════════
   SCROLLBAR — subtle dark
═══════════════════════════════════════════════ */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--muted); }
