/* ================================
   PORTFOLIO SECTION
   ================================ */

/* Tighten the gap between What You Get and Portfolio */
.what-you-get-section {
  padding-bottom: 44px !important;
}

#portfolio.page-section {
  padding: 36px 0 112px !important;
  text-align: center;
}

#portfolio.page-section > h2 {
  margin: 0 0 26px !important;
  color: var(--hm-text);
  font-family: var(--font-display);
  font-size: clamp(2.6rem, 5vw, 4.7rem);
  font-weight: 600;
  line-height: 1.05;
  letter-spacing: -0.04em;
}

.portfolio-toggle-row {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 26px;
  margin: 0 auto 48px !important;
  flex-wrap: wrap;
}

.portfolio-toggle-label {
  color: var(--hm-text) !important;
  font-weight: 900;
  font-size: 1.34rem !important;
  letter-spacing: -0.02em;
  text-transform: none;
}

.portfolio-switch {
  position: relative;
  display: inline-block;
  width: 68px;
  height: 36px;
}

.portfolio-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.portfolio-slider {
  position: absolute;
  inset: 0;
  cursor: pointer;
  border: 1px solid rgba(212, 175, 55, 0.22);
  border-radius: 999px;
  background: rgba(5, 7, 13, 0.62);
  transition: 200ms ease;
}

.portfolio-slider::before {
  content: "";
  position: absolute;
  left: 4px;
  top: 4px;
  width: 26px;
  height: 26px;
  border-radius: 999px;
  background: var(--hm-gold);
  box-shadow: 0 0 18px rgba(212, 175, 55, 0.35);
  transition: 200ms ease;
}

.portfolio-switch input:checked + .portfolio-slider {
  background: rgba(212, 175, 55, 0.14);
}

.portfolio-switch input:checked + .portfolio-slider::before {
  transform: translateX(31px);
}

/* ================================
   SUMMARY CARDS
   ================================ */

.portfolio-summary {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 18px;
  margin-bottom: 28px;
}

.summary-card {
  min-height: 170px;
  padding: 24px;
  text-align: left;
  border: 1px solid var(--hm-border);
  border-radius: 22px;
  background:
    radial-gradient(
      circle at 86% 12%,
      rgba(212, 175, 55, 0.08),
      transparent 28%
    ),
    linear-gradient(180deg, rgba(22, 34, 56, 0.88), rgba(11, 18, 32, 0.96));
  box-shadow: var(--hm-shadow-soft);
}

.summary-label {
  color: var(--hm-muted);
  font-size: 0.74rem;
  font-weight: 800;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.summary-value {
  margin-top: 12px;
  color: var(--hm-text);
  font-size: clamp(1.5rem, 2.6vw, 2.6rem);
  font-weight: 800;
  letter-spacing: -0.045em;
  line-height: 1.02;
}

.summary-value.positive,
.positive {
  color: #22c55e !important;
}

.summary-value.negative,
.negative {
  color: #ef4444 !important;
}

.summary-sub {
  margin-top: 8px;
  color: var(--hm-faint);
  font-size: 0.88rem;
}

/* ================================
   CHART LAYOUT
   ================================ */

.chart-section-container {
  display: grid;
  grid-template-columns: 1fr;
  gap: 28px;
  align-items: start;
}

.allocation-chart-wrapper,
.performance-chart-wrapper,
.holdings-section-wrapper,
.heatmap-section-wrapper {
  width: 100%;
  border: 1px solid var(--hm-border);
  border-radius: 24px;
  background: linear-gradient(
    180deg,
    rgba(22, 34, 56, 0.84),
    rgba(11, 18, 32, 0.96)
  );
  box-shadow: var(--hm-shadow-soft);
  overflow: hidden;
}

.allocation-chart-wrapper,
.performance-chart-wrapper {
  padding: 32px;
  overflow: visible;
}

.allocation-chart-wrapper {
  min-height: 760px !important;
}

.performance-chart-wrapper {
  margin-bottom: 24px !important;
}

.performance-chart-wrapper .chart-container {
  min-height: 520px;
}

.holdings-section-wrapper,
.heatmap-section-wrapper {
  grid-column: 1 / -1;
}

.chart-container {
  position: relative;
  width: 100%;
  min-height: 360px;
}

#allocation-chart-container {
  position: relative;
  width: 100%;
  height: 500px !important;
  min-height: 500px !important;
  max-height: 500px !important;
  overflow: visible;
}

