/* ================================================
   DIVIDENDEN-ETF DEEP DIVE — Residual Styles
   Theme-aware with CSS custom properties
   ================================================ */

/* ---- Theme Variables ---- */
:root {
  --bg-primary: #ffffff;
  --bg-secondary: #f3f4f6;
  --bg-card: #ffffff;
  --bg-hover: rgba(0, 0, 0, 0.03);
  --bg-overlay: rgba(0, 0, 0, 0.04);
  --bg-overlay-strong: rgba(0, 0, 0, 0.08);
  --text-primary: #111827;
  --text-secondary: #6b7280;
  --text-tertiary: #9ca3af;
  --text-bright: #111827;
  --text-on-accent: #ffffff;
  --border-subtle: rgba(0, 0, 0, 0.06);
  --border-normal: rgba(0, 0, 0, 0.12);
  --chart-grid: #e5e7eb;
  --chart-axis: #d1d5db;
  --chart-text: #374151;
  --chart-label: #6b7280;
  --chart-plot-line: #9ca3af;
  --chart-outline: #f3f4f6;
  --tooltip-bg: #ffffff;
  --tooltip-border: #e5e7eb;
  --select-bg: #ffffff;
  --select-text: #374151;
  --badge-bg: rgba(196, 163, 90, 0.12);
  --footnote-border: rgba(0, 0, 0, 0.06);
}

[data-theme="dark"] {
  --bg-primary: #030712;
  --bg-secondary: #0c0f14;
  --bg-card: rgba(255, 255, 255, 0.03);
  --bg-hover: rgba(255, 255, 255, 0.03);
  --bg-overlay: rgba(255, 255, 255, 0.05);
  --bg-overlay-strong: rgba(255, 255, 255, 0.1);
  --text-primary: #e8e6e1;
  --text-secondary: #8b8d94;
  --text-tertiary: #6b6e75;
  --text-bright: #e5e7eb;
  --text-on-accent: #0a0e17;
  --border-subtle: rgba(255, 255, 255, 0.05);
  --border-normal: rgba(255, 255, 255, 0.1);
  --chart-grid: #1c2230;
  --chart-axis: #232a38;
  --chart-text: #e8e6e1;
  --chart-label: #8b8d94;
  --chart-plot-line: #555a65;
  --chart-outline: #0a0e17;
  --tooltip-bg: #171c26;
  --tooltip-border: #2a3348;
  --select-bg: #1a1e2e;
  --select-text: #c9cad0;
  --badge-bg: rgba(196, 163, 90, 0.15);
  --footnote-border: rgba(255, 255, 255, 0.05);
}

/* ---- Noise Texture Overlay ---- */
:root .noise-overlay {
  display: none;
}

[data-theme="dark"] .noise-overlay {
  display: block;
}

.noise-overlay {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 9999;
  opacity: 0.025;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  background-repeat: repeat;
  background-size: 256px 256px;
}

/* ---- Chart Container Heights ---- */
.chart-container {
  width: 100%;
  height: 380px;
}

.chart-container-full {
  height: 420px;
}

@media (max-width: 640px) {
  .chart-container { height: 300px; }
  .chart-container-full { height: 320px; }
}

/* ---- Loading State ---- */
.chart-container.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  font-size: 0.875rem;
}

.chart-container.loading::after {
  content: 'Daten werden geladen...';
  animation: pulse 1.5s ease-in-out infinite;
}

/* ---- Animations ---- */
@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

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

/* ---- Update Button ---- */
.update-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 6px;
  background: var(--bg-overlay);
  color: var(--text-secondary);
  font-size: 16px;
  cursor: pointer;
  transition: color 0.15s, background 0.15s;
}

.update-btn:hover {
  color: var(--text-primary);
  background: var(--bg-overlay-strong);
}

.update-btn.updating {
  animation: spin 1s linear infinite;
  pointer-events: none;
  color: var(--color-accent);
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

/* ---- Highcharts Theme Overrides ---- */
.highcharts-background {
  fill: transparent;
}

.highcharts-tooltip-box {
  fill: var(--tooltip-bg);
  stroke: var(--border-normal);
}

.highcharts-button-box {
  fill: var(--tooltip-bg);
  stroke: var(--border-normal);
}

/* ---- Toggle Buttons ---- */
.chart-toggle {
  display: inline-flex;
  gap: 2px;
  margin-top: 0.75rem;
  background: var(--bg-overlay);
  border-radius: 6px;
  padding: 2px;
  ring: 1px inset rgba(255, 255, 255, 0.1);
}

#strategyToggle {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin-top: 0;
}

#strategyToggle .toggle-btn {
  white-space: nowrap;
}

.toggle-btn {
  font-size: 0.75rem;
  font-weight: 500;
  padding: 4px 12px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  border-radius: 4px;
  transition: all 0.2s ease;
}

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

.toggle-btn.active {
  background: var(--color-accent);
  color: var(--text-on-accent);
  font-weight: 600;
}

/* ---- ETF Data Table ---- */
.etf-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8125rem;
}

.etf-table th {
  padding: 0.75rem 1rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  font-size: 0.6875rem;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border-normal);
  white-space: nowrap;
}

.etf-table td {
  padding: 0.625rem 1rem;
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text-primary);
}

.etf-table tbody tr:hover {
  background: var(--bg-hover);
}

.etf-table .rank-cell {
  text-align: center;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}

.etf-table .name-cell {
  max-width: 280px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 500;
  color: var(--text-bright);
}

.etf-table .isin-cell {
  font-family: ui-monospace, SFMono-Regular, monospace;
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.strategy-badge {
  display: inline-block;
  padding: 0.125rem 0.5rem;
  border-radius: 9999px;
  font-size: 0.6875rem;
  font-weight: 500;
  background: var(--badge-bg);
  color: #c4a35a;
}

.loading-cell {
  text-align: center;
  padding: 2rem 1rem;
  color: var(--text-secondary);
}

/* ---- Tab Navigation ---- */
.tab-btn {
  font-size: 0.8125rem;
  font-weight: 500;
  padding: 6px 16px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  border-radius: 6px;
  transition: all 0.2s ease;
}

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

.tab-btn.active {
  background: var(--color-accent);
  color: var(--text-on-accent);
  font-weight: 600;
}

/* ---- ETF List Filter Select ---- */
.etf-filter-select {
  background: var(--bg-overlay);
  border: 1px solid var(--border-normal);
  border-radius: 6px;
  padding: 4px 28px 4px 10px;
  font-size: 0.75rem;
  color: var(--select-text);
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%238b8d94' d='M3 5l3 3 3-3'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
}

.etf-filter-select:focus {
  outline: none;
  border-color: var(--color-accent);
}

.etf-filter-select option {
  background: var(--select-bg);
  color: var(--select-text);
}

/* ---- Chart Footnotes ---- */
.chart-footnote {
  margin-top: 0.5rem;
  padding-top: 0.375rem;
  border-top: 1px solid var(--footnote-border);
  font-size: 0.6875rem;
  color: var(--text-tertiary);
  text-align: right;
}

/* ---- Theme Toggle ---- */
.theme-toggle {
  display: inline-flex;
  gap: 2px;
  background: var(--bg-overlay);
  border-radius: 6px;
  padding: 2px;
}

.theme-toggle button {
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 4px;
  background: transparent;
  color: var(--text-secondary);
  font-size: 14px;
  cursor: pointer;
  transition: color 0.15s, background 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.theme-toggle button:hover {
  color: var(--text-primary);
}

.theme-toggle button.active {
  background: var(--bg-overlay-strong);
  color: var(--text-bright);
}
