@use '../../raaghu-react-themes/tokens/breakpoints' as bp;

.rds-comp-map {
  /* Use theme variable and avoid forcing white fallback so dark themes stay dark */
  background: var(--rds-bg, transparent) !important;
  border: none !important;
  box-shadow: none !important;
  padding: calc(var(--rds-spacing-sm) + var(--rds-spacing-xs)) !important;
  margin: 0 !important;
  min-height: auto;
  height: auto;
  position: relative;
  overflow: hidden;

  &__label {
    font-size: var(--rds-font-size-2xl);
    font-weight: 500;
    color: var(--rds-text, #222);
    margin-bottom: var(--rds-spacing-sm);
    margin-left: 0;
    letter-spacing: 0.2px;
    text-align: left;
  }

  &__center {
    display: flex;
    justify-content: center;
    align-items: flex-start;
    width: 100%;
    position: relative;
    min-height: auto;
    height: auto;
    
    & > div {
      width: 100%;
      max-width: 100%;
      overflow: visible;
      height: auto;
    }
  }

  &__worldmap-host {
    width: 100%;
    height: auto;
    overflow: visible;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    background: transparent;
  }

  svg {
    display: block;
    margin: 0 auto;
    width: 100%;
    height: auto;
    max-width: 700px;
    min-width: 280px;
    
    & > * {
      max-width: 100%;
      height: auto;
    }
  }

  & > div:first-child {
    width: 100%;
    height: auto;
    overflow: visible;
  }

  .svg-map,
  svg {
    background: var(--rds-background-paper, transparent) !important;
  }

  .svg-map__background,
  svg > rect:first-of-type {
    fill: var(--rds-background-paper, transparent) !important;
  }

  // Fix: figure wrapper from react-svg-worldmap should be transparent
  figure,
  .worldmap__figure-container,
  figure.worldmap__figure-container {
    background-color: transparent !important;
    background: transparent !important;
    margin: 0 !important;
    padding: 0 !important;
  }

  div[style*="height"] {
    height: auto !important;
  }

  @include bp.down(sm) {
    svg {
      max-width: calc(100vw - 20px) !important;
      width: calc(100vw - 20px) !important;
    }
  }

  .rds-theme--dark .rds-comp-map .worldmap__figure-container,
[data-theme="dark"] .rds-comp-map .worldmap__figure-container {
  background-color: transparent !important;
}

  &__heatmap-image {
    display: block;
    margin: 0 auto;
    width: 100%;
    height: auto;
    max-width: 700px;
    border-radius: var(--rds-border-radius-sm);
    box-shadow: var(--rds-elevation-2);
  }

  @include bp.down(md) {
    &__label {
      font-size: var(--rds-font-size-xl);
    }
    
    svg, &__heatmap-image {
      max-width: 100%;
    }
  }

  @include bp.down(mobile-sm) {
    padding: calc(var(--rds-spacing-xs) + 1px) !important;
    max-width: 100vw;
    box-sizing: border-box;
    height: auto;
    min-height: auto;
    
    &__label {
      font-size: var(--rds-font-size-lg);
      margin-bottom: var(--rds-spacing-sm);
    }
    
    &__center {
      width: 100%;
      max-width: 100%;
      overflow: visible;
      padding: 0;
      margin: 0;
      min-height: auto;
      height: auto;
      display: flex;
      justify-content: center;
      align-items: flex-start;
    }
    
    svg, &__heatmap-image {
      width: 310px !important;
      max-width: 310px !important;
      min-width: 280px !important;
      height: auto !important;
      transform: scale(1);
      transform-origin: center top;
      box-sizing: border-box;
      margin: 0 auto;
      display: block;
    }

    & > div {
      width: 310px !important;
      max-width: 310px !important;
      height: auto !important;
      margin: 0 auto !important;
      overflow: visible !important;
    }
  }

  @include bp.between(mobile-sm, 420) {
    padding: var(--rds-spacing-sm) !important;
    max-width: 100vw;
    box-sizing: border-box;
    height: auto;
    min-height: auto;
    
    &__label {
      font-size: var(--rds-font-size-lg, 17px);
      margin-bottom: var(--rds-spacing-sm, 10px);
    }
    
    &__center {
      width: 100%;
      max-width: 100%;
      overflow: visible;
      padding: 0;
      margin: 0;
      min-height: auto;
      height: auto;
      display: flex;
      justify-content: center;
      align-items: flex-start;
    }
    
    svg, &__heatmap-image {
      width: 400px !important;
      max-width: 400px !important;
      min-width: 380px !important;
      height: auto !important;
      transform: scale(1);
      transform-origin: center top;
      box-sizing: border-box;
      margin: 0 auto;
      display: block;
    }

    & > div {
      width: 400px !important;
      max-width: 400px !important;
      height: auto !important;
      margin: 0 auto !important;
      overflow: visible !important;
    }
  }

  &--heatmap {
    background: linear-gradient(0deg, var(--rds-comp-map-heatmap-0), var(--rds-comp-map-heatmap-0)),
      radial-gradient(50.38% 50.38% at 30.5% 6.53%, var(--rds-comp-map-heatmap-1) 0%, var(--rds-comp-map-heatmap-2) 33%, var(--rds-comp-map-heatmap-3) 67.18%, var(--rds-comp-map-heatmap-4) 100%),
      radial-gradient(61.69% 61.69% at 78.5% 19.32%, var(--rds-comp-map-heatmap-5) 0%, var(--rds-comp-map-heatmap-6) 38.26%, var(--rds-comp-map-heatmap-7) 100%),
      radial-gradient(36.18% 63.42% at 35.64% 37.56%, var(--rds-comp-map-heatmap-8) 0%, var(--rds-comp-map-heatmap-9) 44.15%, rgba(181, 228, 62, 0) 100%),
      radial-gradient(18.75% 43.04% at 26.5% 80.97%, var(--rds-comp-map-heatmap-10) 0%, var(--rds-comp-map-heatmap-11) 50%, rgba(252, 71, 3, 0) 100%);

    .rds-comp-map__label {
      color: var(--rds-text, #333);
      font-weight: 600;
    }

    svg {
      filter: drop-shadow(0 2px 4px rgba(0,0,0,0.1));
    }
  }
}

/* Dark-theme SVG/background fixes so the map doesn't render a white inner canvas */
body[data-theme="dark"], html[data-theme="dark"], body[data-bs-theme="dark"], html[data-bs-theme="dark"], .theme-dark, .sb-show-main[data-theme="dark"],
.rds-theme--dark, body.theme-dark, .dark-theme {
  .rds-comp-map {
    background: var(--rds-bg, transparent) !important;

    // Target the figure/container rendered by react-svg-worldmap
    figure,
    .worldmap__figure-container,
    figure.worldmap__figure-container {
      background-color: transparent !important;
      background: transparent !important;
      margin: 0 !important;
      padding: 0 !important;
    }

    svg {
      background-color: transparent !important;
    }

    .rds-comp-map__worldmap-host,
    .svg-map {
      background-color: transparent !important;
    }

    /* Some world map implementations render a rect or a white group; ensure it's dark */
    .svg-map__background,
    svg > rect:first-of-type,
    svg rect[fill="#fff"],
    svg rect[fill="#ffffff"],
    svg rect[fill="white"] {
      fill: transparent !important;
    }

    /* Make label and surrounding areas adapt to dark theme */
    &__label {
      color: var(--rds-color-on-surface-dark, #e6e6e6);
    }
  }
}
