// assets/styles/risk_map.scss

@use '../../vendor/twbs/bootstrap/scss/bootstrap' as *;
@use 'variables' as variables;

/* =========================================================
   VARIABLES LOCALES
========================================================= */

$risk-border-color: #e5e7eb;
$risk-border-soft: #dbe4ea;
$risk-surface: #ffffff;
$risk-surface-soft: #f8fafc;
$risk-text-dark: #0f172a;
$risk-text-muted: #475569;

$risk-shadow-sm: 0 8px 20px rgba(15, 23, 42, 0.05);
$risk-shadow-md: 0 14px 28px rgba(15, 23, 42, 0.1);
$risk-shadow-lg: 0 12px 24px rgba(15, 23, 42, 0.12);

/* =========================================================
   MIXINS
========================================================= */

@mixin hover-lift($translate: -2px, $shadow: $risk-shadow-md) {
  transition:
          transform 0.18s ease,
          box-shadow 0.18s ease,
          border-color 0.18s ease,
          background 0.18s ease;

  &:hover {
    transform: translateY($translate);
    box-shadow: $shadow;
  }
}

@mixin thumbnail-card($size: 100%, $height: 120px) {
  position: relative;
  flex: 1 1 auto;
  width: $size !important;
  min-width: 0 !important;
  max-width: 100% !important;
  margin: 0 !important;
  padding: 0 !important;
  border: 1px solid rgba(0, 0, 0, 0.08);
  border-radius: 1rem;
  overflow: hidden;
  background: #fff;
  display: flex;
  flex-direction: column;
  text-align: left;
  box-shadow: $risk-shadow-sm;
  cursor: pointer;
  transition:
          transform 0.18s ease,
          box-shadow 0.18s ease,
          border-color 0.18s ease;

  &:hover {
    transform: translateY(-2px);
    box-shadow: $risk-shadow-md;
    border-color: rgba(62, 144, 158, 0.35);
  }

  &.active-layer {
    border: 2px solid variables.$tertiary;
    box-shadow:
            0 0 0 3px rgba(62, 144, 158, 0.14),
            0 0.75rem 1.5rem rgba(62, 144, 158, 0.18);
  }

  p {
    position: absolute;
    top: 0.5rem;
    left: 0.5rem;
    right: 0.5rem;
    z-index: 1;
    margin: 0;
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    width: fit-content;
    max-width: calc(100% - 1rem);
    padding: 0.35rem 0.55rem;
    border-radius: 999px;
    background: rgba(15, 23, 42, 0.72);
    backdrop-filter: blur(8px);
    color: #fff;
    font-size: 0.72rem;
    font-weight: 800;
    line-height: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  img {
    width: 100%;
    height: $height;
    display: block;
    background: #f8fafc;
    object-fit: contain;
    object-position: center;
    padding: 0.35rem;
  }

  &::before {
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
    border-radius: 1rem;
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.2);
  }
}

/* =========================================================
   STRUCTURE GÉNÉRALE
========================================================= */

#article {
  .time {
    color: variables.$primary;
    font-size: 1rem;
  }
}

#map-bloc {
  position: relative;

  .nav-link {
    padding: 0.5rem;
  }
}

.risk-premium-layout {
  display: block;
}

.risk-premium-map-shell {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.risk-map-top-legend,
.risk-map-bottom-legend {
  width: 100%;
}

/* =========================================================
   CARTE
========================================================= */

.risk-map {
  &--premium {
    height: 450px;
    border-radius: 1.35rem;

    @include media-breakpoint-down(xl) {
      height: 400px;
    }

    @include media-breakpoint-down(lg) {
      height: 450px;
    }

    @include media-breakpoint-down(sm) {
      height: 430px;
    }
  }

  &--edition,
  &--edition#map {
    height: 100% !important;
    min-height: 420px;

    @include media-breakpoint-down(lg) {
      min-height: 380px;
    }

    @include media-breakpoint-down(sm) {
      min-height: 320px;
    }
  }
}

