/* ═══════════════════════════════════════════════════════════
   CryptoTrading Anomaly Detector — Design System
   Premium dark theme with glassmorphism, smooth animations
   ═══════════════════════════════════════════════════════════ */

/* ─── Google Fonts ─── */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800;900&family=JetBrains+Mono:wght@400;500;600;700&display=swap');

/* ─── CSS Custom Properties ─── */
:root {
  /* Colors */
  --bg-primary: #0a0e17;
  --bg-secondary: #0d1117;
  --bg-card: rgba(15, 20, 30, 0.7);
  --bg-card-hover: rgba(20, 28, 42, 0.8);
  --bg-glass: rgba(13, 17, 23, 0.6);

  --border-primary: rgba(255, 255, 255, 0.06);
  --border-hover: rgba(255, 255, 255, 0.12);
  --border-accent: rgba(99, 179, 237, 0.3);

  --text-primary: #e6edf3;
  --text-secondary: rgba(230, 237, 243, 0.6);
  --text-muted: rgba(230, 237, 243, 0.35);

  --bullish: #00d68f;
  --bullish-dim: rgba(0, 214, 143, 0.15);
  --bullish-glow: rgba(0, 214, 143, 0.4);

  --bearish: #ff3d71;
  --bearish-dim: rgba(255, 61, 113, 0.15);
  --bearish-glow: rgba(255, 61, 113, 0.4);

  --accent-blue: #63b3ed;
  --accent-purple: #a78bfa;
  --accent-orange: #ff9f43;
  --accent-yellow: #fdcb6e;
  --accent-cyan: #48dbfb;

  /* Layout */
  --header-height: 56px;
  --sidebar-width: 360px;
  --gap: 12px;
  --radius: 12px;
  --radius-sm: 8px;
  --radius-xs: 6px;

  /* Transitions */
  --transition-fast: 150ms ease;
  --transition-normal: 250ms ease;
  --transition-slow: 400ms cubic-bezier(0.4, 0, 0.2, 1);

  /* Shadows */
  --shadow-card: 0 2px 8px rgba(0, 0, 0, 0.3), 0 0 1px rgba(255, 255, 255, 0.05);
  --shadow-elevated: 0 8px 32px rgba(0, 0, 0, 0.5), 0 0 1px rgba(255, 255, 255, 0.08);
  --shadow-glow-bull: 0 0 20px rgba(0, 214, 143, 0.15);
  --shadow-glow-bear: 0 0 20px rgba(255, 61, 113, 0.15);
}

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

html {
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
  line-height: 1.5;
}

/* Animated gradient background */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse at 20% 0%, rgba(99, 179, 237, 0.06) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 100%, rgba(167, 139, 250, 0.04) 0%, transparent 50%),
    radial-gradient(ellipse at 50% 50%, rgba(0, 214, 143, 0.02) 0%, transparent 60%);
  pointer-events: none;
  z-index: 0;
}

/* ─── HEADER ─── */
.header {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--header-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  background: rgba(10, 14, 23, 0.85);
  backdrop-filter: blur(20px) saturate(1.5);
  -webkit-backdrop-filter: blur(20px) saturate(1.5);
  border-bottom: 1px solid var(--border-primary);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 16px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--text-primary);
}

.logo-icon {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--accent-purple), var(--accent-blue));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  box-shadow: 0 0 12px rgba(167, 139, 250, 0.3);
}

.logo-text {
  font-weight: 700;
  font-size: 1rem;
  letter-spacing: -0.02em;
}

.logo-text span {
  color: var(--accent-blue);
}

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

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

/* ─── BUTTONS ─── */
.btn-group {
  display: flex;
  background: rgba(255, 255, 255, 0.04);
  border-radius: var(--radius-sm);
  padding: 3px;
  gap: 2px;
  border: 1px solid var(--border-primary);
}

.btn {
  border: none;
  background: transparent;
  color: var(--text-secondary);
  padding: 6px 14px;
  border-radius: var(--radius-xs);
  font-family: 'Inter', sans-serif;
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition-fast);
  white-space: nowrap;
  letter-spacing: 0.01em;
}

.btn:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.06);
}

.btn.active {
  color: #fff;
  background: rgba(99, 179, 237, 0.2);
  box-shadow: 0 0 8px rgba(99, 179, 237, 0.15);
}

.btn-icon {
  width: 36px;
  height: 36px;
  border: 1px solid var(--border-primary);
  background: var(--bg-card);
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1.1rem;
  transition: var(--transition-fast);
}

.btn-icon:hover {
  background: var(--bg-card-hover);
  border-color: var(--border-hover);
}

.btn-icon.active {
  color: var(--accent-yellow);
}

/* ─── STATUS ─── */
.status-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
  transition: var(--transition-normal);
}

.status-dot.connected {
  background: var(--bullish);
  box-shadow: 0 0 8px var(--bullish-glow);
  animation: pulse-glow 2s infinite;
}

