/* ── Variables ───────────────────────────────────────────────────────────── */
:root {
  --bg:           #080b10;
  --surface:      #0f1319;
  --surface2:     #151b24;
  --surface3:     #1b2230;
  --border:       #1e2838;
  --border-hi:    #28364a;
  --accent:       #4f8ef7;
  --accent-dim:   rgba(79,142,247,0.12);
  --accent-hover: #6ba0ff;
  --bullish:      #22c55e;
  --bullish-dim:  rgba(34,197,94,0.12);
  --bearish:      #ef4444;
  --bearish-dim:  rgba(239,68,68,0.12);
  --mixed:        #f59e0b;
  --mixed-dim:    rgba(245,158,11,0.12);
  --dp:           #a78bfa;
  --dp-dim:       rgba(167,139,250,0.12);
  --sweep:        #38bdf8;
  --sweep-dim:    rgba(56,189,248,0.12);
  --floor:        #fb923c;
  --floor-dim:    rgba(251,146,60,0.12);
  --text:         #dde3ed;
  --text-dim:     #9aaabb;
  --text-muted:   #5a6a7e;
  --mono:         'SF Mono', 'Fira Code', 'Cascadia Code', ui-monospace, monospace;
  --radius:       6px;
  --radius-lg:    10px;
}

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

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

/* ── App layout ──────────────────────────────────────────────────────────── */
.app { display: flex; flex-direction: column; min-height: 100vh; }

/* ── Header ──────────────────────────────────────────────────────────────── */
header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(8,11,16,0.9);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
}

.header-inner {
  max-width: 1320px;
  margin: 0 auto;
  padding: 0 24px;
  height: 54px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 16px;
  letter-spacing: -0.02em;
}

.logo-icon { font-size: 18px; line-height: 1; }
.logo-tag {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  background: var(--surface2);
  border: 1px solid var(--border);
  padding: 2px 7px;
  border-radius: 4px;
}

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

.last-scan {
  font-size: 11px;
  color: var(--text-muted);
  font-family: var(--mono);
}

.api-status {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  padding: 3px 10px;
  border-radius: 20px;
  border: 1px solid transparent;
}
.api-status.ok    { color: var(--bullish); background: var(--bullish-dim); border-color: rgba(34,197,94,0.3); }
.api-status.warn  { color: var(--mixed);   background: var(--mixed-dim);   border-color: rgba(245,158,11,0.3); }
.api-status.error { color: var(--bearish); background: var(--bearish-dim); border-color: rgba(239,68,68,0.3); }

/* ── Main ────────────────────────────────────────────────────────────────── */
main {
  max-width: 1320px;
  margin: 0 auto;
  padding: 24px 24px 64px;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ── Controls card ───────────────────────────────────────────────────────── */
.controls-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px 24px;
}

.controls-row {
  display: flex;
  gap: 32px;
  align-items: flex-start;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

.control-group { display: flex; flex-direction: column; gap: 10px; }
.control-group--slider { flex: 1; min-width: 200px; }

.control-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.control-value {
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0;
}

.button-group { display: flex; gap: 4px; flex-wrap: wrap; }

.day-btn {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 5px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  font-family: var(--mono);
  transition: all 0.12s;
}
.day-btn:hover { color: var(--text); border-color: var(--border-hi); }
.day-btn.active { background: var(--accent-dim); border-color: var(--accent); color: var(--accent); }

input[type="range"] {
  width: 100%;
  height: 4px;
  -webkit-appearance: none;
  appearance: none;
  background: var(--border);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  box-shadow: 0 0 0 3px rgba(79,142,247,0.2);
  transition: box-shadow 0.15s;
}
input[type="range"]::-webkit-slider-thumb:hover {
  box-shadow: 0 0 0 5px rgba(79,142,247,0.25);
}

.slider-hints {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 2px;
}

.checkbox-row { display: flex; flex-direction: column; gap: 7px; }

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-dim);
  cursor: pointer;
  user-select: none;
}
.checkbox-label input { accent-color: var(--accent); cursor: pointer; }

