@import "../variables.scss";

.weekly-schedule {
  height: auto;

  .schedule-header {
    margin-bottom: 15px;
  }

  .schedule-navigation {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;

    button {
      padding: 0.3rem 0.6rem;
    }

    .date-range-header {
      font-weight: bold;
      display: flex;
      align-items: center;
      gap: 10px;

      button {
        padding: 0.2rem 0.4rem;
      }
    }
  }

  .schedule-grid {
    display: grid;
    grid-template-columns: 3rem repeat(5, 1fr);
    gap: 1px;
    background-color: var(--colour-neutral-1000);
    border: 1px solid var(--colour-neutral-800);
    border-radius: 8px;
    overflow: visible;
    position: relative;
  }

  .grid-header {
    display: contents;
  }

  .day-header {
    color: var(--colour-neutral-000);
    padding: 6px 4px;
    text-align: center;
    font-weight: bold;

    .day-date {
      color: var(--colour-neutral-400);
    }
  }

  .time-column {
    display: flex;
    flex-direction: column;
    position: relative;
  }

  .time-label {
    color: var(--colour-neutral-000);
    height: 17.5px;
    position: relative;
  }

  .time-text {
    position: absolute;
    right: 1px;
    top: -10px;
    font-size: 0.8rem;
    background-color: var(--colour-neutral-1000);
    padding: 0 2px;
    font-family: monospace;
  }

  .time-label--half {
    color: var(--colour-neutral-400);
  }

  .day-column {
    position: relative;
    background-color: var(--colour-neutral-1100);
  }

  .time-slot {
    height: 17.5px;
    border-bottom: 1px dashed var(--colour-neutral-900);
  }

  .time-slot--half {
    border-bottom-style: solid;
  }

  .course-block {
    position: absolute;
    left: 2px;
    right: 2px;
    color: var(--colour-neutral-000);
    padding: 2px 3px;
    border-radius: 2px;
    font-size: 0.75rem;
    overflow: hidden;
    white-space: normal;
    z-index: 1;
  }

  .course-block:hover {
    overflow: visible;
    z-index: 2;
    box-shadow: 0 0 5px rgba(0, 0, 0, 0.3);
  }

  // Mobile responsiveness
  @include viewport(mobile) {
    .date-range-header {
      flex-direction: column;
      align-items: center;
    }

    .schedule-grid {
      width: 100%;
      overflow-x: auto;
    }

    .time-text {
      font-size: 0.7rem;
    }

    .course-block {
      font-size: 0.7rem;
      padding: 1px 2px;
    }
  }
}