#allocationChart {
  display: block;
  width: 100% !important;
  height: 470px !important;
  max-height: 470px !important;
}

#performance-chart-container {
  min-height: 545px !important;
  padding-bottom: 18px !important;
}

#performanceChart {
  width: 100% !important;
  height: 385px !important;
  max-height: 385px !important;
}

.chart-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  padding: 20px 22px;
  border-bottom: 1px solid rgba(148, 163, 184, 0.13);
}

.allocation-chart-wrapper .chart-header,
.performance-chart-wrapper .chart-header {
  padding: 0 0 18px;
  border-bottom: 0;
}

.chart-header h4 {
  margin: 0;
  color: var(--hm-text);
  font-family: var(--font-display);
  font-size: 1.85rem;
  font-weight: 600;
  letter-spacing: -0.025em;
}

/* ================================
   BUTTONS / TIME SELECTORS
   ================================ */

.time-selector-container {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.time-btn {
  min-height: 28px;
  padding: 0 9px;
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.15);
  background: rgba(5, 7, 13, 0.42);
  color: var(--hm-muted);
  font-size: 0.72rem;
  font-weight: 800;
  cursor: pointer;
  transition: 160ms ease;
}

.time-btn:hover {
  color: var(--hm-text);
  border-color: rgba(212, 175, 55, 0.25);
}

.time-btn.active {
  background: rgba(212, 175, 55, 0.16);
  border-color: rgba(212, 175, 55, 0.36);
  color: var(--hm-gold-bright);
}

#card-gain-loss #gain-time-selector {
  display: flex;
  flex-wrap: nowrap;
  gap: 5px;
  align-items: center;
}

#card-gain-loss .time-btn {
  min-width: 0;
  padding: 0 8px;
  font-size: 0.68rem;
}

/* ================================
   ALLOCATION LEGEND
   ================================ */

#allocation-legend,
.chart-legend {
  margin-top: 56px !important;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 12px 18px;
  overflow: visible;
  max-height: none;
  padding-right: 0;
  text-align: left;
}

#allocation-legend * {
  max-width: 100%;
}

.legend-item,
#allocation-legend > div,
#allocation-legend > a {
  min-height: 42px;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(5, 7, 13, 0.28);
  border: 1px solid rgba(148, 163, 184, 0.1);
  color: var(--hm-text-soft);
  font-size: 0.86rem;
  overflow: hidden;
  text-decoration: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-width: 0;
  transition:
    transform 160ms ease,
    border-color 160ms ease,
    background 160ms ease,
    box-shadow 160ms ease;
}

.legend-item:visited {
  color: var(--hm-text-soft);
}

.legend-item span,
#allocation-legend span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.legend-item--link {
  cursor: pointer;
}

.legend-item--link:hover {
  transform: translateY(-1px);
  border-color: rgba(212, 175, 55, 0.34);
  background: rgba(212, 175, 55, 0.08);
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.24);
}

.legend-item--link .legend-name {
  color: var(--hm-text);
}

.legend-item--link:hover .legend-name {
  color: var(--hm-gold-bright);
}

.legend-item.active-sync {
  border-color: rgba(212, 175, 55, 0.38);
  background: rgba(212, 175, 55, 0.08);
}

#allocation-legend img,
.chart-legend img {
  width: 24px !important;
  height: 24px !important;
  min-width: 24px !important;
  max-width: 24px !important;
  max-height: 24px !important;
  object-fit: contain;
  border-radius: 4px;
}

.legend-color,
.legend-color-box {
  width: 10px;
  height: 10px;
  min-width: 10px;
  border-radius: 999px;
  display: inline-block;
  margin-right: 2px;
}

/* ================================
   TABLE / ACCORDIONS
   ================================ */

.holdings-header {
  cursor: pointer;
}

.toggle-icon {
  color: var(--hm-gold-bright);
  transition: transform 180ms ease;
}

.holdings-header.active .toggle-icon {
  transform: rotate(180deg);
}

.portfolio-table-container {
  max-height: 1000px;
  overflow: auto;
  transition:
    max-height 240ms ease,
    opacity 240ms ease;
}

