/**
 * factor_timing.css
 * Design system for the Factor Timing Analysis page.
 * Part of the index_fetcher web frontend — CSS/JS/HTML separated convention.
 *
 * Color tokens, layout, component styles, animations.
 * All pages that follow this design system should import this file.
 */

/* ── Design Tokens ─────────────────────────────────────────────── */
:root {
  /* Backgrounds */
  --bg:   #0b0e17;
  --bg2:  #111827;
  --card: rgba(17, 24, 39, .85);

  /* Borders & shadows */
  --border: rgba(255, 255, 255, .06);
  --shadow: 0 8px 32px rgba(0, 0, 0, .45);

  /* Text */
  --txt:  #e5e7eb;
  --txt2: #9ca3af;
  --txt3: #6b7280;

  /* Accent palette */
  --indigo: #818cf8;
  --cyan:   #22d3ee;
  --violet: #a78bfa;
  --warn:   #f59e0b;

  /* Semantic colors */
  --up:   #34d399;
  --dn:   #f87171;
  --buy:  #10b981;
  --sell: #ef4444;

  /* Radius */
  --r-sm: 6px;
  --r-md: 12px;
  --r-lg: 20px;

  /* Typography */
  --mono: 'JetBrains Mono', 'Cascadia Code', Consolas, monospace;
  --sans: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}

/* ── Reset ──────────────────────────────────────────────────────── */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
html { font-size: 14px; }

/* ── Body & ambient glow ────────────────────────────────────────── */
body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--txt);
  min-height: 100vh;
  overflow-x: hidden;
}
body::before {
  content: '';
  position: fixed;
  top: -40%; left: -20%;
  width: 70%; height: 70%;
  background: radial-gradient(circle, rgba(99, 102, 241, .12) 0%, transparent 70%);
  pointer-events: none;
  z-index: 0;
}
body::after {
  content: '';
  position: fixed;
  bottom: -30%; right: -15%;
  width: 60%; height: 60%;
  background: radial-gradient(circle, rgba(16, 185, 129, .10) 0%, transparent 70%);
  pointer-events: none;
  z-index: 0;
}

/* ── Page wrapper ───────────────────────────────────────────────── */
.wrap {
  position: relative;
  z-index: 1;
  max-width: 1500px;
  margin: 0 auto;
  padding: 1.5rem 2rem 3rem;
}

/* ── Top bar ────────────────────────────────────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.topbar-left { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }

.back-link {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  color: var(--indigo);
  text-decoration: none;
  font-size: .85rem;
  font-weight: 500;
  transition: color .2s;
}
.back-link:hover { color: var(--cyan); }

.page-title {
  font-size: 1.6rem;
  font-weight: 800;
  background: linear-gradient(135deg, var(--indigo), var(--cyan));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.badge {
  font-size: .7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  padding: .25rem .6rem;
  border-radius: 999px;
  background: rgba(99, 102, 241, .15);
  color: var(--indigo);
  border: 1px solid rgba(99, 102, 241, .25);
}

/* ── Index switcher ─────────────────────────────────────────────── */
.index-switcher { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; }
.index-switcher label { font-size: .82rem; color: var(--txt2); }

.index-select {
  background: var(--bg2);
  color: var(--cyan);
  border: 1px solid rgba(34, 211, 238, .3);
  border-radius: var(--r-md);
  outline: none;
  font-size: .85rem;
  font-family: var(--sans);
  padding: .4rem .8rem;
  cursor: pointer;
  transition: border-color .2s;
}
.index-select:hover { border-color: rgba(34, 211, 238, .6); }

.quick-btns { display: flex; gap: .4rem; flex-wrap: wrap; }
.q-btn {
  font-size: .78rem;
  padding: .3rem .7rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--txt2);
  cursor: pointer;
  transition: all .2s;
  font-family: var(--sans);
}
.q-btn:hover, .q-btn.active {
  background: rgba(34, 211, 238, .12);
  color: var(--cyan);
  border-color: rgba(34, 211, 238, .3);
}