.scan-btn {
  width: 100%;
  padding: 11px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: background 0.15s, transform 0.1s, opacity 0.15s;
  letter-spacing: 0.01em;
}
.scan-btn:hover  { background: var(--accent-hover); }
.scan-btn:active { transform: scale(0.99); }
.scan-btn:disabled { opacity: 0.55; cursor: not-allowed; transform: none; }
.scan-btn.loading { background: var(--surface2); color: var(--text-muted); }
.scan-btn.loading #scan-icon { animation: spin 1s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Stats grid ──────────────────────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
}
.stat-card--accent { border-color: rgba(79,142,247,0.3); background: rgba(79,142,247,0.05); }

.stat-value {
  font-family: var(--mono);
  font-size: 26px;
  font-weight: 700;
  line-height: 1.1;
  margin-bottom: 5px;
  color: var(--text);
}
.stat-card--accent .stat-value { color: var(--accent); }

.stat-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--text-muted);
}

/* ── Results section ─────────────────────────────────────────────────────── */
.results-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.results-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.results-title { font-size: 15px; font-weight: 600; margin-bottom: 2px; }
.results-sub   { font-size: 11px; color: var(--text-muted); }

.legend {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  font-size: 11px;
}
.legend-item         { color: var(--text-muted); }
.legend-item.bullish { color: var(--bullish); }
.legend-item.bearish { color: var(--bearish); }
.legend-item.mixed   { color: var(--mixed); }
.legend-item.sweep   { color: var(--sweep); }
.legend-item.floor   { color: var(--floor); }
.legend-item.dp      { color: var(--dp); }

/* ── Table ───────────────────────────────────────────────────────────────── */
.table-wrapper { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; }

thead tr { border-bottom: 1px solid var(--border); }

thead th {
  padding: 9px 14px;
  text-align: left;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  white-space: nowrap;
  background: var(--surface2);
}

thead th.sortable { cursor: pointer; user-select: none; }
thead th.sortable:hover { color: var(--text); }
.sort-arrow        { opacity: 0.35; margin-left: 3px; }
.sort-arrow.active { opacity: 1; color: var(--accent); }

/* Data rows */
tbody tr.result-row {
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.1s;
}
tbody tr.result-row:hover    { background: rgba(255,255,255,0.025); }
tbody tr.result-row.expanded { background: rgba(79,142,247,0.04); border-left: 2px solid var(--accent); }

tbody tr.result-row td { padding: 12px 14px; vertical-align: middle; }

/* Expand detail row */
tbody tr.detail-row { border-bottom: 1px solid var(--border); }
tbody tr.detail-row.hidden { display: none; }
tbody tr.detail-row td { padding: 0; }

.detail-panel {
  background: var(--surface2);
  border-top: 1px solid var(--border);
  padding: 14px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.detail-section { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }

.detail-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  white-space: nowrap;
}

/* Mini trades table */
.mini-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  margin-top: 6px;
}
.mini-table thead th {
  padding: 5px 12px;
  background: var(--surface3);
  font-size: 10px;
  text-align: left;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--text-muted);
}
.mini-table tbody td {
  padding: 7px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--text-dim);
}
.mini-table tbody tr:last-child td { border-bottom: none; }
.mini-table tbody tr:hover { background: rgba(255,255,255,0.02); }

/* ── Column widths ───────────────────────────────────────────────────────── */
.col-rank    { width: 36px;  text-align: center; }
.col-ticker  { min-width: 140px; }
.col-premium { min-width: 110px; }
.col-trades  { min-width: 70px; }
.col-zscore  { min-width: 110px; }
.col-callpct { min-width: 110px; }
.col-avgtrade{ min-width: 90px; }
.col-signals { min-width: 100px; }
.col-expand  { width: 30px; text-align: center; }

/* ── Cell styles ─────────────────────────────────────────────────────────── */
.td-rank {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-muted);
  text-align: center;
}

.ticker-wrap { display: flex; align-items: center; gap: 6px; }

.ticker-badge {
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 4px;
  letter-spacing: 0.04em;
}
.ticker-badge.bullish { background: var(--bullish-dim); color: var(--bullish); }
.ticker-badge.bearish { background: var(--bearish-dim); color: var(--bearish); }
.ticker-badge.mixed   { background: var(--mixed-dim);   color: var(--mixed); }

