/* Performance-Heatmaps auf der Makro-Seite (Ä-68, macro/_heatmap.html): Megasektoren und
   Sektoren nebeneinander, darunter die Industrien in aufklappbaren Gruppen (≤ 1100 px alles
   untereinander). Formensprache der Marktampel: kleine Gruppenüberschriften, ruhige Kacheln mit
   Abstand statt Trennlinien. Zellfarbe divergierend aus den Richtungsfarben (DESIGN 2.3:
   Verlust --neg, Gewinn --pos) in vier Stufen je Richtung, neutral um 0; die Zahl steht immer in
   der Zelle, der Text bleibt --text-1 auf allen Stufen. Grau: zu wenige Aktien. */

.heat-card {
  --heat-pos-rgb: 90, 186, 102;
  --heat-neg-rgb: 216, 78, 90;
  margin-bottom: var(--grid-gap);
}

.heat-card__skeleton {
  max-width: 640px;
}

.heat-card__body {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: var(--space-6) var(--space-8);
  align-items: start;
}

.heat-group {
  min-width: 0;
}

.heat-group--wide {
  grid-column: 1 / -1;
}

.heat-group__title {
  margin: 0 0 var(--space-2);
  font: var(--text-h3);
}

.heat-group__note {
  color: var(--text-2);
  font-weight: 400;
}

.heat-group__bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2) var(--space-4);
  margin-bottom: var(--space-2);
}

.heat-group__bar .heat-group__title {
  margin: 0;
}

.heat-search__input {
  width: 220px;
  max-width: 100%;
}

.heat-search__none {
  margin: var(--space-3) 0 0;
  color: var(--text-2);
  font: var(--text-label);
}

.heat-card__note {
  margin: var(--space-5) 0 0;
  color: var(--text-2);
  font: var(--text-label);
}

/* --- Tabelle --------------------------------------------------------------------------------- */

.heat {
  width: 100%;
  border-collapse: separate;
  border-spacing: 3px;
  table-layout: fixed;
  font: var(--text-table);
}

.heat__col-name {
  width: 38%;
}

.heat__head {
  padding: 0 0 var(--space-1);
  color: var(--text-2);
  font: var(--text-label);
  text-align: center;
}

.heat thead .heat__name {
  padding: 0 0 var(--space-1);
  color: var(--text-2);
  font: var(--text-label);
  text-align: left;
}

.heat__name {
  overflow: hidden;
  padding: 4px var(--space-2) 4px 0;
  font-weight: 500;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.heat__link,
.heat__label {
  color: var(--text-1);
  text-decoration: none;
}

.heat__link:hover,
.heat__link:focus-visible {
  color: var(--accent);
  text-decoration: underline;
}

.heat__sub {
  display: block;
  overflow: hidden;
  color: var(--text-3);
  font: var(--text-label);
  font-weight: 400;
  text-overflow: ellipsis;
}

.heat__block-head th {
  padding: var(--space-3) 0 2px;
  color: var(--text-2);
  font: var(--text-label);
  letter-spacing: 0.04em;
  text-align: left;
  text-transform: uppercase;
}

.heat__block:first-of-type .heat__block-head th {
  padding-top: 0;
}

/* Eine Zelle: Rendite groß, Aktienzahl klein darunter. */
.heat__cell {
  padding: 5px 4px;
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--text-1);
  text-align: center;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  cursor: default;
}

.heat__value {
  display: block;
  font-weight: 600;
}

.heat__count {
  display: block;
  color: var(--text-2);
  font-size: 0.6875rem;
  line-height: 0.875rem;
}

.heat--pos-1 { background: rgba(var(--heat-pos-rgb), 0.14); }
.heat--pos-2 { background: rgba(var(--heat-pos-rgb), 0.26); }
.heat--pos-3 { background: rgba(var(--heat-pos-rgb), 0.38); }
.heat--pos-4 { background: rgba(var(--heat-pos-rgb), 0.52); }
.heat--neg-1 { background: rgba(var(--heat-neg-rgb), 0.14); }
.heat--neg-2 { background: rgba(var(--heat-neg-rgb), 0.26); }
.heat--neg-3 { background: rgba(var(--heat-neg-rgb), 0.38); }
.heat--neg-4 { background: rgba(var(--heat-neg-rgb), 0.52); }