.risk-map-wrapper {
  &--premium {
    position: relative;
    overflow: visible;
  }

  &--edition {
    overflow: visible;
    min-width: 0;
    min-height: 0;
  }
}

.risk-public-layout {
  .risk-map-wrapper--premium {
    position: relative;
  }

  .risk-map--premium {
    height: clamp(320px, 45vh, 520px) !important;
    min-height: 320px;
    border-radius: 0;
  }
}

.risk-edition-titlebox {
  position: absolute;
  left: 1rem;
  bottom: 1rem;
  z-index: 21;
  max-width: 320px;
  padding: 0.9rem 1rem;
  border-radius: 1rem;
  background: rgba(15, 23, 42, 0.72);
  backdrop-filter: blur(10px);
  color: #fff;

  @include media-breakpoint-down(sm) {
    left: 0.75rem;
    right: 0.75rem;
    bottom: 0.75rem;
    max-width: none;
  }

  &__eyebrow {
    margin: 0 0 0.2rem;
    font-size: 0.72rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: rgba(255, 255, 255, 0.72);
  }

  &__title {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 900;
    line-height: 1.1;
  }

  &__subtitle {
    margin: 0.3rem 0 0;
    font-size: 0.95rem;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.9);
  }
}

/* =========================================================
   LÉGENDES PUBLIQUES
========================================================= */

.risk-map-public-legend-top,
.risk-map-public-legend-bottom {
  position: relative;
  z-index: 1;
}

.risk-map-public-legend-top {
  margin-bottom: -0.6rem;
}

.risk-map-public-legend-bottom {
  margin-top: -0.6rem;
  margin-bottom: 0;
}

.risk-public-toolbar {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  padding: 0.75rem 0.85rem;
  border: 1px solid $risk-border-soft;
  background: #ffffff;
  box-shadow: $risk-shadow-sm;

  &__label {
    font-size: 0.68rem;
    font-weight: 900;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: $risk-text-muted;
  }

  &__group {
    display: flex;
    flex-wrap: wrap;
    gap: 0.45rem;
    padding-bottom: 0.5rem;
  }
}

.risk-map-public-legend-top .risk-public-toolbar {
  border-top-left-radius: 1rem;
  border-top-right-radius: 1rem;
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
  border-bottom: none;
}

.risk-map-public-legend-bottom .risk-public-toolbar {
  border-top-left-radius: 0;
  border-top-right-radius: 0;
  border-bottom-left-radius: 1rem;
  border-bottom-right-radius: 1rem;
  border-top: none;
}

/* Variante top / bottom autour de la carte */
.risk-map-top-legend {
  @include media-breakpoint-up(md) {
    display: flex;
    justify-content: flex-end;
  }
}

.risk-map-bottom-legend {
  @include media-breakpoint-up(md) {
    display: flex;
    justify-content: flex-start;
  }
}

.risk-public-toolbar__group--levels {
  @include media-breakpoint-up(md) {
    justify-content: flex-end;
  }

  @include media-breakpoint-down(md) {
    justify-content: center;
  }
}

.risk-public-toolbar__group--phenomena {
  @include media-breakpoint-up(md) {
    justify-content: flex-start;
  }

  @include media-breakpoint-down(md) {
    justify-content: center;
  }
}

.risk-public-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  min-height: 24px;
  padding: 0.15rem 0.5rem;
  border: 1px solid $risk-border-soft;
  border-radius: 999px;
  background: #fff;
  color: $risk-text-dark;
  font-size: 0.76rem;
  font-weight: 700;
  line-height: 1;
  box-shadow: 0 4px 10px rgba(15, 23, 42, 0.045);

  i {
    font-size: 0.82rem;
    color: variables.$primary;
  }

  span {
    white-space: nowrap;
  }
}

