:root {
  --bg-primary: #070b12;
  --bg-card: #0e1522;
  --bg-card-hover: #131c2e;
  --bg-elevated: #172236;
  --border-subtle: rgba(148, 163, 184, 0.12);
  --border-highlight: rgba(56, 189, 248, 0.28);

  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;

  /* Sentiment Palette:
     Note: In contrarian investing, Extreme Fear (<25) is a high-value BUY/DCA zone (Emerald/Teal),
     while Extreme Greed (>75) is an overheated RISK zone (Rose/Red).
     We make colors intuitive with clear labels. */
  --color-extreme-fear: #ef4444;
  --color-fear: #f97316;
  --color-neutral: #eab308;
  --color-greed: #22c55e;
  --color-extreme-greed: #10b981;

  --accent-us: #38bdf8;
  --accent-crypto: #f59e0b;
  --accent-purple: #a855f7;
}

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

body {
  background-color: var(--bg-primary);
  background-image:
    radial-gradient(circle at 12% 0%, rgba(56, 189, 248, 0.08), transparent 35%),
    radial-gradient(circle at 88% 0%, rgba(245, 158, 11, 0.08), transparent 35%);
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "SF Pro Display", "PingFang SC", "Microsoft YaHei", sans-serif;
  line-height: 1.45;
  min-height: 100vh;
  overflow-x: hidden;
}

/* Container & Layout */
.cockpit-container {
  max-width: 1640px;
  margin: 0 auto;
  padding: 14px 18px 28px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* Header Bar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  background: rgba(14, 21, 34, 0.85);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  padding: 10px 16px;
}