.portfolio-table-container.collapsed {
  max-height: 0;
  opacity: 0;
  overflow: hidden;
}

.portfolio-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
}

.portfolio-table th,
.portfolio-table td {
  padding: 16px 18px;
  border-bottom: 1px solid rgba(148, 163, 184, 0.1);
}

.portfolio-table th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: rgba(11, 18, 32, 0.96);
  color: var(--hm-muted);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  cursor: pointer;
}

.portfolio-table td {
  color: var(--hm-text-soft);
  font-size: 0.93rem;
}

.portfolio-table tbody tr:hover {
  background: rgba(255, 255, 255, 0.025);
}

.portfolio-table td.positive-gain {
  color: #22c55e !important;
  font-weight: 800;
}

.portfolio-table td.negative-gain {
  color: #ef4444 !important;
  font-weight: 800;
}

.portfolio-table th[data-sort] {
  position: relative;
  white-space: nowrap;
}

.portfolio-table th[data-sort]::after {
  content: "▲▼";
  display: inline-block;
  margin-left: 8px;
  color: rgba(212, 175, 55, 0.42);
  font-size: 0.62rem;
  letter-spacing: -0.18em;
  transform: translateY(-1px);
  transition:
    color 160ms ease,
    opacity 160ms ease;
}

.portfolio-table th[data-sort]:hover::after {
  color: var(--hm-gold-bright);
  opacity: 1;
}

/* ================================
   HEATMAP
   ================================ */

.heatmap-section-wrapper {
  width: 100%;
  margin: 0 auto;
  overflow: hidden;
}

.heatmap-section-wrapper .chart-header {
  align-items: center;
}

.treemap-container {
  position: relative;
  width: 100%;
  height: clamp(500px, calc(100vh - 285px), 640px);
  min-height: 500px;
  max-height: 640px;
  overflow: hidden;
  padding: 0;
  background:
    radial-gradient(
      circle at 80% 20%,
      rgba(212, 175, 55, 0.05),
      transparent 34%
    ),
    rgba(5, 7, 13, 0.32);
  border-top: 1px solid rgba(148, 163, 184, 0.1);
}

.heatmap-loading {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--hm-muted);
  font-size: 0.95rem;
}

.treemap-node {
  position: absolute;
  box-sizing: border-box;
  overflow: hidden;
  border: 1px solid rgba(5, 7, 13, 0.58);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: default;
  transition:
    transform 160ms ease,
    box-shadow 160ms ease,
    border-color 160ms ease,
    filter 160ms ease;
}

.treemap-node:hover {
  z-index: 10;
  transform: scale(1.018);
  border-color: rgba(255, 255, 255, 0.72);
  box-shadow: 0 14px 36px rgba(0, 0, 0, 0.42);
  filter: brightness(1.08);
}

.tm-content {
  width: 100%;
  height: 100%;
  padding: 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  text-align: center;
  pointer-events: none;
  overflow: hidden;
}

.tm-logo {
  width: 28px;
  height: 28px;
  object-fit: contain;
  margin-bottom: 2px;
  border-radius: 5px;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.45));
}

.tm-ticker {
  max-width: 100%;
  color: #ffffff;
  font-size: 0.86rem;
  font-weight: 800;
  line-height: 1;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.72);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tm-change {
  color: rgba(255, 255, 255, 0.92);
  font-size: 0.76rem;
  font-weight: 700;
  line-height: 1;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.72);
  white-space: nowrap;
}

/* Compact tiles: logo + percentage, no ticker */

.treemap-node.logo-only .tm-content,
.treemap-node.small .tm-content {
  padding: 4px;
  gap: 2px;
}

.treemap-node.logo-only .tm-logo,
.treemap-node.small .tm-logo {
  width: 22px;
  height: 22px;
  margin-bottom: 1px;
}

.treemap-node.logo-only .tm-ticker,
.treemap-node.small .tm-ticker {
  display: none;
}

.treemap-node.logo-only .tm-change,
.treemap-node.small .tm-change {
  font-size: 0.64rem;
}

/* Very small tiles: still show logo + percentage, just smaller */

.treemap-node.tiny .tm-content {
  padding: 3px;
  gap: 2px;
}

