@use "sass:color";

$primary-color: #00a346;
$secondary-color: #667788;
$background-dark: #1c1f23;
$text-white: #ffffff;
$text-gray: #667788;
$border-color: #2c3038;
$hover-color: rgba(102, 119, 136, 0.2);

.poster-selector {
  margin-top: 5rem;
  margin-bottom: 2rem;

  .content-paper {
    padding: 1.5rem;
    border-radius: 4px;
    background-color: $background-dark;
    max-width: calc((120vh - 340px) * 7 / 9 + 3rem);
    margin: 0 auto;
  }

  .title {
    margin-bottom: 1rem;
    color: $text-white;
  }

  // Calendar navigation
  .calendar-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
  }

  .calendar-nav-center {
    display: flex;
    align-items: center;
    gap: 0.25rem;
  }

  .calendar-nav-btn {
    color: $text-white !important;

    &:hover {
      background-color: $hover-color !important;
    }
  }

  .calendar-month-label {
    color: $text-white;
    min-width: 160px;
    text-align: center;
  }

  .calendar-today-btn {
    color: $text-gray !important;
    font-size: 0.75rem !important;
    text-transform: none !important;
    padding: 2px 8px !important;
    border: 1px solid $text-gray !important;
    border-radius: 4px !important;
    min-width: unset !important;

    &:hover {
      color: $text-white !important;
      border-color: $text-white !important;
    }
  }

  .calendar-month-selects {
    display: flex;
    align-items: center;
    gap: 4px;
    border: 1px solid $border-color;
    border-radius: 4px;
    padding: 0 4px;

    &:hover {
      border-color: $text-gray;
    }
  }

  .calendar-select {
    color: $text-gray !important;
    font-size: 0.8rem !important;

    .MuiSelect-root {
      padding: 4px 24px 4px 6px !important;
    }

    .MuiSelect-icon {
      color: $text-gray;
    }

    &:hover {
      color: $text-white !important;
    }
  }

  .calendar-select-menu {
    background-color: #1c1f23 !important;
    color: $text-white !important;
    border: 1px solid $border-color;

    .MuiMenuItem-root {
      font-size: 0.85rem;
      color: $text-gray;

      &:hover, &.Mui-selected {
        background-color: rgba(102, 119, 136, 0.2) !important;
        color: $text-white;
      }
    }
  }

  .rss-notice {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.75rem;
    color: $text-gray;
    background-color: rgba(102, 119, 136, 0.08);
    border: 1px solid rgba(102, 119, 136, 0.2);
    border-radius: 4px;
    padding: 6px 10px;
    margin-bottom: 1rem;
  }

  .rss-notice-icon {
    font-size: 0.8rem;
    flex-shrink: 0;
  }

  .rss-notice-link {
    color: $primary-color;
    cursor: pointer;
    text-decoration: underline;

    &:hover { color: color.scale($primary-color, $lightness: 15%); }
  }

  // Calendar grid
  .calendar-grid-wrapper {
    position: relative;
  }

  .calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 6px;
    max-width: calc((120vh - 340px) * 7 / 9);
    min-width: 280px;
    margin: 0 auto;
  }

  .calendar-day-header {
    color: $text-gray;
    font-size: 0.75rem;
    font-weight: 600;
    text-align: center;
    text-transform: uppercase;
    padding: 0.25rem 0;
    letter-spacing: 0.05em;
  }

  .calendar-cell {
    position: relative;
    border-radius: 4px;
    border: 1px solid $border-color;
    overflow: hidden;
    background-color: #14181c;
    aspect-ratio: 2/3;
    min-height: 14vh;

    &--empty {
      border-color: transparent;
      background-color: transparent;
    }

    &--future {
      background-color: rgba(255, 255, 255, 0.02);
      border-color: rgba(255, 255, 255, 0.04);

      .calendar-day-number {
        opacity: 0.25;
      }
    }

    &--today {
      border-color: $secondary-color;

      .calendar-day-number {
        color: $text-white;
        font-weight: 700;
      }
    }

    &--has-movie {
      cursor: pointer;
      border-color: transparent;

      &:hover .calendar-poster-overlay {
        opacity: 1;
      }

      &:hover .calendar-day-number {
        color: $text-white;
        text-shadow: 0 1px 4px rgba(0, 0, 0, 0.8);
      }
    }
  }

  .calendar-day-number {
    position: absolute;
    top: 4px;
    left: 6px;
    font-size: 0.7rem;
    color: $text-gray;
    z-index: 2;
    line-height: 1;
  }

  .calendar-poster-wrapper {
    position: absolute;
    inset: 0;
  }

  .calendar-cell-skeleton {
    position: absolute;
    inset: 0;
    background: linear-gradient(90deg, #1c1f23 25%, #252930 50%, #1c1f23 75%);
    background-size: 200% 100%;
    animation: calendar-shimmer 1.4s infinite;
  }

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

  .calendar-poster {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
  }

  .calendar-poster-overlay {
    position: absolute;
    inset: 0;
    background: linear-gradient(to top, rgba(0, 0, 0, 0.85) 0%, rgba(0, 0, 0, 0.2) 60%, transparent 100%);
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    padding: 6px;
    opacity: 0;
    transition: opacity 0.2s ease;
  }

  .calendar-movie-title {
    color: $text-white;
    font-size: 0.65rem;
    font-weight: 600;
    line-height: 1.2;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }

  .calendar-movie-year {
    color: $text-gray;
    font-size: 0.6rem;
    margin-top: 2px;
  }

  .calendar-more-badge {
    position: absolute;
    top: 4px;
    right: 4px;
    background-color: $primary-color;
    color: $text-white;
    font-size: 0.6rem;
    font-weight: 700;
    padding: 1px 4px;
    border-radius: 3px;
    z-index: 2;
  }

  .calendar-selected-badge {
    position: absolute;
    bottom: 4px;
    right: 4px;
    background-color: $primary-color;
    color: $text-white;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2;
  }

  .calendar-cell--selected {
    box-shadow: 0 0 0 2px $primary-color;
    border-radius: 4px;
  }

  // Shared states
  .progress-container {
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    height: 200px;

    .MuiLinearProgress-root {
      width: 100%;
      margin-bottom: 1rem;
    }
  }

  .progress-label {
    margin-top: 1rem;
    color: $text-white;
  }

  .no-movies-container {
    position: absolute;
    inset: 0;
    z-index: 10;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: $text-white;
    background: rgba(28, 31, 35, 0.7);
    backdrop-filter: blur(6px);
    border-radius: 4px;
    animation: fade-in 0.3s ease;
  }

  @keyframes fade-in {
    from { opacity: 0; }
    to   { opacity: 1; }
  }

  .gif-container {
    display: flex;
    justify-content: center;
    position: relative;
    width: 200px;
    height: 200px;
    margin-bottom: 1rem;
  }

  .circle-background {
    position: absolute;
    width: 120%;
    height: 120%;
    border-radius: 50%;
    background-color: $text-white;
    clip-path: inset(0 0 25% 0);
    bottom: -28%;
  }

  .reaction-gif {
    position: absolute;
    width: 100%;
    height: 100%;
    object-fit: contain;
  }

  .back-button {
    margin-top: 1rem;
    background-color: $primary-color !important;
    color: $text-white !important;
    transition: background-color 0.3s ease;

    &:hover {
      background-color: color.scale($primary-color, $lightness: 10%) !important;
    }
  }
}

