/* Chart colors share the page theme; each daily close stays a visible turn. */
:root {
  --chart-line: #68abff;
  --chart-ma5: #e2e8f0;
  --chart-ma10: #f3c954;
  --chart-ma20: #d68cfa;
  --chart-crosshair: #8296ae;
}

:root[data-theme="light"] {
  --chart-line: #2563c9;
  --chart-ma5: #475569;
  --chart-ma10: #9f7105;
  --chart-ma20: #9753c4;
  --chart-crosshair: #698097;
}

.chart-type-tabs {
  display: inline-flex;
  flex: 0 0 auto;
  gap: 3px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}
.chart-type-tabs button {
  min-height: 28px;
  padding: 5px 12px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
  white-space: nowrap;
  cursor: pointer;
}
.chart-type-tabs button:hover { color: var(--text); background: var(--surface-hover); }
.chart-type-tabs button[aria-pressed="true"] { color: var(--text); background: var(--selected-bg); font-weight: 700; }
.chart-type-tabs button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.chart-actions .period-tabs { flex-wrap: wrap; gap: 2px; max-width: 100%; }
.chart-actions .period-tabs button { flex: 1 0 auto; white-space: nowrap; min-height: 28px; }
.chart-adjustment { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 11px; white-space: nowrap; }
.chart-adjustment select {
  min-height: 32px;
  padding: 5px 8px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface-soft);
  color: var(--text);
  font: inherit;
  cursor: pointer;
}
.chart-adjustment select:disabled { opacity: .55; cursor: default; }
.chart-adjustment select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.volume-stage { min-width: 0; padding: 0 14px 6px; border-top: 1px solid var(--line-soft); }
.volume-header { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 14px; padding: 8px 12px 0; color: var(--muted); font-size: 11px; line-height: 1.8; font-variant-numeric: tabular-nums; }
.volume-header strong { color: var(--body-copy); font-weight: 500; }
#volumeChart { display: block; width: 100%; height: 110px; }
.volume-status { margin: 0; padding: 0 12px 4px; color: var(--muted-2); font-size: 10px; line-height: 1.7; overflow-wrap: anywhere; }

.chart-market-strip {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 7px 20px;
  padding: 11px 22px;
  border-block: 1px solid var(--line-soft);
  background: var(--surface-soft);
  font-variant-numeric: tabular-nums;
}
.chart-readout {
  display: flex;
  flex: 1 1 auto;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 14px;
  min-width: 0;
  min-height: 20px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.8;
}
.chart-readout .readout-date { color: var(--text); font-weight: 650; white-space: nowrap; }
.chart-readout > span { white-space: nowrap; }
.chart-readout b { color: var(--text); font-weight: 650; }
.chart-ma-legend {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 14px;
  font-size: 11px;
  line-height: 1.8;
}
.chart-ma-legend[hidden] { display: none; }
.chart-ma-legend > span { display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; }
.chart-ma-legend > span::before { content: ""; width: 13px; height: 0; border-top: 2px solid currentColor; }
.chart-ma-legend .ma5 { color: var(--chart-ma5); }
.chart-ma-legend .ma10 { color: var(--chart-ma10); }
.chart-ma-legend .ma20 { color: var(--chart-ma20); }
.forecast-legend .legend-line.is-close { border-top-color: var(--chart-line); }
.chart-stage { --chart-stage-padding: 14px; padding-inline: var(--chart-stage-padding); }
#priceChart { touch-action: pan-y; cursor: grab; }
#priceChart.is-panning, .chart-stage.is-panning #priceChart { cursor: grabbing; }
#priceChart:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
#chartCursor {
  position: absolute;
  top: 0;
  left: var(--chart-stage-padding);
  z-index: 2;
  display: block;
  width: calc(100% - var(--chart-stage-padding) * 2);
  height: 100%;
  pointer-events: none;
}
.chart-mode-notice {
  margin: 0;
  padding: 8px 22px 13px;
  color: var(--muted-2);
  font-size: 11px;
  line-height: 1.7;
  overflow-wrap: anywhere;
}
.chart-navigation {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
  padding: 10px 22px 4px;
}
.chart-viewport-status {
  margin: 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.7;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}
.chart-navigation-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  min-width: 0;
}
.chart-navigation button {
  flex: 0 0 auto;
  min-height: 30px;
  padding: 5px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 11px;
  line-height: 1.6;
  white-space: nowrap;
  cursor: pointer;
}
.chart-navigation button:hover { color: var(--text); background: var(--surface-hover); }
.chart-navigation button:focus-visible, #chartHistoryRange:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.chart-navigation button:disabled { opacity: .45; cursor: default; }
.chart-zoom-controls { display: inline-flex; flex: 0 0 auto; gap: 4px; }
.chart-history-slider {
  display: flex;
  flex: 1 1 250px;
  align-items: center;
  gap: 8px;
  min-width: 120px;
  color: var(--muted-2);
  font-size: 10px;
  white-space: nowrap;
}
#chartHistoryRange {
  flex: 1 1 auto;
  min-width: 0;
  width: 100%;
  height: 24px;
  margin: 0;
  accent-color: var(--accent);
  direction: rtl;
  cursor: ew-resize;
}
#chartHistoryRange:disabled { opacity: .45; cursor: default; }