/* ── Layout grid ────────────────────────────────────────────────── */
.main-grid {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 1.5rem;
  align-items: start;
}
@media (max-width: 1100px) { .main-grid { grid-template-columns: 1fr; } }

/* ── Glass card ─────────────────────────────────────────────────── */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  padding: 1.5rem;
}
.card-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--txt);
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: .5rem;
}

/* ── Chart container ────────────────────────────────────────────── */
#timing-chart { width: 100%; height: 660px; }

/* ── Side panel — section label ─────────────────────────────────── */
.section-label {
  font-size: .7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--txt3);
  margin: 1.25rem 0 .6rem;
}
.section-label:first-child { margin-top: 0; }

/* ── Strategy card ──────────────────────────────────────────────── */
.strategy-card {
  background: rgba(0, 0, 0, .2);
  border-radius: var(--r-md);
  padding: 1rem;
  margin-bottom: .75rem;
  border-left: 3px solid var(--buy);
}
.strategy-card.sell    { border-left-color: var(--sell); }
.strategy-card h3      { font-size: .9rem; font-weight: 700; margin-bottom: .4rem; display: flex; align-items: center; gap: .4rem; }
.strategy-card.buy  h3 { color: var(--buy); }
.strategy-card.sell h3 { color: var(--sell); }
.strategy-card p       { font-size: .8rem; color: var(--txt2); line-height: 1.55; }

.strategy-card .thresholds { margin-top: .6rem; display: flex; gap: .5rem; flex-wrap: wrap; }
.thresh-tag {
  font-size: .75rem;
  font-family: var(--mono);
  padding: .15rem .5rem;
  border-radius: var(--r-sm);
  background: rgba(255, 255, 255, .06);
  color: var(--txt);
}

/* ── Stats grid ─────────────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .6rem;
  margin-bottom: .75rem;
}
.stat-box {
  background: rgba(0, 0, 0, .25);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: .75rem 1rem;
  text-align: center;
}
.stat-val {
  font-size: 1.05rem;
  font-weight: 700;
  font-family: var(--mono);
  color: var(--cyan);
}
.stat-lbl   { font-size: .72rem; color: var(--txt3); margin-top: .2rem; }
.stat-box.buy  .stat-val { color: var(--buy); }
.stat-box.sell .stat-val { color: var(--sell); }

/* ── Loading / error states ─────────────────────────────────────── */
.state-overlay {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 5rem 2rem;
  gap: 1rem;
  min-height: 300px;
}
.spinner {
  width: 36px; height: 36px;
  border: 3px solid rgba(99, 102, 241, .2);
  border-top-color: var(--indigo);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.state-txt { color: var(--txt2); font-size: .9rem; }
.error-msg {
  color: var(--dn);
  background: rgba(239, 68, 68, .1);
  border: 1px solid rgba(239, 68, 68, .25);
  border-radius: var(--r-md);
  padding: 1rem 1.5rem;
  font-size: .85rem;
}

/* ── Animations ─────────────────────────────────────────────────── */
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}
.ani { animation: fadeInUp .45s ease both; }

/* ── Sensitivity slider ─────────────────────────────────────────── */
.sens-row {
  display: flex;
  align-items: center;
  gap: .75rem;
  margin-bottom: .5rem;
}
.sens-row label { font-size: .8rem; color: var(--txt2); white-space: nowrap; }

.sens-slider {
  flex: 1;
  -webkit-appearance: none;
  height: 4px;
  border-radius: 2px;
  background: rgba(255, 255, 255, .1);
  outline: none;
  cursor: pointer;
}
.sens-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--indigo);
  cursor: pointer;
  box-shadow: 0 0 6px rgba(129, 140, 248, .5);
}
.sens-slider::-moz-range-thumb {
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--indigo);
  cursor: pointer;
  border: none;
}
.sens-val {
  font-size: .8rem;
  font-family: var(--mono);
  color: var(--indigo);
  min-width: 24px;
  text-align: right;
}