// Responsive
@media (max-width: 768px) {
  .poster-selector {
    margin-top: 3.5rem !important;
    padding-left: 0.5rem !important;
    padding-right: 0.5rem !important;
  }

  .poster-selector .content-paper {
    padding: 0.75rem !important;
    max-width: 100% !important;
  }

  // Nav : deux rangées
  // Rangée 1 : Today (gauche) | chevrons + label (droite)
  // Rangée 2 : selects centrés
  .poster-selector .calendar-nav {
    flex-wrap: wrap;
    row-gap: 8px;
    margin-bottom: 0.75rem;
  }

  .poster-selector .calendar-today-btn {
    order: 1;
  }

  .poster-selector .calendar-nav-center {
    order: 2;
    flex: 1;
    justify-content: flex-end;
  }

  .poster-selector .calendar-month-label {
    min-width: unset !important;
    font-size: 0.9rem !important;
  }

  .poster-selector .calendar-month-selects {
    order: 3;
    width: 100%;
    justify-content: center !important;
    border: none !important;
    border-top: 1px solid #2c3038 !important;
    border-radius: 0 !important;
    padding: 6px 0 0 !important;
    gap: 8px !important;
  }

  // Grille
  .poster-selector .calendar-grid {
    gap: 3px;
    max-width: 100%;
    min-width: unset;
  }

  .poster-selector .calendar-day-header {
    font-size: 0.6rem;
    padding: 0.15rem 0;
  }

  .poster-selector .calendar-cell {
    min-height: unset; // aspect-ratio 2/3 contrôle la hauteur
    border-radius: 3px;
  }

  .poster-selector .calendar-day-number {
    font-size: 0.6rem;
  }

  .poster-selector .calendar-movie-title {
    font-size: 0.55rem;
  }

  .poster-selector .calendar-more-badge,
  .poster-selector .calendar-selected-badge {
    display: none;
  }
}

// Popover multi-films (rendu en portal, hors de .poster-selector)
.multi-movie-popover {
  background-color: #1c1f23 !important;
  border: 1px solid #2c3038;
  border-radius: 6px !important;
  overflow: hidden;
  min-width: 220px;
}

.multi-movie-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  cursor: pointer;
  border-bottom: 1px solid #2c3038;

  &:last-child { border-bottom: none; }

  &:hover { background-color: rgba(102, 119, 136, 0.2); }
}

.multi-movie-poster {
  width: 36px;
  height: 54px;
  object-fit: cover;
  border-radius: 2px;
  flex-shrink: 0;

  &--empty { background-color: #2c3038; }
}

.multi-movie-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.multi-movie-title {
  color: #ffffff;
  font-size: 0.8rem;
  font-weight: 500;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.multi-movie-year {
  color: #667788;
  font-size: 0.7rem;
}

.multi-movie-check {
  color: #00a346 !important;
  flex-shrink: 0;
}