.weekly-schedule {
  .time-blocking-hint {
    text-align: center;
    color: var(--colour-neutral-400);
    margin-bottom: 10px;
    font-size: 0.9rem;
  }

  .schedule-grid {
    cursor: default;

    .day-column {
      position: relative;

      .time-slot {
        cursor: cell;
        transition: background-color 0.1s ease;

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

  .course-block {
    &.time-block {
      cursor: pointer;
      border: 1px dashed rgba(255, 255, 255, 0.5);
      background-image: repeating-linear-gradient(
        45deg,
        rgba(0, 0, 0, 0.1),
        rgba(0, 0, 0, 0.1) 10px,
        rgba(0, 0, 0, 0.2) 10px,
        rgba(0, 0, 0, 0.2) 20px
      );

      .time-block-label {
        font-weight: bold;
        font-size: 0.85rem;
        margin-bottom: 4px;
      }

      .time-block-time {
        font-size: 0.75rem;
        opacity: 0.9;
      }

      &:hover {
        opacity: 0.8;
        border: 1px solid white;
      }

      &.preview {
        border: 2px dashed white;
        animation: pulse 1.5s infinite;
        pointer-events: none;
      }
    }
  }
}

@keyframes pulse {
  0% {
    opacity: 0.7;
  }
  50% {
    opacity: 0.9;
  }
  100% {
    opacity: 0.7;
  }
}

/* Mobile Adjustments */
@media (max-width: 768px) {
  .weekly-schedule {
    .time-blocking-hint {
      font-size: 0.8rem;
    }

    .course-block.time-block {
      .time-block-label {
        font-size: 0.7rem;
      }

      .time-block-time {
        font-size: 0.65rem;
      }
    }
  }
}

/* Animation for newly merged blocks */
@keyframes merge-pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(255, 255, 255, 0.7);
  }
  70% {
    box-shadow: 0 0 0 10px rgba(255, 255, 255, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(255, 255, 255, 0);
  }
}

/* Style for blocks that were recently merged */
.course-block.time-block.merged {
  border: 2px solid #fff;
  animation: merge-pulse 1.5s ease-out;
  background-image: repeating-linear-gradient(
    45deg,
    rgba(0, 0, 0, 0.2),
    rgba(0, 0, 0, 0.2) 10px,
    rgba(0, 0, 0, 0.3) 10px,
    rgba(0, 0, 0, 0.3) 20px
  );
}

/* Style for the merge indicator */
.merge-indicator {
  position: absolute;
  right: 5px;
  top: 5px;
  background-color: rgba(255, 255, 255, 0.9);
  color: #dc4c64;
  font-size: 0.7rem;
  padding: 2px 4px;
  border-radius: 4px;
  font-weight: bold;
  opacity: 0.8;
  pointer-events: none;
}

.time-block-toggle-container {
  display: flex;
  justify-content: center;
  margin-bottom: 10px;
}

.time-block-toggle-button {
  padding: 8px 12px;
  background-color: var(--colour-neutral-900);
  color: var(--colour-neutral-100);
  border: none;
  border-radius: 20px;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.2s ease;

  &.active {
    background-color: rgba(220, 76, 100, 0.9);
    color: white;
    box-shadow: 0 0 8px rgba(220, 76, 100, 0.6);
  }

  &:hover {
    opacity: 0.9;
  }
}

/* Visual indicator when in time block creation mode */
.schedule-grid.time-block-mode {
  // border: 2px dashed rgba(220, 76, 100, 0.6);

  .day-column .time-slot {
    cursor: pointer;

    &:hover {
      background-color: rgba(220, 76, 100, 0.2);
    }
  }
}

/* Mobile-specific adjustments */
@media (max-width: 768px) {
  .weekly-schedule {
    .course-block {
      /* Make blocks easier to tap */
      min-height: 30px;

      &.time-block {
        padding: 3px;

        .time-block-label {
          font-size: 0.7rem;
          font-weight: bold;
        }

        .time-block-time {
          font-size: 0.65rem;
        }
      }
    }

    /* Increase touch target sizes */
    .time-slot {
      height: 17.5px;
    }

    // /* Simple mode for small screens */
    // .time-block-minimal {
    //   .time-block-time {
    //     display: none;
    //   }
    // }
  }

  /* Mobile instruction helper */
  .mobile-instruction-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.7);
    color: white;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 100;
    padding: 20px;
    text-align: center;

    p {
      margin-bottom: 15px;
    }

    .instruction-btn {
      padding: 8px 15px;
      background-color: var(--colour-sosy-green-800);
      border: none;
      border-radius: 20px;
      color: white;
      font-weight: bold;
    }
  }
}

@media (max-width: 480px) {
  .weekly-schedule {
    .course-block {
      font-size: 0.7rem;
      padding: 2px;
      font-weight: bold;

      &.time-block {
        .time-block-label {
          font-size: 0.65rem;
        }
      }
    }

    .day-header {
      font-size: 0.8rem;

      .day-date {
        font-size: 0.7rem;
      }
    }
  }
}