.heat--flat {
  background: var(--surface-3);
}

.heat--pos-3 .heat__count,
.heat--pos-4 .heat__count,
.heat--neg-3 .heat__count,
.heat--neg-4 .heat__count {
  color: var(--text-1);
}

/* Zu wenige Aktien: grau und gedämpft, die Zahl der Aktien bleibt lesbar. */
.heat--none {
  background: transparent;
  box-shadow: inset 0 0 0 1px var(--border-subtle);
  color: var(--text-3);
}

/* --- Industrien: Sortierköpfe und aufklappbare Gruppen ----------------------------------------- */

.heat--header {
  margin-bottom: var(--space-1);
}

.heat__sort {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 2px 6px;
  border: 0;
  border-radius: var(--r-pill);
  background: transparent;
  color: inherit;
  font: inherit;
  cursor: pointer;
}

.heat__sort:hover,
.heat__sort:focus-visible {
  background: var(--surface-pill-hover);
  color: var(--text-1);
}

.heat__sort-icon {
  width: 12px;
  height: 12px;
  opacity: 0;
  transition: transform var(--ease), opacity var(--ease);
}

.heat__head[aria-sort="ascending"] .heat__sort,
.heat__head[aria-sort="descending"] .heat__sort {
  color: var(--accent);
}

.heat__head[aria-sort="ascending"] .heat__sort-icon {
  opacity: 1;
}

.heat__head[aria-sort="descending"] .heat__sort-icon {
  opacity: 1;
  transform: rotate(180deg);
}

.heat-fold {
  border-top: 1px solid var(--border-subtle);
}

.heat-fold__summary {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) 0;
  font-weight: 500;
  cursor: pointer;
  list-style: none;
}

.heat-fold__summary::-webkit-details-marker {
  display: none;
}

.heat-fold__summary:hover {
  color: var(--accent);
}

.heat-fold__icon {
  flex: none;
  width: 14px;
  height: 14px;
  color: var(--text-2);
  transform: rotate(90deg);
  transition: transform var(--ease);
}

.heat-fold[open] .heat-fold__icon {
  transform: rotate(180deg);
}

.heat-fold__name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.heat-fold__count {
  margin-left: auto;
  color: var(--text-2);
  font: var(--text-label);
}

.heat-fold > .heat {
  margin-bottom: var(--space-2);
}

/* --- Tooltip je Zelle (pages/macro_heatmap.js, fest positioniert) ------------------------------ */

.heat-tip {
  position: fixed;
  z-index: var(--z-menu);
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-width: min(320px, calc(100vw - 24px));
  min-width: 0;
  pointer-events: none;
}

.heat-tip[hidden] {
  display: none;
}

.heat-tip__title {
  color: var(--text-2);
}

.heat-tip__value {
  color: var(--text-1);
  font-weight: 600;
}

.heat-tip__top {
  color: var(--text-2);
}

@media (max-width: 1100px) {
  .heat-card__body {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (max-width: 600px) {
  .heat {
    border-spacing: 2px;
  }

  .heat__col-name {
    width: 32%;
  }

  /* Schmale Namensspalte: Namen umbrechen statt abschneiden, die deutsche Unterzeile entfällt. */
  .heat__name {
    overflow-wrap: anywhere;
    font-size: 0.75rem;
    line-height: 1.2;
    text-overflow: clip;
    white-space: normal;
    hyphens: auto;
  }

  .heat__sub {
    display: none;
  }

  .heat__cell {
    padding: 4px 1px;
    font-size: 0.75rem;
  }

  .heat__sort {
    padding: 2px;
  }

  .heat__sort-icon {
    display: none;
  }

  .heat-search__input {
    width: 100%;
  }

  .heat-search {
    flex: 1 1 100%;
  }
}