.brand-group {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-logo {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: linear-gradient(135deg, #0ea5e9, #f59e0b);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 16px;
  color: #070b12;
  box-shadow: 0 0 16px rgba(14, 165, 233, 0.3);
}

.brand-title h1 {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.01em;
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand-subtitle {
  font-size: 11.5px;
  color: var(--text-secondary);
}

.topbar-controls {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

/* Status Pills */
.status-group {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #64748b;
}

.status-dot.live {
  background: #10b981;
  box-shadow: 0 0 8px #10b981;
}

.status-dot.proxy {
  background: #38bdf8;
  box-shadow: 0 0 8px #38bdf8;
}

.status-dot.cache {
  background: #f59e0b;
}

/* Timeframe Selector */
.timeframe-group {
  display: inline-flex;
  background: var(--bg-primary);
  padding: 3px;
  border-radius: 8px;
  border: 1px solid var(--border-subtle);
}

.tf-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.tf-btn:hover {
  color: var(--text-primary);
}

.tf-btn.active {
  background: var(--bg-elevated);
  color: #38bdf8;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
}

.btn-refresh {
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  font-size: 12px;
  font-weight: 600;
  padding: 5px 12px;
  border-radius: 8px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  transition: all 0.15s ease;
}

.btn-refresh:hover {
  border-color: var(--accent-us);
  background: rgba(56, 189, 248, 0.12);
}

/* Macro Quick Strip */
.macro-strip {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 10px;
}

.metric-mini-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  padding: 9px 13px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 3px;
}

.metric-mini-label {
  font-size: 11px;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.metric-mini-value-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 6px;
}

.metric-mini-value {
  font-size: 17px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.metric-mini-tag {
  font-size: 11px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 4px;
}

/* Main Grid Sections */
.dual-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  position: relative;
}

.card-us {
  border-top: 2px solid rgba(56, 189, 248, 0.55);
}

.card-crypto {
  border-top: 2px solid rgba(245, 158, 11, 0.55);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.card-title-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.market-badge {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 5px;
  text-transform: uppercase;
}

.badge-us {
  background: rgba(56, 189, 248, 0.14);
  color: #38bdf8;
  border: 1px solid rgba(56, 189, 248, 0.3);
}

.badge-crypto {
  background: rgba(245, 158, 11, 0.14);
  color: #fbbf24;
  border: 1px solid rgba(245, 158, 11, 0.3);
}

.card-title {
  font-size: 14.5px;
  font-weight: 700;
}

.card-meta {
  font-size: 11.5px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 8px;
}

.card-meta a {
  color: var(--text-secondary);
  text-decoration: none;
}

.card-meta a:hover {
  color: var(--accent-us);
  text-decoration: underline;
}

/* Top Gauge + History Delta Layout */
.gauge-hero-row {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 14px;
  align-items: center;
}

.gauge-box {
  width: 220px;
  height: 165px;
  position: relative;
}

.gauge-details {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.signal-banner {
  background: var(--bg-elevated);
  border-radius: 8px;
  padding: 8px 12px;
  border-left: 3px solid var(--accent-us);
  font-size: 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.signal-banner-title {
  font-weight: 700;
  font-size: 12.5px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.signal-banner-desc {
  color: var(--text-secondary);
  font-size: 11.5px;
}

.history-compare-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.hist-item {
  background: rgba(7, 11, 18, 0.55);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  padding: 7px 9px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.hist-label {
  font-size: 11px;
  color: var(--text-secondary);
}

.hist-score-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 4px;
}

.hist-score {
  font-size: 15px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.hist-delta {
  font-size: 11px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.hist-rating-tag {
  font-size: 10.5px;
  font-weight: 600;
  margin-top: 2px;
}

/* Charts */
.chart-box-lg {
  width: 100%;
  height: 310px;
}

.chart-box-md {
  width: 100%;
  height: 270px;
}

.chart-legend-note {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 11.5px;
  color: var(--text-secondary);
  padding-top: 4px;
  border-top: 1px solid var(--border-subtle);
}

.zone-pills {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.zone-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
}

.zone-swatch {
  width: 10px;
  height: 10px;
  border-radius: 2px;
}

/* CNN 7 Sub-indicators List */
.sub-indicators-wrapper {
  display: grid;
  grid-template-columns: 1.35fr 0.85fr;
  gap: 14px;
  align-items: center;
}

.sub-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sub-item {
  background: rgba(7, 11, 18, 0.5);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  padding: 7px 11px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.sub-item-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.sub-name-group {
  display: flex;
  align-items: baseline;
  gap: 7px;
  flex-wrap: wrap;
}

.sub-name {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-primary);
}

.sub-desc {
  font-size: 11px;
  color: var(--text-muted);
}

.sub-score-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.sub-bar-track {
  width: 100%;
  height: 6px;
  background: #1e293b;
  border-radius: 999px;
  overflow: hidden;
}

.sub-bar-fill {
  height: 100%;
  border-radius: 999px;
  transition: width 0.4s ease;
}

/* Stats Table in Cross-Market Card */
.stats-matrix {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-top: 4px;
}

.stat-box {
  background: rgba(7, 11, 18, 0.5);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  padding: 8px 11px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
}

.stat-box-label {
  color: var(--text-secondary);
}

.stat-box-val {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* Sentiment Color Utilities */
.sent-extreme-fear {
  color: #f87171;
}
.sent-fear {
  color: #fb923c;
}
.sent-neutral {
  color: #facc15;
}
.sent-greed {
  color: #4ade80;
}
.sent-extreme-greed {
  color: #34d399;
}

.bg-extreme-fear {
  background: rgba(239, 68, 68, 0.16);
  color: #fca5a5;
  border: 1px solid rgba(239, 68, 68, 0.35);
}
.bg-fear {
  background: rgba(249, 115, 22, 0.16);
  color: #fdba74;
  border: 1px solid rgba(249, 115, 22, 0.35);
}
.bg-neutral {
  background: rgba(234, 179, 8, 0.16);
  color: #fde047;
  border: 1px solid rgba(234, 179, 8, 0.35);
}
.bg-greed {
  background: rgba(34, 197, 94, 0.16);
  color: #86efac;
  border: 1px solid rgba(34, 197, 94, 0.35);
}
.bg-extreme-greed {
  background: rgba(16, 185, 129, 0.16);
  color: #6ee7b7;
  border: 1px solid rgba(16, 185, 129, 0.35);
}

/* Footer */
.footer-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 11.5px;
  color: var(--text-muted);
  padding: 6px 4px;
}

/* Responsive Breakpoints */
@media (max-width: 1280px) {
  .macro-strip {
    grid-template-columns: repeat(3, 1fr);
  }
  .dual-grid {
    grid-template-columns: 1fr;
  }
  .sub-indicators-wrapper {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  .cockpit-container {
    padding: 10px;
  }
  .macro-strip {
    grid-template-columns: repeat(2, 1fr);
  }
  .gauge-hero-row {
    grid-template-columns: 1fr;
    justify-items: center;
  }
  .history-compare-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .stats-matrix {
    grid-template-columns: 1fr;
  }
}