.sector-tag {
  font-size: 10px;
  font-weight: 500;
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--surface3);
  border: 1px solid var(--border);
  color: var(--text-muted);
  white-space: nowrap;
}

.td-premium {
  font-family: var(--mono);
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
}

.td-trades { font-family: var(--mono); font-size: 13px; color: var(--text-dim); }

/* Z-score cell */
.zscore-cell { display: flex; flex-direction: column; gap: 4px; }
.zscore-val {
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 700;
  color: var(--accent);
}
.zscore-bar-bg {
  height: 3px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
  width: 80px;
}
.zscore-bar-fill {
  height: 100%;
  border-radius: 2px;
  transition: width 0.4s ease;
}
.zscore-bar-fill.bullish { background: var(--bullish); }
.zscore-bar-fill.bearish { background: var(--bearish); }
.zscore-bar-fill.mixed   { background: var(--mixed); }

/* Call% bar */
.callpct-cell { display: flex; align-items: center; gap: 8px; }
.callpct-bar-bg {
  width: 70px;
  height: 5px;
  background: rgba(239,68,68,0.25);
  border-radius: 3px;
  overflow: hidden;
  flex-shrink: 0;
}
.callpct-bar-fill {
  height: 100%;
  background: var(--bullish);
  border-radius: 3px;
  transition: width 0.4s ease;
}
.callpct-label {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-dim);
  min-width: 30px;
}

.td-avgtrade {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-dim);
  white-space: nowrap;
}

.td-signals { white-space: nowrap; }

.expand-btn {
  font-size: 9px;
  color: var(--text-muted);
  display: inline-block;
  transition: transform 0.2s;
}
.result-row.expanded .expand-btn { transform: rotate(90deg); }

/* ── Badges ──────────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 4px;
  border: 1px solid transparent;
  white-space: nowrap;
  margin-right: 3px;
}
.badge-sweep { background: var(--sweep-dim); color: var(--sweep); border-color: rgba(56,189,248,0.25); }
.badge-floor { background: var(--floor-dim); color: var(--floor); border-color: rgba(251,146,60,0.25); }
.badge-dp    { background: var(--dp-dim);    color: var(--dp);    border-color: rgba(167,139,250,0.25); }

.alert-tag {
  font-size: 10px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 4px;
  background: var(--accent-dim);
  border: 1px solid rgba(79,142,247,0.25);
  color: var(--accent);
  font-family: var(--mono);
}

.mini-type {
  font-size: 10px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 3px;
  font-family: var(--mono);
  letter-spacing: 0.04em;
}
.mini-type.call { background: var(--bullish-dim); color: var(--bullish); }
.mini-type.put  { background: var(--bearish-dim); color: var(--bearish); }

/* ── Empty / Error ───────────────────────────────────────────────────────── */
.empty-state, .error-state {
  text-align: center;
  padding: 64px 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}
.empty-icon  { font-size: 36px; margin-bottom: 14px; }
.empty-title { font-size: 16px; font-weight: 600; margin-bottom: 6px; }
.empty-sub   { font-size: 13px; color: var(--text-muted); }

.error-icon    { font-size: 28px; color: var(--bearish); margin-bottom: 10px; }
.error-message { color: var(--bearish); font-size: 13px; font-family: var(--mono); margin-top: 6px; }

/* ── Utility ─────────────────────────────────────────────────────────────── */
.hidden { display: none !important; }

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 960px) {
  .controls-row { gap: 20px; }
  .stats-grid   { grid-template-columns: repeat(2, 1fr); }
  .col-avgtrade, tbody td:nth-child(7) { display: none; }
}
@media (max-width: 640px) {
  main { padding: 12px 12px 48px; }
  .header-inner { padding: 0 16px; }
  .controls-row { flex-direction: column; }
  .stats-grid   { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .col-signals, tbody td:nth-child(8) { display: none; }
  .results-header { flex-direction: column; align-items: flex-start; gap: 10px; }
}