.treemap-node.tiny .tm-logo {
  width: 18px;
  height: 18px;
  margin-bottom: 0;
}

.treemap-node.tiny .tm-ticker {
  display: none;
}

.treemap-node.tiny .tm-change {
  display: block;
  font-size: 0.56rem;
}

.tm-bright-green {
  background: linear-gradient(
    135deg,
    rgba(34, 197, 94, 0.96),
    rgba(21, 128, 61, 0.96)
  );
}

.tm-mid-green {
  background: linear-gradient(
    135deg,
    rgba(22, 163, 74, 0.88),
    rgba(21, 94, 59, 0.94)
  );
}

.tm-mid-red {
  background: linear-gradient(
    135deg,
    rgba(239, 68, 68, 0.88),
    rgba(127, 29, 29, 0.94)
  );
}

.tm-bright-red {
  background: linear-gradient(
    135deg,
    rgba(220, 38, 38, 0.96),
    rgba(127, 29, 29, 0.98)
  );
}

.tm-neutral {
  background: linear-gradient(
    135deg,
    rgba(100, 116, 139, 0.86),
    rgba(51, 65, 85, 0.96)
  );
}

/* ================================
   PERFORMANCE METHODOLOGY NOTE
   ================================ */

.benchmark-methodology-note {
  width: calc(100% - 56px) !important;
  max-width: calc(100% - 56px) !important;
  margin: 14px 28px 0 !important;
  padding-top: 12px !important;
  border-top: 1px solid rgba(212, 175, 55, 0.14);
  color: rgba(229, 231, 235, 0.56);
  font-size: 0.78rem !important;
  line-height: 1.35 !important;
  text-align: left !important;
  letter-spacing: -0.01em;
  white-space: nowrap !important;
}

.benchmark-methodology-note::before {
  content: "Methodology note: ";
  color: rgba(212, 175, 55, 0.82);
  font-weight: 700;
}

/* ================================
   METHODOLOGY SECTION COPY
   ================================ */

.methodology-copy {
  padding: 2rem;
  color: var(--hm-text-soft);
  line-height: 1.7;
  text-align: left;
  width: 100%;
  max-width: 1120px;
}

.methodology-copy h5 {
  margin: 0 0 0.65rem;
  color: var(--hm-gold-bright);
  font-family: var(--font-display);
  font-size: 1.12rem;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.methodology-copy p {
  width: 100%;
  max-width: 1050px;
  margin: 0 0 1.55rem;
  color: #cccccc;
  font-size: 0.96rem;
  line-height: 1.7;
}

.methodology-copy p:last-child {
  margin-bottom: 0;
}

.methodology-copy strong {
  color: #ffffff;
  font-weight: 800;
}

/* ================================
   RESPONSIVE
   ================================ */

@media (max-width: 1100px) {
  .portfolio-summary {
    grid-template-columns: repeat(2, 1fr);
  }

  .chart-section-container {
    grid-template-columns: 1fr;
  }

  .benchmark-methodology-note {
    white-space: normal !important;
    font-size: 0.78rem !important;
  }
}

@media (max-width: 760px) {
  #portfolio.page-section {
    padding: 72px 0 92px !important;
  }

  .portfolio-toggle-label {
    font-size: 1rem !important;
  }

  .portfolio-summary {
    grid-template-columns: 1fr;
  }

  .summary-card {
    min-height: auto;
  }

  .chart-header {
    display: block;
  }

  .chart-header .time-selector-container {
    margin-top: 14px;
  }

  .portfolio-table {
    min-width: 860px;
  }

  .benchmark-toggles {
    flex-direction: column;
    align-items: center;
  }

  .allocation-chart-wrapper {
    padding: 22px;
    min-height: 680px !important;
  }

  #allocation-chart-container {
    height: 440px !important;
    min-height: 440px !important;
    max-height: 440px !important;
  }

  #allocationChart {
    height: 420px !important;
    max-height: 420px !important;
  }

  #allocation-legend,
  .chart-legend {
    grid-template-columns: 1fr;
  }

  .treemap-container {
    height: 560px;
    min-height: 560px;
    max-height: 560px;
  }

  .methodology-copy {
    padding: 1.4rem;
  }

  .methodology-copy p {
    font-size: 0.92rem;
  }
}
