@import "../variables.scss";

#schedule-container {
  display: flex;
  max-width: 100%;
  width: 100rem;
  gap: 1rem;
  position: relative;

  .courses-section {
    display: flex;
    flex-direction: column;
    max-width: 100%;
    width: 22.5rem;
    // gap: 0.2rem;
    flex: 0 0 auto;

    &__header {
      display: flex;
      flex-direction: column;
      align-items: flex-start;
      gap: 0.5rem;
      margin-bottom: 0.5rem;

      .big.explore {
        margin-top: 0;
      }
    }

    .courses-container {
      display: flex;
      flex-direction: column;
      gap: 0.75rem;
    }

    .search-filter-row {
      display: flex;
      align-items: center;
      margin-bottom: 0.5rem;

      .search-bar {
        flex: 1;
      }

      @media screen and (max-width: 600px) {
        flex-direction: column;
        align-items: stretch;
      }
    }

    .term-filter-row {
      display: flex;
      align-items: center;
      gap: 0.5rem;
      width: 100%;
      margin-bottom: 0.75rem;
    }

    .section-details-container {
      cursor: pointer;

      &:hover {
        opacity: 0.9;
        transform: translateY(-0.1rem);
      }

      &:active {
        transform: scale(0.99);
      }
    }
  }

  .campus-filter {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-top: 0.25rem;
    width: fit-content;

    .campus-select {
      flex: 1;
      background-color: var(--colour-neutral-1000);
      border: 1px solid var(--colour-neutral-800);
      border-radius: 0.25rem;
      color: var(--colour-neutral-100);
      padding: 0.5rem;
      font-size: 0.9rem;
      width: 6rem;

      &:focus {
        outline: none;
        border-color: var(--colour-sosy-green-600);
      }

      option {
        background-color: var(--colour-neutral-1100);
        color: var(--colour-neutral-000);
      }
    }
  }

  .term-toggle-button {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4rem;
    width: fit-content;
    background-color: var(--colour-neutral-1000);
    border: 1px solid var(--colour-neutral-800);
    color: var(--colour-neutral-000);
    border-radius: 0.5rem;
    font-size: 0.95rem;
    transition: all $transition-speed-fast $easing-bounce;
    cursor: pointer;

    svg {
      font-size: 1.1rem;
    }

    &:hover {
      background-color: var(--colour-neutral-900);
    }

    &.active {
      background-color: var(--colour-sosy-green-800);
      border-color: var(--colour-sosy-green-700);

      &:hover {
        background-color: var(--colour-sosy-green-700);
      }
    }
  }

  .term-toggle-group {
    display: flex;
  }

  @media screen and (max-width: 600px) {
    .term-toggle-button {
      flex: 1;
      justify-content: center;
      font-size: 0.85rem;
      padding: 0.35rem 0.6rem;
    }

    .term-toggle-group {
      width: 100%;
    }
  }

  .search-filter-container {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-bottom: 0.5rem;
  }

  .schedule-section {
    margin-top: 4.5rem;
    flex: 1 1;
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    position: sticky;
    top: 1rem;
    align-self: flex-start;
    z-index: 20;
    height: auto;
    overflow: auto;

    &__header {
      display: flex;
      justify-content: space-between;
      align-items: flex-end;
      gap: 0.5rem;
    }

    &__content {
      width: 100%;
      display: flex;
      gap: 1rem;
      padding: 1rem;
      border: 1px dashed gray;
      border-radius: 0.5rem;
      flex: 1;
      height: auto;
      /* No fixed height */
      overflow: visible;
      /* No overflow handling - show all content */

      /* No max-height */
    }

    .selected-courses {
      flex: 1 1;
      width: 100%;
      max-width: 22.5rem;
      display: flex;
      flex-direction: column;
      gap: 1rem;
      overflow: auto;
      // max-height: 45rem;

      &__items {
        display: flex;
        flex-direction: column;
        gap: 1rem;
        /* No max-height or overflow settings */
      }
    }

    .schedule-container {
      flex: 1 1;
      width: 100%;
      display: flex;
      flex-direction: column;
      gap: 1rem;
      height: auto;
      /* Allow natural height */
    }
  }

  &.two-column {
    width: 75rem;

    .schedule-section__content {
      flex-direction: column-reverse;
    }
  }

  // Handle smaller screens
  @media (max-width: 1024px) {
    flex-direction: column-reverse;

    .schedule-section {
      position: static; // Remove sticky behavior on small screens
    }
  }

  // Mobile layout
  @media (max-width: 768px) {
    flex-direction: column-reverse;

    .courses-section {
      .term-filter-row {
        justify-content: flex-end;
      }
    }

    .schedule-section {
      margin-top: 1rem;
      flex-direction: column;
      position: static;

      &__header {
        flex-direction: column;
      }

      .view-column-button-group {
        display: none;
      }

      &__content {
        flex-direction: column-reverse;
        padding: 0.75rem;
      }

      .selected-courses,
      .schedule-container {
        max-width: 100%;
      }
    }

    // Adjust campus filter for mobile
    .search-filter-container {
      .campus-filter {
        flex-direction: column;
        align-items: flex-start;

        label {
          margin-bottom: 0.25rem;
        }

        .campus-select {
          width: 100%;
        }
      }
    }
  }
}

/* Empty message styling */
.empty-message {
  text-align: center;
  padding: 2rem 0;
  font-style: italic;
}

/* General layout improvements */
.section-title {
  background-color: var(--colour-neutral-1200);
  padding: 0.5rem 0;
  margin-top: 0;
  margin-bottom: 0.5rem;
}

/* Ensure WeeklySchedule component shows all content */
.weekly-schedule {
  .schedule-grid {
    height: auto;
    /* Let content determine height */
    overflow: visible;
    /* No overflow handling */
  }
}

/* Empty state styling */
.schedule-container:empty::after {
  content: "Select courses to see your schedule";
  display: block;
  text-align: center;
  color: var(--colour-neutral-500);
  padding: 2rem;
  font-style: italic;
}

.text-badge.explore {
  background: var(--colour-neutral-1100) 100%;
  color: var(--colour-sosy-green-500);
  width: fit-content;
}

.campus-filter-select {
  display: flex;
  align-items: center;
  padding: 0.4rem 0.2rem;
  width: fit-content;
  background-color: var(--colour-neutral-1000);
  border: 1px solid var(--colour-neutral-800);
  color: var(--colour-neutral-000);
  border-radius: 0.5rem;
  font-size: 0.95rem;
  transition: all $transition-speed-fast $easing-bounce;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;

  &:hover {
    background-color: var(--colour-neutral-900);
  }

  &:focus {
    outline: 2px solid var(--colour-sosy-green-600);
    outline-offset: 1px;
  }

  option {
    background-color: var(--colour-neutral-1000);
  }
}

.filter-with-icon {
  position: relative;
  display: inline-flex;
  align-items: center;

  svg {
    position: absolute;
    left: 0.5rem;
    color: var(--colour-sosy-green-500);
    font-size: 1.1rem;
  }

  select {
    padding-left: 2rem;
  }
}

@media screen and (max-width: 600px) {
  .campus-filter-select {
    font-size: 0.85rem;
    padding: 0.35rem 0.6rem;
    padding-left: 1.8rem;
  }

  .filter-with-icon svg {
    font-size: 1rem;
    left: 0.4rem;
  }
}