.risk-public-pill--level {
  .risk-level-dot {
    width: 0.82rem;
    height: 0.82rem;
    margin-right: 0;
  }
}

.risk-public-pill--phenomenon {
  i {
    width: 0.85rem;
    min-width: 0.85rem;
    text-align: center;
  }
}

/* =========================================================
   NIVEAUX / OUTILS / PICTOS
========================================================= */

.risk-level-dot {
  width: 1.5rem;
  height: 1.5rem;
  margin-right: 0.3rem;
  border-radius: 50%;
  display: inline-flex;
  flex: 0 0 auto;
  border: 1px solid rgba(0, 0, 0, 0.08);

  &.level-0 {
    background: var(--risk-color-0, #d9d9d9);
  }

  &.level-1 {
    background: var(--risk-color-1, #f3f06a);
  }

  &.level-2 {
    background: var(--risk-color-2, #ffcc66);
  }

  &.level-3 {
    background: var(--risk-color-3, #ff6600);
  }

  &.level-4 {
    background: var(--risk-color-4, #c00000);
  }
}

.risk-tool-btn {
  padding: 0.5rem;
  border-radius: 1rem;
  border: 1px solid $risk-border-soft;
  background: linear-gradient(180deg, #ffffff 0%, #f4f8fb 100%);
  color: #1f2937;
  box-shadow: 0 6px 14px rgba(15, 23, 42, 0.06);
  transition:
          transform 0.16s ease,
          box-shadow 0.16s ease,
          border-color 0.16s ease,
          background-color 0.16s ease;

  &:hover {
    transform: translateY(-2px);
    border-color: variables.$tertiary;
    box-shadow: $risk-shadow-lg;
    background: linear-gradient(180deg, #ffffff 0%, lighten(variables.$tertiary, 49%) 100%);
  }

  &.active {
    border-color: variables.$tertiary;
    background: linear-gradient(
            180deg,
            lighten(variables.$tertiary, 42%) 0%,
            lighten(variables.$tertiary, 35%) 100%
    );
    box-shadow:
            inset 0 0 0 1px rgba(255, 255, 255, 0.45),
            0 12px 24px rgba(62, 144, 158, 0.22);
    color: $risk-text-dark;
  }

  .risk-level-dot {
    width: 1rem;
    height: 1rem;
    margin-right: 0;
  }

  i {
    color: variables.$primary;
  }

  .small,
  .fw-semibold {
    line-height: 1.15;
  }
}

.risk-tool-btn--level,
.risk-tool-btn--picto {
  width: 100%;
}

.risk-tool-btn--picto {
  i {
    font-size: 1.7rem;
  }
}

.risk-pictos-row {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 0.5rem;
}

.risk-picto-marker {
  font-size: 22px;
  color: #1f2937;
  text-shadow:
          0 0 4px #fff,
          0 0 6px #fff,
          0 0 10px rgba(255, 255, 255, 0.85);
  pointer-events: none;
  line-height: 1;

  i {
    display: block;
  }
}

/* =========================================================
   MINIATURES PUBLIQUES
========================================================= */

.risk-premium-thumbnails-block {
  margin-top: 1.5rem;

  &__header {
    display: flex;
    justify-content: space-between;
    align-items: end;
    gap: 1rem;
    margin-bottom: 0.9rem;
  }

  &__title {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 900;
    color: #111827;
  }

  &__hint {
    font-size: 0.9rem;
    color: #64748b;
    font-weight: 600;
  }
}

.risk-premium-thumbnails-grid > [class*="col-"] {
  display: flex;
}

.risk-premium-thumbnails-grid .map-thumbnail {
  @include thumbnail-card(100%, 118px);
}

.map-thumbnail {
  appearance: none;
  outline: none;
}

.risk-phenomenon-thumb img.is-placeholder-plus,
.risk-phenomenon-thumb img.is-fallback {
  object-fit: cover;
}

.risk-phenomenon-thumb img.is-placeholder-plus {
  opacity: 0.95;
}

/* =========================================================
   ÉDITION / CARTES PHÉNOMÈNES
========================================================= */

.risk-phenomenon-card {
  width: 100%;
  transition: transform 0.18s ease;

  &.is-active {
    border: 1px solid variables.$tertiary;
  }

  &:hover {
    transform: translateY(-2px);
  }
}

.risk-phenomenon-card__inner {
  position: relative;
  border: 1px solid rgba(0, 0, 0, 0.08);
  transition:
          border-color 0.18s ease,
          box-shadow 0.18s ease,
          transform 0.18s ease;
}

.risk-phenomenon-card__inner--active {
  position: relative;
  border: 2px solid variables.$tertiary;
  box-shadow:
          0 0 0 3px rgba(62, 144, 158, 0.14),
          0 0.75rem 1.5rem rgba(62, 144, 158, 0.22);

  &::after {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: 1rem;
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.35);
    pointer-events: none;
  }

  .risk-phenomenon-thumb__category {
    background: rgba(62, 144, 158, 0.92);
    color: #fff;

    i {
      color: #fff;
    }
  }
}

.risk-phenomenon-thumb {
  position: relative;
  background: $risk-surface-soft;
  overflow: hidden;

  img {
    display: block;
  }

  &__top {
    position: absolute;
    inset: 0 auto auto 0;
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 0.5rem;
    padding: 0.55rem;
    pointer-events: none;
  }

  &__category {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.35rem 0.55rem;
    border-radius: 999px;
    background: rgba(15, 23, 42, 0.72);
    backdrop-filter: blur(8px);
    color: #fff;
    font-size: 0.75rem;
    font-weight: 700;
    line-height: 1;

    i {
      font-size: 0.8rem;
      color: #fff;
    }

    span {
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }
  }

  &__status {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.35rem 0.5rem;
    border-radius: 999px;
    font-size: 0.68rem;
    font-weight: 800;
    line-height: 1;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    background: rgba(255, 255, 255, 0.92);
    color: $risk-text-dark;
    white-space: nowrap;

    &.is-available {
      border: 1px solid rgba(16, 185, 129, 0.28);
      color: #047857;
    }

    &.is-new {
      border: 1px solid rgba(59, 130, 246, 0.2);
      color: #1d4ed8;
    }
  }

  &__empty {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: linear-gradient(180deg, #f8fbff 0%, #eef6fb 100%);
    color: #475569;
  }

  &__plus {
    font-size: 2.2rem;
    line-height: 1;
    font-weight: 300;
    color: variables.$tertiary;
  }

  &__empty-label {
    margin-top: 0.15rem;
    font-size: 0.8rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.05em;
  }
}

/* =========================================================
   TOOLTIP
========================================================= */

.ol-tooltip {
  position: absolute;
  z-index: 2000;
  pointer-events: none;
  overflow: visible;
  min-width: 300px;
}

.risk-tooltip-card {
  width: 220px;
  max-width: 220px;
  padding: 0.7rem 0.75rem;
  border-radius: 0.95rem;
  background: rgba(255, 255, 255, 0.98);
  backdrop-filter: blur(10px);
  color: $risk-text-dark;
  box-shadow:
          0 10px 24px rgba(15, 23, 42, 0.14),
          0 4px 10px rgba(15, 23, 42, 0.08);
  border: 1px solid rgba(226, 232, 240, 0.95);
  overflow: hidden;

  &__zone {
    margin-bottom: 0.6rem;
    padding-bottom: 0.55rem;
    border-bottom: 1px solid rgba(226, 232, 240, 0.95);
    font-size: 0.88rem;
    font-weight: 900;
    line-height: 1.15;
    color: #0f172a;
    word-break: break-word;
  }

  &__body {
    display: grid;
    grid-template-columns: 42px minmax(0, 1fr);
    gap: 0.65rem;
    align-items: start;

    &.no-icon {
      grid-template-columns: 1fr;
    }
  }

  &__icon {
    width: 42px;
    height: 42px;
    border-radius: 999px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(180deg, #f8fbff 0%, #eef6fb 100%);
    border: 1px solid rgba(219, 228, 234, 0.9);
    color: variables.$primary;
    font-size: 1rem;
    flex-shrink: 0;
  }

  &__content {
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
  }

  &__row {
    display: grid;
    grid-template-columns: 46px minmax(0, 1fr);
    gap: 0.45rem;
    align-items: center;
    min-width: 0;
  }

  &__label {
    font-size: 0.62rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #64748b;
  }

  &__value {
    min-width: 0;
    font-size: 0.74rem;
    font-weight: 700;
    color: $risk-text-dark;
    line-height: 1.15;
    word-break: break-word;
  }
}

.risk-tooltip-level-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  max-width: 100%;
  padding: 0.28rem 0.45rem;
  border-radius: 999px;
  background: #f8fafc;
  border: 1px solid rgba(219, 228, 234, 0.95);
  line-height: 1.05;
  flex-wrap: wrap;

  .risk-level-dot {
    width: 0.72rem;
    height: 0.72rem;
    margin-right: 0;
    flex-shrink: 0;
  }

  span:last-child {
    word-break: break-word;
  }
}

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

@include media-breakpoint-down(md) {
  .risk-public-layout {
    .risk-map--premium {
      height: 300px !important;
      min-height: 300px;
    }
  }

  .risk-public-toolbar {
    padding: 0.65rem 0.7rem;

    &__group {
      gap: 0.4rem;
    }
  }

  .risk-public-pill {
    min-height: 28px;
    padding: 0.34rem 0.58rem;
    font-size: 0.7rem;
    gap: 0.34rem;

    i {
      font-size: 0.74rem;
    }
  }

  .risk-public-pill--level {
    .risk-level-dot {
      width: 0.72rem;
      height: 0.72rem;
    }
  }

  .risk-tool-btn--level,
  .risk-tool-btn--picto {
    padding: 0.4rem;
  }

  .risk-tool-btn--picto {
    i {
      font-size: 1.35rem;
    }

    .small,
    .fw-semibold {
      font-size: 0.72rem;
    }
  }

  .risk-pictos-row {
    gap: 0.35rem;
  }

  .risk-premium-thumbnails-grid .map-thumbnail {
    @include thumbnail-card(100%, 102px);

    p {
      top: 0.4rem;
      left: 0.4rem;
      right: 0.4rem;
      font-size: 0.66rem;
      padding: 0.3rem 0.48rem;
    }

    img {
      padding: 0.25rem;
    }
  }

  .risk-phenomenon-thumb {
    &__top {
      padding: 0.4rem;
    }

    &__category {
      max-width: calc(100% - 74px);
      font-size: 0.68rem;
      padding: 0.28rem 0.45rem;

      i {
        font-size: 0.72rem;
      }
    }

    &__status {
      font-size: 0.6rem;
      padding: 0.28rem 0.38rem;
    }

    &__plus {
      font-size: 1.8rem;
    }

    &__empty-label {
      font-size: 0.68rem;
    }
  }
}

@include media-breakpoint-down(sm) {
  .risk-tooltip-card {
    width: 200px;
    max-width: 200px;
    padding: 0.65rem;

    &__zone {
      font-size: 0.8rem;
    }

    &__body {
      grid-template-columns: 38px minmax(0, 1fr);
      gap: 0.55rem;

      &.no-icon {
        grid-template-columns: 1fr;
      }
    }

    &__icon {
      width: 38px;
      height: 38px;
      font-size: 0.9rem;
    }

    &__row {
      grid-template-columns: 42px minmax(0, 1fr);
      gap: 0.38rem;
    }

    &__label {
      font-size: 0.58rem;
    }

    &__value {
      font-size: 0.7rem;
    }
  }
}