/* Point markers stay on the curve; their readable news summaries sit below it. */
#chartAnnotations[hidden], #eventTimeline[hidden], #showMoreNewsBtn[hidden] { display: none; }
#showMoreNewsBtn { margin: 0 16px 16px; }
.chart-annotations { padding-top: 14px; }
#chartTooltip { width: min(340px, calc(100vw - 24px)); }
#chartTooltip .tooltip-date { font-size: 11px; line-height: 1.6; }
#chartTooltip .tooltip-event strong { font-size: 13px; line-height: 1.65; }
#chartTooltip .tooltip-event span { font-size: 11px; line-height: 1.6; }
.chart-news-summary {
  margin: 0;
  padding: 16px 22px 10px;
  border-top: 1px solid var(--line-soft);
  color: var(--muted);
  font-size: 12px;
  line-height: 1.7;
  overflow-wrap: anywhere;
}

.chart-news-summary.is-empty { color: var(--muted-2); }

.chart-annotations {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  padding: 0 20px 20px;
}

.chart-annotations:empty { padding-bottom: 14px; }

.chart-annotation-card {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  min-width: 0;
  width: 100%;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--surface-soft);
  color: var(--text);
  text-align: left;
  cursor: pointer;
  overflow-wrap: anywhere;
  transition: background-color .16s ease, border-color .16s ease;
}

.chart-annotation-card:hover { background: var(--surface-hover); border-color: var(--border-strong); }
.chart-annotation-card.is-active { border-color: var(--accent); background: var(--selected-bg); }
.chart-annotation-card.is-empty { border-style: dashed; }
.chart-annotation-card:focus-visible { outline-offset: 3px; }

.annotation-top {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 5px 8px;
  min-width: 0;
  line-height: 1.5;
}

.annotation-kind {
  padding: 2px 6px;
  border-radius: 5px;
  background: var(--warning-bg);
  color: var(--warning);
  font-size: 11px;
  font-weight: 700;
}

.annotation-date { color: var(--muted); font-size: 11px; }
.annotation-move { margin-left: auto; font-size: 11px; font-weight: 700; color: var(--body-copy); }

.annotation-title {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
  font-size: 13px;
  line-height: 1.65;
}

.annotation-summary {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
  margin: 0;
  color: var(--body-copy);
  font-size: 12px;
  line-height: 1.7;
}

.annotation-meta { color: var(--muted); font-size: 11px; line-height: 1.6; }
.annotation-link { margin-top: auto; padding-top: 2px; color: var(--accent); font-size: 11px; line-height: 1.6; }
.chart-annotation-card.is-empty .annotation-link { color: var(--muted); }

.chart-markers {
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
}

.chart-marker {
  position: absolute;
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  padding: 6px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--warning);
  transform: translate(-50%, -50%);
  pointer-events: auto;
  cursor: pointer;
  touch-action: manipulation;
}

.marker-number {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border: 1px solid var(--chart-event);
  border-radius: 50%;
  background: var(--panel);
  box-shadow: 0 0 0 3px var(--chart-event-halo);
  font-size: 11px;
  font-weight: 800;
  line-height: 1;
}

.chart-marker:hover, .chart-marker.is-active { z-index: 2; }
.chart-marker:hover .marker-number, .chart-marker.is-active .marker-number {
  background: var(--warning);
  color: var(--bg);
  border-color: var(--warning);
}
.chart-marker.is-empty .marker-number { border-style: dashed; }
.chart-marker:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

@media (max-width: 700px) {
  .chart-actions { justify-content: flex-start; gap: 8px; }
  .chart-actions .ghost-btn { flex: 0 0 auto; }
  .chart-market-strip { padding: 10px 16px; gap: 5px 14px; }
  .chart-readout { gap: 3px 12px; }
  .chart-stage { --chart-stage-padding: 6px; }
  .volume-stage { padding-inline: 6px; }
  #volumeChart { height: 90px; }
  .chart-mode-notice { padding: 8px 16px 12px; }
  .chart-navigation { padding-inline: 16px; }
  .chart-navigation-controls { gap: 7px 8px; }
  .chart-news-summary { padding: 14px 16px 10px; }
  .chart-annotations { grid-template-columns: minmax(0, 1fr); padding: 0 16px 16px; }
  .chart-annotation-card { padding: 12px; }
}

@media (max-width: 400px) {
  .chart-actions .chart-type-tabs { flex: 1 1 auto; }
  .chart-type-tabs button { flex: 1 1 auto; }
  .chart-market-strip, .chart-mode-notice { padding-inline: 14px; }
  .chart-navigation { padding-inline: 14px; }
  .chart-history-slider { flex-basis: 100%; order: 1; }
  #chartLatestBtn { margin-left: auto; }
  .chart-news-summary { padding-inline: 14px; }
  .chart-annotations { padding-inline: 14px; }
}

@media (prefers-reduced-motion: reduce) {
  .chart-annotation-card { transition: none; }
}