.weekly-schedule {
  .schedule-grid {
    .day-column {
      .time-slot {
        cursor: pointer;
        transition: background-color 0.15s ease;
        position: relative;

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

        /* Style for selected slots during time block creation */
        &.selected {
          background-color: rgba(220, 76, 100, 0.3);

          &:hover {
            background-color: rgba(220, 76, 100, 0.4);
          }
        }
      }
    }
  }

  /* Enhanced styles for time block mode */
  .schedule-grid.time-block-mode {
    // border: 2px dashed rgba(220, 76, 100, 0.6);

    .day-column .time-slot {
      &:hover {
        background-color: rgba(220, 76, 100, 0.2);
      }

      &.selected {
        background-color: rgba(220, 76, 100, 0.4);

        &:hover {
          background-color: rgba(220, 76, 100, 0.5);
        }
      }
    }
  }

  .course-block {
    &.time-block.preview {
      z-index: 10;
      border: 2px dashed white;
      box-shadow: 0 0 5px rgba(0, 0, 0, 0.3);
    }
  }

  /* Improved time block toggle button */
  .time-block-toggle-button {
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 0.95rem;
    transition: all 0.2s ease;

    &.active {
      background-color: rgba(220, 76, 100, 0.9);
      color: white;
      box-shadow: 0 0 8px rgba(220, 76, 100, 0.5);
    }
  }

  /* Improve accessibility and clarity of time blocks */
  .course-block.time-block {
    cursor: pointer;

    &:hover {
      opacity: 0.9;
      border: 1px solid rgba(255, 255, 255, 0.8);
    }

    /* Animation for newly created time blocks */
    &.new {
      animation: pulse-highlight 1s ease-in-out;
    }
  }

  /* Animation for new time blocks */
  @keyframes pulse-highlight {
    0% {
      box-shadow: 0 0 0 0 rgba(255, 255, 255, 0.7);
    }
    50% {
      box-shadow: 0 0 0 10px rgba(255, 255, 255, 0);
    }
    100% {
      box-shadow: 0 0 0 0 rgba(255, 255, 255, 0);
    }
  }

  @media (max-width: 768px) {
    .time-block-toggle-button {
      width: 100%;
      padding: 10px;
      font-size: 0.9rem;
    }

    .time-blocking-hint {
      font-size: 0.8rem;
      padding: 0 5px;
    }
  }
}

/* Schedule Insights Compact Section */
.schedule-insights-compact {
  margin-top: 16px;
  padding: 12px;
  background-color: var(--colour-neutral-1100);
  border-radius: 8px;
  border: 2px solid var(--colour-neutral-800);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);

  .insights-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--colour-neutral-900);

    .insights-title {
      color: var(--colour-neutral-000);
      font-size: 0.95rem;
      font-weight: 600;
      display: flex;
      align-items: center;
      gap: 4px;

      .info-icon {
        font-size: 1.2rem;
        color: var(--colour-neutral-400);
        cursor: pointer;
      }
    }

    .schedule-quality-badge {
      font-size: 0.8rem;
      padding: 2px 8px;
      border-radius: 12px;
      font-weight: 500;

      &.quality-excellent {
        background-color: rgba(34, 197, 94, 0.2);
        color: #22c55e;
        border: 1px solid rgba(34, 197, 94, 0.3);
      }

      &.quality-good {
        background-color: rgba(59, 130, 246, 0.2);
        color: #3b82f6;
        border: 1px solid rgba(59, 130, 246, 0.3);
      }

      &.quality-fair {
        background-color: rgba(245, 158, 11, 0.2);
        color: #f59e0b;
        border: 1px solid rgba(245, 158, 11, 0.3);
      }

      &.quality-poor {
        background-color: rgba(239, 68, 68, 0.2);
        color: #ef4444;
        border: 1px solid rgba(239, 68, 68, 0.3);
      }

      &.quality-very-poor {
        background-color: rgba(220, 38, 38, 0.2);
        color: #dc2626;
        border: 1px solid rgba(220, 38, 38, 0.3);
      }
    }
  }

  .insights-list {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-auto-rows: min-content;
    gap: 6px 12px;
    grid-auto-flow: row;
  }

  .insight-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 8px;
    border-radius: 4px;
    border: 1px solid var(--colour-neutral-900);
    background-color: var(--colour-neutral-1000);

    .insight-icon {
      font-size: 1rem;
      width: 20px;
      color: var(--colour-neutral-300);
      flex-shrink: 0;
    }

    .insight-text {
      color: var(--colour-neutral-300);
      font-size: 0.85rem;
      flex: 1;
    }

    .insight-value {
      color: var(--colour-neutral-000);
      font-size: 0.85rem;
      font-weight: 600;
      font-family: monospace;
      min-width: 40px;
      text-align: right;
    }
  }

  @media (max-width: 768px) {
    .insights-list {
      grid-template-columns: 1fr;
      gap: 4px;
    }

    .insight-row {
      padding: 5px 6px;

      .insight-icon {
        font-size: 0.9rem;
        width: 18px;
      }

      .insight-text {
        font-size: 0.8rem;
      }

      .insight-value {
        font-size: 0.8rem;
        min-width: 35px;
      }
    }
  }
}
