/* ═══════════════════════════════════════════════════════════
   CHARTS — Line chart & Pie chart
   ═══════════════════════════════════════════════════════════ */

/* ── Portfolio line chart ── */
.chart-container {
  position: relative;
  width: calc(100% + var(--page-px) * 2);
  margin: 12px calc(var(--page-px) * -1) 24px;
  min-height: 180px;
}

.chart-container canvas {
  display: block;
  width: 100%;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

.chart-empty-state {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  color: var(--text-tertiary);
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0;
  pointer-events: none;
}

.chart-container.no-data {
  min-height: 96px;
  margin-top: 4px;
  margin-bottom: 12px;
}

.chart-container.no-data canvas {
  display: none;
}

.chart-container.no-data .chart-empty-state {
  display: flex;
}

/* ── Time period toggles ── */
.chart-periods {
  display: flex;
  justify-content: center;
  gap: 2px;
  padding: 4px 0 0;
}

.chart-period-btn {
  padding: 5px 13px;
  border: 1px solid transparent;
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--text-tertiary);
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.02em;
  cursor: pointer;
  transition: background var(--motion-normal, 0.26s) var(--ease), color var(--motion-normal, 0.26s) var(--ease), transform var(--motion-fast, 0.18s) var(--ease), border-color var(--motion-normal, 0.26s) var(--ease);
}

.chart-period-btn:active {
  transform: scale(0.92);
}

.chart-period-btn.active {
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(255, 255, 255, 0.1);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
  color: #ffffff;
}

/* ── View toggle (chart / allocation) ── */
.view-toggle {
  display: flex;
  background: rgba(255, 255, 255, 0.04);
  backdrop-filter: blur(20px);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: var(--radius-20);
  padding: 4px;
  margin-bottom: 16px;
}

.view-toggle-btn {
  flex: 1;
  padding: 8px 0;
  border: none;
  border-radius: var(--radius-12);
  background: transparent;
  color: var(--text-secondary);
  font-family: var(--heading); font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em;
  cursor: pointer;
  transition: all 0.25s var(--ease-out);
}

.view-toggle-btn.active {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text);
  box-shadow: 0 2px 10px rgba(0,0,0,0.2), inset 0 1px 1px rgba(255,255,255,0.05);
}

/* ── Pie chart ── */
.pie-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px 0;
}

.pie-canvas-wrap {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 240px;
  margin: 0 auto 24px;
}

.pie-legend {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.pie-legend-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.pie-legend-item:last-child {
  border-bottom: none;
}

.pie-legend-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.pie-legend-ticker {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  flex: 1;
}

.pie-legend-pct {
  font-family: var(--heading); font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--text-secondary);
  min-width: 48px;
  text-align: right;
}

.pie-legend-val {
  font-family: var(--heading); font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--text-tertiary);
  min-width: 72px;
  text-align: right;
}

/* ── Chart scrub tooltip ── */
.chart-scrub-tooltip {
  position: absolute;
  top: 0;
  left: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-12);
  padding: 6px 12px;
  pointer-events: none;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity var(--motion-fast, 0.18s) var(--ease), transform var(--motion-fast, 0.18s) var(--ease);
  z-index: 10;
  white-space: nowrap;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}

[data-theme="light"] .chart-scrub-tooltip {
  background: #ffffff;
  border: 1px solid rgba(0,0,0,0.08);
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.chart-scrub-tooltip.visible {
  opacity: 1;
  transform: translateY(0);
}

.scrub-price {
  font-family: var(--mono);
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.2;
}

.scrub-date {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--text-secondary);
  line-height: 1.2;
  margin-top: 2px;
}

/* ── Theme toggle button ── */
.theme-toggle {
  width: 32px;
  height: 32px;
  border: none;
  border-radius: var(--radius-12);
  background: var(--surface);
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s var(--ease), transform 0.2s var(--ease-out), color 0.2s var(--ease);
}

.theme-toggle:active {
  transform: scale(0.88);
}

.theme-toggle svg {
  width: 16px;
  height: 16px;
}

.chart-container.loading {
  opacity: 0.5;
  pointer-events: none;
  animation: pulse 1.5s infinite;
}

@keyframes pulse {
  0% { opacity: 0.4; }
  50% { opacity: 0.6; }
  100% { opacity: 0.4; }
}

[data-theme="light"] .chart-period-btn {
  color: var(--text-secondary);
}
[data-theme="light"] .chart-period-btn.active {
  color: var(--text);
  background: rgba(0,0,0,0.07);
}

/* ── Light mode overrides ── */
[data-theme="light"] .chart-container {
  background: transparent;
  --chart-line-gain: var(--gain);
  --chart-line-loss: var(--loss);
  --chart-crosshair: rgba(0,0,0,0.15);
  --chart-axis-label: var(--text-tertiary);
  --chart-grid-line: rgba(0,0,0,0.06);
}
[data-theme="light"] .chart-container canvas {
  background: transparent;
}

[data-theme="light"] .chart-period-btn {
  color: var(--text-secondary);
}
[data-theme="light"] .chart-period-btn.active {
  background: #ffffff;
  border-color: rgba(0,0,0,0.08);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.9);
  color: var(--text);
}

[data-theme="light"] .view-toggle {
  background: rgba(0,0,0,0.03);
  border-color: rgba(0,0,0,0.08);
}
[data-theme="light"] .view-toggle-btn {
  color: var(--text-secondary);
}
[data-theme="light"] .view-toggle-btn.active {
  background: #ffffff;
  color: var(--text);
  box-shadow: 0 2px 10px rgba(0,0,0,0.08), inset 0 1px 1px rgba(255,255,255,0.9);
}

[data-theme="light"] .pie-legend-item {
  border-bottom-color: rgba(0,0,0,0.08);
}
[data-theme="light"] .pie-legend-ticker {
  color: var(--text);
}
[data-theme="light"] .pie-legend-pct {
  color: var(--text-secondary);
}
[data-theme="light"] .pie-legend-val {
  color: var(--text-tertiary);
}

[data-theme="light"] .chart-scrub-tooltip {
  background: #ffffff;
  border-color: rgba(0,0,0,0.08);
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}
[data-theme="light"] .scrub-price {
  color: var(--text);
}
[data-theme="light"] .scrub-date {
  color: var(--text-secondary);
}
