/**
 * Portfolio Heatmap Component - Professional Styling
 */

/* Main Component Container */
.portfolio-heatmap-component {
  background: white;
  border-radius: 16px;
  padding: 0;
  margin-bottom: 2rem;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
  border: 1px solid var(--color-grey-dark, #f3f4f6);
  font-family: 'Poppins', sans-serif;
  overflow: visible;
}

/* Header Section */
.heatmap-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 28px;
  border-bottom: 1px solid var(--color-grey-dark, #e5e7eb);
  flex-wrap: wrap;
  gap: 1rem;
}

.heatmap-title-section {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.heatmap-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--color-dark, #1f2937);
  margin: 0;
  letter-spacing: -0.01em;
}

.heatmap-description {
  font-size: 0.8125rem;
  font-weight: 400;
  color: var(--color-dark, #6b7280);
  margin: 0;
  opacity: 0.8;
}

/* Filter Buttons */
.heatmap-filters {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.heatmap-filters .btn {
  font-family: 'Poppins', sans-serif;
  font-size: 0.875rem;
  font-weight: 500;
  transition: all 0.2s ease;
}

/* Button styling inherited from app.css:
 * - btn-primary uses --color-green
 * - btn-unselected uses --color-grey with green hover
 */

/* Loading State — single shimmer block matching SVG height */
.heatmap-loading {
  display: none;
  padding: 28px;
  flex-direction: column;
  gap: 1rem;
}

.shimmer-block {
  height: 480px;
  border-radius: 8px;
  background: linear-gradient(
    90deg,
    var(--color-grey, #f1f3f5) 25%,
    var(--color-grey-dark, #e9ecef) 50%,
    var(--color-grey, #f1f3f5) 75%
  );
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
}

/* Keep shimmer-grid for backwards compatibility with existing shimmer cells */
.shimmer-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 4px;
}

.shimmer-cell {
  min-height: 64px;
  border-radius: 8px;
  background: linear-gradient(
    90deg,
    var(--color-grey, #f1f3f5) 25%,
    var(--color-grey-dark, #e9ecef) 50%,
    var(--color-grey, #f1f3f5) 75%
  );
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
}

.shimmer-cell.shimmer-wide {
  grid-column: span 2;
  grid-row: span 2;
}

@keyframes shimmer {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}

.heatmap-loading .loading-text {
  color: var(--color-dark, #6b7280);
  opacity: 0.6;
  font-size: 0.95rem;
  margin: 0;
  font-weight: 400;
  text-align: center;
}

/* Error State */
.heatmap-error-state {
  display: none;
  text-align: center;
  padding: 4rem 2rem;
  min-height: 400px;
  justify-content: center;
  align-items: center;
  flex-direction: column;
}

.heatmap-error-state .error-icon {
  font-size: 3rem;
  margin-bottom: 1rem;
  opacity: 0.5;
}

.heatmap-error-state h4 {
  color: var(--color-dark, #374151);
  font-size: 1.125rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
}

.heatmap-error-state p {
  color: var(--color-dark, #6b7280);
  opacity: 0.7;
  margin-bottom: 1.5rem;
}

.heatmap-error-state .retry-btn {
  font-family: 'Poppins', sans-serif;
}

/* Empty State */
.heatmap-empty-state {
  display: none;
  text-align: center;
  padding: 4rem 2rem;
  min-height: 400px;
  justify-content: center;
  align-items: center;
  flex-direction: column;
}

.heatmap-empty-state .empty-icon {
  font-size: 3rem;
  margin-bottom: 1rem;
  opacity: 0.4;
}

.heatmap-empty-state h4 {
  color: var(--color-dark, #374151);
  font-size: 1.125rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
}

.heatmap-empty-state .empty-message {
  color: var(--color-dark, #6b7280);
  opacity: 0.8;
  margin-bottom: 1.5rem;
  font-size: 0.95rem;
}

.heatmap-empty-state .btn {
  font-family: 'Poppins', sans-serif;
}

/* Visualization Container */
.portfolio-heatmap-container {
  position: relative;
  min-height: auto;
  border-radius: 8px;
  overflow: visible;
  margin: 28px;
}

.heatmap-visualization {
  width: 100%;
  min-height: auto;
  border-radius: 8px;
  transition: opacity 0.3s ease;
}

/* Tooltip styles in assets/styles/components/popup.css (.widget-popup) */

/* Legend */
.heatmap-footer {
  padding: 0.75rem 28px 1.25rem;
  border-top: 1px solid var(--color-grey-dark, #e5e7eb);
}

.heatmap-portfolio-legend {
  display: flex;
  gap: 1.25rem;
  flex-wrap: wrap;
  margin-bottom: 0.5rem;
}

.heatmap-legend {
  display: flex;
  gap: 1.5rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.875rem;
  color: var(--color-dark, #6b7280);
  font-weight: 400;
}

.legend-color {
  width: 18px;
  height: 18px;
  border-radius: 4px;
  flex-shrink: 0;
  border: 1px solid rgba(0, 0, 0, 0.1);
}

/* Compact legend — colored badges with percentage label inside */
.heatmap-legend--compact {
  gap: 0.25rem;
  justify-content: flex-end;
}

.legend-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 28px;
  border-radius: 4px;
  font-size: 0.6875rem;
  font-weight: 600;
  border: 1px solid rgba(0, 0, 0, 0.08);
  flex-shrink: 0;
  letter-spacing: -0.01em;
}

/* Responsive Design */
@media (max-width: 992px) {
  .heatmap-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .heatmap-filters {
    width: 100%;
    justify-content: flex-start;
  }

  .heatmap-visualization {
    min-height: 500px;
  }

  .portfolio-heatmap-container {
    min-height: 500px;
  }
}

@media (max-width: 768px) {
  .portfolio-heatmap-component {
    margin-bottom: 1.5rem;
  }

  .heatmap-title {
    font-size: 1.125rem;
  }

  .heatmap-filters .btn {
    font-size: 0.8125rem;
    padding: 0.4rem 0.875rem;
  }

  .heatmap-legend {
    gap: 1rem;
    justify-content: center;
  }

  .legend-item {
    font-size: 0.8125rem;
  }

  .legend-color {
    width: 16px;
    height: 16px;
  }

  .heatmap-visualization {
    min-height: 450px;
  }

  .portfolio-heatmap-container {
    min-height: 450px;
  }
}


@media (max-width: 576px) {
  .heatmap-header {
    padding: 16px 20px;
  }

  .portfolio-heatmap-container {
    margin: 20px;
  }

  .heatmap-footer {
    padding: 0.75rem 20px 1rem;
  }

  .heatmap-title {
    font-size: 1rem;
  }

  .heatmap-filters {
    gap: 0.375rem;
  }

  .heatmap-filters .btn {
    font-size: 0.75rem;
    padding: 0.375rem 0.75rem;
  }

  .heatmap-legend {
    gap: 0.75rem;
  }

  .heatmap-visualization {
    min-height: 400px;
    border-radius: 6px;
  }

  .portfolio-heatmap-container {
    min-height: 400px;
  }
}


/* ─── Controls ───────────────────────────────────────────── */
.heatmap-controls {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}


/* ─── D3 SVG Treemap ──────────────────────────────────────── */
.hm-treemap-svg {
  display: block;
  width: 100%;
  overflow: hidden;
}

.hm-treemap-cell {
  cursor: pointer;
}

.hm-treemap-cell rect {
  transition: opacity 0.12s ease;
}

/* Portfolio group labels — pointer-events: none so they don't interfere with cell hover */
.hm-portfolio-label,
.hm-lane-label {
  pointer-events: none;
  user-select: none;
}

/* ─── JS-positioned popup overlay for SVG cells ──────────── */
/* Appended to document.body so it is never clipped by any parent
   overflow:hidden or affected by CSS transforms on ancestors */
.hm-popup-overlay {
  position: absolute;
  display: none;
  z-index: 9999;
  pointer-events: none;
}

/* Make the widget-popup inside the overlay visible (it is opacity:0 by default
   and relies on .has-popup:hover which doesn't apply to SVG-based popups) */
.hm-popup-overlay .widget-popup {
  position: relative;
  opacity: 1;
  transform: none;
  bottom: auto;
  left: auto;
  top: auto;
  right: auto;
  margin: 0;
  pointer-events: none;
}


/* ─── Responsive: treemap ────────────────────────────────── */
@media (max-width: 768px) {
  .heatmap-controls {
    flex-direction: column;
    align-items: flex-start;
  }
}

/* Hide lane labels below 500px — too narrow to render usefully */
@media (max-width: 500px) {
  .hm-lane-label {
    display: none;
  }
}


/* Print Styles */
@media print {
  .portfolio-heatmap-component {
    break-inside: avoid;
    box-shadow: none;
    border: 1px solid #ddd;
  }

  .heatmap-filters {
    display: none;
  }
}
