/**
 * Frontend Styles
 */

@primary-color: #f7c938;
@secondary-color: #ffd966;
@text-color: #333;
@border-radius: 8px;
@panel-width: 400px;
@transition-speed: 0.3s;
@z-index-overlay: 9998;
@z-index-panel: 9999;
@z-index-tab: 10000;

// Sticky Edit Tab
.websamurai-edit-tab {
  position: fixed;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  background: linear-gradient(135deg, @primary-color 0%, @secondary-color 100%);
  color: #333;
  padding: 15px 12px;
  border-radius: @border-radius 0 0 @border-radius;
  cursor: pointer;
  z-index: @z-index-tab;
  box-shadow: -2px 2px 10px rgba(0, 0, 0, 0.2);
  transition: all @transition-speed ease;
  writing-mode: vertical-rl;
  text-orientation: mixed;
  font-weight: 600;
  font-size: 14px;
  letter-spacing: 1px;

  &:hover {
    background: linear-gradient(135deg, @secondary-color 0%, @primary-color 100%);
    box-shadow: -3px 3px 15px rgba(0, 0, 0, 0.3);
    padding-left: 15px;
  }

  &.open {
    right: @panel-width;
  }

  .tab-text {
    user-select: none;
  }
}

// Slide-out Panel
.websamurai-edit-panel {
  position: fixed;
  top: 32px;
  right: -@panel-width;
  width: @panel-width;
  height: calc( 100vh - 32px );
  background: #fff;
  box-shadow: -2px 0 20px rgba(0, 0, 0, 0.1);
  z-index: @z-index-panel;
  transition: right @transition-speed ease;
  display: flex;
  flex-direction: column;

  &.open {
    right: 0;
  }

  .panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    border-bottom: 1px solid #e5e7eb;
    background: linear-gradient(135deg, @primary-color 0%, @secondary-color 100%);
    color: #333;

    h3 {
      margin: 0;
      font-size: 18px;
      font-weight: 600;
    }

    .close-button {
      background: transparent;
      border: none;
      color: #333;
      font-size: 32px;
      line-height: 1;
      cursor: pointer;
      padding: 0;
      width: 32px;
      height: 32px;
      display: flex;
      align-items: center;
      justify-content: center;
      border-radius: 4px;
      transition: background-color 0.2s ease;

      &:hover {
        background-color: rgba(0, 0, 0, 0.1);
      }
    }
  }

  .panel-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;

    .responses-area {
      flex: 1;
      display: flex;
      flex-direction: column;
      overflow: hidden;
      padding: 20px 20px 0 20px;

      .empty-state {
        flex: 1;
        display: flex;
        align-items: center;
        justify-content: center;
        color: #9ca3af;
        text-align: center;
        padding: 40px 20px;

        p {
          margin: 0;
          font-size: 14px;
        }
      }

      .responses-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin-bottom: 15px;
        padding-bottom: 10px;
        border-bottom: 1px solid #e5e7eb;

        .responses-count {
          font-size: 12px;
          color: #6b7280;
          font-weight: 600;
        }

        .clear-button {
          background: transparent;
          border: none;
          color: #6b7280;
          font-size: 12px;
          cursor: pointer;
          padding: 4px 8px;
          border-radius: 4px;
          transition: background-color 0.2s ease;

          &:hover {
            background-color: #f3f4f6;
          }
        }
      }

      .responses-list {
        flex: 1;
        overflow-y: auto;
        display: flex;
        flex-direction: column;
        gap: 12px;

        .response-message {
          padding: 12px;
          border-radius: @border-radius;
          animation: slideIn 0.2s ease;

          &.user {
            background-color: #fffbeb;
            border-left: 3px solid @primary-color;
          }

          &.ai {
            background-color: #fef9e7;
            border-left: 3px solid @primary-color;
          }

          &.error {
            background-color: #fef2f2;
            border-left: 3px solid #ef4444;
          }

          .message-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 6px;

            .message-label {
              font-size: 11px;
              font-weight: 700;
              text-transform: uppercase;
              letter-spacing: 0.5px;
            }

            .message-time {
              font-size: 11px;
              color: #6b7280;
            }
          }

          .message-text {
            font-size: 13px;
            line-height: 1.5;
            color: @text-color;
            word-wrap: break-word;
          }

          &.user .message-label {
            color: #d97706;
          }

          &.ai .message-label {
            color: #b45309;
          }

          &.error .message-label {
            color: #ef4444;
          }
        }
      }
    }

    .input-area {
      padding: 15px 20px 20px 20px;
      border-top: 1px solid #e5e7eb;
      background-color: #f9fafb;

      .ai-textarea {
        width: 100%;
        padding: 10px 12px;
        border: 2px solid #e5e7eb;
        border-radius: @border-radius;
        font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
        font-size: 13px;
        line-height: 1.4;
        resize: none;
        transition: border-color 0.2s ease;
        margin-bottom: 10px;
        background-color: #fff;

        &:focus {
          outline: none;
          border-color: @primary-color;
          background-color: #fff;
        }

        &:disabled {
          background-color: #f3f4f6;
          cursor: not-allowed;
        }

        &::placeholder {
          color: #9ca3af;
          font-size: 12px;
        }
      }

      .panel-actions {
        display: flex;
        gap: 8px;

        button {
          padding: 10px 20px;
          border: none;
          border-radius: @border-radius;
          font-weight: 600;
          font-size: 13px;
          cursor: pointer;
          transition: all 0.2s ease;

          &:disabled {
            opacity: 0.5;
            cursor: not-allowed;
          }
        }

        .submit-button {
          flex: 1;
          background: linear-gradient(135deg, @primary-color 0%, @secondary-color 100%);
          color: #333;
          font-weight: 700;

          &:hover:not(:disabled) {
            box-shadow: 0 4px 12px rgba(247, 201, 56, 0.4);
            transform: translateY(-1px);
          }

          &:active:not(:disabled) {
            transform: translateY(0);
          }
        }
      }
    }
  }
}

// Overlay
.websamurai-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  z-index: @z-index-overlay;
  animation: fadeIn @transition-speed ease;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes thinking-bounce {
  0%, 80%, 100% {
    transform: scale(0);
    opacity: 0.5;
  }
  40% {
    transform: scale(1);
    opacity: 1;
  }
}

// Thinking animation
.thinking-animation {
  display: flex;
  gap: 6px;
  align-items: center;
  padding: 8px 0;

  .dot {
    width: 8px;
    height: 8px;
    background-color: @primary-color;
    border-radius: 50%;
    animation: thinking-bounce 1.4s infinite ease-in-out both;

    &:nth-child(1) {
      animation-delay: -0.32s;
    }

    &:nth-child(2) {
      animation-delay: -0.16s;
    }

    &:nth-child(3) {
      animation-delay: 0s;
    }
  }
}

// Responsive adjustments
@media (max-width: 768px) {
  .websamurai-edit-panel {
    width: 100%;
    right: -100%;
  }

  .websamurai-edit-tab.open {
    right: 100%;
  }
}
