/* Rule-based forecast controls and explanations share the current theme. */
#priceChart {
  --forecast-line: var(--blue);
  --forecast-band: var(--blue-bg);
  --forecast-region: var(--surface-soft);
}
.forecast-panel {
  min-width: 0;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-gradient);
  color: var(--text);
  overflow-wrap: anywhere;
}

.forecast-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 16px;
}

.forecast-head h3 { min-width: 0; margin: 0; font-size: 15px; line-height: 1.6; }
.forecast-bias {
  max-width: 100%;
  padding: 4px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-raised);
  color: var(--body-copy);
  font-size: 11px;
  line-height: 1.6;
}

.forecast-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px 14px;
  margin-bottom: 14px;
}

.forecast-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  max-width: 100%;
  color: var(--body-copy);
  font-size: 12px;
  line-height: 1.7;
  cursor: pointer;
}

.forecast-toggle input { flex: 0 0 16px; width: 16px; height: 16px; margin: 0; accent-color: var(--accent); }
.forecast-toggle span { min-width: 0; }
.forecast-controls select {
  min-width: 0;
  max-width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border-strong);
  border-radius: 7px;
  background: var(--surface);
  color: var(--text);
  font-size: 12px;
}

.forecast-summary { margin: 0 0 14px; color: var(--body-copy); font-size: 13px; line-height: 1.8; }

.forecast-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 14px;
}

.forecast-stat {
  min-width: 0;
  padding: 12px;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: var(--surface-soft);
}

.forecast-stat span { display: block; color: var(--muted); font-size: 11px; line-height: 1.6; }
.forecast-stat strong { display: block; margin-top: 6px; color: var(--text); font-size: 14px; line-height: 1.6; }

.forecast-drivers {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.forecast-driver {
  min-width: 0;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--surface-soft);
}

.forecast-driver > strong { display: block; font-size: 12px; line-height: 1.6; }
.forecast-driver > span { display: block; margin-top: 5px; color: var(--muted); font-size: 11px; line-height: 1.6; }
.forecast-driver > p { margin: 8px 0 0; color: var(--body-copy); font-size: 12px; line-height: 1.75; }
.forecast-driver[data-signal="positive"] > span { color: var(--danger); }
.forecast-driver[data-signal="negative"] > span { color: var(--accent); }

.forecast-news { min-width: 0; margin-top: 18px; }
.forecast-news h4 { margin: 0 0 8px; font-size: 13px; line-height: 1.7; }
.forecast-news > p { margin: 0 0 8px; color: var(--muted); font-size: 12px; line-height: 1.75; }
.forecast-news-item {
  display: block;
  width: 100%;
  min-width: 0;
  margin: 0;
  padding: 11px 0;
  border: 0;
  border-bottom: 1px solid var(--line-soft);
  background: transparent;
  color: var(--body-copy);
  text-align: left;
  overflow-wrap: anywhere;
  font-size: 12px;
  line-height: 1.75;
  cursor: pointer;
}

.forecast-news-item:last-child { border-bottom: 0; }
.forecast-news-item:hover { color: var(--accent); }
.forecast-news-item strong { color: var(--text); }
.forecast-news-item span, .forecast-news-item small { color: var(--muted); }
.forecast-news-item:focus-visible { border-radius: 5px; outline-offset: 3px; }
.forecast-news-item p { margin: 5px 0 0; color: var(--muted); font-size: 11px; line-height: 1.7; }

.forecast-notice {
  margin: 16px 0 0;
  padding-top: 12px;
  border-top: 1px solid var(--line-soft);
  color: var(--muted);
  font-size: 11px;
  line-height: 1.8;
}
.forecast-method { margin-top: 16px; }
.forecast-method > summary { color: var(--muted); font-size: 12px; line-height: 1.8; cursor: pointer; }

.forecast-panel .empty-state { margin: 0; padding: 10px 0; }
.forecast-stats:empty, .forecast-drivers:empty, .forecast-news:empty { display: none; }

.forecast-legend {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px 16px;
  min-width: 0;
  padding: 10px 22px 14px;
  color: var(--muted);
  overflow-wrap: anywhere;
  font-size: 11px;
  line-height: 1.7;
}

.forecast-legend > span { display: inline-flex; align-items: center; gap: 6px; min-width: 0; }
.forecast-legend .legend-line { flex: 0 0 20px; width: 20px; height: 0; border-top: 2px solid var(--chart-label); }
.forecast-legend .legend-line.is-forecast { border-top-style: dashed; border-top-color: var(--blue); }
.forecast-legend .legend-band { flex: 0 0 20px; width: 20px; height: 10px; border: 1px solid var(--line); border-radius: 2px; background: var(--blue-bg); }
.forecast-legend[hidden] { display: none; }

.backtest-panel { min-width: 0; margin-block: 18px; padding-block: 16px; border-block: 1px solid var(--line); }
.backtest-head { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px; }
.backtest-head h4 { margin: 0; font-size: 14px; }
.backtest-head .ghost-btn { font-size: 12px; padding: 8px 12px; }
.backtest-status { margin: 12px 0; color: var(--muted); font-size: 12px; line-height: 1.8; overflow-wrap: anywhere; }
.backtest-results { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.backtest-results:empty { display: none; }
.backtest-card { min-width: 0; padding: 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-soft); }
.backtest-card h5 { margin: 0 0 10px; font-size: 12px; }
.backtest-card dl { margin: 0; display: grid; gap: 12px; }
.backtest-card dt, .backtest-card p, .backtest-card summary { color: var(--muted); font-size: 11px; line-height: 1.7; overflow-wrap: anywhere; }
.backtest-card dd { margin: 3px 0 0; color: var(--text); font-size: 13px; font-variant-numeric: tabular-nums; }
.backtest-card small { display: block; margin-top: 3px; color: var(--muted); font-size: 11px; line-height: 1.5; }
.backtest-card .backtest-skipped { margin: 12px 0 0; }
.backtest-card details { margin-top: 8px; }
.backtest-card summary { cursor: pointer; }
@media (max-width: 640px) { .backtest-results { grid-template-columns: minmax(0, 1fr); } .backtest-card dl { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

@media (max-width: 700px) {
  .forecast-panel { padding: 16px; }
  .forecast-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .forecast-stat:last-child:nth-child(odd) { grid-column: 1 / -1; }
  .forecast-drivers { grid-template-columns: minmax(0, 1fr); }
  .forecast-legend { padding: 10px 16px 12px; gap: 6px 12px; }
}

@media (max-width: 400px) {
  .forecast-panel { padding: 14px; }
  .forecast-stats { grid-template-columns: minmax(0, 1fr); }
  .forecast-controls { align-items: flex-start; }
  .forecast-legend { padding-inline: 14px; }
}