.status-dot.error {
  background: var(--bearish);
  box-shadow: 0 0 8px var(--bearish-glow);
}

@keyframes pulse-glow {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* ─── LOADING ─── */
.loading-indicator {
  position: fixed;
  top: var(--header-height);
  left: 0;
  right: 0;
  height: 2px;
  z-index: 200;
  overflow: hidden;
  opacity: 0;
  transition: opacity var(--transition-fast);
}

.loading-indicator.visible {
  opacity: 1;
}

.loading-indicator::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, var(--accent-blue), var(--accent-purple), transparent);
  animation: loading-slide 1.2s ease-in-out infinite;
}

@keyframes loading-slide {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}

/* ─── MAIN LAYOUT ─── */
.main-layout {
  display: grid;
  grid-template-columns: 1fr var(--sidebar-width);
  gap: var(--gap);
  padding: var(--gap);
  min-height: calc(100vh - var(--header-height));
  position: relative;
  z-index: 1;
}

/* ─── CARDS (Glassmorphism) ─── */
.card {
  background: var(--bg-card);
  backdrop-filter: blur(12px) saturate(1.3);
  -webkit-backdrop-filter: blur(12px) saturate(1.3);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow-card);
  transition: border-color var(--transition-normal), box-shadow var(--transition-normal);
}

.card:hover {
  border-color: var(--border-hover);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.card-title {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}

/* ─── LEFT COLUMN: Charts ─── */
.chart-column {
  display: flex;
  flex-direction: column;
  gap: var(--gap);
  min-width: 0;
}

/* Price Hero */
.price-hero {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
}

.price-left {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.symbol-name {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-weight: 500;
}

.price-value {
  font-family: 'JetBrains Mono', monospace;
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  transition: color var(--transition-fast);
}

.price-value.bullish { color: var(--bullish); }
.price-value.bearish { color: var(--bearish); }

.price-change {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.82rem;
  font-family: 'JetBrains Mono', monospace;
}

.change-amount { font-weight: 600; }
.change-amount.bullish { color: var(--bullish); }
.change-amount.bearish { color: var(--bearish); }

.change-percent { font-weight: 500; }
.change-percent.bullish { color: var(--bullish); }
.change-percent.bearish { color: var(--bearish); }

.change-period {
  color: var(--text-muted);
  font-size: 0.72rem;
  font-family: 'Inter', sans-serif;
}

/* Chart Containers */
.chart-container {
  position: relative;
}

.chart-container canvas {
  width: 100%;
  display: block;
}

.chart-main-wrap {
  height: 340px;
}

.chart-main-wrap canvas {
  height: 100%;
}

.chart-sub-wrap {
  height: 100px;
}

.chart-sub-wrap canvas {
  height: 100%;
}

.chart-label {
  position: absolute;
  top: 8px;
  left: 12px;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  pointer-events: none;
  z-index: 2;
}

/* ─── RIGHT COLUMN: Signal + Indicators ─── */
.signal-column {
  display: flex;
  flex-direction: column;
  gap: var(--gap);
  min-width: 0;
}

/* Signal Panel */
.signal-panel {
  text-align: center;
  padding: 20px 16px;
  position: relative;
  overflow: hidden;
  transition: box-shadow var(--transition-normal);
}

.signal-panel.flash {
  animation: signal-flash 1s ease;
}

@keyframes signal-flash {
  0%, 100% { box-shadow: var(--shadow-card); }
  50% { box-shadow: var(--shadow-elevated), 0 0 40px rgba(99, 179, 237, 0.2); }
}

.gauge-container {
  width: 180px;
  height: 120px;
  margin: 0 auto 8px;
}

.gauge-container canvas {
  width: 100%;
  height: 100%;
}

.signal-badge {
  display: inline-block;
  padding: 5px 16px;
  border-radius: 20px;
  font-weight: 700;
  font-size: 0.9rem;
  letter-spacing: 0.03em;
  margin-bottom: 8px;
}

.signal-badge.signal-strong-buy {
  background: var(--bullish-dim);
  color: var(--bullish);
  box-shadow: var(--shadow-glow-bull);
}
.signal-badge.signal-buy {
  background: rgba(72, 219, 251, 0.12);
  color: var(--accent-cyan);
}
.signal-badge.signal-neutral {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-secondary);
}
.signal-badge.signal-sell {
  background: rgba(255, 159, 67, 0.12);
  color: var(--accent-orange);
}
.signal-badge.signal-strong-sell {
  background: var(--bearish-dim);
  color: var(--bearish);
  box-shadow: var(--shadow-glow-bear);
}

.signal-confidence {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.signal-description {
  font-size: 0.72rem;
  color: var(--text-secondary);
  line-height: 1.5;
  max-height: 3em;
  overflow: hidden;
}

/* ─── INDICATOR CARDS ─── */
.indicator-card {
  padding: 12px 14px;
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-rows: auto auto;
  gap: 4px 12px;
  position: relative;
  overflow: hidden;
}

.indicator-card::before {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 40px;
  pointer-events: none;
}

.indicator-label {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.indicator-value {
  font-family: 'JetBrains Mono', monospace;
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.card-score {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.82rem;
  font-weight: 600;
  text-align: right;
  align-self: center;
}

.card-score.positive { color: var(--bullish); }
.card-score.negative { color: var(--bearish); }
.card-score.neutral { color: var(--text-muted); }

.indicator-detail {
  font-size: 0.7rem;
  color: var(--text-secondary);
  grid-column: 1 / -1;
}

.spark-container {
  grid-column: 1 / -1;
  height: 30px;
  margin-top: 4px;
}

.spark-container canvas {
  width: 100%;
  height: 100%;
}

/* ─── MARKET OVERVIEW ─── */
.market-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.market-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.market-label {
  font-size: 0.68rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 500;
}

.market-value {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-primary);
}

/* ─── ALERT HISTORY ─── */
.alert-history-wrap {
  max-height: 240px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.08) transparent;
}

.alert-history-wrap::-webkit-scrollbar {
  width: 4px;
}

.alert-history-wrap::-webkit-scrollbar-track {
  background: transparent;
}

.alert-history-wrap::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.1);
  border-radius: 2px;
}

.alert-item {
  display: grid;
  grid-template-columns: 55px auto 36px;
  gap: 6px;
  padding: 8px 10px;
  border-radius: var(--radius-xs);
  margin-bottom: 4px;
  font-size: 0.72rem;
  align-items: center;
  transition: background var(--transition-fast);
}

.alert-item:hover {
  background: rgba(255, 255, 255, 0.03);
}

.alert-item.signal-strong-buy { border-left: 2px solid var(--bullish); }
.alert-item.signal-buy { border-left: 2px solid var(--accent-cyan); }
.alert-item.signal-sell { border-left: 2px solid var(--accent-orange); }
.alert-item.signal-strong-sell { border-left: 2px solid var(--bearish); }

.alert-time {
  font-family: 'JetBrains Mono', monospace;
  color: var(--text-muted);
  font-size: 0.7rem;
}

.alert-signal {
  font-weight: 600;
  white-space: nowrap;
}

.alert-score {
  font-family: 'JetBrains Mono', monospace;
  font-weight: 700;
  text-align: right;
}

.alert-desc {
  grid-column: 1 / -1;
  color: var(--text-secondary);
  font-size: 0.68rem;
  line-height: 1.4;
}

.alert-empty {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.78rem;
  padding: 20px 0;
}

/* ─── RESPONSIVE ─── */
@media (max-width: 1100px) {
  .main-layout {
    grid-template-columns: 1fr;
  }

  .signal-column {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--gap);
  }

  .signal-panel {
    grid-column: 1 / -1;
  }
}

@media (max-width: 640px) {
  :root {
    --gap: 8px;
  }

  .header {
    padding: 0 12px;
    flex-wrap: wrap;
    height: auto;
    min-height: var(--header-height);
    gap: 8px;
    padding-top: 8px;
    padding-bottom: 8px;
  }

  .header-center {
    order: 3;
    width: 100%;
    justify-content: center;
  }

  .logo-text {
    font-size: 0.85rem;
  }

  .price-value {
    font-size: 1.5rem;
  }

  .signal-column {
    grid-template-columns: 1fr;
  }

  .chart-main-wrap {
    height: 250px;
  }

  .chart-sub-wrap {
    height: 80px;
  }
}

/* ─── Utility animations ─── */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.card {
  animation: fadeIn 0.4s ease both;
}

.card:nth-child(2) { animation-delay: 0.05s; }
.card:nth-child(3) { animation-delay: 0.1s; }
.card:nth-child(4) { animation-delay: 0.15s; }
.card:nth-child(5) { animation-delay: 0.2s; }
.card:nth-child(6) { animation-delay: 0.25s; }
.card:nth-child(7) { animation-delay: 0.3s; }
.card:nth-child(8) { animation-delay: 0.35s; }

/* Score color transitions */
.score-value {
  transition: color var(--transition-normal);
}

.score-value.signal-strong-buy { color: var(--bullish); }
.score-value.signal-buy { color: var(--accent-cyan); }
.score-value.signal-neutral { color: var(--text-secondary); }
.score-value.signal-sell { color: var(--accent-orange); }
.score-value.signal-strong-sell { color: var(--bearish); }

/* ─── Disclaimer ─── */
.disclaimer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  text-align: center;
  padding: 6px 16px;
  font-size: 0.65rem;
  color: var(--text-muted);
  background: rgba(10, 14, 23, 0.8);
  backdrop-filter: blur(8px);
  border-top: 1px solid var(--border-primary);
  z-index: 50;
}
